예제 #1
0
        public static VertexStorage PolygonToPathStorage(this Polygons polygons)
        {
            VertexStorage output = new VertexStorage();

            foreach (Polygon polygon in polygons)
            {
                bool first = true;
                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }
            output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

            return(output);
        }
예제 #2
0
        public static VertexStorage CreatePathStorage(List <List <IntPoint> > polygons)
        {
            VertexStorage output = new VertexStorage();

            foreach (List <IntPoint> polygon in polygons)
            {
                bool first = true;
                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }

            return(output);
        }
예제 #3
0
        public static VertexStorage CreateVertexStorage(this Polygons polygons, double scaling = 1000)
        {
            var output = new VertexStorage();

            foreach (Polygon polygon in polygons)
            {
                bool first = true;

                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }

            return(output);
        }
예제 #4
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
            {
                double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                Color extrusionColor = Color.Black;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    extrusionColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    extrusionColor = Color.Gray;
                }
                else
                {
                    extrusionColor = renderInfo.GetMaterialColor(extruderIndex);
                }

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new Color(extrusionColor, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    Vector3Float startF = this.GetStart(renderInfo);
                    Vector3Float endF   = this.GetEnd(renderInfo);
                    Vector2      start  = new Vector2(startF.x, startF.y);
                    renderInfo.Transform.transform(ref start);

                    Vector2 end = new Vector2(endF.x, endF.y);
                    renderInfo.Transform.transform(ref end);

                    graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths / 2, extrusionColor);
                }
                else
                {
                    VertexStorage pathStorage = new VertexStorage();
                    VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths / 2);

                    stroke.line_cap(LineCap.Round);
                    stroke.line_join(LineJoin.Round);

                    Vector3Float start = this.GetStart(renderInfo);
                    Vector3Float end   = this.GetEnd(renderInfo);

                    pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo);
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo);

                    graphics2D.Render(stroke, 0, extrusionColor);
                }
            }
        }
예제 #5
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double movementLineWidth = 0.2 * renderInfo.LayerScale;
                Color  movementColor     = (highlightFeature) ? RenderFeatureBase.HighlightColor : new Color(10, 190, 15);

                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    // render using opengl
                    var startPoint = new Vector2(start.X, start.Y);
                    renderInfo.Transform.transform(ref startPoint);

                    var endPoint = new Vector2(end.X, end.Y);
                    renderInfo.Transform.transform(ref endPoint);

                    if (retractionTravel)
                    {
                        movementColor = GCodeRenderer.RetractionColor;
                    }

                    if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                    {
                        movementColor = movementColor.WithAlpha(120);
                    }

                    graphics2DGl.DrawAALineRounded(startPoint, endPoint, movementLineWidth, movementColor);
                }
                else
                {
                    // render using agg
                    var pathStorage            = new VertexStorage();
                    var transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    var stroke = new Stroke(transformedPathStorage, movementLineWidth)
                    {
                        LineCap  = LineCap.Round,
                        LineJoin = LineJoin.Round
                    };

                    pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo);
                    if (end.X != start.X || end.Y != start.Y)
                    {
                        pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo);
                    }
                    else
                    {
                        pathStorage.Add(end.X + .01, end.Y, ShapePath.FlagsAndCommand.LineTo);
                    }

                    graphics2D.Render(stroke, movementColor);
                }
            }
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double movementLineWidth = 0.35 * renderInfo.LayerScale;
                Color  movementColor     = new Color(10, 190, 15);

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    Vector3Float startF = this.GetStart(renderInfo);
                    Vector3Float endF   = this.GetEnd(renderInfo);
                    Vector2      start  = new Vector2(startF.x, startF.y);
                    renderInfo.Transform.transform(ref start);

                    Vector2 end = new Vector2(endF.x, endF.y);
                    renderInfo.Transform.transform(ref end);

                    if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                    {
                        movementColor = new Color(movementColor, 200);
                    }

                    graphics2DGl.DrawAALineRounded(start, end, movementLineWidth, movementColor);
                }
                else
                {
                    VertexStorage pathStorage = new VertexStorage();
                    VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

                    stroke.line_cap(LineCap.Round);
                    stroke.line_join(LineJoin.Round);

                    Vector3Float start = this.GetStart(renderInfo);
                    Vector3Float end   = this.GetEnd(renderInfo);

                    pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo);
                    if (end.x != start.x || end.y != start.y)
                    {
                        pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo);
                    }
                    else
                    {
                        pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.LineTo);
                    }

                    graphics2D.Render(stroke, movementColor);
                }
            }
        }
예제 #7
0
            public ClosedLoopGlyphData(VertexStorage source)
            {
                storage = new VertexStorage();

                var vertexData = source.Vertices().Where(v => v.command != ShapePath.FlagsAndCommand.FlagNone).ToArray();

                VertexData previous = default(VertexData);

                for (var i = 0; i < vertexData.Length; i++)
                {
                    var current = vertexData[i];

                    // All MoveTo operations should be preceded by ClosePolygon
                    if (i > 0 &&
                        current.IsMoveTo &&
                        ShapePath.is_vertex(previous.command))
                    {
                        storage.ClosePolygon();
                    }

                    // Add original VertexData
                    storage.Add(current.position.X, current.position.Y, current.command);

                    // Hold prior item
                    previous = current;
                }

                // Ensure closed
                storage.ClosePolygon();
            }
예제 #8
0
 /// <summary>
 /// Animates the control of a vertex to a given position.
 /// </summary>
 /// <param name="control">Vertex control which should be animated to its new position</param>
 /// <param name="coord">New vertex position coordinates</param>
 public void AddVertexData(IGraphControl control, Measure.Point coord)
 {
     if (double.IsNaN(coord.X) || double.IsNaN(coord.Y))
     {
         throw new GX_InvalidDataException("AddVertexData() -> NaN coordinated has been supplied! Correct coordinates was expected.");
     }
     if (!VertexStorage.ContainsKey(control))
     {
         VertexStorage.Add(control, coord);
     }
     else
     {
         throw new GX_GeneralException("AddVertexData() -> Same control can't be loaded in animation list twice!");
     }
 }
예제 #9
0
		public static VertexStorage Offset(this IVertexSource a, double distance)
		{
			List<List<IntPoint>> aPolys = a.CreatePolygons();

			ClipperOffset offseter = new ClipperOffset();
			offseter.AddPaths(aPolys, JoinType.jtMiter, EndType.etClosedPolygon);
			var solution = new List<List<IntPoint>>();
			offseter.Execute(ref solution, distance * 1000);

			Clipper.CleanPolygons(solution);

			VertexStorage output = solution.CreateVertexStorage();

			output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

			return output;
		}
예제 #10
0
        private VertexStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
        {
            List <List <IntPoint> > aPolys = VertexSourceToClipperPolygons.CreatePolygons(a);
            List <List <IntPoint> > bPolys = VertexSourceToClipperPolygons.CreatePolygons(b);

            Clipper clipper = new Clipper();

            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);

            List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >();

            clipper.Execute(clipType, intersectedPolys);

            VertexStorage output = VertexSourceToClipperPolygons.CreateVertexStorage(intersectedPolys);

            output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

            return(output);
        }
예제 #11
0
        public static VertexStorage Offset(this IVertexSource a, double distance, JoinType joinType = JoinType.jtMiter, double scale = 1000)
        {
            var aPolys = a.CreatePolygons(scale);

            aPolys = aPolys.GetCorrectedWinding();

            var offseter = new ClipperOffset();

            offseter.AddPaths(aPolys, joinType, EndType.etClosedPolygon);
            var solution = new Polygons();

            offseter.Execute(ref solution, distance * scale);

            Clipper.CleanPolygons(solution);

            VertexStorage output = solution.CreateVertexStorage();

            output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

            return(output);
        }
예제 #12
0
    public static VertexStorage MergePaths(this IVertexSource a, IVertexSource b, ClipType clipType)
    {
        List <List <IntPoint> > aPolys = a.CreatePolygons();
        List <List <IntPoint> > bPolys = b.CreatePolygons();

        var clipper = new Clipper();

        clipper.AddPaths(aPolys, PolyType.ptSubject, true);
        clipper.AddPaths(bPolys, PolyType.ptClip, true);

        var outputPolys = new List <List <IntPoint> >();

        clipper.Execute(clipType, outputPolys);

        Clipper.CleanPolygons(outputPolys);

        VertexStorage output = outputPolys.CreateVertexStorage();

        output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

        return(output);
    }
예제 #13
0
        public CalibrationTabWidget(XyCalibrationWizard calibrationWizard, TextButton nextButton, ThemeConfig theme)
        {
            this.calibrationWizard = calibrationWizard;
            this.theme             = theme;
            this.NextButton        = nextButton;
            tabBaseColor           = new Color(theme.SlightShade.ToColorF(), theme.SlightShade.Alpha0To1 * 1.2);

            double barWidth  = 30;
            double barHeight = 300;

            double left   = LocalBounds.Left + 15;
            double bottom = LocalBounds.Bottom + 15;
            double right  = left + barHeight;

            var a = new Vector2(left, bottom);
            var b = new Vector2(left, bottom + barHeight);
            var c = new Vector2(left + barWidth, bottom + barHeight);
            var d = new Vector2(left + barWidth, bottom + barWidth);
            var e = new Vector2(right, bottom + barWidth);
            var f = new Vector2(right + (barWidth * .7), bottom + (barWidth / 2));
            var g = new Vector2(right, bottom);

            var m = new Vector2(b.X + (barWidth / 2), b.Y + (barWidth * .6));
            var n = new Vector2(m.X, b.Y);
            var r = new Vector2(b.X, m.Y);

            var tabShape2 = new VertexStorage();

            tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A
            tabShape2.LineTo(b);                             // A - B

            tabShape2.curve3(r.X, r.Y, m.X, m.Y);            // B -> C
            tabShape2.curve3(c.X, c.Y);

            tabShape2.LineTo(d);             // C -> D
            tabShape2.LineTo(e);             // D -> E
            tabShape2.LineTo(f);             // E -> F
            tabShape2.LineTo(g);             // F -> G
            tabShape2.ClosePolygon();

            int highlightStroke = 2;
            int highlightOffset = 8;
            int highlightWidth  = 16;

            double x1 = d.X + highlightOffset;
            double x2 = x1 + highlightWidth;
            double y1 = d.Y + highlightOffset;
            double y2 = c.Y - highlightOffset;

            double midY = y1 + (y2 - y1) / 2;

            var highlighter = new VertexStorage();

            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x2, y1);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2 + highlightOffset, midY);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x1, y2);

            xHighlighter = new Stroke(highlighter, highlightStroke);

            xLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute
            };

            xLabel.Position = new Vector2(x2 + highlightOffset * 2, midY - xLabel.Height / 2);

            this.AddChild(xLabel);

            x1 = d.X + highlightOffset;
            y1 = d.Y + 50;

            x1 = d.X + highlightOffset;
            x2 = e.X - highlightOffset;
            y1 = d.Y + highlightOffset;
            y2 = y1 + highlightWidth;

            double midX = x1 + (x2 - x1) / 2;

            highlighter = new VertexStorage();
            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x1, y2);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(midX, y2 + highlightOffset);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x2, y1);

            yHighlighter = new Stroke(highlighter, highlightStroke);

            yLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute,
                Visible = false,
            };
            this.AddChild(yLabel);

            yLabel.Position = new Vector2(midX - yLabel.Width / 2, y2 + (highlightOffset * 2));

            yHighlighter = new Stroke(highlighter, highlightStroke);

            int padCount = 7;

            double cellSize = (barHeight - barWidth) / padCount;
            int    padding  = (int)(cellSize * .3);

            double padSize = cellSize - padding;

            var titles = new[] { "-3", "-2", "-1", "0", "+1", "+2", "+3" };

            for (var i = 0; i < padCount; i++)
            {
                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left, bottom + 3 + barWidth + (cellSize * i)),
                    Height   = padSize,
                    Width    = barWidth,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.X
                });

                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left + 3 + barWidth + (cellSize * i), bottom),
                    Height   = barWidth,
                    Width    = padSize,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.Y
                });
            }

            foreach (var calibrationPad in this.Children.OfType <CalibrationPad>())
            {
                calibrationPad.Click   += this.CalibrationPad_Click;
                calibrationPad.Hovered += this.CalibrationPad_Hovered;
            }

            tabShape  = new FlattenCurves(tabShape2);
            tabStroke = new Stroke(tabShape);
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
            {
                double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                Color extrusionColor = Color.Black;

                if (highlightFeature)
                {
                    extrusionColor = RenderFeatureBase.HighlightColor;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    extrusionColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    extrusionColor = Color.Gray;
                }
                else
                {
                    extrusionColor = renderInfo.GetMaterialColor(toolIndex);
                }

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new Color(extrusionColor, 200);
                }

                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    // render using opengl
                    var startPoint = new Vector2(start.X, start.Y);
                    renderInfo.Transform.transform(ref startPoint);

                    var endPoint = new Vector2(end.X, end.Y);
                    renderInfo.Transform.transform(ref endPoint);

                    var eWidth = extrusionLineWidths / 2;

                    graphics2DGl.DrawAALineRounded(startPoint, endPoint, eWidth, extrusionColor);

                    if (highlightFeature)
                    {
                        Render3DStartEndMarkers(graphics2DGl, eWidth / 2, startPoint, endPoint);
                    }
                }
                else
                {
                    // render using agg
                    var pathStorage            = new VertexStorage();
                    var transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    var stroke = new Stroke(transformedPathStorage, extrusionLineWidths / 2)
                    {
                        LineCap  = LineCap.Round,
                        LineJoin = LineJoin.Round
                    };

                    pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo);
                    pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo);

                    graphics2D.Render(stroke, extrusionColor);
                }
            }
        }