예제 #1
0
        private static graphmlGraphEdge BuildArrowGraphEdge(DiagramEdgeModel diagramEdge)
        {
            if (diagramEdge == null)
            {
                throw new ArgumentNullException(nameof(diagramEdge));
            }
            var outputEdge = new graphmlGraphEdge
            {
                id     = FormatArrowGraphEdgeId(diagramEdge.Id),
                source = FormatArrowGraphNodeId(diagramEdge.SourceId),
                target = FormatArrowGraphNodeId(diagramEdge.TargetId)
            };

            string dashStyle;

            switch (diagramEdge.DashStyle)
            {
            case EdgeDashStyle.Normal:
                dashStyle = @"line";
                break;

            case EdgeDashStyle.Dashed:
                dashStyle = @"dashed";
                break;

            default:
                throw new InvalidOperationException($@"Unknown EdgeDashStyle value ""{diagramEdge.DashStyle}""");
            }

            outputEdge.data = new data
            {
                key          = "d10",
                PolyLineEdge = new PolyLineEdge
                {
                    Path = new PolyLineEdgePath
                    {
                        sx = "0.0",
                        sy = "0.0",
                        tx = "0.0",
                        ty = "0.0"
                    },
                    LineStyle = new PolyLineEdgeLineStyle
                    {
                        color = diagramEdge.ForegroundColorHexCode,
                        type  = dashStyle,
                        width = diagramEdge.StrokeThickness.ToString(CultureInfo.InvariantCulture)
                    },
                    Arrows = new PolyLineEdgeArrows
                    {
                        source = "none",
                        target = "standard"
                    },
                    EdgeLabel = new PolyLineEdgeEdgeLabel
                    {
                        alignment          = "center",
                        backgroundColor    = "#FFFFFF",
                        configuration      = "AutoFlippingLabel",
                        distance           = "2.0",
                        fontFamily         = "Dialog",
                        fontSize           = "12",
                        fontStyle          = "plain",
                        hasLineColor       = "false",
                        height             = "18.701171875",
                        modelName          = "centered",
                        modelPosition      = "center",
                        preferredPlacement = "on_edge",
                        ratio     = "0.5",
                        textColor = "#000000",
                        visible   = diagramEdge.ShowLabel ? "true" : "false",
                        width     = "10.673828125",
                        x         = "48.66937255859375",
                        y         = "-10.915985107421875",
                        PreferredPlacementDescriptor = new PolyLineEdgeEdgeLabelPreferredPlacementDescriptor
                        {
                            angle = "0.0",
                            angleOffsetOnRightSide   = "0",
                            angleReference           = "absolute",
                            angleRotationOnRightSide = "co",
                            distance      = "-1.0",
                            placement     = "anywhere",
                            side          = "on_edge",
                            sideReference = "relative_to_edge_flow"
                        },
                        hasText = "true",
                        Text    = diagramEdge.Label
                    },
                    BendStyle = new PolyLineEdgeBendStyle
                    {
                        smoothed = "false"
                    }
                }
            };
            return(outputEdge);
        }
예제 #2
0
        private static DiagramEdgeModel BuildDiagramEdge(EdgeControl edgeControl)
        {
            if (edgeControl == null)
            {
                throw new ArgumentNullException(nameof(edgeControl));
            }
            var outputEdge = new DiagramEdgeModel();

            if (edgeControl.Edge is ArrowGraphEdge edge)
            {
                outputEdge.Id       = Convert.ToInt32(edge.ID);
                outputEdge.Name     = edge.Name;
                outputEdge.SourceId = Convert.ToInt32(edge.Source.ID);
                outputEdge.TargetId = Convert.ToInt32(edge.Target.ID);

                Common.ProjectPlan.EdgeDashStyle dashStyle;
                switch (edge.DashStyle)
                {
                case GraphX.Controls.EdgeDashStyle.Solid:
                    dashStyle = Common.ProjectPlan.EdgeDashStyle.Normal;
                    break;

                case GraphX.Controls.EdgeDashStyle.Dash:
                    dashStyle = Common.ProjectPlan.EdgeDashStyle.Dashed;
                    break;

                default:
                    throw new InvalidOperationException($@"Unknown EdgeDashStyle value ""{edge.DashStyle}""");
                }

                outputEdge.DashStyle = dashStyle;
                Color foregroundColor = ((SolidColorBrush)edgeControl.Foreground).Color;
                outputEdge.ForegroundColorHexCode =
                    ViewModel.ProjectPlan.Converter.HexConverter(foregroundColor.R, foregroundColor.G, foregroundColor.B);
                outputEdge.StrokeThickness = edge.StrokeThickness;
                var labelText = new StringBuilder();
                if (edge.IsDummy)
                {
                    if (!edge.CanBeRemoved)
                    {
                        labelText.AppendFormat(CultureInfo.InvariantCulture, "{0}", edge.ID);
                        if (!edge.IsCritical)
                        {
                            labelText.AppendLine();
                            labelText.AppendFormat(CultureInfo.InvariantCulture, "{0}|{1}", edge.FreeSlack, edge.TotalSlack);
                        }
                        outputEdge.ShowLabel = true;
                    }
                    else
                    {
                        if (!edge.IsCritical)
                        {
                            labelText.AppendFormat(CultureInfo.InvariantCulture, "{0}|{1}", edge.FreeSlack, edge.TotalSlack);
                            outputEdge.ShowLabel = true;
                        }
                    }
                }
                else
                {
                    labelText.AppendFormat(CultureInfo.InvariantCulture, "{0} ({1})", edge.ID, edge.Duration);
                    if (!edge.IsCritical)
                    {
                        labelText.AppendLine();
                        labelText.AppendFormat(CultureInfo.InvariantCulture, "{0}|{1}", edge.FreeSlack, edge.TotalSlack);
                    }
                    outputEdge.ShowLabel = true;
                }
                outputEdge.Label = labelText.ToString();
            }
            return(outputEdge);
        }