Пример #1
0
 public void resetDiagram(Gates.GateObject node)
 {
     node.setHighlight(false);
     if (node.GetType() != typeof(Gates.Input))
     {
         node.in1val = -1;
         node.in2val = -1;
     }
     if (node == null)
     {
         return;
     }
     if (node.hasLeft() && node.input1 != null)
     {
         this.resetDiagram(node.input1);
     }
     if (!node.hasRight() || node.input2 == null)
     {
         return;
     }
     this.resetDiagram(node.input2);
 }
Пример #2
0
            private void simulateDiagramRec(Gates.GateObject Node)
            {
                bool flag = false;

                if (Node == null)
                {
                    this.result = this.stack.Pop();
                }
                if (Node.getOutput() != -1)
                {
                    this.stack.Push(Node.getOutput());
                    if (Node.getOutput() == 1)
                    {
                        Node.setHighlight(true);
                    }
                }
                if (Node.hasLeft())
                {
                    if (Node.input1 != null)
                    {
                        if (Node.input1 == Node.input2)
                        {
                            flag = true;
                        }
                        this.simulateDiagramRec(Node.input1);
                    }
                    else
                    {
                        this.error = true;
                    }
                }
                if (Node.hasRight() && !flag)
                {
                    if (Node.input2 != null)
                    {
                        this.simulateDiagramRec(Node.input2);
                    }
                    else
                    {
                        this.error = true;
                    }
                }
                if (Node.hasLeft() && Node.hasRight() && this.stack.Count > 0)
                {
                    if (Node.in2val == -1 && !flag)
                    {
                        Node.in2val = this.stack.Pop();
                    }
                    else
                    {
                        int num = this.stack.Pop();
                        Node.in2val = num;
                        this.stack.Push(num);
                    }
                }
                if (Node.in1val != -1 || this.stack.Count <= 0)
                {
                    return;
                }
                Node.in1val = this.stack.Pop();
                if (Node.in2val != -1 || Node.hasLeft() && !Node.hasRight())
                {
                    int output = Node.getOutput();
                    this.stack.Push(output);
                    if (output == 1)
                    {
                        Node.setHighlight(true);
                    }
                }
            }
Пример #3
0
        public void renderGates(Gates.GateObject gate, PaintEventArgs e)
        {
            if (gate.getOutput() == 1)
            {
                gate.setHighlight(true);
            }
            else
            {
                gate.setHighlight(false);
            }
            Image image = gate.getImage();
            Point pos1  = gate.getPos();

            e.Graphics.DrawImageUnscaled(image, pos1);

            if (gate.GetType() == typeof(Gates.Input) || gate.GetType() == typeof(Gates.Output))
            {
                SolidBrush solidBrush = new SolidBrush(Color.Black);
                Font       font       = new Font(FontFamily.GenericSansSerif, 12f, FontStyle.Bold);
                Point      point      = new Point(pos1.X + 12, pos1.Y - 10);
                if (gate.GetType() == typeof(Gates.Input))
                {
                    e.Graphics.DrawString(gate.getName(), font, (Brush)solidBrush, (PointF)point);
                }
                else
                {
                    e.Graphics.DrawString("Q", font, (Brush)solidBrush, (PointF)point);
                }
            }

            Pen pen1 = new Pen(Color.Black, 1f);

            int[][] circlePositions1 = gate.getCirclePositions();
            for (int index = 0; index < circlePositions1.Length; ++index)
            {
                e.Graphics.DrawEllipse(pen1, pos1.X + circlePositions1[index][0], pos1.Y + circlePositions1[index][1], circlePositions1[index][2], circlePositions1[index][3]);
            }
            if (gate == null)
            {
                return;
            }
            Point pos2;
            Point start;
            Point end;

            if (gate.hasLeft() && gate.input1 != null)
            {
                Pen pen2 = new Pen(Color.Black, 2f);
                if (this.wireList.Count == this.wireHighlight && this.wireHighlight != -1)
                {
                    pen2 = new Pen(Color.Red, 2f);
                }
                int[][] circlePositions2 = gate.input1.getCirclePositions();
                pos2  = gate.input1.getPos();
                start = new Point(circlePositions2[0][0] + pos2.X + 4, circlePositions2[0][1] + pos2.Y + 2);
                if (gate.input1.getOutput() == 1 && this.simulating)
                {
                    pen2 = new Pen(Color.FromArgb(38, 126, 241), 2f);
                }
                if (circlePositions1.Length > 1)
                {
                    end = new Point(circlePositions1[1][0] + pos1.X, circlePositions1[1][1] + pos1.Y + 2);
                    Point[] points = this.calculatePoints(start, end);
                    this.wireList.Add(points);
                    e.Graphics.DrawLines(pen2, points);
                }
                else
                {
                    end = new Point(circlePositions1[0][0] + pos1.X, circlePositions1[0][1] + pos1.Y + 2);
                    Point[] points = this.calculatePoints(start, end);
                    this.wireList.Add(points);
                    e.Graphics.DrawLines(pen2, points);
                }
                this.renderGates(gate.input1, e);
            }
            if (!gate.hasRight() || gate.input2 == null)
            {
                return;
            }
            Pen pen3 = new Pen(Color.Black, 2f);

            if (this.wireList.Count == this.wireHighlight && this.wireHighlight != -1)
            {
                pen3 = new Pen(Color.Red, 2f);
            }
            int[][] circlePositions3 = gate.input2.getCirclePositions();
            if (gate.input2.getOutput() == 1 && this.simulating)
            {
                pen3 = new Pen(Color.FromArgb(38, 126, 241), 2f);
            }
            pos2  = gate.input2.getPos();
            start = new Point(circlePositions3[0][0] + pos2.X + 4, circlePositions3[0][1] + pos2.Y + 2);
            end   = new Point(circlePositions1[2][0] + pos1.X, circlePositions1[2][1] + pos1.Y + 2);
            Point[] points1 = this.calculatePoints(start, end);
            this.wireList.Add(points1);
            e.Graphics.DrawLines(pen3, points1);
            this.renderGates(gate.input2, e);
        }