Profile Picture

Automatically activate CreateConnectionTool when mouse it is 'near' a port

Posted By Luciano Cavallero 14 Years Ago

Automatically activate CreateConnectionTool when mouse it is 'near' a...

Author
Message
Luciano Cavallero
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 2, Visits: 7
Hi All,

I need to realize this simple behaviour in my Nevron Diagram Winform application but I don't know how to do it
(I write this topic after I have not found any in the forum):

My app start with the Selector Tool enabled: I would like that when the mouse cursors is 'near' a any port of a 2D shape the view automatically
activate the Connector Creato Tool (so i can start to create connection without manual selecting the right tool from the toolbar) then and go back to the Selector Tool if the mouse cursor go away from the port location.

I'm able to activate the Connector Tool, but I don't know to raise and 'event' to signal me that I'm 'near' a port (is this is the right way)

Anyone can suggest me if it is possible to solve my proble and how?

Thanks
Luciano Cavallero



Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Luciano,

Following is a code sample that implements similar behavior:

...
view.MouseMove += new MouseEventHandler(view_MouseMove);
...


void view_MouseMove(object sender, MouseEventArgs e)
{
   // create connector tool already activated - do nothing
   if (view.Controller.Tools.GetToolByName(NDWFR.ToolCreateConnector).IsActive)
      return;

   // determine whether there is a port neard the current mouse position.
   // this implementation considers near to be 10 pixels
   NPointF mouseInClient = new NPointF(e.X, e.Y);
   bool hasPortNearMouse = false;
   NRectangleF window = view.Window;

   foreach (NPort port in document.Descendants(Nevron.Diagram.Filters.NFilters.TypeNPort, -1))
   {
      NPointF portInClient = view.SceneToDevice.TransformPoint(port.Location);
      if (window.Contains(portInClient) == false)
         continue;

      if (NGeometry2D.PointsDistance(portInClient, mouseInClient) < 10)
      {
         hasPortNearMouse = true;
         break;
      }
   }

   // enable the create connector tool or the pointer tool
   if (hasPortNearMouse)
   {
      view.Controller.Tools.SingleEnableTool(NDWFR.ToolCreateConnector);
   }
   else
   {
      string[] toolNames = new string[] {   
                               NDWFR.ToolCreateGuideline,
                               NDWFR.ToolHandle,
                               NDWFR.ToolMove,
                               NDWFR.ToolSelector,
                               NDWFR.ToolContextMenu,
                               NDWFR.ToolKeyboard,
                               NDWFR.ToolInplaceEdit,
                               NDWFR.ToolMouseEventDelegator
                            };

      view.Controller.Tools.SingleEnableTools(toolNames);
   }
}



Best Regards,
Nevron Support Team



Luciano Cavallero
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 2, Visits: 7
Hi Support Team

your code is exaclty what I need.
It work correclty.

Thank you very much!!!!!

Best regards,

Luciano Cavallero

Wilhelm Vortisch
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Luciano,

the solution is very usefull, but in which assambly you have found "NGeometry2D"?

I use the last Version of Nevron components coming with Nevron Diagram for .Net 2010 Volume 1.

Regards

Wilhelm

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Wilhelm,

"NGeometry2D" is a static class located in the namespace "Nevron.GraphicsCore" of the assembly "Nevron.Presentation.dll".



Best Regards,
Nevron Support Team



Wilhelm Vortisch
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Nevron Support,

in assembly "Nevron.Presentation.dll" I can't find the static class "NGeometry2D" located in the namespace "Nevron.GraphicsCore". (I have searched in the whole assembly, too ....)

I have installed the latest version "Nevron .NET Vision 2010 Vol.1 for Visual Studio 2010 (build version: 11.1.17.12)" from your web site downloaded yesterday.

By the way: In which way differs the "sub version" (or "builds") of the main "Nevron .NET Vision 2010 Vol.1 for Visual Studio 2010"?
And where can I determine the real version of used Nevron lib? (in "software" tab in the control center of windows xp I can only read about the main version "10.1.0000" ...)

Regards

Wilhelm

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Wilhelm,

It appears that the obfuscator we use has renamed the "NGeometry2D" class in the release build. We’ll fix this for the next release. Until then, here’s the source code of the method you need:

 

/// <summary>

/// Obtains the distance between the specified points.

/// </summary>

/// <param name="pt1"></param>

/// <param name="pt2"></param>

/// <returns></returns>

public static float PointsDistance(NPointF pt1, NPointF pt2)

{

      float dx = pt1.X - pt2.X;

      float dy = pt1.Y - pt2.Y;

      return (float)Math.Sqrt(dx * dx + dy * dy);

}



Best Regards,
Nevron Support Team



Wilhelm Vortisch
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Nevron Support,

thanks for the workaround, this works for the moment (until the next release ...).

Regards

Wilhelm





Similar Topics


Reading This Topic