Ejemplo n.º 1
0
        public override Task Rebuild()
        {
            var allPaths = SvgParser.GetPaths(this.SvgPath);

            var selectedItems = new HashSet <SvgParser.SvgNodeInfo>(allPaths);

            try
            {
                this.Children.Modify(children =>
                {
                    children.Clear();

                    var svgContent = new List <IObject3D>();

                    int i = 0;
                    foreach (var item in selectedItems)
                    {
                        IVertexSource vertexSource = null;

                        if (item is SvgParser.SvgPolygonInfo polygon)
                        {
                            var storage = new VertexStorage();

                            storage.MoveTo(polygon.Points[0]);

                            for (var j = 1; j < polygon.Points.Count; j++)
                            {
                                storage.LineTo(polygon.Points[j]);
                            }

                            // close
                            storage.LineTo(polygon.Points[0]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPolyLineInfo polyline)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(polyline.Points[0]);

                            for (var j = 1; j < polyline.Points.Count; j++)
                            {
                                storage.LineTo(polyline.Points[j]);
                            }

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgLineInfo line)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(line.Points[0]);
                            storage.LineTo(line.Points[1]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPathInfo path)
                        {
                            vertexSource = new VertexStorage(path.DString);
                        }
                        else
                        {
                            // Skip unknown type
                            continue;
                        }

                        var flattened = new FlattenCurves(vertexSource)
                        {
                            ResolutionScale = 6
                        };

                        var itemZ = 3 + item.Z + (0.1 * i++);

                        if (item.Fill is SvgColourServer fill)
                        {
                            var fillColor = fill.Colour.GetAggColor();

                            var object3D = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(flattened, itemZ),
                                Color = fillColor,
                                // Flip
                                //Matrix = Matrix4X4.Identity * Matrix4X4.CreateScale(1, -1, 1)
                            };

                            svgContent.Add(object3D);
                        }

                        if (item.Stroke is SvgColourServer stroke)
                        {
                            var aggStroke = new Stroke(flattened, item.StrokeWidth)
                            {
                                LineCap  = LineCap.Round,
                                LineJoin = LineJoin.Round
                            };

                            //							aggStroke.l

                            var strokeObject = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(aggStroke, itemZ),
                                Color = stroke.Colour.GetAggColor()
                            };

                            svgContent.Add(strokeObject);
                        }
                    }

                    var mirror = new MirrorObject3D()
                    {
                        MirrorOn = MirrorObject3D.MirrorAxis.Y_Axis
                    };

                    mirror.Children.Modify(list =>
                    {
                        list.AddRange(svgContent);
                    });

                    mirror.Rebuild();

                    mirror.Matrix = Matrix4X4.CreateScale(0.15);

                    children.Add(mirror);
                });
            }
            catch { }

            return(base.Rebuild());
        }
Ejemplo n.º 2
0
        public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme)
        {
            this.injectedItem = item as SvgObject3D;
            if (this.injectedItem == null)
            {
                return(null);
            }

            var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.Fit,
                HAnchor = HAnchor.Absolute,
                Width   = 210,
                Padding = new BorderDouble(12),
            };

            column.Closed += (s, e) =>
            {
                //unregisterEvents?.Invoke(this, null);
            };

            var rightPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch
            };

            var label = new TextWidget("All Paths", textColor: AppContext.Theme.TextColor)
            {
                HAnchor = HAnchor.Left,
                Margin  = new BorderDouble(0, 0, 0, 15)
            };

            column.AddChild(label);

            var row = new FlowLayoutWidget()
            {
            };

            column.AddChild(row);

            var editButton = new TextButton("Edit".Localize(), theme)
            {
                Enabled = false,
            };

            editButton.Click += async(s, e) =>
            {
                ApplicationController.Instance.OpenIntoNewTab(new[] { new InMemoryLibraryItem(new VertexStorageObject3D(lastDPath)) });
            };

            int pathCount = 1;
            var droplist  = new PopupMenu(theme)
            {
                BackgroundColor = theme.InactiveTabColor
            };

            row.AddChild(droplist);

            row.AddChild(editButton);

            var allPaths = SvgParser.GetPaths(this.injectedItem.SvgPath);

            selectedItems = new HashSet <SvgParser.SvgNodeInfo>(allPaths);

            foreach (var pathItem in allPaths)
            {
                bool itemChecked = true;

                PopupMenu.MenuItem menuItem = null;

                menuItem = droplist.CreateBoolMenuItem(
                    $"Path {pathCount++}",
                    () => itemChecked,
                    (isChecked) =>
                {
                    lastDPath          = (pathItem as SvgParser.SvgPathInfo)?.DString;
                    editButton.Enabled = true;

                    if (isChecked)
                    {
                        selectedItems.Add(pathItem);
                    }
                    else
                    {
                        selectedItems.Remove(pathItem);
                    }

                    this.Rebuild();
                });
            }

            this.Rebuild();

            return(column);
        }