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)
{
CurrentNetAction.Actions[WhichIndex].DoAction();
return true;
return CurrentNetAction.Actions[WhichIndex];
}
return false;
return null;
}
/// <summary>
@ -188,6 +188,27 @@ namespace EduNetworkBuilder
}
break;
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;
case NBAction.dhcp:
break;

View File

@ -523,6 +523,13 @@ namespace EduNetworkBuilder
return myWin;
}
public static void SetBuilderWindowStatis(string text)
{
BuilderWindow myWin = GetBuilderWin();
if (myWin != null)
myWin.ChangeStatusText(text);
}
public static PersonProfileForm GetProfileWin()
{
PersonProfileForm myWin = (PersonProfileForm)Application.OpenForms["PersonProfileForm"];
@ -1389,6 +1396,21 @@ namespace EduNetworkBuilder
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)
{
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...
NBSettings Settings = NB.GetSettings();
ActionCollection AC = Settings.GetUserActionCollection();
bool Success = AC.RunAction(NextReplayIndex++);
ActionClass Success = AC.RunAction(NextReplayIndex++);
NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays);
if(Success)
if(Success != null)
{
//we did something. keep replaying
NB.MarkToUpdate();

View File

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

View File

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