Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic zoom and others (Read 6425 times)
granit
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Mar 1st, 2010
zoom and others
Nov 26th, 2010 at 5:33pm
Print Post  
Dear Stoyo, several questions

1) Layout/Fit/Undo note

Step1. Spring layout operation of test diagram
SpringLayout layout = new SpringLayout();
layout.Arrange(this.diagram1);

Step2. Fit its bounds.
this.diagram1.ResizeToFitItems(1);

Step3. [Undo] operation
this.diagram1.UndoManager.Undo();

initial layout restored, fit operation not stored in command history stack.
How to remember fit operation in command history stack?

2) I found that it is possible to set diagramView zoom bounds (ZoomToRect function) but not found a way to get current «zoom rectangle». If such function exists, please point me to it. If not, is it possible to include something similar in the future?

3) See picture below. With big pen width and arrowhead diagramLink rendered as lower picture. Is it possible to render link with head as upper picture?


4) See picture below. After diagram saving to binary with wmf pictures in nodes (diagram.savetofile) and reopening it (diagram.loadfromfile) wmf pictures in shape nodes renders like bmp.


5) picture below. ZoomFactor zooms picture relatively upper left point of zoom area (black lines on picture). Is it possible for zooming relatively center of zoom area (red lines)?


6) picture below. Is it possible to get building functionality for zooming similar multiple selection? I mean selecting zooming area by mouse, with following zooming diagram to this rectangle (see Zoom Tool (magnifier) in Adobe Photoshop, for example). I think itis very handy function.


Best
Vlad
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: zoom and others
Reply #1 - Nov 26th, 2010 at 9:43pm
Print Post  
Hi,

6) Try assigning an instance of this class to DiagramView.CustomBehavior:

Code
Select All
class ZoomTool : BehaviorBase
{
	public ZoomTool(DiagramView diagramView) : base(diagramView)
	{
		Diagram.NodeSelecting += Diagram_NodeSelecting;
		Diagram.LinkSelecting += Diagram_LinkSelecting;
	}

	void Diagram_LinkSelecting(object sender, LinkValidationEventArgs e)
	{
		e.Cancel = zoomInteraction != null;
	}

	void Diagram_NodeSelecting(object sender, NodeValidationEventArgs e)
	{
		e.Cancel = zoomInteraction != null;
	}

	protected override void OnMouseUp(Point mousePosition, System.Windows.Forms.MouseButtons mouseButton)
	{
		if (zoomInteraction != null)
			DiagramView.ZoomToRect(zoomInteraction.CurrentItem.GetBounds());
base.OnMouseUp(mousePosition, mouseButton);
		zoomInteraction = null;
	}

	public override InteractionState StartDraw(PointF point)
	{
		zoomInteraction = new InteractionState(Diagram.Selection, -1, Action.Create);
		return zoomInteraction;
	}

	public override CursorHint SetMouseCursor(PointF point, out bool startInteraction)
	{
		startInteraction = true;
		return CursorHint.Pointer;
	}

	private InteractionState zoomInteraction;
} 



Stoyan
  
Back to top
 
IP Logged
 
granit
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Mar 1st, 2010
Re: zoom and others
Reply #2 - Nov 29th, 2010 at 6:37am
Print Post  
Stoyan, thanks for answer.

Concerning image restoration after saving/loading diagram (question 4 in first post) I found the same behaviour in case of copy/past operations through diagramView.CopyToClipBoard/diagramView.PasteFromClipboard tools

Best
Vlad
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: zoom and others
Reply #3 - Nov 29th, 2010 at 7:53am
Print Post  
5. Try the following method:

Code
Select All
private void ZoomInCentered()
{
	RectangleF viewRect = diagramView.ClientToDoc(diagramView.ClientRectangle);
	viewRect.Inflate(- viewRect.Width * 0.1f, - viewRect.Height * 0.1f);
	diagramView.ZoomToRect(viewRect);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: zoom and others
Reply #4 - Nov 29th, 2010 at 8:10am
Print Post  
4. happens because the control calls Image.SaveToStream when saving images, but the framework does not provide a metafile encoder and falls back to PngEndoder. You can verify that like this:

new Metafile("test1.emf").Save("test2.emf");

Now if you open test2 with the VS binary editor, it will have the PNG header. As a work-around you could override the SaveTo and LoadFrom methods of nodes to save the file path to the WMF images, and then load the original images from LoadFrom.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: zoom and others
Reply #5 - Nov 29th, 2010 at 10:03am
Print Post  
For 3 you could try some custom drawing. E.g. check this sample, though it won't work with some arrowhead shapes:
https://mindfusion.eu/_samples/ArrowPenTest.zip
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: zoom and others
Reply #6 - Nov 29th, 2010 at 12:59pm
Print Post  
1) As you've noticed resizing the diagram is not subject to undo/redo. To enable undo/redo, you can use the following custom command:

Code
Select All
class ResizeToFitCommand : Command
{
	public ResizeToFitCommand(Diagram diagram)
		: base("Resize")
	{
		this.diagram = diagram;
	}

	protected override void Execute(bool undoEnabled)
	{
		bounds = diagram.Bounds;

		diagram.ResizeToFitItems(1);
	}

	protected override void Undo()
	{
		diagram.Bounds = bounds;
	}

	protected override void Redo()
	{
		Execute(true);
	}


	private Diagram diagram;
	private RectangleF bounds;
} 


Then, modify your code as follows:

Code
Select All
CompositeCmd composite = diagram1.UndoManager.StartComposite("Arrange and resize");

SpringLayout l = new SpringLayout();
l.Arrange(diagram1);
diagram1.ExecuteCommand(new ResizeToFitCommand(diagram1));

composite.Execute(); 



2) To get the current viewport expressed in document coordinates, use the following code:

Code
Select All
RectangleF viewport = diagramView1.ClientToDoc(diagramView1.ClientRectangle); 


I am assuming that diagramView1 is the DiagramView containing the respective diagram.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
granit
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Mar 1st, 2010
Re: zoom and others
Reply #7 - Dec 1st, 2010 at 2:16pm
Print Post  
thanks

best
vlad
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint