//Here we update the stats void updateStats(std::istringstream& iss, stats *GCODE_stats, vector3D *currentLocation) { vector3D previousLocation = GCODE_stats->currentLocation; GCODE_stats->currentLocation = *currentLocation; GCODE_stats->movementLinesCount++; std::string s; iss >> s; if (scanString(s, "F", NULL)) { GCODE_stats->currentFeedRate = scanFloat(s, "F"); } float currentExtrudedLength = 0.f; iss >> s; if (scanString(s, "E", NULL) || scanString(s, "A", NULL)) { if (scanString(s, "E", NULL)) currentExtrudedLength = scanFloat(s, "E"); else currentExtrudedLength = scanFloat(s, "A"); GCODE_stats->extruding = (currentExtrudedLength > GCODE_stats->currentExtrudedLengthToolA); if (GCODE_stats->extruding) { //Real life test GCODE_stats->currentExtrudedLengthToolA = currentExtrudedLength; } GCODE_stats->usingToolB = false; } else if (scanString(s, "B", NULL)) { currentExtrudedLength = scanFloat(s, "B"); GCODE_stats->extruding = (currentExtrudedLength > GCODE_stats->currentExtrudedLengthToolB); if (GCODE_stats->extruding) { // Real life test GCODE_stats->currentExtrudedLengthToolB = currentExtrudedLength; } GCODE_stats->usingToolB = true; } vector3D* travelVector = new vector3D(GCODE_stats->currentLocation.x, GCODE_stats->currentLocation.y, GCODE_stats->currentLocation.z); travelVector->minus(previousLocation); float longestDistanceToMove = max(fabs(travelVector->x), fabs(travelVector->y)); // mm //printf("%f\n", longestDistanceToMove); float cartesianDistance = travelVector->getLength(); // == Calculating time taken to move or extrude == if (GCODE_stats->extruding){ // Extrusion in progress, let's calculate the time taken // NSLog(@"Extruding %f > %f", currentExtrudedLength, previousExtrudedLength); GCODE_stats->totalExtrudedDistance += cartesianDistance; // mm GCODE_stats->totalExtrudedTime += (longestDistanceToMove / (GCODE_stats->currentFeedRate * __averageAccelerationEfficiencyWhenExtruding)); // min } else { // We're only travelling, let's calculate the time taken // NSLog(@"Travelling"); GCODE_stats->totalTravelledDistance += cartesianDistance; // mm GCODE_stats->totalTravelledTime += (longestDistanceToMove / (GCODE_stats->currentFeedRate * __averageAccelerationEfficiencyWhenTravelling)); // min } }
bool Scanner::scanInt (char c, Parser& parser, bool& cont) { assert(c != '\0'); std::string value; value += c; bool error = false; while (get (c)) { if (std::isdigit (c)) { value += c; } else if (c!='-' && isStringCharacter (c)) { error = true; value += c; } else if (c=='.') { if (error) { putback (c); break; } return scanFloat (value, parser, cont); } else { putback (c); break; } } if (error) { /// workaround that allows names to begin with digits /// \todo disable TokenLoc loc (mLoc); mLoc.mLiteral.clear(); cont = parser.parseName (value, loc, *this); return true; // return false; } TokenLoc loc (mLoc); mLoc.mLiteral.clear(); std::istringstream stream (value); int intValue = 0; stream >> intValue; cont = parser.parseInt (intValue, loc, *this); return true; }
bool VTTScanner::scanPercentage(float& percentage) { Position savedPosition = getPosition(); if (!scanFloat(percentage)) return false; if (scan('%')) return true; // Restore scanner position. seekTo(savedPosition); return false; }
//Get the location in of the gcode X Y Z void updateLocation(std::istringstream& iss, vector3D *currentLocation) { std::string s; float value; iss >> s; if (scanString(s, "X", NULL)) { value = scanFloat(s, "X"); currentLocation->x = value; //printf("%f ", value); } iss >> s; if (scanString(s, "Y", NULL)) { value = scanFloat(s, "Y"); currentLocation->y = value; //printf("%f ", value); } iss >> s; if (scanString(s, "Z", NULL)) { value = scanFloat(s, "Z"); currentLocation->z = value; //printf("%f ", value); } }
bool Scanner::scanInt (char c, Parser& parser, bool& cont) { std::string value; value += c; bool empty = false; bool error = false; while (get (c)) { if (std::isdigit (c)) { value += c; empty = false; } else if (std::isalpha (c) || c=='_') error = true; else if (c=='.' && !error) { return scanFloat (value, parser, cont); } else { putback (c); break; } } if (empty || error) return false; TokenLoc loc (mLoc); mLoc.mLiteral.clear(); std::istringstream stream (value); int intValue = 0; stream >> intValue; cont = parser.parseInt (intValue, loc, *this); return true; }
bool Scanner::scanSpecial (char c, Parser& parser, bool& cont) { int special = -1; if (c=='\n') special = S_newline; else if (c=='(' || c=='[') /// \todo option to disable the use of [ as alias for ( special = S_open; else if (c==')' || c==']') /// \todo option to disable the use of ] as alias for ) special = S_close; else if (c=='.') { // check, if this starts a float literal if (get (c)) { putback (c); if (std::isdigit (c)) return scanFloat ("", parser, cont); } special = S_member; } else if (c=='=') { if (get (c)) { /// \todo hack to allow a space in comparison operators (add option to disable) if (c==' ' && !get (c)) special = S_cmpEQ; else if (c=='=') special = S_cmpEQ; else if (c == '>' || c == '<') // Treat => and =< as == { special = S_cmpEQ; mErrorHandler.warning (std::string("invalid operator =") + c + ", treating it as ==", mLoc); } else { special = S_cmpEQ; putback (c); // return false; /// Allow = as synonym for ==. \todo optionally disable for post-1.0 scripting improvements. } } else { putback (c); return false; } } else if (c=='!') { if (get (c)) { /// \todo hack to allow a space in comparison operators (add option to disable) if (c==' ' && !get (c)) return false; if (c=='=') special = S_cmpNE; else { putback (c); return false; } } else return false; } else if (c=='-') { if (get (c)) { if (c=='>') special = S_ref; else { putback (c); special = S_minus; } } else special = S_minus; } else if (static_cast<unsigned char> (c)==0xe2) { /// Workaround for some translator who apparently can't keep his minus in order /// \todo disable for later script formats if (get (c) && static_cast<unsigned char> (c)==0x80 && get (c) && static_cast<unsigned char> (c)==0x93) { if (get (c)) { if (c=='>') special = S_ref; else { putback (c); special = S_minus; } } else special = S_minus; } else { mErrorHandler.error ("Invalid character", mLoc); return false; } } else if (c=='<') { if (get (c)) { /// \todo hack to allow a space in comparison operators (add option to disable) if (c==' ' && !get (c)) special = S_cmpLT; else if (c=='=') { special = S_cmpLE; if (get (c) && c!='=') // <== is a allowed as an alternative to <= :( putback (c); } else if (c == '<' || c == '>') // Treat <> and << as < { special = S_cmpLT; mErrorHandler.warning (std::string("invalid operator <") + c + ", treating it as <", mLoc); } else { putback (c); special = S_cmpLT; } } else special = S_cmpLT; } else if (c=='>') { if (get (c)) { /// \todo hack to allow a space in comparison operators (add option to disable) if (c==' ' && !get (c)) special = S_cmpGT; else if (c=='=') { special = S_cmpGE; if (get (c) && c!='=') // >== is a allowed as an alternative to >= :( putback (c); } else if (c == '<' || c == '>') // Treat >< and >> as > { special = S_cmpGT; mErrorHandler.warning (std::string("invalid operator >") + c + ", treating it as >", mLoc); } else { putback (c); special = S_cmpGT; } } else special = S_cmpGT; } else if (c==',') special = S_comma; else if (c=='+') special = S_plus; else if (c=='*') special = S_mult; else if (c=='/') special = S_div; else return false; if (special==S_newline) mLoc.mLiteral = "<newline>"; TokenLoc loc (mLoc); mLoc.mLiteral.clear(); cont = parser.parseSpecial (special, loc, *this); return true; }
bool Scanner::scanSpecial (char c, Parser& parser, bool& cont) { int special = -1; if (c=='\n') special = S_newline; else if (c=='(') special = S_open; else if (c==')') special = S_close; else if (c=='.') { // check, if this starts a float literal if (get (c)) { putback (c); if (std::isdigit (c)) return scanFloat ("", parser, cont); } special = S_member; } else if (c=='=') { if (get (c)) { if (c=='=') special = S_cmpEQ; else { special = S_cmpEQ; putback (c); // return false; // Allow = as synonym for ==. \todo optionally disable for post-1.0 scripting improvements. } } else { putback (c); return false; } } else if (c=='!') { if (get (c)) { if (c=='=') special = S_cmpNE; else { putback (c); return false; } } else return false; } else if (c=='-') { if (get (c)) { if (c=='>') special = S_ref; else { putback (c); special = S_minus; } } else special = S_minus; } else if (c=='<') { if (get (c)) { if (c=='=') { special = S_cmpLE; if (get (c) && c!='=') // <== is a allowed as an alternative to <= :( putback (c); } else { putback (c); special = S_cmpLT; } } else special = S_cmpLT; } else if (c=='>') { if (get (c)) { if (c=='=') { special = S_cmpGE; if (get (c) && c!='=') // >== is a allowed as an alternative to >= :( putback (c); } else { putback (c); special = S_cmpGT; } } else special = S_cmpGT; } else if (c==',') special = S_comma; else if (c=='+') special = S_plus; else if (c=='*') special = S_mult; else if (c=='/') special = S_div; else return false; if (special==S_newline) mLoc.mLiteral = "<newline>"; TokenLoc loc (mLoc); mLoc.mLiteral.clear(); cont = parser.parseSpecial (special, loc, *this); return true; }