diff --git a/EduNetworkBuilder/NetTestEditor.cs b/EduNetworkBuilder/NetTestEditor.cs index 9777791..737c3d7 100644 --- a/EduNetworkBuilder/NetTestEditor.cs +++ b/EduNetworkBuilder/NetTestEditor.cs @@ -322,6 +322,14 @@ namespace EduNetworkBuilder } } } + else if(ToEdit.TheTest == NetTestType.LockLocation) + { + cbDest.Items.Add("--"); //This locks it into one location + foreach(string name in theNet.RectangleNames()) + { + cbDest.Items.Add(name); + } + } else { //List all the hosts foreach (string host in HostNames) @@ -397,7 +405,7 @@ namespace EduNetworkBuilder if (theNet.GetDeviceFromName(cbSource.SelectedItem.ToString()) == null) return false; //This should never happen with a drop-down list, but just in case... if (ntt == NetTestType.LockAll || ntt == NetTestType.LockDHCP || ntt == NetTestType.LockIP || - ntt == NetTestType.LockNic || ntt == NetTestType.LockRoute) + ntt == NetTestType.LockNic || ntt == NetTestType.LockRoute || ntt == NetTestType.LockLocation) return true; if (ntt == NetTestType.NeedsRouteToNet) { diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 69c3463..63225cc 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -1027,8 +1027,19 @@ namespace EduNetworkBuilder { if (nt.sHost == host) { - if (WhatToCheck == nt.TheTest && (dest == "" || dest == nt.dHost)) - return true; + if (WhatToCheck == nt.TheTest) + { + if(nt.TheTest == NetTestType.LockLocation) + { + if(dest == "" && (nt.dHost == "" || nt.dHost == "--")) //It cannot be moved at all + { + return true; + } + return false; + } + else if (dest == "" || dest == nt.dHost) + return true; + } } } return false; diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index bfdb7f7..90f197b 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -823,6 +823,17 @@ namespace EduNetworkBuilder } + private Point AdjustedForRectangle(Point Location, Rectangle rec) + { + int x = Location.X; + int y = Location.Y; + if (x < rec.X) x = rec.X; + if (x > rec.X + rec.Width - Size) x = rec.Width - Size; + if (y < 0) y = 0; + if (y > rec.Height - Size) y = rec.Height - Size; + return new Point(x, y); + } + private void TryPutLocation(Point Location) { Network myNet = NB.GetNetwork(); @@ -830,13 +841,8 @@ namespace EduNetworkBuilder MyLocation = Location; // We cannot do checking. Hope for the best. return; } - int x = Location.X; - int y = Location.Y; - if (x < 0) x = 0; - if (x > myNet.myWidth - Size) x = myNet.myWidth - Size; - if (y < 0) y = 0; - if (y > myNet.myHeight - Size) y = myNet.myHeight - Size; - MyLocation = new Point(x,y); + Point AdjustPoint = AdjustedForRectangle(Location, new Rectangle(0, 0, myNet.myWidth, myNet.myHeight)); + MyLocation = AdjustPoint; IsDirty = true; }