Sketcher: Empty list means all geometry for Python addCopy addRectangularArray and addMove
This commit is contained in:
@@ -2847,6 +2847,13 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
|
||||
|
||||
const std::vector< Constraint * > &constrvals = this->Constraints.getValues();
|
||||
std::vector< Constraint * > newconstrVals(constrvals);
|
||||
|
||||
std::vector<int> 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<int> &geoIdList, const Base::Vector3
|
||||
for (x=0;x<csize;x++) {
|
||||
|
||||
if(x == 0 && y == 0) { // the reference for constraining array elements is the first valid point of the first element
|
||||
const Part::Geometry *geo = getGeometry(*(geoIdList.begin()));
|
||||
refgeoid=*(geoIdList.begin());
|
||||
const Part::Geometry *geo = getGeometry(*(newgeoIdList.begin()));
|
||||
refgeoid=*(newgeoIdList.begin());
|
||||
currentrowfirstgeoid = refgeoid;
|
||||
iterfirstgeoid = refgeoid;
|
||||
if(geo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
@@ -2896,7 +2903,7 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<int>::const_iterator it = geoIdList.begin(); it != geoIdList.end(); ++it) {
|
||||
for (std::vector<int>::const_iterator it = newgeoIdList.begin(); it != newgeoIdList.end(); ++it) {
|
||||
const Part::Geometry *geo = getGeometry(*it);
|
||||
Part::Geometry *geocopy = moveonly?const_cast<Part::Geometry *>(geo):geo->copy();
|
||||
|
||||
@@ -2909,7 +2916,7 @@ int SketchObject::addCopy(const std::vector<int> &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<int> &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<int> &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<int> &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<int> &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<int> &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<int> &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<int> &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<int> &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<int> &geoIdList, const Base::Vector3
|
||||
// handle geometry constraints
|
||||
for (std::vector<Constraint *>::const_iterator it = constrvals.begin(); it != constrvals.end(); ++it) {
|
||||
|
||||
std::vector<int>::const_iterator fit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->First);
|
||||
std::vector<int>::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<int> &geoIdList, const Base::Vector3
|
||||
}
|
||||
else { // other geoids intervene in this constraint
|
||||
|
||||
std::vector<int>::const_iterator sit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Second);
|
||||
std::vector<int>::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<int> &geoIdList, const Base::Vector3
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::vector<int>::const_iterator tit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Third);
|
||||
std::vector<int>::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];
|
||||
|
||||
@@ -1025,16 +1025,16 @@ PyObject* SketchObjectPy::addMove(PyObject *args)
|
||||
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
|
||||
std::vector<int> 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user