Adding devices is part of Actions

This commit is contained in:
Tim Young 2018-05-14 10:41:52 -05:00
parent a445ce5bd3
commit 8b82150bbe
5 changed files with 93 additions and 40 deletions

View File

@ -42,15 +42,15 @@ namespace EduNetworkBuilder
} }
} }
public bool RunAction(int WhichIndex) public ActionClass RunAction(int WhichIndex)
{ {
if (CurrentNetAction == null) return false; if (CurrentNetAction == null) return null;
if (WhichIndex < CurrentNetAction.Actions.Count) if (WhichIndex < CurrentNetAction.Actions.Count)
{ {
CurrentNetAction.Actions[WhichIndex].DoAction(); CurrentNetAction.Actions[WhichIndex].DoAction();
return true; return CurrentNetAction.Actions[WhichIndex];
} }
return false; return null;
} }
/// <summary> /// <summary>
@ -188,6 +188,27 @@ namespace EduNetworkBuilder
} }
break; break;
case NBAction.newdevice: case NBAction.newdevice:
bool CanDo = true;
Point tLoc = myNet.clickedPosCentered(Location);
Point CenteredLocation = new Point(Location.X - (Location.X - tLoc.X), Location.Y - ((Location.Y - tLoc.Y)));
Point TopLeft = Location;
Point TopRight = new Point(TopLeft.X + myNet.itemsize, TopLeft.Y);
Point BottomRight = new Point(TopLeft.X + myNet.itemsize, TopLeft.Y + myNet.itemsize);
Point BottomLeft = new Point(TopLeft.X, TopLeft.Y + myNet.itemsize);
ChangedDevice = null; //if we cannot place it, this = null for reference
if (myNet.BlockedByTree(Location)) CanDo = false;
if (myNet.BlockedByTree(TopLeft)) CanDo = false;
if (myNet.BlockedByTree(TopRight)) CanDo = false;
if (myNet.BlockedByTree(BottomRight)) CanDo = false;
if (myNet.BlockedByTree(BottomLeft)) CanDo = false;
if (CanDo)
{
ChangedDevice = (NetworkDevice)myNet.AddItem(newItemType, Location);
}
else
{
NB.SetBuilderWindowStatis(NB.Translate("NB_TreePlacementError"));
}
break; break;
case NBAction.dhcp: case NBAction.dhcp:
break; break;

View File

@ -523,6 +523,13 @@ namespace EduNetworkBuilder
return myWin; return myWin;
} }
public static void SetBuilderWindowStatis(string text)
{
BuilderWindow myWin = GetBuilderWin();
if (myWin != null)
myWin.ChangeStatusText(text);
}
public static PersonProfileForm GetProfileWin() public static PersonProfileForm GetProfileWin()
{ {
PersonProfileForm myWin = (PersonProfileForm)Application.OpenForms["PersonProfileForm"]; PersonProfileForm myWin = (PersonProfileForm)Application.OpenForms["PersonProfileForm"];
@ -1389,6 +1396,21 @@ namespace EduNetworkBuilder
AC.DoAction(); AC.DoAction();
} }
public static NetworkComponent DoActionAddDevice(NetworkComponentType WhatType, Point Location)
{
//Make an action for the location, register the action, and do the action
ActionClass AC = new ActionClass();
AC.Action = NBAction.newdevice;
AC.newItemType = WhatType;
AC.Location = Location;
RegisterAction(AC);
AC.DoAction();
return AC.ChangedDevice;
}
public static void DoActionPingDevice(int HostID, NB_IPAddress Destination) public static void DoActionPingDevice(int HostID, NB_IPAddress Destination)
{ {
ActionClass AC = new ActionClass(); ActionClass AC = new ActionClass();

View File

@ -1653,10 +1653,10 @@ namespace EduNetworkBuilder
//We are doing a replay and enough time has passed from the last replay... //We are doing a replay and enough time has passed from the last replay...
NBSettings Settings = NB.GetSettings(); NBSettings Settings = NB.GetSettings();
ActionCollection AC = Settings.GetUserActionCollection(); ActionCollection AC = Settings.GetUserActionCollection();
bool Success = AC.RunAction(NextReplayIndex++); ActionClass Success = AC.RunAction(NextReplayIndex++);
NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays); NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays);
if(Success) if(Success != null)
{ {
//we did something. keep replaying //we did something. keep replaying
NB.MarkToUpdate(); NB.MarkToUpdate();

View File

@ -1668,82 +1668,87 @@ namespace EduNetworkBuilder
else if (ItemClickedOn == null) else if (ItemClickedOn == null)
{ {
NetworkComponent NC = null; NetworkComponent NC = null;
NetworkComponentType NCType = NetworkComponentType.none;
switch (selectedButton) switch (selectedButton)
{ {
case "btnSwitch": case "btnSwitch":
NC = myNetwork.AddItem(NetworkComponentType.net_switch, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.net_switch, CenteredLocation);
NCType = NetworkComponentType.net_switch;
break; break;
case "btnHub": case "btnHub":
NC = myNetwork.AddItem(NetworkComponentType.net_hub, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.net_hub, CenteredLocation);
NCType = NetworkComponentType.net_hub;
break; break;
case "btnLaptop": case "btnLaptop":
NC = myNetwork.AddItem(NetworkComponentType.laptop, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.laptop, CenteredLocation);
NCType = NetworkComponentType.laptop;
break; break;
case "btnServer": case "btnServer":
NC = myNetwork.AddItem(NetworkComponentType.server, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.server, CenteredLocation);
NCType = NetworkComponentType.server;
break; break;
case "btnPC": case "btnPC":
NC = myNetwork.AddItem(NetworkComponentType.pc, CenteredLocation); NC = myNetwork.AddItem(NetworkComponentType.pc, CenteredLocation);
NCType = NetworkComponentType.pc;
break; break;
case "btnRouter": case "btnRouter":
NC = myNetwork.AddItem(NetworkComponentType.router, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.router, CenteredLocation);
NCType = NetworkComponentType.router;
break; break;
case "btnIPPhone": case "btnIPPhone":
NC = myNetwork.AddItem(NetworkComponentType.ip_phone, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.ip_phone, CenteredLocation);
NCType = NetworkComponentType.ip_phone;
break; break;
case "btnFirewall": case "btnFirewall":
NC = myNetwork.AddItem(NetworkComponentType.firewall, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.firewall, CenteredLocation);
NCType = NetworkComponentType.firewall;
break; break;
case "btnPrinter": case "btnPrinter":
NC = myNetwork.AddItem(NetworkComponentType.printer, CenteredLocation); NC = myNetwork.AddItem(NetworkComponentType.printer, CenteredLocation);
NCType = NetworkComponentType.printer;
break; break;
case "btnCopier": case "btnCopier":
NC = myNetwork.AddItem(NetworkComponentType.copier, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.copier, CenteredLocation);
NCType = NetworkComponentType.copier;
break; break;
case "btnMicrowave": case "btnMicrowave":
NC = myNetwork.AddItem(NetworkComponentType.microwave, CenteredLocation); NC = myNetwork.AddItem(NetworkComponentType.microwave, CenteredLocation);
NCType = NetworkComponentType.microwave;
break; break;
case "btnFluorescent": case "btnFluorescent":
NC = myNetwork.AddItem(NetworkComponentType.fluorescent, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.fluorescent, CenteredLocation);
NCType = NetworkComponentType.fluorescent;
break; break;
case "btnWAP": case "btnWAP":
NC = myNetwork.AddItem(NetworkComponentType.wap, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.wap, CenteredLocation);
NCType = NetworkComponentType.wap;
break; break;
case "btnWRouter": case "btnWRouter":
NC = myNetwork.AddItem(NetworkComponentType.wrouter, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.wrouter, CenteredLocation);
NCType = NetworkComponentType.wrouter;
break; break;
case "btnCellphone": case "btnCellphone":
NC = myNetwork.AddItem(NetworkComponentType.cellphone, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.cellphone, CenteredLocation);
NCType = NetworkComponentType.cellphone;
break; break;
case "btnTablet": case "btnTablet":
NC = myNetwork.AddItem(NetworkComponentType.tablet, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.tablet, CenteredLocation);
NCType = NetworkComponentType.tablet;
break; break;
case "btnWBridge": case "btnWBridge":
NC = myNetwork.AddItem(NetworkComponentType.wbridge, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.wbridge, CenteredLocation);
NCType = NetworkComponentType.wbridge;
break; break;
case "btnWRepeater": case "btnWRepeater":
NC = myNetwork.AddItem(NetworkComponentType.wrepeater, CenteredLocation); //NC = myNetwork.AddItem(NetworkComponentType.wrepeater, CenteredLocation);
NCType = NetworkComponentType.wrepeater;
break; break;
case "btnTree": case "btnTree":
bool CanDo = true; //NC = myNetwork.AddItem(NetworkComponentType.tree, CenteredLocation);
Point TopLeft = CenteredLocation; NCType = NetworkComponentType.tree;
Point TopRight = new Point(TopLeft.X + myNetwork.itemsize, TopLeft.Y);
Point BottomRight = new Point(TopLeft.X + myNetwork.itemsize, TopLeft.Y + myNetwork.itemsize);
Point BottomLeft = new Point(TopLeft.X, TopLeft.Y + myNetwork.itemsize);
if (myNetwork.BlockedByTree(ClickedLocation)) CanDo = false;
if (myNetwork.BlockedByTree(TopLeft)) CanDo = false;
if (myNetwork.BlockedByTree(TopRight)) CanDo = false;
if (myNetwork.BlockedByTree(BottomRight)) CanDo = false;
if (myNetwork.BlockedByTree(BottomLeft)) CanDo = false;
if(CanDo)
NC = myNetwork.AddItem(NetworkComponentType.tree, CenteredLocation);
else
{
lblStatus.Text = NB.Translate("NB_TreePlacementError");
}
break; break;
} }
NC = NB.DoActionAddDevice(NCType, CenteredLocation);
if (NC != null && NB.GetComponentType(NC) == GeneralComponentType.device) if (NC != null && NB.GetComponentType(NC) == GeneralComponentType.device)
{ {
ItemClickedOn = (NetworkDevice)NC; ItemClickedOn = (NetworkDevice)NC;
@ -1768,6 +1773,11 @@ namespace EduNetworkBuilder
LastClick = DateTime.Now; LastClick = DateTime.Now;
} }
public void ChangeStatusText(string text)
{
lblStatus.Text = text;
}
private void UpdateVisuals() private void UpdateVisuals()
{ {
myNetwork.Print(); myNetwork.Print();

View File

@ -2046,8 +2046,8 @@
<comment>NB_cbLineColor = Choose a color for the shape outline</comment> <comment>NB_cbLineColor = Choose a color for the shape outline</comment>
</data> </data>
<data name="NB_TreePlacementError" xml:space="preserve"> <data name="NB_TreePlacementError" xml:space="preserve">
<value>Cannot place a tree on top of a tree.</value> <value>Cannot place an item on top of a tree.</value>
<comment>NB_TreePlacementError = Cannot place a tree on top of a tree.</comment> <comment>NB_TreePlacementError = Cannot place an item on top of a tree.</comment>
</data> </data>
<data name="NT_TstDiscriptLockLocation" xml:space="preserve"> <data name="NT_TstDiscriptLockLocation" xml:space="preserve">
<value>Device cannot be moved</value> <value>Device cannot be moved</value>