Beispiel #1
0
 public override void ShiftNodes(int offset)
 {
     foreach (var node in LeftNodes.Union(RightNodes))
     {
         node.Column += 1;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Given a graph, find the list of possible paths for a train
        /// </summary>
        private void FindPossiblePaths()
        {
            var activePaths      = LeftNodes.Select(n => new PossiblePath(n)).ToList();
            var newPath          = new List <PossiblePath>();
            var allPathsFinished = true;

            do
            {
                allPathsFinished = true;
                activePaths.AddRange(newPath);
                newPath.Clear();
                foreach (var path in activePaths)
                {
                    if (path.lastNode.OutputEdges.Any())
                    {
                        allPathsFinished = false;

                        for (int n = 1; n < path.lastNode.OutputEdges.Count; ++n)
                        {
                            newPath.Add(new PossiblePath(path, path.lastNode.OutputEdges[n]));
                        }

                        // Continue first path
                        path.Add(path.lastNode.OutputEdges[0]);
                    }
                }
            } while (newPath.Any() || !allPathsFinished);

            PossiblePathsOrderedByPenalty = activePaths.OrderBy(p => p.Penalty).ThenBy(p => p.NbResourcesOccupied).ToArray();
        }
Beispiel #3
0
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            base.ReadXml(reader);

            List <TopolotyNode> leftNodes = new List <TopolotyNode>();

            foreach (var item in LeftNodes)
            {
                leftNodes.Add(new TopolotyNode(item.ConnectableDevice));
            }
            LeftNodes.Clear();
            foreach (var item in leftNodes)
            {
                LeftNodes.Add(item);
            }

            List <TopolotyNode> rightNodes = new List <TopolotyNode>();

            foreach (var item in RightNodes)
            {
                rightNodes.Add(new TopolotyNode(item.ConnectableDevice));
            }
            RightNodes.Clear();
            foreach (var item in rightNodes)
            {
                RightNodes.Add(item);
            }
        }
Beispiel #4
0
 public void BindOneWay(BindingNode nextNode)
 {
     if (!LeftNodes.Contains(nextNode))
     {
         LeftNodes.Add(nextNode);
     }
     nextNode.OneWay = true;
 }
Beispiel #5
0
        public void RemoveRightBindings(BindingNode node)
        {
            bool removed = LeftNodes.Remove(node);

            if (LeftNodes.Count == 0)
            {
                RemoveNode();
            }
        }
Beispiel #6
0
        protected override void RemoveANode(rMindBaseNode node)
        {
            var outMax = m_parent.HLines.Where(x => x != this).Max(x => x.LeftNodes.Count);

            if (LeftNodes.Count > outMax)
            {
                /* Если количество занимаемых колонок больше, чем у остальных строк
                 * Нужно удалять колонку грида и сдвинуть все узлы. Кроме своих.
                 */
                var nodes = m_parent.HLines.Where(x => x != this).Select(x => x as rMindLine)
                            .Union(m_parent.VLines.Select(x => x as rMindLine))
                            .Select(x => x.NodesA.Union(x.NodesB));

                foreach (var arr in nodes)
                {
                    foreach (var n in arr)
                    {
                        n.Column--;
                    }
                }

                // Среди своих узлов удаляем только те, что правее
                var offsetNodes = LeftNodes.Union(RightNodes).Where(x => x.Column > node.Column);
                foreach (var n in offsetNodes)
                {
                    n.Column--;
                }

                if (m_parent.Template.ColumnDefinitions.Count > 1)
                {
                    m_parent.Template.ColumnDefinitions.Remove(
                        m_parent.Template.ColumnDefinitions.Last()
                        );
                }
            }
            else
            {
                var offsetNodes = LeftNodes.Where(x => x.Column < node.Column);
                foreach (var n in offsetNodes)
                {
                    n.Column++;
                }
            }

            LeftNodes.Remove(node);
            m_parent.UpdateBase();
            m_parent.RemoveNode(node);
        }
Beispiel #7
0
        public rMindBaseNode AddLeftNode()
        {
            int currentCount = m_parent.HLines.Max(line => line.LeftNodes.Count);

            if (LeftNodes.Count + 1 > currentCount)
            {
                /*
                 * если количество верхних узлов равно максимальному количеству по линиям
                 * добавляем новую строку.
                 */
                m_parent.Template.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width    = GridLength.Auto,
                    MinWidth = 24
                });

                foreach (var line in m_parent.HLines)
                {
                    line.ShiftNodes(1);
                }

                foreach (var line in m_parent.VLines)
                {
                    foreach (var n in line.TopNodes.Union(line.BottomNodes))
                    {
                        n.Column += 1;
                    }
                }
            }

            var node = m_parent.CreateNode();

            int idx = currentCount - LeftNodes.Count - 1;

            node.SetCell(idx > 0 ? idx : 0, m_parent.GetLineIndex(this));
            node.NodeOrientation = rMindNodeOriantation.Left;
            LeftNodes.Add(node);

            m_parent.UpdateBase();

            return(node);
        }
        private void GenerateMeshNodes(int LElements, int HElements)
        {
            Nodes.Clear();
            LeftNodes.Clear();
            RightNodes.Clear();

            int    indexCur = 0;
            double xCur     = 0;
            double yCur     = _shape.H / 2;

            if (HElements % 2 == 1)
            {
                HElements++;
            }

            int HNodes = HElements + 1;
            int LNodes = LElements + 1;

            double xStep = _shape.L / Convert.ToDouble(LElements);
            double yStep = _shape.H / Convert.ToDouble(HElements);

            int HNodesdiv2 = HNodes / 2;

            for (int i = 0; i < HNodesdiv2; i++)
            {
                if (i == 0)
                {
                    TopNodes.Clear();
                }
                for (int j = 0; j < LNodes; j++)
                {
                    Node node = new Node();
                    node.Index = indexCur;
                    node.X     = xCur;
                    node.Y     = yCur;
                    Nodes.Add(node);
                    if (j == 0)
                    {
                        LeftNodes.Add(node);
                    }
                    if (j == (LNodes - 1))
                    {
                        RightNodes.Add(node);
                    }

                    indexCur++;
                    xCur += xStep;
                    if (i == 0)
                    {
                        TopNodes.Add(node);
                    }
                }
                yCur -= yStep;
                xCur  = 0;
            }

            xCur = 0;
            yCur = 0;
            MiddleNodes.Clear();
            for (int j = 0; j < LNodes; j++)
            {
                Node node = new Node();
                node.Index = indexCur;
                node.X     = xCur;
                node.Y     = yCur;
                Nodes.Add(node);
                MiddleNodes.Add(node);
                if (j == 0)
                {
                    LeftNodes.Add(node);
                }
                if (j == (LNodes - 1))
                {
                    RightNodes.Add(node);
                }
                indexCur++;
                xCur += xStep;
            }

            xCur  = 0;
            yCur -= yStep;
            for (int i = 0; i < HNodesdiv2; i++)
            {
                if (i == (HNodesdiv2 - 1))
                {
                    BottomNodes.Clear();
                }
                for (int j = 0; j < LNodes; j++)
                {
                    Node node = new Node();
                    node.Index = indexCur;
                    node.X     = xCur;
                    node.Y     = yCur;
                    Nodes.Add(node);
                    if (j == 0)
                    {
                        LeftNodes.Add(node);
                    }
                    if (j == (LNodes - 1))
                    {
                        RightNodes.Add(node);
                    }

                    if (i == (HNodesdiv2 - 1))
                    {
                        BottomNodes.Add(node);
                    }
                    indexCur++;
                    xCur += xStep;
                }
                yCur -= yStep;
                xCur  = 0;
            }
        }