示例#1
0
        /// <summary>
        /// Parses the provided JSON string, and updates this <see cref="Circuit"/> to represent it.
        /// </summary>
        public void FromJson(string json)
        {
            JObject obj = JObject.Parse(json);

            Clear();
            foreach (JToken token in obj["components"])
            {
                string id   = token["id"].Value <string>();
                string type = token["type"].Value <string>();

                Type componentType = Type.GetType(type, false, true);
                if (componentType == null)
                {
                    Console.WriteLine("Unknown component type: " + type);
                    continue;
                }

                DigitalComponent component = (DigitalComponent)Activator.CreateInstance(componentType, id);
                component.FromJson(token);

                AddComponent(component);
            }

            foreach (JToken token in obj["wires"])
            {
                string p1FullId = token.First().Value <string>();
                string p2FullId = token.Last().Value <string>();

                AddWire(p1FullId, p2FullId);
            }
        }
示例#2
0
 /// <summary>
 /// Removes the given component from the circuit.
 /// </summary>
 public void RemoveComponent(DigitalComponent component)
 {
     if (component == null)
     {
         return;
     }
     RemoveComponent(component.Id);
 }
示例#3
0
        public FormRenameComponent(DigitalComponent component = null)
        {
            InitializeComponent();

            this.component = component;

            if (component != null)
            {
                txtComponentLabel.Text = component.Label;
            }
        }
示例#4
0
        /// <summary>
        /// Adds a component to the circuit. If the circuit already contains a component with the ID this method wont do anything.
        /// </summary>
        public void AddComponent(DigitalComponent component)
        {
            if (lookup.ContainsKey(component.Id))
            {
                Console.WriteLine($"Component with ID already in circuit: {component.Id}");
                return;
            }

            lookup.Add(component.Id, component);
            Components.Add(component);

            Console.WriteLine($"Added {component.GetType().Name} component with ID \"{component.Id}\"");
        }