Private
Public Access
Making sure that drawings don't just disappear
This commit is contained in:
1 parent
e351635e96
commit
c506f3543d
5 files changed
+39
-17
No files matched your search
@@ -13,6 +13,7 @@ namespace Advanced_Software_Engineering {
|
||||
Graphics graphics;
|
||||
List<Verb> commands = new List<Verb>();
|
||||
Drawer drawer;
|
||||
bool commands_ok = true;
|
||||
|
||||
/// <summary>
|
||||
/// This command updates the graphics element (usually) when the page repaints.
|
||||
@@ -60,7 +61,7 @@ namespace Advanced_Software_Engineering {
|
||||
/// <summary>
|
||||
/// Adds a verb to the command list to be executed.
|
||||
/// </summary>
|
||||
/// <param name="command">Verb to be added</param>
|
||||
/// <param name="command">Verb to be added. <seealso cref="Verb"/></param>
|
||||
public void AddCommand(Verb command) {
|
||||
commands.Add(command);
|
||||
}
|
||||
@@ -69,12 +70,13 @@ namespace Advanced_Software_Engineering {
|
||||
/// processes commands. Removes all commands if it fails parsing the raw commands.
|
||||
/// </summary>
|
||||
/// <param name="rawCommands">Processes commands seperated by \n or \r\n</param>
|
||||
public void ProcessCommands(string rawCommands) {
|
||||
/// <param name="pardonCommands">If the command is wrong, don't remove all of the commands</param>
|
||||
public void ProcessCommands(string rawCommands, bool pardonCommands=false) {
|
||||
//ignore case
|
||||
rawCommands = rawCommands.ToLower();
|
||||
Console.WriteLine("Processing:\n" + rawCommands);
|
||||
|
||||
//remove windows \r if they exist
|
||||
//remove windows' \r if they exist
|
||||
rawCommands = rawCommands.Replace("\r", "");
|
||||
|
||||
//isolate commands
|
||||
@@ -98,7 +100,12 @@ namespace Advanced_Software_Engineering {
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) RemoveAllCommands();
|
||||
if (failed) {
|
||||
if(!pardonCommands) RemoveAllCommands();
|
||||
commands_ok = false;
|
||||
} else {
|
||||
commands_ok = true;
|
||||
}
|
||||
|
||||
Console.WriteLine("\n\nHere is what the program is going to do:");
|
||||
Console.WriteLine("Set origin to 0, 0");
|
||||
@@ -112,9 +119,10 @@ namespace Advanced_Software_Engineering {
|
||||
/// Processes the commands and executes them at the same time. It's the same as <see></see>
|
||||
/// </summary>
|
||||
/// <param name="rawCommands">Processes commands seperated by \n or \r\n</param>
|
||||
public void ProcessCommandsAndExecute(string rawCommands) {
|
||||
/// <param name="pardonCommands">If the command is wrong, don't remove all of the commands</param>
|
||||
public void ProcessCommandsAndExecute(string rawCommands, bool pardonCommands = false) {
|
||||
int start = commands.Count;
|
||||
ProcessCommands(rawCommands);
|
||||
ProcessCommands(rawCommands, pardonCommands);
|
||||
|
||||
for (; start < commands.Count; start++) {
|
||||
commands[start].ExecuteVerb();
|
||||
@@ -142,13 +150,12 @@ namespace Advanced_Software_Engineering {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the numder of commands inside the Commader
|
||||
/// Gets the status of the code that was processed
|
||||
/// </summary>
|
||||
/// <returns>Integer number of commands</returns>
|
||||
public int GetNumberOfCommands() {
|
||||
return commands.Count;
|
||||
/// <returns>False if there was no error. True if there was an error</returns>
|
||||
public bool GetLastStatus() {
|
||||
return commands_ok;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -153,6 +153,7 @@ namespace Advanced_Software_Engineering {
|
||||
} else throw new Exception("Command doesn't take parameters");
|
||||
|
||||
case "reset":
|
||||
case "resetpen":
|
||||
if (parameters.Length == 0) {
|
||||
return new ResetPen(drawer);
|
||||
} else throw new Exception("Command doesn't take parameters");
|
||||
|
||||
Generated
+1
@@ -55,6 +55,7 @@
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(449, 20);
|
||||
this.textBox1.TabIndex = 1;
|
||||
this.textBox1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox1_PreviewKeyDown);
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Advanced_Software_Engineering
|
||||
|
||||
Graphics graphics;
|
||||
Commander commander;
|
||||
bool pardonCommands;
|
||||
|
||||
/// <summary>
|
||||
/// The draw preview window. Spawns the basic DrawPreview.
|
||||
@@ -29,6 +30,7 @@ namespace Advanced_Software_Engineering
|
||||
graphics = panel1.CreateGraphics();
|
||||
graphics.ResetClip();
|
||||
commander = new Commander(graphics);
|
||||
pardonCommands = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +45,7 @@ namespace Advanced_Software_Engineering
|
||||
graphics = panel1.CreateGraphics();
|
||||
graphics.ResetClip();
|
||||
commander = new Commander(graphics, commands);
|
||||
|
||||
pardonCommands = false;
|
||||
//disable components
|
||||
textBox1.Enabled = false;
|
||||
button1.Enabled = false;
|
||||
@@ -67,7 +69,7 @@ namespace Advanced_Software_Engineering
|
||||
|
||||
private void SubmitCommand(object sender, EventArgs e)
|
||||
{
|
||||
commander.ProcessCommandsAndExecute(textBox1.Text);
|
||||
commander.ProcessCommandsAndExecute(textBox1.Text, pardonCommands);
|
||||
textBox1.Text = "";
|
||||
}
|
||||
|
||||
@@ -76,7 +78,7 @@ namespace Advanced_Software_Engineering
|
||||
/// </summary>
|
||||
/// <param name="comamnds">Commands seperated by new lines</param>
|
||||
public void SubmitCommands(string comamnds) {
|
||||
commander.ProcessCommandsAndExecute(comamnds);
|
||||
commander.ProcessCommandsAndExecute(comamnds, pardonCommands);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,6 +94,7 @@ namespace Advanced_Software_Engineering
|
||||
public void ReleaseCommandLock() {
|
||||
textBox1.Enabled = true;
|
||||
button1.Enabled = true;
|
||||
pardonCommands = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,12 +106,22 @@ namespace Advanced_Software_Engineering
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns weather there were any errors in the commander. Commander will have 0 commands if there is one bad command.
|
||||
/// Returns weather there were any errors in the commander.
|
||||
/// </summary>
|
||||
/// <returns>A boolean describing the success of command phrasing</returns>
|
||||
public bool IsSuccess() {
|
||||
return commander.GetNumberOfCommands() > 0;
|
||||
return commander.GetLastStatus();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submits the form
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
|
||||
if (e.KeyCode == Keys.Enter && textBox1.Enabled) {
|
||||
button1.PerformClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+1
-1
@@ -180,7 +180,7 @@ namespace Advanced_Software_Engineering
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.label1.Location = new System.Drawing.Point(0, 548);
|
||||
this.label1.Location = new System.Drawing.Point(0, 535);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(0, 13);
|
||||
this.label1.TabIndex = 2;
|
||||
|
||||
Reference in new issue
Block a user