예제 #1
0
        private static Point2F lastpt(List <Sliced_path> trajectories)
        {
            if (trajectories.Count == 0)
            {
                return(Point2F.Undefined);
            }
            Sliced_path last = trajectories[trajectories.Count - 1];

            if (last.Count == 0)
            {
                return(Point2F.Undefined);
            }
            return((Point2F)last[last.Count - 1].LastPoint);
        }
예제 #2
0
        private List <Sliced_path> gen_profile(Polyline poly, bool is_inside, Point2F startpoint)
        {
            if (!startpoint.IsUndefined)
            {
                poly = new Polyline(poly);

                if (poly.Closed)
                {
                    poly = adjust_closed_startpoint(poly, startpoint);
                }
                else
                {
                    if (should_flip_opened_startpoint(poly, startpoint))
                    {
                        poly.Reverse();
                        is_inside = !is_inside;     // preserve side if flipped !
                    }
                }
            }


            List <Sliced_path> trajectories = new List <Sliced_path>();

            double cut_width = _cut_width.Cached;

            if (cut_width == 0)
            {
                cut_width = base.ToolDiameter.Cached * 2;
            }

            double offset = cut_width / 2 + base.RoughingClearance.Cached;

            if (is_inside)
            {
                offset = -offset;
            }

            Polyline[] array;

            // special case - simulation of engrave. do not offset poly at all to allow exact follow of path
            if (Math.Abs(offset) < (double)CamBamConfig.Defaults.GeneralTolerance)
            {
                array = new Polyline[] { poly };
            }
            else
            {
                array = poly.CreateOffsetPolyline(offset, (double)CamBamConfig.Defaults.GeneralTolerance, _should_overcut_corners.Cached, false);
            }

            if (array == null)
            {
                return(trajectories);
            }

            foreach (Polyline p in array)
            {
                if (trajectories.Count != 0)
                {
                    startpoint = lastpt(trajectories);
                }

                Sliced_path toolpath = gen_toolpath(p, cut_width);
                if (toolpath != null)
                {
                    Traj_metainfo meta = new Traj_metainfo();
                    meta.Start_normal  = new Vector2F((Point2F)toolpath[0].FirstPoint, (Point2F)poly.FirstPoint);
                    toolpath.Extension = meta;
                    trajectories.Add(toolpath);
                }
            }

            return(trajectories);
        }
예제 #3
0
        private List <Sliced_path> gen_fine_profile(Polyline poly, bool is_inside, Point2F startpoint)
        {
            if (!startpoint.IsUndefined)
            {
                poly = adjust_closed_startpoint(poly, startpoint);
            }

            double cut_width = _cut_width.Cached;

            if (cut_width == 0)
            {
                cut_width = base.ToolDiameter.Cached * 2;
            }

            double clearance_offset = base.RoughingClearance.Cached;
            double offset           = cut_width + clearance_offset;

            if (is_inside)
            {
                offset           = -offset;
                clearance_offset = -clearance_offset;
            }

            Polyline[] profile_walls;

            if (clearance_offset != 0)
            {
                profile_walls = poly.CreateOffsetPolyline(clearance_offset, (double)CamBamConfig.Defaults.GeneralTolerance, false, false);
            }
            else
            {
                profile_walls = new Polyline[] { poly }
            };

            Polyline[] pseudo_walls = poly.CreateOffsetPolyline(offset, (double)CamBamConfig.Defaults.GeneralTolerance, false, false);

            ShapeList shapes = new ShapeList();

            shapes.ApplyTransformations = true;
            shapes.AddEntities(profile_walls);
            shapes.AddEntities(pseudo_walls);
            shapes = shapes.DetectRegions();

            List <Sliced_path> trajectories = new List <Sliced_path>();

            Vector2F start_tangent = calc_start_tangent(poly);

            foreach (ShapeListItem shape in shapes)
            {
                if (shape.Shape is Polyline && !((Polyline)shape.Shape).Closed)
                {
                    Logger.warn("got open polyline while offsetting profile. ignoring");
                    continue;
                }

                if (trajectories.Count != 0)
                {
                    startpoint = lastpt(trajectories);
                }

                Sliced_path toolpath = gen_pocket_toolpath(shape, startpoint, start_tangent);
                if (toolpath != null)
                {
                    Traj_metainfo meta = new Traj_metainfo();
                    meta.Start_normal  = new Vector2F((Point2F)toolpath[0].FirstPoint, (Point2F)poly.FirstPoint);
                    toolpath.Extension = meta;
                    trajectories.Add(toolpath);
                }
            }

            return(trajectories);
        }
예제 #4
0
파일: mop.cs 프로젝트: robgrz/matmill
 public Toolpath(Sliced_path path, double bottom, double top)
 {
     this.Trajectory = path;
     this.Bottom     = bottom;
     this.Top        = top;
 }
예제 #5
0
        protected override void _GenerateToolpathsWorker()
        {
            try
            {
                base.reset_toolpaths();

                if (base.ToolDiameter.Cached == 0)
                {
                    Logger.err("tool diameter is zero");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                if (_stepover.Cached == 0 || _stepover.Cached > 1)
                {
                    Logger.err("stepover should be > 0 and <= 1");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                // XXX: is it needed ?
                base.UpdateGeometryExtrema(base._CADFile);
                base._CADFile.MachiningOptions.UpdateGeometryExtrema(base._CADFile);
                ShapeList shapes = new ShapeList();
                shapes.ApplyTransformations = true;
                shapes.AddEntities(base._CADFile, base.PrimitiveIds);
                shapes = shapes.DetectRegions();

                bool found_opened_polylines = false;
                for (int i = shapes.Count - 1; i >= 0; i--)
                {
                    if (shapes[i].Shape is Polyline && !((Polyline)shapes[i].Shape).Closed)
                    {
                        found_opened_polylines = true;
                        shapes.RemoveAt(i);
                    }
                }
                if (found_opened_polylines)
                {
                    Logger.warn("ignoring open polylines");
                    base.MachineOpStatus = MachineOpStatus.Warnings;
                }

                List <Sliced_path> trajectories = new List <Sliced_path>();

                foreach (ShapeListItem shape in shapes)
                {
                    Sliced_path traj = gen_pocket(shape);
                    if (traj != null)
                    {
                        trajectories.Add(traj);
                    }
                }

                if (trajectories.Count == 0)
                {
                    return;
                }

                base.insert_toolpaths(trajectories);

                if (base.MachineOpStatus == MachineOpStatus.Unknown)
                {
                    base.MachineOpStatus = MachineOpStatus.OK;
                }
            }
            catch (Exception ex)
            {
                base.MachineOpStatus = MachineOpStatus.Errors;
                ThisApplication.HandleException(ex);
            }
            finally
            {
                base._GenerateToolpathsFinal();
            }
        }