recognize if we click on a link
This commit is contained in:
parent
f397456649
commit
f7b82d38c9
@ -501,6 +501,21 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NetworkLink LinkAtPosition(Point NetworkLocation)
|
||||||
|
{
|
||||||
|
NetworkLink tLink;
|
||||||
|
foreach (NetworkComponent tItem in NetComponents)
|
||||||
|
{
|
||||||
|
if (tItem is NetworkLink)
|
||||||
|
{
|
||||||
|
tLink = (NetworkLink)tItem;
|
||||||
|
if (tLink.AtLocation(NetworkLocation))
|
||||||
|
return tLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public List<NetworkDevice> DevicesInRectangle(Rectangle area)
|
public List<NetworkDevice> DevicesInRectangle(Rectangle area)
|
||||||
{
|
{
|
||||||
NetworkDevice tDevice;
|
NetworkDevice tDevice;
|
||||||
|
@ -1233,6 +1233,10 @@ namespace EduNetworkBuilder
|
|||||||
Point CenteredLocation = myNetwork.clickedPosCentered(e.Location);
|
Point CenteredLocation = myNetwork.clickedPosCentered(e.Location);
|
||||||
Point ClickLocation = myNetwork.clickedPos(e.Location);
|
Point ClickLocation = myNetwork.clickedPos(e.Location);
|
||||||
NetworkDevice ReleasedOn = myNetwork.ItemAtPosition(ClickLocation);
|
NetworkDevice ReleasedOn = myNetwork.ItemAtPosition(ClickLocation);
|
||||||
|
NetworkLink ReleasedOnLink = null;
|
||||||
|
if(ReleasedOn == null)
|
||||||
|
ReleasedOnLink = myNetwork.LinkAtPosition(ClickLocation);
|
||||||
|
|
||||||
LastBackgroundImage = null;
|
LastBackgroundImage = null;
|
||||||
pbNetworkView.Image = null; //erase old highlight area
|
pbNetworkView.Image = null; //erase old highlight area
|
||||||
LastMouseMovePos = new Point(-1, -1);
|
LastMouseMovePos = new Point(-1, -1);
|
||||||
|
@ -320,6 +320,47 @@ namespace EduNetworkBuilder
|
|||||||
return usedLinks;
|
return usedLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AtLocation(Point NetworkPoint)
|
||||||
|
{
|
||||||
|
Network myNet = NB.GetNetwork();
|
||||||
|
NetworkDevice Src = myNet.HostMatchingHostNicID(SrcNic);
|
||||||
|
NetworkDevice Dst = myNet.HostMatchingHostNicID(DstNic);
|
||||||
|
int Slop = 10;
|
||||||
|
int AutoWin = Slop * 2;
|
||||||
|
//Draw a line between them
|
||||||
|
if (Src == null || Dst == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Point sPoint = Src.GetCenter();
|
||||||
|
Point dPoint = Dst.GetCenter();
|
||||||
|
Rectangle SlopRec = new Rectangle(
|
||||||
|
Math.Min(sPoint.X, dPoint.X) - Slop,
|
||||||
|
Math.Min(sPoint.Y, dPoint.Y) - Slop,
|
||||||
|
Math.Abs(sPoint.X - dPoint.X) + (Slop * 2),
|
||||||
|
Math.Abs(sPoint.Y - dPoint.Y) + (Slop * 2));
|
||||||
|
Rectangle ActualRec = new Rectangle(
|
||||||
|
Math.Min(sPoint.X, dPoint.X),
|
||||||
|
Math.Min(sPoint.Y, dPoint.Y),
|
||||||
|
Math.Abs(sPoint.X - dPoint.X),
|
||||||
|
Math.Abs(sPoint.Y - dPoint.Y));
|
||||||
|
if (SlopRec.Contains(NetworkPoint))
|
||||||
|
{
|
||||||
|
if (ActualRec.Width < AutoWin || ActualRec.Height < AutoWin) return true; //we are close enough
|
||||||
|
//We are inside it. Now to figure out if we are somewhere along the line
|
||||||
|
Rectangle smallrec = new Rectangle(Math.Min(sPoint.X, dPoint.X),
|
||||||
|
Math.Min(sPoint.Y, NetworkPoint.Y),
|
||||||
|
Math.Abs(sPoint.X - NetworkPoint.X),
|
||||||
|
Math.Abs(sPoint.Y - NetworkPoint.Y));
|
||||||
|
double deltax = smallrec.Width / (double)ActualRec.Width;
|
||||||
|
double deltay = smallrec.Height / (double)ActualRec.Height;
|
||||||
|
double TrueDelta = Math.Abs(Math.Abs(deltax) - Math.Abs(deltay));
|
||||||
|
if (TrueDelta > .15) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Have the packet traverse the network
|
/// Have the packet traverse the network
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user