Exemple #1
0
        void Add_NOT(double x = 0, double y = 0, string id = "")
        {
            CQGateUI cc    = null;
            QGate    ggate = null;

            cc          = new CQGateUI();
            cc.GateName = "NOT";
            cc.Type     = "NOT";
            cc.Pin_in.Add(new CQPin()
            {
                Type = CQPin.Types.IN, Index = 0
            });
            cc.Pin_out.Add(new CQPin()
            {
                Type = CQPin.Types.OUT
            });
            cc.CreateNOT();
            ggate        = new QGate();
            ggate.Height = 50;
            ggate.Width  = 80;
            cc.ID        = id;
            Canvas.SetLeft(ggate, x);
            Canvas.SetTop(ggate, y);
            ggate.DataContext     = cc;
            ggate.OnPinMouseDwon += Ggate_OnPinMouseDwon;
            ggate.OnPinMouseUp   += Ggate_OnPinMouseUp;
            ggate.OnGateMove     += Ggate_OnGateMove;
            this.canvas.Children.Add(ggate);
        }
Exemple #2
0
        private bool Ggate_OnPinMouseDwon(QGate sender, CQPin pin, Point pt)
        {
            CQGateBaseUI gateui = sender.DataContext as CQGateBaseUI;

            this.m_Line                 = new Line();
            this.m_Line.Fill            = Brushes.Gray;
            this.m_Line.X1              = this.m_Line.X2 = pin.ConnectPoint.X;
            this.m_Line.Y1              = this.m_Line.Y2 = pin.ConnectPoint.Y;
            this.m_Line.Stroke          = Brushes.Gray;
            this.m_Line.StrokeThickness = 1;
            this.m_IsConnect            = true;
            CQSaveFile_Line save_line = new CQSaveFile_Line()
            {
                Line = this.m_Line
            };

            if (this.m_LineDatas.ContainsKey(save_line.Line) == false)
            {
                this.m_LineDatas.Add(save_line.Line, save_line);
            }
            else
            {
            }
            this.m_LineDatas[this.m_Line].Begin.GateID = gateui.ID;
            this.m_LineDatas[this.m_Line].Begin.Index  = pin.Index;
            this.m_LineDatas[this.m_Line].Begin.Type   = pin.Type;

            this.m_LineDatas[this.m_Line].Begin.EndType = CQSaveFile_LinePoint.EndTypes.Start;
            this.canvas.Children.Add(this.m_Line);
            return(true);
        }
Exemple #3
0
        private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (this.m_IsDrag == true)
            {
                this.m_IsDrag = false;
                this.canvas.ReleaseMouseCapture();
                this.m_DragGate        = null;
                this.m_DragInputSwitch = null;
            }
            else if (this.m_IsConnect == true)
            {
                this.canvas.Children.Remove(this.m_Line);
                this.m_LineDatas.Remove(this.m_Line);
                this.m_Line      = null;
                this.m_IsConnect = false;
                this.canvas.ReleaseMouseCapture();
            }
            else if (this.m_IsSelect == true)
            {
                Point pt       = new Point(Canvas.GetLeft(this.m_SelectRect), Canvas.GetTop(this.m_SelectRect));
                Size  sz       = new Size(this.m_SelectRect.Width, this.m_SelectRect.Height);
                Rect  selectrc = new Rect(pt, sz);
                foreach (FrameworkElement child in this.canvas.Children)
                {
                    double       left      = Canvas.GetLeft(child);
                    double       right     = Canvas.GetRight(child);
                    double       top       = Canvas.GetTop(child);
                    double       bottom    = Canvas.GetBottom(child);
                    Rect         rc_gate   = new Rect(new Point(left, top), new Size(child.Width, child.Height));
                    bool         is_select = selectrc.Contains(rc_gate);
                    CQGateBaseUI gateui    = child.DataContext as CQGateBaseUI;
                    if (gateui != null)
                    {
                        gateui.IsSelected = is_select;
                    }
                }

                this.m_IsSelect = false;
                this.canvas.Children.Remove(this.m_SelectRect);
                this.m_SelectRect = null;
                this.canvas.ReleaseMouseCapture();
            }
        }
Exemple #4
0
 private void canvas_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (e.Source is QGate)
     {
         this.m_DragGate   = e.Source as QGate;
         this.m_IsDrag     = true;
         this.m_DragOffset = e.GetPosition(this.m_DragGate);
         this.canvas.CaptureMouse();
     }
     else if (e.Source is QInput_Switch)
     {
         this.m_DragInputSwitch = e.Source as QInput_Switch;
         this.m_IsDrag          = true;
         this.m_DragOffset      = e.GetPosition(this.m_DragInputSwitch);
         this.canvas.CaptureMouse();
     }
     else if (e.Source is QOutput_LED)
     {
         this.m_DragOutputLED = e.Source as QOutput_LED;
         this.m_IsDrag        = true;
         this.m_DragOffset    = e.GetPosition(this.m_DragOutputLED);
         this.canvas.CaptureMouse();
     }
     else
     {
         this.m_SelectPt   = e.GetPosition(this.canvas);
         this.m_SelectRect = new Rectangle();
         //rectangle.Width = 100;
         //rectangle.Height = 100;
         this.m_SelectRect.Stroke = Brushes.Black;
         this.m_SelectRect.StrokeDashArray.Add(6);
         this.m_SelectRect.StrokeDashCap = PenLineCap.Square;
         this.canvas.Children.Add(this.m_SelectRect);
         Canvas.SetLeft(this.m_SelectRect, this.m_SelectPt.X);
         Canvas.SetTop(this.m_SelectRect, this.m_SelectPt.Y);
         this.m_IsSelect = true;
         this.canvas.CaptureMouse();
     }
 }
Exemple #5
0
 private bool Ggate_OnPinMouseUp(QGate sender, CQPin pin, Point pt)
 {
     this.ConnectEnd(sender, pin, pt);
     return(true);
 }
Exemple #6
0
        private void button_load_Click(object sender, RoutedEventArgs e)
        {
            this.togglebutton_simulation.IsChecked = false;
            CQSaveFile sv = null;

            if (File.Exists("QQ.txt") == true)
            {
                XmlSerializer xml = new XmlSerializer(typeof(CQSaveFile));
                using (FileStream fs = new FileStream("QQ.txt", FileMode.Open))
                {
                    sv = (CQSaveFile)xml.Deserialize(fs);
                }
            }
            if (sv != null)
            {
                this.ClearGate();
                foreach (CQSaveFile_Gate gate in sv.Gates)
                {
                    switch (gate.Type)
                    {
                    case "AND":
                    {
                        this.Add_AND(gate.X, gate.Y, gate.ID);
                    }
                    break;

                    case "NOT":
                    {
                        this.Add_NOT(gate.X, gate.Y, gate.ID);
                    }
                    break;

                    case "OR":
                    {
                        this.Add_OR(gate.X, gate.Y, gate.ID);
                    }
                    break;

                    case "Switch":
                    {
                        this.Add_Input_Switch(gate.X, gate.Y, gate.ID);
                    }
                    break;

                    case "LED":
                    {
                        this.Add_LED(gate.X, gate.Y, gate.ID);
                    }
                    break;
                    }
                }
                foreach (CQSaveFile_Line line in sv.Lines)
                {
                    line.Line      = new Line();
                    line.Line.Fill = Brushes.Gray;
                    //this.m_Line.X1 = this.m_Line.X2 = pin.ConnectPoint.X;
                    //this.m_Line.Y1 = this.m_Line.Y2 = pin.ConnectPoint.Y;
                    line.Line.Stroke          = Brushes.Gray;
                    line.Line.StrokeThickness = 1;
                    this.m_LineDatas.Add(line.Line, line);
                    this.canvas.Children.Add(line.Line);
                }
                this.canvas.UpdateLayout();
                foreach (FrameworkElement child in this.canvas.Children)
                {
                    QGate gate = child as QGate;
                    if (gate != null)
                    {
                        gate.RefreshLocation();
                    }
                    QInput_Switch input_switch = child as QInput_Switch;
                    if (input_switch != null)
                    {
                        input_switch.RefreshLocation();
                    }
                    QOutput_LED output_led = child as QOutput_LED;
                    if (output_led != null)
                    {
                        output_led.RefreshLocation();
                    }
                    this.ChangeLine(child);
                }
            }
        }
Exemple #7
0
 private bool Ggate_OnGateMove(QGate gate)
 {
     this.ChangeLine(gate);
     return(true);
 }