void DevSetup::loadAudioDevices (AudioDevices const& d, QComboBox * cb, QAudioDeviceInfo const& device, QAudioDeviceInfo const& defaultDevice) { using std::copy; using std::back_inserter; int currentIndex = -1; int defaultIndex = 0; for (AudioDevices::const_iterator p = d.cbegin (); p != d.cend (); ++p) { // convert supported channel counts into something we can store in the item model QList<QVariant> channelCounts; QList<int> scc (p->supportedChannelCounts ()); copy (scc.cbegin (), scc.cend (), back_inserter (channelCounts)); cb->addItem (p->deviceName (), channelCounts); if (*p == device) { currentIndex = p - d.cbegin (); } else if (*p == defaultDevice) { defaultIndex = p - d.cbegin (); } } cb->setCurrentIndex (currentIndex != -1 ? currentIndex : defaultIndex); }
OsmAnd::RoutePlannerContext::RoutePlannerContext( const QList< std::shared_ptr<ObfReader> >& sources, const std::shared_ptr<RoutingConfiguration>& routingConfig, const QString& vehicle, bool useBasemap, float initialHeading /*= std::numeric_limits<float>::quiet_NaN()*/, QHash<QString, QString>* options /*=nullptr*/, size_t memoryLimit ) : _useBasemap(useBasemap) , _memoryUsageLimit(memoryLimit) , _loadedTiles(0) , _initialHeading(initialHeading) , sources(sources) , configuration(routingConfig) , _routeStatistics(new RouteStatistics) , profileContext(new RoutingProfileContext(configuration->routingProfiles[vehicle], options)) { _partialRecalculationDistanceLimit = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "recalculateDistanceHelp"), 10000.0f); _heuristicCoefficient = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "heuristicCoefficient"), 1.0f); _planRoadDirection = Utilities::parseArbitraryInt(configuration->resolveAttribute(vehicle, "planRoadDirection"), 0); _roadTilesLoadingZoomLevel = Utilities::parseArbitraryUInt(configuration->resolveAttribute(vehicle, "zoomToLoadTiles"), DefaultRoadTilesLoadingZoomLevel); for(auto itSource = sources.cbegin(); itSource != sources.cend(); ++itSource) { const auto& source = *itSource; const auto& obfInfo = source->obtainInfo(); for(auto itRoutingSection = obfInfo->routingSections.cbegin(); itRoutingSection != obfInfo->routingSections.cend(); ++itRoutingSection) _sourcesLUT.insert((*itRoutingSection).get(), source); } }
bool Library::fileDump(QChar key, QList<QString> &keysList, QFlags<QIODevice::OpenModeFlag> openFlags) { QString path, val; QList<QString>::const_iterator cat_i = keysList.cbegin(); QHash<QString, int> * res = catalogs -> value(key); path = libraryPath() + "cat_" + key; qDebug() << "SSave list "<< keysList; QFile f(path); if (f.open(openFlags)) { QTextStream out(&f); out.setCodec("UTF-8"); while(cat_i != keysList.cend()) { val = *cat_i; qDebug() << "Curr val " << val; out << QString::number(res -> value(val)) << val.toUtf8() << "\n"; cat_i++; } f.close(); return true; } return false; }
void PsMainWindow::psInitSize() { setMinimumWidth(st::wndMinWidth); setMinimumHeight(st::wndMinHeight); TWindowPos pos(cWindowPos()); QRect avail(QDesktopWidget().availableGeometry()); bool maximized = false; QRect geom(avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight); if (pos.w && pos.h) { QList<QScreen*> screens = App::app()->screens(); for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) { QByteArray name = (*i)->name().toUtf8(); if (pos.moncrc == hashCrc32(name.constData(), name.size())) { QRect screen((*i)->geometry()); int32 w = screen.width(), h = screen.height(); if (w >= st::wndMinWidth && h >= st::wndMinHeight) { if (pos.w > w) pos.w = w; if (pos.h > h) pos.h = h; pos.x += screen.x(); pos.y += screen.y(); if (pos.x < screen.x() + screen.width() - 10 && pos.y < screen.y() + screen.height() - 10) { geom = QRect(pos.x, pos.y, pos.w, pos.h); } } break; } } if (pos.y < 0) pos.y = 0; maximized = pos.maximized; } setGeometry(geom); }
void AWDataAggregator::setData(const QString &source, float value, const float extremum) { qCDebug(LOG_AW) << "Source" << source << "to value" << value << "with extremum" << extremum; if (data[source].count() == 0) data[source].append(0.0); else if (data[source].count() > configuration[QString("tooltipNumber")].toInt()) data[source].removeFirst(); if (isnan(value)) value = 0.0; // notifications checkValue(source, value, extremum); data[source].append(value); if (source == QString("downTooltip")) { QList<float> netValues = data[QString("downTooltip")] + data[QString("upTooltip")]; boundaries[QString("downTooltip")] = 1.2 * *std::max_element(netValues.cbegin(), netValues.cend()); boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")]; } }
void MainWindow::addToCartOutbound() { QModelIndexList selection = ui->tvOutboundFlights->selectionModel()->selectedRows(); if (selection.count() != 1) { return; } QJsonObject selectedFlight = mOutboundFlights->jsonData(selection.first()); QString airlineName = selectedFlight["name"].toString(); QList<QJsonObject> inbound = mInboundFlights->jsonData(); QList<QJsonObject> inboundCleaned; for (QList<QJsonObject>::const_iterator it = inbound.cbegin(); it != inbound.cend(); ++it) { if (it->value("name") == airlineName) { inboundCleaned.append(*it); } } mInboundFlights->setData(inboundCleaned); mUser.addToCart(selectedFlight); updateShoppingCart(); }
void addGroupFilter(const std::shared_ptr<MapStyleRule>& rule) { for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild) { auto child = *itChild; child->_d->_ifChildren.push_back(rule); } for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup) { auto subgroup = *itSubgroup; assert(subgroup->type == Lexeme::Group); std::static_pointer_cast<Group>(subgroup)->addGroupFilter(rule); } }
void printDifference(const LogOutput &actual, const LogOutput &expected) { QTextStream out(stderr); const QList<QByteArray> actualLines = actual.text.split('\n'); const QList<QByteArray> expectedLines = expected.text.split('\n'); out << "-- ACTUAL:\n"; printRawLines(out, actualLines); out << "-- EXPECTED:\n"; printRawLines(out, expectedLines); if (actualLines.size() != expectedLines.size()) { out << "-- DIFFERENCE IN LINE COUNT:\n" << " actual lines:" << actualLines.size() << '\n' << " expected lines:" << expectedLines.size() << '\n'; } out << "-- FIRST LINE THAT DIFFERS:\n"; auto actualLineIt = actualLines.cbegin(); auto expectedLineIt = expectedLines.cbegin(); int line = 1; forever { if (actualLineIt == actualLines.cend() && expectedLineIt != expectedLines.cend()) { out << " line: " << line << '\n'; out << " actual: <none>\n"; out << " expected: \"" << *expectedLineIt << "\"\n"; } else if (actualLineIt != actualLines.cend() && expectedLineIt == expectedLines.cend()) { out << " line: " << line << '\n'; out << " actual: \"" << *actualLineIt << "\"\n"; out << " expected: <none>\n"; } else { if (*actualLineIt != *expectedLineIt) { out << " line: " << line << '\n'; out << " actual: \"" << *actualLineIt << "\"\n"; out << " expected: \"" << *expectedLineIt << "\"\n"; return; } } ++line; ++actualLineIt; ++expectedLineIt; } }
void OsmAnd::ObfPoiSectionReader_P::readAmenities( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section, QSet<uint32_t>* desiredCategories, QList< std::shared_ptr<const Model::Amenity> >* amenitiesOut, const ZoomLevel& zoom, uint32_t zoomDepth, const AreaI* bbox31, std::function<bool (const std::shared_ptr<const Model::Amenity>&)> visitor, IQueryController* controller) { auto cis = reader->_codedInputStream.get(); QList< std::shared_ptr<Tile> > tiles; for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndPoiIndex::kBoxesFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto oldLimit = cis->PushLimit(length); readTile(reader, section, tiles, nullptr, desiredCategories, zoom, zoomDepth, bbox31, controller, nullptr); cis->PopLimit(oldLimit); if(controller && controller->isAborted()) return; } break; case OBF::OsmAndPoiIndex::kPoiDataFieldNumber: { // Sort tiles byte data offset, to all cache-friendly with I/O system qSort(tiles.begin(), tiles.end(), [](const std::shared_ptr<Tile>& l, const std::shared_ptr<Tile>& r) -> bool { return l->_hash < r->_hash; }); for(auto itTile = tiles.cbegin(); itTile != tiles.cend(); ++itTile) { const auto& tile = *itTile; cis->Seek(section->_offset + tile->_offset); auto length = ObfReaderUtilities::readBigEndianInt(cis); auto oldLimit = cis->PushLimit(length); readAmenitiesFromTile(reader, section, tile.get(), desiredCategories, amenitiesOut, zoom, zoomDepth, bbox31, visitor, controller, nullptr); cis->PopLimit(oldLimit); if(controller && controller->isAborted()) return; } cis->Skip(cis->BytesUntilLimit()); } return; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
/*! \internal */ qint64 QWebSocketPrivate::writeFrames(const QList<QByteArray> &frames) { qint64 written = 0; if (Q_LIKELY(m_pSocket)) { QList<QByteArray>::const_iterator it; for (it = frames.cbegin(); it < frames.cend(); ++it) written += writeFrame(*it); } return written; }
bool registerGlobalRules(const MapStyleRulesetType type) { for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild) { auto child = *itChild; if(!style->registerRule(type, child)) return false; } for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup) { auto subgroup = *itSubgroup; assert(subgroup->type == Lexeme::Group); if(!std::static_pointer_cast<Group>(subgroup)->registerGlobalRules(type)) return false; } return true; }
void printPOIDetailInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfPoiSectionInfo>& section) #endif { output << xT("\tBounds ") << formatBounds(section->area31.left, section->area31.right, section->area31.top, section->area31.bottom) << std::endl; QList< std::shared_ptr<const OsmAnd::Model::AmenityCategory> > categories; OsmAnd::ObfPoiSectionReader::loadCategories(reader, section, categories); output << xT("\tCategories:") << std::endl; for(auto itCategory = categories.cbegin(); itCategory != categories.cend(); ++itCategory) { auto category = *itCategory; output << xT("\t\t") << QStringToStlString(category->name) << std::endl; for(auto itSubcategory = category->subcategories.cbegin(); itSubcategory != category->subcategories.cend(); ++itSubcategory) output << xT("\t\t\t") << QStringToStlString(*itSubcategory) << std::endl; } QList< std::shared_ptr<const OsmAnd::Model::Amenity> > amenities; OsmAnd::AreaI bbox31; bbox31.top = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top); bbox31.bottom = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom); bbox31.left = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left); bbox31.right = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right); OsmAnd::ObfPoiSectionReader::loadAmenities(reader, section, cfg.zoom, 3, &bbox31, nullptr, &amenities); output << xT("\tAmenities, ") << amenities.count() << xT(" item(s)"); if(!cfg.verboseAmenities) { output << std::endl; return; } output << ":" << std::endl;; for(auto itAmenity = amenities.cbegin(); itAmenity != amenities.cend(); ++itAmenity) { auto amenity = *itAmenity; output << xT("\t\t") << QStringToStlString(amenity->latinName) << xT(" [") << amenity->id << xT("], ") << QStringToStlString(categories[amenity->categoryId]->name) << xT(":") << QStringToStlString(categories[amenity->categoryId]->subcategories[amenity->subcategoryId]) << xT(", lat ") << OsmAnd::Utilities::get31LatitudeY(amenity->point31.y) << xT(" lon ") << OsmAnd::Utilities::get31LongitudeX(amenity->point31.x) << std::endl; } }
void WebUploader::createArenaCards(QList<DeckCard> &deckCardList) { for (QList<DeckCard>::const_iterator it = deckCardList.cbegin(); it != deckCardList.cend(); it++) { if(it->total > 0) { QString name = (*cardsJson)[it->code].value("name").toString(); arenaCards.append(QString::number(it->total) + " " + name + "\n"); } } qDebug() << "WebUploader: Building Deck string: "<< endl << arenaCards; }
void AjoutPrecedence::EnregistrerPred(){ //attribut modele à la classe ajoutPrecedence QMap<QString, Tache*> pred; for(int nb=0; nb<modele.rowCount(); nb++){ QList<QString>* liste = new QList<QString>; testChecked(modele.item(nb), liste); for(QList<QString>::const_iterator i = liste->cbegin(); i< liste->cend(); i++){ Projet* p =ProjetManager::getInstance().trouverProjet(modele.item(nb)->text()); Tache* t= p->trouverTache(*i); pred.insert(t->getId(), t); } } EditeurTache::predecesseurs=pred; close(); }
void ApiWrap::requestPeers(const QList<PeerData*> &peers) { QVector<MTPint> chats; QVector<MTPInputUser> users; chats.reserve(peers.size()); users.reserve(peers.size()); for (QList<PeerData*>::const_iterator i = peers.cbegin(), e = peers.cend(); i != e; ++i) { if (!*i || _fullPeerRequests.contains(*i) || _peerRequests.contains(*i)) continue; if ((*i)->chat) { chats.push_back(MTP_int(App::chatFromPeer((*i)->id))); } else { users.push_back((*i)->asUser()->inputUser); } } if (!chats.isEmpty()) MTP::send(MTPmessages_GetChats(MTP_vector<MTPint>(chats)), rpcDone(&ApiWrap::gotChats)); if (!users.isEmpty()) MTP::send(MTPusers_GetUsers(MTP_vector<MTPInputUser>(users)), rpcDone(&ApiWrap::gotUsers)); }
void PsMainWindow::psSavePosition(Qt::WindowState state) { if (state == Qt::WindowActive) state = windowHandle()->windowState(); if (state == Qt::WindowMinimized || !posInited) return; TWindowPos pos(cWindowPos()), curPos = pos; if (state == Qt::WindowMaximized) { curPos.maximized = 1; } else { QRect r(geometry()); curPos.x = r.x(); curPos.y = r.y(); curPos.w = r.width(); curPos.h = r.height(); curPos.maximized = 0; } int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2, d = 0; QScreen *chosen = 0; QList<QScreen*> screens = App::app()->screens(); for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) { int dx = (*i)->geometry().x() + (*i)->geometry().width() / 2 - px; if (dx < 0) dx = -dx; int dy = (*i)->geometry().y() + (*i)->geometry().height() / 2 - py; if (dy < 0) dy = -dy; if (!chosen || dx + dy < d) { d = dx + dy; chosen = *i; } } if (chosen) { curPos.x -= chosen->geometry().x(); curPos.y -= chosen->geometry().y(); QByteArray name = chosen->name().toUtf8(); curPos.moncrc = hashCrc32(name.constData(), name.size()); } if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) { if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) { cSetWindowPos(curPos); Local::writeSettings(); } } }
void printMapDetailInfo(std::ostream& output, const OsmAndTools::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section) #endif { OsmAnd::AreaI bbox31; bbox31.top() = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top()); bbox31.bottom() = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom()); bbox31.left() = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left()); bbox31.right() = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right()); if (cfg.verboseMapObjects) { QList< std::shared_ptr<const OsmAnd::Model::BinaryMapObject> > mapObjects; OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, &mapObjects); output << xT("\tTotal map objects: ") << mapObjects.count() << std::endl; for (auto itMapObject = mapObjects.cbegin(); itMapObject != mapObjects.cend(); ++itMapObject) { auto mapObject = *itMapObject; output << xT("\t\t") << mapObject->id << std::endl; if (mapObject->captions.count() > 0) { output << xT("\t\t\tNames:") << std::endl; for (auto itCaption = mapObject->captions.cbegin(); itCaption != mapObject->captions.cend(); ++itCaption) { const auto& rule = mapObject->section->encodingDecodingRules->decodingRules[itCaption.key()]; output << xT("\t\t\t\t") << QStringToStlString(rule.tag) << xT(" = ") << QStringToStlString(itCaption.value()) << std::endl; } } } } else { uint32_t mapObjectsCount = 0; OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, nullptr, nullptr, nullptr, [&mapObjectsCount] (const std::shared_ptr<const OsmAnd::Model::BinaryMapObject>& mapObject) -> bool { mapObjectsCount++; return false; }); output << xT("\tTotal map objects: ") << mapObjectsCount << std::endl; } }
void MainWindow::_show_updatePortNames() { //we extract the names of the currently available serial ports QList<QSerialPortInfo> availablePorts = QSerialPortInfo::availablePorts(); std::list<QString> availablePortNames; for(auto it = availablePorts.cbegin(); it != availablePorts.cend(); ++it) availablePortNames.push_back(it->portName()); //has any serial port been closed since the last check? for(auto it = m_show_arraySerialPortActions.begin(); it != m_show_arraySerialPortActions.end(); ++it) { QString currentPortName = (*it)->text(); bool found = false; for(auto jt = availablePortNames.begin(); !found && jt != availablePortNames.end(); ++jt) if((*jt) == currentPortName) { //this serial port is still available, and we already have a QAction for it, we remove it from availablePortNames std::cout << "found : " << currentPortName.toStdString() << std::endl; jt = availablePortNames.erase(jt); found = true; } if(!found) { //this serial port is no longer available, we delete it from the GUI. m_show_serialPortActionGroup->removeAction(*it); m_show_menuSerialPort->removeAction(*it); it = m_show_arraySerialPortActions.erase(it); } } //Now, availablePortNames only contains the names of the newly available serial ports. for(auto it = availablePortNames.cbegin(); it != availablePortNames.cend(); ++it) { QAction * serialPortAction = new QAction(*it, this); serialPortAction->setCheckable(true); m_show_arraySerialPortActions.push_back(serialPortAction); m_show_serialPortActionGroup->addAction(serialPortAction); m_show_menuSerialPort->addAction(serialPortAction); } }
void printMapDetailInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section) #endif { OsmAnd::AreaI bbox31; bbox31.top = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top); bbox31.bottom = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom); bbox31.left = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left); bbox31.right = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right); if(cfg.verboseMapObjects) { QList< std::shared_ptr<const OsmAnd::Model::MapObject> > mapObjects; OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, &mapObjects); output << xT("\tTotal map objects: ") << mapObjects.count() << std::endl; for(auto itMapObject = mapObjects.cbegin(); itMapObject != mapObjects.cend(); ++itMapObject) { auto mapObject = *itMapObject; output << xT("\t\t") << mapObject->id << std::endl; if(mapObject->names.count() > 0) { output << xT("\t\t\tNames:"); for(auto itName = mapObject->names.cbegin(); itName != mapObject->names.cend(); ++itName) output << QStringToStlString(itName.value()) << xT(", "); output << std::endl; } else output << xT("\t\t\tNames: [none]") << std::endl; } } else { uint32_t mapObjectsCount = 0; OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, nullptr, nullptr, nullptr, [&mapObjectsCount](const std::shared_ptr<const OsmAnd::Model::MapObject>& mapObject) -> bool { mapObjectsCount++; return false; }); output << xT("\tTotal map objects: ") << mapObjectsCount << std::endl; } }
void printAddressDetailedInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfAddressSectionInfo>& section) #endif { OsmAnd::ObfAddressBlockType types[] = { OsmAnd::ObfAddressBlockType::CitiesOrTowns, OsmAnd::ObfAddressBlockType::Villages, OsmAnd::ObfAddressBlockType::Postcodes, }; char* strTypes[] = { "Cities/Towns section", "Villages section", "Postcodes section", }; for(int typeIdx = 0; typeIdx < sizeof(types)/sizeof(types[0]); typeIdx++) { auto type = types[typeIdx]; QList< std::shared_ptr<const OsmAnd::Model::StreetGroup> > streetGroups; QSet<OsmAnd::ObfAddressBlockType> typeSet; typeSet << types[typeIdx]; OsmAnd::ObfAddressSectionReader::loadStreetGroups(reader, section, &streetGroups, nullptr, nullptr, &typeSet); output << xT("\t") << strTypes[typeIdx] << xT(", ") << streetGroups.size() << xT(" group(s)"); if(!cfg.verboseStreetGroups) { output << std::endl; continue; } output << ":" << std::endl; for(auto itStreetGroup = streetGroups.cbegin(); itStreetGroup != streetGroups.cend(); itStreetGroup++) { auto g = *itStreetGroup; QList< std::shared_ptr<const OsmAnd::Model::Street> > streets; OsmAnd::ObfAddressSectionReader::loadStreetsFromGroup(reader, g, &streets); output << xT("\t\t'") << QStringToStlString(g->_latinName) << xT("' [") << g->_id << xT("], ") << streets.size() << xT(" street(s)"); if(!cfg.verboseStreets) { output << std::endl; continue; } output << xT(":") << std::endl; for(auto itStreet = streets.cbegin(); itStreet != streets.cend(); ++itStreet) { auto s = *itStreet; //TODO: proper filter //const bool isInside = // cfg.latTop >= s->latitude && // cfg.latBottom <= s->latitude && // cfg.lonLeft <= s->longitude && // cfg.lonRight >= s->longitude; //if(!isInside) // continue; // QList< std::shared_ptr<const OsmAnd::Model::Building> > buildings; OsmAnd::ObfAddressSectionReader::loadBuildingsFromStreet(reader, s, &buildings); QList< std::shared_ptr<const OsmAnd::Model::StreetIntersection> > intersections; OsmAnd::ObfAddressSectionReader::loadIntersectionsFromStreet(reader, s, &intersections); output << xT("\t\t\t'") << QStringToStlString(s->latinName) << xT("' [") << s->id << xT("], ") << buildings.size() << xT(" building(s), ") << intersections.size() << xT(" intersection(s)") << std::endl; if(cfg.verboseBuildings && buildings.size() > 0) { output << xT("\t\t\t\tBuildings:") << std::endl; for(auto itBuilding = buildings.cbegin(); itBuilding != buildings.cend(); ++itBuilding) { auto building = *itBuilding; if(building->_interpolationInterval != 0) output << xT("\t\t\t\t\t") << QStringToStlString(building->_latinName) << xT("-") << QStringToStlString(building->_latinName2) << xT(" (+") << building->_interpolationInterval << xT(") [") << building->_id << xT("]") << std::endl; else if(building->_interpolation != OsmAnd::Model::Building::Interpolation::Invalid) output << xT("\t\t\t\t\t") << QStringToStlString(building->_latinName) << xT("-") << QStringToStlString(building->_latinName2) << xT(" (") << building->_interpolation << xT(") [") << building->_id << xT("]") << std::endl; } } if(cfg.verboseIntersections && intersections.size() > 0) { output << xT("\t\t\t\tIntersects with:") << std::endl; for(auto itIntersection = intersections.cbegin(); itIntersection != intersections.cend(); ++itIntersection) { auto intersection = *itIntersection; output << xT("\t\t\t\t\t") << QStringToStlString(intersection->latinName) << std::endl; } } } } } }
int main(int argc, char ** argv) { int status = EXIT_FAILURE; try { avatar::AppEnvironment env(argc, argv); avatar::cmdline_utils::Parser cmdlineParser; std::unique_ptr<avatar::RiftApp> app; auto cmdlineParserResult = cmdlineParser.parseOptions(); switch (cmdlineParserResult.first) { case avatar::cmdline_utils::Parser::Status::LaunchColorCubeDemo: { std::wcout << L"Info >> description: launching color cube demo" << std::endl; app.reset(new avatar::ColorCubeApp); } break; case avatar::cmdline_utils::Parser::Status::LaunchTextureCubeDemo: { std::wcout << L"Info >> description: launching texture cube demo" << std::endl; app.reset(new avatar::TexCubeApp); } break; case avatar::cmdline_utils::Parser::Status::LaunchMonoWebcamDemo: { std::wcout << L"Info >> description: launching mono webcam demo" << std::endl; app.reset(new avatar::WebcamMonoApp); } break; case avatar::cmdline_utils::Parser::Status::LaunchStereoWebcamDemo: { std::wcout << L"Info >> description: launching stereo webcam demo" << std::endl; app.reset(new avatar::WebcamStereoApp); } break; case avatar::cmdline_utils::Parser::Status::LaunchClientDemo: { QString const serverAddressString = cmdlineParser.value(avatar::cmdline_utils::launchClientDemo); QHostAddress serverAddress(serverAddressString); std::wcout << L"Info >> description: launching client demo with server IP address " << serverAddressString.toStdWString() << std::endl; app.reset(new avatar::VideoStreamClientApp(serverAddress)); } break; case avatar::cmdline_utils::Parser::Status::LaunchServerDemo: { std::wcout << L"Info >> description: launching server demo" << std::endl; app.reset(new avatar::VideoStreamServerApp); } break; case avatar::cmdline_utils::Parser::Status::LaunchFirstPersonViewDemo: { std::wcout << L"Info >> description: launching FPV demo" << std::endl; // // Find arduino serial port. // QList<QSerialPortInfo> const ports = QSerialPortInfo::availablePorts(); QList<QSerialPortInfo>::const_iterator arduinoPort = ports.cend(); for (auto it = ports.cbegin(); it != ports.cend(); ++it) { QString const description = it->description(); if (description.contains("arduino", Qt::CaseInsensitive)) { arduinoPort = it; break; } } if (arduinoPort == ports.cend()) { std::wcout << L"Error >> description: failed to find arduino serial port" << std::endl; return EXIT_FAILURE; } // // Find a webcam. // auto const cameras = QCameraInfo::availableCameras(); if (cameras.empty()) { std::wcout << L"Error >> description: failed to find webcam devices" << std::endl; return EXIT_FAILURE; } // // Setup both the interpreter for the arduino port and the camera. // auto commandInterpreter = avatar::FirstPersonViewSerialCli::create(*arduinoPort, QSerialPort::Baud115200, QByteArray("Servo>"), 50); auto imageSystem = avatar::ImageSystem::create(std::make_unique<avatar::WebcamImageReader>(cameras[0]), std::make_unique<avatar::WebcamImageProcessor>()); app.reset(new avatar::FirstPersonViewApp(std::move(commandInterpreter), std::move(imageSystem))); } break; case avatar::cmdline_utils::Parser::Status::ShowHelp: { cmdlineParser.showHelp(EXIT_SUCCESS); // showHelp() will exit the application } break; case avatar::cmdline_utils::Parser::Status::Error: { std::wcout << cmdlineParserResult.second.toStdWString() << std::endl; cmdlineParser.showHelp(EXIT_FAILURE); // showHelp() will exit the application } break; default: { Q_ASSERT(false); cmdlineParser.showHelp(EXIT_FAILURE); // showHelp() will exit the application } } app->show(); status = env.exec(); } catch (avatar::Exception const & e) { std::wcout << e.what().toStdWString() << std::endl; } return status; }
void performJourney(std::ostream &output, const OsmAnd::Voyager::Configuration& cfg) #endif { if(cfg.generateXml) { #if defined(_UNICODE) || defined(UNICODE) output << xT("<?xml version=\"1.0\" encoding=\"UTF-16\"?>") << std::endl; #else output << xT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") << std::endl; #endif } QList< std::shared_ptr<OsmAnd::ObfReader> > obfData; for(auto itObf = cfg.obfs.cbegin(); itObf != cfg.obfs.cend(); ++itObf) { const auto& obf = *itObf; std::shared_ptr<OsmAnd::ObfReader> obfReader(new OsmAnd::ObfReader(std::shared_ptr<QIODevice>(new QFile(obf.absoluteFilePath())))); obfData.push_back(obfReader); } OsmAnd::RoutePlannerContext plannerContext(obfData, cfg.routingConfig, cfg.vehicle, false); std::shared_ptr<const OsmAnd::Model::Road> startRoad; if(!OsmAnd::RoutePlanner::findClosestRoadPoint(&plannerContext, cfg.startLatitude, cfg.startLongitude, &startRoad)) { if(cfg.generateXml) output << xT("<!--"); output << xT("Failed to find road near start point"); if(cfg.generateXml) output << xT("-->"); output << std::endl; return; } std::shared_ptr<const OsmAnd::Model::Road> endRoad; if(!OsmAnd::RoutePlanner::findClosestRoadPoint(&plannerContext, cfg.endLatitude, cfg.endLongitude, &endRoad)) { if(cfg.generateXml) output << xT("<!--"); output << xT("Failed to find road near end point"); if(cfg.generateXml) output << xT("-->"); output << std::endl; return; } if(cfg.verbose) { if(cfg.generateXml) output << xT("<!--"); output << xT("Start point (LAT ") << cfg.startLatitude << xT("; LON ") << cfg.startLongitude << xT("):"); if(cfg.generateXml) output << xT("-->"); output << std::endl; if(cfg.generateXml) output << xT("<!--"); output << xT("\tRoad name(s): "); if(startRoad->names.size() == 0) { output << xT("\t[none] (") << startRoad->id << xT(")"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } else { for(auto itName = startRoad->names.cbegin(); itName != startRoad->names.cend(); ++itName) output << QStringToStlString(itName.value()) << xT("; "); output << xT(" (") << startRoad->id << xT(")"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } output << std::endl; if(cfg.generateXml) output << xT("<!--"); output << xT("End point (LAT ") << cfg.endLatitude << xT("; LON ") << cfg.endLongitude << xT("):"); if(cfg.generateXml) output << xT("-->"); output << std::endl; if(cfg.generateXml) output << xT("<!--"); output << xT("\tRoad name(s): "); if(endRoad->names.size() == 0) { output << xT("\t[none] (") << endRoad->id << xT(")"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } else { for(auto itName = endRoad->names.cbegin(); itName != endRoad->names.cend(); ++itName) output << QStringToStlString(itName.value()) << xT("; "); output << xT(" (") << endRoad->id << xT(")"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } output << std::endl; } QList< std::pair<double, double> > points; points.push_back(std::pair<double, double>(cfg.startLatitude, cfg.startLongitude)); for(auto itIntermediatePoint = cfg.waypoints.cbegin(); itIntermediatePoint != cfg.waypoints.cend(); ++itIntermediatePoint) points.push_back(*itIntermediatePoint); points.push_back(std::pair<double, double>(cfg.endLatitude, cfg.endLongitude)); QList< std::shared_ptr<OsmAnd::RouteSegment> > route; auto routeCalculationStart = std::chrono::steady_clock::now(); if(cfg.verbose) { if(cfg.generateXml) output << xT("<!--"); output << xT("Started route calculation ") << QStringToStlString(QTime::currentTime().toString()); if(cfg.generateXml) output << xT("-->"); output << std::endl; } OsmAnd::RouteCalculationResult routeFound = OsmAnd::RoutePlanner::calculateRoute(&plannerContext, points, cfg.leftSide, nullptr); route = routeFound.list; auto routeCalculationFinish = std::chrono::steady_clock::now(); if(cfg.verbose) { if(cfg.generateXml) output << xT("<!--"); output << xT("Finished route calculation ") << QStringToStlString(QTime::currentTime().toString()) << xT(", took ") << std::chrono::duration<double, std::milli> (routeCalculationFinish - routeCalculationStart).count() << xT(" ms"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } if(cfg.doRecalculate) { auto routeRecalculationStart = std::chrono::steady_clock::now(); if(cfg.verbose) { if(cfg.generateXml) output << xT("<!--"); output << xT("Started route recalculation ") << QStringToStlString(QTime::currentTime().toString()); if(cfg.generateXml) output << xT("-->"); output << std::endl; } routeFound = OsmAnd::RoutePlanner::calculateRoute(&plannerContext, points, cfg.leftSide, nullptr); route = routeFound.list; auto routeRecalculationFinish = std::chrono::steady_clock::now(); if(cfg.verbose) { if(cfg.generateXml) output << xT("<!--"); output << xT("Finished route recalculation ") << QStringToStlString(QTime::currentTime().toString()) << xT(", took ") << std::chrono::duration<double, std::milli> (routeRecalculationFinish - routeRecalculationStart).count() << xT(" ms"); if(cfg.generateXml) output << xT("-->"); output << std::endl; } } if(routeFound.warnMessage == "") { if(cfg.generateXml) output << xT("<!--"); output << xT("FAILED TO FIND ROUTE!") << QStringToStlString(routeFound.warnMessage); if(cfg.generateXml) output << xT("-->"); output << std::endl; } float totalTime = 0.0f; float totalDistance = 0.0f; for(auto itSegment = route.cbegin(); itSegment != route.cend(); ++itSegment) { auto segment = *itSegment; totalTime += segment->time; totalDistance += segment->distance; } if(cfg.generateXml) output << xT("<test") << std::endl; else output << xT("ROUTE:") << std::endl; output << xT("\tregions=\"\"") << std::endl; output << xT("\tdescription=\"\"") << std::endl; output << xT("\tbest_percent=\"\"") << std::endl; output << xT("\tvehicle=\"") << QStringToStlString(cfg.vehicle) << xT("\"") << std::endl; output << xT("\tstart_lat=\"") << cfg.startLatitude << xT("\"") << std::endl; output << xT("\tstart_lon=\"") << cfg.startLongitude << xT("\"") << std::endl; output << xT("\ttarget_lat=\"") << cfg.endLatitude << xT("\"") << std::endl; output << xT("\ttarget_lon=\"") << cfg.endLongitude << xT("\"") << std::endl; output << xT("\tloadedTiles=\"") << 0 << xT("\"") << std::endl; output << xT("\tvisitedSegments=\"") << 0 << xT("\"") << std::endl; output << xT("\tcomplete_distance=\"") << totalDistance << xT("\"") << std::endl; output << xT("\tcomplete_time=\"") << totalTime << xT("\"") << std::endl; output << xT("\trouting_time=\"") << 0 << xT("\"") << std::endl; if(cfg.generateXml) output << xT(">") << std::endl; else output << std::endl; std::unique_ptr<QFile> gpxFile; std::unique_ptr<QTextStream> gpxStream; if(!cfg.gpxPath.isEmpty()) { gpxFile.reset(new QFile(cfg.gpxPath)); gpxFile->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); gpxStream.reset(new QTextStream(gpxFile.get())); } if(gpxFile && gpxFile->isOpen()) { *(gpxStream.get()) << "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n"; *(gpxStream.get()) << "<gpx version=\"1.0\" creator=\"OsmAnd Voyager tool\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"; *(gpxStream.get()) << "\t<trk>\n"; *(gpxStream.get()) << "\t\t<trkseg>\n"; } for(auto itSegment = route.cbegin(); itSegment != route.cend(); ++itSegment) { auto segment = *itSegment; if(cfg.generateXml) output << xT("\t<segment") << std::endl; else output << xT("\tSEGMENT:") << std::endl; output << xT("\t\tid=\"") << segment->road->id << xT("\"") << std::endl; output << xT("\t\tstart=\"") << segment->startPointIndex << xT("\"") << std::endl; output << xT("\t\tend=\"") << segment->endPointIndex << xT("\"") << std::endl; QString name; if(!segment->road->names.isEmpty()) name += segment->road->names.cbegin().value(); /*String ref = res.getObject().getRef(); if (ref != null) { name += " (" + ref + ") "; }*/ output << xT("\t\tname=\"") << QStringToStlString(name) << xT("\"") << std::endl; output << xT("\t\ttime=\"") << segment->time << xT("\"") << std::endl; output << xT("\t\tdistance=\"") << segment->distance << xT("\"") << std::endl; /*float ms = res.getObject().getMaximumSpeed(); if(ms > 0) { additional.append("maxspeed = \"").append(ms * 3.6f).append("\" ").append(res.getObject().getHighway()).append(" "); }*/ /* if (res.getTurnType() != null) { additional.append("turn = \"").append(res.getTurnType()).append("\" "); additional.append("turn_angle = \"").append(res.getTurnType().getTurnAngle()).append("\" "); if (res.getTurnType().getLanes() != null) { additional.append("lanes = \"").append(Arrays.toString(res.getTurnType().getLanes())).append("\" "); } }*/ output << xT("\t\tstart_bearing=\"") << segment->getBearingBegin() << xT("\"") << std::endl; output << xT("\t\tend_bearing=\"") << segment->getBearingEnd() << xT("\"") << std::endl; //additional.append("description = \"").append(res.getDescription()).append("\" "); if(cfg.generateXml) output << xT("\t/>") << std::endl; else output << std::endl; if(gpxFile && gpxFile->isOpen()) { output << xT("\t\tstart=\"") << segment->startPointIndex << xT("\"") << std::endl; output << xT("\t\tend=\"") << segment->endPointIndex << xT("\"") << std::endl; for(auto pointIdx = segment->startPointIndex; pointIdx < segment->endPointIndex; pointIdx++) { const auto& point = segment->road->points[pointIdx]; *(gpxStream.get()) << "\t\t\t<trkpt lon=\"" << OsmAnd::Utilities::get31LongitudeX(point.x) << "\" lat=\"" << OsmAnd::Utilities::get31LatitudeY(point.y) << "\"/>\n"; } } } if(gpxFile && gpxFile->isOpen()) { *(gpxStream.get()) << "\t\t</trkseg>\n"; *(gpxStream.get()) << "\t</trk>\n"; *(gpxStream.get()) << "</gpx>\n"; gpxStream->flush(); gpxFile->close(); } if(cfg.generateXml) output << xT("</test>") << std::endl; }