Beispiel #1
0
        /// <summary>
        /// It returns a string containing current element info for logging purposes.
        /// </summary>
        /// <returns></returns>
        public string ElementInfo()
        {
            var sMsg = "InternalId:" + InternalId.ToString();

            if (ParentElement != null)
            {
                sMsg += " - Parent:" + ParentElement.GetInternalId().ToString();
            }

            if (PreviousElement != null)
            {
                sMsg += " - Previous:" + PreviousElement.GetInternalId().ToString();
            }

            if (NextElement != null)
            {
                sMsg += " - Next:" + NextElement.GetInternalId().ToString();
            }

            if (ChildElement != null)
            {
                sMsg += " - Child:" + ChildElement.GetInternalId().ToString();
            }

            return(sMsg);
        }
Beispiel #2
0
        private bool DeleteElement(SvgElement element, bool deleteFromParent)
        {
            if (element == null)
            {
                return(false);
            }

            var parent = element.GetParent();

            if (parent == null)
            {
                // root node cannot be delete!
                ErrorMessage = "root node cannot be delete!";
                return(false);
            }

            // set the Next reference of the previous
            if (element.GetPrevious() != null)
            {
                element.GetPrevious().SetNext(element.GetNext());
            }

            // set the Previous reference of the next
            if (element.GetNext() != null)
            {
                element.GetNext().SetPrevious(element.GetPrevious());
            }

            // check if the element is the first child
            // the deleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if (deleteFromParent)
            {
                if (IsFirstChild(element))
                {
                    // set the Child reference of the parent to the next
                    element.GetParent().SetChild(element.GetNext());
                }
            }

            // delete its children
            var child = element.GetChild();

            while (child != null)
            {
                DeleteElement(child, false);
                child = child.GetNext();
            }

            // delete the element from the colloection
            svgDocumentElements.Remove(element.GetInternalId());

            return(true);
        }
Beispiel #3
0
        private bool IsLastSibling(SvgElement element)
        {
            SvgElement last = GetLastSibling(element);

            if (last == null)
            {
                return(false);
            }

            return(element.GetInternalId() == last.GetInternalId());
        }
Beispiel #4
0
        private bool IsFirstChild(SvgElement element)
        {
            if (element.GetParent() == null)
            {
                return(false);
            }

            if (element.GetParent().GetChild() == null)
            {
                return(false);
            }

            return(element.GetInternalId() == element.GetParent().GetChild().GetInternalId());
        }
Beispiel #5
0
        /// <summary>
        /// It adds the new element eleToAdd as the last children of the given parent element.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToAdd">Element to be added.</param>
        /// <returns>
        /// true if the element is successfully, false otherwise
        /// </returns>
        public bool AddElement(SvgElement parent, SvgElement eleToAdd)
        {
            if (eleToAdd == null || svgRoot == null)
            {
                ErrorMessage = "Element to be added and Svg Root Element were both Null.";
                return(false);
            }

            SvgElement parentToAdd = svgRoot;

            if (parent != null)
            {
                parentToAdd = parent;
            }

            eleToAdd.SetInternalId(svgDocumentNextInternalId++);
            svgDocumentElements.Add(eleToAdd.GetInternalId(), eleToAdd);

            eleToAdd.SetParent(parentToAdd);
            if (parentToAdd.GetChild() == null)
            {
                // the element is the first child
                parentToAdd.SetChild(eleToAdd);
            }
            else
            {
                // add the element as the last sibling
                var last = GetLastSibling(parentToAdd.GetChild());

                if (last != null)
                {
                    last.SetNext(eleToAdd);
                    eleToAdd.SetPrevious(last);
                }
            }

            return(true);
        }
Beispiel #6
0
        private bool IsLastSibling(SvgElement element)
        {
            SvgElement last = GetLastSibling(element);

            if ( last == null )
            {
                return false;
            }

            return (element.GetInternalId() == last.GetInternalId());
        }
Beispiel #7
0
        private bool IsFirstChild(SvgElement element)
        {
            if ( element.GetParent() == null )
            {
                return false;
            }

            if ( element.GetParent().GetChild() == null )
            {
                return false;
            }

            return (element.GetInternalId() == element.GetParent().GetChild().GetInternalId());
        }
Beispiel #8
0
        private bool DeleteElement(SvgElement element, bool deleteFromParent)
        {
            if ( element == null )
            {
                return false;
            }

            var parent = element.GetParent();
            if ( parent == null )
            {
                // root node cannot be delete!
                ErrorMessage = "root node cannot be delete!";
                return false;
            }

            // set the Next reference of the previous
            if ( element.GetPrevious() != null )
            {
                element.GetPrevious().SetNext(element.GetNext());
            }

            // set the Previous reference of the next
            if ( element.GetNext() != null )
            {
                element.GetNext().SetPrevious(element.GetPrevious());
            }

            // check if the element is the first child
            // the deleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if ( deleteFromParent )
            {
                if ( IsFirstChild(element) )
                {
                    // set the Child reference of the parent to the next
                    element.GetParent().SetChild(element.GetNext());
                }
            }

            // delete its children
            var child = element.GetChild();

            while ( child != null )
            {
                DeleteElement(child, false);
                child = child.GetNext();
            }

            // delete the element from the colloection
            svgDocumentElements.Remove(element.GetInternalId());

            return true;
        }
Beispiel #9
0
        /// <summary>
        /// It adds the new element eleToAdd as the last children of the given parent element.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToAdd">Element to be added.</param>
        /// <returns>
        /// true if the element is successfully, false otherwise
        /// </returns>
        public bool AddElement(SvgElement parent, SvgElement eleToAdd)
        {
            if ( eleToAdd == null || svgRoot == null )
            {
                ErrorMessage = "Element to be added and Svg Root Element were both Null.";
                return false;
            }

            SvgElement parentToAdd = svgRoot;
            if ( parent != null )
            {
                parentToAdd = parent;
            }

            eleToAdd.SetInternalId(svgDocumentNextInternalId++);
            svgDocumentElements.Add(eleToAdd.GetInternalId(), eleToAdd);

            eleToAdd.SetParent(parentToAdd);
            if (parentToAdd.GetChild() == null )
            {
                // the element is the first child
                parentToAdd.SetChild(eleToAdd);
            }
            else
            {
                // add the element as the last sibling
                var last = GetLastSibling(parentToAdd.GetChild());

                if ( last != null )
                {
                    last.SetNext(eleToAdd);
                    eleToAdd.SetPrevious(last);
                }
            }

            return true;
        }
Beispiel #10
0
        private void AddNodeToTree(SvgElement eleParent,
                                   SvgElement eleToAdd,
                                   SvgElement eleBefore)
        {
            if (eleToAdd == null)
            {
                return;
            }

            string sNodeName = eleToAdd.GetElementName();
            string sId;
            sId = eleToAdd.Id;

            if (sId != "")
            {
                sNodeName += "_";
                sNodeName += sId;
                //sNodeName += ")";
            }
            TreeViewItem node = new TreeViewItem { Name = sNodeName };
            node.Tag = eleToAdd.GetInternalId();

            TreeViewItem nodeParent = null;
            TreeViewItem nodeBefore = null;

            if (eleParent != null)
            {
                nodeParent = FindNodeByTag(null, eleParent.GetInternalId().ToString());
            }

            if (eleBefore != null)
            {
                nodeBefore = FindNodeByTag(nodeParent, eleBefore.GetInternalId().ToString());
            }

            if (nodeParent == null)
            {
                if (nodeBefore == null)
                {
                    TreeViewPrintFile.Items.Add(node);
                }
                else
                {
                    //TreeViewPrintFile.Items.Insert(nodeBefore.Index, node);
                }
            }
            else
            {
                if (nodeBefore == null)
                {
                    nodeParent.Items.Add(node);
                }
                else
                {
                    //nodeParent.Items.Insert(nodeBefore.Index, node);
                }
            }

            //node.ImageIndex = (int)eleToAdd.getElementType();
            //node.SelectedImageIndex = nod.ImageIndex;
            //node.Expand();

            if (eleToAdd.GetChild() != null)
            {
                AddNodeToTree(eleToAdd, eleToAdd.GetChild(), null);

                SvgElement nxt = eleToAdd.GetChild().GetNext();
                while (nxt != null)
                {
                    AddNodeToTree(eleToAdd, nxt, null);
                    nxt = nxt.GetNext();
                }
            }
            TreeViewPrintFile.Items.MoveCurrentTo(node);
        }