Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Automatic layout the ContainerNode (Read 8044 times)
sweetdeath
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Automatic layout the ContainerNode
Mar 16th, 2011 at 9:02am
Print Post  
Hi,I have created a set of the ContainerNodes,and I want to layout them automatically.However,it can't work. Below is my codes:
       private void DrawSubContainerTree()
       {
           foreach (ContainerNode parentContainer in conList)
           {
               if (parentContainer == null)
                   continue;
               foreach (ContainerNode childContainer in conList)
               {
                   if (childContainer == null)
                       continue;
                   if (childContainer.Tag.ToString() == parentContainer.Caption)
                   {
                       DiagramLink link = diagram.Factory.CreateDiagramLink(parentContainer, childContainer);
                       childContainer.AttachTo(parentContainer, AttachToNode.BottomCenter);
                       //conLinkList.Add(link);
                       //conLinkID++;
                   }
               }
           }
           container_Rearrange();
       }

       private void container_Rearrange()
       {
           conTreeLayout = new TreeLayout(rootContainer, TreeLayoutType.Centered, false,
               TreeLayoutLinkType.Cascading3, TreeLayoutDirections.TopToBottom,
               levelDistance + 5, nodeDistance + 2, false, new SizeF(1, 1));
           conTreeLayout.Arrange(diagram);
           diagram.ResizeToFitItems(1, true);
       }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #1 - Mar 16th, 2011 at 9:08am
Print Post  
Hi,

By default the layout classes do not modify the content of containers. You will have to use the Arrange(DiagramItemCollection) method to explicitly arrange the children of each container. Here's an example:
http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=127351559...

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #2 - Mar 16th, 2011 at 11:02am
Print Post  
Smileyget it,I will try it.Thanks for your help,Stoyan!
  
Back to top
 
IP Logged
 
sweetdeath
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #3 - Mar 16th, 2011 at 1:55pm
Print Post  
Hi, Stoyan.Thank you for reply.
I am new in mindfusion diagraming. For a set of ContainerNodes, if their children nodes are empty.
For example, code is"container.SubordinateGroup.AttachedNodes==null".
How to automatic them?
I know how to layout the TableNodes automatically,I deeply want to know how to layout the ContainerNodes if their children nodes are empty.
Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #4 - Mar 16th, 2011 at 2:29pm
Print Post  
Hi,

If the sample code crashes with empty containers, insert this condition into the GetContainerItems method before the foreach loop:

if (container.SubordinateGroup == null)
     return items;

Additionally, you should call parentContainer.Add(childContainer) instead of childContainer.AttachTo(parentContainer).

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #5 - Mar 17th, 2011 at 1:46am
Print Post  
Hi,Stoyan. I am sorry to ask your help again,maybe I didn’t explain my problem clearly. Below is my code:

//1.suppose dtProcess is a DataTable, and already contains several data;
//2.loop every row of dtProcess, and every row would generate a ContainerNode;
//3.Rearrange() method want to layout the ContainerNode collection like a tree form;

     private List<ContainerNode> conList = new List<ContainerNode>();
     private TreeLayout conTreeLayout = null;
     private DataTable dtProcess=new DataTable();
     private ContainerNode rootContainer=null;
     int containerID=0;
     .......
     
     private void DrawContainerTree()
       {
           diagram.ClearAll();
           DrawContainerNodes();
           LinksContainers();
           container_Rearrange();
       }
     private void DrawContainerNodes()
       {
           for (int i = 0; i < dtProcess.Rows.Count; i++)
           {
               if (dtProcess.Rows[i]["process"].ToString() != null)
               {
                   ContainerNode conNode = diagram.Factory.CreateContainerNode(xLocation, yLocation, width + 10, height + 10);
                   conNode.Font = new Font("Arial", 4, GraphicsUnit.World);
                   conNode.Caption = dtProcess.Rows[i]["process"].ToString();
                   conNode.Tag = dtProcess.Rows[i]["up_process"].ToString();
                   conNode.Foldable = true;
                   conNode.Folded = true;
                   conNode.AutoShrink = true;
                   conNode.Expandable = true;
                   conNode.AnchorPattern = MindFusion.Diagramming.AnchorPattern.TopInBottomOut;
                   if (conNode.Tag.ToString()=="")
                   {
                       rootContainer = conNode;
                       diagram.Nodes.Add(rootContainer);
                   }
                   //add every ContainerNode to the conList
                   conList.Add(conNode);
                   containerID++;
               }
           }
       }

       private void LinksContainers()
       {
           foreach (ContainerNode upNode in conList)
           {
               if (upNode == null)
                   continue;
               foreach (ContainerNode downNode in conList)
               {
                   if (downNode == null)
                       continue;
                   if (downNode.Tag.ToString() == upNode.Caption)
                   {
                       //if downNode's up_process is upNode, then attach the downNode to the Group of upNode
                       downNode.AttachTo(upNode, AttachToNode.BottomCenter);
                       //link downNode and upNode
                       DiagramLink link = diagram.Factory.CreateDiagramLink(upNode, downNode);
                   }
               }
           }
       }
      
       private void Rearrange()
       {
          conTreeLayout = new TreeLayout(rootContainer, TreeLayoutType.Centered, false,
                       TreeLayoutLinkType.Cascading3, TreeLayoutDirections.TopToBottom,
                       levelDistance + 5, nodeDistance + 2, false, new SizeF(1, 1));

          conTreeLayout.Arrange(diagram);
          diagram.ResizeToFitItems(1, true);
       }
      
       At last: all the ContainerNodes are empty, it just like a Node,contain none of children nodes in it.I want to arrange them automatically
       and being a tree.
       Thans a lot!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #6 - Mar 17th, 2011 at 8:01am
Print Post  
Hi,

How do you need to represent the processes' parent-to-child relation? By drawing links between them, or by containing child process ContainerNodes within parent process ContainerNodes?

It seems your code does both, but that does not make sense. When TreeLayout follows links, it places the links' target nodes on the level below source nodes, so containment would not work here. If you prefer to use containment, you will have to run some layout function recursively for each container. Here's an example:

Code
Select All
private void ArrangeContainers(ContainerNode parent, Layout layout)
{
	DiagramItemCollection children = GetContainerItems(parent);
	foreach (DiagramItem child in children)
	{
		if (child is ContainerNode)
			ArrangeContainers((ContainerNode)child, layout);
	}
	layout.Arrange(diagram, GetContainerItems(parent));
	parent.UpdateBounds(true);
}

private void miLayoutContainersRecursively_Click(object sender, EventArgs e)
{
	LayeredLayout layout = new LayeredLayout();
	layout.MultipleGraphsPlacement = MultipleGraphsPlacement.MinimalArea;

	ArrangeContainers(rootContainer, layout);
} 



where GetContainerItems is from the sample code in the thread linked above. And this is the result from running this on a few hand-drawn nodes:


Also to add a node as a proper child of a container, you should call parentContainer.Add(childNode) instead of using AttachTo.

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #7 - Mar 17th, 2011 at 9:00am
Print Post  
I see your result,but that is not my intention.I send you an e-mail,which include my quetions and intention. My email address is"bailiang908@hotmail.com".I need your help and look forward to your reply
Thanks a lot!
  
Back to top
 
IP Logged
 
sweetdeath
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #8 - Mar 17th, 2011 at 9:14am
Print Post  
Hi,Stoyan
I just want to represent the processes' parent-to-child relation by drawing links between them,and then layout them automatically into a TreeLayout form.
Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #9 - Mar 17th, 2011 at 9:59am
Print Post  
Ok then, if you are using groups so that whole branches in the tree move when the user drags a node, call the AttachTo method after arranging the containers. Containers are just nodes with associated groups (they internally call AttachTo), and since the layout classes skip the containers' groups by default, you will have to call AttachTo after running the layout.

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #10 - Mar 17th, 2011 at 11:02am
Print Post  
Hi,Stoyan.It works perfect!That's what I want!It's very kind of you to help me.
I have another question:For the ContainerNodes Layout,how can I change the direction of TreeLayout
through a funtion? Following is my code:
    private void comboBoxEdit1_SelectedValueChanged(object sender, EventArgs e)
    {
       if (comboBoxEdit1.Text == "TopToBottom")
       {
           TreeLayoutDirections direction = new TreeLayoutDirections();
           direction = TreeLayoutDirections.TopToBottom;
           table_Rearrange(direction);
       }
       else if (comboBoxEdit1.Text == "LeftToRight")
       {
           TreeLayoutDirections direction = new TreeLayoutDirections();
           direction = TreeLayoutDirections.LeftToRight;
           container_Rearrange(direction);
       }
    }
    private void container_Rearrange(TreeLayoutDirections dir)
    {
       TreeLayout containerTreeLayout = new TreeLayout(rootContainer, TreeLayoutType.Centered, false,
           TreeLayoutLinkType.Cascading3, dir, levelDistance, nodeDistance, false, new SizeF(1, 1));

       containerTreeLayout.Arrange(diagram);
       diagram.ResizeToFitItems(1, true);
       AttachContainerToGroup();//call AttachTo after running the layout.
    }
I am trying it,but it can not work.How can change the direction through ComBoxEdit's selected_value_changed event.
Thank you very much. ???
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #11 - Mar 17th, 2011 at 12:08pm
Print Post  
If you need to call the layout method more than once, I suppose you will also need some DetachContainers method that should run before calling TreeLayout.Arrange to remove the groups.

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #12 - Mar 17th, 2011 at 12:57pm
Print Post  
Haha,your idea is great and helps me a lot! Thank you again!
  
Back to top
 
IP Logged
 
sweetdeath
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 16th, 2011
Re: Automatic layout the ContainerNode
Reply #13 - Mar 17th, 2011 at 2:17pm
Print Post  
Hi,Stoyan.I call the AttachTo method after arranging the containers,it works very well.However,when I move or drag one contianer
to a new position, the whole branches belong to it wouldn't move at the same time,just the link is moving disorderly.Futhermore,
other links which are connecting other nodes would disappear. In the TableNode case, this problem does not occur.
Why does this problem happen? Could you help me to solve it? Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Automatic layout the ContainerNode
Reply #14 - Mar 17th, 2011 at 2:29pm
Print Post  
Hi,

Are you sure every node is attached to its parent in the tree? Could you save the diagram to xml and send it to support@mindfusion.eu?

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint