Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) custom nodes (Read 9711 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom nodes
Reply #15 - Oct 24th, 2013 at 2:43pm
Print Post  
It seems that happens because you attach the dragged node to the nearby parent container while still moving the child. Then the Bounds assignment in resizeNode leads to calling the child's Start, Update and Complete -Modify methods (called in order to update attached nodes) leading to resetting some interaction fields while child's current UpdateModify still runs.

You should delay calling AttachTo method until interaction ends, i.e. call it from CompleteModify override. Or otherwise avoid setting the Bounds property in resizeNode, but call the SetBounds method with updateGroups argument set to false, to prevent the extraneous update of attached children including currently moved one.

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


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: custom nodes
Reply #16 - Oct 24th, 2013 at 3:17pm
Print Post  
Ah it works. I changed the resize method to

Code
Select All
public void resizeNode(double widthToAdd, double heightToAdd)
        {
            //this.MinimumSize = new Size(Bounds.Width * 2, Bounds.Height);
            if (lastInflatedNode != this)
            {
                if (lastInflatedNode != null)
                    lastInflatedNode.Bounds = lastBounds;

                Rect r = this.Bounds;
                lastBounds = r;
                Rect newBounds = new Rect(Bounds.X, Bounds.Y, Bounds.Width + widthToAdd, Bounds.Height + heightToAdd);
                this.SetBounds(newBounds, false, true);
                lastInflatedNode = this;
                Debug.WriteLine("New Bounds: " + Bounds);
            }
        }
 



But now something else happens. When I move an operator node to the right slot of another operator node, the dragged operator flickers. It moves to another spot and then back to where the mousecursor is and then back to that spot etc. Do you have an idea of what could be causing this?

Thanks in advance!

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom nodes
Reply #17 - Oct 25th, 2013 at 7:34am
Print Post  
If you add some Debug.WriteLines in BROperator.AlignNodeToMe:

Code
Select All
// Calculate the distance of the two points
double dx = targetPoint.X - pointToSnap.X;
double dy = targetPoint.Y - pointToSnap.Y;

// Move the dragged node to position
var childBounds = toAdd.Bounds;
Debug.WriteLine("1: " + childBounds);
childBounds.Offset(dx, dy);
toAdd.SetBounds(childBounds, true, true);
Debug.WriteLine("2: " + childBounds);
AssignNodeToSlot(toAdd, targetPoint); 



they show that you align childBounds to a different position for the same initial rect:

1: 247.5,232.5,50,20
2: 231.5,192.5,50,20

1: 247.5,232.5,50,20
2: 263.5,262.5,50,20

1: 247.5,232.5,50,20
2: 231.5,192.5,50,20

1: 247.5,232.5,50,20
2: 263.5,262.5,50,20

The first Rect shows where the control wants to place the node due to standard move handling, the second one is where you want it aligned.

So check all variables and fields you are using when calculating dx and dy, you might have to update some of them after each alignment.

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


I Love MindFusion!

Posts: 62
Joined: Oct 3rd, 2013
Re: custom nodes
Reply #18 - Oct 25th, 2013 at 12:13pm
Print Post  
Ahh, I got it.

I changed the point of the child node to calculate the closest connectionpoint with in AlignNodeToMe() from:
Code
Select All
Point pointToSnap = toAdd.connectionPoint;
 


to:
Code
Select All
var childBounds = toAdd.Bounds;

double pX = childBounds.X + 25;
double pY = childBounds.Y;
Point pointToSnap = new Point(pX, pY);
 



But the way it's calculated is exactly the same. I only do it in the method Draw(). Perhaps it isn't updated when Draw() is called. In any case, it works.

Thanks Stoyan!

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom nodes
Reply #19 - Oct 25th, 2013 at 1:17pm
Print Post  
Perhaps the problem is that Draw is not called between two UpdateModify calls due to WPF's asynchronous layout and drawing model, so you shouldn't rely on values cached in Draw. Also I suspect WPF repeats the last system drag-and-drop event when you move an UIElement under the mouse pointer, it looks as if you get these events in pairs because of the SetBounds calls.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint