示例#1
0
        static void CreateNCFile(List <Layer> layers, string outname, double unitsmultiplier, double[] focii)
        {
            STEPNCLib.AptStepMaker asm = new STEPNCLib.AptStepMaker();
            asm.NewProjectWithCCandWP(outname, 4, "Main");
            asm.Millimeters();
            int toolcount = 1;
            Dictionary <double, int> focustoolmap = new Dictionary <double, int>(); //Map focus to tools.

            foreach (double focus in focii)                                         //Make tools.
            {
                asm.DefineTool(focus, 1, 1, 1, 1, 1, 1);
                asm.SELCTLTool(toolcount);
                asm.SetToolIdentifier(Convert.ToString(toolcount), Convert.ToString(toolcount));
                //asm.ToolGeometry("ROD.stp", Convert.ToString(toolcount));
                focustoolmap[focus] = toolcount;
                toolcount++;
            }
            int i = 0;

            foreach (Layer layer in layers)
            {
                asm.NestWorkplan(String.Format("Layer {0}", i));
                foreach (GeomData operation in layer.operations)
                {
                    asm.LoadTool(focustoolmap[operation.MetaData.focus]);
                    if (operation is CLIHatches)
                    {
                        asm.Workingstep(String.Format("Layer {0} Hatching", i));
                        asm.Rapid();
                        bool       firstop = true;
                        CLIHatches tmp     = operation as CLIHatches;
                        foreach (CLIHatch hatch in tmp.hatches)
                        {
                            if (firstop)
                            {
                                asm.GoToXYZ("HatchStart", hatch.startx * unitsmultiplier, hatch.starty * unitsmultiplier, layer.height * unitsmultiplier);
                                asm.Feedrate(operation.MetaData.speed);
                                asm.SpindleSpeed(operation.MetaData.power);
                                firstop = false;
                            }
                            else
                            {
                                asm.GoToXYZ("HatchStart", hatch.startx * unitsmultiplier, hatch.starty * unitsmultiplier, layer.height * unitsmultiplier);
                            }
                            asm.GoToXYZ("HatchEnd", hatch.endx * unitsmultiplier, hatch.endy * unitsmultiplier, layer.height * unitsmultiplier);
                        }
                    }
                    if (operation is Polyline)
                    {
                        asm.Workingstep(String.Format("Layer {0} Polyline", i));
                        bool firstop = true;
                        asm.Rapid();
                        Polyline tmp = operation as Polyline;
                        for (var j = 0; j < tmp.numberofpoints; j++)
                        {
                            if (firstop)
                            {
                                asm.GoToXYZ(String.Format("PolylinePt{0}", j), tmp.points[j].x * unitsmultiplier, tmp.points[j].y * unitsmultiplier, layer.height * unitsmultiplier);
                                asm.SpindleSpeed(operation.MetaData.power);
                                asm.Feedrate(operation.MetaData.speed);
                                firstop = false;
                            }
                            else
                            {
                                asm.GoToXYZ(String.Format("PolylinePt{0}", j), tmp.points[j].x * unitsmultiplier, tmp.points[j].y * unitsmultiplier, layer.height * unitsmultiplier);
                            }
                        }
                    }
                }
                i++;
                asm.EndWorkplan();
            }
            asm.SaveAsModules(outname);
            return;
        }