Пример #1
0
void SoNodeToName::evaluate()
{   
    // make room as necessary
    SO_ENGINE_OUTPUT(output, SoMFString, setNum(input.getNum()));
    int next = 0;
    for( int i = 0; i < input.getNum(); i++ )
    {
        SoNode * node = input[i];
        if( node == NULL || node->getName() == "" )
        {
            if(  compact.getValue() == FALSE )
            {
                SO_ENGINE_OUTPUT(output, SoMFString, set1Value(next, ""));
                next++;
            }
        }
        else
        {
            SO_ENGINE_OUTPUT(output, SoMFString, set1Value(next, node->getName().getString()));
            next++;
        }        
    }
    // truncate as necessary
    SO_ENGINE_OUTPUT(output, SoMFString, setNum(next));
}
void printPath(const SoPath* p)
{
    for (int i = p->getLength() - 1; i >= 0;  --i)
    {
        SoNode * n = p->getNode(i);
        std::string name = n->getName().getString();
        ROS_INFO("Path[%i]: %s, type %s",i,name.c_str(),n->getTypeId().getName().getString());
    }
}
Пример #3
0
/**
 * Takes the name of the selected node and sets to de editor to display it.
 */
void NodeNameDelegate::setEditorData(QWidget *editor,
                                     const QModelIndex &index) const
{
    const SceneModel* model = static_cast< const SceneModel* >( index.model() );

    QString value = model->data(index, Qt::DisplayRole).toString();

    QLineEdit  *textEdit = static_cast<QLineEdit *>(editor);

    SoNode* coinNode = model->NodeFromIndex( index )->GetNode();

    QString nodeName;
    if ( coinNode->getName() == SbName() )
        nodeName = QString( coinNode->getTypeId().getName().getString() );
    else
        nodeName = QString( coinNode->getName().getString() );

    textEdit->setText( nodeName );

}
void SceneModel::setNode(QModelIndex index, SoNode* node)
{
    this->setData(index, QVariant(QString::fromLatin1(node->getTypeId().getName())));
    if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
        SoGroup *group = static_cast<SoGroup*>(node);
        // insert SoGroup icon
        this->insertColumns(0,2,index);
        this->insertRows(0,group->getNumChildren(), index);
        for (int i=0; i<group->getNumChildren();i++) {
            SoNode* child = group->getChild(i);
            setNode(this->index(i, 0, index), child);
            // See ViewProviderDocumentObject::updateData
            QByteArray name(child->getName());
            name = QByteArray::fromPercentEncoding(name);
            this->setData(this->index(i, 1, index), QVariant(QString::fromUtf8(name)));
        }
    }
    // insert icon
}
Пример #5
0
int
ModList::findToken(const SoPath *path)
{
    SoNode	*node = NULL;
    char	*str = NULL;
    int		id = -1;
    int		i;
    char	c;

    for (i = path->getLength() - 1; i >= 0; --i) {
        node = path->getNode(i);
        str = (char *)(node->getName().getString());
        if (strlen(str) && str[0] == theModListId) {
	    sscanf(str, "%c%d", &c, &id);
	    break;
	}
    }

    return id;
}
SoNode * InventorViewer::getIntStr(const std::string& sscanfStr, const SoPath * path, std::string& extStr, int& extNum, int& pathIdx)
{
    if (path->getLength()==0) return NULL;
    for (int i = path->getLength() - 1; i >= 0;  --i)
    {
        SoNode * n = path->getNode(i);
        std::string name = n->getName().getString();
        
        //ROS_INFO("Path[%i]: %s, type %s",i,name.c_str(),n->getTypeId().getName().getString());

        char ln[1000];
        int num;
        if (sscanf(name.c_str(), sscanfStr.c_str(), &num, ln) < 2) continue;
        // ROS_INFO("num: %i rest: %s\n",num,ln);
        extStr = ln; //urdf2inventor::helpers::getFilename(ln); // take only the name after the last '/'
        extNum = num;
        pathIdx = i;
        return n;
    }
    return NULL;
}
Пример #7
0
void SceneModel::setNode(QModelIndex index, SoNode* node)
{
    this->setData(index, QVariant(QString::fromLatin1(node->getTypeId().getName())));
    if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
        SoGroup *group = static_cast<SoGroup*>(node);
        // insert SoGroup icon
        this->insertColumns(0,2,index);
        this->insertRows(0,group->getNumChildren(), index);
        for (int i=0; i<group->getNumChildren();i++) {
            SoNode* child = group->getChild(i);
            setNode(this->index(i, 0, index), child);

            QHash<SoNode*, QString>::iterator it = nodeNames.find(child);
            if (it != nodeNames.end()) {
                this->setData(this->index(i, 1, index), QVariant(it.value()));
            }
            else {
                this->setData(this->index(i, 1, index), QVariant(QString::fromLatin1(child->getName())));
            }
        }
    }
    // insert icon
}
Пример #8
0
void
InvAnnoManager::selectionCB(void *me, SoPath *selectedObject)
{
    InvAnnoManager *mee = static_cast<InvAnnoManager *>(me);

    mee->initCheck();

    if (!mee->isActive_)
        return;

    int isAnnoFlg = 0;

    int len = selectedObject->getLength();
    int ii;
    char *selObjNm;

    SoNode *obj = NULL;
    int objIndex;

    int mode = mee->mode_;

    // we find out if the selected obj is a InvAnnotationFlag
    // and obtain its index from the name of the (sub)-toplevel
    // separator node
    for (ii = 0; ii < len; ii++)
    {
        obj = selectedObject->getNode(ii);
        char *tmp = (char *)obj->getName().getString();
        selObjNm = new char[1 + strlen(tmp)];
        char *chNum = new char[1 + strlen(tmp)];
        strcpy(selObjNm, tmp);
        if (strncmp(selObjNm, "ANNOTATION", 10) == 0)
        {
            strcpy(chNum, &selObjNm[11]);
            int ret = sscanf(chNum, "%d", &objIndex);
            if (ret != 1)
            {
                fprintf(stderr, "InvAnnoManager::selectionCB: sscanf failed\n");
            }
            isAnnoFlg = 1;
            break;
        }
    }

    // we have got an InvAnnoFlag
    // and remove it from the scene graph
    if (isAnnoFlg == 1)
    {
        if (obj->getTypeId() == SoSeparator::getClassTypeId())
        {
            if (mode == InvAnnoManager::EDIT)
            {
                vector<InvAnnoFlag *>::iterator it, selPos;
                // search flag with instance nr = objIndex;
                for (it = mee->flags_.begin(); it != mee->flags_.end(); ++it)
                {
                    if ((*it)->getInstance() == objIndex)
                    {
                        selPos = it;
                        break;
                    }
                }
                mee->viewer_->createAnnotationEditor(*selPos);
            }

            if (mode == InvAnnoManager::REMOVE)
            {
                // deletion of an InvAnnoFlag leads to a proper removal from the
                // scene graph by calling InvActiveNode::~InvActiveNode()
                bool del(false);
                vector<InvAnnoFlag *>::iterator it, remPos;
                // search flag with instance nr = objIndex;
                for (it = mee->flags_.begin(); it != mee->flags_.end(); ++it)
                {
                    if ((*it)->getInstance() == objIndex)
                    {
                        del = true;
                        remPos = it;
                    }
                }
                // delete flag and remove it from flags_
                if (del)
                {
                    delete *remPos;
                    mee->flags_.erase(remPos);
                    mee->trueNumFlags_--;
                    mee->deactivate();
                    mee->sendParameterData();
                }
            }
        }
    }
    // we create a new flag if anything else is selected
    else
    {
        if (mode != InvAnnoManager::MAKE)
            return;

        InvAnnoManager *mee = static_cast<InvAnnoManager *>(me);

        mee->add();

        InvAnnoFlag *af = mee->getActiveFlag();

        if (!af)
            return;

        SbVec3f camPos = mee->viewer_->getCamera()->position.getValue();

        af->setPickedPoint(mee->actPickedPoint_, camPos);

        InvAnnoFlag::selectionCB(af, selectedObject);

        mee->setKbActive();

        mee->deactivate();
    }
}