Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic AnchorPoints -  ShowAnchors & SnapToAncho (Read 2897 times)
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
AnchorPoints -  ShowAnchors & SnapToAncho
Dec 16th, 2011 at 10:19pm
Print Post  
Hi !

After drawing my own nodes based on a DiagramNode (thx to Stoyo!!) I need some Anchorpoints.

I loaded your IconNode Sample and modify the code for the node creation:
Code
Select All
private void diagram_Clicked(object sender, DiagramEventArgs e)
{
IconNode iconNode = new IconNode(diagram);

		var apat2 = new AnchorPattern(new AnchorPoint[]
{
new AnchorPoint(10, 0, true, false, MarkStyle.Circle, Color.RoyalBlue),
new AnchorPoint(50, 0, true, false, MarkStyle.Circle, Color.Blue),
new AnchorPoint(90, 0, true, false, MarkStyle.Circle, Color.Firebrick),
new AnchorPoint(10, 100, false, true, MarkStyle.Rectangle),
new AnchorPoint(50, 100, false, true, MarkStyle.Rectangle),
new AnchorPoint(90, 100, false, true, MarkStyle.Rectangle),
new AnchorPoint(0, 50, true, true, MarkStyle.Custom)
});

    iconNode.AnchorPattern = apat2;

diagram.Nodes.Add(iconNode);

iconNode.Move(e.MousePosition.X, e.MousePosition.Y);
} 



I need to show the Anchorpoints always so I try setting "ShowAnchors" to "Always".
But the result is that the points are gone. If set it back to selection I see the points when I hover over the node with the mouse.

The next problem is the snapping. I need always the same Anchorpoints. So I set SnaptToAnchor to "OnCreate". But if you run the above code, create 2 nodes, link them you could a nive effect.
Move one node around the other and you will see that the link is snapping  Angry

Maybe I did something completely wrong but I can´t find any hints in the help which pointing to some known issues.

And one last question about AnchorPoints. Is it a problem to replace the Points if the drawing of the node changes? I have a node where I can enable / disable an additional text. This causes some changes in the Draw methode. So can I change the positions of the Anchors within the Draw methode of my node?

Greetz
  Dominik
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AnchorPoints -  ShowAnchors & SnapToAncho
Reply #1 - Dec 19th, 2011 at 7:53am
Print Post  
Hi,

1) Add these lines to IconNode.Draw:

Code
Select All
if (ShouldRenderAnchors(options))
	DrawAnchors(graphics); 



2) Move one node around the other and you will see that the link is snapping ...

Do you mean the link anchor points change when moving the nodes? That will happen if the link's Dynamic property is enabled, or if AutoRoute is enabled and RoutingOptions.Anchoring is set to Reassign.

3) You can replace anchor points, but at this time links can't detect the change automatically to update their positions. You will have to loop over the node's links and reset the anchor points like this after changing AnchorPattern:

Code
Select All
int orgPoint = link.OriginAnchor;
link.OriginAnchor = -1;
link.OriginAnchor = orgPoint;
int destPoint = link.DestinationAnchor;
link.DestinationAnchor = -1;
link.DestinationAnchor = destPoint; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: AnchorPoints -  ShowAnchors & SnapToAncho
Reply #2 - Dec 19th, 2011 at 12:15pm
Print Post  
Hi !

Thx for the information.

I found a solution to draw custom AnchorPoints:
Code
Select All
	  private void diagram1_DrawAnchorPoint(object sender, DrawAnchorPointEventArgs e)
	  {
		var idx = e.AnchorIndex;

		// ein Pixel sind wieviel Prozent ??
		var PixelProProz = e.Node.Bounds.Height / 100;

		// ein Prozent sind wievile Pixel ??
		var ProzProPixel = 100 / e.Node.Bounds.Height;

		var ins = e.Node.AnchorPattern.Points.Cast<AnchorPoint>().Count(point => point.AllowIncoming);

		// Top offset berechnen
		float topoff = 6;

		var y = topoff + (idx * 9);

		var posDraw = new PointF
		{
		    X = -2 + e.Node.Bounds.X,
		    Y = y + e.Node.Bounds.Y
		};

		var posPoint = new PointF
		{
		    X = -2 * ProzProPixel,
		    Y = (y + 3) * ProzProPixel
		};

		var drawPen = new Pen(Color.Black)
		{
		    Width = 1
		};
		e.Graphics.FillEllipse(Brushes.Red, posDraw.X, posDraw.Y, 6, 6);
		e.Graphics.DrawEllipse(drawPen, posDraw.X, posDraw.Y, 6, 6);

		// AnchorPoint umsetzen
		e.AnchorPattern.Points[idx].X = posPoint.X;
		e.AnchorPattern.Points[idx].Y = posPoint.Y;
		SiAuto.Main.LogVerbose("Point {0} {1}", idx, posPoint);
	  } 



There is only one question left.
Is there a way to realize a snapping and hoovering effect?

Hoover : If the user places the mouse over an Anchorpoint the point gets another color or an additional border. So he will instantly see that he could start / end a link there.
Snapping : If the user draws a link the endpoint automatically catches / snaps the closest AnchorPoint.
« Last Edit: Dec 20th, 2011 at 6:45am by moelski »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AnchorPoints -  ShowAnchors & SnapToAncho
Reply #3 - Dec 20th, 2011 at 7:41am
Print Post  
Hi,

Hover: Handle MouseMove like this:

Code
Select All
private void diagramView_MouseMove(object sender, MouseEventArgs e)
{
	var diagramPos = diagramView.ClientToDoc(e.Location);
	var node = diagram.GetNodeAt(diagramPos, 3) as IconNode;
	if (node != null)
	{
		node.highlightedAnchor = -1;
		for (int idx = 0; idx < node.AnchorPattern.Points.Count; idx++)
		{
			// point position from your code
			float topoff = 6;

			var y = topoff + (idx * 9);
			var posDraw = new PointF
			{
				X = -2 + node.Bounds.X,
				Y = y + node.Bounds.Y
			};

			if (Utilities.Distance(posDraw, diagramPos) < 4)
			{
				node.highlightedAnchor = idx;
				diagram.Invalidate(node.Bounds);
				break;
			}
		}
	}
} 



where highlightedAnchor is a member of your custom node type:

internal int highlightedAnchor = -1;

and you check it in the DrawAnchorPoint handler:

Code
Select All
e.Graphics.FillEllipse((e.Node as IconNode).highlightedAnchor == idx ?
	Brushes.Yellow : Brushes.Red, posDraw.X, posDraw.Y, 6, 6); 



Snapping: links snap to anchor points by default. If you are using auto-routing, make sure RoutingOptions.Anchoring is not set to Ignore.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
moelski
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Feb 28th, 2011
Re: AnchorPoints -  ShowAnchors & SnapToAncho
Reply #4 - Dec 20th, 2011 at 10:10am
Print Post  
Hi Stoyan,

again a great info.

Is there an option to allow only drawing links from Outgoing Anchors?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AnchorPoints -  ShowAnchors & SnapToAncho
Reply #5 - Dec 20th, 2011 at 10:31am
Print Post  
If you mean there should not be a link drawn when the node does not have appropriate anchor points, set AllowUnanchoredLinks to false. If you want to allow drawing a link only when the mouse cursor is directly over a point, you can implement it using a custom Behavior class as shown here -
http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=128273...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint