Exemple #1
0
 public TreeNode AddNodeToTree(PointOfInterest Point, TreeNode Parent)
 {
     return(Adapter.InsertNode(Parent, Point));
 }
Exemple #2
0
        /// <summary>
        /// Вычисляет место для вставки узла при перетаскивании
        /// </summary>
        /// <param name="tv">Дерево</param>
        /// <param name="x">Экранные координаты курсора</param>
        /// <param name="y">Экранные координаты курсора</param>
        /// <param name="NewParent">Узел, являющийся новым родителем</param>
        /// <param name="NewPos">Позиция среди подузлов этого родителя</param>
        public static void GetPositionToInsert(TreeView tv, TreeViewAdapter tva, int x, int y, out TreeNode NewParent, out int NewPos)
        {
            Point    pt = tv.PointToClient(new Point(x, y));
            TreeNode DestinationNode = tv.GetNodeAt(pt);

            if (DestinationNode == null)
            {
                NewParent = null;
                NewPos    = tv.Nodes.Count;
                return;
            }
            int             kind;
            PointOfInterest pti            = tva.GetPointByNode(DestinationNode);
            bool            NestingAllowed = pti != null;
            int             border         = DestinationNode.Bounds.Height / 4;

            if (pt.Y <= (DestinationNode.Bounds.Top + border))
            {
                kind = -1;  //верхняя четверть - перед узлом
            }
            else if (pt.Y >= (DestinationNode.Bounds.Bottom - border))
            {
                if (!DestinationNode.IsExpanded)
                {
                    kind = 1;   //нижняя четверть неразвернутого узла - после узла
                }
                else
                {
                    kind = 0;   //нижняя четверть развернутого узла - внутрь
                }
            }
            else
            {
                kind = 0;       //Иначе - внутрь
            }
            if (kind == 0 && !NestingAllowed)
            {
                if (pt.Y <= (DestinationNode.Bounds.Top + 2 * border))
                {
                    kind = -1;  //если внутрь нельзя и верхняя половина - перед узлом
                }
                else
                {
                    kind = 1;   //Внутрь нельзя и нижняя половина - после узла
                }
            }
            if (kind == -1)
            {
                //Перед узлом
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                {
                    NewPos = tv.Nodes.IndexOf(DestinationNode);
                }
                else
                {
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode);
                }
            }
            else if (kind == 1)
            {
                //После узла
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                {
                    NewPos = tv.Nodes.IndexOf(DestinationNode) + 1;
                }
                else
                {
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode) + 1;
                }
            }
            else
            {
                //Внутрь узла
                NewParent = DestinationNode;
                NewPos    = DestinationNode.Nodes.Count;
            }
        }
Exemple #3
0
        private static XmlNode BuildPoint(PointOfInterest Point, XmlDocument Doc)
        {
            XmlElement Result = Doc.CreateElement("Node");

            if (!string.IsNullOrWhiteSpace(Point.ID))
            {
                XmlAttribute Name = Doc.CreateAttribute("ID");
                Result.Attributes.Append(Name);
                Name.InnerText = Point.ID;
            }
            if (!string.IsNullOrWhiteSpace(Point.Title))
            {
                XmlAttribute Name = Doc.CreateAttribute("Name");
                Result.Attributes.Append(Name);
                Name.InnerText = Point.Title;
            }
            if (!string.IsNullOrWhiteSpace(Point.FileName))
            {
                XmlElement FileName = Doc.CreateElement("FileName");
                FileName.InnerText = Point.FileName;
                Result.AppendChild(FileName);
            }
            if (!string.IsNullOrWhiteSpace(Point.Note))
            {
                XmlElement Note = Doc.CreateElement("Note");
                Note.InnerText = Point.Note;
                Result.AppendChild(Note);
            }
            if (!string.IsNullOrWhiteSpace(Point.Text))
            {
                XmlElement Text = Doc.CreateElement("Text");
                Text.InnerText = Point.Text;
                Result.AppendChild(Text);
            }

            if (Point.Context != null && Point.Context.Count != 0)
            {
                Result.AppendChild(BuildOuterContext(Point.Context, Doc));
            }
            if (Point.InnerContext != null && Point.InnerContext.Count != 0)
            {
                Result.AppendChild(BuildInnerContext(Point.InnerContext, Doc));
            }
            if (Point.Items != null && Point.Items.Count != 0)
            {
                XmlElement Items = Doc.CreateElement("Items");
                foreach (PointOfInterest p in Point.Items)
                {
                    Items.AppendChild(BuildPoint(p, Doc));
                }
                Result.AppendChild(Items);
            }

            XmlAttribute NearLAttr = Doc.CreateAttribute("NL");
            XmlAttribute NearGAttr = Doc.CreateAttribute("NG");

            NearLAttr.InnerText = Point.NearL.ToString();
            NearGAttr.InnerText = Point.NearG.ToString();
            Result.Attributes.Append(NearLAttr);
            Result.Attributes.Append(NearGAttr);

            return(Result);
        }
Exemple #4
0
 /// <summary>
 /// Отображает свойства выделенного подаспекта в панели Properties (необязательно)
 /// </summary>
 /// <param name="point"></param>
 /// <param name="node"></param>
 public virtual void UpdateSubAspectProperties(PointOfInterest point, System.Windows.Forms.TreeNode node)
 {
 }
 /// <summary>
 /// Сохраняет состояние точки перед действием
 /// Вызывается при любом изменении аспектного дерева
 /// </summary>
 /// <param name="point">Исходная точка</param>
 /// <param name="parent">Исходный родитель точки</param>
 /// <param name="kind">Тип действия</param>
 public void SavePointState(PointOfInterest point, PointOfInterest parent, ActionKind kind, PointOfInterest newParent = null)
 {
     UndoStack.Push(CreateUndoUnit(point, parent, kind, newParent));
     RedoStack.Clear();
 }
        /// <summary>
        /// Создавет экземпляр UndoAction по нынешнему состоянию точки
        /// При kind == move, параметр newParent обязателен
        /// </summary>
        /// <param name="point">Исходная точка</param>
        /// <param name="parent">Исходный родитель точки</param>
        /// <param name="kind">Тип действия</param>
        private UndoUnit CreateUndoUnit(PointOfInterest point, PointOfInterest parent, ActionKind kind, PointOfInterest newParent = null)
        {
            if (kind == ActionKind.Move && newParent == null)
            {
                throw new ArgumentException();
            }
            UndoUnit undo = new UndoUnit();

            undo.Kind             = kind;
            undo.OriginalParent   = parent;
            undo.OriginalPosition = parent == null ? 0 : parent.Items.IndexOf(point);
            undo.OriginalPointRef = point;
            if (kind == ActionKind.Edit)
            {
                undo.OriginalPointContent = point.ClonePointAssignItems();
            }
            if (kind == ActionKind.Move)
            {
                undo.OriginalPointContent = newParent;
            }

            return(undo);
        }