Example #1
0
        private void AddRelationship()
        {
            if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect())
            {
                return;
            }

            var relationshipParameters = new RelationshipParameters
            {
                Nodes         = CircleDiagramModel.Nodes,
                Relationships = CircleDiagramModel.Relationships
            };

            if (relationshipParameters.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var newRelationship = new CircleDiagramRelationship(
                relationshipParameters.BeginNode,
                relationshipParameters.EndNode);

            if (CircleDiagramModel.AddRelationship(newRelationship))
            {
                lvRelationships.AddCircleDiagramRelationship(newRelationship);
            }

            RedrawDiagramOnControl();
        }
 private static XmlRelationship GetXmlRelationship(CircleDiagramRelationship relationship)
 {
     if (relationship == null)
     {
         return(null);
     }
     return(new XmlRelationship(relationship.Name, relationship.BeginNode.Name, relationship.EndNode.Name));
 }
        public void AddCircleDiagramRelationship(CircleDiagramRelationship relationship)
        {
            if (relationship == null)
            {
                return;
            }
            var relationshipText = string.Format("{0} -> {1}",
                                                 relationship.BeginNode != null
                    ? string.Format("{0} - {1}",
                                    relationship.BeginNode.StartCircleNumber,
                                    relationship.BeginNode.Text.Trim().Replace("\r\n", " "))
                    : string.Empty,
                                                 relationship.EndNode != null
                    ? string.Format("{0} - {1}",
                                    relationship.EndNode.StartCircleNumber,
                                    relationship.EndNode.Text.Trim().Replace("\r\n", " "))
                    : string.Empty);

            var lvItem = new ListViewItem {
                Text = relationshipText, Name = relationship.Name
            };

            Items.Add(lvItem);
        }
Example #4
0
        private void DrawRelationship(CircleDiagramRelationship relationship, Graphics graphics)
        {
            if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect())
            {
                return;
            }
            if (relationship == null)
            {
                return;
            }
            if (graphics == null)
            {
                return;
            }

            //Связи с такой же стартовой вершиной
            var relationshipsWithSameBeginNode =
                GetOrderedOutRelationshipsForNode(relationship.BeginNode);

            if (relationshipsWithSameBeginNode == null)
            {
                return;
            }

            var beginNodeIndex = relationshipsWithSameBeginNode.IndexOf(relationship);

            if (beginNodeIndex < 0)
            {
                return;
            }

            //Связи с такой же конечной вершиной
            var relationshipsWithSameEndNode =
                GetOrderedInRelationshipsForNode(relationship.EndNode);

            if (relationshipsWithSameEndNode == null)
            {
                return;
            }

            var endNodeIndex = relationshipsWithSameEndNode.IndexOf(relationship);

            if (endNodeIndex < 0)
            {
                return;
            }

            var angleForBeginVertex = relationship.BeginNode.StartAngle
                                      + (relationship.BeginNode.SweepAngle / (relationshipsWithSameBeginNode.Count + 1))
                                      * (beginNodeIndex + 1);

            var angleForEndVertex = relationship.EndNode.StartCircleNumber != 0
                ? relationship.EndNode.StartAngle
                                    + (relationship.EndNode.SweepAngle / (relationshipsWithSameEndNode.Count + 1))
                                    * (endNodeIndex + 1)
                : angleForBeginVertex;

            float beginNodeRadius1, beginNodeRadius2, endNodeRadius1, endNodeRadius2;

            GetRadiusesOfNode(relationship.BeginNode, out beginNodeRadius1, out beginNodeRadius2);
            GetRadiusesOfNode(relationship.EndNode, out endNodeRadius1, out endNodeRadius2);

            var ringThickness = GetRingThickness();

            var beginFunctionalRadius =
                beginNodeRadius1 <= beginNodeRadius2
                    ? beginNodeRadius1
                    : beginNodeRadius2;

            var endFunctionalRadius =
                endNodeRadius1 >= endNodeRadius2
                    ? endNodeRadius1
                    : endNodeRadius2;

            float beginAngle, endAngle;

            if (angleForBeginVertex <= angleForEndVertex)
            {
                beginAngle = angleForBeginVertex;
                endAngle   = angleForEndVertex;
            }
            else
            {
                beginAngle = angleForEndVertex;
                endAngle   = angleForBeginVertex;
            }

            var actualPen = (Pen)CircleDiagramModel.RelationshipPen.Clone();

            actualPen.Width = actualPen.Width * PercentageScale;

            var deltaAngle = (float)(Math.Abs(beginAngle - endAngle) * 0.15);

            var vertexes = new List <PointF>();

            vertexes.Add(GraphicsUtils.GetPointOnCircle(beginFunctionalRadius,
                                                        new PointF(0, 0), angleForBeginVertex));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.75f * ringThickness,
                                                        new PointF(0, 0), angleForBeginVertex));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.5f * ringThickness,
                                                        new PointF(0, 0), angleForBeginVertex));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.5f * ringThickness,
                                                        new PointF(0, 0), angleForBeginVertex + deltaAngle));

            for (var curAngle = angleForBeginVertex + deltaAngle + 1;
                 curAngle < angleForEndVertex - deltaAngle; curAngle++)
            {
                vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.5f * ringThickness,
                                                            new PointF(0, 0), curAngle));
            }

            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.5f * ringThickness,
                                                        new PointF(0, 0), angleForEndVertex - deltaAngle));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.5f * ringThickness,
                                                        new PointF(0, 0), angleForEndVertex));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius + 0.25f * ringThickness,
                                                        new PointF(0, 0), angleForEndVertex));
            vertexes.Add(GraphicsUtils.GetPointOnCircle(endFunctionalRadius,
                                                        new PointF(0, 0), angleForEndVertex));

            if (vertexes.Count < 8)
            {
                return;
            }

            graphics.DrawLine(actualPen, vertexes[0], vertexes[1]);
            graphics.DrawBezier(actualPen, vertexes[1], vertexes[2], vertexes[2], vertexes[3]);
            graphics.DrawCurve(actualPen, vertexes.GetRange(3, vertexes.Count - 6).ToArray());
            graphics.DrawBezier(actualPen, vertexes[vertexes.Count - 4],
                                vertexes[vertexes.Count - 3], vertexes[vertexes.Count - 3],
                                vertexes[vertexes.Count - 2]);
            graphics.DrawLine(actualPen, vertexes[vertexes.Count - 2], vertexes[vertexes.Count - 1]);

            graphics.DrawArrow(vertexes[vertexes.Count - 1], 50,
                               360 - angleForEndVertex, 0.30f * ringThickness, new SolidBrush(actualPen.Color));
        }