// Instructions /should/ have a parent, unless they are of type "M" public void addParent(Instruction parent) { if (this.type.ToLower().Equals ("m04")) { throw new ArgumentException ("The instruction of type M cannot be called with a parent"); } this.parent = parent; }
// Takes a string, such as "G01 X2.0000 Y1.0000", and converts // it to an instruction object public Instruction StringToInstruction(String line) { // Split on whitespace String[] pieces = line.Split (' '); Instruction i = new Instruction (); foreach (String piece in pieces) { if (piece.Length > 1) { string pieceType = piece.Substring (0, 1); double pieceValue = Double.Parse (piece.Substring (1)); switch (Char.Parse (pieceType)) { case 'M': i.setType (piece); break; case 'G': if (piece.Substring (1, 1).Equals ("-")) i.extra += piece + " "; else i.setType (piece); break; case 'X': i.setX (pieceValue); break; case 'Y': i.setY (pieceValue); break; case 'Z': i.setZ (pieceValue); break; default: i.extra += piece + " "; break; } } } return i; }
// TODO: check and instruction block for integrity public Boolean addInstruction(Instruction instruction) { this.instructions.Add (instruction); return true; }