Expressions: Integrate into the property editor

- basic infrastructure for handling of expressions
- port the unit properties editor to support expressions
- port placement editor to support expressions
- expressions for double spinbox
- expressions in sketch constraints
This commit is contained in:
Stefan Tröger
2015-10-06 08:45:15 +02:00
committed by wmayer
parent f037bf9f52
commit 96a586d04a
11 changed files with 467 additions and 62 deletions

View File

@@ -122,8 +122,10 @@ void PropertyExpressionEngine::Paste(const Property &from)
aboutToSetValue();
expressions.clear();
for (ExpressionMap::const_iterator it = fromee->expressions.begin(); it != fromee->expressions.end(); ++it)
for (ExpressionMap::const_iterator it = fromee->expressions.begin(); it != fromee->expressions.end(); ++it) {
expressions[it->first] = ExpressionInfo(it->second);
expressionChanged(it->first);
}
validator = fromee->validator;
@@ -272,8 +274,10 @@ void PropertyExpressionEngine::slotObjectRenamed(const DocumentObject &obj)
aboutToSetValue();
for (ExpressionMap::iterator it = expressions.begin(); it != expressions.end(); ++it)
for (ExpressionMap::iterator it = expressions.begin(); it != expressions.end(); ++it) {
it->second.expression->visit(v);
expressionChanged(it->first);
}
hasSetValue();
}
@@ -312,6 +316,10 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::sh
// Try to access value; it should trigger an exception if it is not supported, or if the path is invalid
prop->getPathValue(usePath);
// Check if the current expression equals the new one and do nothing if so to reduce unneeded computations
if(expressions.find(usePath) != expressions.end() && expr == expressions[usePath].expression)
return;
if (expr) {
std::string error = validateExpression(usePath, expr);
@@ -320,11 +328,13 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::sh
aboutToSetValue();
expressions[usePath] = ExpressionInfo(expr, comment);
expressionChanged(usePath);
hasSetValue();
}
else {
aboutToSetValue();
expressions.erase(usePath);
expressionChanged(usePath);
hasSetValue();
}
}
@@ -669,6 +679,9 @@ void PropertyExpressionEngine::renameExpressions(const std::map<ObjectIdentifier
aboutToSetValue();
expressions = newExpressions;
for (ExpressionMap::const_iterator i = expressions.begin(); i != expressions.end(); ++i)
expressionChanged(i->first);
hasSetValue();
}

View File

@@ -25,6 +25,7 @@
#include <boost/unordered/unordered_map.hpp>
#include <boost/function.hpp>
#include <boost/signals.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
#include <App/Property.h>
@@ -49,7 +50,7 @@ class AppExport PropertyExpressionEngine : public App::Property
public:
typedef boost::function<std::string (const App::ObjectIdentifier & path, boost::shared_ptr<const App::Expression> expr)> ValidatorFunc;
/**
* @brief The ExpressionInfo struct encapsulates an expression and a comment.
*/
@@ -117,6 +118,9 @@ public:
size_t numExpressions() const;
void slotObjectRenamed(const App::DocumentObject & obj);
///signal called when a expression was changed
boost::signal<void (const App::ObjectIdentifier &)> expressionChanged;
/* Python interface */
PyObject *getPyObject(void);