Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Selecting diagram bounds and not selecting nodes on it! (Read 3061 times)
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Selecting diagram bounds and not selecting nodes on it!
May 12th, 2021 at 11:24pm
Print Post  
I am trying to implement zooming in on the diagram using Shift key continuously pressed and mouse drag (mouse dragged with left key pressed, and released, to zoom into selected area).
Here when we keep Shift pressed i want only the blue selection box to appear, and None of the nodes on the diagram should get selected and it should also Not allow link creation at this time.

I tried:
..
diagram.KeyDown += OnDiagramKeyDown;
diagram.KeyUp += OnDiagramKeyUp;
diagram.MouseUp += OnMouseUp;
..

void OnDiagramKeyDown(object sender..
{
if (Keyboard.Modifiers == ModifierKeys.Shift)
{
shiftPressed = true;
diagram.Behavior = Behavior.SelectOnly; // ! doesn't help.
}
}

void OnDiagramKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
{
isShiftPressed = false;
diagram.Behavior = Behavior.DrawLinks;
}
}


private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (isShiftPressed)
diagram.ZoomToRect(diagram.Selection.Bounds, true);
}

The zooming is fine but, even though the diagram Behavior is set to 'SelectOnly' the nodes also gets selected, that i am not looking for. Huh . Any help is appreciated. Thanks a lot.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #1 - May 13th, 2021 at 10:37am
Print Post  
Hi,

Note that changing Behavior values clears selection too. You can avoid it along with item selection like this -

Code
Select All
diagram.ModifierKeyActions.Shift = ModifierKeyAction.Select;

bool isShiftPressed = false;
Rect zoomToRect = new Rect();

void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	isShiftPressed = Keyboard.Modifiers == ModifierKeys.Shift;
}

void OnDiagramKeyUp(object sender, KeyEventArgs e)
{
	if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
		isShiftPressed = false;
}

void OnMouseUp(object sender, MouseButtonEventArgs e)
{
	if (isShiftPressed)
		diagram.ZoomToRect(zoomToRect, true);
}

void OnNodeSelecting(object sender, NodeValidationEventArgs e)
{
	e.Cancel = isShiftPressed;
	zoomToRect = diagram.Selection.Bounds;
}

void OnLinkSelecting(object sender, LinkValidationEventArgs e)
{
	e.Cancel = isShiftPressed;
	zoomToRect = diagram.Selection.Bounds;
} 



You could also try adapting the ZoomTool code here from our WinForms API to WPF -
https://mindfusion.eu/Forum/YaBB.pl?num=1290792836/1#1

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #2 - May 13th, 2021 at 3:28pm
Print Post  
Thank you , that did the trick.
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #3 - May 13th, 2021 at 7:11pm
Print Post  
One more question, if you don't mind.
While testing I noticed, when i use ZoomToRect(diagram.Selection.Bounds) , while zooming it captures all selected items.

(Related issue: https://mindfusion.eu/Forum/YaBB.pl?num=1259167870)

What can i do to zoom only to the selection blue box, and selection should come to center of the diagram screen!?
Thanks again.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #4 - May 14th, 2021 at 5:54am
Print Post  
That's why using "zoomToRect" in code above, I guess you have omitted that part? Selection.Bounds matches the lasso coordinates while it's being drawn, i.e. during validation events like the xxSelecting ones, but it's set to the union of selected nodes' bounds when you finish drawing. This will be more apparent if you change Selection.Style to Frame.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #5 - May 14th, 2021 at 4:09pm
Print Post  
Thanks.
I have used diagram.Selection.Bounds like this:

...
private void OnMouseUp(object sender, MouseButtonEventArgs e){
if (isShiftPressed)
diagram.ZoomToRect(diagram.Selection.Bounds, true); // doesn't work on selection area
}

The above doesn't zoom the selected blue box. For example, if there is a link (that stretches end to end) and a node under the selection, then the diagram just zooms slightly enough to accommodate the link and node.


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #6 - May 17th, 2021 at 6:02am
Print Post  
So save the Selection.Bounds value reported during Selecting event handlers, as shown with the 'zoomToRect'  field in our code above, and it should zoom as expected. Alternatively use a temporary node with dashed border and transparent fill for drawing the lasso, and DrawNodes behavior instead of SelectOnly.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #7 - May 17th, 2021 at 6:57am
Print Post  
Our developer has added a built-in zoom behavior here -
https://mindfusion.eu/_beta/wpfdiag363.zip

Code
Select All
void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (Keyboard.Modifiers == ModifierKeys.Shift)
		diagram.Behavior = Behavior.Zoom;
} 



You can customize zoom-selection's appearance from new InitializeLasso event handler -

Code
Select All
void OnInitializeLasso(object sender, SelectionEventArgs e)
{
	e.Selection.Stroke = Brushes.Red;
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #8 - May 18th, 2021 at 12:37am
Print Post  
Thanks for the reply & updates.  Smiley
I couldn't verify it now; currently my organization is using version 3.6.1.450 dll's. So, if these are part of your next release cycle, I can use it then!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Selecting diagram bounds and not selecting nodes on it!
Reply #9 - May 18th, 2021 at 10:41am
Print Post  
Yep, we should be releasing this next week.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint