public SubProgram(string name, Coordinate origen, int size, int color, SectionOptions options) : base(origen, color) { Content = new FileCoordinateObject[size]; Name = name; Program = options.ProgramType; InitializeNull = options.InitializeNull; InnerSection = options.InnerSection; MadeByProgram = options.MadeByProgram; }
private FileObject HandleCommand(CommandRef command) { FileObject result = new FileObject(); try { command.Line = command.Line.Substring(command.Line.IndexOf(command.Reference)); command.Line = command.Line.Replace(" ", ""); switch (command.Command) { case Commands.NONE: break; case Commands.LINE: { //PenDown = (command.Reference == "G0" || command.Reference == "G00") ? false : true; string[] args = MakeArguments(command); double[] coords = Array.ConvertAll(command.Line.Split(args, StringSplitOptions.RemoveEmptyEntries), double.Parse); for (int i = 0; i < coords.Length; i++) { coords[i] = coords[i] / Scaling; } Coordinate origen = UseOldCoordinates(coords, args)[0]; if (args.Contains("Z")) { Depth = coords[Array.IndexOf(args, "Z") - 1]; } if (RelativeMode && !Statements.IsNull(origen)) { origen += OldOrigen; } if (PenDown && !Statements.IsNull(origen)) { result = new Line(OldOrigen, origen, Color, Depth); TotalDistanceDrawn += AddDistance((Line)result); } else { result = new FileObject(); TotalDistanceBridge += AddDistance(new Line(OldOrigen, origen, Color, Depth)); } if (origen != null) { OldOrigen = origen; OldArcCentre = origen; } break; } case Commands.ARC: { string[] args = MakeArguments(command); double[] coords = Array.ConvertAll(command.Line.Split(args, StringSplitOptions.RemoveEmptyEntries), double.Parse); for (int i = 0; i < coords.Length; i++) { coords[i] = coords[i] / Scaling; } Coordinate[] coordinates = UseOldCoordinates(coords, args); Coordinate origen = coordinates[0]; Coordinate distance = coordinates[1]; if (RelativeMode) { origen += OldOrigen; } if (Module_Main.RelativeArc) { if (!Statements.IsNull(distance) && !Statements.IsNull(OldArcCentre) && !Statements.IsNull(OldOrigen)) { if (distance.X == OldArcCentre.X && distance.Y != OldArcCentre.Y) { distance.Y += OldOrigen.Y; } else if (distance.X != OldArcCentre.X && distance.Y == OldArcCentre.Y) { distance.X += OldOrigen.X; } else { distance += OldOrigen; } } } if (PenDown) { if (command.Reference != "G02" && command.Reference != "G2") { result = new Arc(OldOrigen, origen, distance, Color, false, Depth); } else { result = new Arc(OldOrigen, origen, distance, Color, true, Depth); } TotalDistanceDrawn += AddDistance((Arc)result); } else { result = new FileObject(); } OldOrigen = origen; OldArcCentre = distance; break; } case Commands.SUBPROG: { if (CurrentProgram != null && CurrentProgram.MadeByProgram) { Programs.Add(CurrentProgram); } if (!Statements.IsNull(CurrentProgram)) { if (!CurrentProgram.ContainsContent()) { break; } } if (Programs.Contains(CurrentProgram)) { break; } if (command.Reference.Contains("DFS,PC")) { result = new SubProgram("C" + SubCounter, new Coordinate(0, 0), 0, new SectionOptions(SubPrograms.BOX, true, true, true)); CurrentProgram = (SubProgram)result; break; } int[] indexs = ObjHndlr.GetSubIndexs(Lines, Index); int size = indexs[1] - indexs[0]; int section = ObjHndlr.GetSection(command.Line); string name = section.ToString(); if (section <= 0) { name = "MAIN"; } SectionOptions options = new SectionOptions(); if (section > ObjHndlr.LastSubIndex && MainFound) { result = new FileObject(); break; } if (!MainFound) { options = new SectionOptions(SubPrograms.BOX, false, false, false); } else if (ObjHndlr.IsLastSub(section) && section > 2) { options = new SectionOptions(SubPrograms.BOX, true, true, false); } else { options = new SectionOptions(SubPrograms.SECTION, false, false, false); } result = new SubProgram(name, new Coordinate(0, 0), size, Color, options); if (!SubAlreadyExists((SubProgram)result)) { CurrentProgram = (SubProgram)result; } else { result = new FileObject(); } OldOrigen = new Coordinate(0, 0); OldArcCentre = new Coordinate(0, 0); break; } case Commands.SUBEND: { if (CurrentProgram.ContainsCoordinates() && CurrentProgram.Program == SubPrograms.BOX) { CurrentProgram.InnerSection = true; CurrentProgram.InitializeNull = true; } if (CurrentProgram != null) { Programs.Add(CurrentProgram); } if (command.Line != "CLOSEDBYPROGRAM") { MainNotClosed = false; } CurrentProgram = null; break; } case Commands.SUBCALL: { int section = int.Parse(command.Line.Substring(command.Line.IndexOf(command.Reference) + command.Reference.Length)); if (ObjHndlr.IsLastSub(section) || section > ObjHndlr.LastSubIndex) { result = new FileObject(); } else { result = new SubCall(section, OldOrigen); } MainProgram.AddContent((SubCall)result); SubCalled = true; result = null; break; } case Commands.ABSOLUTE: { RelativeMode = false; break; } case Commands.RELATIVE: { RelativeMode = true; break; } case Commands.TOOL: { int temp = 0; if (int.TryParse(command.Line.Substring(command.Line.IndexOf(command.Reference) + command.Reference.Length), out temp)) { Color = temp; } else { for (int i = 0; i < command.Line.Length - command.Reference.Length; i++) { string s = command.Line.Substring(command.Reference.Length, i); if (!int.TryParse(s, out temp)) { if (i > 0) { if (int.TryParse(command.Line.Substring(command.Reference.Length, i - 1), out temp)) { Color = int.Parse(command.Line.Substring(command.Reference.Length, i - 1)); break; } } } } } break; } case Commands.ON: { PenDown = true; break; } case Commands.OFF: { PenDown = false; break; } default: break; } if (result.GetType().IsSubclassOf(typeof(FileCoordinateObject)) && result.GetType() != typeof(SubProgram) && Statements.IsNull(CurrentProgram)) { NoSubClause(); } } catch (Exception e) { ErrorHandler.AddMessage(e, Index + " | " + Lines[Index]); result = new FileObject(); } return(result); }
public SubProgram(string name, Coordinate origen, int color, SectionOptions options) : this(name, origen, 1000, color, options) { }