Example #1
0
 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();
 }
Example #2
0
 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)
                 {
                     eChanged = code.e != 0;
                     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)
                     { eChanged = code.e != 0; e += code.e; }
                     else
                     {
                         eChanged = e != (eOffset + code.e);
                         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;
     code.emax = emax;
 }
Example #3
0
 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();
 }
Example #4
0
 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();
 }
Example #5
0
 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();
 }
Example #6
0
 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();
 }
Example #7
0
        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)
                    {
                        eChanged = code.e != 0;
                        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)
                        {
                            eChanged = code.e != 0; e += code.e;
                        }
                        else
                        {
                            eChanged = e != (eOffset + code.e);
                            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;
            code.emax  = emax;
        }