예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Toolpath tp    = null;
            Plane    plane = Plane.Unset;

            DA.GetData("Toolpath", ref tp);
            DA.GetData("Retract plane", ref plane);

            if (tp == null)
            {
                return;
            }

            Toolpath tp2 = tp.Duplicate();

            tp2.CreateLeadsAndLinks(plane);

            DA.SetData("Toolpath", new GH_Toolpath(tp2));
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Plane m_baseplane = Plane.WorldXY;

            DA.GetData("Baseplane", ref m_baseplane);

            Plane m_workplane = Plane.WorldXY;

            DA.GetData("Workplane", ref m_workplane);

            Point3d m_point = Point3d.Origin;

            DA.GetData("Point", ref m_point);

            MachineTool m_machine_tool = null;

            DA.GetData("MachineTool", ref m_machine_tool);

            Toolpath m_toolpath = null;

            DA.GetData("Toolpath", ref m_toolpath);

            Mesh m_stock = null;

            DA.GetData("Stock mesh", ref m_stock);

            bool m_reset = false;

            DA.GetData("Reset", ref m_reset);

            Toolpath tpViz = null; int tpVizN = 0;

            if (m_toolpath != null)
            {
                tpViz = m_toolpath.Duplicate();
            }

            // Transform the workpiece and TCP to the G54 work offset
            Transform G54_xform = Transform.PlaneToPlane(Plane.WorldXY, m_workplane);

            m_stock.Transform(G54_xform);

            m_point.Transform(G54_xform);

            if (tpViz != null)
            {
                tpVizN = XFORM(tpViz, G54_xform);
            }

            // Machine coordinates
            var coords = new double[] {
                m_point.X,
                m_point.Y,
                m_point.Z + m_machine_tool.Length
            };

            /*
             * bool is_good;
             * for (int i = 0; i < 3; ++i)
             *  if (!m_limits[i].IncludesParameter(coords[i]))
             *  {
             *      is_good = false;
             *  }
             * is_good = true;
             */

            if (!IsInMachineLimits(coords))
            {
                this.Message = "Out of bounds!";
            }
            else
            {
                this.Message = "";
            }

            if (m_reset)
            {
                m_machine_meshes = new List <Mesh>();
                DA.GetDataList("Machine meshes", m_machine_meshes);

                // Hard-code machine part transformations (could also just move the meshes in place)
                machine_part_xforms[0] = Transform.Translation(new Vector3d(0, 0, -506));
                machine_part_xforms[1] = Transform.Translation(new Vector3d(-508, -254, -506));
                machine_part_xforms[2] = Transform.Translation(new Vector3d(-508, -254, -506));
                machine_part_xforms[3] = Transform.Translation(new Vector3d(0, 0, -101.6));
                machine_part_xforms[4] = Transform.Translation(new Vector3d(0, 0, 0));
            }

            // Hard-code meshes
            meshes[0] =                                      // chassis
                        m_machine_meshes[0].DuplicateMesh();
            meshes[2] =                                      // bed (moves in XY)
                        m_machine_meshes[1].DuplicateMesh();
            meshes[3] =                                      // tower
                        m_machine_meshes[2].DuplicateMesh();
            meshes[4] =                                      //new Mesh();
                        m_machine_meshes[3].DuplicateMesh(); // tool
            meshes[4].Append(
                Mesh.CreateFromCylinder(new Cylinder(new Circle(
                                                         new Plane(
                                                             new Point3d(0, 0, 0),
                                                             -Vector3d.XAxis, Vector3d.YAxis),
                                                         m_machine_tool.Diameter / 2), m_machine_tool.Length), 4, 24));


            // Pre-move all the machine parts in place
            for (int i = 0; i < machine_part_xforms.Length; ++i)
            {
                if (meshes[i] == null)
                {
                    continue;
                }
                meshes[i].Transform(machine_part_xforms[i]);
            }

            // Global transform
            xforms[0] = Transform.PlaneToPlane(Plane.WorldXY, m_baseplane);

            // Convert point to transforms
            xforms[1] = Transform.Translation(new Vector3d(-m_point.X, 0, 0));
            xforms[2] = Transform.Translation(new Vector3d(0, -m_point.Y, 0));
            xforms[3] = Transform.Translation(new Vector3d(0, 0, m_point.Z + m_machine_tool.Length));

            // Transform machine parts
            for (int i = meshes.Length - 1; i >= 0; --i)
            {
                if (meshes[i] == null)
                {
                    continue;
                }
                for (int j = 0; j < axis_relations[i].Length; ++j)
                {
                    meshes[i].Transform(xforms[axis_relations[i][j]]);
                }
            }

            // Transform workpiece
            Transform total = G54_xform;

            for (int i = wp_relations.Length - 1; i >= 0; --i)
            {
                m_stock.Transform(xforms[wp_relations[i]]);
                m_workplane.Transform(xforms[wp_relations[i]]);
                if (tpViz != null)
                {
                    tpVizN = XFORM(tpViz, xforms[wp_relations[i]]);
                }
                total = Transform.Multiply(total, xforms[wp_relations[i]]);
            }

            DA.SetData("Path", new Polyline(tpViz.Paths.SelectMany(x => x.Select(y => y.Plane.Origin))));
            DA.SetData("Toolpath", new GH_Toolpath(tpViz));
            DA.SetData("Work offset", m_workplane);

            DA.SetData("Stock mesh", m_stock);
            DA.SetDataList("Machine meshes", meshes);
        }