示例#1
0
 public void RemovePin(Pin pin)
 {
     DesignPanel.Controls.Remove(pin);
     PinsList.Items.Add(pin.Name);
     SaveButton.Enabled = false;
 }
        public void LoadSystemFromFile(string fileName)
        {
            signals    = new LinkedList <Signal>();
            Buses      = new LinkedList <Bus>();
            components = new LinkedList <SystemComponent>();
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);
            XmlNode systemNode = doc.FirstChild;

            foreach (XmlNode childNode in systemNode.ChildNodes)
            {
                if (childNode.Name.Equals("components"))
                {
                    foreach (XmlNode componentNode in childNode.ChildNodes)
                    {
                        SystemComponent component = clipboard.Component.First(c => c.Name == componentNode.Attributes["name"].Value);
                        component.Name     = componentNode.Attributes["name"].Value;
                        component.System   = this;
                        component.Location = new Point(Convert.ToInt32(componentNode.Attributes["x"].Value), Convert.ToInt32(componentNode.Attributes["y"].Value));
                        components.AddLast(component);
                    }
                }
                else if (childNode.Name.Equals("signals"))
                {
                    foreach (XmlNode signalNode in childNode.ChildNodes)
                    {
                        Signal signal = new Signal(this);
                        foreach (XmlNode innerNode in signalNode.ChildNodes)
                        {
                            switch (innerNode.Name)
                            {
                            case "lines":
                                foreach (XmlNode lineNode in innerNode.ChildNodes)
                                {
                                    int  x1   = Convert.ToInt32(lineNode.Attributes["x1"].Value);
                                    int  x2   = Convert.ToInt32(lineNode.Attributes["x2"].Value);
                                    int  y1   = Convert.ToInt32(lineNode.Attributes["y1"].Value);
                                    int  y2   = Convert.ToInt32(lineNode.Attributes["y2"].Value);
                                    Line line = new Line(1, x1, y1, x2, y2, signal);
                                    signal.Lines.AddLast(line);
                                }
                                break;

                            case "pins":
                                foreach (XmlNode pinNode in innerNode.ChildNodes)
                                {
                                    Pin pin = components.First(c => c.Name == pinNode.Attributes["component_name"].Value).GetPin(pinNode.Attributes["pin_name"].Value);
                                    pin.Signal    = signal;
                                    pin.Clipboard = clipboard;
                                    signal.Pins.AddLast(pin);
                                }
                                break;

                            case "name":
                                signal.Names.AddLast(innerNode.InnerText.Trim());
                                break;

                            default:
                                break;
                            }
                        }
                        signals.AddLast(signal);
                    }
                }
                else if (childNode.Name.Equals("buses"))
                {
                    foreach (XmlNode busNode in childNode.ChildNodes)
                    {
                        Bus bus = new Bus(this);
                        foreach (XmlNode innerNode in busNode.ChildNodes)
                        {
                            switch (innerNode.Name)
                            {
                            case "lines":
                                foreach (XmlNode lineNode in innerNode.ChildNodes)
                                {
                                    int  x1   = Convert.ToInt32(lineNode.Attributes["x1"].Value);
                                    int  x2   = Convert.ToInt32(lineNode.Attributes["x2"].Value);
                                    int  y1   = Convert.ToInt32(lineNode.Attributes["y1"].Value);
                                    int  y2   = Convert.ToInt32(lineNode.Attributes["y2"].Value);
                                    Line line = new Line(5, x1, y1, x2, y2);
                                    line.ContainedByBus = bus;
                                    bus.Lines.AddLast(line);
                                }
                                break;

                            case "signal":
                                string signalName = innerNode.InnerText.Trim();
                                Signal signal     = signals.First(s => s.Names.Any(n => n == signalName));
                                bus.Signals.AddLast(signal);
                                signal.Bus = bus;
                                break;

                            case "name":
                                string name = innerNode.InnerText.Trim();
                                bus.Names.AddLast(name);
                                break;

                            default:
                                break;
                            }
                        }
                        foreach (Signal s in bus.Signals)
                        {
                            foreach (Line l in bus.Lines)
                            {
                                s.Lines.AddLast(l);
                            }
                        }
                        Buses.AddLast(bus);
                    }
                }
            }
        }