From c10330f705ec2bc929c1078789f00892c7c603fd Mon Sep 17 00:00:00 2001 From: Adrian Insaurralde Avalos Date: Thu, 3 Nov 2022 01:03:39 -0300 Subject: [PATCH] [fixes #5965] CarbonCopy: if existing use constraint name in expressions --- src/Mod/Sketcher/App/SketchObject.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 4d77fb44a5..2efa30663f 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -6151,25 +6152,26 @@ int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction) int sourceid = 0; for (std::vector< Sketcher::Constraint * >::const_iterator it= scvals.begin(); it != scvals.end(); ++it, nextcid++, sourceid++) { - if ((*it)->Type == Sketcher::Distance || - (*it)->Type == Sketcher::Radius || - (*it)->Type == Sketcher::Diameter || - (*it)->Type == Sketcher::Weight || - (*it)->Type == Sketcher::Angle || - (*it)->Type == Sketcher::SnellsLaw || - (*it)->Type == Sketcher::DistanceX || - (*it)->Type == Sketcher::DistanceY ) { + if ((*it)->isDimensional()) { // then we link its value to the parent - // (there is a plausible alternative for a slightly different use case to copy the expression of the parent if one is existing) if ((*it)->isDriving) { - App::ObjectIdentifier spath = psObj->Constraints.createPath(sourceid); + App::ObjectIdentifier spath; + std::shared_ptr expr; + std::string scname = (*it)->Name; + if ( App::ExpressionParser::isTokenAnIndentifier(scname) ) { + spath = App::ObjectIdentifier(psObj->Constraints) << App::ObjectIdentifier::SimpleComponent(scname); + expr = std::shared_ptr(App::Expression::parse(this, spath.getDocumentObjectName().getString() + spath.toString())); + } + else { + spath = psObj->Constraints.createPath(sourceid); + expr = std::shared_ptr(App::Expression::parse(this, spath.getDocumentObjectName().getString() +std::string(1,'.') + spath.toString())); + } + // (there is a plausible alternative for a slightly different use case to copy the expression of the parent if one is existing) /* * App::PropertyExpressionEngine::ExpressionInfo expr_info = psObj->getExpression(path); * * if (expr_info.expression)*/ //App::Expression * expr = parse(this, const std::string& buffer); - - std::shared_ptr expr(App::Expression::parse(this, spath.getDocumentObjectName().getString() +std::string(1,'.') + spath.toString())); setExpression(Constraints.createPath(nextcid), expr); } }