예제 #1
0
 /// <summary>
 /// 删除梯形图节点
 /// </summary>
 public bool Delete(LCNode delnode)
 {
     // 不存在
     if (nodedict[delnode.X, delnode.Y] != delnode)
     {
         return(false);
     }
     // 链接解除
     if (delnode.Left != null)
     {
         delnode.Left.Right = null;
     }
     if (delnode.Right != null)
     {
         delnode.Right.Left = null;
     }
     if (delnode.Up != null)
     {
         delnode.Up.Down = null;
     }
     if (delnode.Down != null)
     {
         delnode.Down.Up = null;
     }
     if (delnode.RiDo != null)
     {
         delnode.RiDo.LeUp = null;
     }
     if (delnode.RiUp != null)
     {
         delnode.RiUp.LeDo = null;
     }
     if (delnode.LeDo != null)
     {
         delnode.LeDo.RiUp = null;
     }
     if (delnode.LeUp != null)
     {
         delnode.LeUp.RiDo = null;
     }
     nodes.Remove(delnode);
     nodedict[delnode.X, delnode.Y] = default(LCNode);
     return(true);
 }
예제 #2
0
        /// <summary>
        /// 添加梯形图节点
        /// </summary>
        public bool Insert(LCNode newnode)
        {
            LCNode node = null;

            // 节点已经存在的话
            node = nodedict[newnode.X, newnode.Y];
            if (node != null)
            {
                return(false);
            }
            // 链接相邻节点
            node = nodedict[newnode.X - 1, newnode.Y];
            if (node != default(LCNode))
            {
                node.Right   = newnode;
                newnode.Left = node;
            }
            node = nodedict[newnode.X + 1, newnode.Y];
            if (node != default(LCNode))
            {
                node.Left     = newnode;
                newnode.Right = node;
            }
            node = nodedict[newnode.X, newnode.Y - 1];
            if (node != default(LCNode))
            {
                node.Down  = newnode;
                newnode.Up = node;
            }
            node = nodedict[newnode.X, newnode.Y + 1];
            if (node != default(LCNode))
            {
                node.Up      = newnode;
                newnode.Down = node;
            }
            node = nodedict[newnode.X + 1, newnode.Y + 1];
            if (node != default(LCNode))
            {
                node.LeUp    = newnode;
                newnode.RiDo = node;
            }
            node = nodedict[newnode.X + 1, newnode.Y - 1];
            if (node != default(LCNode))
            {
                node.LeDo    = newnode;
                newnode.RiUp = node;
            }
            node = nodedict[newnode.X - 1, newnode.Y - 1];
            if (node != default(LCNode))
            {
                node.RiDo    = newnode;
                newnode.LeUp = node;
            }
            node = nodedict[newnode.X - 1, newnode.Y + 1];
            if (node != default(LCNode))
            {
                node.RiUp    = newnode;
                newnode.LeDo = node;
            }
            nodes.Add(newnode);
            nodedict.Set(newnode);
            return(true);
        }
예제 #3
0
 /// <summary>
 /// 对梯形图中的线路进行合并并标号
 /// </summary>
 private bool LGVSearch(LCNode node, Direction dir, int value)
 {
     if (node == null)
     {
         return(false);
     }
     // 线路在元件右
     if (dir == Direction.Right)
     {
         if (node.RNodeID != 0)
         {
             return(false);
         }
         node.RNodeID = value;
         // 该元件水平方向可导通
         if (node.Type.Equals(String.Empty) && node.HAccess)
         {
             LGVSearch(node, Direction.Left, value);
         }
         // 存在右方相邻的元件
         if (node.Right != null)
         {
             LGVSearch(node.Right, Direction.Left, value);
         }
         // 存在上方相邻且可以导通的元件
         if (node.RiUp != null && node.RiUp.VAccess)
         {
             LGVSearch(node.RiUp, Direction.Left, value);
             if (node.Up != null)
             {
                 LGVSearch(node.Up, Direction.Right, value);
             }
         }
         // 存在下方相邻且可以导通的元件
         if (node.Right != null && node.Right.VAccess)
         {
             if (node.Down != null)
             {
                 LGVSearch(node.Down, Direction.Right, value);
             }
             if (node.RiDo != null)
             {
                 LGVSearch(node.RiDo, Direction.Left, value);
             }
         }
     }
     // 线路在元件左
     if (dir == Direction.Left)
     {
         if (node.LNodeID != 0)
         {
             return(false);
         }
         node.LNodeID = value;
         // 该元件水平方向可导通
         if (node.Type.Equals(String.Empty) && node.HAccess)
         {
             LGVSearch(node, Direction.Right, value);
         }
         // 存在左方相邻的元件
         if (node.Left != null)
         {
             LGVSearch(node.Left, Direction.Right, value);
         }
         // 存在上方相邻且可以导通的元件
         if (node.Up != null && node.Up.VAccess)
         {
             LGVSearch(node.Up, Direction.Left, value);
             if (node.LeUp != null)
             {
                 LGVSearch(node.LeUp, Direction.Right, value);
             }
         }
         // 存在下方相邻且可以导通的元件
         if (node.VAccess)
         {
             if (node.Down != null)
             {
                 LGVSearch(node.Down, Direction.Left, value);
             }
             if (node.LeDo != null)
             {
                 LGVSearch(node.LeDo, Direction.Right, value);
             }
         }
     }
     return(true);
 }