string Player::getDescription(string command, string object){ string roomDesc=""; string checker = currentLocation()->listItem()->listAllDesc(); if((command=="LOOK"||command=="OBSERVE")&&(object=="ROOM"||object=="")) roomDesc = currentLocation()->shortDescript() + " " + currentLocation()->longDescript(); else{ roomDesc = currentLocation()->shortDescript(); } roomDesc += "\n\n " + checker; return roomDesc; }
TokenInfo getNextToken() { consumeWhitespace(); TokenInfo Result; Result.Range.Start = currentLocation(); if (Code.empty()) { Result.Kind = TokenInfo::TK_Eof; Result.Text = ""; return Result; } switch (Code[0]) { case ',': Result.Kind = TokenInfo::TK_Comma; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case '(': Result.Kind = TokenInfo::TK_OpenParen; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case ')': Result.Kind = TokenInfo::TK_CloseParen; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case '"': case '\'': // Parse a string literal. consumeStringLiteral(&Result); break; default: if (isAlphanumeric(Code[0])) { // Parse an identifier size_t TokenLength = 1; while (TokenLength < Code.size() && isAlphanumeric(Code[TokenLength])) ++TokenLength; Result.Kind = TokenInfo::TK_Ident; Result.Text = Code.substr(0, TokenLength); Code = Code.drop_front(TokenLength); } else { Result.Kind = TokenInfo::TK_InvalidChar; Result.Text = Code.substr(0, 1); Code = Code.drop_front(1); } break; } Result.Range.End = currentLocation(); return Result; }
/// \brief Consume a string literal. /// /// \c Code must be positioned at the start of the literal (the opening /// quote). Consumed until it finds the same closing quote character. void consumeStringLiteral(TokenInfo *Result) { bool InEscape = false; const char Marker = Code[0]; for (size_t Length = 1, Size = Code.size(); Length != Size; ++Length) { if (InEscape) { InEscape = false; continue; } if (Code[Length] == '\\') { InEscape = true; continue; } if (Code[Length] == Marker) { Result->Kind = TokenInfo::TK_Literal; Result->Text = Code.substr(0, Length + 1); Result->Value = Code.substr(1, Length - 1).str(); Code = Code.drop_front(Length + 1); return; } } StringRef ErrorText = Code; Code = Code.drop_front(Code.size()); SourceRange Range; Range.Start = Result->Range.Start; Range.End = currentLocation(); Error->pushErrorFrame(Range, Error->ET_ParserStringError) << ErrorText; Result->Kind = TokenInfo::TK_Error; }
void Player::performAction(string verb, string noun) { Item* EnvBlock = currentLocation()->listItem()->findByCommand(verb, noun); if(EnvBlock!=NULL && EnvBlock->currentState()==true){ cout << "The " << EnvBlock->name() << " is in the way!\n"; } else if (verb == "TAKE") { bool found = false; bool status = false; Node* walker = (currentLocation() -> listItem()) -> getHead(); for (int i = 0; i < ((currentLocation()) -> listItem()) -> getSize(); i++) { if (((walker -> data)->name()) == noun) { found = true; status = (walker -> data)->take(currentLocation()->listItem(),inventory()); int newNum = currentLocation() -> numItem(); newNum --; currentLocation() -> numItem(newNum); } walker = walker -> next; } walker = NULL; if (found){ if (status) cout << "You have taken " << noun << "." << endl; else cout << "You cannot do that with that object\n"; } else cout << "There is no " << noun << " here." << endl; } // drop function else if (verb == "DROP") { bool found = false; bool status = false; Node* walker = inventory() -> getHead(); for (int i = 0; i < inventory() -> getSize(); i++) { if (((walker -> data)->name()) == noun) { found = true; status = (walker -> data)->drop(currentLocation()->listItem(),inventory()); int newNum = currentLocation() -> numItem(); newNum++; currentLocation() -> numItem(newNum); } walker = walker -> next; } walker = NULL; if (found){ if (status) cout << "You have dropped " << noun << "." << endl; else cout << "You cannot do that with that object\n"; } else cout << "You don't have" << noun << " here." << endl; } // observe function else if (verb == "OBSERVE" || verb == "READ" || verb == "LOOK") { if(verb=="LOOK"&&noun=="INVENTORY"){ string currentInventory = inventory()->listAll(); if(currentInventory=="") cout << "You have nothing in your inventory\n"; else cout << "You have a " << currentInventory <<" in your inventory\n"; } else if(noun=="ROOM" || noun==""){ cout << "You're in "<<getDescription(verb, noun) <<endl; string itemsInRoom=currentLocation()->listItem()->listAll(); if (itemsInRoom != "") cout <<"There is a " << itemsInRoom <<" in this room." << endl; } else{ bool found = false; bool status = false; Node* walker = inventory() -> getHead(); for (int i = 0; i < inventory() -> getSize(); i++) { if (((walker -> data)->name()) == noun) { found = true; status = (walker -> data)->observe(); break; } walker = walker -> next; } walker = NULL; if (found){ if (status) cout << endl; } else cout << "You don't have a " << noun << " with you." << endl; } } //move function else if (verb == "MOVE" || verb == "GO") { bool moved=false; for (int i=0; i<currentLocation()->numNeighbour(); i++) { if (*(currentLocation()->moveCommand()+i)==noun) { currentLocation(*(currentLocation()->moveDest()+i)); moved=true; break; } } if (moved==false) { cout<< "You can not move " << noun << endl; } else { cout <<"You have moved " << noun << endl << endl; cout << "You're in " << getDescription(verb, noun) <<endl; string itemsInRoom=currentLocation()->listItem()->listAll(); if (itemsInRoom != "") cout <<"There is a " << itemsInRoom <<" in this room." << endl; } } else if(verb=="USE"){ Item* wanted = inventory()->findByName(noun); //this is the item we are looking for if(wanted==NULL) cout << "You have no " << noun <<" in your inventory\n"; else if(wanted->currentState()){ cout << "This item cannot be used in it's current state\n"; } else if(wanted->target()!=""){ string target=""; //completely different from above statement bool itWorked = wanted->use(inventory(), target); if(itWorked) cout << "You used " << noun << " on " << target<<".\n"; else cout << "You cannot use " << noun << " here. \n"; } else{ string target = ""; bool itWorked = wanted->use(currentLocation()->listItem(), target); if(itWorked) cout << "You used " << noun << " on " << target<<".\n"; else cout << "You cannot use " << noun << " here. \n"; } } else if(verb == "HELP"){ cout << " You must enter in a two-word command, in the format\n \nverb noun\n\n"; cout << "If you get stuck, try looking at the room or at some of the items in your inventory.\n\n"; cout << "If you forget the items you have with you, look at your inventory to see them.\n\nGood Luck!\n"; } else { cout << "I'm sorry, I don't understand that." << endl; } }
void MaintainingReader<TokenLookupClass, LookupKey>::validateElement(const LookupKey elementName) const { Q_ASSERT(tokenType() == QXmlStreamReader::StartElement); if(m_elementDescriptions.contains(elementName)) { const ElementDescription<TokenLookupClass, LookupKey> &desc = m_elementDescriptions.value(elementName); const int attCount = m_currentAttributes.count(); QSet<typename TokenLookupClass::NodeName> encounteredXSLTAtts; for(int i = 0; i < attCount; ++i) { const QXmlStreamAttribute &attr = m_currentAttributes.at(i); if(attr.namespaceUri().isEmpty()) { const typename TokenLookupClass::NodeName attrName(TokenLookupClass::toToken(attr.name())); encounteredXSLTAtts.insert(attrName); if(!desc.requiredAttributes.contains(attrName) && !desc.optionalAttributes.contains(attrName) && !m_standardAttributes.contains(attrName) && !isAnyAttributeAllowed()) { QString translationString; QList<typename TokenLookupClass::NodeName> all(desc.requiredAttributes.toList() + desc.optionalAttributes.toList()); const int totalCount = all.count(); QStringList allowed; for(int i = 0; i < totalCount; ++i) allowed.append(formatKeyword(toString(all.at(i)))); /* Note, we can't run toString() on attrName, because we're in this branch, * the token lookup doesn't have the string(!).*/ const QString stringedName(attr.name().toString()); if(totalCount == 0) { translationString = QtXmlPatterns::tr("Attribute %1 cannot appear on the element %2. Only the standard attributes can appear.") .arg(formatKeyword(stringedName), formatKeyword(name())); } else if(totalCount == 1) { translationString = QtXmlPatterns::tr("Attribute %1 cannot appear on the element %2. Only %3 is allowed, and the standard attributes.") .arg(formatKeyword(stringedName), formatKeyword(name()), allowed.first()); } else if(totalCount == 1) { /* Note, allowed has already had formatKeyword() applied. */ translationString = QtXmlPatterns::tr("Attribute %1 cannot appear on the element %2. Allowed is %3, %4, and the standard attributes.") .arg(formatKeyword(stringedName), formatKeyword(name()), allowed.first(), allowed.last()); } else { /* Note, allowed has already had formatKeyword() applied. */ translationString = QtXmlPatterns::tr("Attribute %1 cannot appear on the element %2. Allowed is %3, and the standard attributes.") .arg(formatKeyword(stringedName), formatKeyword(name()), allowed.join(QLatin1String(", "))); } m_context->error(translationString, ReportContext::XTSE0090, currentLocation()); } } else if(attr.namespaceUri() == namespaceUri()) { m_context->error(QtXmlPatterns::tr("XSL-T attributes on XSL-T elements must be in the null namespace, not in the XSL-T namespace which %1 is.") .arg(formatKeyword(attr.name())), ReportContext::XTSE0090, currentLocation()); } /* Else, attributes in other namespaces are allowed, continue. */ } const QSet<typename TokenLookupClass::NodeName> requiredButMissing(QSet<typename TokenLookupClass::NodeName>(desc.requiredAttributes).subtract(encounteredXSLTAtts)); if(!requiredButMissing.isEmpty()) { error(QtXmlPatterns::tr("The attribute %1 must appear on element %2.") .arg(formatKeyword(toString(*requiredButMissing.constBegin())), formatKeyword(name())), ReportContext::XTSE0010); } } else { error(QtXmlPatterns::tr("The element with local name %1 does not exist in XSL-T.").arg(formatKeyword(name())), ReportContext::XTSE0010); } }
void MaintainingReader<TokenLookupClass, LookupKey>::warning(const QString &message) const { m_context->warning(message, currentLocation()); }
void MaintainingReader<TokenLookupClass, LookupKey>::error(const QString &message, const ReportContext::ErrorCode code) const { m_context->error(message, code, currentLocation()); }
int main(int argc, char* argv[]) { #ifdef DEBUG auto start = get_time::now(); #endif Map mapData; if(argc != 6) { std::cout << "Modo de uso: " << std::endl << argv[0] << " [archivo ubicaciones data 3D]" << " [archivo ubicaciones a consultar 3D]" << " [ventana de busqueda en X Y Z]" << std::endl; return 0; } arma::mat data; arma::mat locations; arma::vec search_window; data.load(argv[1], arma::raw_ascii); locations.load(argv[2], arma::raw_ascii); search_window << std::stod(argv[3]) << std::stod(argv[4]) << std::stod(argv[5]); double minDataX = data.col(0).min(); double minDataY = data.col(1).min(); double minDataZ = data.col(2).min(); double maxDataX = data.col(0).max(); double maxDataY = data.col(1).max(); double maxDataZ = data.col(2).max(); for(int i = 0; i < data.n_rows; i++) { Triple dataLocation( ceil((abs(data(i,0) - minDataX)) / search_window(0)), ceil((abs(data(i,1) - minDataY)) / search_window(1)), ceil((abs(data(i,2) - minDataZ)) / search_window(2)) ); mapData.insert({dataLocation,i}); } for(int i = locations.n_rows-1; i >= 0 ; i--) { Triple location( ceil((abs(locations(i,0) - minDataX)) / search_window(0)), ceil((abs(locations(i,1) - minDataY)) / search_window(1)), ceil((abs(locations(i,2) - minDataZ)) / search_window(2)) ); std::pair <Map::const_iterator, Map::const_iterator> ret; ret = mapData.equal_range(location); if(ret.first==ret.second) continue; for (Map::const_iterator itRet=ret.first; itRet!=ret.second; ++itRet) if( abs(locations(i,0) - data(itRet->second,0)) <= search_window(0) && abs(locations(i,1) - data(itRet->second,1)) <= search_window(1) && abs(locations(i,2) - data(itRet->second,2)) <= search_window(2) ) { /* aca esta la data del mismo bloque donde esta la ubicacion data(itRet->second,0) data(itRet->second,1) data(itRet->second,2) */ } for(int z = -1; z <= 1; z++) for(int y = -1; y <= 1; y++) for(int x = -1; x <= 1; x++) { Triple currentLocation( std::get<0>(location)+x, std::get<1>(location)+y, std::get<2>(location)+z ); std::pair <Map::const_iterator, Map::const_iterator> retNeighbors; retNeighbors = mapData.equal_range(currentLocation); if(retNeighbors.first==retNeighbors.second) continue; for (Map::const_iterator itRet=retNeighbors.first; itRet!=retNeighbors.second; ++itRet) if( abs(locations(i,0) - data(itRet->second,0)) <= search_window(0) && abs(locations(i,1) - data(itRet->second,1)) <= search_window(1) && abs(locations(i,2) - data(itRet->second,2)) <= search_window(2) ) { /* aca estan los datos correspondientes de los bloque colindantes a donde esta la ubicacion data(itRet->second,0) data(itRet->second,1) data(itRet->second,2) */ } } } #ifdef DEBUG std::cout << "tama~no data: " << data.n_rows << "x" << data.n_cols << std::endl; std::cout << "tama~no ubicaciones: " << locations.n_rows << "x" << locations.n_cols << std::endl; std::cout << "tama~no de ventana de busqueda en XYZ respectivamente: " << search_window; std::cout << "data min x: " << minDataX << " y: " << minDataY << " z: " << minDataZ << std::endl; std::cout << "data max x: " << maxDataX << " y: " << maxDataY << " z: " << maxDataZ << std::endl; std::cout << ceil((maxDataX - minDataX) / search_window(0)) << " bloques en eje X" << std::endl; std::cout << ceil((maxDataY - minDataY) / search_window(1)) << " bloques en eje Y" << std::endl; std::cout << ceil((maxDataZ - minDataZ) / search_window(2)) << " bloques en eje Z" << std::endl; auto end = get_time::now(); auto diff = end - start; std::cout<<"Elapsed time is : "<< std::chrono::duration_cast<ms>(diff).count()<<" ms "<<std::endl; #endif return 0; }
//Here we parse the gocde void parseGCode(HWND hWnd, HINSTANCE g_hInst, char *filePath) { std::string line; std::ifstream gcodeFile; gcodeFile.open(filePath); //Get number of lines in the file //int numLines = std::count(std::istreambuf_iterator<char>(gcodeFile), // std::istreambuf_iterator<char>(), '\n'); //wchar_t szMessage[300]; //StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"%d lines", numLines); //MessageBox(hWnd, szMessage, L"Error", MB_OK); //Reset cursor file position //gcodeFile.seekg(0, ios::beg); CSplash splash1(TEXT(""), RGB(128, 128, 128), g_hInst); splash1.ShowSplash(); if (hWnd) { if (gcodeFile.is_open()) { //MessageBox(hWnd, L"File Opened !", L"Error", MB_OK); } } else { printf("File Opened\n"); } printf("Parsing GCode File\n"); initStatistics(); vector3D cornerLow(0.f, 0.f, 0.f); vector3D cornerHigh(0.f, 0.f, 0.f); float extrusionWidth = 0.f; vector3D currentLocation(0.f,0.f,0.f); vector3D highCorner(-FLT_MAX,-FLT_MAX,-FLT_MAX); vector3D lowCorner(FLT_MAX,FLT_MAX,FLT_MAX); while (getline(gcodeFile, line)) { float oldZ = currentLocation.z; //std::istringstream *iss = new std::istringstream(line.c_str()); std::istringstream iss(line.c_str()); // Is this a new Layer ? if (isNewLayer(iss, ¤tLocation)) { statistics.layersCount++; // If height has not been found yet if (statistics.layerHeight == 0.0){ float theoreticalHeight = floor((currentLocation.z - oldZ)*100)/100; if (theoreticalHeight > 0 && theoreticalHeight < 1){ // We assume that a layer is less than 1mm thick statistics.layerHeight = theoreticalHeight; } } } else { iss = std::istringstream(line.c_str()); } std::string s; iss >> s; std::string command; bool commandFound = scanCharactersFromSet(s, "GMT0123456789", command); if (!commandFound) { continue; } if(command == "M104" || command == "M109" || command == "G10") { //printf("M104 M109 G10\n"); // M104: Set Extruder Temperature // Set the temperature of the current extruder and return control to the host immediately // (i.e. before that temperature has been reached by the extruder). See also M109 that does the same but waits. // /!\ This is deprecated because temperatures should be set using the G10 and T commands. // G10 // Example: G10 P3 X17.8 Y-19.3 Z0.0 R140 S205 // This sets the offset for extrude head 3 (from the P3) to the X and Y values specified. // The R value is the standby temperature in oC that will be used for the tool, and the S value is its operating temperature. // Makerware puts the temperature first, skip it iss >> s; if (scanString(s, "S", NULL)) { scanInt(s, "S"); } // Extract the tool index iss >> s; if (scanString(s, "P", NULL) || scanString(s, "T", NULL)) { int toolIndex; if (scanString(s, "P", NULL)) toolIndex = scanInt(s, "P"); else toolIndex = scanInt(s, "T"); bool previouslyUsingToolB = statistics.usingToolB; statistics.usingToolB = (toolIndex >= 1); if (statistics.usingToolB == !previouslyUsingToolB) { statistics.dualExtrusion = true; } } } else if(command == "G1") {