Beispiel #1
0
        public virtual LinearToolpath CreateExtrude(
            List <Vector2d> toPoints,
            double fSpeed, Vector2d dimensions,
            IFillType fillType,
            bool isHole,
            List <TPVertexFlags> perVertexFlags = null)
        {
            Vector2d useDims = currentDims;

            if (dimensions.x > 0 && dimensions.x != NO_DIM.x)
            {
                useDims.x = dimensions.x;
            }
            if (dimensions.y > 0 && dimensions.y != NO_DIM.y)
            {
                useDims.y = dimensions.y;
            }

            LinearToolpath extrusion = new LinearToolpath(MoveType);

            extrusion.FillType = fillType;
            extrusion.AppendVertex(new PrintVertex(currentPos, NO_RATE, useDims), TPVertexFlags.IsPathStart);

            for (int k = 1; k < toPoints.Count; ++k)
            {
                Vector3d      pos  = new Vector3d(toPoints[k].x, toPoints[k].y, currentPos.z);
                TPVertexFlags flag = (k == toPoints.Count - 1) ? TPVertexFlags.IsPathEnd : TPVertexFlags.None;
                extrusion.AppendVertex(new PrintVertex(pos, fSpeed, useDims), flag);
            }
            if (perVertexFlags != null)
            {
                ToolpathUtil.AddPerVertexFlags(extrusion, perVertexFlags);
            }
            return(extrusion);
        }
Beispiel #2
0
 public void Append(Polygon2d poly, IFillType fillType)
 {
     Loops.Add(new FillLoop <FillSegment>(poly.VerticesItr(false).ToList())
     {
         FillType = fillType
     });
 }
Beispiel #3
0
 public void Append(List <Polygon2d> polys, IFillType fillType)
 {
     foreach (var p in polys)
     {
         Append(p, fillType);
     }
 }
Beispiel #4
0
        // [RMS] only using this for hit-testing to make sure no connectors cross polygon border...
        // [TODO] replace with GeneralPolygon2dBoxTree (currently does not have intersection test!)
        //SegmentSet2d BoundaryPolygonCache;

        public ParallelLinesFillPolygon(GeneralPolygon2d poly, IFillType fillType, bool exportToSVG = false)
        {
            Polygon          = poly;
            FillCurves       = new List <FillCurveSet2d>();
            FillType         = fillType;
            this.exportToSVG = exportToSVG;
        }
Beispiel #5
0
        public virtual Vector3d AppendExtrude(List <Vector2d> toPoints, double fSpeed,
                                              Vector2d dimensions, IFillType fillType, bool isHole, List <TPVertexFlags> perVertexFlags = null)
        {
            var extrusion = CreateExtrude(toPoints, fSpeed, dimensions, fillType, isHole, perVertexFlags);

            AppendPath(extrusion);
            return(currentPos);
        }
Beispiel #6
0
        public virtual Vector3d AppendExtrude(Vector3d toPos, double fSpeed, IFillType fillType)
        {
            LinearToolpath extrusion = new LinearToolpath(MoveType);

            extrusion.FillType = fillType;
            extrusion.AppendVertex(new PrintVertex(currentPos, NO_RATE, currentDims), TPVertexFlags.IsPathStart);
            extrusion.AppendVertex(new PrintVertex(toPos, fSpeed, currentDims), TPVertexFlags.IsPathEnd);
            AppendPath(extrusion);
            return(currentPos);
        }
Beispiel #7
0
        public void SetFillType(IFillType fillType)
        {
            foreach (var loop in Loops)
            {
                loop.FillType = fillType;
            }

            foreach (var curve in Curves)
            {
                curve.FillType = fillType;
            }
        }
Beispiel #8
0
 public void Append(GeneralPolygon2d poly, IFillType fillType)
 {
     Loops.Add(new FillLoop <FillSegment>(poly.Outer.VerticesItr(false).ToList())
     {
         FillType = fillType
     });
     foreach (var h in poly.Holes)
     {
         Loops.Add(new FillLoop <FillSegment>(h.VerticesItr(false).ToList())
         {
             FillType = fillType
         });
     }
 }
Beispiel #9
0
        protected bool LineIsNewFillTypeComment(GCodeLine line, out IFillType fillType)
        {
            if (line.Comment != null)
            {
                var match = fillTypeLabelPattern.Match(line.Comment);
                if (match.Success)
                {
                    if (!FillTypes.TryGetValue(match.Groups[1].Captures[0].Value, out fillType))
                    {
                        fillType = new DefaultFillType();
                    }
                    return(true);
                }
            }

            fillType = null;
            return(false);
        }
Beispiel #10
0
        public virtual Vector3d AppendExtrude(List <Vector3d> toPoints, double fSpeed,
                                              IFillType fillType, List <TPVertexFlags> perVertexFlags = null)
        {
            LinearToolpath extrusion = new LinearToolpath(MoveType);

            extrusion.FillType = fillType;
            extrusion.AppendVertex(new PrintVertex(currentPos, NO_RATE, currentDims), TPVertexFlags.IsPathStart);
            for (int k = 0; k < toPoints.Count; ++k)
            {
                TPVertexFlags flag = (k == toPoints.Count - 1) ? TPVertexFlags.IsPathEnd : TPVertexFlags.None;
                extrusion.AppendVertex(new PrintVertex(toPoints[k], fSpeed, currentDims), flag);
            }
            if (perVertexFlags != null)
            {
                ToolpathUtil.AddPerVertexFlags(extrusion, perVertexFlags);
            }
            AppendPath(extrusion);
            return(currentPos);
        }
Beispiel #11
0
        public ShellsFillPolygon(GeneralPolygon2d poly, IFillType fillType, IFillType firstShellFillType = null)
        {
            Polygon = poly;
            Shells  = new List <FillCurveSet2d>();

            InsetDistanceFactoryF = (shell_i) =>
            {
                if (shell_i == 0)
                {
                    return(ToolWidth * InsetFromInputPolygonX);
                }
                else
                {
                    return(PathSpacing);
                }
            };

            this.fillType           = fillType;
            this.firstShellFillType = firstShellFillType;
        }
Beispiel #12
0
        //SegmentSet2d BoundaryPolygonCache;

        public RasterFillPolygon(GeneralPolygon2d poly, IFillType fillType)
        {
            Polygon    = poly;
            FillCurves = new List <FillCurveSet2d>();
            FillType   = fillType;
        }
Beispiel #13
0
 public virtual Vector3d AppendExtrude(Vector2d toPos, double fSpeed, IFillType fillType)
 {
     return(AppendExtrude(new Vector3d(toPos.x, toPos.y, currentPos.z), fSpeed, fillType));
 }
Beispiel #14
0
 public SparseLinesFillPolygon(GeneralPolygon2d poly, IFillType fillType) : base(poly, fillType)
 {
     SimplifyAmount = SimplificationLevel.Moderate;
 }
 protected virtual void AddFeatureTypeLabel(IFillType fillType)
 {
     AddFeatureTypeLabel(fillType.GetLabel());
 }
Beispiel #16
0
 public virtual Vector3d AppendExtrude(List <Vector2d> toPoints, double fSpeed,
                                       IFillType fillType, List <TPVertexFlags> perVertexFlags = null, bool isHole = false)
 {
     return(AppendExtrude(toPoints, fSpeed, currentDims, fillType, isHole, perVertexFlags));
 }
Beispiel #17
0
        /// <summary>
        /// Convert the input polygons to a set of paths.
        /// If FilterSelfOverlaps=true, then the paths will be clipped against
        /// themselves, in an attempt to avoid over-printing.
        /// </summary>
        public virtual FillCurveSet2d ShellPolysToPaths(List <GeneralPolygon2d> shell_polys, int nShell)
        {
            FillCurveSet2d paths = new FillCurveSet2d();

            IFillType currentFillType = nShell == 0 ? firstShellFillType ?? fillType : fillType;

            if (FilterSelfOverlaps == false)
            {
                foreach (var shell in shell_polys)
                {
                    paths.Append(new FillLoop <FillSegment>(shell.Outer.Vertices)
                    {
                        FillType = currentFillType, PerimeterOrder = nShell
                    });
                    foreach (var hole in shell.Holes)
                    {
                        paths.Append(new FillLoop <FillSegment>(hole.Vertices)
                        {
                            FillType = currentFillType, PerimeterOrder = nShell, IsHoleShell = true
                        });;
                    }
                }
                return(paths);
            }

            int outer_shell_edgegroup = 100;

            foreach (GeneralPolygon2d shell in shell_polys)
            {
                PathOverlapRepair repair = new PathOverlapRepair();
                repair.OverlapRadius = SelfOverlapTolerance;
                repair.Add(shell, outer_shell_edgegroup);

                // Ideally want to presreve outermost shell of external perimeters.
                // However in many cases internal holes are 'too close' to outer border.
                // So we will still apply to those, but use edge filter to preserve outermost loop.
                // [TODO] could we be smarter about this somehow?
                if (PreserveOuterShells && nShell == 0)
                {
                    repair.PreserveEdgeFilterF = (eid) => { return(repair.Graph.GetEdgeGroup(eid) == outer_shell_edgegroup); }
                }
                ;

                repair.Compute();

                DGraph2Util.Curves c = DGraph2Util.ExtractCurves(repair.GetResultGraph());

                #region Borrow nesting calculations from PlanarSlice to enforce winding direction

                PlanarComplex complex = new PlanarComplex();
                foreach (Polygon2d poly in c.Loops)
                {
                    complex.Add(poly);
                }

                PlanarComplex.FindSolidsOptions options
                    = PlanarComplex.FindSolidsOptions.Default;
                options.WantCurveSolids            = false;
                options.SimplifyDeviationTolerance = 0.001;
                options.TrustOrientations          = false;
                options.AllowOverlappingHoles      = false;

                PlanarComplex.SolidRegionInfo solids = complex.FindSolidRegions(options);
                foreach (var polygon in solids.Polygons)
                {
                    polygon.EnforceCounterClockwise();
                    paths.Append(new FillLoop <FillSegment>(polygon.Outer.Vertices)
                    {
                        FillType       = currentFillType,
                        PerimeterOrder = nShell
                    });
                    foreach (var hole in polygon.Holes)
                    {
                        paths.Append(new FillLoop <FillSegment>(hole.Vertices)
                        {
                            FillType       = currentFillType,
                            PerimeterOrder = nShell,
                            IsHoleShell    = true,
                        });
                    }
                }

                #endregion Borrow nesting calculations from PlanarSlice to enforce winding direction

                foreach (var polyline in c.Paths)
                {
                    if (polyline.ArcLength < DiscardTinyPerimeterLengthMM)
                    {
                        continue;
                    }
                    if (polyline.Bounds.MaxDim < DiscardTinyPerimeterLengthMM)
                    {
                        continue;
                    }
                    paths.Append(new FillCurve <FillSegment>(polyline)
                    {
                        FillType = currentFillType, PerimeterOrder = nShell
                    });
                }
            }
            return(paths);
        }