Beispiel #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Toolpath> tpIn      = new List <Toolpath>();
            object          safety    = null;
            string          post_name = "";
            bool            post_all  = false;
            Plane           frame     = Plane.WorldXY;


            DA.GetData("Machine", ref post_name);
            this.Message = post_name;

            DA.GetDataList("Toolpaths", tpIn);
            DA.GetData("Safety", ref safety);
            DA.GetData("Frame", ref frame);
            DA.GetData("All codes", ref post_all);

            List <Toolpath> TP = tpIn.Select(x => x.Duplicate()).ToList();

            MachinePost post = null;

            switch (post_name)
            {
            case ("CMS"):
                post = new CMSPost();
                break;

            case ("Haas"):
                post = new HaasPost();
                break;

            case ("Shopbot"):
                post = new ShopbotPost();
                break;

            case ("Raptor"):
                post = new RaptorBCNPost();
                break;

            case ("CNC-STEP"):
                post = new CncStepPost();
                break;

            default:
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Machine {post_name} not found.");
                return;
            }


            // Program initialization
            var doc = OnPingDocument();

            if (doc != null)
            {
                post.Author = doc.Author.Name;
                post.Name   = doc.DisplayName;
            }
            else
            {
                post.Author = "Author";
                post.Name   = "Post";
            }

            post.StockModel = null;

            post.AlwaysWriteGCode = post_all;

            for (int i = 0; i < TP.Count; ++i)
            {
                var toolpath = TP[i];
                post.AddTool(toolpath.Tool);

                if (frame != Plane.WorldXY)
                {
                    toolpath.Transform(Transform.PlaneToPlane(Plane.WorldXY, frame));
                }

                post.AddPath(toolpath);
            }

            //cms.WorkOffset = new Point3d(0, 0, 0);

            // Post-process toolpaths

            var code = (post.Compute() as List <string>).Select(x => new GH_String(x));

            // ****** Fun stuff ends here. ******


            List <Point3d>  points  = new List <Point3d>();
            List <int>      types   = new List <int>();
            List <Vector3d> vectors = new List <Vector3d>();

            for (int i = 0; i < post.Paths.Count; ++i)
            {
                for (int j = 0; j < post.Paths[i].Paths.Count; ++j)
                {
                    for (int k = 0; k < post.Paths[i].Paths[j].Count; ++k)
                    {
                        points.Add(post.Paths[i].Paths[j][k].Plane.Origin);
                        vectors.Add(post.Paths[i].Paths[j][k].Plane.ZAxis);

                        if (post.Paths[i].Paths[j][k].IsRapid())
                        {
                            types.Add(0);
                        }
                        else if (post.Paths[i].Paths[j][k].IsFeed())
                        {
                            types.Add(1);
                        }
                        else if (post.Paths[i].Paths[j][k].IsPlunge())
                        {
                            types.Add(2);
                        }
                        else
                        {
                            types.Add(-1);
                        }
                    }
                }
            }

            Polyline    poly  = new Polyline(points);
            List <Line> lines = new List <Line>();

            for (int i = 1; i < poly.Count; ++i)
            {
                lines.Add(new Line(poly[i - 1], poly[i]));
            }

            types.RemoveAt(0);

            DA.SetDataList("Gcode", code);
            DA.SetDataList("Path", lines);
            DA.SetDataList("debug", post.Errors);

            if (post.Axes != null)
            {
                var axes = new List <string>();
                foreach (var values in post.Axes)
                {
                    axes.Add($"{values.X:0.000}, {values.Y:0.000}, {values.Z:0.000}, {values.B:0.000}, {values.C:0.000}");
                }
                DA.SetDataList("Axes", axes);
                DA.SetDataList("Speeds", post.Axes.Select(x => x.Speed));
            }
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Toolpath> tpIn   = new List <Toolpath>();
            object          safety = null;

            DA.GetDataList("Toolpaths", tpIn);
            DA.GetData("Safety", ref safety);

            List <Toolpath> TP = tpIn.Select(x => x.Duplicate()).ToList();

            /*
             * // Create and initialize toolpath
             * Toolpath T = new Toolpath();
             * T.Safety = safety;
             * T.PlaneRetractVertical = false;
             * T.SafeZ = 10.0;
             * T.Paths = new List<List<Waypoint>>();
             *
             * bool zigzag = false;
             * bool zz = false;
             * bool rev = false;
             *
             * // Add individual paths to toolpath, zigzag or reverse if necessary
             * for (int i = 0; i < TP.Count; ++i)
             * {
             *  List<Waypoint> waypoints = new List<Waypoint>();
             *  waypoints.AddRange(TP[i].Select(x => new Waypoint(x, (int)WaypointType.FEED)));
             *
             *  if (zigzag && zz)
             *      waypoints.Reverse();
             *  else if (!zz && rev)
             *      waypoints.Reverse();
             *
             *  T.Paths.Add(waypoints);
             *
             *  zigzag = !zigzag;
             * }
             */

            //T.CreateRamps(20, 50);

            // Program initialization

            HaasPost haas = new HaasPost();

            haas.Author     = "Tom Svilans";
            haas.Name       = "TestPost";
            haas.StockModel = null;

            for (int i = 0; i < TP.Count; ++i)
            {
                haas.AddTool(TP[i].Tool);
                //TP[i].CreateLeadsAndLinks();
                haas.AddPath(TP[i]);
            }

            //haas.WorkOffset = new Point3d(0, 0, 0);

            // Post-process toolpaths

            var code = (haas.Compute() as List <string>).Select(x => new GH_String(x));

            // ****** Fun stuff ends here. ******


            List <Point3d>  points  = new List <Point3d>();
            List <int>      types   = new List <int>();
            List <Vector3d> vectors = new List <Vector3d>();

            for (int i = 0; i < haas.Paths.Count; ++i)
            {
                for (int j = 0; j < haas.Paths[i].Paths.Count; ++j)
                {
                    for (int k = 0; k < haas.Paths[i].Paths[j].Count; ++k)
                    {
                        points.Add(haas.Paths[i].Paths[j][k].Plane.Origin);
                        vectors.Add(haas.Paths[i].Paths[j][k].Plane.ZAxis);

                        if (haas.Paths[i].Paths[j][k].IsRapid())
                        {
                            types.Add(0);
                        }
                        else if (haas.Paths[i].Paths[j][k].IsFeed())
                        {
                            types.Add(1);
                        }
                        else if (haas.Paths[i].Paths[j][k].IsPlunge())
                        {
                            types.Add(2);
                        }
                        else
                        {
                            types.Add(-1);
                        }
                    }
                }
            }

            Polyline    poly  = new Polyline(points);
            List <Line> lines = new List <Line>();

            for (int i = 1; i < poly.Count; ++i)
            {
                lines.Add(new Line(poly[i - 1], poly[i]));
            }

            types.RemoveAt(0);

            DA.SetDataList("Gcode", code);
            DA.SetDataList("Path", lines);
        }