示例#1
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);
        }
示例#2
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 (_cut_width.Cached != 0 && _cut_width.Cached < base.ToolDiameter.Cached * 1.05)
                {
                    Logger.err("cut width is too small");
                    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();

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

                bool is_inside = _cut_side.Cached == InsideOutsideOptions.Inside;

                Point2F startpoint = (Point2F)base.StartPoint.Cached;

                foreach (ShapeListItem shape in shapes)
                {
                    if (trajectories.Count != 0)
                    {
                        startpoint = lastpt(trajectories);
                    }

                    if (shape.Shape is Polyline)
                    {
                        trajectories.AddRange(gen_profile((Polyline)shape.Shape, is_inside, startpoint));
                    }
                    else if (shape.Shape is CamBam.CAD.Region)
                    {
                        trajectories.AddRange(gen_profile((CamBam.CAD.Region)shape.Shape, is_inside, startpoint));
                    }
                }

                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();
            }
        }
示例#3
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();
            }
        }