public void addNodeShape(node n, Boolean redraw = true)
        {
            if (!(n.DisplayShape is DisplayShape))
            {
                GS1xCompatibility.UpdateNodeShape(n);
            }
            var shape = (Shape)n.DisplayShape.Shape;

            nodeShapes.Add(shape);
            shape.RenderTransformOrigin = new Point(0.5, 0.5);
            if (double.IsNaN(n.X))
            {
                n.X = 0.0;
            }
            if (double.IsNaN(n.Y))
            {
                n.Y = 0.0;
            }
            shape.RenderTransform = new MatrixTransform(
                shape.RenderTransform.Value.M11,
                shape.RenderTransform.Value.M12,
                shape.RenderTransform.Value.M21,
                shape.RenderTransform.Value.M22,
                n.X - (shape.Width / 2) + Origin.X,
                n.Y - (shape.Height / 2) + Origin.Y);
            nodeIcons.Add(shape, n);
            if (redraw)
            {
                RedrawResizeAndReposition(true);
            }
        }
Beispiel #2
0
        private Canvas BuildGraphGUICanvas(designGraph graph, CanvasProperty cp)
        {
            var dtc = new DisplayTextConverter();
            var ptc = new PositionTextConverter();

            var saveCanvas = new Canvas
            {
                Background          = cp.BackgroundColor,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                Height          = cp.CanvasHeight / cp.ScaleFactor,
                Width           = cp.CanvasWidth.Left / cp.ScaleFactor,
                RenderTransform = new MatrixTransform(1, 0, 0,
                                                      -1, 0, cp.CanvasHeight / cp.ScaleFactor)
            };

            if (UserCancelled)
            {
                return(null);
            }
            progress += 2;
            var canvString = XamlWriter.Save(saveCanvas);

            canvString = canvString.EndsWith("</Canvas>")
                ? canvString.Replace("</Canvas>", "")
                : canvString.Replace("/>", ">");
            progress += 2;
            var progressStart = progress;
            var progStep      = (double)(progressEnd - progressStart) / (graph.nodes.Count
                                                                         + graph.arcs.Count + graph.hyperarcs.Count);
            var step = 1;

            foreach (node n in graph.nodes)
            {
                if (n.DisplayShape == null)
                {
                    GS1xCompatibility.UpdateNodeShape(n);
                }
                canvString += ((DisplayShape)n.DisplayShape).String;
                var nodeText = (FormattedText)dtc.Convert(new object[]
                {
                    cp.ShowNodeName,
                    cp.ShowNodeLabel, cp.NodeFontSize
                }, null, n, null);
                if (nodeText != null)
                {
                    var textPos = (Point)ptc.Convert(new object[]
                    {
                        cp.NodeTextDistance,
                        cp.NodeTextPosition, nodeText
                    }, null, null, null);
                    var tb = new TextBlock
                    {
                        FontSize            = cp.NodeFontSize,
                        Text                = nodeText.Text,
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        RenderTransform     = new MatrixTransform(1, 0, 0, -1,
                                                                  n.DisplayShape.ScreenX + textPos.X,
                                                                  n.DisplayShape.ScreenY - textPos.Y)
                    };
                    canvString += RemoveXAMLns(XamlWriter.Save(tb));
                }
                if (UserCancelled)
                {
                    return(null);
                }
                progress = progressStart + (int)(progStep * step++);
            }
            foreach (arc a in graph.arcs)
            {
                if (a.DisplayShape == null)
                {
                    GS1xCompatibility.UpdateArcShape(a);
                }
                canvString += ((DisplayShape)a.DisplayShape).String;
                var arcText = (FormattedText)dtc.Convert(new object[]
                {
                    cp.ShowArcName,
                    cp.ShowArcLabel, cp.ArcFontSize
                }, null, a, null);
                if (arcText != null)
                {
                    AbstractController ac;
                    if ((a.DisplayShape != null) && (a.DisplayShape.Shape != null) &&
                        (((ArcShape)a.DisplayShape.Shape).Controller != null))
                    {
                        ac = ((ArcShape)a.DisplayShape.Shape).Controller;
                    }
                    else
                    {
                        ac = new StraightArcController((Shape)a.DisplayShape.Shape);
                    }
                    var textPos = (Point)ptc.Convert(new object[] { cp.ArcTextDistance, cp.ArcTextPosition, arcText },
                                                     null, ac, null);
                    var tb = new TextBlock
                    {
                        FontSize        = cp.ArcFontSize,
                        Text            = arcText.Text,
                        RenderTransform = new MatrixTransform(1, 0, 0, -1, textPos.X, textPos.Y)
                    };
                    canvString += RemoveXAMLns(XamlWriter.Save(tb));
                }
            }
            foreach (hyperarc h in graph.hyperarcs)
            {
                canvString += ((DisplayShape)h.DisplayShape).String;
                var hatext = (FormattedText)dtc.Convert(new object[]
                {
                    cp.ShowHyperArcName,
                    cp.ShowHyperArcLabel, cp.HyperArcFontSize
                }, null, h, null);
                if (hatext != null)
                {
                    AbstractController ac;
                    if ((h.DisplayShape != null) && (h.DisplayShape.Shape != null) &&
                        (((HyperArcShape)h.DisplayShape.Shape).Controller != null))
                    {
                        ac = ((HyperArcShape)h.DisplayShape.Shape).Controller;
                    }
                    else
                    {
                        ac = new CircleHyperArcController((Shape)h.DisplayShape.Shape,
                                                          new[] { 25.0 - 1.0 });
                    }
                    var textPos = (Point)ptc.Convert(new object[] { cp.HyperArcTextDistance,
                                                                    cp.HyperArcTextPosition, hatext },
                                                     null, ac, null);
                    var tb = new TextBlock
                    {
                        FontSize        = cp.HyperArcFontSize,
                        Text            = hatext.Text,
                        RenderTransform = new MatrixTransform(1, 0, 0, -1, textPos.X, textPos.Y)
                    };
                    canvString += RemoveXAMLns(XamlWriter.Save(tb));
                }
                if (UserCancelled)
                {
                    return(null);
                }
                progress = progressStart + (int)(progStep * step++);
            }
            canvString += "</Canvas>";
            return((Canvas)MyXamlHelpers.Parse(canvString));
        }