Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Query regarding attached node. (Read 2975 times)
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Query regarding attached node.
Mar 18th, 2009 at 2:50pm
Print Post  
Hi,

I want to know is there any way by which i can attach a rectangle shaped node to a decision shaped node such a way that the rectangle shaped node is aligned parallel to one of the edge of the decision shaped node.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query regarding attached node.
Reply #1 - Mar 18th, 2009 at 3:10pm
Print Post  
Hi,

You'll have to do some math to find the slope of the decision's edge, and then set the rectangle's RotationAngle accordingly. If the decision's Width and Height are always the same (e.g. if you Constraints.KeepRatio), RotationgAngle = 45 should do.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query regarding attached node.
Reply #2 - Mar 19th, 2009 at 9:07am
Print Post  
Hi Stoyan,

I tried your suggestion and following is the code I used to accomplish the desired task :

ShapeNode mainNode = new ShapeNode(diagram);
           mainNode = diagram.Factory.CreateShapeNode(
                       new Point(200, -80), new Size(45, 45));
           
           mainNode.Shape = Shapes.Decision;
           ShapeNode labelNode = new ShapeNode(diagram);
           labelNode = diagram.Factory.CreateShapeNode(
                   mainNode.Bounds.X - (mainNode.Bounds.Width/2) , mainNode.Bounds.Bottom ,
                   15, 30);
           labelNode.Shape = Shapes.Rectangle;
           labelNode.Text = "Hi";

           labelNode.Move(mainNode.Bounds.X + mainNode.Bounds.Width/2 , mainNode.Bounds.Bottom );
           
           labelNode.AttachTo(mainNode, AttachToNode.BottomCenter);
           labelNode.Locked = true;
labelNode.RotationAngle = 45;
           diagram.Nodes.Add(mainNode);

  
Back to top
 
IP Logged
 
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query regarding attached node.
Reply #3 - Mar 19th, 2009 at 10:36am
Print Post  
Hi Stoyan,

I tried your suggestion and following is the code I used to accomplish the desired task :

ShapeNode mainNode = new ShapeNode(diagram);
mainNode = diagram.Factory.CreateShapeNode(
new Point(200, -80), new Size(45, 45));

mainNode.Shape = Shapes.Decision;
ShapeNode labelNode = new ShapeNode(diagram);
labelNode = diagram.Factory.CreateShapeNode(
mainNode.Bounds.X - (mainNode.Bounds.Width/2) , mainNode.Bounds.Bottom ,
15, 30);
labelNode.Shape = Shapes.Rectangle;
labelNode.Text = "Hi";

labelNode.Move(mainNode.Bounds.X + mainNode.Bounds.Width/2 , mainNode.Bounds.Bottom );

labelNode.AttachTo(mainNode, AttachToNode.BottomCenter);
labelNode.Locked = true;
labelNode.RotationAngle = 45;
diagram.Nodes.Add(mainNode);

Where mainNode is for the node on which the node has to be attached and labelNode is for the node that has to be attached. But this code is not working fine.

Any suggestions what I am doing wrong.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query regarding attached node.
Reply #4 - Mar 19th, 2009 at 4:29pm
Print Post  
If your problem is aligning the label node sides with the decision node sides, try this:

Code
Select All
Rect r = mainNode.Bounds;
Point nodeCenter = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
Vector labelOffset = new Vector(r.Width / 2, r.Width / 2);
Point labelCenter = nodeCenter + labelOffset;
labelNode.Move(
labelCenter.X - labelNode.Bounds.Width / 2,
labelCenter.Y - labelNode.Bounds.Height / 2);
 



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