From 8ebb8ce90bdbbbcfb30b4ddca4569b30d4e4eee0 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 28 May 2018 23:35:54 +0200 Subject: [PATCH] Sketcher: Empty list means all geometry for Python addCopy addRectangularArray and addMove --- src/Mod/Sketcher/App/SketchObject.cpp | 43 +++++++++++++--------- src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 20 +++++----- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 5d83e5b275..38874cff5c 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2847,6 +2847,13 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 const std::vector< Constraint * > &constrvals = this->Constraints.getValues(); std::vector< Constraint * > newconstrVals(constrvals); + + std::vector newgeoIdList(geoIdList); + + if(newgeoIdList.size() == 0) {// default option to operate on all the geometry + for(int i = 0; i < int(geovals.size()); i++) + newgeoIdList.push_back(i); + } int cgeoid = getHighestCurveIndex()+1; @@ -2872,8 +2879,8 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 for (x=0;xgetTypeId() == Part::GeomCircle::getClassTypeId() || @@ -2896,7 +2903,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 } } - for (std::vector::const_iterator it = geoIdList.begin(); it != geoIdList.end(); ++it) { + for (std::vector::const_iterator it = newgeoIdList.begin(); it != newgeoIdList.end(); ++it) { const Part::Geometry *geo = getGeometry(*it); Part::Geometry *geocopy = moveonly?const_cast(geo):geo->copy(); @@ -2909,7 +2916,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geosymline->setPoints( ssp, ep+double(x)*displacement+double(y)*perpendicularDisplacement); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = ssp; } else if(geocopy->getTypeId() == Part::GeomCircle::getClassTypeId()){ @@ -2919,7 +2926,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geosymcircle->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = scp; } else if(geocopy->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()){ @@ -2929,7 +2936,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geoaoc->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = geoaoc->getStartPoint(true); } else if(geocopy->getTypeId() == Part::GeomEllipse::getClassTypeId()){ @@ -2939,7 +2946,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geosymellipse->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = scp; } else if(geocopy->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()){ @@ -2949,7 +2956,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geoaoe->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = geoaoe->getStartPoint(true); } else if(geocopy->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()){ @@ -2959,7 +2966,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geoaoe->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = geoaoe->getStartPoint(true); } else if(geocopy->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()){ @@ -2969,7 +2976,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geoaoe->setCenter(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = geoaoe->getStartPoint(true); } else if(geocopy->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()){ @@ -2984,7 +2991,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 geobsp->setPoles(poles); - if (it == geoIdList.begin()) + if (it == newgeoIdList.begin()) iterfirstpoint = geobsp->getStartPoint(); } else if(geocopy->getTypeId() == Part::GeomPoint::getClassTypeId()){ @@ -2993,7 +3000,7 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 Base::Vector3d scp = cp+double(x)*displacement+double(y)*perpendicularDisplacement; geopoint->setPoint(scp); - if(it == geoIdList.begin()) + if(it == newgeoIdList.begin()) iterfirstpoint = scp; } else { @@ -3012,9 +3019,9 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 // handle geometry constraints for (std::vector::const_iterator it = constrvals.begin(); it != constrvals.end(); ++it) { - std::vector::const_iterator fit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->First); + std::vector::const_iterator fit=std::find(newgeoIdList.begin(), newgeoIdList.end(), (*it)->First); - if(fit != geoIdList.end()) { // if First of constraint is in geoIdList + if(fit != newgeoIdList.end()) { // if First of constraint is in geoIdList if( (*it)->Second == Constraint::GeoUndef /*&& (*it)->Third == Constraint::GeoUndef*/) { if( ((*it)->Type != Sketcher::DistanceX && (*it)->Type != Sketcher::DistanceY ) || @@ -3045,9 +3052,9 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 } else { // other geoids intervene in this constraint - std::vector::const_iterator sit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Second); + std::vector::const_iterator sit=std::find(newgeoIdList.begin(), newgeoIdList.end(), (*it)->Second); - if(sit != geoIdList.end()) { // Second is also in the list + if(sit != newgeoIdList.end()) { // Second is also in the list if( (*it)->Third == Constraint::GeoUndef ) { if (((*it)->Type == Sketcher::DistanceX || (*it)->Type == Sketcher::DistanceY || @@ -3068,9 +3075,9 @@ int SketchObject::addCopy(const std::vector &geoIdList, const Base::Vector3 } } else { - std::vector::const_iterator tit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Third); + std::vector::const_iterator tit=std::find(newgeoIdList.begin(), newgeoIdList.end(), (*it)->Third); - if(tit != geoIdList.end()) { // Third is also in the list + if(tit != newgeoIdList.end()) { // Third is also in the list Constraint *constNew = (*it)->copy(); constNew->First = geoIdMap[(*it)->First]; constNew->Second = geoIdMap[(*it)->Second]; diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 4906de9b35..fa556bb509 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -1025,16 +1025,16 @@ PyObject* SketchObjectPy::addMove(PyObject *args) if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { std::vector geoIdList; - Py::Sequence list(pcObj); - for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { - #if PY_MAJOR_VERSION >= 3 - if (PyLong_Check((*it).ptr())) - geoIdList.push_back(PyLong_AsLong((*it).ptr())); - #else - if (PyInt_Check((*it).ptr())) - geoIdList.push_back(PyInt_AsLong((*it).ptr())); - #endif - } + Py::Sequence list(pcObj); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + #if PY_MAJOR_VERSION >= 3 + if (PyLong_Check((*it).ptr())) + geoIdList.push_back(PyLong_AsLong((*it).ptr())); + #else + if (PyInt_Check((*it).ptr())) + geoIdList.push_back(PyInt_AsLong((*it).ptr())); + #endif + } this->getSketchObjectPtr()->addCopy(geoIdList, vect, true);