From 588f1bd7952b6256788e0439af9557cfbbeba5ff Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 12 Dec 2017 15:01:27 +0100 Subject: [PATCH] Sketcher: Merge, copy expressions =================================== Support for copying expressions instead of hard values. fixes #2936 --- src/Mod/Sketcher/App/SketchObject.cpp | 39 +++++++++++++++++++++++++++ src/Mod/Sketcher/App/SketchObject.h | 2 ++ src/Mod/Sketcher/Gui/Command.cpp | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 83f0b04348..066c448601 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -813,6 +813,45 @@ int SketchObject::addConstraints(const std::vector &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; jcopy()); + + std::size_t valssize = vals.size(); + + this->Constraints.setValues(newVals); + + for(std::size_t i = valssize, j = 0; iisDriving && ( + 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(expr_info.expression->copy())); + } + + } + } + + return this->Constraints.getSize()-1; +} + int SketchObject::addConstraint(const Constraint *constraint) { const std::vector< Constraint * > &vals = this->Constraints.getValues(); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index a01e36c1cf..2329a384b5 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -101,6 +101,8 @@ public: int deleteAllGeometry(); /// add all constraints in the list int addConstraints(const std::vector &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 diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 241cb520ca..80e0a4d630 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -818,7 +818,7 @@ void CmdSketcherMergeSketches::activated(int iMsg) const Sketcher::SketchObject* Obj = static_cast((*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];