Ejemplo n.º 1
0
 public void Append(Polygon2d poly, FillTypeFlags typeFlags)
 {
     Loops.Add(new FillPolygon2d(poly)
     {
         TypeFlags = typeFlags
     });
 }
        private void AddFeatureTypeLabel(FillTypeFlags typeModifier)
        {
            var featureLabel = featureTypeLabeler.FeatureLabelFromFillTypeFlag(typeModifier);

            Builder.AddExplicitLine("");
            Builder.AddCommentLine(" feature " + featureLabel);
        }
Ejemplo n.º 3
0
        public virtual Vector3d AppendExtrude(List <Vector2d> toPoints,
                                              double fSpeed, Vector2d dimensions,
                                              FillTypeFlags pathTypeFlags         = FillTypeFlags.Unknown,
                                              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(ToolpathTypes.Deposition);

            extrusion.TypeModifiers = pathTypeFlags;
            extrusion.AppendVertex(new PrintVertex(currentPos, NO_RATE, useDims), TPVertexFlags.IsPathStart);

            for (int k = 0; 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);
            }
            AppendPath(extrusion);
            return(currentPos);
        }
Ejemplo n.º 4
0
        protected virtual List <LayerInfo <TFeatureInfo> > PerLayerInfoFromGCodeFile(GCodeFile gcode)
        {
            featureInfoFactory.Initialize();
            var layers = new List <LayerInfo <TFeatureInfo> >();

            LayerInfo <TFeatureInfo> currentLayer = null;
            FillTypeFlags            fillType     = FillTypeFlags.Unknown;

            foreach (var line in gcode.AllLines())
            {
                if (LineIsNewLayer(line))
                {
                    if (currentLayer != null)
                    {
                        currentLayer.AddFeatureInfo(featureInfoFactory.SwitchFeature(fillType));
                        layers.Add(currentLayer);
                    }
                    currentLayer = new LayerInfo <TFeatureInfo>();
                    continue;
                }

                if (LineIsNewFeatureType(line, fillType, out var newFillType))
                {
                    currentLayer?.AddFeatureInfo(featureInfoFactory.SwitchFeature(newFillType));
                }

                featureInfoFactory.ObserveGcodeLine(line);
            }

            currentLayer?.AddFeatureInfo(featureInfoFactory.SwitchFeature(fillType));
            layers.Add(currentLayer);
            return(layers);
        }
Ejemplo n.º 5
0
 public void Append(List <Polygon2d> polys, FillTypeFlags typeFlags)
 {
     foreach (var p in polys)
     {
         Append(p, typeFlags);
     }
 }
Ejemplo n.º 6
0
        protected virtual ToolpathPreviewVertex VertexFactory(int layerIndex, FillTypeFlags fillType, Vector2d dimensions, double feedrate, float brightness, int pointCount, Vector3d vertex, Vector3f color)
        {
            // Update adaptive ranges for custom data
            customDataFeedRate.ObserveValue((float)feedrate);
            customDataCompletion.ObserveValue(pointCount);

            return(new ToolpathPreviewVertex(vertex,
                                             (int)fillType, layerIndex, color, brightness,
                                             (float)dimensions.x, (float)feedrate, pointCount));
        }
Ejemplo n.º 7
0
 public void AddFlags(FillTypeFlags flags)
 {
     foreach (var loop in Loops)
     {
         loop.TypeFlags |= flags;
     }
     foreach (var curve in Curves)
     {
         curve.TypeFlags |= flags;
     }
 }
Ejemplo n.º 8
0
        public virtual Vector3d AppendExtrude(Vector3d toPos, double fSpeed,
                                              FillTypeFlags pathTypeFlags = FillTypeFlags.Unknown)
        {
            LinearToolpath extrusion = new LinearToolpath(ToolpathTypes.Deposition);

            extrusion.TypeModifiers = pathTypeFlags;
            extrusion.AppendVertex(new PrintVertex(currentPos, NO_RATE, currentDims), TPVertexFlags.IsPathStart);
            extrusion.AppendVertex(new PrintVertex(toPos, fSpeed, currentDims), TPVertexFlags.IsPathEnd);
            AppendPath(extrusion);
            return(currentPos);
        }
Ejemplo n.º 9
0
 private bool LineIsNewFeatureType(GCodeLine line, FillTypeFlags fillType, out FillTypeFlags newFillType)
 {
     newFillType = fillType;
     if (GCodeLineUtil.ExtractFillType(line, ref newFillType))
     {
         if (newFillType != fillType)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 10
0
        public string FeatureLabelFromFillTypeFlag(FillTypeFlags flag)
        {
            var flagInt = (int)flag;

            if (FlagToFeatureLabelDictionary.TryGetValue(flagInt, out string name))
            {
                return(name);
            }
            else
            {
                return(FlagToFeatureLabelDictionary[(int)FillTypeFlags.Unknown]);
            }
        }
Ejemplo n.º 11
0
 public void Append(GeneralPolygon2d poly, FillTypeFlags typeFlags)
 {
     Loops.Add(new FillPolygon2d(poly.Outer)
     {
         TypeFlags = typeFlags
     });
     foreach (var h in poly.Holes)
     {
         Loops.Add(new FillPolygon2d(h)
         {
             TypeFlags = typeFlags
         });
     }
 }
Ejemplo n.º 12
0
        public FeatureInfo SwitchFeature(FillTypeFlags featureType)
        {
            var result = currentFeatureInfo;

            currentFeatureInfo = new FeatureInfo(featureType);
            if (result?.Extrusion > 0)
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 13
0
 public static bool ExtractFillType(GCodeLine line, ref FillTypeFlags fillType)
 {
     if (line.comment != null)
     {
         int indexOfFillType = line.comment.IndexOf("feature");
         if (indexOfFillType >= 0)
         {
             var featureName = line.comment.Substring(indexOfFillType + 8).Trim();
             fillType = FeatureTypeLabelerFFF.Value.FillTypeFlagFromFeatureLabel(featureName);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 14
0
        protected virtual int AddVertex(List <ToolpathPreviewVertex> vertices, int layerIndex, Vector3d point,
                                        FillTypeFlags fillType, Vector2d dimensions, double feedrate, Vector3d miterNormal,
                                        Vector2d crossSectionVertex, double secant, float brightness, int pointCount)
        {
            Vector3d offset = miterNormal * (dimensions.x * crossSectionVertex.x * secant) + new Vector3d(0, 0, dimensions.y * crossSectionVertex.y);
            Vector3d vertex = point + offset;

            Vector3f color = FillTypes[(int)FillTypeFlags.Unknown].Color;

            if (FillTypes.TryGetValue((int)fillType, out var fillInfo))
            {
                color = fillInfo.Color;
            }

            vertices.Add(VertexFactory(layerIndex, fillType, dimensions, feedrate, brightness, pointCount, vertex, color));

            return(vertices.Count - 1);
        }
Ejemplo n.º 15
0
        public virtual Vector3d AppendExtrude(List <Vector3d> toPoints, double fSpeed,
                                              FillTypeFlags pathTypeFlags         = FillTypeFlags.Unknown,
                                              List <TPVertexFlags> perVertexFlags = null)
        {
            LinearToolpath extrusion = new LinearToolpath(ToolpathTypes.Deposition);

            extrusion.TypeModifiers = pathTypeFlags;
            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);
        }
Ejemplo n.º 16
0
 public bool GetFeatureInfo(FillTypeFlags fillType, out TFeatureInfo featureInfo)
 {
     return(perFeatureInfo.TryGetValue(fillType, out featureInfo));
 }
Ejemplo n.º 17
0
 public bool HasTypeFlag(FillTypeFlags f)
 {
     return((TypeFlags & f) == f);
 }
Ejemplo n.º 18
0
 public virtual Vector3d AppendExtrude(List <Vector2d> toPoints, double fSpeed,
                                       FillTypeFlags pathTypeFlags         = FillTypeFlags.Unknown,
                                       List <TPVertexFlags> perVertexFlags = null)
 {
     return(AppendExtrude(toPoints, fSpeed, currentDims, pathTypeFlags, perVertexFlags));
 }
Ejemplo n.º 19
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();

            FillTypeFlags flags = FillTypeFlags.PerimeterShell;

            if (nShell == 0 && ShellType == ShellTypes.ExternalPerimeters)
            {
                flags = FillTypeFlags.OutermostShell;
            }
            else if (ShellType == ShellTypes.InternalShell)
            {
                flags = FillTypeFlags.InteriorShell;
            }
            else if (ShellType == ShellTypes.BridgeShell)
            {
                flags = FillTypeFlags.BridgeSupport;
            }

            if (FilterSelfOverlaps == false)
            {
                foreach (GeneralPolygon2d shell in shell_polys)
                {
                    paths.Append(shell, flags);
                }
                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 && ShellType == ShellTypes.ExternalPerimeters)
                {
                    repair.PreserveEdgeFilterF = (eid) => { return(repair.Graph.GetEdgeGroup(eid) == outer_shell_edgegroup); }
                }
                ;

                repair.Compute();

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

                foreach (var polygon in c.Loops)
                {
                    paths.Append(polygon, flags);
                }
                foreach (var polyline in c.Paths)
                {
                    if (polyline.ArcLength < DiscardTinyPerimterLengthMM)
                    {
                        continue;
                    }
                    if (polyline.Bounds.MaxDim < DiscardTinyPerimterLengthMM)
                    {
                        continue;
                    }
                    paths.Append(new FillPolyline2d(polyline)
                    {
                        TypeFlags = flags
                    });
                }
            }
            return(paths);
        }
Ejemplo n.º 20
0
 public virtual Vector3d AppendExtrude(Vector2d toPos, double fSpeed,
                                       FillTypeFlags pathTypeFlags = FillTypeFlags.Unknown)
 {
     return(AppendExtrude(new Vector3d(toPos.x, toPos.y, currentPos.z), fSpeed, pathTypeFlags));
 }
Ejemplo n.º 21
0
 public FeatureInfo(FillTypeFlags fillType)
 {
     FillType = fillType;
 }