Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Multiple AttachTo not working (Read 2200 times)
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Multiple AttachTo not working
Oct 25th, 2012 at 8:38am
Print Post  
Code can be seen below. When both lines of code are used at same time, second one works. If second is commented out, first one does the job as required. Why?
Code
Select All
 // attach current shapenode to previous shapenode
                    tempShape.AttachTo(prevShapeNode, AttachToNode.BottomCenter);

                    // attach previous shapenode to current shapenode
                    prevShapeNode.AttachTo(tempShape, AttachToNode.TopCenter);
 

  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Multiple AttachTo not working
Reply #1 - Oct 25th, 2012 at 9:21am
Print Post  
I temporarily solved this by restricting handles so that only BottomCenter would be enabled in each.

This is inefficient.

Code
Select All
 // restricting lanes/stages handles so that only height can be adjusted by user.
                        // if first stage encountered: allow only bottom center handle
                        if (i == 0)
                        {
                            tempShape.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;

                        }
                        // if last stage encountered: allow no handle
                        if (i == (extVarStages-1))
                        {
                            tempShape.EnabledHandles = AdjustmentHandles.None;
                        }
                        // for all other stages allow only bottom center handle
                        else
                        {
                            tempShape.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;
                            //tempShape.EnabledHandles = AdjustmentHandles.ResizeTopCenter | AdjustmentHandles.ResizeBottomCenter;
                        } 

  

Capture_024.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple AttachTo not working
Reply #2 - Oct 25th, 2012 at 4:15pm
Print Post  
This should work for only two nodes. However, an attached node can have only one master node, so doing that from a loop for all 'lane' nodes will cause a second AttachTo for a node to detach from the previous master. If you need to move lanes  when one of them is resized, you can do that from the NodeModified event handler instead - starting the loop from the modified nodes' index + 1 and moving each next lane to the bottom of previous one.

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


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Multiple AttachTo not working
Reply #3 - Oct 30th, 2012 at 7:55pm
Print Post  
Solved

In page_load ... !ispostback


Code
Select All
// Horizontal Lanes: create lanes based on stages

            // iterate while 'extVarStages' is reached
            for (int i = 0; i < extVarStages; i++)
            {
                // defining y-axis with 'rectangleHeight' predefined variable
                // and multiplying it by the next lane to be created by sequence.
                // e.g if height is 2 then second shape would be at 2*2=4, 3rd would be 2*3=6
                // this would ensure they are placed sequentially one after another.
                ShapeNode tempShape = diagram.Factory.CreateShapeNode(0, rectangleHeight * i, diagramWidth, rectangleHeight);

                // set type of shape to rectangle to resemble a lane
                tempShape.Shape = Shapes.Rectangle;

                // name the shape concatenating the number of stage at end
                tempShape.Text = "Stage " + (Convert.ToInt32(i) + 1).ToString();

                // set Id of shape to that later on if for instance one lane is resized, another can be refered to for adjustment.
                // call the Id same as the text of the shape.
                tempShape.Id = "Stage " + (Convert.ToInt32(i) + 1).ToString();

                // set ZIndex so that the lane stays at bottom at all times below other shapes on diagramView.
                tempShape.ZBottom();

                // set color of shape
                tempShape.Brush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.GreenYellow);

                // disable self loops on lanes //TEST

                //// prevent links on lanes/stages
                //tempShape.AllowIncomingLinks = false;
                //tempShape.AllowOutgoingLinks = false;


                // attaching to previous stage and restricting handles if first or last stage
                // check if shape is greater than 0 (means greater than Stage 1)

                if (i > 0)
                {

                    // get stage number of current stage (add by 1 as stages start from 1)
                    int currStageNum = i + 1;

                    //Shape prevStage = Shape.FromId("Stage " + (currStageNum - 1)) as Shape;

                    //ShapeNode pNode = ShapeNode.f

                    // reference previous shapenode
                    ShapeNode prevShapeNode = diagram.FindNodeById("Stage " + (currStageNum - 1)) as ShapeNode;

                    // attach current shapenode to previous shapenode
                    tempShape.AttachTo(prevShapeNode, AttachToNode.BottomCenter); // TEMP COMMENTED!!!

                    // attach previous shapenode to current shapenode
                    //prevShapeNode.AttachTo(tempShape, AttachToNode.TopCenter);


                }

                // restricting lanes/stages handles so that only height can be adjusted by user.

                // if first stage encountered: allow only bottom center handle
                if (i == 0)
                {
                    //tempShape.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;  // TEMP COMMENTED!!!
                    tempShape.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;

                }
                // if last stage encountered: allow top center handle
                else if (i == (extVarStages - 1))
                {
                    tempShape.EnabledHandles = AdjustmentHandles.ResizeTopCenter;
                }
                // for all other stages allow only bottom center handle and top center handle
                else
                {
                    tempShape.EnabledHandles = AdjustmentHandles.ResizeBottomCenter | AdjustmentHandles.ResizeTopCenter;
                    //tempShape.EnabledHandles = AdjustmentHandles.ResizeTopCenter | AdjustmentHandles.ResizeBottomCenter;
                }
            } 

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