예제 #1
0
        private void button_save_Click(object sender, RoutedEventArgs e)
        {
            CQSaveFile sv = new CQSaveFile();

            foreach (FrameworkElement child in this.canvas.Children)
            {
                CQGateBaseUI gateui = child.DataContext as CQGateBaseUI;
                if (gateui != null)
                {
                    CQSaveFile_Gate sg = new CQSaveFile_Gate();
                    sg.ID   = gateui.ID;
                    sg.X    = Canvas.GetLeft(child);
                    sg.Y    = Canvas.GetTop(child);
                    sg.Type = gateui.Type;
                    sv.Gates.Add(sg);
                }
            }
            sv.Lines.AddRange(this.m_LineDatas.Values);
            MemoryStream snapshot = this.Snapshot();

            sv.SnapshotRaw = snapshot.ToArray();
            XmlSerializer xml      = new XmlSerializer(typeof(CQSaveFile));
            string        filename = string.Format("{0}.txt", this.textbox_savename.Text);

            using (FileStream fs = new FileStream(filename, FileMode.Create))
            {
                xml.Serialize(fs, sv);
            }
        }
예제 #2
0
        private bool Output_led_OnPinMouseDwon(QOutput_LED 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);
        }
예제 #3
0
        private void toggglebutton_switch_Click(object sender, RoutedEventArgs e)
        {
            this.textblock_state.Text = this.toggglebutton_switch.IsChecked == true ? "On" : "Off";
            CQGateBaseUI gateui = this.DataContext as CQGateBaseUI;

            for (int i = 0; i < gateui.Pin_out.Count; i++)
            {
                gateui.Pin_out[i].IsTrue = this.toggglebutton_switch.IsChecked == true;
            }
        }
예제 #4
0
 void FineGateFromGateID(string id, List <FrameworkElement> gates, out FrameworkElement gate, out CQGateBaseUI gateui)
 {
     gate   = null;
     gateui = null;
     foreach (FrameworkElement child in gates)
     {
         CQGateBaseUI ui = child.DataContext as CQGateBaseUI;
         if (ui.ID == id)
         {
             gate   = child;
             gateui = ui;
             break;
         }
     }
 }
예제 #5
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();
            }
        }
예제 #6
0
        void ConnectEnd(FrameworkElement sender, CQPin pin, Point pt)
        {
            CQGateBaseUI gateui = sender.DataContext as CQGateBaseUI;

            this.m_Line.X2 = pin.ConnectPoint.X;
            this.m_Line.Y2 = pin.ConnectPoint.Y;
            this.m_LineDatas[this.m_Line].End.GateID  = gateui.ID;
            this.m_LineDatas[this.m_Line].End.Index   = pin.Index;
            this.m_LineDatas[this.m_Line].End.Type    = pin.Type;
            this.m_LineDatas[this.m_Line].End.EndType = CQSaveFile_LinePoint.EndTypes.End;
            if (this.m_LineDatas[this.m_Line].Begin.Type == CQPin.Types.IN)
            {
                CQSaveFile_LinePoint pp1 = new CQSaveFile_LinePoint(this.m_LineDatas[this.m_Line].End);
                CQSaveFile_LinePoint pp2 = new CQSaveFile_LinePoint(this.m_LineDatas[this.m_Line].Begin);
                this.m_LineDatas[this.m_Line].Begin = pp1;
                this.m_LineDatas[this.m_Line].End   = pp2;
            }
            this.m_IsConnect = false;
        }
예제 #7
0
        private void togglebutton_simulation_Click(object sender, RoutedEventArgs e)
        {
            ToggleButton togglebutton = sender as ToggleButton;

            if (togglebutton != null)
            {
                List <QInput_Switch> inputs;
                List <QGate>         gates;
                List <QOutput_LED>   outputs;
                this.GetGates(out inputs, out gates, out outputs);
                if (togglebutton.IsChecked == true)
                {
                    List <FrameworkElement> gates1 = new List <FrameworkElement>();
                    for (int i = 0; i < gates.Count; i++)
                    {
                        gates1.Add(gates[i]);
                    }
                    for (int i = 0; i < outputs.Count; i++)
                    {
                        gates1.Add(outputs[i]);
                    }
                    for (int i = 0; i < inputs.Count; i++)
                    {
                        int            col = 1;
                        CQSimulateData sud = new CQSimulateData()
                        {
                            GateData = inputs[i].DataContext as CQInput_SwitchUI
                        };
                        sud.GateData.IsSimulate = true;

                        Dictionary <CQSimulateData, CQSimlateEndData> temp_suds = this.FindNexts(sud.GateData.ID, col, gates1);
                        CQSimulateData find_sud = null;
                        if (temp_suds.Count > 0)
                        {
                            this.FindGate(temp_suds.ElementAt(0).Key, this.m_Simulate, out find_sud);
                        }

                        if (find_sud == null)
                        {
                            foreach (var vvv1 in temp_suds)
                            {
                                sud.Nexts.Add(vvv1.Key, vvv1.Value);
                            }
                            //sud.Nexts.AddRange(temp_suds);
                            while (true)
                            {
                                List <CQSimulateData> temp_suds_find = temp_suds.Keys.ToList();

                                col = col + 1;
                                bool isend = true;
                                foreach (CQSimulateData simd in temp_suds_find)
                                {
                                    temp_suds = this.FindNexts(simd.GateData.ID, col, gates1);

                                    if (temp_suds.Count > 0)
                                    {
                                        isend = false;
                                        foreach (CQSimulateData ssd in temp_suds.Keys)
                                        {
                                            CQSimulateData oip;
                                            this.FindGate(ssd, new List <CQSimulateData>()
                                            {
                                                sud
                                            }, out oip);
                                            if (oip != null)
                                            {
                                                var v1_begin = this.m_LineDatas.Values.Where(x => x.End.GateID == ssd.GateData.ID);
                                                var v1_end   = this.m_LineDatas.Values.Where(x => x.Begin.GateID == ssd.GateData.ID);
                                                ssd.Nexts.Add(oip, new CQSimlateEndData(v1_begin.First().End.Index, v1_end.First().Begin.Index));
                                                isend = true;
                                                System.Diagnostics.Trace.WriteLine("");
                                            }
                                        }


                                        if (isend == false)
                                        {
                                            foreach (var vvv1 in temp_suds)
                                            {
                                                simd.Nexts.Add(vvv1.Key, vvv1.Value);
                                            }
                                        }
                                    }
                                }
                                if (isend == true)
                                {
                                    this.m_Simulate.Add(sud);

                                    break;
                                }
                            }
                        }
                        else
                        {
                            //find_sud.PinIndex = temp_suds[0].PinIndex;
                            //sud.Nexts.Add(find_sud);
                            foreach (var vvv1 in temp_suds)
                            {
                                sud.Nexts.Add(vvv1.Key, vvv1.Value);
                            }
                            this.m_Simulate.Add(sud);
                            //break;
                        }
                    }
                }
                else
                {
                    this.m_IsStartSimulate = false;
                    foreach (var vv in gates)
                    {
                        CQGateBaseUI gateui = vv.DataContext as CQGateBaseUI;
                        gateui.IsSimulate = false;
                    }
                    foreach (var vv in inputs)
                    {
                        CQGateBaseUI gateui = vv.DataContext as CQGateBaseUI;
                        gateui.IsSimulate = false;
                    }
                    foreach (var vv in outputs)
                    {
                        CQGateBaseUI gateui = vv.DataContext as CQGateBaseUI;
                        gateui.IsSimulate = false;
                    }
                    this.m_Simulate.Clear();
                }
            }
            if (this.m_Simulate.Count > 0)
            {
                if (this.m_Thread_Sim.IsBusy == false)
                {
                    this.m_IsStartSimulate = true;
                    this.m_Thread_Sim.RunWorkerAsync();
                }
            }
        }
예제 #8
0
        void ChangeLine(FrameworkElement gate)
        {
            CQGateBaseUI gateui = gate.DataContext as CQGateBaseUI;

            if (gateui != null)
            {
                var vv1 = this.m_LineDatas.Values.Where(x => x.Begin.GateID == gateui.ID);
                if (vv1 != null)
                {
                    foreach (var vv in vv1)
                    {
                        switch (vv.Begin.EndType)
                        {
                        case CQSaveFile_LinePoint.EndTypes.Start:
                        {
                            switch (vv.Begin.Type)
                            {
                            case CQPin.Types.IN:
                            {
                                vv.Line.X1 = gateui.Pin_in[vv.Begin.Index].ConnectPoint.X;
                                vv.Line.Y1 = gateui.Pin_in[vv.Begin.Index].ConnectPoint.Y;
                            }
                            break;

                            case CQPin.Types.OUT:
                            {
                                vv.Line.X1 = gateui.Pin_out[vv.Begin.Index].ConnectPoint.X;
                                vv.Line.Y1 = gateui.Pin_out[vv.Begin.Index].ConnectPoint.Y;
                            }
                            break;
                            }
                        }
                        break;

                        case CQSaveFile_LinePoint.EndTypes.End:
                        {
                            switch (vv.Begin.Type)
                            {
                            case CQPin.Types.IN:
                            {
                                vv.Line.X2 = gateui.Pin_in[vv.Begin.Index].ConnectPoint.X;
                                vv.Line.Y2 = gateui.Pin_in[vv.Begin.Index].ConnectPoint.Y;
                            }
                            break;

                            case CQPin.Types.OUT:
                            {
                                vv.Line.X2 = gateui.Pin_out[vv.Begin.Index].ConnectPoint.X;
                                vv.Line.Y2 = gateui.Pin_out[vv.Begin.Index].ConnectPoint.Y;
                            }
                            break;
                            }
                        }
                        break;
                        }
                    }
                }
                vv1 = this.m_LineDatas.Values.Where(x => x.End.GateID == gateui.ID);
                if (vv1 != null)
                {
                    foreach (var vv in vv1)
                    {
                        switch (vv.End.EndType)
                        {
                        case CQSaveFile_LinePoint.EndTypes.Start:
                        {
                            switch (vv.End.Type)
                            {
                            case CQPin.Types.IN:
                            {
                                vv.Line.X1 = gateui.Pin_in[vv.End.Index].ConnectPoint.X;
                                vv.Line.Y1 = gateui.Pin_in[vv.End.Index].ConnectPoint.Y;
                            }
                            break;

                            case CQPin.Types.OUT:
                            {
                                vv.Line.X1 = gateui.Pin_out[vv.End.Index].ConnectPoint.X;
                                vv.Line.Y1 = gateui.Pin_out[vv.End.Index].ConnectPoint.Y;
                            }
                            break;
                            }
                        }
                        break;

                        case CQSaveFile_LinePoint.EndTypes.End:
                        {
                            switch (vv.End.Type)
                            {
                            case CQPin.Types.IN:
                            {
                                vv.Line.X2 = gateui.Pin_in[vv.End.Index].ConnectPoint.X;
                                vv.Line.Y2 = gateui.Pin_in[vv.End.Index].ConnectPoint.Y;
                            }
                            break;

                            case CQPin.Types.OUT:
                            {
                                vv.Line.X2 = gateui.Pin_out[vv.End.Index].ConnectPoint.X;
                                vv.Line.Y2 = gateui.Pin_out[vv.End.Index].ConnectPoint.Y;
                            }
                            break;
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }