Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rviz_common] fix loading of icon resources #56

Closed
wjwwood opened this issue Sep 27, 2017 · 3 comments · Fixed by #235
Closed

[rviz_common] fix loading of icon resources #56

wjwwood opened this issue Sep 27, 2017 · 3 comments · Fixed by #235
Labels
enhancement New feature or request

Comments

@wjwwood
Copy link
Member

wjwwood commented Sep 27, 2017

See:

  • // TODO(wjwwood): replace this with ROS 2 and boost-free version
    // boost::filesystem::path getPath(QString url)
    // {
    // boost::filesystem::path path;
    // if (url.indexOf("package://", 0, Qt::CaseInsensitive) == 0) {
    // QString package_name = url.section('/', 2, 2);
    // QString file_name = url.section('/', 3);
    // path = ros::package::getPath(package_name.toStdString());
    // path = path / file_name.toStdString();
    // } else if (url.indexOf("file://", 0, Qt::CaseInsensitive) == 0) {
    // path = url.section('/', 2).toStdString();
    // } else {
    // ROS_ERROR("Invalid or unsupported URL: '%s'", url.toStdString().c_str() );
    // }
    // return path;
    // }
  • // TODO(wjwwood): reenable this, or in the meantime add a placeholder pixmap
    Q_UNUSED(url);
    Q_UNUSED(fill_cache);
    // RVIZ_COMMON_LOG_WARNING_STREAM("did not load pixmap at " << url.toStdString());
    // // if it's in the cache, no need to locate
    // if (QPixmapCache::find(url, &pixmap) ) {
    // return pixmap;
    // }
    // boost::filesystem::path path = getPath(url);
    // // If something goes wrong here, we go on and store the empty pixmap,
    // // so the error won't appear again anytime soon.
    // if (boost::filesystem::exists(path) ) {
    // ROS_DEBUG_NAMED("load_resource", "Loading '%s'", path.string().c_str() );
    // if (!pixmap.load(QString::fromStdString(path.string() ) ) ) {
    // ROS_ERROR("Could not load pixmap '%s'", path.string().c_str() );
    // }
    // }
    // if (fill_cache) {
    // QPixmapCache::insert(url, pixmap);
    // }
  • // TODO(wjwwood): reenable this
    Q_UNUSED(url);
    Q_UNUSED(fill_cache);
    // RVIZ_COMMON_LOG_WARNING_STREAM("did not load icon as cursor at " << url.toStdString());
    return QCursor(Qt::ArrowCursor);
    #if 0
    QPixmap icon = loadPixmap(url, fill_cache);
    if (icon.width() == 0 || icon.height() == 0) {
    ROS_ERROR("Could not load pixmap '%s' -- using default cursor instead.",
    url.toStdString().c_str() );
    return getDefaultCursor();
    }
    QString cache_key = url + ".cursor";
    return makeIconCursor(icon, cache_key, fill_cache);
    #endif
  • // TODO(wjwwood): reenable this
    Q_UNUSED(icon);
    Q_UNUSED(cache_key);
    Q_UNUSED(fill_cache);
    // RVIZ_COMMON_LOG_WARNING_STREAM("did not make icon into cursor at " << cache_key.toStdString());
    return QCursor(Qt::ArrowCursor);
    #if 0
    // if it's in the cache, no need to locate
    QPixmap cursor_img;
    if (QPixmapCache::find(cache_key, &cursor_img) ) {
    return QCursor(cursor_img, 0, 0);
    }
    QPixmap base_cursor = loadPixmap("package://rviz/icons/cursor.svg", fill_cache);
    const int cursor_size = 32;
    cursor_img = QPixmap(cursor_size, cursor_size);
    cursor_img.fill(QColor(0, 0, 0, 0) );
    // copy base cursor & icon into one image
    QPainter painter(&cursor_img);
    int draw_x = 12;
    int draw_y = 16;
    // if the icon is too large, move it to the left
    if (draw_x + icon.width() > cursor_size) {
    draw_x = cursor_size - icon.width();
    }
    if (draw_y + icon.height() > cursor_size) {
    draw_y = cursor_size - icon.height();
    }
    painter.drawPixmap(0, 0, base_cursor);
    painter.drawPixmap(draw_x, draw_y, icon);
    if (fill_cache) {
    QPixmapCache::insert(cache_key, cursor_img);
    }
    return QCursor(cursor_img, 1, 1);
    #endif

This will probably be solved with a combination of either ament_index_cpp (to have a relocatable solution to finding the files at runtime) and QDir/QFile/QFileInfo to replace boost::filesystem.

@wjwwood wjwwood added the enhancement New feature or request label Sep 27, 2017
@greimela-si
Copy link
Contributor

Will this use the resource_retriever from #51 or should ament_index_cpp be used directly?

@wjwwood
Copy link
Member Author

wjwwood commented Sep 28, 2017

Will this use the resource_retriever from #51 or should ament_index_cpp be used directly?

We should use resource_retriever if possible. If resource_retriever gives us a file:// back from a package:// then we can use that directly. Otherwise we'll have to let resource_retriever open the file and see if QPixmap has a version of .load() that takes a buffer/file-like object instead of a path.

@wjwwood
Copy link
Member Author

wjwwood commented Dec 5, 2017

This should be reevaluated after #123 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants