public void analyzeShort(GCodeShort code) { isG1Move = false; switch (code.compressedCommand) { case 1: isG1Move = true; if (code.hasF) { f = code.f; } if (relative) { if (code.hasX) { x += code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.hasY) { y += code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.hasZ) { z += code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.hasE) { e += code.e; if (e > emax) { emax = e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } } else { if (code.x != -99999) { x = xOffset + code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.y != -99999) { y = yOffset + code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.z != -99999) { z = zOffset + code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.e != -99999) { if (eRelative) { e += code.e; } else { e = eOffset + code.e; } if (e > emax) { emax = e; if (z != lastZPrint) { lastZPrint = z; layer++; } } } } if (eventPosChangedFast != null) { eventPosChangedFast(x, y, z, e); } float dx = Math.Abs(x - lastX); float dy = Math.Abs(y - lastY); float dz = Math.Abs(z - lastZ); float de = Math.Abs(e - lastE); if (dx + dy + dz > 0.001) { printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f; } else { printingTime += de * 60.0f / f; } lastX = x; lastY = y; lastZ = z; lastE = e; break; case 4: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XHomePos; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YHomePos; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.ZHomePos; hasZHome = true; } if (code.hasE) { eOffset = 0; e = 0; emax = 0; } // [delegate positionChangedFastX:x y:y z:z e:e]; } break; case 5: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XMax; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YMax; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; } //[delegate positionChangedFastX:x y:y z:z e:e]; } break; case 6: relative = false; break; case 7: relative = true; break; case 8: if (code.hasX) { xOffset = x - code.x; x = xOffset; } if (code.hasY) { yOffset = y - code.y; y = yOffset; } if (code.hasZ) { zOffset = z - code.z; z = zOffset; } if (code.hasE) { eOffset = e - code.e; lastE = e = eOffset; } break; case 12: // Host command { string hc = code.text.Trim(); if (hc == "@hide") { drawing = false; } else if (hc == "@show") { drawing = true; } else if (hc == "@isathome") { hasXHome = hasYHome = hasZHome = true; x = xOffset = Main.printerSettings.XHomePos; y = yOffset = Main.printerSettings.YHomePos; z = zOffset = Main.printerSettings.ZHomePos; } } break; case 9: eRelative = false; break; case 10: eRelative = true; break; case 11: activeExtruder = code.tool; break; } code.layer = layer; code.tool = activeExtruder; }
public void DeleteSelection(bool redraw) { int rstart = row; int cstart = col; int rend = selRow; int cend = selCol; if (row > selRow || (row == selRow && col > selCol)) { rstart = selRow; cstart = selCol; rend = row; cend = col; } cstart = Math.Min(cstart, lines[rstart].Length); cend = Math.Min(cend, lines[rend].Length); cur.AddUndo(new Undo(UndoAction.ReplaceSelection, "", getSelection(), col, row, selCol, selRow)); // start row = begin first + end last row lines[rstart] = new GCodeShort(lines[rstart].text.Substring(0, cstart) + lines[rend].text.Substring(cend)); if(rend>rstart) lines.RemoveRange(rstart + 1, rend - rstart); row = selRow = rstart; col = selCol = cstart; if (lines.Count == 0) Clear(); if (redraw) PositionShowCursor(true, false); Changed(); }
public void analyzeShort(GCodeShort code) { isG1Move = false; switch (code.compressedCommand) { case 1: isG1Move = true; eChanged = false; if (code.hasF) f = code.f; if (relative) { if (code.hasX) { x += code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.hasY) { y += code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.hasZ) { z += code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.hasE) { if (eChanged = code.e != 0) { if (code.e < 0) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; } else activeExtruder.e += code.e; if (activeExtruder.e > activeExtruder.emax) { activeExtruder.emax = activeExtruder.e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } } } else { if (code.x != -99999) { x = xOffset + code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.y != -99999) { y = yOffset + code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.z != -99999) { z = zOffset + code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.e != -99999) { if (eRelative) { if (eChanged = code.e != 0) { if (code.e < 0) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; } else activeExtruder.e += code.e; } } else { if (eChanged = activeExtruder.e != (activeExtruder.eOffset + code.e)) { activeExtruder.e = activeExtruder.eOffset + code.e; if (activeExtruder.e < activeExtruder.lastE) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; activeExtruder.eOffset = activeExtruder.e - code.e; } } } if (activeExtruder.e > activeExtruder.emax) { activeExtruder.emax = activeExtruder.e; if (z != lastZPrint) { lastZPrint = z; layer++; } } } } if (eventPosChangedFast != null) eventPosChangedFast(x, y, z, activeExtruder.e); float dx = Math.Abs(x - lastX); float dy = Math.Abs(y - lastY); float dz = Math.Abs(z - lastZ); float de = Math.Abs(activeExtruder.e - activeExtruder.lastE); if (dx + dy + dz > 0.001) { printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f; } else printingTime += de * 60.0f / f; lastX = x; lastY = y; lastZ = z; activeExtruder.lastE = activeExtruder.e; break; case 2: case 3: { isG1Move = true; eChanged = false; if (code.hasF) f = code.f; if (relative) { if (code.hasX) { x += code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.hasY) { y += code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.hasZ) { z += code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.hasE) { if (eChanged = code.e != 0) { if (code.e < 0) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; } else activeExtruder.e += code.e; if (activeExtruder.e > activeExtruder.emax) { activeExtruder.emax = activeExtruder.e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } } } else { if (code.x != -99999) { x = xOffset + code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.y != -99999) { y = yOffset + code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.z != -99999) { z = zOffset + code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.e != -99999) { if (eRelative) { if (eChanged = code.e != 0) { if (code.e < 0) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; } else activeExtruder.e += code.e; } } else { if (eChanged = activeExtruder.e != (activeExtruder.eOffset + code.e)) { activeExtruder.e = activeExtruder.eOffset + code.e; if (activeExtruder.e < activeExtruder.lastE) activeExtruder.retracted = true; else if (activeExtruder.retracted) { activeExtruder.retracted = false; activeExtruder.e = activeExtruder.emax; activeExtruder.eOffset = activeExtruder.e - code.e; } } } } } float[] offset = new float[] { code.getValueFor("I", 0), code.getValueFor("J", 0) }; /* if(unit_inches) { offset[0]*=25.4; offset[1]*=25.4; }*/ float[] position = new float[] { lastX, lastY }; float[] target = new float[] { x, y }; float r = code.getValueFor("R", -1000000); if (r > 0) { /* We need to calculate the center of the circle that has the designated radius and passes through both the current position and the target position. This method calculates the following set of equations where [x,y] is the vector from current to target position, d == magnitude of that vector, h == hypotenuse of the triangle formed by the radius of the circle, the distance to the center of the travel vector. A vector perpendicular to the travel vector [-y,x] is scaled to the length of h [-y/d*h, x/d*h] and added to the center of the travel vector [x/2,y/2] to form the new point [i,j] at [x/2-y/d*h, y/2+x/d*h] which will be the center of our arc. d^2 == x^2 + y^2 h^2 == r^2 - (d/2)^2 i == x/2 - y/d*h j == y/2 + x/d*h O <- [i,j] - | r - | - | - | h - | [0,0] -> C -----------------+--------------- T <- [x,y] | <------ d/2 ---->| C - Current position T - Target position O - center of circle that pass through both C and T d - distance from C to T r - designated radius h - distance from center of CT to O Expanding the equations: d -> sqrt(x^2 + y^2) h -> sqrt(4 * r^2 - x^2 - y^2)/2 i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2 j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2 Which can be written: i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2 j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2 Which we for size and speed reasons optimize to: h_x2_div_d = sqrt(4 * r^2 - x^2 - y^2)/sqrt(x^2 + y^2) i = (x - (y * h_x2_div_d))/2 j = (y + (x * h_x2_div_d))/2 */ //if(unit_inches) r*=25.4; // Calculate the change in position along each selected axis float cx = target[0] - position[0]; float cy = target[1] - position[1]; float h_x2_div_d = -(float)Math.Sqrt(4 * r * r - cx * cx - cy * cy) / (float)Math.Sqrt(cx * cx + cy * cy); // == -(h * 2 / d) // If r is smaller than d, the arc is now traversing the complex plane beyond the reach of any // real CNC, and thus - for practical reasons - we will terminate promptly: // if(isnan(h_x2_div_d)) { OUT_P_LN("error: Invalid arc"); break; } // Invert the sign of h_x2_div_d if the circle is counter clockwise (see sketch below) if (code.compressedCommand == 3) { h_x2_div_d = -h_x2_div_d; } /* The counter clockwise circle lies to the left of the target direction. When offset is positive, the left hand circle will be generated - when it is negative the right hand circle is generated. T <-- Target position ^ Clockwise circles with this center | Clockwise circles with this center will have will have > 180 deg of angular travel | < 180 deg of angular travel, which is a good thing! \ | / center of arc when h_x2_div_d is positive -> x <----- | -----> x <- center of arc when h_x2_div_d is negative | | C <-- Current position */ // Negative R is g-code-alese for "I want a circle with more than 180 degrees of travel" (go figure!), // even though it is advised against ever generating such circles in a single line of g-code. By // inverting the sign of h_x2_div_d the center of the circles is placed on the opposite side of the line of // travel and thus we get the unadvisably long arcs as prescribed. if (r < 0) { h_x2_div_d = -h_x2_div_d; r = -r; // Finished with r. Set to positive for mc_arc } // Complete the operation by calculating the actual center of the arc offset[0] = 0.5f * (cx - (cy * h_x2_div_d)); offset[1] = 0.5f * (cy + (cx * h_x2_div_d)); } else { // Offset mode specific computations r = (float)Math.Sqrt(offset[0] * offset[0] + offset[1] * offset[1]); // Compute arc radius for mc_arc } // Set clockwise/counter-clockwise sign for mc_arc computations bool isclockwise = code.compressedCommand == 2; // Trace the arc arc(position, target, offset, r, isclockwise,null); lastX = x; lastY = y; lastZ = z; activeExtruder.lastE = activeExtruder.e; if (activeExtruder.e > activeExtruder.emax) { activeExtruder.emax = activeExtruder.e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } break; case 4: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XHomePos; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YHomePos; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.ZHomePos; hasZHome = true; } if (code.hasE) { activeExtruder.eOffset = 0; activeExtruder.e = 0; activeExtruder.emax = 0; } // [delegate positionChangedFastX:x y:y z:z e:e]; } break; case 5: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.XMax; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.YMax; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; } //[delegate positionChangedFastX:x y:y z:z e:e]; } break; case 6: relative = false; break; case 7: relative = true; break; case 8: if (code.hasX) { xOffset = x - code.x; x = xOffset; } if (code.hasY) { yOffset = y - code.y; y = yOffset; } if (code.hasZ) { zOffset = z - code.z; z = zOffset; } if (code.hasE) { activeExtruder.eOffset = activeExtruder.e - code.e; activeExtruder.lastE = activeExtruder.e = activeExtruder.eOffset; } break; case 12: // Host command { string hc = code.text.Trim(); if (hc == "@hide") drawing = false; else if (hc == "@show") drawing = true; else if (hc == "@isathome") { hasXHome = hasYHome = hasZHome = true; x = xOffset = Main.printerSettings.XHomePos; y = yOffset = Main.printerSettings.YHomePos; z = zOffset = Main.printerSettings.ZHomePos; } } break; case 9: eRelative = false; break; case 10: eRelative = true; break; case 11: activeExtruderId = code.tool; if (!extruder.ContainsKey(activeExtruderId)) extruder.Add(activeExtruderId, new ExtruderData(activeExtruderId)); activeExtruder = extruder[activeExtruderId]; break; } if (layer != lastlayer) { foreach (GCodeShort c in unchangedLayer) { c.layer = layer; } unchangedLayer.Clear(); layerZ = z; lastlayer = layer; } else if (z != layerZ) unchangedLayer.AddLast(code); code.layer = layer; code.tool = activeExtruderId; code.emax = totalFilamentUsed(); }
public void Backspace() { string t = lines[row].text; if (col > t.Length) { col = t.Length; } else if (col==0) { // Join with next line if (row == 0) return; cur.AddUndo(new Undo(UndoAction.ReplaceSelection, "", "\n", col, row, lines[row-1].Length, row -1)); col = lines[row-1].Length; lines[row - 1] = new GCodeShort(lines[row - 1].text+lines[row].text); lines.RemoveAt(row); row--; } else { cur.AddUndo(new Undo(UndoAction.ReplaceSelection, "", t.Substring(col-1, 1), col, row, col -1, row)); lines[row] = new GCodeShort(t.Substring(0, col-1) + t.Substring(col )); CursorLeft(); } PositionShowCursor(true, false); Changed(); }
public void DeleteChar() { string t = lines[row].text; if (t.Length == col) { // Join with next line if (row == lines.Count - 1) return; lines[row] = new GCodeShort(lines[row].text+lines[row + 1].text); lines.RemoveAt(row + 1); cur.AddUndo(new Undo(UndoAction.ReplaceSelection,"","\n",col,row,0,row+1)); } else { cur.AddUndo(new Undo(UndoAction.ReplaceSelection,"",t.Substring(col,1),col,row,col+1,row)); lines[row] = new GCodeShort(t.Substring(0, col) + t.Substring(col + 1)); } editor.Invalidate(); Changed(); }
private void InsertString(string s) { cur.AddUndo(new Undo(UndoAction.ReplaceSelection,s,getSelection(),col,row,selCol,selRow)); if (hasSelection) DeleteSelection(false); s = s.Replace("\r\n", "\n"); s = s.Replace('\r', '\n'); string[] la = s.Split('\n'); string l = lines[row].text; if (col > l.Length) col = l.Length; la[0] = l.Substring(0, col) + la[0]; int nc = la[la.Length - 1].Length; la[la.Length - 1] = la[la.Length - 1] + l.Substring(col); col = nc; lines[row] = new GCodeShort(la[0]); string[] la2 = new string[la.Length - 1]; for (int i = 1; i < la.Length; i++) { la2[i - 1] = la[i]; } for (int i = 0; i < la2.Length; i++) lines.Insert(row + 1 + i, new GCodeShort(la2[i])); row += la.Length - 1; PositionShowCursor(true,false); Changed(); }
private void InsertChar(char c) { cur.AddUndo(new Undo(UndoAction.ReplaceSelection, c.ToString(), getSelection(), col, row, selCol, selRow)); if (hasSelection) DeleteSelection(false); string l = lines[row].text; if(col>l.Length) col = l.Length; if(_overwrite && col < l.Length) lines[row] = new GCodeShort(l.Substring(0, col) + c.ToString() + l.Substring(col+1)); else lines[row] = new GCodeShort(l.Substring(0,col)+c.ToString()+l.Substring(col)); col++; PositionShowCursor(true, false); Changed(); }
public void analyzeShort(GCodeShort code) { isG1Move = false; switch (code.compressedCommand) { case 1: isG1Move = true; if (code.hasF) f = code.f; if (relative) { if (code.hasX) { x += code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.hasY) { y += code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.hasZ) { z += code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.hasE) { e += code.e; if (e > emax) { emax = e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } } else { if (code.x != -99999) { x = xOffset + code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.y != -99999) { y = yOffset + code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.z != -99999) { z = zOffset + code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.e != -99999) { if (eRelative) e += code.e; else e = eOffset + code.e; if (e > emax) { emax = e; if (z > lastZPrint) { lastZPrint = z; layer++; } } } } if(eventPosChangedFast!=null) eventPosChangedFast(x, y, z, e); float dx = Math.Abs(x - lastX); float dy = Math.Abs(y - lastY); float dz = Math.Abs(z - lastZ); float de = Math.Abs(e - lastE); if (dx + dy + dz > 0.001) { printingTime += Math.Sqrt(dx * dx + dy * dy + dz * dz) * 60.0f / f; } else printingTime += de * 60.0f / f; lastX = x; lastY = y; lastZ = z; lastE = e; break; case 4: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = 0; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = 0; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = 0; hasZHome = true; } if (code.hasE) { eOffset = 0; e = 0; emax = 0; } // [delegate positionChangedFastX:x y:y z:z e:e]; } break; case 5: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; } //[delegate positionChangedFastX:x y:y z:z e:e]; } break; case 6: relative = false; break; case 7: relative = true; break; case 8: if (code.hasX) { xOffset = x - code.x; x = xOffset; } if (code.hasY) { yOffset = y - code.y; y = yOffset; } if (code.hasZ) { zOffset = z - code.z; z = zOffset; } if (code.hasE) { eOffset = e - code.e; lastE = e = eOffset; } break; case 12: // Host command { string hc = code.text.Trim(); if (hc == "@hide") drawing = false; else if (hc == "@show") drawing = true; else if (hc == "@isathome") { hasXHome = hasYHome = hasZHome = true; x = xOffset = 0; y = yOffset = 0; z = zOffset = 0; } } break; case 9: eRelative = false; break; case 10: eRelative = true; break; case 11: activeExtruder = code.tool; break; } code.layer = layer; code.tool = activeExtruder; }
private void DrawRow(Graphics g, int line, GCodeShort code, float x, float y) { string text = code.text; float s1 = 0, s2 = 0; g.FillRectangle(((line & 1)==0?backBrush:evenBackBrush), linesWidth, y, editor.Width - linesWidth, fontHeight); string ln = line.ToString(); line--; int minc=-1, maxc=-1; if (line >= Math.Min(row, selRow) && line <= Math.Max(row, selRow)) { // mark selection if(row<selRow || (row==selRow && col<selCol)) { minc = col;maxc=selCol; } else { minc = selCol;maxc=col; } if (line > Math.Min(row, selRow)) { minc = 0; s1 = linesWidth; } else s1 = linesWidth + minc * fontWidth; if (line < Math.Max(row, selRow)) { s2 = editor.Width; maxc = 10000; } else s2 = linesWidth + maxc * fontWidth; g.FillRectangle(selectionBrush, s1, y, s2 - s1, fontHeight); } string comment = ""; string command = ""; string parameter = ""; float ps = linesWidth + x; int i,ac=0; if (text.StartsWith("@")) { for (i = 0; i < text.Length; i++) { g.DrawString(text[i].ToString(), drawFont,(ac >=minc && ac<maxc ? selectionTextColor : hostBrush), ps, y); ac++; ps += fontWidth; } text = ""; } int p = text.IndexOf(';'); if (p != -1) { comment = text.Substring(p); text = text.Substring(0, p); } p = text.IndexOf(' '); if (p == -1) { command = text; } else { parameter = text.Substring(p); command = text.Substring(0, p); } if (command.Length > 0) { for (i = 0; i < command.Length; i++) { g.DrawString(command[i].ToString(), drawFont, (ac >=minc && ac<maxc ? selectionTextColor :commandBrush), ps, y); ps += fontWidth; ac++; } } if (parameter.Length > 0) { for (i = 0; i < parameter.Length; i++) { char c = parameter[i]; if((c>='A' && c<='Z') || (c>='a' && c<='z')) g.DrawString(c.ToString(), drawFont,(ac >=minc && ac<maxc ? selectionTextColor : paramTypeBrush), ps, y); else g.DrawString(c.ToString(), drawFont, (ac >=minc && ac<maxc ? selectionTextColor :blackBrush), ps, y); ps += fontWidth; ac++; } } if (comment.Length > 0) { for (i = 0; i < comment.Length; i++) { g.DrawString(comment[i].ToString(), drawFont,(ac >=minc && ac<maxc ? selectionTextColor : commentBrush), ps, y); ps += fontWidth; ac++; } } if((code.layer & 1)==0) g.FillRectangle(linesBgColor, 0, y, linesWidth, fontHeight); else g.FillRectangle(linesBgAltColor, 0, y, linesWidth, fontHeight); g.DrawString(ln, drawFont, linesTextColor, linesWidth - 3 - fontWidth * ln.Length, y); PositionCursor(); }
public void analyzeShort(GCodeShort code) { isG1Move = false; switch (code.compressedCommand) { case 1: isG1Move = true; if (relative) { if (code.hasX) { x += code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.hasY) { y += code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.hasZ) { if (code.z != 0) layer++; z += code.z; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.hasE) { e += code.e; if (e > emax) emax = e; } } else { if (code.x != -99999) { x = xOffset + code.x; //if (x < 0) { x = 0; hasXHome = NO; } //if (x > printerWidth) { hasXHome = NO; } } if (code.y != -99999) { y = yOffset + code.y; //if (y < 0) { y = 0; hasYHome = NO; } //if (y > printerDepth) { hasYHome = NO; } } if (code.z != -99999) { float lastz = z; z = zOffset + code.z; if (z != lastz) layer++; //if (z < 0) { z = 0; hasZHome = NO; } //if (z > printerHeight) { hasZHome = NO; } } if (code.e != -99999) { if (eRelative) e += code.e; else e = eOffset + code.e; if (e > emax) emax = e; } } if(eventPosChangedFast!=null) eventPosChangedFast(x, y, z, e); break; case 4: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = 0; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = 0; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = 0; hasZHome = true; } if (code.hasE) { eOffset = 0; e = 0; emax = 0; } // [delegate positionChangedFastX:x y:y z:z e:e]; } break; case 5: { bool homeAll = !(code.hasX || code.hasY || code.hasZ); if (code.hasX || homeAll) { xOffset = 0; x = Main.printerSettings.PrintAreaWidth; hasXHome = true; } if (code.hasY || homeAll) { yOffset = 0; y = Main.printerSettings.PrintAreaDepth; hasYHome = true; } if (code.hasZ || homeAll) { zOffset = 0; z = Main.printerSettings.PrintAreaHeight; hasZHome = true; } //[delegate positionChangedFastX:x y:y z:z e:e]; } break; case 6: relative = false; break; case 7: relative = true; break; case 8: if (code.hasX) { xOffset = x - code.x; x = xOffset; } if (code.hasY) { yOffset = y - code.y; y = yOffset; } if (code.hasZ) { zOffset = z - code.z; z = zOffset; } if (code.hasE) { eOffset = e - code.e; e = eOffset; } break; case 12: // Host command { string hc = code.text.Trim(); if (hc == "@hide") drawing = false; else if (hc == "@show") drawing = true; else if (hc == "@isathome") { hasXHome = hasYHome = hasZHome = true; x = xOffset = 0; y = yOffset = 0; z = zOffset = 0; } } break; case 9: eRelative = false; break; case 10: eRelative = true; break; case 11: activeExtruder = code.tool; break; } code.layer = layer; code.tool = activeExtruder; }