Esempio n. 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);
            }
        }
Esempio n. 2
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);
                }
            }
        }