示例#1
0
        bool FindGate(CQSimulateData sd, List <CQSimulateData> src, out CQSimulateData dst)
        {
            dst = null;
            bool result = false;
            List <CQSimulateData> temp;

            for (int i = 0; i < src.Count; i++)
            {
                temp = src[i].Nexts.Keys.ToList();
                bool isend = false;
                var  hr1   = temp.FirstOrDefault(x => x.GateData.ID == sd.GateData.ID);
                if (hr1 != null)
                {
                    dst   = hr1;
                    isend = true;
                    break;
                }
                else
                {
                    while (true)
                    {
                        if (temp.All(x => x.Nexts.Count == 0) == true)
                        {
                            isend = true;
                        }
                        else
                        {
                            var hr = temp.SelectMany(x => x.Nexts).FirstOrDefault(x => x.Key.GateData.ID == sd.GateData.ID);
                            if (hr.Key != null)
                            {
                                dst   = hr.Key;
                                isend = true;
                                break;
                            }
                            else
                            {
                                temp = temp.Select(x => x.Nexts.Keys.ToList()).ElementAt(0);
                            }
                        }

                        if (isend == true)
                        {
                            break;
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
        Dictionary <CQSimulateData, CQSimlateEndData> FindNexts(string id, int col, List <FrameworkElement> gates)
        {
            Dictionary <CQSimulateData, CQSimlateEndData> suds = new Dictionary <CQSimulateData, CQSimlateEndData>();
            var            v1 = this.m_LineDatas.Values.Where(x => x.Begin.GateID == id);
            CQSimulateData sud1;

            foreach (CQSaveFile_Line line in v1)
            {
                CQGateBaseUI     gateui;
                FrameworkElement gate;
                this.FineGateFromGateID(line.End.GateID, gates, out gate, out gateui);
                if (gateui != null)
                {
                    sud1     = new CQSimulateData();
                    sud1.Col = col++;
                    //sud1.PinIndex = line.End.Index;
                    sud1.GateData            = gateui;
                    sud1.GateData.IsSimulate = true;
                    suds.Add(sud1, new CQSimlateEndData(line.Begin.Index, line.End.Index));
                }
            }
            return(suds);
        }
示例#3
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();
                }
            }
        }