/// <summary>
        /// Compile this set of toolpaths and pass to assembler.
        /// Settings are optional, pass null to ignore
        /// </summary>
        public virtual void AppendPaths(ToolpathSet paths, SingleMaterialFFFSettings pathSettings)
        {
            Assembler.FlushQueues();

            SingleMaterialFFFSettings useSettings = (pathSettings == null) ? Settings : pathSettings;

            CalculateExtrusion calc = new CalculateExtrusion(paths, useSettings);

            calc.Calculate(Assembler.NozzlePosition, Assembler.ExtruderA, Assembler.InRetract);


            int path_index = 0;

            foreach (var gpath in paths)
            {
                path_index++;

                if (IsCommandToolpath(gpath))
                {
                    ProcessCommandToolpath(gpath);
                    continue;
                }

                LinearToolpath p = gpath as LinearToolpath;

                if (p[0].Position.Distance(Assembler.NozzlePosition) > 0.00001)
                {
                    throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": Start of path is not same as end of previous path!");
                }

                int i = 0;
                if ((p.Type == ToolpathTypes.Travel || p.Type == ToolpathTypes.PlaneChange) && Assembler.InTravel == false)
                {
                    //Assembler.DisableFan();

                    // do retract cycle
                    if (p[0].Extrusion.x < Assembler.ExtruderA)
                    {
                        if (Assembler.InRetract)
                        {
                            throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": already in retract!");
                        }
                        Assembler.BeginRetract(p[0].Position, useSettings.RetractSpeed, p[0].Extrusion.x);
                    }
                    Assembler.BeginTravel();
                }
                else if (p.Type == ToolpathTypes.Deposition)
                {
                    // end travel / retract if we are in that state
                    if (Assembler.InTravel)
                    {
                        if (Assembler.InRetract)
                        {
                            Assembler.EndRetract(p[0].Position, useSettings.RetractSpeed, p[0].Extrusion.x);
                        }
                        Assembler.EndTravel();
                        //Assembler.EnableFan();
                    }
                }

                i = 1;                      // do not need to emit code for first point of path,
                // we are already at this pos

                for (; i < p.VertexCount; ++i)
                {
                    if (p.Type == ToolpathTypes.Travel)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Travel");
                    }
                    else if (p.Type == ToolpathTypes.PlaneChange)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Plane Change");
                    }
                    else
                    {
                        Assembler.AppendExtrudeTo(p[i].Position, p[i].FeedRate, p[i].Extrusion.x);
                    }
                }
            }


            Assembler.FlushQueues();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compile this set of toolpaths and pass to assembler.
        /// Settings are optional, pass null to ignore
        /// </summary>
        public virtual void AppendPaths(ToolpathSet toolpathSet, SingleMaterialFFFSettings pathSettings)
        {
            Assembler.FlushQueues();

            SingleMaterialFFFSettings useSettings = (pathSettings == null) ? Settings : pathSettings;

            var paths = toolpathSet.GetPaths <PrintVertex>();
            var calc  = new CalculateExtrusion <PrintVertex>(paths, useSettings);

            calc.Calculate(Assembler.NozzlePosition, Assembler.ExtruderA, Assembler.InRetract);

            int path_index = 0;

            foreach (var gpath in toolpathSet)
            {
                path_index++;

                if (IsCommandToolpath(gpath))
                {
                    ProcessCommandToolpath(gpath);
                    continue;
                }

                LinearToolpath p = gpath as LinearToolpath;

                if (p[0].Position.Distance(Assembler.NozzlePosition) > 0.00001)
                {
                    throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": Start of path is not same as end of previous path!");
                }

                int i = 0;
                if (p.Type == ToolpathTypes.Travel || p.Type == ToolpathTypes.PlaneChange)
                {
                    HandleTravelAndPlaneChangePath(p, path_index, useSettings);
                }
                else if (p.Type == ToolpathTypes.Deposition)
                {
                    HandleDepositionPath(p, useSettings);
                }

                i = 1;      // do not need to emit code for first point of path,
                            // we are already at this pos

                var currentDimensions = p[1].Dimensions;

                for (; i < p.VertexCount; ++i)
                {
                    if (p.Type == ToolpathTypes.Travel)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Travel");
                    }
                    else if (p.Type == ToolpathTypes.PlaneChange)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Plane Change");
                    }
                    else
                    {
                        if (p.Type == ToolpathTypes.Deposition && !p[i].Dimensions.EpsilonEqual(currentDimensions, 1e-6))
                        {
                            currentDimensions = p[i].Dimensions;
                            AppendDimensions(p[i].Dimensions);
                        }
                        Assembler.AppendExtrudeTo(p[i].Position, p[i].FeedRate, p[i].Extrusion.x, null);
                    }
                }
            }

            /*
             * TODO: Should there be an EndTravel() call here?
             */
            HandleDepositionEnd();
            Assembler.FlushQueues();
        }