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


Automatically activate CreateConnectionTool when mouse it is 'near' a...
Author
Message
Luciano Cavallero
Luciano Cavallero
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
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


Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
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


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search