示例#1
0
        private void addComponentButton_Click(object sender, EventArgs e)
        {
            Graphics        graphics          = systemPanel1.CreateGraphics();
            SystemComponent selectedComponent = componentsList.ElementAt(componentsListBox.SelectedIndex);
            SystemComponent componentToAdd;

            if (!system.ContainsComponentOfGivenType(selectedComponent))
            {
                componentToAdd = selectedComponent;
            }
            else
            {
                componentToAdd = (SystemComponent)selectedComponent.Clone();
            }
            if (componentToAdd.SignalAttached == false)
            {
                componentToAdd.Draw();
                systemPanel1.Controls.Add(componentToAdd);
                if (!system.Components.Contains(componentToAdd))
                {
                    system.Components.AddLast(componentToAdd);
                }
                componentToAdd.System = system;
                componentToAdd.GetAllPins().ForEach(p => p.Clipboard = this);
            }

            DisableCloseButton();
        }
        /// <summary>
        /// Remove component from system.
        /// </summary>
        /// <param name="component">
        /// Component to be removed.
        /// </param>
        public void RemoveComponent(SystemComponent component)
        {
            components.Remove(component);

            if (!components.Any())
            {
                clipboard.EnableCloseButton();
            }
        }
 /// <summary>
 /// Checks if system contains given type of the component.
 /// </summary>
 /// <param name="selectedComponent">
 /// Component that should be checked.
 /// </param>
 /// <returns>
 /// True if system contains component and false otherwise.
 /// </returns>
 public bool ContainsComponentOfGivenType(SystemComponent selectedComponent)
 {
     foreach (SystemComponent component in components)
     {
         if (component.Name.ToLower().Equals(selectedComponent.Name.ToLower()))
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
        /// <summary>
        /// Creates one object of Port class.
        /// </summary>
        /// <param name="name">
        /// Name of the port.
        /// </param>
        /// <param name="size">
        /// Size of the port in bits.
        /// </param>
        /// <param name="val">
        /// Initial value of the port.
        /// </param>
        public Port(string name, SystemComponent component, int size = 0, int val = 0)
        {
            this.name = name;
            this.size = size;
            if (pins == null)
            {
                pins = new Pin[size];
                for (var i = 0; i < size; i++)
                {
                    pins[i] = new Pin(this, i);
                }
            }

            this.Val       = val;
            this.component = component;
            Initializing   = false;
        }
示例#5
0
        private void ComponentsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedComponent = _componentsList.ElementAt(ComponentsComboBox.SelectedIndex);

            if (_selectedComponent.System != null)
            {
                MessageBox.Show("This component is already added to system. Please remove it in order to change its design");
            }
            else
            {
                BrowseComponentImageButton.Enabled = true;
                PinsList.Items.Clear();
                _selectedComponent.Ports.ForEach(port => port.GetAllPins().ForEach(pin => PinsList.Items.Add(pin.Name)));
                PinsList.Enabled     = true;
                AddPinButton.Enabled = true;
                SaveButton.Enabled   = false;
                _addedImages.Clear();
                _lastLevel = 0;
            }
        }
        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);
                    }
                }
            }
        }
示例#7
0
 public void AddToSystemComponent(SystemComponent component)
 {
     component.Controls.Add(this);
     _addedToComponent = true;
 }