Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Updating X and Y Coordinates of child nodes (Read 3334 times)
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Updating X and Y Coordinates of child nodes
Nov 28th, 2013 at 4:16pm
Print Post  

Hi Stoyan,

During some testing we noticed that the X- and Y- coordinates of the child nodes aren't set properly, which is having some weird side-effects to the nesting of our new operator nodes. At first we didn't notice this because visually, nothing seemed to be wrong.

For example:

If my first node would have the following Bounds: 232.5, 172.5, 100, 100 and my second node, which is nested in the first node, would have the following Bounds: 252.5, 232.5, 100, 100 nothing seems to be wrong. Now if i would move the node with the nested node, lets say, to the upper part of the diagram field, my bounds would look something like this: 1st node: 232.5, 67.5, 100, 100 and 2nd: 252.5, 232.5, 100, 100. This would indicate that the nested node is still in its old location, according to its coordinates, but visually it isn't.

We tried fixing the problem by overriding the MindFusion CompleteModify() method, which in turn will call our own method, called UpdateModelBounds() and eventually calling the method in the class NodeControl called UpdateModelBoundsOnMove. The code from the child-class will handle the node specific updates.

Code in Super:
Code
Select All
 protected override void CompleteModify(Point end, InteractionState ist)
        {
            UpdateModelBounds();
            AlignToNearestPoint(end, ist);
            if (NodeToAttachTo != null)
            {
                AttachNodes(NodeToAttachTo, this);
                NodeToAttachTo = null;
            }
        }

        public virtual void UpdateModelBounds()
        {
            if (this.Tag != null)
            {
                BRNodeControl.UpdateModelBoundsOnMove((int)this.Tag, Bounds);
                if (ConnectedNode != null)
                    BRNodeControl.UpdateModelBoundsOnMove((int)ConnectedNode.Tag, ConnectedNode.Bounds);
            }
        }
 



Code in NodeControl (Controllerclass)

Code
Select All
        public static void UpdateModelBoundsOnMove(int movedNodeID, Rect newBounds)
        {
            BRNodeModel movedNodeModel = models.FirstOrDefault(x => (int)x.Tag == movedNodeID);

            if (movedNodeModel != null)
            {
                movedNodeModel.SetBounds(newBounds, false, true);
            }
            else
                throw new Exception("Unable to update the bounds of the model!");
        }  



Code in child class BRTryCatchNode    (the E shape)

Code
Select All
        public override void UpdateModelBounds()
        {
            base.UpdateModelBounds();

            if (this.tryConnectedNode != null)
                BRNodeControl.UpdateModelBoundsOnMove((int)tryConnectedNode.Tag, tryConnectedNode.Bounds);
            if (this.catchConnectedNode != null)
                BRNodeControl.UpdateModelBoundsOnMove((int)catchConnectedNode.Tag, catchConnectedNode.Bounds);
        }
  



This seems to work for 1 node with 1 nested node, but if i would nest a new node in the 1st nested node, it doesn't get updated.

Could you give some words of advice?


Thanks in advance.  Cool

Greets,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Updating X and Y Coordinates of child nodes
Reply #1 - Nov 29th, 2013 at 12:11pm
Print Post  
Hi,

What kind of objects do you keep in that models collection? Are you trying to synchronize some model object coordinates with the  DiagramNode.Bounds coordinates of actual objects in the diagram? If a child node is displayed at the correct position, there's no way its coordinates are wrong unless you are overriding its Draw method in a strange way, so check your synchronization code if some model object you create for the node shows wrong coordinates.

Stoyan
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Updating X and Y Coordinates of child nodes
Reply #2 - Dec 2nd, 2013 at 8:55am
Print Post  
Hi,

Yes, last week we changed the design of the modeler to fit some sort of MVC pattern. Now we have node classes, a controller and a model class of each node class.

The node classes only handle the drawing of the nodes and get their values from the model classes. If, for example the node needs to be re-sized, the node class will send a request to the controller class, and the controller class will call the model classes which in turn will do the calculations. Basically, the model classes handle all the logic. 

Greets,

Sander
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Updating X and Y Coordinates of child nodes
Reply #3 - Dec 2nd, 2013 at 10:36am
Print Post  
Good morning Stoyan,

Me and Vincent tried out your suggestion, and debugged the draw method and model classes, but we cant seem to find the problem Sad. Could you maybe take a look? In the attachment you can find the modeler project. You can start it up using the bootstrap.

Test-case which will show the problem:

1) Drag 4 Operator nodes on to the diagram field.
2) Drag Operator node 2 into operator node 1's left slot. Drag operator 1 & 2 into operator node 3's left slot. Then drag the nested operator nodes of 1, 2 and 3 in the left slot of the 4th Operator node.

Thanks in advance, we would really appreciate it.

Greets,

Sander
  

Project.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Updating X and Y Coordinates of child nodes
Reply #4 - Dec 2nd, 2013 at 1:43pm
Print Post  
Hi,

Try synchronizing your model's coordinates from DiagramNode.OnUpdateBounds override instead of UpdateModify. UpdateModify is called only for the selected node you are actually dragging, and its child nodes' models remain with their old coordinates after you move the parent node:

Code
Select All
override void OnUpdateBounds()
{
    base.OnUpdateBounds();
    model.SetBounds(...);
} 



Alternatively, you might try calling models' AttachTo methods in parallel to actual nodes AttachTo calls, then calling SetBounds(... updateGroups = true ...) on a parent node should update the children too. However overriding OnUpdateBounds is better IMO.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Updating X and Y Coordinates of child nodes
Reply #5 - Dec 2nd, 2013 at 2:03pm
Print Post  
Hi Stoyan,

Wow, it works like a charm. Been busy with this 'bitch' for quite some time. What a relief. Thanks a billion!

Greets,

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