示例#1
0
void PoseSeq::store(Mapping& archive, const BodyPtr body) const
{
    archive.write("type", "PoseSeq");
    archive.write("name", name(), DOUBLE_QUOTED);
    archive.write("targetBody", body->name(), DOUBLE_QUOTED);

    Listing& refsNode = *archive.createListing("refs");
    
    for(PoseRefList::const_iterator p = refs.begin(); p != refs.end(); ++p){
        const PoseRef& ref = *p;
        MappingPtr refNode = refsNode.newMapping();
        refNode->write("time", ref.time());
        if(ref.maxTransitionTime() > 0.0){
            refNode->write("maxTransitionTime", ref.maxTransitionTime());
        }
        const string& name = ref.name();
        if((storedNames.find(name) == storedNames.end() /* && !ref.isExternalReference()*/) ||
           name.empty()){
            const_cast<PoseSeq*>(this)->storedNames.insert(name);
            MappingPtr childNode = refNode->createMapping("refer");
            ref.poseUnit()->store(*childNode, body);
        } else {
            refNode->write("refer", name, DOUBLE_QUOTED);
        }
    }
}
示例#2
0
LinkPropertyViewImpl::LinkPropertyViewImpl(LinkPropertyView* self)
    : self(self)
{
    linkSelectionView = LinkSelectionView::mainInstance();
    
    setFrameShape(QFrame::NoFrame);
    setColumnCount(2);
    setSelectionBehavior(QAbstractItemView::SelectRows);
    setSelectionMode(QAbstractItemView::NoSelection);

    QHeaderView* hh = horizontalHeader();
    QHeaderView* vh = verticalHeader();
    hh->hide();
    vh->hide();
    hh->setSectionResizeMode(QHeaderView::Stretch);
    vh->setSectionResizeMode(QHeaderView::ResizeToContents);
    hh->setStretchLastSection(true);

    fontPointSizeDiff = 0;
    MappingPtr config = AppConfig::archive()->openMapping("LinkPropertyView");
    int storedFontPointSizeDiff;
    if(config->read("fontZoom", storedFontPointSizeDiff)){
        zoomFontSize(storedFontPointSizeDiff);
    }

    connections.add(
        BodyBar::instance()->sigCurrentBodyItemChanged().connect(
            std::bind(&LinkPropertyViewImpl::onCurrentBodyItemChanged, this, _1)));

    connections.add(
        linkSelectionView->sigSelectionChanged().connect(
            std::bind(&LinkPropertyViewImpl::updateProperties, this)));
}
示例#3
0
bool EditableSceneBodyImpl::storeProperties(Archive& archive)
{
    ListingPtr states = new Listing();

    ItemList<BodyItem> bodyItems;
    bodyItems.extractChildItems(RootItem::instance());
    
    for(size_t i=0; i < bodyItems.size(); ++i){
        BodyItem* bodyItem = bodyItems[i];
        EditableSceneBody* sceneBody = bodyItem->existingSceneBody();
        if(sceneBody){
            ValueNodePtr id = archive.getItemId(bodyItem);
            if(id){
                EditableSceneBodyImpl* impl = sceneBody->impl;
                MappingPtr state = new Mapping();
                state->insert("bodyItem", id);
                state->write("showCenterOfMass", impl->isCmVisible);
                state->write("showZmp", impl->isZmpVisible);
                states->append(state);
            }
        }
    }
    if(!states->empty()){
        archive.insert("editableSceneBodies", states);
        return true;
    }
    return false;
}
示例#4
0
SgNode* YAMLSceneLoaderImpl::load(const std::string& filename)
{
    SgNodePtr scene;
    MappingPtr topNode;
    
    try {
        YAMLReader reader;
        topNode = reader.loadDocument(filename)->toMapping();
        if(topNode){
            boost::filesystem::path filepath(filename);
            sceneReader.setBaseDirectory(filepath.parent_path().string());
            sceneReader.readHeader(*topNode);
            ValueNodePtr sceneElements = topNode->findMapping("scene");
            if(!sceneElements->isValid()){
                os() << format(_("Scene file \"{}\" does not have the \"scene\" node."), filename) << endl;
            } else {
                scene = sceneReader.readNodeList(*sceneElements);
                if(!scene){
                    os() << format(_("Scene file \"{}\" is an empty scene."), filename) << endl;
                    scene = new SgNode;
                }
            }
        }
    } catch(const ValueNode::Exception& ex){
        os() << ex.message();
    }

    os().flush();

    sceneReader.clear();
    
    return scene.retn();
}
示例#5
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();
}
示例#6
0
void View::enableFontSizeZoomKeys(bool on)
{
    isFontSizeZoomKeysEnabled = on;
    if(on){
        MappingPtr config = AppConfig::archive()->openMapping(viewClass()->className());
        int storedZoom;
        if(config->read("fontZoom", storedZoom)){
            zoomFontSize(storedZoom);
        }
    }
}
示例#7
0
bool PoseSeq::save(const std::string& filename, const BodyPtr body)
{
    YAMLWriter writer(filename);
    writer.setKeyOrderPreservationMode(true);
    storedNames.clear();
    MappingPtr archive = new Mapping();
    archive->setDoubleFormat("%.9g");
    store(*archive, body);
    writer.putComment("Body pose sequence format version 1.0 defined by cnoid-Robotics\n");
    writer.putNode(archive);
    return true;
}
SceneGraphPropertyViewImpl::SceneGraphPropertyViewImpl(SceneGraphPropertyView* self)
    : self(self)
{
    tableWidget = new CustomizedTableWidget(self);
    tableWidget->setFrameShape(QFrame::NoFrame);
    tableWidget->setColumnCount(2);
    tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableWidget->setSelectionMode(QAbstractItemView::NoSelection);

    tableWidget->horizontalHeader()->hide();
    tableWidget->horizontalHeader()->setStretchLastSection(true);

    tableWidget->verticalHeader()->hide();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    tableWidget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#else
    tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif

    QStyledItemDelegate* delegate = new CustomizedItemDelegate(tableWidget);
    QItemEditorFactory* factory = new QItemEditorFactory;
    
    QItemEditorCreatorBase* selectionListCreator =
        new QStandardItemEditorCreator<SelectionListEditor>();
    factory->registerEditor(QVariant::StringList, selectionListCreator);
    
    delegate->setItemEditorFactory(factory);

    tableWidget->setItemDelegate(delegate);

    QVBoxLayout* layout = new QVBoxLayout();
    layout->addWidget(tableWidget);
    self->setLayout(layout);
    
    self->sigActivated().connect(std::bind(&SceneGraphPropertyViewImpl::onActivated, this, true));
    self->sigDeactivated().connect(std::bind(&SceneGraphPropertyViewImpl::onActivated, this ,false));

    currentObject = 0;

    fontPointSizeDiff = 0;
    MappingPtr config = AppConfig::archive()->openMapping("SceneGraphPropertyView");
    int storedFontPointSizeDiff;
    if(config->read("fontZoom", storedFontPointSizeDiff)){
        zoomFontSize(storedFontPointSizeDiff);
    }
}
示例#9
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;
    }
}
示例#10
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();
}
示例#11
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();
    }
}
示例#12
0
MappingPtr ViewAreaImpl::storePaneState(ViewPane* pane, Archive* archive)
{
    MappingPtr state = new Mapping();
    
    state->write("type", "pane");
    
    Listing* views = state->createFlowStyleListing("views");
    const int n = pane->count();
    for(int i=0; i < n; ++i){
        View* view = pane->view(i);
        int id = archive->getViewId(view);
        if(id >= 0){
            views->append(id);
            if(i == pane->currentIndex()){
                state->write("current", id);
            }
        }
    }
    if(views->empty()){
        state.reset();
    }
    return state;
}
示例#13
0
MappingPtr ViewAreaImpl::storeSplitterState(QSplitter* splitter, Archive* archive)
{
    MappingPtr state = new Mapping;

    ListingPtr children = new Listing;

    for(int i=0; i < splitter->count(); ++i){
        QSplitter* childSplitter = dynamic_cast<QSplitter*>(splitter->widget(i));
        if(childSplitter){
            MappingPtr childState = storeSplitterState(childSplitter, archive);
            if(childState){
                children->append(childState);
            }
        } else {
            ViewPane* pane = dynamic_cast<ViewPane*>(splitter->widget(i));
            if(pane && pane->count() > 0){
                MappingPtr childState = storePaneState(pane, archive);
                if(childState){
                    children->append(childState);
                }
            }
        }
    }

    const int numChildren = children->size();
    if(numChildren == 0){
        state.reset();
    } else if(numChildren == 1){
        state = children->at(0)->toMapping();
    } else if(numChildren == 2){
        state->write("type", "splitter");
        state->write("orientation", (splitter->orientation() == Qt::Vertical) ? "vertical" : "horizontal");
        Listing* sizeSeq = state->createFlowStyleListing("sizes");
        QList<int> sizes = splitter->sizes();
        for(int i=0; i < sizes.size(); ++i){
            sizeSeq->append(sizes[i]);
        }
        state->insert("children", children);
    }

    return state;
}
示例#14
0
bool BodyLoaderImpl::load(Body* body, const std::string& filename)
{
    bool result = false;

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

    try {
        if(ext != "yaml"){
            modelFilename = filename;
        } else {
            YAMLReader parser;
            yamlDoc = parser.loadDocument(filename)->toMapping();

            ValueNode* modelFileNode = yamlDoc->find("modelFile");
            if(modelFileNode->isValid()){
                filesystem::path mpath(modelFileNode->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);

            YAMLBodyLoader* yamlBodyLoader = 0;
            if(yamlDoc){
                YAMLBodyLoader* yamlBodyLoader = dynamic_cast<YAMLBodyLoader*>(loader.get());
            }

            if(yamlBodyLoader){
                result = yamlBodyLoader->read(body, yamlDoc);

            } else {
                int dn = defaultDivisionNumber;
                if(yamlDoc){
                    Mapping& geometryInfo = *yamlDoc->findMapping("geometry");
                    if(geometryInfo.isValid()){
                        geometryInfo.read("divisionNumber", dn);
                    }
                }
                if(dn > 0){
                    loader->setDefaultDivisionNumber(dn);
                }

                if(defaultCreaseAngle >= 0.0){
                    loader->setDefaultCreaseAngle(defaultCreaseAngle);
                }
            
                if(yamlDoc){
                    body->resetInfo(yamlDoc);
                } 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;
}
示例#15
0
ItemTreeViewImpl::ItemTreeViewImpl(ItemTreeView* self, RootItem* rootItem, bool showRoot)
    : self(self),
      rootItem(rootItem)
{
    using boost::bind;
    
    isProceccingSlotForRootItemSignals = 0;
    isDropping = false;
    
    setColumnCount(1);

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    header()->setResizeMode(0, QHeaderView::Stretch);
    header()->setMinimumSectionSize(0);
#else
    header()->setSectionResizeMode(0, QHeaderView::Stretch);
    //header()->setMinimumSectionSize(0);
#endif

    // default check column
    addCheckColumn();
    header()->setStretchLastSection(false);
    header()->swapSections(0, 1);

    setWordWrap(true);
    setFrameShape(QFrame::NoFrame);
    setHeaderHidden(true);
    setIndentation(12);
    setSelectionMode(QAbstractItemView::ExtendedSelection);
    setDragDropMode(QAbstractItemView::InternalMove);

    sigItemSelectionChanged().connect(bind(&ItemTreeViewImpl::onSelectionChanged, this));

    connectionsFromRootItem.add(
        rootItem->sigSubTreeAdded().connect(bind(&ItemTreeViewImpl::onSubTreeAddedOrMoved, this, _1)));
    connectionsFromRootItem.add(
        rootItem->sigSubTreeMoved().connect(bind(&ItemTreeViewImpl::onSubTreeAddedOrMoved, this, _1)));
    connectionsFromRootItem.add(
        rootItem->sigSubTreeRemoved().connect(bind(&ItemTreeViewImpl::onSubTreeRemoved, this, _1, _2)));
    connectionsFromRootItem.add(
        rootItem->sigTreeChanged().connect(bind(&ItemTreeViewImpl::onTreeChanged, this)));
    connectionsFromRootItem.add(
        rootItem->sigItemAssigned().connect(bind(&ItemTreeViewImpl::onItemAssigned, this, _1, _2)));

    QObject::connect(model(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)),
                     self, SLOT(onRowsAboutToBeRemoved(const QModelIndex&, int, int)));
    QObject::connect(model(), SIGNAL(rowsInserted(const QModelIndex&, int, int)),
                     self, SLOT(onRowsInserted(const QModelIndex&, int, int)));

    popupMenu = new Menu(this);
    menuManager.setTopMenu(popupMenu);

    menuManager.addItem(_("Cut"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::cutSelectedItems, this));
    menuManager.addItem(_("Copy (single)"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::copySelectedItems, this));
    menuManager.addItem(_("Copy (sub tree)"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::copySelectedItemsWithChildren, this));
    menuManager.addItem(_("Paste"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::pasteItems, this));

    menuManager.addSeparator();
    menuManager.addItem(_("Check"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::checkSelectedItems, this, true));
    menuManager.addItem(_("Uncheck"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::checkSelectedItems, this, false));
    menuManager.addItem(_("Toggle checks"))
        ->sigTriggered().connect(bind(&ItemTreeViewImpl::toggleSelectedItemChecks, this));

    menuManager.addSeparator();
    menuManager.addItem(_("Select all"))
        ->sigTriggered().connect(bind(&ItemTreeView::selectAllItems, self));
    menuManager.addItem(_("Clear selection"))
        ->sigTriggered().connect(bind(&ItemTreeView::clearSelection, self));
    
    fontPointSizeDiff = 0;
    MappingPtr config = AppConfig::archive()->openMapping("ItemTreeView");
    int storedFontPointSizeDiff;
    if(config->read("fontZoom", storedFontPointSizeDiff)){
        zoomFontSize(storedFontPointSizeDiff);
    }
}