Ejemplo n.º 1
0
BaseData* deriveTypeFromParentValue(Base* obj, const std::string& value)
{
    BaseObject* o = dynamic_cast<BaseObject*>(obj);
    if (!o)
        return nullptr;

    // if data is a link
    if (value.length() > 0 && value[0] == '@')
    {
        std::string componentPath = value.substr(1, value.find('.') - 1);
        std::string parentDataName = value.substr(value.find('.') + 1);

        if (!o->getContext())
        {
	    msg_warning("SofaPython") << "No context created. Cannot find data link to derive input type.";
            return nullptr;
        }
        BaseObject* component;
        component = o->getContext()->get<BaseObject>(componentPath);
        if (!component)
	    msg_warning("SofaPython") << "No object with path " << componentPath << " in scene graph.";
        BaseData* parentData = component->findData(parentDataName);
        return parentData->getNewInstance();
    }
    return nullptr;
}
Ejemplo n.º 2
0
std::string BaseLink::CreateStringPath(Base* dest, Base* from)
{
    if (!dest || dest == from) return std::string("[]");
    BaseObject* o = dest->toBaseObject();
    BaseObject* f = from->toBaseObject();
    BaseContext* ctx = from->toBaseContext();
    if (!ctx && f) ctx = f->getContext();
    if (o)
    {
        std::string objectPath = o->getName();
        BaseObject* master = o->getMaster();
        while (master)
        {
            objectPath = master->getName() + std::string("/") + objectPath;
            master = master->getMaster();
        }
        BaseNode* n = o->getContext()->toBaseNode();
        if (f && o->getContext() == ctx)
            return objectPath;
        else if (n)
            return n->getPathName() + std::string("/") + objectPath; // TODO: compute relative path
        else
            return objectPath; // we could not determine destination path, specifying simply its name might be enough to find it back
    }
    else // dest is a context
    {
        if (f && ctx == dest)
            return std::string("./");
        BaseNode* n = dest->toBaseNode();
        if (n) return n->getPathName(); // TODO: compute relative path
        else return dest->getName(); // we could not determine destination path, specifying simply its name might be enough to find it back
    }
}