Esempio n. 1
0
    std::shared_ptr<const CityModel> load( const std::string& fname, const ParserParams& params , std::shared_ptr<CityGMLLogger> logger)
    {
        if (!logger) {
            logger = std::make_shared<StdLogger>();
        }

        if (!initXerces(logger)) {
            return nullptr;
        }

        std::shared_ptr<XMLCh> fileName = toXercesString(fname);

#ifdef NDEBUG
        try {
#endif
            xercesc::LocalFileInputSource fileSource(fileName.get());
            return parse(fileSource, params, logger, fname);
#ifdef NDEBUG
        } catch (xercesc::XMLException& e) {
            CITYGML_LOG_ERROR(logger, "Error parsing file " << fname << ": " << e.getMessage());
            return nullptr;
        }
#endif

    }
bool FileSystemManager::copyFile(QString source, QString target, qint64 totalSize, bool cut)
{
    QFile fileSource(source);
    QFile fileTarget(target);

    fileSource.open(QFile::ReadOnly);
    fileTarget.open(QFile::WriteOnly);

    char block[BLOCK_SIZE];
    qint64 total = fileSource.size();
    qint64 steps = total >> 7;        //shift right 7, same as divide 128, much faster
    qint64 bytesCopied = 0;

    while(!fileSource.atEnd())
    {
        if(m_cancel)
            break;

        qint64 inBytes = fileSource.read(block, sizeof(block));
        fileTarget.write(block, inBytes);
        bytesCopied += inBytes;

        if(bytesCopied > steps)
        {
            emit updateCopyProgress(target, bytesCopied, totalSize);
            bytesCopied = 0;
        }
    }

    emit updateCopyProgress(target, bytesCopied, totalSize);

    fileTarget.close();
    fileSource.close();

    if(fileTarget.size() != total)
        return false;

    if(cut)
        fileSource.remove();  //if file is cut remove the source

    return true;
}
void QgsBinaryWidgetWrapper::setContent()
{
  QgsSettings s;
  QString file = QFileDialog::getOpenFileName( nullptr,
                 tr( "Embed File" ),
                 defaultPath(),
                 tr( "All files" ) + " (*.*)" );
  QFileInfo fi( file );
  if ( file.isEmpty() || !fi.exists() )
  {
    return;
  }

  s.setValue( QStringLiteral( "/UI/lastBinaryDir" ), fi.absolutePath() );

  QFile fileSource( file );
  if ( !fileSource.open( QIODevice::ReadOnly ) )
  {
    return;
  }

  setValue( fileSource.readAll() );
  emitValueChanged();
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
    int fullscreen_flag = 0;
    std::string style;

    const struct option long_options[] = {
        {"fullscreen", no_argument, &fullscreen_flag, 'f'},
        {"style", required_argument, 0, 's'},
        {0, 0, 0, 0}
    };

    while (true) {
        int option_index = 0;
        int opt = getopt_long(argc, argv, "fs:", long_options, &option_index);
        if (opt == -1) break;
        switch (opt)
        {
        case 0:
            if (long_options[option_index].flag != 0)
                break;
        case 'f':
            // handle fullscreen_flag
            break;
        case 's':
            style = std::string("asset://") + std::string(optarg);
        default:
            break;
        }

    }

    // sigint handling
    struct sigaction sigIntHandler;
    sigIntHandler.sa_handler = quit_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(SIGINT, &sigIntHandler, NULL);

    view = mbgl::util::make_unique<GLFWView>();

    mbgl::SQLiteCache cache("/tmp/mbgl-cache.db");
    mbgl::DefaultFileSource fileSource(&cache);
    mbgl::Map map(*view, fileSource);

    // Load settings
    mbgl::Settings_JSON settings;
    map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
    map.setBearing(settings.bearing);
    map.setDebug(settings.debug);

    // Set access token if present
    const char *token = getenv("MAPBOX_ACCESS_TOKEN");
    if (token == nullptr) {
        mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work.");
    } else {
        map.setAccessToken(std::string(token));
    }

    // Load style
    if (style.empty()) {
        style = std::string("asset://") + std::string("styles/bright-v7.json");
    }

    map.setStyleURL(style);

    int ret = view->run();

    // Save settings
    mbgl::LatLng latLng = map.getLatLng();
    settings.latitude = latLng.latitude;
    settings.longitude = latLng.longitude;
    settings.zoom = map.getZoom();
    settings.bearing = map.getBearing();
    settings.debug = map.getDebug();
    settings.save();

    return ret;
}
Esempio n. 5
0
int main(int argc, char *argv[]) {
    bool fullscreen = false;
    bool benchmark = false;
    std::string style;
    double latitude = 0, longitude = 0;
    double bearing = 0, zoom = 1, pitch = 0;
    bool skipConfig = false;

    const struct option long_options[] = {
        {"fullscreen", no_argument, 0, 'f'},
        {"benchmark", no_argument, 0, 'b'},
        {"style", required_argument, 0, 's'},
        {"lon", required_argument, 0, 'x'},
        {"lat", required_argument, 0, 'y'},
        {"zoom", required_argument, 0, 'z'},
        {"bearing", required_argument, 0, 'r'},
        {"pitch", required_argument, 0, 'p'},
        {0, 0, 0, 0}
    };

    while (true) {
        int option_index = 0;
        int opt = getopt_long(argc, argv, "fbs:", long_options, &option_index);
        if (opt == -1) break;
        switch (opt)
        {
        case 0:
            if (long_options[option_index].flag != 0)
                break;
        case 'f':
            fullscreen = true;
            break;
        case 'b':
            benchmark = true;
            break;
        case 's':
            style = std::string("asset://") + std::string(optarg);
            break;
        case 'x':
            longitude = atof(optarg);
            skipConfig = true;
            break;
        case 'y':
            latitude = atof(optarg);
            skipConfig = true;
            break;
        case 'z':
            zoom = atof(optarg);
            skipConfig = true;
            break;
        case 'r':
            bearing = atof(optarg);
            skipConfig = true;
            break;
        case 'p':
            pitch = atof(optarg);
            skipConfig = true;
            break;
        default:
            break;
        }

    }

    // sigint handling
    struct sigaction sigIntHandler;
    sigIntHandler.sa_handler = quit_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(SIGINT, &sigIntHandler, NULL);

    if (benchmark) {
        mbgl::Log::Info(mbgl::Event::General, "BENCHMARK MODE: Some optimizations are disabled.");
    }

    view = std::make_unique<GLFWView>(fullscreen, benchmark);

    mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db", ".");
    fileSource.setMaximumCacheEntrySize(1 * 1024 * 1024); // 1 MB
    fileSource.setMaximumCacheSize(50 * 1024 * 1024); // 50 MB

    // Set access token if present
    const char *token = getenv("MAPBOX_ACCESS_TOKEN");
    if (token == nullptr) {
        mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work.");
    } else {
        fileSource.setAccessToken(std::string(token));
    }

    mbgl::Map map(*view, fileSource);

    // Load settings
    mbgl::Settings_JSON settings;

    if (skipConfig) {
        map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
        map.setBearing(bearing);
        map.setPitch(pitch);
        mbgl::Log::Info(mbgl::Event::General, "Location: %f/%f (z%.2f, %.2f deg)", latitude, longitude, zoom, bearing);
    } else {
        map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
        map.setBearing(settings.bearing);
        map.setPitch(settings.pitch);
        map.setDebug(mbgl::MapDebugOptions(settings.debug));
    }

    view->setChangeStyleCallback([&map] () {
        static uint8_t currentStyleIndex;

        if (++currentStyleIndex == mbgl::util::default_styles::numOrderedStyles) {
            currentStyleIndex = 0;
        }

        mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[currentStyleIndex];
        map.setStyleURL(newStyle.url);
        view->setWindowTitle(newStyle.name);

        mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.name);
    });

    // Load style
    if (style.empty()) {
        mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[0];
        style = newStyle.url;
        view->setWindowTitle(newStyle.name);
    }

    map.setStyleURL(style);

    view->run();

    // Save settings
    mbgl::LatLng latLng = map.getLatLng();
    settings.latitude = latLng.latitude;
    settings.longitude = latLng.longitude;
    settings.zoom = map.getZoom();
    settings.bearing = map.getBearing();
    settings.pitch = map.getPitch();
    settings.debug = mbgl::EnumType(map.getDebug());
    if (!skipConfig) {
        settings.save();
    }
    mbgl::Log::Info(mbgl::Event::General,
                    "Exit location: --lat=\"%f\" --lon=\"%f\" --zoom=\"%f\" --bearing \"%f\"",
                    settings.latitude, settings.longitude, settings.zoom, settings.bearing);

    return 0;
}
Esempio n. 6
0
  void MapboxRenderer::render()
  {
    bool debug = false;

    std::string token_path = "/sdcard/gisrenderer/mapbox-token.txt";
    std::string style_path = "/sdcard/gisrenderer/mapbox-basic-style.json";
    std::string cache_file = "/sdcard/gisrenderer/cache.sqlite";
    std::string asset_root = ".";
//    static std::string output = "/sdcard/out.png";

//    double lat = 0, lon = 0;
//    double zoom = 0;
    double lat = 55.7522200, lon = 37.6155600; // Moscow
    double zoom = 11;
    double bearing = 0;
    double pitch = 0;

    float pixelRatio = 1.0;

    std::vector <std::string> classes;
    mbgl::util::RunLoop loop;

    std::string token = read_file(token_path);
    std::string style = read_file(style_path);

    mbgl::DefaultFileSource fileSource(cache_file, asset_root);

    // Set access token if present
    if (token.size()) {
      fileSource.setAccessToken(std::string(token));
    }

    mbgl::HeadlessView view(pixelRatio, mImageWidth, mImageHeight);
    mbgl::Map map(view, fileSource, mbgl::MapMode::Still);

    map.setStyleJSON(style, ".");
    map.setClasses(classes);

    map.setLatLngZoom({lat, lon}, zoom);
    map.setBearing(bearing);
    map.setPitch(pitch);

    if (debug) {
      map.setDebug(
          debug
              ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus
              : mbgl::MapDebugOptions::NoDebug);
    }

    map.renderStill(
        [&](
            std::exception_ptr error,
            mbgl::PremultipliedImage&& image)
        {
          try {
            if (error) {
              std::rethrow_exception(error);
            }
          } catch (std::exception& e) {
            mbgl::Log::Error(mbgl::Event::Render, "Error: %s", e.what());
            exit(1);
          }

//          write_file(output, mbgl::encodePNG(image));
          std::memcpy(mpImageData, image.data.get(), image.size());
          loop.stop();
        });

    loop.run();
  }