From b70bec971e176b6dede242dce8451fd68e28991f Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 16 Mar 2018 16:51:20 +0100 Subject: [PATCH] Sketcher: Carbon Copy Support for external geometry --- src/Mod/Sketcher/App/SketchObject.cpp | 64 +++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index cf5623ee23..9cf7a9c195 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -4419,12 +4419,63 @@ int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction) int nextgeoid = vals.size(); + int nextextgeoid = getExternalGeometryCount(); + int nextcid = cvals.size(); const std::vector< Part::Geometry * > &svals = psObj->getInternalGeometry(); const std::vector< Sketcher::Constraint * > &scvals = psObj->Constraints.getValues(); - + + if(psObj->ExternalGeometry.getSize()>0) { + std::vector Objects = ExternalGeometry.getValues(); + std::vector SubElements = ExternalGeometry.getSubValues(); + + const std::vector originalObjects = Objects; + const std::vector originalSubElements = SubElements; + + std::vector sObjects = psObj->ExternalGeometry.getValues(); + std::vector sSubElements = psObj->ExternalGeometry.getSubValues(); + + if (Objects.size() != SubElements.size() || sObjects.size() != sSubElements.size()) { + assert(0 /*counts of objects and subelements in external geometry links do not match*/); + Base::Console().Error("Internal error: counts of objects and subelements in external geometry links do not match\n"); + return -1; + } + + int si=0; + for (auto & sobj : sObjects) { + int i=0; + for (auto & obj : Objects){ + if (obj == sobj && SubElements[i] == sSubElements[si]){ + Base::Console().Error("Link to %s already exists in this sketch. Delete the link and try again\n",sSubElements[si]); + return -1; + } + + i++; + } + + Objects.push_back(sobj); + SubElements.push_back(sSubElements[si]); + + si++; + } + + ExternalGeometry.setValues(Objects,SubElements); + + try { + rebuildExternalGeometry(); + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + // revert to original values + ExternalGeometry.setValues(originalObjects,originalSubElements); + return -1; + } + + solverNeedsUpdate=true; + } + for (std::vector::const_iterator it=svals.begin(); it != svals.end(); ++it){ Part::Geometry *geoNew = (*it)->copy(); if(construction) { @@ -4432,7 +4483,7 @@ int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction) } 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 ) @@ -4442,9 +4493,16 @@ int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction) if( (*it)->Third>=0 ) newConstr->Third += nextgeoid; + if( (*it)->First<-2 && (*it)->First != Constraint::GeoUndef ) + newConstr->First -= (nextextgeoid-2); + if( (*it)->Second<-2 && (*it)->Second != Constraint::GeoUndef) + newConstr->Second -= (nextextgeoid-2); + if( (*it)->Third<-2 && (*it)->Third != Constraint::GeoUndef) + newConstr->Third -= (nextextgeoid-2); + newcVals.push_back(newConstr); } - + Geometry.setValues(newVals); Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex();