//Copy Constructor /// <summary> /// Copy Constructor of the Gate Class /// </summary> /// <param name="g">The gate object to be copied</param> public Gate(Gate g) { Connected = new List <Connection>(); this.row = g.getRow(); this.col = g.getColumn(); this.Value = g.calcValue(); }
/// <summary> /// This function checks, for whether the Gate gate overlaps another gate in the circuit by /// comparing the row and column of the gate with every gate in the circuit /// </summary> /// <param name="gate"> /// The newly created gate to be placed in a cell in the circuit /// </param> /// <returns> /// It returns true when the gate doesn't overlap, or false if a gate exist in the same cell /// </returns> public bool addGate(Gate gate) { foreach (Gate ga in gateList) { if ((ga.getRow() == gate.getRow()) && (ga.getColumn() == gate.getColumn())) { MessageBox.Show("This cell has been occupied, please select another cell to place the gate", "Overlapping gate", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } setUndoList(); this.redoList.Clear(); gateList.Add(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); }