/// <summary> /// This function deletes the selected gate along with all of its connection from the circuit /// It deletes all connection of that gate first before finally deleting the gate itself /// </summary> /// <param name="gate">The gate to be deleted</param> /// <returns>True if the gate is deleted</returns> public bool deleteGate(Gate gate) { setUndoList(); this.redoList.Clear(); List <Connection> temp = gate.getListOfConnections(); int count = temp.Count(); for (int i = 0; i < count; i++) { if (temp[i] != null) { if (temp[i].isFirstGate(gate)) { Gate temp2 = temp[i].getSecondGate(); Connection Cx = temp[i]; do { Cx = temp2.inputConnectionInvalid(Cx); if (Cx != null) { temp2 = Cx.getSecondGate(); } else { temp2.calcValue(); } }while (Cx != null); } deleteConnection(temp[i]); } } gateList.Remove(gate); return(true); }
/// <summary> /// this function draw the connection and determine its color (value) /// </summary> /// <param name="pic">The pictureBox where the connection will be drawn</param> public void drawConnection(ref PictureBox pic) { int col1 = first.getColumn(); int row1 = first.getRow(); int col2 = second.getColumn(); int row2 = second.getRow(); Pen P; if (getValue() == 0) { P = new Pen(Color.Blue, 3); } else if (getValue() == 1) { P = new Pen(Color.Green, 3); } else { P = new Pen(Color.Red, 3); } Graphics g = pic.CreateGraphics(); Point p1 = new Point((col1 - 1) * 50 + 50, (row1 - 1) * 50 + 25); Point p2 = new Point(0, 0); //the following code define where the line end if (second is NotGate || second is SinkGate) { p2 = new Point((col2 - 1) * 50, (row2 - 1) * 50 + 25); } else { List <Connection> temp = second.getListOfConnections(); if (temp.Count() == 1 || (temp.Count() > 1 && temp[0] != null && temp[1] == null) || (temp.Count() > 1 && temp[0] != null && temp[1] != null && this.Equals(temp[0]))) { p2 = new Point((col2 - 1) * 50, (row2 - 1) * 50); } else if ((temp.Count() > 1 && temp[0] != null && temp[1] != null) || (temp.Count() > 1 && temp[1].Equals(this))) { p2 = new Point((col2 - 1) * 50, (row2 - 1) * 50 + 50); } } g.DrawLine(P, p1, p2); }