bool ExpressionBinding::apply(const std::string & propName)
{
    if (hasExpression()) {
        DocumentObject * docObj = path.getDocumentObject();

        if (!docObj)
            throw Base::Exception("Document object not found.");

        Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', u'%s')",
                                docObj->getDocument()->getName(),
                                docObj->getNameInDocument(),
                                path.toEscapedString().c_str(),
                                getEscapedExpressionString().c_str());
        return true;
    }
    else {
        if (isBound()) {
            DocumentObject * docObj = path.getDocumentObject();

            if (!docObj)
                throw Base::Exception("Document object not found.");

            if (lastExpression)
                Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', None)",
                                        docObj->getDocument()->getName(),
                                        docObj->getNameInDocument(),
                                        path.toEscapedString().c_str());
        }

        return false;
    }
}
void PropertyExpressionEngine::slotObjectRenamed(const DocumentObject &obj)
{
#ifdef FC_PROPERTYEXPRESSIONENGINE_LOG
    std::clog << "Object " << obj.getOldLabel() << " renamed to " << obj.Label.getValue() << std::endl;
#endif

    DocumentObject * docObj = freecad_dynamic_cast<DocumentObject>(getContainer());

    /* In a document object, and on undo stack? */
    if (!docObj || docObj->getNameInDocument() == 0)
        return;

    RelabelDocumentObjectExpressionVisitor v(boost::bind( &PropertyExpressionEngine::aboutToSetValue, this),
                                             boost::bind( &PropertyExpressionEngine::hasSetValue, this),
                                             obj.getOldLabel(), obj.Label.getStrValue());

    for (ExpressionMap::iterator it = expressions.begin(); it != expressions.end(); ++it) {
        int changed = v.getChanged();

        it->second.expression->visit(v);

        if (changed != v.getChanged())
            expressionChanged(it->first);
    }
}
Py::String DocumentObjectPy::getName(void) const
{
    DocumentObject* object = this->getDocumentObjectPtr();
    const char* internal = object->getNameInDocument();
    if (!internal) {
        throw Py::RuntimeError(std::string("This object is currently not part of a document"));
    }
    return Py::String(std::string(internal));
}
Esempio n. 4
0
DocumentObject* GroupExtension::addObject(const char* sType, const char* pObjectName)
{
    DocumentObject* obj = getExtendedObject()->getDocument()->addObject(sType, pObjectName);
    if(!allowObject(obj)) {
        getExtendedObject()->getDocument()->remObject(obj->getNameInDocument());
        return nullptr;
    }
    if (obj) addObject(obj);
    return obj;
}
void PropertyLinkList::Save(Base::Writer &writer) const
{
    writer.Stream() << writer.ind() << "<LinkList count=\"" << getSize() << "\">" << endl;
    writer.incInd();
    for (int i = 0; i<getSize(); i++) {
        DocumentObject* obj = _lValueList[i];
        if (obj)
            writer.Stream() << writer.ind() << "<Link value=\"" << obj->getNameInDocument() << "\"/>" << endl;
        else
            writer.Stream() << writer.ind() << "<Link value=\"\"/>" << endl;
    }

    writer.decInd();
    writer.Stream() << writer.ind() << "</LinkList>" << endl;
}
void PropertyExpressionEngine::slotObjectDeleted(const DocumentObject &obj)
{
    DocumentObject * docObj = freecad_dynamic_cast<DocumentObject>(getContainer());

    /* In a document object, and on undo stack? */
    if (!docObj || docObj->getNameInDocument() == 0)
        return;

    ObjectDeletedExpressionVisitor v(&obj);

    for (ExpressionMap::iterator it = expressions.begin(); it != expressions.end(); ++it) {
        it->second.expression->visit(v);

        if (v.isFound()) {
            touch(); // Touch to force recompute; that will trigger a proper error
            return;
        }
    }
}