Ejemplo n.º 1
0
        //private-----------------------------------------------------------------
        private MetaData parseMastercamAPT(Queue <string> lines)
        {
            string   line;
            Indirv   current_indirv   = new Indirv();
            Point    current_position = new Point(0.0, 0.0, 0.0);
            int      current_tool     = -1;
            MetaData metadata         = new MetaData();

            while (!lines.Peek().Contains("FINI"))//data parsing
            {
                if (lines.Peek().Contains("$$Machine Group-"))
                {
                    MachineGroup mg = new MachineGroup();
                    mg.ID = Convert.ToInt32(lines.Peek().Substring("$$Machine Group-".Length));

                    while (!lines.Peek().Contains("FINI") || (lines.Peek().Contains("$$Machine Group-") && (Convert.ToInt32(lines.Peek().Substring("$$Machine Group-".Length)) == mg.ID)))
                    {
                        lines.Dequeue();
                        ToolpathGroup tpg = new ToolpathGroup();
                        tpg.ID++;

                        while (!lines.Peek().Contains("$$Machine Group-") && !lines.Peek().Contains("FINI"))
                        {
                            line = lines.Dequeue();
                            if (line.Contains("PARTNO/"))
                            {
                                metadata.PartNo = line.Substring("PARTNO/".Length);
                                continue;
                            }

                            if (line.Contains("UNITS/"))
                            {
                                metadata.Units = line.Substring("UNITS/".Length);
                                metadata.Units = metadata.Units.Replace(" ", string.Empty);
                                continue;
                            }

                            if (line.Contains("MULTAX/"))
                            {
                                metadata.Multax = line.Substring("MULTAX/".Length);
                                metadata.Multax = metadata.Multax.Replace(" ", string.Empty);
                                continue;
                            }

                            //if (line.Contains("MACHIN/"))
                            //{
                            //    string[] substrings = Regex.Split(line.Substring("MACHIN/".Length), ",");
                            //    metadata.Machin = substrings[0].Replace(" ", string.Empty);
                            //    continue;
                            //}

                            if (line.Contains("CUTTER/"))
                            {
                                Cutter   tool       = new Cutter();
                                string[] substrings = Regex.Split(line.Substring("CUTTER/".Length), ",");
                                tool.Diameter = Convert.ToDouble(substrings[0].Replace(" ", string.Empty));
                                //tpg.tpgtool.length = Convert.ToDouble(substrings[1].Replace(" ", string.Empty));

                                line      = lines.Dequeue();
                                tool.Name = line.Substring("TPRINT/".Length);

                                line = lines.Dequeue();
                                string[] substrings2 = Regex.Split(line.Substring("LOAD/".Length), ",");
                                current_tool = tpg.Tool = tool.ID = Convert.ToInt32(substrings2[1].Replace(" ", string.Empty).Replace(".", string.Empty));

                                if (!metadata.CutterTools.ContainsKey(tool.ID))
                                {
                                    metadata.CutterTools.Add(tool.ID, tool);
                                }

                                continue;
                            }

                            if (line.Contains("RAPID"))
                            {
                                tpg.MachiningData.Add(new Rapid());
                                continue;
                            }

                            if (line.Contains("GOTO/"))
                            {
                                GoTo gotoxyz = new GoTo();
                                gotoxyz.parseGoto(line);
                                tpg.MachiningData.Add(gotoxyz);
                                current_position = gotoxyz.point;
                                continue;
                            }

                            if (line.Contains("INDIRV/"))
                            {
                                Indirv indirv = new Indirv();
                                indirv.parseIndirv(line);
                                tpg.MachiningData.Add(indirv);
                                current_indirv = indirv;
                                continue;
                            }

                            if (line.Contains("CIRCLE/"))
                            {
                                Circle circle = new Circle();
                                circle.parseCircle(current_indirv, current_position, line, lines.Dequeue(), lines.Dequeue());
                                tpg.MachiningData.Add(circle);
                                current_position = circle.endpoint;
                                continue;
                            }

                            if (line.Contains("FEDRAT/"))
                            {
                                Feedrate fedrat = new Feedrate();
                                fedrat.parseFedrat(line);
                                tpg.MachiningData.Add(fedrat);
                                continue;
                            }

                            if (line.Contains("SPINDL/"))
                            {
                                SpindleSpeed spindle = new SpindleSpeed();
                                spindle.parseSpindleSpeed(line);
                                tpg.MachiningData.Add(spindle);
                                continue;
                            }

                            if (line.Contains("COOLNT/"))
                            {
                                Coolant coolant = new Coolant();
                                coolant.parseCoolant(line);
                                tpg.MachiningData.Add(coolant);
                                continue;
                            }
                        }
                        if (tpg.Tool == -1)
                        {
                            tpg.Tool = current_tool;
                        }

                        mg.Operations.Add(tpg);     //add toolpath to list
                    }
                    metadata.MachineGroups.Add(mg); //add current machine group to list
                }
                else
                {
                    lines.Dequeue();
                }
            }
            lines.Dequeue();
            return(metadata);
        }
Ejemplo n.º 2
0
        public void WriteSTEPNC(MetaData metadata, string outname)
        {
            STEPNCLib.AptStepMaker stnc = new STEPNCLib.AptStepMaker();

            stnc.NewProjectWithCCandWP(metadata.PartNo, 1, "Main Workplan");//make new project

            if (metadata.Units == "IN" || metadata.Units == "Inches")
            {
                stnc.Inches();
            }
            else
            {
                stnc.Millimeters();
            }

            if (metadata.Multax == "ON")
            {
                stnc.MultaxOn();
            }

            Cutter[] tools = new Cutter[metadata.CutterTools.Keys.Count];
            metadata.CutterTools.Values.CopyTo(tools, 0);

            for (int i = 0; i < tools.Length; i++)//define all tools
            {
                stnc.DefineTool(tools[i].Diameter, tools[i].Diameter / 2, 10.0, 10.0, 1.0, 0.0, 45.0);
            }

            foreach (MachineGroup machineGroup in metadata.MachineGroups)
            {
                stnc.NestWorkplan("Machine Group-" + machineGroup.ID.ToString());

                foreach (ToolpathGroup toolpahtGroup in machineGroup.Operations)
                {
                    stnc.LoadTool(toolpahtGroup.Tool);//load tool associated with the current operation
                    stnc.Workingstep("WS-" + toolpahtGroup.ID.ToString());

                    foreach (MachiningData mchData in toolpahtGroup.MachiningData)
                    {
                        if (mchData is Rapid)
                        {
                            stnc.Rapid();
                        }
                        if (mchData is GoTo)
                        {
                            GoTo temp = mchData as GoTo;
                            stnc.GoToXYZ("point", temp.point.X, temp.point.Y, temp.point.Z);
                        }
                        if (mchData is Circle)
                        {
                            Circle temp = mchData as Circle;
                            stnc.ArcXYPlane("arc", temp.endpoint.X, temp.endpoint.Y, temp.endpoint.Z, temp.center.X, temp.center.Y, temp.center.Z, temp.radius, temp.direction);
                        }
                        if (mchData is Feedrate)
                        {
                            Feedrate temp = mchData as Feedrate;
                            stnc.Feedrate(temp.Fedrat);
                        }
                        if (mchData is SpindleSpeed)
                        {
                            SpindleSpeed temp = mchData as SpindleSpeed;
                            stnc.SpindleSpeed(temp.Spindlespeed);
                        }
                        if (mchData is Coolant)
                        {
                            Coolant temp = mchData as Coolant;
                            if (temp.activation)
                            {
                                stnc.CoolantOn();
                            }
                            else
                            {
                                stnc.CoolantOff();
                            }
                        }
                    }
                }
                stnc.EndWorkplan();
            }
            stnc.SaveAsP21(outname);
            return;
        }