From 11a0970b919c3fbfe8cdd9ce79d00d90e0047cd5 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 8 Apr 2017 16:46:01 +0200 Subject: [PATCH] Sketcher: SketchObject basic carbon copy functionality - without expressions engine --- src/Mod/Sketcher/App/SketchObject.cpp | 52 +++++++++++++++++++++++++++ src/Mod/Sketcher/App/SketchObject.h | 2 ++ 2 files changed, 54 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 504762abea..b327456146 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -4143,6 +4143,58 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m return true; } +int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction) +{ + if (pObj->getTypeId() != Sketcher::SketchObject::getClassTypeId()) + return -1; + + SketchObject * psObj = static_cast(pObj); + + const std::vector< Part::Geometry * > &vals = getInternalGeometry(); + + const std::vector< Sketcher::Constraint * > &cvals = Constraints.getValues(); + + std::vector< Part::Geometry * > newVals(vals); + + std::vector< Constraint * > newcVals(cvals); + + int nextgeoid = vals.size(); + + //int nextcid = cvals.size(); + + const std::vector< Part::Geometry * > &svals = psObj->getInternalGeometry(); + + const std::vector< Sketcher::Constraint * > &scvals = psObj->Constraints.getValues(); + + for (std::vector::const_iterator it=svals.begin(); it != svals.end(); ++it){ + Part::Geometry *geoNew = (*it)->clone(); + if(construction) { + geoNew->Construction = true; + } + newVals.push_back(geoNew); + } + + for (std::vector< Sketcher::Constraint * >::const_iterator it= scvals.begin(); it != scvals.end(); ++it) { + Sketcher::Constraint *newConstr = (*it)->copy(); + if( (*it)->First>=0 ) + newConstr->First += nextgeoid; + if( (*it)->Second>=0 ) + newConstr->Second += nextgeoid; + if( (*it)->Third>=0 ) + newConstr->Third += nextgeoid; + + newcVals.push_back(newConstr); + } + + Geometry.setValues(newVals); + Constraints.acceptGeometry(getCompleteGeometry()); + rebuildVertexIndex(); + + this->Constraints.setValues(newcVals); + + return svals.size(); +} + int SketchObject::addExternal(App::DocumentObject *Obj, const char* SubName) { // so far only externals to the support of the sketch and datum features diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 81d076d111..59912e4006 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -109,6 +109,8 @@ public: int delConstraintsToExternal(); /// transfers all contraints of a point to a new point int transferConstraints(int fromGeoId, PointPos fromPosId, int toGeoId, PointPos toPosId); + /// Carbon copy another sketch geometry and constraints + int carbonCopy(App::DocumentObject * pObj, bool construction = true); /// add an external geometry reference int addExternal(App::DocumentObject *Obj, const char* SubName); /** delete external