Beispiel #1
0
 public void Clear()
 {
     _elementsByName.Clear();
     _rootElements.Clear();
     _selectedElement = null;
     ClearSearch();
 }
Beispiel #2
0
 public Diagram()
 {
     _scale           = 1.0f;
     _lastScale       = 1.0f;
     _size            = new Size(100, 100);
     _padding         = new Size(10, 10);
     _boundingBox     = Rectangle.Empty;
     _alignement      = DiagramAlignement.Center;
     _rootElements    = new List <DiagramItem>();
     _selectedElement = null;
     _elementsByName  = new Dictionary <string, XSDObject>(); // StringComparer.OrdinalIgnoreCase);
 }
Beispiel #3
0
        private void ExpandOneLevel(DiagramItem parentItem)
        {
            foreach (DiagramItem item in parentItem.ChildElements)
            {
                this.ExpandOneLevel(item);

                if (item.HasChildElements && item.ChildElements.Count == 0)
                {
                    this.ExpandChildren(item);
                }
            }
        }
Beispiel #4
0
 public void SelectElement(DiagramItem element)
 {
     if (_selectedElement != null)
     {
         _selectedElement.IsSelected = false;
     }
     if (element != null)
     {
         _selectedElement   = element;
         element.IsSelected = true;
     }
 }
Beispiel #5
0
 public Diagram()
 {
     _scale = 1.0f;
     _lastScale = 1.0f;
     _size = new Size(100, 100);
     _padding = new Size(10, 10);
     _boundingBox = Rectangle.Empty;
     _alignement = DiagramAlignement.Center;
     _rootElements = new List<DiagramItem>();
     _selectedElement = null;
     _elementsByName = new Dictionary<string, XSDObject>(StringComparer.OrdinalIgnoreCase);
 }
Beispiel #6
0
 public void Remove(DiagramItem element)
 {
     if (element.Parent == null)
     {
         _rootElements.Remove(element);
     }
     else
     {
         element.Parent.ChildElements.Remove(element);
         if (element.Parent.ChildElements.Count == 0)
         {
             element.Parent.ShowChildElements = false;
         }
     }
 }
Beispiel #7
0
        private bool ExpandOneLevel(DiagramItem parentItem)
        {
            bool result = false;

            ClearSearch();
            foreach (DiagramItem item in parentItem.ChildElements)
            {
                result |= this.ExpandOneLevel(item);

                if (item.HasChildElements && item.ChildElements.Count == 0)
                {
                    result |= this.ExpandChildren(item);
                }
            }
            return(result);
        }
Beispiel #8
0
        public DiagramItem AddComplexType(DiagramItem parentDiagramElement,
                                          XMLSchema.complexType childElement, bool isReference,
                                          string nameSpace)
        {
            ClearSearch();
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();
                childDiagramElement.Diagram          = this;
                childDiagramElement.TabSchema        = childElement;
                childDiagramElement.Name             = childElement.name != null ? childElement.name : "";
                childDiagramElement.NameSpace        = nameSpace;
                childDiagramElement.ItemType         = DiagramItemType.type;
                childDiagramElement.MinOccurrence    = 1;
                childDiagramElement.MaxOccurrence    = 1;
                childDiagramElement.IsReference      = isReference;
                childDiagramElement.IsSimpleContent  = false;
                childDiagramElement.HasChildElements = false;

                if (childElement.Items != null)
                {
                    for (int i = 0; i < childElement.Items.Length; i++)
                    {
                        if (childElement.Items[i] is XMLSchema.group ||
                            childElement.Items[i] is XMLSchema.complexType ||
                            childElement.Items[i] is XMLSchema.complexContent)
                        {
                            childDiagramElement.HasChildElements = true;
                            break;
                        }
                    }
                }

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramElement);
                }
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                return(childDiagramElement);
            }
            return(null);
        }
Beispiel #9
0
        public void HitTest(Point point, out DiagramItem element, out DiagramHitTestRegion region)
        {
            element = null;
            region  = DiagramHitTestRegion.None;

            foreach (DiagramItem childElement in _rootElements)
            {
                DiagramItem          resultElement;
                DiagramHitTestRegion resultRegion;
                childElement.HitTest(point, out resultElement, out resultRegion);
                if (resultRegion != DiagramHitTestRegion.None)
                {
                    element = resultElement;
                    region  = resultRegion;
                    break;
                }
            }
        }
Beispiel #10
0
 private void ExpandAnnotated(DiagramItem parentDiagramElement,
                              XMLSchema.annotated annotated, string nameSpace)
 {
     if (annotated is XMLSchema.element)
     {
         AddElement(parentDiagramElement, annotated as XMLSchema.element, nameSpace);
         parentDiagramElement.ShowChildElements = true;
     }
     else if (annotated is XMLSchema.group)
     {
         AddCompositors(parentDiagramElement, annotated as XMLSchema.group, nameSpace);
         parentDiagramElement.ShowChildElements = true;
     }
     else if (annotated is XMLSchema.complexType)
     {
         ExpandComplexType(parentDiagramElement, annotated as XMLSchema.complexType);
         parentDiagramElement.ShowChildElements = true;
     }
 }
Beispiel #11
0
 public void HitTest(Point point, out DiagramItem element, out DiagramHitTestRegion region)
 {
     element = null;
     if (ScaleRectangle(_boundingBox).Contains(point))
     {
         element = this;
         if (ScaleRectangle(new Rectangle(_location, _size)).Contains(point))
         {
             if (_hasChildElements && ScaleRectangle(_childExpandButtonBox).Contains(point))
             {
                 region = DiagramHitTestRegion.ChildExpandButton;
             }
             else
             {
                 region = DiagramHitTestRegion.Element;
             }
         }
         else
         {
             region = DiagramHitTestRegion.BoundingBox;
             if (_showChildElements)
             {
                 foreach (DiagramItem childElement in _childElements)
                 {
                     DiagramItem          resultElement;
                     DiagramHitTestRegion resultRegion;
                     childElement.HitTest(point, out resultElement, out resultRegion);
                     if (resultRegion != DiagramHitTestRegion.None)
                     {
                         element = resultElement;
                         region  = resultRegion;
                         break;
                     }
                 }
             }
         }
     }
     else
     {
         region = DiagramHitTestRegion.None;
     }
 }
Beispiel #12
0
        public DiagramItem AddCompositors(DiagramItem parentDiagramElement,
                                          XMLSchema.group childGroup, DiagramItemGroupType type,
                                          string nameSpace)
        {
            ClearSearch();
            if (childGroup != null)
            {
                DiagramItem childDiagramGroup = new DiagramItem();
                childDiagramGroup.ItemType = DiagramItemType.group;

                XMLSchema.group referenceGroup = null;
                if (childGroup.@ref != null)
                {
                    childDiagramGroup.IsReference = true;
                    childDiagramGroup.Name        = [email protected] != null ? [email protected] : "";
                    childDiagramGroup.NameSpace   = [email protected] != null ? [email protected] : "";
                    XSDObject grpObject = null;
                    if (_elementsByName.TryGetValue(childDiagramGroup.FullName, out grpObject) && grpObject != null)
                    {
                        XMLSchema.group group = grpObject.Tag as XMLSchema.group;
                        if (group != null)
                        {
                            referenceGroup = childGroup;
                            childGroup     = group;
                        }
                    }
                }
                else if (type == DiagramItemGroupType.Group)
                {
                    childDiagramGroup.Name      = childGroup.name != null ? childGroup.name : "";
                    childDiagramGroup.NameSpace = nameSpace;
                }
                else
                {
                    childDiagramGroup.NameSpace = nameSpace;
                }

                childDiagramGroup.Diagram   = this;
                childDiagramGroup.TabSchema = childGroup;
                int occurrence;
                if (int.TryParse(referenceGroup != null ? referenceGroup.minOccurs : childGroup.minOccurs, out occurrence))
                {
                    childDiagramGroup.MinOccurrence = occurrence;
                }
                else
                {
                    childDiagramGroup.MinOccurrence = -1;
                }
                //try { childDiagramGroup.MinOccurrence = int.Parse(childGroup.minOccurs); }
                //catch { childDiagramGroup.MinOccurrence = -1; }
                if (int.TryParse(referenceGroup != null ? referenceGroup.maxOccurs : childGroup.maxOccurs, out occurrence))
                {
                    childDiagramGroup.MaxOccurrence = occurrence;
                }
                else
                {
                    childDiagramGroup.MaxOccurrence = -1;
                }
                //try { childDiagramGroup.MaxOccurrence = int.Parse(childGroup.maxOccurs); }
                //catch { childDiagramGroup.MaxOccurrence = -1; }
                childDiagramGroup.HasChildElements = true;
                childDiagramGroup.GroupType        = type;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramGroup);
                }
                else
                {
                    childDiagramGroup.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramGroup);
                }

                return(childDiagramGroup);
            }
            return(null);
        }
Beispiel #13
0
 public DiagramItem AddComplexType(DiagramItem parentDiagramElement,
                                   XMLSchema.complexType childElement, string nameSpace)
 {
     return(AddComplexType(parentDiagramElement, childElement,
                           false, nameSpace));
 }
Beispiel #14
0
        public DiagramItem AddAny(DiagramItem parentDiagramElement,
                                  XMLSchema.any childElement, string nameSpace)
        {
            bool isDisabled = false;

            if (childElement == null)
            {
                isDisabled = true;
                if (_fakeAny == null)
                {
                    _fakeAny           = new XMLSchema.any();
                    _fakeAny.minOccurs = "0";
                    _fakeAny.maxOccurs = "unbounded";
                }
                childElement = _fakeAny;
            }
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();
                childDiagramElement.IsDisabled = isDisabled;
                childDiagramElement.Diagram    = this;
                childDiagramElement.TabSchema  = childElement;
                childDiagramElement.Name       = "any  " + childElement.@namespace;
                childDiagramElement.NameSpace  = nameSpace;
                childDiagramElement.ItemType   = DiagramItemType.group;                //DiagramBase.TypeEnum.element;
                int occurrence;
                if (int.TryParse(childElement.minOccurs, out occurrence))
                {
                    childDiagramElement.MinOccurrence = occurrence;
                }
                else
                {
                    childDiagramElement.MinOccurrence = -1;
                }
                //try { childDiagramElement.MinOccurrence = int.Parse(childElement.minOccurs); }
                //catch { childDiagramElement.MinOccurrence = -1; }
                if (int.TryParse(childElement.maxOccurs, out occurrence))
                {
                    childDiagramElement.MaxOccurrence = occurrence;
                }
                else
                {
                    childDiagramElement.MaxOccurrence = -1;
                }
                //try { childDiagramElement.MaxOccurrence = int.Parse(childElement.maxOccurs); }
                //catch { childDiagramElement.MaxOccurrence = -1; }

                childDiagramElement.IsReference      = false;
                childDiagramElement.IsSimpleContent  = false;
                childDiagramElement.HasChildElements = false;                 // true;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramElement);
                }
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                return(childDiagramElement);
            }

            return(null);
        }
Beispiel #15
0
        public override void Render(DiagramItem drawingItem)
        {
            bool showDocumentation = drawingItem.Diagram.ShowDocumentation && !drawingItem.DocumentationBox.IsEmpty && _graphics != null;

            //if (drawingItem.diagram.ShowBoundingBox)
            //{
            //    int color = 255 - depth * 8;
            //    g.FillRectangle(new SolidBrush(Color.FromArgb(color, color, color)), drawingItem.ScaleRectangle(drawingItem.boundingBox));
            //    g.DrawRectangle(foregroundPen, drawingItem.ScaleRectangle(drawingItem.boundingBox));
            //}

            // Draw the children
            if (drawingItem.ShowChildElements)
            {
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.Render(element);
                    _writer.WriteLine();
                }
            }

            string backgroundBrush    = "fill:rgb(255,255,255)";
            string foregroundColor    = "rgb(0,0,0)";
            string foregroundBrush    = "fill:" + foregroundColor;
            string foregroundPen      = "stroke:" + foregroundColor + ";stroke-width:1";
            string foregroundRoundPen = foregroundPen + ";stroke-linecap:round";
            string dashed             = "stroke-dasharray:4,1";

            Rectangle scaledElementBox = drawingItem.ScaleRectangle(drawingItem.ElementBox);

            // Draw the children lines
            if (drawingItem.ShowChildElements && drawingItem.ChildElements.Count > 0)
            {
                if (drawingItem.ChildElements.Count == 1 && !showDocumentation)
                {
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    this.SVGLine(foregroundRoundPen,
                                 drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
                                 parentMidleY, drawingItem.ScaleInt(drawingItem.ChildElements[0].Location.X), parentMidleY);
                }
                else if (drawingItem.ChildElements.Count > 1 || showDocumentation)
                {
                    DiagramItem firstElement = drawingItem.ChildElements[0];
                    DiagramItem lastElement  = drawingItem.ChildElements[drawingItem.ChildElements.Count - 1];
                    int         verticalLine = drawingItem.ScaleInt(firstElement.BoundingBox.Left);

                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.InheritFrom == null)
                        {
                            int currentMidleY = drawingItem.ScaleInt(element.Location.Y + element.Size.Height / 2);
                            SVGLine(foregroundRoundPen, verticalLine, currentMidleY,
                                    drawingItem.ScaleInt(element.Location.X), currentMidleY);
                        }
                    }

                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    int firstMidleY  = drawingItem.ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
                    firstMidleY = Math.Min(firstMidleY, parentMidleY);
                    int lastMidleY = drawingItem.ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
                    lastMidleY = Math.Max(lastMidleY, parentMidleY);
                    this.SVGLine(foregroundRoundPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
                    this.SVGLine(foregroundRoundPen,
                                 drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
                                 parentMidleY, verticalLine, parentMidleY);
                }
            }

            // Draw the inheritor line
            if (drawingItem.InheritFrom != null)
            {
                string foregroundInheritPen = foregroundPen + ";" + dashed;

                Point p1 = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 5),
                                     drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 5));
                Point p2 = new Point(drawingItem.ScaleInt(drawingItem.Location.X - 5),
                                     drawingItem.ScaleInt(drawingItem.Location.Y - 5));
                this.SVGLine(foregroundInheritPen, p1, p2);
                this.SVGLine(foregroundInheritPen, p2,
                             new Point(drawingItem.ScaleInt(drawingItem.Location.X), drawingItem.ScaleInt(drawingItem.Location.Y)));

                Point targetPoint = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 3),
                                              drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 3));
                SVGLine(foregroundInheritPen, targetPoint, p1);
                Point[] pathPoint = new Point[5];
                pathPoint[0]    = targetPoint;
                pathPoint[1]    = targetPoint;
                pathPoint[1].X += drawingItem.ScaleInt(2);
                pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2]    = targetPoint;
                pathPoint[2].X += drawingItem.ScaleInt(3);
                pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3]    = targetPoint;
                pathPoint[3].X -= drawingItem.ScaleInt(2);
                pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4]    = targetPoint;

                string path = SVGPolygonToDrawCommand(pathPoint);
                SVGPath(backgroundBrush + ";" + foregroundPen, path);
            }

            switch (drawingItem.ItemType)
            {
            case DiagramItemType.element:
            {
                // Draw the main shape following the min/max occurences
                string foregroundBoxPen = foregroundPen;

                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen += ";" + dashed;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
                }
                else
                {
                    Rectangle elementBoxShifted = scaledElementBox;
                    elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                    this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, elementBoxShifted);
                    this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
                }
            }
            break;

            case DiagramItemType.type:
            {
                // Draw the main shape following the min/max occurences
                int     bevel     = (int)(scaledElementBox.Height * 0.30);
                Point[] pathPoint = new Point[6];
                pathPoint[0]    = pathPoint[5] = scaledElementBox.Location;
                pathPoint[1]    = scaledElementBox.Location;
                pathPoint[1].X  = scaledElementBox.Right;
                pathPoint[2]    = scaledElementBox.Location + scaledElementBox.Size;
                pathPoint[3]    = scaledElementBox.Location;
                pathPoint[3].Y  = scaledElementBox.Bottom;
                pathPoint[4]    = pathPoint[3];
                pathPoint[0].X += bevel;
                pathPoint[3].X += bevel;
                pathPoint[4].Y -= bevel;
                pathPoint[5].Y += bevel;

                string path = SVGPolygonToDrawCommand(pathPoint);

                Point[] pathPointShifted   = new Point[6];
                Size    scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                for (int i = 0; i < pathPoint.Length; i++)
                {
                    pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
                }

                string pathShifted = SVGPolygonToDrawCommand(pathPointShifted);

                string foregroundBoxPen = foregroundPen;
                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen += ";" + dashed;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                }
                else
                {
                    Rectangle elementBoxShifted = scaledElementBox;
                    elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                    this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
                    this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                }
            }
            break;

            case DiagramItemType.group:
            {
                // Draw the main shape following the min/max occurences
                int     bevel     = (int)(scaledElementBox.Height * 0.30);
                Point[] pathPoint = new Point[8];
                pathPoint[0]    = pathPoint[7] = scaledElementBox.Location;
                pathPoint[1]    = scaledElementBox.Location;
                pathPoint[1].X  = scaledElementBox.Right; pathPoint[2] = pathPoint[1];
                pathPoint[3]    = pathPoint[4] = scaledElementBox.Location + scaledElementBox.Size;
                pathPoint[5]    = scaledElementBox.Location;
                pathPoint[5].Y  = scaledElementBox.Bottom;
                pathPoint[6]    = pathPoint[5];
                pathPoint[0].X += bevel;
                pathPoint[1].X -= bevel;
                pathPoint[2].Y += bevel;
                pathPoint[3].Y -= bevel;
                pathPoint[4].X -= bevel;
                pathPoint[5].X += bevel;
                pathPoint[6].Y -= bevel;
                pathPoint[7].Y += bevel;

                string path = SVGPolygonToDrawCommand(pathPoint);

                Point[] pathPointShifted   = new Point[8];
                Size    scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                for (int i = 0; i < pathPoint.Length; i++)
                {
                    pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
                }

                string pathShifted = this.SVGPolygonToDrawCommand(pathPointShifted);


                string foregroundBoxPen = foregroundPen;
                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen += ";" + dashed;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                }
                else
                {
                    this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
                    this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                }

                // Draw the group type
                switch (drawingItem.GroupType)
                {
                case DiagramItemGroupType.Sequence:
                {
                    Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                    Point p1 = p0 + new Size(3, 0);
                    Point p2 = p1 + new Size(drawingItem.ElementBox.Width - 6, 0);
                    SVGLine(foregroundPen, drawingItem.ScalePoint(p1), drawingItem.ScalePoint(p2));
                    Point point2     = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                    Point point1     = point2 + new Size(-5, 0);
                    Point point3     = point2 + new Size(+5, 0);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point3), pointSize));

                    //Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                    //Point point0 = p0 + new Size(3, 0);
                    //Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                    //Point point1 = point2 + new Size(-5, 0);
                    //Point point3 = point2 + new Size(+5, 0);
                    //Point point4 = point0 + new Size(drawingItem.ElementBox.Width - 6, 0);

                    //Pen foregroundBallPen = new Pen(foreground);
                    //foregroundBallPen.EndCap = LineCap.RoundAnchor;
                    ////foregroundBallPen.ScaleTransform(1.0f / drawingItem.diagram.Scale, 1.0f / drawingItem.diagram.Scale);
                    //foregroundBallPen.ScaleTransform(drawingItem.diagram.Scale, drawingItem.diagram.Scale);

                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point0), drawingItem.ScalePoint(point1));
                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point1), drawingItem.ScalePoint(point2));
                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point2), drawingItem.ScalePoint(point3));
                    //foregroundBallPen.EndCap = LineCap.Flat;
                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point3), drawingItem.ScalePoint(point4));
                }
                break;

                case DiagramItemGroupType.Choice:
                {
                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                    int yUp     = yMiddle - 4;
                    int yDown   = yMiddle + 4;
                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                    int xLeft2  = xMiddle - 4;
                    int xLeft1  = xLeft2 - 4;
                    int xLeft0  = xLeft1 - 4;
                    int xRight0 = xMiddle + 4;
                    int xRight1 = xRight0 + 4;
                    int xRight2 = xRight1 + 4;

                    Point point1     = new Point(xMiddle, yUp);
                    Point point2     = new Point(xMiddle, yMiddle);
                    Point point3     = new Point(xMiddle, yDown);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft0, yMiddle)),
                            drawingItem.ScalePoint(new Point(xLeft1, yMiddle)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft1, yMiddle)),
                            drawingItem.ScalePoint(new Point(xLeft2, yUp)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yUp)),
                            drawingItem.ScalePoint(new Point(xRight1, yUp)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
                            drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yDown)),
                            drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight1, yUp)),
                            drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                }
                break;

                case DiagramItemGroupType.All:
                {
                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                    int yUp     = yMiddle - 4;
                    int yDown   = yMiddle + 4;
                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                    int xLeft2  = xMiddle - 4;
                    int xLeft1  = xLeft2 - 4;
                    int xLeft0  = xLeft1 - 4;
                    int xRight0 = xMiddle + 4;
                    int xRight1 = xRight0 + 4;
                    int xRight2 = xRight1 + 4;

                    Point point1     = new Point(xMiddle, yUp);
                    Point point2     = new Point(xMiddle, yMiddle);
                    Point point3     = new Point(xMiddle, yDown);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft2, yUp)),
                            drawingItem.ScalePoint(new Point(xLeft1, yUp)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft2, yMiddle)),
                            drawingItem.ScalePoint(new Point(xLeft0, yMiddle)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft2, yDown)),
                            drawingItem.ScalePoint(new Point(xLeft1, yDown)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xLeft1, yUp)),
                            drawingItem.ScalePoint(new Point(xLeft1, yDown)));

                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yUp)),
                            drawingItem.ScalePoint(new Point(xRight1, yUp)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
                            drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight0, yDown)),
                            drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    SVGLine(foregroundPen,
                            drawingItem.ScalePoint(new Point(xRight1, yUp)),
                            drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    SVGEllipse(foregroundColor,
                               new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                }
                break;
                }
                break;
            }
            }

            float fontScale = 0.8f;

            // Draw text
            if (drawingItem.Name.Length > 0)
            {
                string style = String.Format(
                    "font-family:{0};font-size:{1}pt;fill:{2};font-weight:bold;text-anchor:middle;dominant-baseline:central",
                    drawingItem.Font.Name, drawingItem.Font.Size * fontScale, foregroundColor);
                SVGText(drawingItem.Name, style,
                        new Rectangle(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height));
            }

            // Draw Documentation
            if (showDocumentation)
            {
                string text = drawingItem.GetTextDocumentation();
                if (text != null)
                {
                    Rectangle     scaledDocumentationBox = drawingItem.ScaleRectangle(drawingItem.DocumentationBox);
                    List <string> lines = WrapText(_graphics, drawingItem.DocumentationFont, text, scaledDocumentationBox.Width * fontScale * 0.6f);
                    //stringFormatText.Trimming = StringTrimming.EllipsisCharacter;
                    string style = String.Format(
                        "font-family:{0};font-size:{1}pt;fill:{2};font-weight:normal;text-anchor:start;dominant-baseline:central;inline-size={3}",
                        drawingItem.DocumentationFont.Name, drawingItem.DocumentationFont.Size * fontScale * 0.9, foregroundColor, scaledDocumentationBox.Width);
                    float fontSizeAdjustement = drawingItem.DocumentationFont.Size * fontScale * 1.4f;
                    SVGText(lines, style,
                            new Point(scaledDocumentationBox.X, scaledDocumentationBox.Y), fontSizeAdjustement,
                            new Size(scaledDocumentationBox.Width, scaledDocumentationBox.Height));
                }
            }

            // Draw occurences small text
            if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1)
            {
                string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
                                    (drawingItem.MaxOccurrence == -1 ? "∞" : string.Format("{0}", drawingItem.MaxOccurrence));
                PointF pointOccurences = new PointF();
                pointOccurences.X = drawingItem.Diagram.Scale * (drawingItem.Location.X + drawingItem.Size.Width - 10);
                pointOccurences.Y = drawingItem.Diagram.Scale * (drawingItem.Location.Y + drawingItem.Size.Height + 10);
                string style = String.Format(
                    "font-family:{0};font-size:{1}pt;fill:{2};text-anchor:end;dominant-baseline:central",
                    drawingItem.SmallFont.Name, drawingItem.SmallFont.Size * fontScale, foregroundColor);
                SVGText(occurences, style, new Point((int)pointOccurences.X, (int)pointOccurences.Y));
            }

            // Draw type
            if (drawingItem.IsSimpleContent)
            {
                Point currentPoint = scaledElementBox.Location + new Size(2, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(8), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
            }

            // Draw reference arrow
            if (drawingItem.IsReference)
            {
                string arrowPen = String.Format("stroke:{0};stroke-width:{1}",
                                                foregroundColor, drawingItem.Diagram.Scale * 2.0f);
                Point basePoint   = new Point(drawingItem.ElementBox.Left + 1, drawingItem.ElementBox.Bottom - 1);
                Point targetPoint = basePoint + new Size(3, -3);
                basePoint   = drawingItem.ScalePoint(basePoint);
                targetPoint = drawingItem.ScalePoint(targetPoint);
                if (drawingItem.ItemType == DiagramItemType.group)
                {
                    int bevel             = (int)(scaledElementBox.Height * 0.30);
                    int groupCornerOffset = (int)((double)bevel * 0.424264068713); // 0.6/sqr(2)
                    basePoint.X   += groupCornerOffset;
                    basePoint.Y   -= groupCornerOffset;
                    targetPoint.X += groupCornerOffset;
                    targetPoint.Y -= groupCornerOffset;
                }
                SVGLine(arrowPen, basePoint, targetPoint);

                Point[] pathPoint = new Point[5];
                pathPoint[0]    = targetPoint;
                pathPoint[1]    = targetPoint;
                pathPoint[1].X += drawingItem.ScaleInt(2);
                pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2]    = targetPoint;
                pathPoint[2].X += drawingItem.ScaleInt(3);
                pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3]    = targetPoint;
                pathPoint[3].X -= drawingItem.ScaleInt(2);
                pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4]    = targetPoint;

                string path = SVGPolygonToDrawCommand(pathPoint);
                SVGPath(foregroundBrush, path);
            }

            // Draw children expand box
            if (drawingItem.HasChildElements)
            {
                Rectangle scaledChildExpandButtonBox = drawingItem.ScaleRectangle(drawingItem.ChildExpandButtonBox);
                SVGRectangle(backgroundBrush + ";" + foregroundPen, scaledChildExpandButtonBox);

                Point middle        = new Point(scaledChildExpandButtonBox.Width / 2, scaledChildExpandButtonBox.Height / 2);
                int   borderPadding = Math.Max(2, drawingItem.ScaleInt(2));

                Point p1 = scaledChildExpandButtonBox.Location + new Size(borderPadding, middle.Y);
                Point p2 = new Point(scaledChildExpandButtonBox.Right - borderPadding, p1.Y);
                SVGLine(foregroundPen, p1, p2);
                if (!drawingItem.ShowChildElements)
                {
                    p1 = scaledChildExpandButtonBox.Location + new Size(middle.X, borderPadding);
                    p2 = new Point(p1.X, scaledChildExpandButtonBox.Bottom - borderPadding);
                    SVGLine(foregroundPen, p1, p2);
                }
            }
        }
Beispiel #16
0
 private void ExpandCollapseElement(DiagramItem element)
 {
     ExpandCollapseElement(element, false);
 }
Beispiel #17
0
        public void Render(DiagramItem drawingItem, Rectangle? clipRectangle)
        {
            //System.Diagnostics.Trace.WriteLine("DiagramElement.Paint\n\tName: " + drawingItem.Name);

            Color backgroundColor = Color.White;
            if(drawingItem.IsSelected)
                backgroundColor = Color.FromArgb(0xA6, 0xCA, 0xF0);

            Brush background = new SolidBrush(backgroundColor);
            Brush backgroundExpandBox = new SolidBrush(Color.White);
            SolidBrush foreground = new SolidBrush(Color.Black);
            if (drawingItem.IsDisabled)
            {
                background = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Gray, backgroundColor);
                foreground = new SolidBrush(Color.Gray);
            }
            Pen foregroundPen = new Pen(foreground);
            float[] dashPattern = new float[] { Math.Max(2f, drawingItem.ScaleInt(5)), Math.Max(1f, drawingItem.ScaleInt(2)) };

            //if (drawingItem.IsReference && drawingItem.diagram.ShowBoundingBox)
            if (drawingItem.Diagram.ShowBoundingBox)
            {
                int color = 255 - drawingItem.Depth * 8;
                _graphics.FillRectangle(new SolidBrush(Color.FromArgb(color, color, color)), drawingItem.ScaleRectangle(drawingItem.BoundingBox));
                _graphics.DrawRectangle(foregroundPen, drawingItem.ScaleRectangle(drawingItem.BoundingBox));
            }

            // Draw the children
            if (drawingItem.ShowChildElements)
            {
                if (clipRectangle.HasValue)
                {
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.BoundingBox.IntersectsWith(clipRectangle.Value))
                        {
                            this.Render(element, clipRectangle);
                        }
                    }
                }
                else
                {
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        this.Render(element);
                    }
                }
            }

            Rectangle scaledElementBox = drawingItem.ScaleRectangle(drawingItem.ElementBox);

            // Draw the children lines
            if (drawingItem.ShowChildElements && drawingItem.ChildElements.Count > 0)
            {
                Pen foregroundInheritPen = new Pen(foreground);
                foregroundInheritPen.StartCap = LineCap.Round;
                foregroundInheritPen.EndCap = LineCap.Round;

                bool showDocumentation = (drawingItem.Diagram.ShowDocumentation); // && !drawingItem.DocumentationBox.IsEmpty);
                if (drawingItem.ChildElements.Count == 1 && !showDocumentation)
                {
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    _graphics.DrawLine(foregroundInheritPen, drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width), parentMidleY, drawingItem.ScaleInt(drawingItem.ChildElements[0].Location.X), parentMidleY);
                }
                else if (drawingItem.ChildElements.Count > 1 || showDocumentation)
                {
                    DiagramItem firstElement = drawingItem.ChildElements[0];
                    DiagramItem lastElement = drawingItem.ChildElements[drawingItem.ChildElements.Count - 1];
                    int verticalLine = drawingItem.ScaleInt(firstElement.BoundingBox.Left);
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.InheritFrom == null)
                        {
                            int currentMidleY = drawingItem.ScaleInt(element.Location.Y + element.Size.Height / 2);
                            _graphics.DrawLine(foregroundInheritPen, verticalLine, currentMidleY, drawingItem.ScaleInt(element.Location.X), currentMidleY);
                        }
                    }
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    int firstMidleY = drawingItem.ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
                    firstMidleY = Math.Min(firstMidleY, parentMidleY);
                    int lastMidleY = drawingItem.ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
                    lastMidleY = Math.Max(lastMidleY, parentMidleY);
                    _graphics.DrawLine(foregroundInheritPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
                    _graphics.DrawLine(foregroundInheritPen, drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width), parentMidleY, verticalLine, parentMidleY);
                }
            }

            // Draw the inheritor line
            if (drawingItem.InheritFrom != null)
            {
                Pen foregroundInheritPen = new Pen(foreground);
                foregroundInheritPen.DashStyle = DashStyle.Dash;
                foregroundInheritPen.DashPattern = dashPattern;

                Point p1 = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 5), drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 5));
                Point p2 = new Point(drawingItem.ScaleInt(drawingItem.Location.X - 5), drawingItem.ScaleInt(drawingItem.Location.Y - 5));
                _graphics.DrawLine(foregroundInheritPen, p1, p2);
                _graphics.DrawLine(foregroundInheritPen, p2, new Point(drawingItem.ScaleInt(drawingItem.Location.X), drawingItem.ScaleInt(drawingItem.Location.Y)));

                Point targetPoint = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X), drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height));
                _graphics.DrawLine(foregroundInheritPen, targetPoint, p1);

                Point[] pathPoint = new Point[4];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint; pathPoint[1].Y += drawingItem.ScaleInt(5);
                pathPoint[2] = targetPoint; pathPoint[2].X -= drawingItem.ScaleInt(5);
                pathPoint[3] = targetPoint;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();

                Pen foregroundBoxPen = new Pen(foreground);
                _graphics.FillPath(background, path);
                _graphics.DrawPath(foregroundBoxPen, path);
            }

            switch (drawingItem.ItemType)
            {
                case DiagramItemType.element:
                    {
                        // Draw the main shape following the min/max occurences
                        Pen foregroundBoxPen = new Pen(foreground);
                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                            foregroundBoxPen.DashPattern = dashPattern;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            _graphics.FillRectangle(background, scaledElementBox);
                            _graphics.DrawRectangle(foregroundBoxPen, scaledElementBox);
                        }
                        else
                        {
                            Rectangle elementBoxShifted = scaledElementBox;
                            elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                            _graphics.FillRectangle(background, elementBoxShifted);
                            _graphics.DrawRectangle(foregroundBoxPen, elementBoxShifted);
                            _graphics.FillRectangle(background, scaledElementBox);
                            _graphics.DrawRectangle(foregroundBoxPen, scaledElementBox);
                        }
                    }
                    break;

                case DiagramItemType.type:
                    {
                        // Draw the main shape following the min/max occurences
                        int bevel = (int)(scaledElementBox.Height * 0.30);
                        Point[] pathPoint = new Point[6];
                        pathPoint[0] = pathPoint[5] = scaledElementBox.Location;
                        pathPoint[1] = scaledElementBox.Location; pathPoint[1].X = scaledElementBox.Right;
                        pathPoint[2] = scaledElementBox.Location + scaledElementBox.Size;
                        pathPoint[3] = scaledElementBox.Location; pathPoint[3].Y = scaledElementBox.Bottom; pathPoint[4] = pathPoint[3];
                        pathPoint[0].X += bevel;
                        pathPoint[3].X += bevel;
                        pathPoint[4].Y -= bevel;
                        pathPoint[5].Y += bevel;

                        GraphicsPath path = new GraphicsPath();
                        path.StartFigure();
                        path.AddPolygon(pathPoint);
                        path.CloseFigure();

                        Point[] pathPointShifted = new Point[6];
                        Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                        for (int i = 0; i < pathPoint.Length; i++)
                            pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;

                        GraphicsPath pathShifted = new GraphicsPath();
                        pathShifted.StartFigure();
                        pathShifted.AddPolygon(pathPointShifted);
                        pathShifted.CloseFigure();

                        Pen foregroundBoxPen = new Pen(foreground);
                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                            foregroundBoxPen.DashPattern = dashPattern;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            _graphics.FillPath(background, path);
                            _graphics.DrawPath(foregroundBoxPen, path);
                        }
                        else
                        {
                            Rectangle elementBoxShifted = scaledElementBox;
                            elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                            _graphics.FillPath(background, pathShifted);
                            _graphics.DrawPath(foregroundBoxPen, pathShifted);
                            _graphics.FillPath(background, path);
                            _graphics.DrawPath(foregroundBoxPen, path);
                        }
                    }
                    break;

                case DiagramItemType.group:
                    {
                        // Draw the main shape following the min/max occurences
                        int bevel = (int)(scaledElementBox.Height * 0.30);
                        Point[] pathPoint = new Point[8];
                        pathPoint[0] = pathPoint[7] = scaledElementBox.Location;
                        pathPoint[1] = scaledElementBox.Location; pathPoint[1].X = scaledElementBox.Right; pathPoint[2] = pathPoint[1];
                        pathPoint[3] = pathPoint[4] = scaledElementBox.Location + scaledElementBox.Size;
                        pathPoint[5] = scaledElementBox.Location; pathPoint[5].Y = scaledElementBox.Bottom; pathPoint[6] = pathPoint[5];
                        pathPoint[0].X += bevel;
                        pathPoint[1].X -= bevel;
                        pathPoint[2].Y += bevel;
                        pathPoint[3].Y -= bevel;
                        pathPoint[4].X -= bevel;
                        pathPoint[5].X += bevel;
                        pathPoint[6].Y -= bevel;
                        pathPoint[7].Y += bevel;

                        GraphicsPath path = new GraphicsPath();
                        path.StartFigure();
                        path.AddPolygon(pathPoint);
                        path.CloseFigure();

                        Point[] pathPointShifted = new Point[8];
                        Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                        for (int i = 0; i < pathPoint.Length; i++)
                            pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;

                        GraphicsPath pathShifted = new GraphicsPath();
                        pathShifted.StartFigure();
                        pathShifted.AddPolygon(pathPointShifted);
                        pathShifted.CloseFigure();

                        Pen foregroundBoxPen = new Pen(foreground);
                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                            foregroundBoxPen.DashPattern = dashPattern;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            _graphics.FillPath(background, path);
                            _graphics.DrawPath(foregroundBoxPen, path);
                        }
                        else
                        {
                            Rectangle elementBoxShifted = scaledElementBox;
                            elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                            _graphics.FillPath(background, pathShifted);
                            _graphics.DrawPath(foregroundBoxPen, pathShifted);
                            _graphics.FillPath(background, path);
                            _graphics.DrawPath(foregroundBoxPen, path);
                        }

                        // Draw the group type
                        //Pen foregroundPointPen = new Pen(foreground, 4.0f);
                        switch (drawingItem.GroupType)
                        {
                            case DiagramItemGroupType.Sequence:
                                {
                                    Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                                    Point p1 = p0 + new Size(3, 0);
                                    Point p2 = p1 + new Size(drawingItem.ElementBox.Width - 6, 0);
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(p1), drawingItem.ScalePoint(p2));
                                    Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                                    Point point1 = point2 + new Size(-5, 0);
                                    Point point3 = point2 + new Size(+5, 0);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));

                                    //Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                                    //Point point0 = p0 + new Size(3, 0);
                                    //Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                                    //Point point1 = point2 + new Size(-5, 0);
                                    //Point point3 = point2 + new Size(+5, 0);
                                    //Point point4 = point0 + new Size(drawingItem.ElementBox.Width - 6, 0);

                                    //Pen foregroundBallPen = new Pen(foreground);
                                    //foregroundBallPen.EndCap = LineCap.RoundAnchor;
                                    ////foregroundBallPen.ScaleTransform(1.0f / drawingItem.diagram.Scale, 1.0f / drawingItem.diagram.Scale);
                                    //foregroundBallPen.ScaleTransform(drawingItem.diagram.Scale, drawingItem.diagram.Scale);

                                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point0), drawingItem.ScalePoint(point1));
                                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point1), drawingItem.ScalePoint(point2));
                                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point2), drawingItem.ScalePoint(point3));
                                    //foregroundBallPen.EndCap = LineCap.Flat;
                                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point3), drawingItem.ScalePoint(point4));
                                }
                                break;
                            case DiagramItemGroupType.Choice:
                                {
                                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                                    int yUp = yMiddle - 4;
                                    int yDown = yMiddle + 4;
                                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                                    int xLeft2 = xMiddle - 4;
                                    int xLeft1 = xLeft2 - 4;
                                    int xLeft0 = xLeft1 - 4;
                                    int xRight0 = xMiddle + 4;
                                    int xRight1 = xRight0 + 4;
                                    int xRight2 = xRight1 + 4;

                                    Point point1 = new Point(xMiddle, yUp);
                                    Point point2 = new Point(xMiddle, yMiddle);
                                    Point point3 = new Point(xMiddle, yDown);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft0, yMiddle)), drawingItem.ScalePoint(new Point(xLeft1, yMiddle)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft1, yMiddle)), drawingItem.ScalePoint(new Point(xLeft2, yUp)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yUp)), drawingItem.ScalePoint(new Point(xRight1, yUp)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yMiddle)), drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yDown)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight1, yUp)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                                }
                                break;
                            case DiagramItemGroupType.All:
                                {
                                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                                    int yUp = yMiddle - 4;
                                    int yDown = yMiddle + 4;
                                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                                    int xLeft2 = xMiddle - 4;
                                    int xLeft1 = xLeft2 - 4;
                                    int xLeft0 = xLeft1 - 4;
                                    int xRight0 = xMiddle + 4;
                                    int xRight1 = xRight0 + 4;
                                    int xRight2 = xRight1 + 4;

                                    Point point1 = new Point(xMiddle, yUp);
                                    Point point2 = new Point(xMiddle, yMiddle);
                                    Point point3 = new Point(xMiddle, yDown);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yUp)), drawingItem.ScalePoint(new Point(xLeft1, yUp)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yMiddle)), drawingItem.ScalePoint(new Point(xLeft0, yMiddle)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yDown)), drawingItem.ScalePoint(new Point(xLeft1, yDown)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft1, yUp)), drawingItem.ScalePoint(new Point(xLeft1, yDown)));

                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yUp)), drawingItem.ScalePoint(new Point(xRight1, yUp)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yMiddle)), drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yDown)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight1, yUp)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                                }
                                break;
                        }
                        break;
                    }
            }

            // Draw text
            if (drawingItem.Name.Length > 0)
            {
                StringFormat stringFormatText = new StringFormat();
                stringFormatText.Alignment = StringAlignment.Center;
                stringFormatText.LineAlignment = StringAlignment.Center;
                stringFormatText.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
                _graphics.DrawString(drawingItem.Name, drawingItem.FontScaled, foreground, new RectangleF(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height), stringFormatText);
            }

            // Draw Documentation
            if (drawingItem.Diagram.ShowDocumentation && !drawingItem.DocumentationBox.IsEmpty)
            {
                string text = drawingItem.GetTextDocumentation();
                if (text != null)
                {
                    StringFormat stringFormatText = new StringFormat();
                    stringFormatText.Alignment = StringAlignment.Near;
                    stringFormatText.LineAlignment = StringAlignment.Near;
                    stringFormatText.Trimming = StringTrimming.EllipsisCharacter;
                    stringFormatText.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX

                    Rectangle scaledDocumentationBox = drawingItem.ScaleRectangle(drawingItem.DocumentationBox);
                    if (drawingItem.Diagram.ShowBoundingBox)
                    {
                        int color = 255 - drawingItem.Depth * 8;
                        _graphics.FillRectangle(new SolidBrush(Color.FromArgb(color, 255 - color, color)), scaledDocumentationBox);
                        _graphics.DrawRectangle(foregroundPen, scaledDocumentationBox);
                    }
                    _graphics.DrawString(text, drawingItem.DocumentationFontScaled, foreground
                        , new RectangleF(scaledDocumentationBox.X, scaledDocumentationBox.Y, scaledDocumentationBox.Width, scaledDocumentationBox.Height)
                        , stringFormatText);
                }
            }

            // Draw occurences small text
            if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1)
            {
                StringFormat stringFormatOccurences = new StringFormat();
                stringFormatOccurences.Alignment = StringAlignment.Far;
                stringFormatOccurences.LineAlignment = StringAlignment.Center;
                stringFormatOccurences.FormatFlags |= StringFormatFlags.NoClip; //MONOFIX
                //string occurences = string.Format("{0}..", drawingItem.MinOccurrence) + (drawingItem.MaxOccurrence == -1 ? "\u0066∞" : string.Format("{0}", drawingItem.MaxOccurrence));
                string occurences = string.Format("{0}..", drawingItem.MinOccurrence) + (drawingItem.MaxOccurrence == -1 ? "\u221E" : string.Format("{0}", drawingItem.MaxOccurrence));
                PointF pointOccurences = new PointF();
                pointOccurences.X = drawingItem.Diagram.Scale * (drawingItem.Location.X + drawingItem.Size.Width - 10);
                pointOccurences.Y = drawingItem.Diagram.Scale * (drawingItem.Location.Y + drawingItem.Size.Height + 10);
                _graphics.DrawString(occurences, drawingItem.SmallFontScaled, foreground, pointOccurences, stringFormatOccurences);
            }

            // Draw type
            if (drawingItem.IsSimpleContent)
            {
                Point currentPoint = scaledElementBox.Location + new Size(2, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(8), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
            }

            // Draw reference arrow
            if (drawingItem.IsReference)
            {
                Pen arrowPen = new Pen(foreground, drawingItem.Diagram.Scale * 2.0f);
                //arrowPen.EndCap = LineCap.ArrowAnchor;
                //Point basePoint = new Point(drawingItem.ElementBox.Left + 2, drawingItem.ElementBox.Bottom - 2);
                //g.DrawLine(arrowPen, drawingItem.ScalePoint(basePoint), drawingItem.ScalePoint(basePoint + new Size(4, -4)));
                Point basePoint = new Point(drawingItem.ElementBox.Left + 1, drawingItem.ElementBox.Bottom - 1);
                Point targetPoint = basePoint + new Size(3, -3);
                basePoint = drawingItem.ScalePoint(basePoint);
                targetPoint = drawingItem.ScalePoint(targetPoint);
                if (drawingItem.ItemType == DiagramItemType.group)
                {
                    int bevel = (int)(scaledElementBox.Height * 0.30);
                    int groupCornerOffset = (int)((double)bevel * 0.424264068713); // 0.6/sqr(2)
                    basePoint.X += groupCornerOffset;
                    basePoint.Y -= groupCornerOffset;
                    targetPoint.X += groupCornerOffset;
                    targetPoint.Y -= groupCornerOffset;
                }
                _graphics.DrawLine(arrowPen, basePoint, targetPoint);

                Point[] pathPoint = new Point[5];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint; pathPoint[1].X += drawingItem.ScaleInt(2); pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2] = targetPoint; pathPoint[2].X += drawingItem.ScaleInt(3); pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3] = targetPoint; pathPoint[3].X -= drawingItem.ScaleInt(2); pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4] = targetPoint;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();
                _graphics.FillPath(foreground, path);
            }

            // Draw children expand box
            if (drawingItem.HasChildElements)
            {
                Rectangle scaledChildExpandButtonBox = drawingItem.ScaleRectangle(drawingItem.ChildExpandButtonBox);
                _graphics.FillRectangle(backgroundExpandBox, scaledChildExpandButtonBox);
                _graphics.DrawRectangle(foregroundPen, scaledChildExpandButtonBox);

                Point middle = new Point(scaledChildExpandButtonBox.Width / 2, scaledChildExpandButtonBox.Height / 2);
                int borderPadding = Math.Max(2, drawingItem.ScaleInt(2));

                Point p1 = scaledChildExpandButtonBox.Location + new Size(borderPadding, middle.Y);
                Point p2 = new Point(scaledChildExpandButtonBox.Right - borderPadding, p1.Y);
                _graphics.DrawLine(foregroundPen, p1, p2);
                if (!drawingItem.ShowChildElements)
                {
                    p1 = scaledChildExpandButtonBox.Location + new Size(middle.X, borderPadding);
                    p2 = new Point(p1.X, scaledChildExpandButtonBox.Bottom - borderPadding);
                    _graphics.DrawLine(foregroundPen, p1, p2);
                }
            }
        }
Beispiel #18
0
        private void ExpandComplexType(DiagramItem parentDiagramElement, 
            XMLSchema.complexType complexTypeElement)
        {
            if (complexTypeElement.Items != null)
            {
                XMLSchema.annotated[] items = complexTypeElement.Items;
                XMLSchema.ItemsChoiceType4[] itemsChoiceType = complexTypeElement.ItemsElementName;

                for (int i = 0; i < items.Length; i++)
                {
                    if (items[i] is XMLSchema.group)
                    {
                        XMLSchema.group group = items[i] as XMLSchema.group;
                        DiagramItem diagramCompositors = AddCompositors(parentDiagramElement,
                            group, (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), itemsChoiceType[i].ToString(), true), parentDiagramElement.NameSpace);
                        parentDiagramElement.ShowChildElements = true;
                        if (diagramCompositors != null)
                            ExpandChildren(diagramCompositors);
                    }
                    else if (items[i] is XMLSchema.complexContent)
                    {
                        XMLSchema.complexContent complexContent = items[i] as XMLSchema.complexContent;
                        if (complexContent.Item is XMLSchema.extensionType)
                        {
                            XMLSchema.extensionType extensionType = complexContent.Item as XMLSchema.extensionType;

                            XSDObject xsdObject = null;
                            if(_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }

                            XMLSchema.group group = extensionType.group as XMLSchema.group;
                            if (group != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, group, DiagramItemGroupType.Group, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                    ExpandChildren(diagramCompositors);
                            }

                            XMLSchema.group groupSequence = extensionType.sequence as XMLSchema.group;
                            if (groupSequence != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupSequence, DiagramItemGroupType.Sequence, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                    ExpandChildren(diagramCompositors);
                            }

                            XMLSchema.group groupChoice = extensionType.choice as XMLSchema.group;
                            if (groupChoice != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupChoice, DiagramItemGroupType.Choice, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                    ExpandChildren(diagramCompositors);
                            }
                        }
                        else if (complexContent.Item is XMLSchema.restrictionType)
                        {
                            XMLSchema.restrictionType restrictionType = complexContent.Item as XMLSchema.restrictionType;
                            XSDObject xsdObject = null;
                            if(_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }
                            else
                            {
                                //dgis fix github issue 2
                                if(restrictionType.Items != null)
                                {
                                    //for (int j = 0; j < items.Length; j++)
                                    for (int j = 0; j < restrictionType.Items.Length; j++)
                                    {
                                        if (restrictionType.Items[j] is XMLSchema.group)
                                        {
                                            XMLSchema.group group = restrictionType.Items[j] as XMLSchema.group;
                                            DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, group,
                                                (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), restrictionType.ItemsElementName[j].ToString(), true), parentDiagramElement.NameSpace);
                                            parentDiagramElement.ShowChildElements = true;
                                            if (diagramCompositors != null)
                                                ExpandChildren(diagramCompositors);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #19
0
 private void gotoXSDFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.contextualMenuPointedElement != null)
     {
         //XSDObject xsdObject = this.schema.ElementsByName[this.contextualMenuPointedElement.FullName] as XSDObject;
         //if (xsdObject != null)
         XSDObject xsdObject;
         if (this.schema.ElementsByName.TryGetValue(this.contextualMenuPointedElement.FullName, out xsdObject) && xsdObject != null)
         {
             TabPage tabPage = null;
             if (this.hashtableTabPageByFilename.TryGetValue(xsdObject.Filename, out tabPage) && tabPage != null)
                 this.tabControlView.SelectedTab = tabPage;
         }
     }
     this.contextualMenuPointedElement = null;
 }
Beispiel #20
0
 private void expandToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ExpandCollapseElement(this.contextualMenuPointedElement, false);
     this.contextualMenuPointedElement = null;
 }
Beispiel #21
0
 public void SelectElement(DiagramItem element)
 {
     if(_selectedElement != null)
         _selectedElement.IsSelected = false;
     if (element != null)
     {
         _selectedElement = element;
         element.IsSelected = true;
     }
 }
Beispiel #22
0
        public override void Render(DiagramItem drawingItem)
        {
            string type = "";
            if (drawingItem.TabSchema is XMLSchema.element)
                type = "element";
            else if (drawingItem.TabSchema is XMLSchema.simpleType)
                type = "simpleType";
            else if (drawingItem.TabSchema is XMLSchema.complexType)
                type = "complexType";

            if (type.Length > 0)
            {
                string path = '/' + drawingItem.Name;
                DiagramItem parentElement = drawingItem.Parent;
                while (parentElement != null)
                {
                    //if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                    if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
                            path = '/' + parentElement.Name + path;
                    parentElement = parentElement.Parent;
                }

                string comment = "";
                XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
                if (annotated != null && annotated.annotation != null)
                {
                    foreach (object o in annotated.annotation.Items)
                    {
                        if (o is XMLSchema.documentation)
                        {
                            XMLSchema.documentation documentation = o as XMLSchema.documentation;
                            if (documentation.Any != null && documentation.Any.Length > 0 && documentation.Any[0].Value != null)
                            {
                                string text = documentation.Any[0].Value;
                                text = text.Replace("\n", " ");
                                text = text.Replace("\t", " ");
                                text = text.Replace("\r", "");
                                text = Regex.Replace(text, " +", " ");
                                text = text.Trim();
                                comment = text;
                            }
                            else if (documentation.source != null)
                            {
                                comment = documentation.source;
                            }
                            break;
                        }
                    }
                }

                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                {
                    if (i > 0)
                        _writer.Write(_fieldSeparator);
                    string field = _finalTextOutputFields[i];
                    switch (field)
                    {
                        case "PATH": _writer.Write(path); break;
                        case "NAME": _writer.Write(drawingItem.Name); break;
                        case "TYPE": _writer.Write(type); break;
                        case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;
                        case "COMMENT": _writer.Write(comment); break;
                    }
                }
                _writer.WriteLine();

                //// Draw the inheritor line
                //if (drawingItem.InheritFrom != null)
                //{
                //}

                //switch (drawingItem.ItemType)
                //{
                //    case DiagramItemType.element:
                //        break;

                //    case DiagramItemType.type:
                //        break;

                //    case DiagramItemType.group:
                //        {
                //            // Draw the main shape following the min/max occurences

                //            // Draw the group type
                //            switch (drawingItem.GroupType)
                //            {
                //                case DiagramItemGroupType.Sequence: break;
                //                case DiagramItemGroupType.Choice: break;
                //                case DiagramItemGroupType.All: break;
                //            }
                //            break;
                //        }
                //}

                //// Draw text
                //if (drawingItem.Name.Length > 0)
                //{
                //    //drawingItem.Name;
                //}

                //// Draw occurences small text
                //if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}

                //// Draw type
                //if (drawingItem.IsSimpleContent) {}

                //// Draw reference arrow
                //if (drawingItem.IsReference) {}
            }

            // Draw children expand box
            if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
            {
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.Render(element);
                    //_writer.WriteLine();
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// Renders the specified drawing item.
        /// </summary>
        /// <param name="drawingItem">The drawing item.</param>
        public override void Render(DiagramItem drawingItem)
        {
            string type = "";

            if (drawingItem.TabSchema is XMLSchema.element)
            {
                type = "element";
            }
            else if (drawingItem.TabSchema is XMLSchema.simpleType)
            {
                type = "simpleType";
            }
            else if (drawingItem.TabSchema is XMLSchema.complexType)
            {
                type = "complexType";
            }

            string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
                                (drawingItem.MaxOccurrence == -1 ? "∞" : string.Format("{0}", drawingItem.MaxOccurrence));

            if (type.Length > 0)
            {
                string      path          = '/' + drawingItem.Name;
                DiagramItem parentElement = drawingItem.Parent;
                while (parentElement != null)
                {
                    //if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                    if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
                    {
                        path = '/' + parentElement.Name + path;
                    }
                    parentElement = parentElement.Parent;
                }

                // Get the comment/documentation
                string comment = "";
                XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
                if (annotated != null && annotated.annotation != null)
                {
                    foreach (object o in annotated.annotation.Items)
                    {
                        if (o is XMLSchema.documentation)
                        {
                            XMLSchema.documentation documentation = o as XMLSchema.documentation;
                            if (documentation.Any != null && documentation.Any.Length > 0 && documentation.Any[0].Value != null)
                            {
                                string text = documentation.Any[0].Value;
                                text    = text.Replace("\n", " ");
                                text    = text.Replace("\t", " ");
                                text    = text.Replace("\r", "");
                                text    = Regex.Replace(text, " +", " ");
                                text    = text.Trim();
                                comment = text;
                            }
                            else if (documentation.source != null)
                            {
                                comment = documentation.source;
                            }
                            break;
                        }
                    }
                }

                //bool lastChild = drawingItem.Parent.ChildElements[drawingItem.Parent.ChildElements.Count - 1] == drawingItem;

                // Output the item
                string            t;
                XMLSchema.element el;
                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                {
                    el = drawingItem.TabSchema as XMLSchema.element;
                    if (el != null)
                    {
                        string et = "" + el.type;
                        if (et == "")
                        {
                            t = "[none]";
                        }
                        else
                        {
                            t = et.Substring(et.LastIndexOf(':') + 1);
                            if (t == "")
                            {
                                t = "[none]";
                            }
                        }
                    }
                    else
                    {
                        t = "[none]";
                    }
                    if (i > 0)
                    {
                        _writer.Write(_fieldSeparator);
                    }
                    string field = _finalTextOutputFields[i];
                    switch (field)
                    {
                    case "PATH": _writer.Write(path); break;

                    case "NAME": _writer.Write(drawingItem.Name); break;

                    case "TYPE": _writer.Write(type); break;

                    case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;

                    case "COMMENT": _writer.Write(comment); break;

                    case "SEQ": _writer.Write(occurences); break;

                    case "LASTCHILD": _writer.Write(this.iteratingLastChild ? "1" : "0"); break;

                    case "XSDTYPE": _writer.Write(t); break;
                    }
                }
                _writer.WriteLine();


                // Output the item attributes
                if (this.Schema != null && this.DisplayAttributes)
                {
                    string nameSpace = drawingItem.NameSpace;
                    if (annotated != null)
                    {
                        // Attributes enumeration
                        List <XSDAttribute> listAttributes = DiagramHelpers.GetAnnotatedAttributes(this.Schema, annotated, nameSpace);
                        listAttributes.Reverse();
                        for (int a = 0; a < listAttributes.Count; a++)
                        {
                            XSDAttribute xsdAttribute = listAttributes[a];
                            if (xsdAttribute != null)
                            {
                                string commentAttribute       = "";
                                XMLSchema.attribute attribute = xsdAttribute.Tag;
                                if (attribute != null && attribute.annotation != null)
                                {
                                    commentAttribute = DiagramHelpers.GetAnnotationText(attribute.annotation);
                                }

                                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                                {
                                    if (i > 0)
                                    {
                                        _writer.Write(_fieldSeparator);
                                    }
                                    string field = _finalTextOutputFields[i];
                                    switch (field)
                                    {
                                    case "PATH": _writer.Write(path + "@" + xsdAttribute.Name); break;

                                    case "NAME": _writer.Write(drawingItem.Name + "@" + xsdAttribute.Name); break;

                                    case "TYPE": _writer.Write(xsdAttribute.Type); break;

                                    case "NAMESPACE": _writer.Write(xsdAttribute.NameSpace); break;

                                    case "COMMENT": _writer.Write(commentAttribute); break;
                                    }
                                }
                                _writer.WriteLine();
                            }

                            //this.listViewAttributes.Items.Add(new ListViewItem(new string[] { attribute.Name, attribute.Type, attribute.Use, attribute.DefaultValue, s })).Tag = attribute;
                        }
                    }
                }


                //// Draw the inheritor line
                //if (drawingItem.InheritFrom != null)
                //{
                //}

                //switch (drawingItem.ItemType)
                //{
                //    case DiagramItemType.element:
                //        break;

                //    case DiagramItemType.type:
                //        break;

                //    case DiagramItemType.group:
                //        {
                //            // Draw the main shape following the min/max occurences

                //            // Draw the group type
                //            switch (drawingItem.GroupType)
                //            {
                //                case DiagramItemGroupType.Sequence: break;
                //                case DiagramItemGroupType.Choice: break;
                //                case DiagramItemGroupType.All: break;
                //            }
                //            break;
                //        }
                //}

                //// Draw text
                //if (drawingItem.Name.Length > 0)
                //{
                //    //drawingItem.Name;
                //}

                //// Draw occurences small text
                //if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}

                //// Draw type
                //if (drawingItem.IsSimpleContent) {}

                //// Draw reference arrow
                //if (drawingItem.IsReference) {}
            }

            // Draw children expand box
            if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
            {
                int c = 0;
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.iteratingLastChild = drawingItem.ChildElements.Count == ++c;
                    this.Render(element);
                    //_writer.WriteLine();
                }
            }
        }
Beispiel #24
0
 public void Clear()
 {
     _elementsByName.Clear();
     _rootElements.Clear();
     _selectedElement = null;
 }
Beispiel #25
0
 public abstract void Render(DiagramItem item);
Beispiel #26
0
 private void SelectSchemaElement(DiagramItem diagramBase)
 {
     SelectSchemaElement(diagramBase.TabSchema, diagramBase.NameSpace);
 }
Beispiel #27
0
 private void ExpandCollapseElement(DiagramItem element, bool scrollToElement)
 {
     if (element != null && element.HasChildElements)
     {
         if (element.ChildElements.Count == 0)
         {
             this.diagram.ExpandChildren(element);
             element.ShowChildElements = true;
         }
         else
             element.ShowChildElements ^= true;
         UpdateDiagram();
         this.panelDiagram.ScrollTo(this.diagram.ScalePoint(element.Location), true);
     }
 }
Beispiel #28
0
        private void SelectDiagramElement(DiagramItem element, bool scrollToElement)
        {
            this.textBoxElementPath.Text = "";

            if (element == null)
            {
                this.toolStripComboBoxSchemaElement.SelectedItem = "";
                this.propertyGridSchemaObject.SelectedObject = null;
                this.listViewAttributes.Items.Clear();
            }
            else
            {
                XSDObject xsdObject;
                if (this.schema.ElementsByName.TryGetValue(element.FullName, out xsdObject) && xsdObject != null)
                    this.toolStripComboBoxSchemaElement.SelectedItem = xsdObject;
                else
                    this.toolStripComboBoxSchemaElement.SelectedItem = null;

                SelectSchemaElement(element);

                string path = '/' + element.Name;
                DiagramItem parentElement = element.Parent;
                while (parentElement != null)
                {
                    if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                        path = '/' + parentElement.Name + path;
                    parentElement = parentElement.Parent;
                }
                this.textBoxElementPath.Text = path;
            }

            this.diagram.SelectElement(element);
            UpdateDiagram();
            if (scrollToElement)
                this.panelDiagram.ScrollTo(this.diagram.ScalePoint(element.Location), true);
        }
Beispiel #29
0
        public DiagramItem AddAny(DiagramItem parentDiagramElement, 
            XMLSchema.any childElement, string nameSpace)
        {
            bool isDisabled = false;
            if (childElement == null)
            {
                isDisabled = true;
                if (_fakeAny == null)
                {
                    _fakeAny = new XMLSchema.any();
                    _fakeAny.minOccurs = "0";
                    _fakeAny.maxOccurs = "unbounded";
                }
                childElement = _fakeAny;
            }
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();
                childDiagramElement.IsDisabled = isDisabled;
                childDiagramElement.Diagram = this;
                childDiagramElement.TabSchema = childElement;
                childDiagramElement.Name = "any  " + childElement.@namespace;
                childDiagramElement.NameSpace = nameSpace;
                childDiagramElement.ItemType = DiagramItemType.group;  //DiagramBase.TypeEnum.element;
                int occurrence;
                if (int.TryParse(childElement.minOccurs, out occurrence))
                    childDiagramElement.MinOccurrence = occurrence;
                else
                    childDiagramElement.MinOccurrence = -1;
                //try { childDiagramElement.MinOccurrence = int.Parse(childElement.minOccurs); }
                //catch { childDiagramElement.MinOccurrence = -1; }
                if (int.TryParse(childElement.maxOccurs, out occurrence))
                    childDiagramElement.MaxOccurrence = occurrence;
                else
                    childDiagramElement.MaxOccurrence = -1;
                //try { childDiagramElement.MaxOccurrence = int.Parse(childElement.maxOccurs); }
                //catch { childDiagramElement.MaxOccurrence = -1; }

                childDiagramElement.IsReference = false;
                childDiagramElement.IsSimpleContent = false;
                childDiagramElement.HasChildElements = false; // true;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramElement);
                }
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                return childDiagramElement;
            }

            return null;
        }
Beispiel #30
0
 private void ExpandAnnotated(DiagramItem parentDiagramElement, 
     XMLSchema.annotated annotated, string nameSpace)
 {
     if (annotated is XMLSchema.element)
     {
         AddElement(parentDiagramElement, annotated as XMLSchema.element, nameSpace);
         parentDiagramElement.ShowChildElements = true;
     }
     else if (annotated is XMLSchema.group)
     {
         AddCompositors(parentDiagramElement, annotated as XMLSchema.group, nameSpace);
         parentDiagramElement.ShowChildElements = true;
     }
     else if (annotated is XMLSchema.complexType)
     {
         ExpandComplexType(parentDiagramElement, annotated as XMLSchema.complexType);
         parentDiagramElement.ShowChildElements = true;
     }
 }
Beispiel #31
0
 public DiagramItem AddComplexType(DiagramItem parentDiagramElement, 
     XMLSchema.complexType childElement, string nameSpace)
 {
     return AddComplexType(parentDiagramElement, childElement,
         false, nameSpace);
 }
Beispiel #32
0
        private void ExpandOneLevel(DiagramItem parentItem)
        {
            foreach (DiagramItem item in parentItem.ChildElements)
            {
                this.ExpandOneLevel(item);

                if (item.HasChildElements && item.ChildElements.Count == 0)
                {
                    this.ExpandChildren(item);
                }
            }
        }
Beispiel #33
0
        private void ExpandComplexType(DiagramItem parentDiagramElement,
                                       XMLSchema.complexType complexTypeElement)
        {
            if (complexTypeElement.Items != null)
            {
                XMLSchema.annotated[]        items           = complexTypeElement.Items;
                XMLSchema.ItemsChoiceType4[] itemsChoiceType = complexTypeElement.ItemsElementName;

                for (int i = 0; i < items.Length; i++)
                {
                    if (items[i] is XMLSchema.group)
                    {
                        XMLSchema.group group = items[i] as XMLSchema.group;
                        DiagramItem     diagramCompositors = AddCompositors(parentDiagramElement,
                                                                            group, (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), itemsChoiceType[i].ToString(), true), parentDiagramElement.NameSpace);
                        parentDiagramElement.ShowChildElements = true;
                        if (diagramCompositors != null)
                        {
                            ExpandChildren(diagramCompositors);
                        }
                    }
                    else if (items[i] is XMLSchema.complexContent)
                    {
                        XMLSchema.complexContent complexContent = items[i] as XMLSchema.complexContent;
                        if (complexContent.Item is XMLSchema.extensionType)
                        {
                            XMLSchema.extensionType extensionType = complexContent.Item as XMLSchema.extensionType;

                            XSDObject xsdObject = null;
                            if (_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }

                            XMLSchema.group group = extensionType.group as XMLSchema.group;
                            if (group != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, group, DiagramItemGroupType.Group, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupSequence = extensionType.sequence as XMLSchema.group;
                            if (groupSequence != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupSequence, DiagramItemGroupType.Sequence, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupChoice = extensionType.choice as XMLSchema.group;
                            if (groupChoice != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupChoice, DiagramItemGroupType.Choice, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupAll = extensionType.all as XMLSchema.group;
                            if (groupAll != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupAll, DiagramItemGroupType.All, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }
                        }
                        else if (complexContent.Item is XMLSchema.restrictionType)
                        {
                            XMLSchema.restrictionType restrictionType = complexContent.Item as XMLSchema.restrictionType;
                            XSDObject xsdObject = null;
                            if (_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }
                            else
                            {
                                //dgis fix github issue 2
                                if (restrictionType.Items != null)
                                {
                                    //for (int j = 0; j < items.Length; j++)
                                    for (int j = 0; j < restrictionType.Items.Length; j++)
                                    {
                                        if (restrictionType.Items[j] is XMLSchema.group)
                                        {
                                            XMLSchema.group group = restrictionType.Items[j] as XMLSchema.group;
                                            DiagramItem     diagramCompositors = AddCompositors(parentDiagramElement, group,
                                                                                                (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), restrictionType.ItemsElementName[j].ToString(), true), parentDiagramElement.NameSpace);
                                            parentDiagramElement.ShowChildElements = true;
                                            if (diagramCompositors != null)
                                            {
                                                ExpandChildren(diagramCompositors);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #34
0
 public abstract void Render(DiagramItem item);
        public override void Render(DiagramItem drawingItem)
        {
            //if (drawingItem.diagram.ShowBoundingBox)
            //{
            //    int color = 255 - depth * 8;
            //    g.FillRectangle(new SolidBrush(Color.FromArgb(color, color, color)), drawingItem.ScaleRectangle(drawingItem.boundingBox));
            //    g.DrawRectangle(foregroundPen, drawingItem.ScaleRectangle(drawingItem.boundingBox));
            //}

            // Draw the children
            if (drawingItem.ShowChildElements)
            {
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.Render(element);
                    _writer.WriteLine();
                }
            }

            string backgroundBrush = "fill:rgb(255,255,255)";
            string foregroundColor = "rgb(0,0,0)";
            string foregroundBrush = "fill:" + foregroundColor;
            string foregroundPen = "stroke:" + foregroundColor + ";stroke-width:1";
            string foregroundRoundPen = foregroundPen + ";stroke-linecap:round";
            string dashed = "stroke-dasharray:4,1";

            Rectangle scaledElementBox = drawingItem.ScaleRectangle(drawingItem.ElementBox);

            // Draw the children lines
            if (drawingItem.ShowChildElements)
            {
                if (drawingItem.ChildElements.Count == 1)
                {
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    this.SVGLine(foregroundRoundPen,
                        drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
                        parentMidleY, drawingItem.ScaleInt(drawingItem.ChildElements[0].Location.X), parentMidleY);
                }
                else if (drawingItem.ChildElements.Count > 1)
                {
                    DiagramItem firstElement = drawingItem.ChildElements[0];
                    DiagramItem lastElement  = drawingItem.ChildElements[drawingItem.ChildElements.Count - 1];
                    int verticalLine         = drawingItem.ScaleInt(firstElement.BoundingBox.Left);

                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.InheritFrom == null)
                        {
                            int currentMidleY = drawingItem.ScaleInt(element.Location.Y + element.Size.Height / 2);
                            SVGLine(foregroundRoundPen, verticalLine, currentMidleY,
                                drawingItem.ScaleInt(element.Location.X), currentMidleY);
                        }
                    }

                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    int firstMidleY  = drawingItem.ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
                    firstMidleY      = Math.Min(firstMidleY, parentMidleY);
                    int lastMidleY   = drawingItem.ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
                    lastMidleY       = Math.Max(lastMidleY, parentMidleY);
                    this.SVGLine(foregroundRoundPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
                    this.SVGLine(foregroundRoundPen,
                        drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width),
                        parentMidleY, verticalLine, parentMidleY);
                }
            }

            // Draw the inheritor line
            if (drawingItem.InheritFrom != null)
            {
                string foregroundInheritPen = foregroundPen + ";" + dashed;

                Point p1 = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 5),
                    drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 5));
                Point p2 = new Point(drawingItem.ScaleInt(drawingItem.Location.X - 5),
                    drawingItem.ScaleInt(drawingItem.Location.Y - 5));
                this.SVGLine(foregroundInheritPen, p1, p2);
                this.SVGLine(foregroundInheritPen, p2,
                    new Point(drawingItem.ScaleInt(drawingItem.Location.X), drawingItem.ScaleInt(drawingItem.Location.Y)));

                Point targetPoint = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 3),
                    drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 3));
                SVGLine(foregroundInheritPen, targetPoint, p1);
                Point[] pathPoint = new Point[5];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint;
                pathPoint[1].X += drawingItem.ScaleInt(2);
                pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2] = targetPoint;
                pathPoint[2].X += drawingItem.ScaleInt(3);
                pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3] = targetPoint;
                pathPoint[3].X -= drawingItem.ScaleInt(2);
                pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4] = targetPoint;

                string path = SVGPolygonToDrawCommand(pathPoint);
                SVGPath(backgroundBrush + ";" + foregroundPen, path);
            }

            switch (drawingItem.ItemType)
            {
                case DiagramItemType.element:
                    {
                        // Draw the main shape following the min/max occurences
                        string foregroundBoxPen = foregroundPen;

                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen += ";" + dashed;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
                        }
                        else
                        {
                            Rectangle elementBoxShifted = scaledElementBox;
                            elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                            this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, elementBoxShifted);
                            this.SVGRectangle(backgroundBrush + ";" + foregroundBoxPen, scaledElementBox);
                        }
                    }
                    break;

                case DiagramItemType.type:
                    {
                        // Draw the main shape following the min/max occurences
                        int bevel = (int)(scaledElementBox.Height * 0.30);
                        Point[] pathPoint = new Point[6];
                        pathPoint[0]    = pathPoint[5] = scaledElementBox.Location;
                        pathPoint[1]    = scaledElementBox.Location;
                        pathPoint[1].X  = scaledElementBox.Right;
                        pathPoint[2]    = scaledElementBox.Location + scaledElementBox.Size;
                        pathPoint[3]    = scaledElementBox.Location;
                        pathPoint[3].Y  = scaledElementBox.Bottom;
                        pathPoint[4]    = pathPoint[3];
                        pathPoint[0].X += bevel;
                        pathPoint[3].X += bevel;
                        pathPoint[4].Y -= bevel;
                        pathPoint[5].Y += bevel;

                        string path = SVGPolygonToDrawCommand(pathPoint);

                        Point[] pathPointShifted = new Point[6];
                        Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                        for (int i = 0; i < pathPoint.Length; i++)
                            pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;

                        string pathShifted = SVGPolygonToDrawCommand(pathPointShifted);

                        string foregroundBoxPen = foregroundPen;
                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen += ";" + dashed;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                        }
                        else
                        {
                            Rectangle elementBoxShifted = scaledElementBox;
                            elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                            this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
                            this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                        }
                    }
                    break;

                case DiagramItemType.group:
                    {
                        // Draw the main shape following the min/max occurences
                        int bevel = (int)(scaledElementBox.Height * 0.30);
                        Point[] pathPoint = new Point[8];
                        pathPoint[0] = pathPoint[7] = scaledElementBox.Location;
                        pathPoint[1] = scaledElementBox.Location;
                        pathPoint[1].X = scaledElementBox.Right; pathPoint[2] = pathPoint[1];
                        pathPoint[3] = pathPoint[4] = scaledElementBox.Location + scaledElementBox.Size;
                        pathPoint[5] = scaledElementBox.Location;
                        pathPoint[5].Y = scaledElementBox.Bottom;
                        pathPoint[6] = pathPoint[5];
                        pathPoint[0].X += bevel;
                        pathPoint[1].X -= bevel;
                        pathPoint[2].Y += bevel;
                        pathPoint[3].Y -= bevel;
                        pathPoint[4].X -= bevel;
                        pathPoint[5].X += bevel;
                        pathPoint[6].Y -= bevel;
                        pathPoint[7].Y += bevel;

                        string path = SVGPolygonToDrawCommand(pathPoint);

                        Point[] pathPointShifted = new Point[8];
                        Size scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                        for (int i = 0; i < pathPoint.Length; i++)
                            pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;

                        string pathShifted = this.SVGPolygonToDrawCommand(pathPointShifted);

                        string foregroundBoxPen = foregroundPen;
                        if (drawingItem.MinOccurrence == 0)
                        {
                            foregroundBoxPen += ";" + dashed;
                        }
                        if (drawingItem.MaxOccurrence == 1)
                        {
                            this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                        }
                        else
                        {
                            this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, pathShifted);
                            this.SVGPath(backgroundBrush + ";" + foregroundBoxPen, path);
                        }

                        // Draw the group type
                        switch (drawingItem.GroupType)
                        {
                            case DiagramItemGroupType.Sequence:
                                {
                                    Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                                    Point p1 = p0 + new Size(3, 0);
                                    Point p2 = p1 + new Size(drawingItem.ElementBox.Width - 6, 0);
                                    SVGLine(foregroundPen, drawingItem.ScalePoint(p1), drawingItem.ScalePoint(p2));
                                    Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                                    Point point1 = point2 + new Size(-5, 0);
                                    Point point3 = point2 + new Size(+5, 0);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    SVGEllipse(foregroundColor, new Rectangle(drawingItem.ScalePoint(point3), pointSize));

                                    //Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                                    //Point point0 = p0 + new Size(3, 0);
                                    //Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                                    //Point point1 = point2 + new Size(-5, 0);
                                    //Point point3 = point2 + new Size(+5, 0);
                                    //Point point4 = point0 + new Size(drawingItem.ElementBox.Width - 6, 0);

                                    //Pen foregroundBallPen = new Pen(foreground);
                                    //foregroundBallPen.EndCap = LineCap.RoundAnchor;
                                    ////foregroundBallPen.ScaleTransform(1.0f / drawingItem.diagram.Scale, 1.0f / drawingItem.diagram.Scale);
                                    //foregroundBallPen.ScaleTransform(drawingItem.diagram.Scale, drawingItem.diagram.Scale);

                                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point0), drawingItem.ScalePoint(point1));
                                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point1), drawingItem.ScalePoint(point2));
                                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point2), drawingItem.ScalePoint(point3));
                                    //foregroundBallPen.EndCap = LineCap.Flat;
                                    //SVGDrawLine(result, foregroundBallPen, drawingItem.ScalePoint(point3), drawingItem.ScalePoint(point4));
                                }
                                break;
                            case DiagramItemGroupType.Choice:
                                {
                                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                                    int yUp = yMiddle - 4;
                                    int yDown = yMiddle + 4;
                                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                                    int xLeft2 = xMiddle - 4;
                                    int xLeft1 = xLeft2 - 4;
                                    int xLeft0 = xLeft1 - 4;
                                    int xRight0 = xMiddle + 4;
                                    int xRight1 = xRight0 + 4;
                                    int xRight2 = xRight1 + 4;

                                    Point point1 = new Point(xMiddle, yUp);
                                    Point point2 = new Point(xMiddle, yMiddle);
                                    Point point3 = new Point(xMiddle, yDown);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft0, yMiddle)),
                                        drawingItem.ScalePoint(new Point(xLeft1, yMiddle)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft1, yMiddle)),
                                        drawingItem.ScalePoint(new Point(xLeft2, yUp)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yUp)),
                                        drawingItem.ScalePoint(new Point(xRight1, yUp)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
                                        drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yDown)),
                                        drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight1, yUp)),
                                        drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                                }
                                break;
                            case DiagramItemGroupType.All:
                                {
                                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                                    int yUp = yMiddle - 4;
                                    int yDown = yMiddle + 4;
                                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                                    int xLeft2 = xMiddle - 4;
                                    int xLeft1 = xLeft2 - 4;
                                    int xLeft0 = xLeft1 - 4;
                                    int xRight0 = xMiddle + 4;
                                    int xRight1 = xRight0 + 4;
                                    int xRight2 = xRight1 + 4;

                                    Point point1 = new Point(xMiddle, yUp);
                                    Point point2 = new Point(xMiddle, yMiddle);
                                    Point point3 = new Point(xMiddle, yDown);
                                    Size pointSize = new Size(4, 4);
                                    Size pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                                    point1 -= pointSize2;
                                    point2 -= pointSize2;
                                    point3 -= pointSize2;
                                    pointSize = drawingItem.ScaleSize(pointSize);
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft2, yUp)),
                                        drawingItem.ScalePoint(new Point(xLeft1, yUp)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft2, yMiddle)),
                                        drawingItem.ScalePoint(new Point(xLeft0, yMiddle)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft2, yDown)),
                                        drawingItem.ScalePoint(new Point(xLeft1, yDown)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xLeft1, yUp)),
                                        drawingItem.ScalePoint(new Point(xLeft1, yDown)));

                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yUp)),
                                        drawingItem.ScalePoint(new Point(xRight1, yUp)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yMiddle)),
                                        drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight0, yDown)),
                                        drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    SVGLine(foregroundPen,
                                        drawingItem.ScalePoint(new Point(xRight1, yUp)),
                                        drawingItem.ScalePoint(new Point(xRight1, yDown)));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                                    SVGEllipse(foregroundColor,
                                        new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                                }
                                break;
                        }
                        break;
                    }
            }

            float fontScale = 0.8f;

            // Draw text
            if (drawingItem.Name.Length > 0)
            {
                string style = String.Format(
                    "font-family:{0};font-size:{1}pt;fill:{2};font-weight:bold;text-anchor:middle;dominant-baseline:central",
                    drawingItem.Font.Name, drawingItem.Font.Size * fontScale, foregroundColor);
                SVGText(drawingItem.Name, style,
                    new Rectangle(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height));
            }

            // Draw occurences small text
            if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1)
            {
                string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
                    (drawingItem.MaxOccurrence == -1 ? "∞" : string.Format("{0}", drawingItem.MaxOccurrence));
                PointF pointOccurences = new PointF();
                pointOccurences.X = drawingItem.Diagram.Scale * (drawingItem.Location.X + drawingItem.Size.Width - 10);
                pointOccurences.Y = drawingItem.Diagram.Scale * (drawingItem.Location.Y + drawingItem.Size.Height + 10);
                string style = String.Format(
                    "font-family:{0};font-size:{1}pt;fill:{2};text-anchor:end;dominant-baseline:central",
                    drawingItem.SmallFont.Name, drawingItem.SmallFont.Size * fontScale, foregroundColor);
                SVGText(occurences, style, new Point((int)pointOccurences.X, (int)pointOccurences.Y));
            }

            // Draw type
            if (drawingItem.IsSimpleContent)
            {
                Point currentPoint = scaledElementBox.Location + new Size(2, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(8), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                SVGLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
            }

            // Draw reference arrow
            if (drawingItem.IsReference)
            {
                string arrowPen = String.Format("stroke:{0};stroke-width:{1}",
                    foregroundColor, drawingItem.Diagram.Scale * 2.0f);
                Point basePoint = new Point(drawingItem.ElementBox.Left + 1, drawingItem.ElementBox.Bottom - 1);
                Point targetPoint = basePoint + new Size(3, -3);
                basePoint = drawingItem.ScalePoint(basePoint);
                targetPoint = drawingItem.ScalePoint(targetPoint);
                SVGLine(arrowPen, basePoint, targetPoint);

                Point[] pathPoint = new Point[5];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint;
                pathPoint[1].X += drawingItem.ScaleInt(2);
                pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2] = targetPoint;
                pathPoint[2].X += drawingItem.ScaleInt(3);
                pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3] = targetPoint;
                pathPoint[3].X -= drawingItem.ScaleInt(2);
                pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4] = targetPoint;

                string path = SVGPolygonToDrawCommand(pathPoint);
                SVGPath(foregroundBrush, path);
            }

            // Draw children expand box
            if (drawingItem.HasChildElements)
            {
                Rectangle scaledChildExpandButtonBox = drawingItem.ScaleRectangle(drawingItem.ChildExpandButtonBox);
                SVGRectangle(backgroundBrush + ";" + foregroundPen, scaledChildExpandButtonBox);

                Point middle = new Point(scaledChildExpandButtonBox.Width / 2, scaledChildExpandButtonBox.Height / 2);
                int borderPadding = Math.Max(2, drawingItem.ScaleInt(2));

                Point p1 = scaledChildExpandButtonBox.Location + new Size(borderPadding, middle.Y);
                Point p2 = new Point(scaledChildExpandButtonBox.Right - borderPadding, p1.Y);
                SVGLine(foregroundPen, p1, p2);
                if (!drawingItem.ShowChildElements)
                {
                    p1 = scaledChildExpandButtonBox.Location + new Size(middle.X, borderPadding);
                    p2 = new Point(p1.X, scaledChildExpandButtonBox.Bottom - borderPadding);
                    SVGLine(foregroundPen, p1, p2);
                }
            }
        }
Beispiel #36
0
        public DiagramItem AddElement(DiagramItem parentDiagramElement, XMLSchema.element childElement, string nameSpace)
        {
            ClearSearch();
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();

                XMLSchema.element referenceElement = null;
                if (childElement.@ref != null)
                {
                    if ([email protected])
                    {
                        childDiagramElement.IsReference = true;

                        XSDObject objectReferred = null;
                        if (_elementsByName.TryGetValue([email protected] + ":element:" + [email protected], out objectReferred) && objectReferred != null)
                        {
                            XMLSchema.element elementReferred = objectReferred.Tag as XMLSchema.element;
                            if (elementReferred != null)
                            {
                                referenceElement = childElement;
                                childElement     = elementReferred;
                            }
                        }
                        else
                        {
                            childElement.name = [email protected];
                        }
                    }
                }

                childDiagramElement.Diagram   = this;
                childDiagramElement.TabSchema = childElement;
                childDiagramElement.Name      = childElement.name != null ? childElement.name : "";
                childDiagramElement.NameSpace = nameSpace;
                string type = childDiagramElement.GetTypeAnnotation();
                if (!String.IsNullOrEmpty(type))
                {
                    childDiagramElement.Type = type;
                }
                childDiagramElement.ItemType = DiagramItemType.element;
                int occurrence;
                if (int.TryParse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs, out occurrence))
                {
                    childDiagramElement.MinOccurrence = occurrence;
                }
                else
                {
                    childDiagramElement.MinOccurrence = -1;
                }
                //try { childDiagramElement.MinOccurrence = int.Parse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs); }
                //catch { childDiagramElement.MinOccurrence = -1; }
                if (int.TryParse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs, out occurrence))
                {
                    childDiagramElement.MaxOccurrence = occurrence;
                }
                else
                {
                    childDiagramElement.MaxOccurrence = -1;
                }
                //try { childDiagramElement.MaxOccurrence = int.Parse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs); }
                //catch { childDiagramElement.MaxOccurrence = -1; }

                bool hasChildren;
                bool isSimpleType;
                GetChildrenInfo(childElement, out hasChildren, out isSimpleType);
                childDiagramElement.HasChildElements = hasChildren;
                childDiagramElement.IsSimpleContent  = isSimpleType;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramElement);
                }
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                if (childElement.@abstract)
                {
                    string abstractElementFullName = childDiagramElement.FullName;
                    foreach (XSDObject xsdObject in _elementsByName.Values)
                    {
                        if (xsdObject != null && xsdObject.Tag is XMLSchema.element)
                        {
                            XMLSchema.element element = xsdObject.Tag as XMLSchema.element;
                            if (element.substitutionGroup != null)
                            {
                                string elementFullName = element.substitutionGroup.Namespace + ":element:" + element.substitutionGroup.Name;
                                if (elementFullName == abstractElementFullName)
                                {
                                    DiagramItem diagramBase = AddElement(parentDiagramElement, element, xsdObject.NameSpace);
                                    if (diagramBase != null)
                                    {
                                        diagramBase.InheritFrom = childDiagramElement;
                                    }
                                }
                            }
                        }
                    }
                }

                return(childDiagramElement);
            }

            return(null);
        }
Beispiel #37
0
        public void Render(DiagramItem drawingItem, Rectangle?clipRectangle)
        {
            //System.Diagnostics.Trace.WriteLine("DiagramElement.Paint\n\tName: " + drawingItem.Name);

            Brush      background = new SolidBrush(Color.White);
            SolidBrush foreground = new SolidBrush(Color.Black);

            if (drawingItem.IsDisabled)
            {
                background = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Gray, Color.White);
                foreground = new SolidBrush(Color.Gray);
            }
            Pen foregroundPen = new Pen(foreground);

            float[] dashPattern = new float[] { Math.Max(2f, drawingItem.ScaleInt(5)), Math.Max(1f, drawingItem.ScaleInt(2)) };

            //if (drawingItem.IsReference && drawingItem.diagram.ShowBoundingBox)
            if (drawingItem.Diagram.ShowBoundingBox)
            {
                int color = 255 - drawingItem.Depth * 8;
                _graphics.FillRectangle(new SolidBrush(Color.FromArgb(color, color, color)), drawingItem.ScaleRectangle(drawingItem.BoundingBox));
                _graphics.DrawRectangle(foregroundPen, drawingItem.ScaleRectangle(drawingItem.BoundingBox));
            }

            // Draw the children
            if (drawingItem.ShowChildElements)
            {
                if (clipRectangle.HasValue)
                {
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.BoundingBox.IntersectsWith(clipRectangle.Value))
                        {
                            this.Render(element, clipRectangle);
                        }
                    }
                }
                else
                {
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        this.Render(element);
                    }
                }
            }

            Rectangle scaledElementBox = drawingItem.ScaleRectangle(drawingItem.ElementBox);

            // Draw the children lines
            if (drawingItem.ShowChildElements)
            {
                Pen foregroundInheritPen = new Pen(foreground);
                foregroundInheritPen.StartCap = LineCap.Round;
                foregroundInheritPen.EndCap   = LineCap.Round;

                if (drawingItem.ChildElements.Count == 1)
                {
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    _graphics.DrawLine(foregroundInheritPen, drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width), parentMidleY, drawingItem.ScaleInt(drawingItem.ChildElements[0].Location.X), parentMidleY);
                }
                else if (drawingItem.ChildElements.Count > 1)
                {
                    DiagramItem firstElement = drawingItem.ChildElements[0];
                    DiagramItem lastElement  = drawingItem.ChildElements[drawingItem.ChildElements.Count - 1];
                    int         verticalLine = drawingItem.ScaleInt(firstElement.BoundingBox.Left);
                    foreach (DiagramItem element in drawingItem.ChildElements)
                    {
                        if (element.InheritFrom == null)
                        {
                            int currentMidleY = drawingItem.ScaleInt(element.Location.Y + element.Size.Height / 2);
                            _graphics.DrawLine(foregroundInheritPen, verticalLine, currentMidleY, drawingItem.ScaleInt(element.Location.X), currentMidleY);
                        }
                    }
                    int parentMidleY = drawingItem.ScaleInt(drawingItem.Location.Y + drawingItem.Size.Height / 2);
                    int firstMidleY  = drawingItem.ScaleInt(firstElement.Location.Y + firstElement.Size.Height / 2);
                    firstMidleY = Math.Min(firstMidleY, parentMidleY);
                    int lastMidleY = drawingItem.ScaleInt(lastElement.Location.Y + lastElement.Size.Height / 2);
                    lastMidleY = Math.Max(lastMidleY, parentMidleY);
                    _graphics.DrawLine(foregroundInheritPen, verticalLine, firstMidleY, verticalLine, lastMidleY);
                    _graphics.DrawLine(foregroundInheritPen, drawingItem.ScaleInt(drawingItem.Location.X + drawingItem.Size.Width), parentMidleY, verticalLine, parentMidleY);
                }
            }


            // Draw the inheritor line
            if (drawingItem.InheritFrom != null)
            {
                Pen foregroundInheritPen = new Pen(foreground);
                foregroundInheritPen.DashStyle   = DashStyle.Dash;
                foregroundInheritPen.DashPattern = dashPattern;

                Point p1 = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X - 5), drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height + 5));
                Point p2 = new Point(drawingItem.ScaleInt(drawingItem.Location.X - 5), drawingItem.ScaleInt(drawingItem.Location.Y - 5));
                _graphics.DrawLine(foregroundInheritPen, p1, p2);
                _graphics.DrawLine(foregroundInheritPen, p2, new Point(drawingItem.ScaleInt(drawingItem.Location.X), drawingItem.ScaleInt(drawingItem.Location.Y)));

                Point targetPoint = new Point(drawingItem.ScaleInt(drawingItem.InheritFrom.Location.X), drawingItem.ScaleInt(drawingItem.InheritFrom.Location.Y + drawingItem.InheritFrom.Size.Height));
                _graphics.DrawLine(foregroundInheritPen, targetPoint, p1);

                Point[] pathPoint = new Point[4];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint; pathPoint[1].Y += drawingItem.ScaleInt(5);
                pathPoint[2] = targetPoint; pathPoint[2].X -= drawingItem.ScaleInt(5);
                pathPoint[3] = targetPoint;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();

                Pen foregroundBoxPen = new Pen(foreground);
                _graphics.FillPath(background, path);
                _graphics.DrawPath(foregroundBoxPen, path);
            }

            switch (drawingItem.ItemType)
            {
            case DiagramItemType.element:
            {
                // Draw the main shape following the min/max occurences
                Pen foregroundBoxPen = new Pen(foreground);
                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Dash;
                    foregroundBoxPen.DashPattern = dashPattern;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    _graphics.FillRectangle(background, scaledElementBox);
                    _graphics.DrawRectangle(foregroundBoxPen, scaledElementBox);
                }
                else
                {
                    Rectangle elementBoxShifted = scaledElementBox;
                    elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                    _graphics.FillRectangle(background, elementBoxShifted);
                    _graphics.DrawRectangle(foregroundBoxPen, elementBoxShifted);
                    _graphics.FillRectangle(background, scaledElementBox);
                    _graphics.DrawRectangle(foregroundBoxPen, scaledElementBox);
                }
            }
            break;

            case DiagramItemType.type:
            {
                // Draw the main shape following the min/max occurences
                int     bevel     = (int)(scaledElementBox.Height * 0.30);
                Point[] pathPoint = new Point[6];
                pathPoint[0]    = pathPoint[5] = scaledElementBox.Location;
                pathPoint[1]    = scaledElementBox.Location; pathPoint[1].X = scaledElementBox.Right;
                pathPoint[2]    = scaledElementBox.Location + scaledElementBox.Size;
                pathPoint[3]    = scaledElementBox.Location; pathPoint[3].Y = scaledElementBox.Bottom; pathPoint[4] = pathPoint[3];
                pathPoint[0].X += bevel;
                pathPoint[3].X += bevel;
                pathPoint[4].Y -= bevel;
                pathPoint[5].Y += bevel;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();

                Point[] pathPointShifted   = new Point[6];
                Size    scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                for (int i = 0; i < pathPoint.Length; i++)
                {
                    pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
                }

                GraphicsPath pathShifted = new GraphicsPath();
                pathShifted.StartFigure();
                pathShifted.AddPolygon(pathPointShifted);
                pathShifted.CloseFigure();

                Pen foregroundBoxPen = new Pen(foreground);
                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Dash;
                    foregroundBoxPen.DashPattern = dashPattern;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    _graphics.FillPath(background, path);
                    _graphics.DrawPath(foregroundBoxPen, path);
                }
                else
                {
                    Rectangle elementBoxShifted = scaledElementBox;
                    elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                    _graphics.FillPath(background, pathShifted);
                    _graphics.DrawPath(foregroundBoxPen, pathShifted);
                    _graphics.FillPath(background, path);
                    _graphics.DrawPath(foregroundBoxPen, path);
                }
            }
            break;

            case DiagramItemType.group:
            {
                // Draw the main shape following the min/max occurences
                int     bevel     = (int)(scaledElementBox.Height * 0.30);
                Point[] pathPoint = new Point[8];
                pathPoint[0]    = pathPoint[7] = scaledElementBox.Location;
                pathPoint[1]    = scaledElementBox.Location; pathPoint[1].X = scaledElementBox.Right; pathPoint[2] = pathPoint[1];
                pathPoint[3]    = pathPoint[4] = scaledElementBox.Location + scaledElementBox.Size;
                pathPoint[5]    = scaledElementBox.Location; pathPoint[5].Y = scaledElementBox.Bottom; pathPoint[6] = pathPoint[5];
                pathPoint[0].X += bevel;
                pathPoint[1].X -= bevel;
                pathPoint[2].Y += bevel;
                pathPoint[3].Y -= bevel;
                pathPoint[4].X -= bevel;
                pathPoint[5].X += bevel;
                pathPoint[6].Y -= bevel;
                pathPoint[7].Y += bevel;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();

                Point[] pathPointShifted   = new Point[8];
                Size    scaledShiftedBevel = drawingItem.ScaleSize(new Size(3, 3));
                for (int i = 0; i < pathPoint.Length; i++)
                {
                    pathPointShifted[i] = pathPoint[i] + scaledShiftedBevel;
                }

                GraphicsPath pathShifted = new GraphicsPath();
                pathShifted.StartFigure();
                pathShifted.AddPolygon(pathPointShifted);
                pathShifted.CloseFigure();

                Pen foregroundBoxPen = new Pen(foreground);
                if (drawingItem.MinOccurrence == 0)
                {
                    foregroundBoxPen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Dash;
                    foregroundBoxPen.DashPattern = dashPattern;
                }
                if (drawingItem.MaxOccurrence == 1)
                {
                    _graphics.FillPath(background, path);
                    _graphics.DrawPath(foregroundBoxPen, path);
                }
                else
                {
                    Rectangle elementBoxShifted = scaledElementBox;
                    elementBoxShifted.Offset(drawingItem.ScalePoint(new Point(3, 3)));
                    _graphics.FillPath(background, pathShifted);
                    _graphics.DrawPath(foregroundBoxPen, pathShifted);
                    _graphics.FillPath(background, path);
                    _graphics.DrawPath(foregroundBoxPen, path);
                }

                // Draw the group type
                //Pen foregroundPointPen = new Pen(foreground, 4.0f);
                switch (drawingItem.GroupType)
                {
                case DiagramItemGroupType.Sequence:
                {
                    Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                    Point p1 = p0 + new Size(3, 0);
                    Point p2 = p1 + new Size(drawingItem.ElementBox.Width - 6, 0);
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(p1), drawingItem.ScalePoint(p2));
                    Point point2     = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                    Point point1     = point2 + new Size(-5, 0);
                    Point point3     = point2 + new Size(+5, 0);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));

                    //Point p0 = drawingItem.Location + new Size(0, drawingItem.ElementBox.Height / 2);
                    //Point point0 = p0 + new Size(3, 0);
                    //Point point2 = p0 + new Size(drawingItem.ElementBox.Width / 2, 0);
                    //Point point1 = point2 + new Size(-5, 0);
                    //Point point3 = point2 + new Size(+5, 0);
                    //Point point4 = point0 + new Size(drawingItem.ElementBox.Width - 6, 0);

                    //Pen foregroundBallPen = new Pen(foreground);
                    //foregroundBallPen.EndCap = LineCap.RoundAnchor;
                    ////foregroundBallPen.ScaleTransform(1.0f / drawingItem.diagram.Scale, 1.0f / drawingItem.diagram.Scale);
                    //foregroundBallPen.ScaleTransform(drawingItem.diagram.Scale, drawingItem.diagram.Scale);

                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point0), drawingItem.ScalePoint(point1));
                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point1), drawingItem.ScalePoint(point2));
                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point2), drawingItem.ScalePoint(point3));
                    //foregroundBallPen.EndCap = LineCap.Flat;
                    //g.DrawLine(foregroundBallPen, drawingItem.ScalePoint(point3), drawingItem.ScalePoint(point4));
                }
                break;

                case DiagramItemGroupType.Choice:
                {
                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                    int yUp     = yMiddle - 4;
                    int yDown   = yMiddle + 4;
                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                    int xLeft2  = xMiddle - 4;
                    int xLeft1  = xLeft2 - 4;
                    int xLeft0  = xLeft1 - 4;
                    int xRight0 = xMiddle + 4;
                    int xRight1 = xRight0 + 4;
                    int xRight2 = xRight1 + 4;

                    Point point1     = new Point(xMiddle, yUp);
                    Point point2     = new Point(xMiddle, yMiddle);
                    Point point3     = new Point(xMiddle, yDown);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft0, yMiddle)), drawingItem.ScalePoint(new Point(xLeft1, yMiddle)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft1, yMiddle)), drawingItem.ScalePoint(new Point(xLeft2, yUp)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yUp)), drawingItem.ScalePoint(new Point(xRight1, yUp)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yMiddle)), drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yDown)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight1, yUp)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                }
                break;

                case DiagramItemGroupType.All:
                {
                    int yMiddle = drawingItem.ElementBox.Y + drawingItem.ElementBox.Height / 2;
                    int yUp     = yMiddle - 4;
                    int yDown   = yMiddle + 4;
                    int xMiddle = drawingItem.ElementBox.X + drawingItem.ElementBox.Width / 2;
                    int xLeft2  = xMiddle - 4;
                    int xLeft1  = xLeft2 - 4;
                    int xLeft0  = xLeft1 - 4;
                    int xRight0 = xMiddle + 4;
                    int xRight1 = xRight0 + 4;
                    int xRight2 = xRight1 + 4;

                    Point point1     = new Point(xMiddle, yUp);
                    Point point2     = new Point(xMiddle, yMiddle);
                    Point point3     = new Point(xMiddle, yDown);
                    Size  pointSize  = new Size(4, 4);
                    Size  pointSize2 = new Size(pointSize.Width / 2, pointSize.Height / 2);
                    point1   -= pointSize2;
                    point2   -= pointSize2;
                    point3   -= pointSize2;
                    pointSize = drawingItem.ScaleSize(pointSize);
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yUp)), drawingItem.ScalePoint(new Point(xLeft1, yUp)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yMiddle)), drawingItem.ScalePoint(new Point(xLeft0, yMiddle)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft2, yDown)), drawingItem.ScalePoint(new Point(xLeft1, yDown)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xLeft1, yUp)), drawingItem.ScalePoint(new Point(xLeft1, yDown)));

                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yUp)), drawingItem.ScalePoint(new Point(xRight1, yUp)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yMiddle)), drawingItem.ScalePoint(new Point(xRight2, yMiddle)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight0, yDown)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    _graphics.DrawLine(foregroundPen, drawingItem.ScalePoint(new Point(xRight1, yUp)), drawingItem.ScalePoint(new Point(xRight1, yDown)));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point1), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point2), pointSize));
                    _graphics.FillEllipse(foreground, new Rectangle(drawingItem.ScalePoint(point3), pointSize));
                }
                break;
                }
                break;
            }
            }

            // Draw text
            if (drawingItem.Name.Length > 0)
            {
                StringFormat stringFormatText = new StringFormat();
                stringFormatText.Alignment     = StringAlignment.Center;
                stringFormatText.LineAlignment = StringAlignment.Center;
                stringFormatText.FormatFlags  |= StringFormatFlags.NoClip; //MONOFIX
                _graphics.DrawString(drawingItem.Name, drawingItem.Font, foreground, new RectangleF(scaledElementBox.X, scaledElementBox.Y, scaledElementBox.Width, scaledElementBox.Height), stringFormatText);
            }

            // Draw occurences small text
            if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1)
            {
                StringFormat stringFormatOccurences = new StringFormat();
                stringFormatOccurences.Alignment     = StringAlignment.Far;
                stringFormatOccurences.LineAlignment = StringAlignment.Center;
                stringFormatOccurences.FormatFlags  |= StringFormatFlags.NoClip; //MONOFIX
                //string occurences = string.Format("{0}..", drawingItem.MinOccurrence) + (drawingItem.MaxOccurrence == -1 ? "\u0066∞" : string.Format("{0}", drawingItem.MaxOccurrence));
                string occurences      = string.Format("{0}..", drawingItem.MinOccurrence) + (drawingItem.MaxOccurrence == -1 ? "\u221E" : string.Format("{0}", drawingItem.MaxOccurrence));
                PointF pointOccurences = new PointF();
                pointOccurences.X = drawingItem.Diagram.Scale * (drawingItem.Location.X + drawingItem.Size.Width - 10);
                pointOccurences.Y = drawingItem.Diagram.Scale * (drawingItem.Location.Y + drawingItem.Size.Height + 10);
                _graphics.DrawString(occurences, drawingItem.SmallFont, foreground, pointOccurences, stringFormatOccurences);
            }

            // Draw type
            if (drawingItem.IsSimpleContent)
            {
                Point currentPoint = scaledElementBox.Location + new Size(2, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(8), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
                currentPoint += new Size(0, 2);
                _graphics.DrawLine(foregroundPen, currentPoint, currentPoint + new Size(drawingItem.ScaleInt(6), 0));
            }

            // Draw reference arrow
            if (drawingItem.IsReference)
            {
                Pen arrowPen = new Pen(foreground, drawingItem.Diagram.Scale * 2.0f);
                //arrowPen.EndCap = LineCap.ArrowAnchor;
                //Point basePoint = new Point(drawingItem.ElementBox.Left + 2, drawingItem.ElementBox.Bottom - 2);
                //g.DrawLine(arrowPen, drawingItem.ScalePoint(basePoint), drawingItem.ScalePoint(basePoint + new Size(4, -4)));
                Point basePoint   = new Point(drawingItem.ElementBox.Left + 1, drawingItem.ElementBox.Bottom - 1);
                Point targetPoint = basePoint + new Size(3, -3);
                basePoint   = drawingItem.ScalePoint(basePoint);
                targetPoint = drawingItem.ScalePoint(targetPoint);
                _graphics.DrawLine(arrowPen, basePoint, targetPoint);

                Point[] pathPoint = new Point[5];
                pathPoint[0] = targetPoint;
                pathPoint[1] = targetPoint; pathPoint[1].X += drawingItem.ScaleInt(2); pathPoint[1].Y += drawingItem.ScaleInt(2);
                pathPoint[2] = targetPoint; pathPoint[2].X += drawingItem.ScaleInt(3); pathPoint[2].Y -= drawingItem.ScaleInt(3);
                pathPoint[3] = targetPoint; pathPoint[3].X -= drawingItem.ScaleInt(2); pathPoint[3].Y -= drawingItem.ScaleInt(2);
                pathPoint[4] = targetPoint;

                GraphicsPath path = new GraphicsPath();
                path.StartFigure();
                path.AddPolygon(pathPoint);
                path.CloseFigure();
                _graphics.FillPath(foreground, path);
            }

            // Draw children expand box
            if (drawingItem.HasChildElements)
            {
                Rectangle scaledChildExpandButtonBox = drawingItem.ScaleRectangle(drawingItem.ChildExpandButtonBox);
                _graphics.FillRectangle(background, scaledChildExpandButtonBox);
                _graphics.DrawRectangle(foregroundPen, scaledChildExpandButtonBox);

                Point middle        = new Point(scaledChildExpandButtonBox.Width / 2, scaledChildExpandButtonBox.Height / 2);
                int   borderPadding = Math.Max(2, drawingItem.ScaleInt(2));

                Point p1 = scaledChildExpandButtonBox.Location + new Size(borderPadding, middle.Y);
                Point p2 = new Point(scaledChildExpandButtonBox.Right - borderPadding, p1.Y);
                _graphics.DrawLine(foregroundPen, p1, p2);
                if (!drawingItem.ShowChildElements)
                {
                    p1 = scaledChildExpandButtonBox.Location + new Size(middle.X, borderPadding);
                    p2 = new Point(p1.X, scaledChildExpandButtonBox.Bottom - borderPadding);
                    _graphics.DrawLine(foregroundPen, p1, p2);
                }
            }
        }
Beispiel #38
0
        void diagram_RequestAnyElement(DiagramItem diagramElement, out XMLSchema.element element, out string nameSpace)
        {
            element = null;
            nameSpace = "";

            //ElementsForm elementsForm = new ElementsForm();
            //elementsForm.Location = MousePosition; //diagramElement.Location //MousePosition;
            //elementsForm.ListBoxElements.Items.Clear();
            //elementsForm.ListBoxElements.Items.Insert(0, "(Cancel)");
            //foreach (XSDObject xsdObject in this.schema.ElementsByName.Values)
            //    if (xsdObject != null && xsdObject.Type == "element")
            //        elementsForm.ListBoxElements.Items.Add(xsdObject);
            //if (elementsForm.ShowDialog(this.diagramControl) == DialogResult.OK && (elementsForm.ListBoxElements.SelectedItem as XSDObject) != null)
            //{
            //    XSDObject xsdObject = elementsForm.ListBoxElements.SelectedItem as XSDObject;
            //    element = xsdObject.Tag as XMLSchema.element;
            //    nameSpace = xsdObject.NameSpace;
            //}
        }
Beispiel #39
0
 private void SelectDiagramElement(DiagramItem element)
 {
     SelectDiagramElement(element, false);
 }
Beispiel #40
0
 public DiagramItem AddCompositors(DiagramItem parentDiagramElement,
                                   XMLSchema.group childElement, string nameSpace)
 {
     return(AddCompositors(parentDiagramElement,
                           childElement, DiagramItemGroupType.Group, nameSpace));
 }
Beispiel #41
0
        public void ExpandChildren(DiagramItem parentDiagramElement)
        {
            if (parentDiagramElement.ItemType == DiagramItemType.element || parentDiagramElement.ItemType == DiagramItemType.type)
            {
                DiagramItem diagramElement = parentDiagramElement;
                if (diagramElement.TabSchema is XMLSchema.element)
                {
                    XMLSchema.element element = diagramElement.TabSchema as XMLSchema.element;

                    if (element.Item is XMLSchema.complexType)
                    {
                        XMLSchema.complexType complexTypeElement = element.Item as XMLSchema.complexType;
                        ExpandComplexType(diagramElement, complexTypeElement);
                    }
                    else if (element.type != null)
                    {
                        XSDObject objectAnnotated = null;
                        if(_elementsByName.TryGetValue(element.type.Namespace + ":type:" + element.type.Name, out objectAnnotated) && objectAnnotated != null)
                        {
                            XMLSchema.annotated annotated = objectAnnotated.Tag as XMLSchema.annotated;
                            ExpandAnnotated(diagramElement, annotated, element.type.Namespace);
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.any)
                {
                    //XMLSchema.any any = diagramElement.TabSchema as XMLSchema.any;

                    if (RequestAnyElement != null)
                    {
                        XMLSchema.element requestElement;
                        string requestNameSpace;
                        RequestAnyElement(diagramElement, out requestElement, out requestNameSpace);
                        if(requestElement != null)
                        {
                            AddElement(diagramElement, requestElement, requestNameSpace);
                            diagramElement.ShowChildElements = true;
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.complexType)
                {
                    XMLSchema.complexType complexTypeElement = diagramElement.TabSchema as XMLSchema.complexType;
                    ExpandComplexType(diagramElement, complexTypeElement);
                }
            }
            else if (parentDiagramElement.ItemType == DiagramItemType.group)
            {
                DiagramItem diagramCompositors = parentDiagramElement;
                XMLSchema.group group = diagramCompositors.TabSchema as XMLSchema.group;

                if (group.Items != null)
                {
                    for (int i = 0; i < group.Items.Length; i++)
                    {
                        switch (group.ItemsElementName[i])
                        {
                            case XMLSchema.ItemsChoiceType2.element:
                                if (group.Items[i] is XMLSchema.element)
                                    AddElement(diagramCompositors, group.Items[i] as XMLSchema.element, diagramCompositors.NameSpace);
                                break;
                            case XMLSchema.ItemsChoiceType2.any:
                                if (group.Items[i] is XMLSchema.any)
                                    AddAny(diagramCompositors, group.Items[i] as XMLSchema.any, diagramCompositors.NameSpace);
                                break;
                            case XMLSchema.ItemsChoiceType2.group:
                                if (group.Items[i] is XMLSchema.group)
                                    AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Group, diagramCompositors.NameSpace);
                                break;
                            case XMLSchema.ItemsChoiceType2.all:
                                if (group.Items[i] is XMLSchema.group)
                                    AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.All, diagramCompositors.NameSpace);
                                break;
                            case XMLSchema.ItemsChoiceType2.choice:
                                if (group.Items[i] is XMLSchema.group)
                                    AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Choice, diagramCompositors.NameSpace);
                                break;
                            case XMLSchema.ItemsChoiceType2.sequence:
                                if (group.Items[i] is XMLSchema.group)
                                    AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Sequence, diagramCompositors.NameSpace);
                                break;
                        }
                    }
                    parentDiagramElement.ShowChildElements = true;
                }
                else
                {
                    AddAny(diagramCompositors, null, diagramCompositors.NameSpace);
                }
            }
        }
Beispiel #42
0
        private void contextMenuStripDiagram_Opened(object sender, EventArgs e)
        {
            this.gotoXSDFileToolStripMenuItem.Enabled = false;
            this.expandToolStripMenuItem.Enabled = false;
            this.removeFromDiagramToolStripMenuItem.Enabled = false;

            Point contextualMenuMousePosition = this.panelDiagram.DiagramControl.PointToClient(MousePosition);
            contextualMenuMousePosition.Offset(this.panelDiagram.VirtualPoint);
            DiagramItem resultElement;
            DiagramHitTestRegion resultRegion;
            this.diagram.HitTest(contextualMenuMousePosition, out resultElement, out resultRegion);
            if (resultRegion != DiagramHitTestRegion.None)
            {
                if (resultRegion == DiagramHitTestRegion.Element) // && resultElement.Parent == null)
                {
                    this.contextualMenuPointedElement = resultElement;
                    this.gotoXSDFileToolStripMenuItem.Enabled = this.schema.ElementsByName.ContainsKey(this.contextualMenuPointedElement.FullName);
                    this.expandToolStripMenuItem.Enabled = true;
                    this.removeFromDiagramToolStripMenuItem.Enabled = true;
                }
            }
        }
Beispiel #43
0
        public void HitTest(Point point, out DiagramItem element, out DiagramHitTestRegion region)
        {
            element = null;
            region = DiagramHitTestRegion.None;

            foreach (DiagramItem childElement in _rootElements)
            {
                DiagramItem resultElement;
                DiagramHitTestRegion resultRegion;
                childElement.HitTest(point, out resultElement, out resultRegion);
                if (resultRegion != DiagramHitTestRegion.None)
                {
                    element = resultElement;
                    region = resultRegion;
                    break;
                }
            }
        }
Beispiel #44
0
        public bool ExpandChildren(DiagramItem parentDiagramElement)
        {
            bool result = false;

            ClearSearch();
            if (parentDiagramElement.ItemType == DiagramItemType.element || parentDiagramElement.ItemType == DiagramItemType.type)
            {
                result = true;
                DiagramItem diagramElement = parentDiagramElement;
                if (diagramElement.TabSchema is XMLSchema.element)
                {
                    XMLSchema.element element = diagramElement.TabSchema as XMLSchema.element;

                    if (element.Item is XMLSchema.complexType)
                    {
                        XMLSchema.complexType complexTypeElement = element.Item as XMLSchema.complexType;
                        ExpandComplexType(diagramElement, complexTypeElement);
                    }
                    else if (element.type != null)
                    {
                        XSDObject objectAnnotated = null;
                        if (_elementsByName.TryGetValue(element.type.Namespace + ":type:" + element.type.Name, out objectAnnotated) && objectAnnotated != null)
                        {
                            XMLSchema.annotated annotated = objectAnnotated.Tag as XMLSchema.annotated;
                            ExpandAnnotated(diagramElement, annotated, element.type.Namespace);
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.any)
                {
                    //XMLSchema.any any = diagramElement.TabSchema as XMLSchema.any;

                    if (RequestAnyElement != null)
                    {
                        XMLSchema.element requestElement;
                        string            requestNameSpace;
                        RequestAnyElement(diagramElement, out requestElement, out requestNameSpace);
                        if (requestElement != null)
                        {
                            AddElement(diagramElement, requestElement, requestNameSpace);
                            diagramElement.ShowChildElements = true;
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.complexType)
                {
                    XMLSchema.complexType complexTypeElement = diagramElement.TabSchema as XMLSchema.complexType;
                    ExpandComplexType(diagramElement, complexTypeElement);
                }
            }
            else if (parentDiagramElement.ItemType == DiagramItemType.group)
            {
                result = true;
                DiagramItem     diagramCompositors = parentDiagramElement;
                XMLSchema.group group = diagramCompositors.TabSchema as XMLSchema.group;

                if (group.Items != null)
                {
                    for (int i = 0; i < group.Items.Length; i++)
                    {
                        switch (group.ItemsElementName[i])
                        {
                        case XMLSchema.ItemsChoiceType2.element:
                            if (group.Items[i] is XMLSchema.element)
                            {
                                AddElement(diagramCompositors, group.Items[i] as XMLSchema.element, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.any:
                            if (group.Items[i] is XMLSchema.any)
                            {
                                AddAny(diagramCompositors, group.Items[i] as XMLSchema.any, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.group:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Group, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.all:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.All, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.choice:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Choice, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.sequence:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Sequence, diagramCompositors.NameSpace);
                            }
                            break;
                        }
                    }
                    parentDiagramElement.ShowChildElements = true;
                }
                else
                {
                    AddAny(diagramCompositors, null, diagramCompositors.NameSpace);
                }
            }
            return(result);
        }
Beispiel #45
0
 public void Remove(DiagramItem element)
 {
     if (element.Parent == null)
         _rootElements.Remove(element);
     else
     {
         element.Parent.ChildElements.Remove(element);
         if (element.Parent.ChildElements.Count == 0)
             element.Parent.ShowChildElements = false;
     }
 }
Beispiel #46
0
        public DiagramItem AddComplexType(DiagramItem parentDiagramElement, 
            XMLSchema.complexType childElement, bool isReference,
            string nameSpace)
        {
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();
                childDiagramElement.Diagram = this;
                childDiagramElement.TabSchema = childElement;
                childDiagramElement.Name = childElement.name != null ? childElement.name : "";
                childDiagramElement.NameSpace = nameSpace;
                childDiagramElement.ItemType = DiagramItemType.type;
                childDiagramElement.MinOccurrence = 1;
                childDiagramElement.MaxOccurrence = 1;
                childDiagramElement.IsReference = isReference;
                childDiagramElement.IsSimpleContent = false;
                childDiagramElement.HasChildElements = false;

                if (childElement.Items != null)
                {
                    for (int i = 0; i < childElement.Items.Length; i++)
                    {
                        if (childElement.Items[i] is XMLSchema.group ||
                            childElement.Items[i] is XMLSchema.complexType ||
                            childElement.Items[i] is XMLSchema.complexContent)
                        {
                            childDiagramElement.HasChildElements = true;
                            break;
                        }
                    }
                }

                if (parentDiagramElement == null)
                    _rootElements.Add(childDiagramElement);
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                return childDiagramElement;
            }
            return null;
        }
Beispiel #47
0
 public override void Render(DiagramItem item)
 {
     Render(item, null);
 }
Beispiel #48
0
 public void HitTest(Point point, out DiagramItem element, out DiagramHitTestRegion region)
 {
     element = null;
     if (ScaleRectangle(_boundingBox).Contains(point))
     {
         element = this;
         if (ScaleRectangle(new Rectangle(_location, _size)).Contains(point))
         {
             if (_hasChildElements && ScaleRectangle(_childExpandButtonBox).Contains(point))
                 region = DiagramHitTestRegion.ChildExpandButton;
             else
                 region = DiagramHitTestRegion.Element;
         }
         else
         {
             region = DiagramHitTestRegion.BoundingBox;
             if (_showChildElements)
             {
                 foreach (DiagramItem childElement in _childElements)
                 {
                     DiagramItem resultElement;
                     DiagramHitTestRegion resultRegion;
                     childElement.HitTest(point, out resultElement, out resultRegion);
                     if (resultRegion != DiagramHitTestRegion.None)
                     {
                         element = resultElement;
                         region = resultRegion;
                         break;
                     }
                 }
             }
         }
     }
     else
     {
         region = DiagramHitTestRegion.None;
     }
 }
Beispiel #49
0
 public DiagramItem AddCompositors(DiagramItem parentDiagramElement, 
     XMLSchema.group childElement, string nameSpace)
 {
     return AddCompositors(parentDiagramElement,
         childElement, DiagramItemGroupType.Group, nameSpace);
 }
Beispiel #50
0
 public override void Render(DiagramItem item)
 {
     Render(item, null);
 }
Beispiel #51
0
        public DiagramItem AddCompositors(DiagramItem parentDiagramElement, 
            XMLSchema.group childGroup, DiagramItemGroupType type,
            string nameSpace)
        {
            if (childGroup != null)
            {
                DiagramItem childDiagramGroup = new DiagramItem();
                childDiagramGroup.ItemType = DiagramItemType.group;
                if (childGroup.@ref != null)
                {
                    childDiagramGroup.IsReference = true;
                    childDiagramGroup.Name = [email protected] != null ? [email protected] : "";
                    childDiagramGroup.NameSpace = [email protected] != null ? [email protected] : "";
                    XSDObject grpObject = null;
                    if (_elementsByName.TryGetValue(childDiagramGroup.FullName, out grpObject) && grpObject != null)
                    {
                        XMLSchema.group group = grpObject.Tag as XMLSchema.group;
                        if (group != null)
                            childGroup = group;
                    }
                }
                else if (type == DiagramItemGroupType.Group)
                {
                    childDiagramGroup.Name = childGroup.name != null ? childGroup.name : "";
                    childDiagramGroup.NameSpace = nameSpace;
                }
                else
                {
                    childDiagramGroup.NameSpace = nameSpace;
                }

                childDiagramGroup.Diagram = this;
                childDiagramGroup.TabSchema = childGroup;
                int occurrence;
                if (int.TryParse(childGroup.minOccurs, out occurrence))
                    childDiagramGroup.MinOccurrence = occurrence;
                else
                    childDiagramGroup.MinOccurrence = -1;
                //try { childDiagramGroup.MinOccurrence = int.Parse(childGroup.minOccurs); }
                //catch { childDiagramGroup.MinOccurrence = -1; }
                if (int.TryParse(childGroup.maxOccurs, out occurrence))
                    childDiagramGroup.MaxOccurrence = occurrence;
                else
                    childDiagramGroup.MaxOccurrence = -1;
                //try { childDiagramGroup.MaxOccurrence = int.Parse(childGroup.maxOccurs); }
                //catch { childDiagramGroup.MaxOccurrence = -1; }
                childDiagramGroup.HasChildElements = true;
                childDiagramGroup.GroupType = type;

                if (parentDiagramElement == null)
                    _rootElements.Add(childDiagramGroup);
                else
                {
                    childDiagramGroup.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramGroup);
                }

                return childDiagramGroup;
            }
            return null;
        }
Beispiel #52
0
        public DiagramItem AddElement(DiagramItem parentDiagramElement, XMLSchema.element childElement, string nameSpace)
        {
            if (childElement != null)
            {
                DiagramItem childDiagramElement = new DiagramItem();

                XMLSchema.element referenceElement = null;
                if (childElement.@ref != null)
                {
                    if ([email protected])
                    {
                        childDiagramElement.IsReference = true;

                        XSDObject objectReferred = null;
                        if(_elementsByName.TryGetValue([email protected] + ":element:" + [email protected], out objectReferred) && objectReferred != null)
                        {
                            XMLSchema.element elementReferred = objectReferred.Tag as XMLSchema.element;
                            if (elementReferred != null)
                            {
                                referenceElement = childElement;
                                childElement = elementReferred;
                            }
                        }
                        else
                            childElement.name = [email protected];
                    }
                }

                childDiagramElement.Diagram = this;
                childDiagramElement.TabSchema = childElement;
                childDiagramElement.Name = childElement.name != null ? childElement.name : "";
                childDiagramElement.NameSpace = nameSpace;
                childDiagramElement.ItemType = DiagramItemType.element;
                int occurrence;
                if (int.TryParse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs, out occurrence))
                    childDiagramElement.MinOccurrence = occurrence;
                else
                    childDiagramElement.MinOccurrence = -1;
                //try { childDiagramElement.MinOccurrence = int.Parse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs); }
                //catch { childDiagramElement.MinOccurrence = -1; }
                if (int.TryParse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs, out occurrence))
                    childDiagramElement.MaxOccurrence = occurrence;
                else
                    childDiagramElement.MaxOccurrence = -1;
                //try { childDiagramElement.MaxOccurrence = int.Parse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs); }
                //catch { childDiagramElement.MaxOccurrence = -1; }

                bool hasChildren;
                bool isSimpleType;
                GetChildrenInfo(childElement, out hasChildren, out isSimpleType);
                childDiagramElement.HasChildElements = hasChildren;
                childDiagramElement.IsSimpleContent = isSimpleType;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramElement);
                }
                else
                {
                    childDiagramElement.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramElement);
                }

                if (childElement.@abstract)
                {
                    string abstractElementFullName = childDiagramElement.FullName;
                    foreach(XSDObject xsdObject in _elementsByName.Values)
                    {
                        if (xsdObject != null && xsdObject.Tag is XMLSchema.element)
                        {
                            XMLSchema.element element = xsdObject.Tag as XMLSchema.element;
                            if (element.substitutionGroup != null)
                            {
                                string elementFullName = element.substitutionGroup.Namespace + ":element:" + element.substitutionGroup.Name;
                                if (elementFullName == abstractElementFullName)
                                {
                                    DiagramItem diagramBase = AddElement(parentDiagramElement, element, xsdObject.NameSpace);
                                    if (diagramBase != null)
                                        diagramBase.InheritFrom = childDiagramElement;
                                }
                            }
                        }
                    }
                }

                return childDiagramElement;
            }

            return null;
        }
Beispiel #53
0
        public override void Render(DiagramItem drawingItem)
        {
            string type = "";

            if (drawingItem.TabSchema is XMLSchema.element)
            {
                type = "element";
            }
            else if (drawingItem.TabSchema is XMLSchema.simpleType)
            {
                type = "simpleType";
            }
            else if (drawingItem.TabSchema is XMLSchema.complexType)
            {
                type = "complexType";
            }

            if (type.Length > 0)
            {
                string      path          = '/' + drawingItem.Name;
                DiagramItem parentElement = drawingItem.Parent;
                while (parentElement != null)
                {
                    //if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                    if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
                    {
                        path = '/' + parentElement.Name + path;
                    }
                    parentElement = parentElement.Parent;
                }

                string comment = "";
                XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
                if (annotated != null && annotated.annotation != null)
                {
                    foreach (object o in annotated.annotation.Items)
                    {
                        if (o is XMLSchema.documentation)
                        {
                            XMLSchema.documentation documentation = o as XMLSchema.documentation;
                            if (documentation.Any != null && documentation.Any.Length > 0)
                            {
                                string text = documentation.Any[0].Value;
                                text    = text.Replace("\n", " ");
                                text    = text.Replace("\t", " ");
                                text    = text.Replace("\r", "");
                                text    = Regex.Replace(text, " +", " ");
                                text    = text.Trim();
                                comment = text;
                            }
                            else if (documentation.source != null)
                            {
                                comment = documentation.source;
                            }
                            break;
                        }
                    }
                }

                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                {
                    if (i > 0)
                    {
                        _writer.Write(_fieldSeparator);
                    }
                    string field = _finalTextOutputFields[i];
                    switch (field)
                    {
                    case "PATH": _writer.Write(path); break;

                    case "NAME": _writer.Write(drawingItem.Name); break;

                    case "TYPE": _writer.Write(type); break;

                    case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;

                    case "COMMENT": _writer.Write(comment); break;
                    }
                }
                _writer.WriteLine();


                //// Draw the inheritor line
                //if (drawingItem.InheritFrom != null)
                //{
                //}

                //switch (drawingItem.ItemType)
                //{
                //    case DiagramItemType.element:
                //        break;

                //    case DiagramItemType.type:
                //        break;

                //    case DiagramItemType.group:
                //        {
                //            // Draw the main shape following the min/max occurences

                //            // Draw the group type
                //            switch (drawingItem.GroupType)
                //            {
                //                case DiagramItemGroupType.Sequence: break;
                //                case DiagramItemGroupType.Choice: break;
                //                case DiagramItemGroupType.All: break;
                //            }
                //            break;
                //        }
                //}

                //// Draw text
                //if (drawingItem.Name.Length > 0)
                //{
                //    //drawingItem.Name;
                //}

                //// Draw occurences small text
                //if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}

                //// Draw type
                //if (drawingItem.IsSimpleContent) {}

                //// Draw reference arrow
                //if (drawingItem.IsReference) {}
            }

            // Draw children expand box
            if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
            {
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.Render(element);
                    //_writer.WriteLine();
                }
            }
        }