Example #1
0
        /// <summary>
        ///     Конструктор.
        /// </summary>
        /// <param name="node">Нода.</param>
        public CircuitTreeNode(ICircuitNode node)
        {
            Value = node ?? throw new ArgumentNullException(nameof(node));

            Value = node;

            switch (node)
            {
            case SeriesSubcircuit series:
                Text = $"[Послед] (Id:{series.Id})";
                break;

            case ParallelSubcircuit parallel:
                Text = $"[Паралл] (Id:{parallel.Id})";
                break;

            case Resistor resistor:
                Text = $"[R] [{resistor.Value}] ({resistor.Name})";
                break;

            case Capacitor capacitor:
                Text = $"[C] [{capacitor.Value}] ({capacitor.Name})";
                break;

            case Inductor inductor:
                Text = $"[L] [{inductor.Value}] ({inductor.Name})";
                break;

            default:
                throw new InvalidOperationException(nameof(node));
            }
        }
 public void Add(ICircuitNode node)
 {
     if (!m_nodes.Contains(node))
     {
         m_nodes.Add(node);
     }
 }
Example #3
0
 private void TreeViewCircuit_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node is CircuitTreeNode treeNode)
     {
         _currentNode = treeNode.Value;
     }
 }
Example #4
0
        public bool ConnectToNode(ICircuitNode circuitNode)
        {
            circuitNode.ConnectFrom(this);
            m_connectedNodes.Add(circuitNode);

            //TODO: detect anomalies
            return(true);
        }
Example #5
0
 public static List <ICircuitNode> FindPreviousEndPoints(this ICircuitNode self)
 {
     return(self.Previouses
            .Select(previous =>
                    previous.IsEndPoint
                 ? new List <ICircuitNode>()
     {
         previous
     }
                 : previous.FindPreviousEndPoints())
            .SelectMany(i => i)
            .ToList());
 }
Example #6
0
        /// <summary>
        ///     Добавить новый узел в дети узла.
        /// </summary>
        /// <param name="node">Узел в который добавляют детей.</param>
        /// <param name="newNode">Новый узел.</param>
        public void AddAfter(ICircuitNode node, ICircuitNode newNode)
        {
            if (newNode == null)
            {
                throw new ArgumentNullException(nameof(newNode),
                                                "Новый узел не может быть не определен.");
            }

            if (node == newNode)
            {
                throw new ArgumentOutOfRangeException("Узел был равен новому узлу.");
            }

            if (IsEmpty())
            {
                Root = newNode;
                return;
            }

            if (!IsEmpty() && node == null)
            {
                throw new ArgumentNullException(nameof(newNode),
                                                "Выберите узел относительно которого будет происходить добавление. Для добавления нового корня сделайте очистку цепи или удалите корень.");
            }

            if (node is ElementBase)
            {
                throw new ArgumentException("Узел не может быть элементом.");
            }

            if (node is SubcircuitBase subcircuit)
            {
                if (subcircuit.Nodes == null)
                {
                    throw new InvalidOperationException("Дети узла были null");
                }

                subcircuit.Nodes.Add(newNode);

                if (newNode is SubcircuitBase newSubcircuit)
                {
                    newSubcircuit.Parent = subcircuit;
                    ;
                }

                if (newNode is ElementBase newElementBase)
                {
                    newElementBase.Parent = subcircuit;
                }
            }
        }
Example #7
0
 public static List <ICircuitNode> FindNextEndPoints(this ICircuitNode self)
 {
     Console.WriteLine(self.GetType());
     return(self.Nexts
            .Select(next =>
                    next.IsEndPoint
                 ? new List <ICircuitNode>()
     {
         next
     }
                 : next.FindNextEndPoints())
            .SelectMany(i => i)
            .ToList());
 }
Example #8
0
        /// <summary>
        ///     Удалить узел.
        /// </summary>
        /// <param name="node">Узел.</param>
        /// <returns>Удален ли узел.</returns>
        public void Remove(ICircuitNode node)
        {
            if (IsEmpty())
            {
                throw new InvalidOperationException("Цепь пуста. Удалять нечего.");
            }

            if (node == null)
            {
                throw new ArgumentNullException(nameof(node),
                                                "Узел не может быть null, потому что в цепи есть узлы.");
            }

            if (node == Root)
            {
                Root = null;
                return;
            }

            node.Parent.Nodes.Remove(node);
        }
Example #9
0
 public bool ConnectToNode(ICircuitNode circuitNode)
 {
     throw new NotImplementedException();
 }
Example #10
0
 /// <summary>
 ///     Очистить TreeViewCircuit
 /// </summary>
 private void ClearTreeViewCircuit()
 {
     _treeViewCircuit.Nodes.Clear();
     _currentNode = null;
 }
Example #11
0
 /// <summary>
 ///     Очистить цепь.
 /// </summary>
 public void Clear()
 {
     Root = null;
 }