Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Ways to select and drag ShapeNode (Read 3150 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Ways to select and drag ShapeNode
Aug 31st, 2020 at 1:29pm
Print Post  
Hi, Slavcho Smiley

When multiple ShapeNodes intersect or overlap, I want to click on the edge of any ShapeNode to switch the mouse focus between them at will, so I put this piece of implementation code:

base.OnPreviewMouseMove(e);

if (diagram.Interaction == null)
{
    var point = e.GetPosition(diagram.DocumentPlane);
    var node = NearestRect(point);
    if (node ​​!= null)
    {
        node.ZTop(false);
        diagram.Selection.Change(node);
    }
}

Is placed in the OnPreviewMouseDown event, but the effect is unexpected. The result is that the mouse left click to select it in the area near the closest ShapeNode, not on the edge of this ShapeNode, and the left mouse button cannot click on the center handle of the outer ShapeNode to drag it, because As soon as the left mouse button clicks on the position of the center handle of the ShapeNoder, it is mistaken for the ShapeNode that is closest to it, and the ShapeNode inside is selected. How should I change it so that the left mouse button can click on the edge of any ShapeNode to switch the mouse focus at will, and it will not affect the dragging by pressing the center handle of the selected ShapeNode after selection.

Best regards.
  

8_31_8.png ( 493 KB | 107 Downloads )
8_31_8.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Ways to select and drag ShapeNode
Reply #1 - Sep 1st, 2020 at 6:13am
Print Post  
Hi,

Move this to MouseUp handler then -

Code
Select All
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
	base.OnPreviewMouseLeftButtonUp(e);

	if (diagram.Interaction == null)
	{
		var point = e.GetPosition(diagram.DocumentPlane);
		var node = NearestRect(point);
		if (node != null)
		{
			node.ZTop(false);
			diagram.Selection.Change(node);
		}
	}
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to select and drag ShapeNode
Reply #2 - Sep 1st, 2020 at 7:13am
Print Post  
Thanks, Slavcho Smiley

double DistToRect(Point point, Rect rect)
{
var v = new[]
{
new Point(rect.Left, rect.Top),
new Point(rect.Right, rect.Top),
new Point(rect.Right, rect.Bottom),
new Point(rect.Left, rect.Bottom),
};
double minDist = double.MaxValue;
for (var i = 0; i < 4; i++)
{
var v1 = v[i];
var v2 = v[(i + 1) % 4];
var dist = Utilities.DistToLineSegment(point, v1, v2);
if (dist < minDist)
minDist = dist;
}
return minDist;
}

DiagramNode NearestRect(Point point)
{
DiagramNode nearest = null;
double minDist = double.MaxValue;
foreach (var node in diagram.Nodes)
{
var dist = DistToRect(point, node.Bounds);
if (dist < minDist)
{
minDist = dist;
nearest = node;
}
}
return nearest;
}

Currently I need to implement this function: the left mouse button can only click on the edge of the ShapeNode to select it. How to modify?
When multiple ShapeNodes intersect or overlap, the center handle of the selected ShapeNode will not be affected by another ShapeNode close to it and cannot be dragged. How can I solve it?

Best regards.
  

9_1.png ( 356 KB | 105 Downloads )
9_1.png
9_1_0.png ( 130 KB | 102 Downloads )
9_1_0.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Ways to select and drag ShapeNode
Reply #3 - Sep 1st, 2020 at 11:49am
Print Post  
Hi,

You could return a result from NearestRect only if dist is very small - e.g. 2 or 3 points, otherwise return null. Then the selection code should run only for nodes clicked on border or very close to it.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to select and drag ShapeNode
Reply #4 - Sep 1st, 2020 at 12:44pm
Print Post  
Thanks, Slavcho Smiley

Yes, I initialized the value of minDist to 2. I can just click the border of the ShapeNode to select it. But some other unexpected phenomena appeared. I was inside the diagram but far away from the ShapeNode, which is the position of the red circle in the figure below. I clicked with the left mouse button several times and the ShapeNode disappeared in the diagram. After I clicked the border area of ​​the ShapeNode again Will be displayed, how can this phenomenon be eliminated? I don't want ShapeNode to disappear into the diagram without understanding. There is another phenomenon. Sometimes when I click the border of the ShapeNode with the left mouse button, it is selected when it is pressed, and then the ShapeNode is not selected after the left mouse button is released. Try a few more times to select it. This Phenomenon should also be eliminated. What changes do I need to make?

Best regards.
  

9_1_5.png ( 473 KB | 106 Downloads )
9_1_5.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Ways to select and drag ShapeNode
Reply #5 - Sep 1st, 2020 at 1:39pm
Print Post  
Is that electronics image from your screenshots shown inside ShapeNode? In such case you'll have to add some checks for that node to make sure the mouse-down handler doesn't select and move it to top of Z order, but only do that for the rectangles.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to select and drag ShapeNode
Reply #6 - Sep 1st, 2020 at 1:56pm
Print Post  
Yes, you are right. Smiley
The electronic image in the screenshot is displayed inside the ShapeNode. I understand what you mean, thank you very much, Slavcho. Could you please tell me how to use code to implement the inspection operation? I want to learn from your ideas.

Best regards.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Ways to select and drag ShapeNode
Reply #7 - Sep 2nd, 2020 at 5:42am
Print Post  
For example set node.Locked = true for that node so users cannot select and resize it interactively. Then add a continue statement to foreach loop in NearestRect:

Code
Select All
if (node.Locked)
  continue; 



Then the code calling NearestRect will not receive the image node and bring it to top of Z order.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to select and drag ShapeNode
Reply #8 - Sep 7th, 2020 at 6:31am
Print Post  
Thank you very much! Slavcho Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint