Sketcher: Merge, copy expressions

===================================

Support for copying expressions instead of hard values.

fixes #2936
This commit is contained in:
Abdullah Tahiri
2017-12-12 15:01:27 +01:00
committed by wmayer
parent 9b781f9c54
commit 588f1bd795
3 changed files with 42 additions and 1 deletions

View File

@@ -813,6 +813,45 @@ int SketchObject::addConstraints(const std::vector<Constraint *> &ConstraintList
return this->Constraints.getSize()-1;
}
int SketchObject::addCopyOfConstraints(const SketchObject &orig)
{
const std::vector< Constraint * > &vals = this->Constraints.getValues();
const std::vector< Constraint * > &origvals = orig.Constraints.getValues();
std::vector< Constraint * > newVals(vals);
for(std::size_t j = 0; j<origvals.size(); j++)
newVals.push_back(origvals[j]->copy());
std::size_t valssize = vals.size();
this->Constraints.setValues(newVals);
for(std::size_t i = valssize, j = 0; i<newVals.size(); i++,j++){
if ( newVals[i]->isDriving && (
newVals[i]->Type == Sketcher::Distance ||
newVals[i]->Type == Sketcher::DistanceX ||
newVals[i]->Type == Sketcher::DistanceY ||
newVals[i]->Type == Sketcher::Radius ||
newVals[i]->Type == Sketcher::Angle ||
newVals[i]->Type == Sketcher::SnellsLaw)) {
App::ObjectIdentifier spath = orig.Constraints.createPath(j);
App::PropertyExpressionEngine::ExpressionInfo expr_info = orig.getExpression(spath);
if (expr_info.expression) { // if there is an expression on the source dimensional
App::ObjectIdentifier dpath = this->Constraints.createPath(i);
setExpression(dpath, boost::shared_ptr<App::Expression>(expr_info.expression->copy()));
}
}
}
return this->Constraints.getSize()-1;
}
int SketchObject::addConstraint(const Constraint *constraint)
{
const std::vector< Constraint * > &vals = this->Constraints.getValues();

View File

@@ -101,6 +101,8 @@ public:
int deleteAllGeometry();
/// add all constraints in the list
int addConstraints(const std::vector<Constraint *> &ConstraintList);
/// Copy the constraints instead of cloning them and copying the expressions if any
int addCopyOfConstraints(const SketchObject &orig);
/// add constraint
int addConstraint(const Constraint *constraint);
/// delete constraint

View File

@@ -818,7 +818,7 @@ void CmdSketcherMergeSketches::activated(int iMsg)
const Sketcher::SketchObject* Obj = static_cast<const Sketcher::SketchObject*>((*it).getObject());
int addedGeometries=mergesketch->addGeometry(Obj->getInternalGeometry());
int addedConstraints=mergesketch->addConstraints(Obj->Constraints.getValues());
int addedConstraints=mergesketch->addCopyOfConstraints(*Obj);
for (int i=0; i<=(addedConstraints-baseConstraints); i++){
Sketcher::Constraint * constraint= mergesketch->Constraints.getValues()[i+baseConstraints];