Example #1
0
/**
   \note A pointer returned by archive() must be replaced with a new one
   when a new config is loaed.
*/
Mapping* AppConfig::archive()
{
    if(pYAMLReader && pYAMLReader->numDocuments()){
        return pYAMLReader->document()->toMapping();
    }
    static MappingPtr appArchive(new Mapping);
    return appArchive.get();
}
Example #2
0
void CaptureBar::initialize(ExtensionManager* ext)
{
    static bool initialized = false;
    if(!initialized){
        ext->addToolBar(instance());

        MenuManager& mm = ext->menuManager();
        MappingPtr config = AppConfig::archive()->openMapping("CaptureBar");
        mm.setPath("/Options").setPath(N_("Capture Bar"));
        
        includeTabCheck = mm.addCheckItem(_("Include Tab"));
        includeTabCheck->setChecked(config->get("includeTab", false));
        includeTabCheck->sigToggled().connect(onIncludeTabToggled);
        
        lastCaptureWidget = 0;
        
        initialized = true;
    }
}
Example #3
0
PluginManagerImpl::PluginManagerImpl(ExtensionManager* ext)
    : mv(MessageView::mainInstance())
{
    pluginNamePattern.setPattern(QString(DLL_PREFIX) + "Cnoid.+Plugin" + DEBUG_SUFFIX + "\\." + DLL_SUFFIX);

    MappingPtr config = AppConfig::archive()->openMapping("PluginManager");

    // for the base module
    PluginInfoPtr info = boost::make_shared<PluginInfo>();
    info->name = "Base";
    nameToPluginInfoMap.insert(make_pair(string("Base"), info));

    MenuManager& mm = ext->menuManager();
    mm.setPath("/File");
    mm.addItem(_("Load Plugin"))
        ->sigTriggered().connect(boost::bind(&PluginManagerImpl::onLoadPluginTriggered, this));

    startupLoadingCheck = mm.addCheckItem(_("Startup Plugin Loading"));
    startupLoadingCheck->setChecked(config->get("startupPluginLoading", true));
    
    mm.addSeparator();
}
Example #4
0
void PluginManagerImpl::onLoadPluginTriggered()
{
    QFileDialog dialog(MainWindow::instance());
    dialog.setWindowTitle(_("Load plugins"));
    dialog.setFileMode(QFileDialog::ExistingFiles);
    dialog.setViewMode(QFileDialog::List);
    dialog.setLabelText(QFileDialog::Accept, _("Open"));
    dialog.setLabelText(QFileDialog::Reject, _("Cancel"));

    QStringList filters;
    filters << QString(_("Plugin files (*.%1)")).arg(DLL_SUFFIX);
    filters << _("Any files (*)");
    dialog.setNameFilters(filters);

    MappingPtr config = AppConfig::archive()->openMapping("PluginManager");
    dialog.setDirectory(config->get("pluginLoadingDialogDirectory", executableTopDirectory()).c_str());
    
    if(dialog.exec()){
        config->writePath("pluginLoadingDialogDirectory", dialog.directory().absolutePath().toStdString());
        QStringList filenames = dialog.selectedFiles();
        for(int i=0; i < filenames.size(); ++i){
            string filename = getNativePathString(filesystem::path(filenames[i].toStdString()));

            // This code was taken from 'scanPluginFiles'. This should be unified.
            //if(pluginNamePattern.exactMatch(QString(getFilename(pluginPath).c_str()))){
            if(true){
                PluginMap::iterator p = pathToPluginInfoMap.find(filename);
                if(p == pathToPluginInfoMap.end()){
                    PluginInfoPtr info(new PluginInfo);
                    info->pathString = filename;
                    allPluginInfos.push_back(info);
                    pathToPluginInfoMap[filename] = info;
                }
            }
        }
        loadPlugins();
    }
}
Example #5
0
bool BodyLoaderImpl::load(BodyPtr& body, const std::string& filename)
{
    bool result = false;

    filesystem::path orgpath(filename);
    string ext = getExtension(orgpath);
    string modelFilename;
    MappingPtr info;

    try {
        if(ext != "yaml"){
            modelFilename = filename;
        } else {
            YAMLReader parser;
            info = parser.loadDocument(filename)->toMapping();
            filesystem::path mpath(info->get("modelFile").toString());
            if(mpath.has_root_path()){
                modelFilename = getNativePathString(mpath);
            } else {
                modelFilename = getNativePathString(orgpath.parent_path() / mpath);
            }
            ext = getExtension(mpath);
        }

        LoaderMap::iterator p = loaderMap.find(ext);
        if(p != loaderMap.end()){
            loader = p->second;
        } else {
            boost::lock_guard<boost::mutex> lock(loaderFactoryMapMutex);
            LoaderFactoryMap::iterator q = loaderFactoryMap.find(ext);
            if(q != loaderFactoryMap.end()){
                LoaderFactory factory = q->second;
                loader = factory();
                loaderMap[ext] = loader;
            }
        }

        if(!loader){
            (*os) << str(boost::format(_("The file format of \"%1%\" is not supported by the body loader.\n"))
                         % getFilename(filesystem::path(modelFilename)));

        } else {
            loader->setMessageSink(*os);
            loader->setVerbose(isVerbose);
            loader->setShapeLoadingEnabled(isShapeLoadingEnabled);
            
            int dn = defaultDivisionNumber;
            if(info){
                Mapping& geometryInfo = *info->findMapping("geometry");
                if(geometryInfo.isValid()){
                    geometryInfo.read("divisionNumber", dn);
                }
            }
            if(dn > 0){
                loader->setDefaultDivisionNumber(dn);
            }

            if(defaultCreaseAngle >= 0.0){
                loader->setDefaultCreaseAngle(defaultCreaseAngle);
            }
            
            body->clearDevices();
            body->clearExtraJoints();
            if(info){
                body->resetInfo(info.get());
            } else {
                body->info()->clear();
            }

            result = loader->load(body, modelFilename);
        }
        
    } catch(const ValueNode::Exception& ex){
        (*os) << ex.message();
    } catch(const nonexistent_key_error& error){
        if(const std::string* message = boost::get_error_info<error_info_message>(error)){
            (*os) << *message;
        }
    } catch(const std::exception& ex){
        (*os) << ex.what();
    }
    os->flush();
    
    return result;
}