Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Attach to link (Read 14611 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Attach to link
Sep 11th, 2015 at 9:23am
Print Post  
Hi,
I have a problem, i want to attach a node to a link and I use this code:
int startposition = l.getOriginIndex();
if(nID >= 1){
s.attachTo(l, AttachToLink.Segment, startposition);
}
but it doesn't work, it gave me null pointer exception.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attach to link
Reply #1 - Sep 11th, 2015 at 10:13am
Print Post  
Hi,

Check if both s and l are different from null. Also getOriginIndex doesn't return anything related to link segment indices, which attachTo expects when using AttachToLink.Segment option; pass 0 instead if you want to attach the node to first segment.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #2 - Sep 11th, 2015 at 10:14am
Print Post  
Ok, thank you very much...i'll try
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #3 - Sep 11th, 2015 at 1:04pm
Print Post  
Sorry, I still have a problem with attachTo, I want to attach a node in the middle of a link...now it doesn't give me null pointer exception but it doesn't show the node, here is the code:
ShapeNode addedNode = new ShapeNode(diagram);
                            addedNode.setShape(Shape.fromId("Ellipse"));
addedNode.resize(2, 2);
addedNode.attachTo(l, AttachToLink.Point, 0); diagram.add(addedNode);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attach to link
Reply #4 - Sep 11th, 2015 at 1:47pm
Print Post  
The node's probably at default 0,0 position. You should also move it to where you want it, e.g. at mid-point of a segment, before calling attachTo. attachTo does not move the node but only records its current offset from specified point and maintains that offset when the master item is modified later. E.g. that also lets you keep attached nodes at some distance above or below link segments or points to serve as labels.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #5 - Sep 11th, 2015 at 2:23pm
Print Post  
Ok, thank you but the problem is that I have something like the first picture and i want to add a node in order to obtain something like the second picture
  

example_005.png ( 4 KB | 135 Downloads )
example_005.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attach to link
Reply #6 - Sep 14th, 2015 at 9:02am
Print Post  
If you are asking how to move addedNode to the middle point of link, it should look something like this:

Code
Select All
PointF pt1 = l.getControlPoints().get(0);
PointF pt2 = l.getControlPoints().get(1);
PointF m = new PointF((pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2));
m.x -= addedNode.getBounds().width() / 2;
m.y -= addedNode.getBounds().height() / 2;
addedNode.moveTo(m.x, m.y); 



assuming that link has a single straight-line segment.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #7 - Sep 14th, 2015 at 12:41pm
Print Post  
Ok, thank you, I'll try Smiley
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #8 - Sep 29th, 2015 at 2:54pm
Print Post  
Hi, I used the code you suggested to me above and it works but then if I add another ellipse apart from that drawing it blocks. While if I add rectangle of decision it doesn't block.
It gave me this message:
09-29 16:54:01.143  17399-17399/com.example.silvia.er I/ViewRootImpl﹕ Reporting drop result: false
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #9 - Sep 29th, 2015 at 3:02pm
Print Post  
Sorry, I solved. Thank you anyway Smiley
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #10 - Oct 6th, 2015 at 10:01am
Print Post  
Hi, is there a way to create a link like the red one of the attachment?
  

example3.png ( 1 KB | 156 Downloads )
example3.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attach to link
Reply #11 - Oct 6th, 2015 at 12:13pm
Print Post  
Hi,

Assuming it connects small nodes attached to the other links, set its Shape property to LinkShape.Cascading value and SegmentCount to 2 after creating it. Then the link's segments should stay horizontal and vertical when its ends are moved.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #12 - Oct 7th, 2015 at 8:15am
Print Post  
Hi, is there a way to know to which side of the node a link is attached?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attach to link
Reply #13 - Oct 7th, 2015 at 10:32am
Print Post  
Hi,

Call the following method with node.Bounds and respective end point of link as arguments:

Code
Select All
enum RectSide
{
	LEFT {
		float dist(PointF point, RectF rect) { return Math.abs(point.x - rect.left); }
	},
	TOP {
		float dist(PointF point, RectF rect) { return Math.abs(point.y - rect.top); }
	},
	RIGHT {
		float dist(PointF point, RectF rect) { return Math.abs(point.x - rect.right); }
	},
	BOTTOM {
		float dist(PointF point, RectF rect) { return Math.abs(point.y - rect.bottom); }
	};

	static RectSide fromPoint(PointF point, RectF rect)
	{
		float minDist = Float.MAX_VALUE;
		RectSide closest = LEFT;

		for (RectSide side: values())
		{
			float dist = side.dist(point, rect);
			if (dist < minDist)
			{
				minDist = dist;
				closest = side;
			}
		}

		return closest;
	}

	abstract float dist(PointF point, RectF rect);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Attach to link
Reply #14 - Oct 7th, 2015 at 2:19pm
Print Post  
Hi, I create a picture like the first two of the attachments, rect1 and rect2, using LinkShape.Cascading and setting as orientation vertical and it works in the first two cases but it doesn't work in case rect3 and rect4, how can I solve this problem? How can I distinguish if decision is above, below, right or left with respect to the rectangle?
  

Untitled_017.png ( 8 KB | 161 Downloads )
Untitled_017.png
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint