Exemple #1
0
        public void stats()
        {
            PrinterConnection.logInfo("Path segments:" + segments.Count.ToString());
            int pts = 0;

            foreach (GCodePath p in segments)
            {
                pts += p.pointsCount;
            }
            PrinterConnection.logInfo("Points total:" + pts.ToString());
        }
        public void Analyze(GCode code)
        {
            if (code.hostCommand)
            {
                string cmd = code.getHostCommand();
                if (cmd.Equals("@hide"))
                {
                    drawing = false;
                }
                else if (cmd.Equals("@show"))
                {
                    drawing = true;
                }
                else if (cmd.Equals("@isathome"))
                {
                    hasXHome = hasYHome = hasZHome = true;
                    x        = Main.printerSettings.XHomePos;
                    y        = Main.printerSettings.YHomePos;
                    z        = Main.printerSettings.ZHomePos;
                    xOffset  = yOffset = zOffset = 0;
                }
                return;
            }
            //if (code.forceAscii) return; // Don't analyse host commands and unknown commands
            if (code.hasN)
            {
                lastline = code.N;
            }
            if (uploading && !code.hasM && code.M != 29)
            {
                return;                                          // ignore upload commands
            }
            if (code.hasG)
            {
                switch (code.G)
                {
                case 0:
                case 1:
                    if (code.hasF)
                    {
                        f = code.F;
                    }
                    if (relative)
                    {
                        if (code.hasX)
                        {
                            x += code.X;
                        }
                        if (code.hasY)
                        {
                            y += code.Y;
                        }
                        if (code.hasZ)
                        {
                            z += code.Z;
                        }
                        if (code.hasE)
                        {
                            e += code.E;
                        }
                    }
                    else
                    {
                        if (code.hasX)
                        {
                            x = xOffset + code.X;
                        }
                        if (code.hasY)
                        {
                            y = yOffset + code.Y;
                        }
                        if (code.hasZ)
                        {
                            z = zOffset + code.Z;
                        }
                        if (code.hasE)
                        {
                            if (eRelative)
                            {
                                e += code.E;
                            }
                            else
                            {
                                e = eOffset + code.E;
                            }
                        }
                    }
                    if (x < Main.printerSettings.XMin)
                    {
                        x = Main.printerSettings.XMin; hasXHome = false;
                    }
                    if (y < Main.printerSettings.YMin)
                    {
                        y = Main.printerSettings.YMin; hasYHome = false;
                    }
                    if (z < 0)
                    {
                        z = 0; hasZHome = false;
                    }
                    if (x > Main.printerSettings.XMax)
                    {
                        hasXHome = false;
                    }
                    if (y > Main.printerSettings.YMax)
                    {
                        hasYHome = false;
                    }
                    if (z > printerHeight)
                    {
                        hasZHome = false;
                    }
                    if (e > emax)
                    {
                        emax = e;
                        if (z != lastZPrint)
                        {
                            layer++;
                            lastZPrint = z;
                            if (!privateAnalyzer && Main.conn.job.hasData() && Main.conn.job.maxLayer >= 0)
                            {
                                //PrinterConnection.logInfo("Printing layer " + layer.ToString() + " of " + Main.conn.job.maxLayer.ToString());
                                PrinterConnection.logInfo(Trans.T2("L_PRINTING_LAYER_X_OF_Y", layer.ToString(), Main.conn.job.maxLayer.ToString()));
                            }
                        }
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    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 28:
                case 161:
                {
                    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;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 162:
                {
                    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;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                }
                break;

                case 90:
                    relative = false;
                    break;

                case 91:
                    relative = true;
                    break;

                case 92:
                    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;
                    }
                    if (eventPosChanged != null)
                    {
                        if (privateAnalyzer)
                        {
                            eventPosChanged(code, x, y, z);
                        }
                        else
                        {
                            Main.main.Invoke(eventPosChanged, code, x, y, z);
                        }
                    }
                    break;
                }
            }
            else if (code.hasM)
            {
                switch (code.M)
                {
                case 28:
                    uploading = true;
                    break;

                case 29:
                    uploading = false;
                    break;

                case 80:
                    powerOn = true;
                    fireChanged();
                    break;

                case 81:
                    powerOn = false;
                    fireChanged();
                    break;

                case 82:
                    eRelative = false;
                    break;

                case 83:
                    eRelative = true;
                    break;

                case 104:
                case 109:
                    if (code.hasS)
                    {
                        extruderTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 106:
                    fanOn = true;
                    if (code.hasS)
                    {
                        fanVoltage = code.S;
                    }
                    fireChanged();
                    break;

                case 107:
                    fanOn = false;
                    fireChanged();
                    break;

                case 110:
                    lastline = code.N;
                    break;

                case 111:
                    if (code.hasS)
                    {
                        debugLevel = code.S;
                    }
                    break;

                case 140:
                case 190:
                    if (code.hasS)
                    {
                        bedTemp = code.S;
                    }
                    fireChanged();
                    break;

                case 203:     // Temp monitor
                    if (code.hasS)
                    {
                        tempMonitor = code.S;
                    }
                    break;

                case 220:
                    if (code.hasS)
                    {
                        speedMultiply = code.S;
                    }
                    break;
                }
            }
            else if (code.hasT)
            {
                activeExtruder = code.T;
            }
        }