DragZoomingTool

Hi

I have problems with the DragZoomingTool. The first (and sometimes second) zooming works fine but then when trying to zoom the zoomed area it fails. The viewport updates but nothing is zoomed, objects in the upper left corner in the zooming rectangle are placed in the upper left corner of the viewport but nothing else happens.
Using GoWPF 1.2.6.4 / VS2010
Best regards
Henrik

I’m unable to reproduce any problems.

Could you describe your application and these circumstances in more detail?
Did you set Diagram.DragZoomingTool?
Did you set Diagram.PanningTool and DragSelectingTool to null, or otherwise disable them?

Have you changed the DiagramPanel.MaximumScale, or is the drag-zoom hitting that limit?

I have disabled the tools this way:

myDiagram.DragSelectingTool.MouseEnabled = False
myDiagram.PanningTool.MouseEnabled = False
and then activating the DragZoomingTool
myDiagram.CurrentTool = New DragZoomingTool
I have not made any changes to MaximumScale.
/Henrik

Ah, so you are using the tool in a modal fashion. It is normally a mode-less tool, to be part of the Diagram’s MouseMoveTools. So normally a mouse up while it’s operating will stop that tool, causing the default tool to run, which is normally a ToolManager.

So I’m surprised that it ever ran twice in a row.

You can override DragZoomingTool.DoMouseUp to do this:
public override void DoMouseUp() {
Diagram diagram = this.Diagram;
if (this.Active && diagram != null) {
try {
diagram.Cursor = Cursors.Wait;
ZoomToRect(ComputeBoxBounds());
} finally {
diagram.Cursor = null;
}
}
}

This way the user can keep using the tool repeatedly until they hit Escape or invoke another command of yours that sets Diagram.CurrentTool to some other tool.

Hi, I have implemented the following

Public Class MyDragZoom
Inherits DragZoomingTool
Public Overrides Sub DoMouseUp()
Dim diagram As Diagram = Me.Diagram
If Me.Active AndAlso diagram IsNot Nothing Then
Try
diagram.Cursor = Cursors.Wait
ZoomToRect(ComputeBoxBounds())
Finally
diagram.Cursor = Nothing
DoDeactivate()
End Try
End If
End Sub
End Class
How do I start the DragZoomingTool then?
Public MyDragZoomTool As MyDragZoom
myDiagram.DragSelectingTool.MouseEnabled = False
myDiagram.PanningTool.MouseEnabled = False
myDiagram.CurrentTool = MyDragZoomTool
gives same result as before, only difference is it doesnt stop after each zoom. But it does not zoom to rectangle more than once...
/Henrik

Ah yes, you do want to de-activate the tool between uses. Sorry about that – I should have tried it first.

Here’s what I just tried:

public class ModalZoomingTool : DragZoomingTool { public override void DoMouseUp() { Diagram diagram = this.Diagram; if (this.Active && diagram != null) { if (!this.IsBeyondDragSize()) { StopTool(); // stop this tool if it's just a click } else { try { diagram.Cursor = Cursors.Wait; ZoomToRect(ComputeBoxBounds()); } finally { diagram.Cursor = null; } DoDeactivate(); // finish the drag // don't stop -- be ready to drag-zoom again } } } }
I have also had it stop running when the user clicks somewhere.
Otherwise the user might not realize they need to cancel (Escape) to stop running this modal tool.
(That’s an example of why modal tools aren’t always the best way to organize functionality.)

To start this modal tool, say from a Button or other command:

private void Button_Click(object sender, RoutedEventArgs e) { var zt = new ModalZoomingTool(); zt.Diagram = myDiagram; myDiagram.CurrentTool = zt; }

Thanks, but the problems remain

Before dragzoom:
And after:
but if I zoom by increasing MyDiagram.Panel.Scale I can zoom to desired level:
/Henrik

That’s because DraggingTool.ZoomToRect is artificially limiting the maximum scale that’s allowed.

This will avoid that limit:

[code] public override void ZoomToRect(Rect brect) {
Diagram observed = this.ZoomedDiagram;
if (observed == null) observed = this.Diagram;
if (observed == null) return;
if (brect.Width < 0.1) return;

  double vrectw = observed.Panel.ViewportWidth;
  // do scale first, so DiagramPanel.NormalizePosition isn't constrained unduly when increasing scale
  observed.Panel.Scale = vrectw/brect.Width;
  observed.Panel.Position = new Point(brect.X, brect.Y);
}[/code]

It works great!

Thank you!
/Henrik