示例#1
0
PropertyContainer& Mesh:: createPropertyContainer()
{
  PropertyContainer* newPropertyContainer = new PropertyContainer();
  newPropertyContainer->addParent(*this);
  _propertyContainers.push_back(newPropertyContainer);
  return *newPropertyContainer;
}
void PropertyPythonObject::restoreObject(Base::XMLReader &reader)
{
    Base::PyGILStateLocker lock;
    try {
        PropertyContainer* parent = this->getContainer();
        if (reader.hasAttribute("object")) {
            if (strcmp(reader.getAttribute("object"),"yes") == 0) {
                Py::Object obj = Py::asObject(parent->getPyObject());
                this->object.setAttr("__object__", obj);
            }
        }
        if (reader.hasAttribute("vobject")) {
            if (strcmp(reader.getAttribute("vobject"),"yes") == 0) {
                Py::Object obj = Py::asObject(parent->getPyObject());
                this->object.setAttr("__vobject__", obj);
            }
        }
    }
    catch (Py::Exception& e) {
        e.clear();
    }
    catch (const Base::Exception& e) {
        Base::Console().Error("%s\n",e.what());
    }
    catch (...) {
        Base::Console().Error("Critical error in PropertyPythonObject::restoreObject\n");
    }
}
示例#3
0
文件: Reader.cpp 项目: joeld42/gto
//-*****************************************************************************
Reader::Request
Reader::component( const std::string &name, 
                      const std::string &ininterp,
                      const ComponentInfo &info ) 
{
    std::string interp = ininterp;
    if ( fileHeader().version < 3 ) { interp = GTO_INTERPRET_DEFAULT; }
    
    if ( m_objects == NULL )
    {
        GTC_THROW( "Reader reading without objects" );
    }
    
    PropertyContainer *g  = 
        reinterpret_cast<PropertyContainer*>( info.object->objectData );
    Component *c = g->component( name );
    
    if ( !c )
    {
        // adds it too.
        c = g->createComponent( name, info.flags & Gto::Matrix );
    }

    return Request( true, c );
}
std::string PropertyFileIncluded::getDocTransientPath(void) const
{
    PropertyContainer *co = getContainer();
    if (co->isDerivedFrom(DocumentObject::getClassTypeId()))
        return dynamic_cast<DocumentObject*>(co)->getDocument()->TransientDir.getValue();

    return std::string();
}
示例#5
0
std::string PropertyFileIncluded::getDocTransientPath(void) const
{
    std::string path;
    PropertyContainer *co = getContainer();
    if (co->isDerivedFrom(DocumentObject::getClassTypeId())) {
        path = static_cast<DocumentObject*>(co)->getDocument()->TransientDir.getValue();
        std::replace(path.begin(), path.end(), '\\', '/');
    }
    return path;
}
示例#6
0
Expression * VariableExpression::eval() const
{
    const Property * prop = getProperty();
    PropertyContainer * parent = prop->getContainer();

    if (!parent->isDerivedFrom(App::DocumentObject::getClassTypeId()))
        throw ExpressionError("Property must belong to a document object.");

    boost::any value = prop->getPathValue(var);

    if (value.type() == typeid(Quantity)) {
        Quantity qvalue = boost::any_cast<Quantity>(value);

        return new NumberExpression(owner, qvalue);
    }
    else if (value.type() == typeid(double)) {
        double dvalue = boost::any_cast<double>(value);

        return new NumberExpression(owner, dvalue);
    }
    else if (value.type() == typeid(float)) {
        double fvalue = boost::any_cast<float>(value);

        return new NumberExpression(owner, fvalue);
    }
    else if (value.type() == typeid(int)) {
        int ivalue = boost::any_cast<int>(value);

        return new NumberExpression(owner, ivalue);
    }
    else if (value.type() == typeid(std::string)) {
        std::string svalue = boost::any_cast<std::string>(value);

        return new StringExpression(owner, svalue);
    }
    else if (value.type() == typeid(char*)) {
        char* svalue = boost::any_cast<char*>(value);

        return new StringExpression(owner, svalue);
    }
    else if (value.type() == typeid(const char*)) {
        const char* svalue = boost::any_cast<const char*>(value);

        return new StringExpression(owner, svalue);
    }

    throw ExpressionError("Property is of invalid type.");
}
void PropertyPythonObject::saveObject(Base::Writer &writer) const
{
    Base::PyGILStateLocker lock;
    try {
        PropertyContainer* parent = this->getContainer();
        if (parent->isDerivedFrom(Base::Type::fromName("App::DocumentObject"))) {
            if (this->object.hasAttr("__object__")) {
                writer.Stream() << " object=\"yes\"";
            }
        }
        if (parent->isDerivedFrom(Base::Type::fromName("Gui::ViewProvider"))) {
            if (this->object.hasAttr("__vobject__")) {
                writer.Stream() << " vobject=\"yes\"";
            }
        }
    }
    catch (Py::Exception& e) {
        e.clear();
    }
}
示例#8
0
文件: Reader.cpp 项目: joeld42/gto
//-*****************************************************************************
Reader::Request
Reader::object( const std::string &name, 
                const std::string &prot, 
                unsigned int protVersion,
                const ObjectInfo &info ) 
{
    if ( m_objects == NULL )
    {
        GTC_THROW( "Reader reading without objects" );
    }
    
    PropertyContainer *g = NULL;
    Protocol protocol( prot, protVersion );
    bool found = false;

    if ( m_useExisting )
    {
        for ( int i = 0; i < m_objects->size(); ++i )
        {
            PropertyContainer *pc = (*m_objects)[i];

            if ( pc->name() == name &&
                 pc->protocol() == protocol )
            {
                found = true;
                g = pc;
            }
        }
    }
    
    if ( !g )
    {
        g = newContainer( protocol );
        g->setName( name );
        g->setProtocol( protocol );
    }

    if ( !found ) { m_objects->push_back( g ); }

    return Request( true, g );
}