Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) ShapeNode moved within Container (Read 4102 times)
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
ShapeNode moved within Container
Jan 8th, 2009 at 4:53pm
Print Post  
Hi,

I have a problem with a shapeNode contained within a container. I already read http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=121635899... and tried the workaround, but unfortunately I need another one.

The shapeNode should always stay in the bottom-right corner of the container. It can't be moved by the user. It is added to the container this way (where node is a ContainerNode):
Code
Select All
RectangleF nodeBounds = node.Bounds;
Bitmap image = MyProject.Properties.Resources.Image;
ShapeNode btn = this.diagram.Factory.CreateShapeNode(nodeBounds.Right - image.Width, nodeBounds.Bottom - image.Height, image.Width, image.Height);
btn.Transparent = true;
btn.Image = image;
btn.ImageAlign = ImageAlign.Center;
btn.AttachTo(node, AttachToNode.BottomRight);
btn.Locked = true;
btn.Tag = tag;
btn.Obstacle = false;
btn.Constraints.KeepInsideParent = true;    // TODO Change?

if (node.SubordinateGroup != null)
{
    node.SubordinateGroup.AutoDeleteItems = true;
    node.SubordinateGroup.FollowMasterContainment = true;
    node.SubordinateGroup.FollowMasterRotation = true;
} 



It is displayed as I wanted it after creation.
The problem is that when I fold/unfold the container, when an item is added or removed from it or when an item that is contained within the container is moved, the button (ShapeNode) gets moved. It always stays within the container, but never on the bottom-right corner anymore (I believe it then respects ContainerMargin, but I don't want that).

I found a workaround about the fold/unfold problem (I just remove & re-add the shapeNode), but I don't know how to catch that a contained item is moved.

Do you have any idea?

Thanks a lot,
Marie
« Last Edit: Jan 16th, 2009 at 7:04pm by marie »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #1 - Jan 12th, 2009 at 6:01am
Print Post  
Hi Marie,

Our developers implemented ContainerNodes using Group objects, and contained items are stored in the same SubordinateGroup as the nodes attached using the AttachTo method. We'll add some code to distinct between contained and attached nodes, and will send you updated version of the control in a few days.

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #2 - Jan 15th, 2009 at 12:53pm
Print Post  
Please check the version from the PM page, let me know if it works for you.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: ShapeNode moved within Container
Reply #3 - Jan 15th, 2009 at 2:26pm
Print Post  
Hi Stoyan,

Thanks a lot Smiley!

Could you tell me what changed or if there is any documentation about that version somewhere?

Thanks again,
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #4 - Jan 15th, 2009 at 2:37pm
Print Post  
Hi Marie,

If you are asking what's new in v5.2, it only adds the layout classes shown here
http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=123122634...

and a few customer-requested features. If you are asking about AttachTo and containment changes, now ContainerNodes simply make a difference between the two types of child items.

That pre-release build should be safe to use in production, unless you need to use the save/load functions - we haven't finalized the v5.2 file format yet.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: ShapeNode moved within Container
Reply #5 - Jan 15th, 2009 at 3:59pm
Print Post  
Hi Stoyan,

I'm wondering about AttachTo & containment changes. How can I use that functionnality in code? Is there something I need to do or is it just going to display my attached ShapeNode as I want it?

If there is something I need to do, I could find it myself in the documentation, but I don't know where to find it... You said
Quote:
The archive also contains an updated help file for version 2.1.
Where can I find those archives?

Thanks a lot!
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #6 - Jan 15th, 2009 at 4:13pm
Print Post  
You shouldn't do anything other than calling AttachTo the usual way. Now attached items should not increase the container size by adding margins after fold/unfold.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: ShapeNode moved within Container
Reply #7 - Jan 15th, 2009 at 6:36pm
Print Post  
Thanks!!

It works great, except when I combine this with my previous request. If I have this:
Code
Select All
void diagram_ContainerFolded(object sender, NodeEventArgs e)
{
    ContainerNode cont = e.Node as ContainerNode;

    if (cont != null)
    {
        cont.Resize(cont.UnfoldedSize.Width, cont.Bounds.Height);
    }
} 



Then, after the first fold/unfold, the attached ShapeNode is moved outside the ContainerNode's boundaries (to the right). What's more, the container is not resized to its original size. If I move the containerNode, the ShapeNode is moved to where it belongs (but the containerNode is still with a bad size).

To test this, I added a button to the Entities sample project. The action related to this button does:
Code
Select All
private void button2_Click(object sender, EventArgs e)
{
    ContainerNode cont = this.diagram.Factory.CreateContainerNode(10, 10, 100, 50, true);

    RectangleF nodeBounds = cont.Bounds;
    Image image = images.Images[4];
    float x = nodeBounds.Right  - image.Width;
    float y = nodeBounds.Bottom  - image.Height;
    AttachToNode attType = AttachToNode.BottomRight;

    ShapeNode btn = this.diagram.Factory.CreateShapeNode(x, y, image.Width, image.Height);
    btn.Transparent = true;
    btn.Image = image;
    btn.ImageAlign = ImageAlign.Center;
    btn.AttachTo(cont, attType);
    btn.Locked = true;
    btn.Obstacle = false;
    btn.Constraints.KeepInsideParent = true;

    if (cont.SubordinateGroup != null)
    {
        cont.SubordinateGroup.AutoDeleteItems = true;
        cont.SubordinateGroup.FollowMasterContainment = true;
        cont.SubordinateGroup.FollowMasterRotation = true;
    }
} 


After that, you just have to create a comment, fold/unfold it and that's it (you don't have to put anything in it).

Do you know what causes this?
Thanks,
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #8 - Jan 16th, 2009 at 12:46pm
Print Post  
Please use the same link to download a version that fixes the Resize problem, and you should also remove this line:

btn.Constraints.KeepInsideParent = true;

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



Posts: 147
Joined: Nov 11th, 2008
Re: ShapeNode moved within Container
Reply #9 - Jan 16th, 2009 at 3:49pm
Print Post  
Thanks a lot! Cheesy

Just to know, why should I remove the KeepInsideParent line?

Have a great week-end,
Marie
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeNode moved within Container
Reply #10 - Jan 16th, 2009 at 4:55pm
Print Post  
It turned out there isn't enough space to keep the button node inside the folded container, which leads to aligning their top-left corners, which was one of the components of that displacement (apart from the bug with calling Resize from the Folded event handler).

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