Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Creating child Shapes within a parent Shape (Read 3685 times)
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Creating child Shapes within a parent Shape
Apr 2nd, 2013 at 12:24am
Print Post  
Hi,

I have attached a sample screenshot of what I am looking to do.
From the documentation, it would appear that I should perhaps be looking at a ContainerNode.  Is this correct?  Am I on the right path?

The main shape (a task) can have zero or more of the child shapes illustrated in the bottom right corner.  I am using ImageMap and the main shape and the child shapes must respond to a NodeClick as well as support a tooltip.  The shapes will all be produced programmatically on code behind.

I searched the latest beta 5 samples for ContainerNode and came up with nothing, and the documentation really doesn't provide a "cookbook" approach - it's more of a reference guide.

Anyway, can you either provide me with an overall approach, or (as you have in the past), some code snippets that would get me going.

We're looking at taking our current diagrams to a new level and this capability will certainly help us out a lot.

Thanks in advance.

Jim
  

Sample_Composite_Shape.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Creating child Shapes within a parent Shape
Reply #1 - Apr 2nd, 2013 at 12:10pm
Print Post  
Hi,

Use regular ShapeNodes both for the main and child shapes, and attach children to the main shape by calling their AttachTo method. Set ShapeNode.Transparent to hide the child nodes' borders and make only their image visible. You will be able to access child's main shape via the MasterGroup.MainItem property.

Drawing the icons could also be done with some custom drawing, but you will need separate nodes to get support for click events and tooltips.

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


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Creating child Shapes within a parent Shape
Reply #2 - Apr 2nd, 2013 at 8:59pm
Print Post  
Hi,

Thanks for the tips.
I am having 2 challenges.
If I use AttachTo while I am creating the shapes, I get the result shown in the attached screenshot.
The 3 blue circles should be located at the BottomRight of the shapes to their left.

If I wait until after I have called the "arrange" method, I call the following functions:

Code
Select All
protected void getAnnotations(Diagram diagram)
    {
        Factory factory = diagram.Factory;
        DiagramNodeCollection allNodes = diagram.Nodes;
        foreach (ShapeNode node in allNodes)
        {
            if (node.Shape == Shapes.RoundRect) // A task shape
            {
                // Attach an annotation node - POC
                ShapeNode annotationNode = factory.CreateShapeNode(0, 0, 3, 3, Shapes.Ellipse);
                MindFusion.Drawing.SolidBrush annotationShapeFill = new MindFusion.Drawing.SolidBrush(Color.Navy);
                annotationNode.Brush = annotationShapeFill;
                annotationNode.Tag = "annotation";
                annotationNode.ToolTip = "This is an annotation";
                //annotationNode.Transparent = true;
                AttachToParent(diagram, annotationNode, node.Id);
            }
        }
    }

    protected void AttachToParent(Diagram diagram, ShapeNode childNode, Object parentID)
    {
        DiagramNode parent = diagram.FindNodeById(parentID);
        childNode.AttachTo(parent, AttachToNode.BottomRight);
    } 



This results in the following exception:

"Collection was modified; enumeration operation may not execute."

Any suggestions as to how to proceed?  When exactly should I be executing the AttachTo method?

Thanks

Jim
  

Netdiagram_-_AttachTo_Issue_Screenshot_-_Before_Arrange.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Creating child Shapes within a parent Shape
Reply #3 - Apr 3rd, 2013 at 7:37am
Print Post  
Hi,

If you add the annotation nodes before applying a layout algorithm, either set annotationNode.IgnoreLayout = true, or run the layout method with KeepGroupLayout enabled.

You cannot modify a collection while it's being iterated with a foreach statement. You could either iterate over its clone, or use an integer counter running until the original Nodes.Count value.

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


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Creating child Shapes within a parent Shape
Reply #4 - Apr 3rd, 2013 at 7:53pm
Print Post  
Hi,

Great advice.  I've made some progress, but am still having challenges.

It seems that regardless of the AttachToNode setting, the shape is placed in the TopLeft of the master shape.  See attached screenshot.

I tried both IgnoreLayout and KeepGroupLayout and they work as far as ensuring that the annotation shape "sticks" with the parent, but I can't get it anywhere other than the top left.

I had some other code after the arrange method, but I disabled all of that and the problem persists.

Any suggestions.

Thanks again.

Jim
  

Netdiagram_-_AttachTo_Issue_-_03Apr2013.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Creating child Shapes within a parent Shape
Reply #5 - Apr 4th, 2013 at 8:26am
Print Post  
Hi,

Have you set the child node's Bounds to the position shown in your first image relative to the main node? AttachTo does not actually move the child node to the specified corner. It retains the node's initial position, and only stores the offset vector from the child to the corner, so that when you resize the main node, the children stay anchored to the respective corner. You will have to set the children' Bounds or call their Move method to align them to the main node's bottom right corner before attaching, e.g.:

Code
Select All
child.Move(main.Bounds.Right - child.Bounds.Width, main.Bounds.Bottom - child.Bounds.Height);
child.AttachTo(main, ...); 



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


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Creating child Shapes within a parent Shape
Reply #6 - Apr 5th, 2013 at 7:56pm
Print Post  
Stoyan,

This worked great.
Thanks for the advice and code.

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