From 3e6eb430fa10b0b80c45ca5a8271b059066d1e53 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Thu, 12 Mar 2015 23:41:10 +0300 Subject: [PATCH] Sketcher: small asserts cleanup --- src/Mod/Sketcher/App/Sketch.cpp | 28 ++++++++++----------------- src/Mod/Sketcher/App/SketchObject.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 5d85e3fedec6..4fb5541c5832 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -594,8 +594,9 @@ Py::Tuple Sketch::getPyGeometry(void) const int Sketch::checkGeoId(int geoId) { if (geoId < 0) - geoId += Geoms.size(); - assert(geoId >= 0 && geoId < int(Geoms.size())); + geoId += Geoms.size();//convert negative external-geometry index to index into Geoms + if(!( geoId >= 0 && geoId < int(Geoms.size()) )) + throw Base::Exception("Sketch::checkGeoId. GeoId index out range."); return geoId; } @@ -619,7 +620,6 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId) return &ArcsOfEllipse[Geoms[geoId].index]; break; default: - assert(0); return 0; }; } @@ -628,8 +628,8 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId) int Sketch::addConstraint(const Constraint *constraint) { - // constraints on nothing makes no sense - assert(int(Geoms.size()) > 0); + if(int(Geoms.size()) <= 0) + throw Base::Exception("Sketch::addConstraint. Can't add constraint to a sketch with no geometry!"); int rtn = -1; switch (constraint->Type) { case DistanceX: @@ -767,7 +767,7 @@ int Sketch::addConstraint(const Constraint *constraint) } break; case SnellsLaw: - assert(constraint->ThirdPos==none); + //assert(constraint->ThirdPos==none); //will work anyway... rtn = addSnellsLawConstraint(constraint->First, constraint->FirstPos, constraint->Second, constraint->SecondPos, constraint->Third, @@ -781,9 +781,6 @@ int Sketch::addConstraint(const Constraint *constraint) int Sketch::addConstraints(const std::vector &ConstraintList) { - // constraints on nothing makes no sense - assert(!Geoms.empty() || ConstraintList.empty()); - int rtn = -1; for (std::vector::const_iterator it = ConstraintList.begin();it!=ConstraintList.end();++it) rtn = addConstraint (*it); @@ -1157,7 +1154,7 @@ int Sketch::addAngleAtPointConstraint( { if(!(cTyp == Angle || cTyp == Tangent || cTyp == Perpendicular)) { - assert(0);//none of the three types. Why are we here?? + //assert(0);//none of the three types. Why are we here?? return -1; } @@ -1166,7 +1163,7 @@ int Sketch::addAngleAtPointConstraint( bool e2e = pos2 != none && pos1 != none;//is endpoint-to-endpoint? if (!( avp || e2c || e2e )) { - assert(0);//none of the three types. Why are we here?? + //assert(0);//none of the three types. Why are we here?? return -1; } @@ -1177,14 +1174,13 @@ int Sketch::addAngleAtPointConstraint( if (Geoms[geoId1].type == Point || Geoms[geoId2].type == Point){ - assert(0);//point is not a curve. No tangency/whatever! + Base::Console().Error("addAngleAtPointConstraint: one of the curves is a point!\n"); return -1; } GCS::Curve* crv1 =getGCSCurveByGeoId(geoId1); GCS::Curve* crv2 =getGCSCurveByGeoId(geoId2); if (!crv1 || !crv2) { - assert(0); Base::Console().Error("addAngleAtPointConstraint: getGCSCurveByGeoId returned NULL!\n"); return -1; } @@ -1196,7 +1192,6 @@ int Sketch::addAngleAtPointConstraint( pointId = getPointId(geoId1, pos1); if (pointId < 0 || pointId >= int(Points.size())){ - assert(0); Base::Console().Error("addAngleAtPointConstraint: point index out of range.\n"); return -1; } @@ -1205,7 +1200,6 @@ int Sketch::addAngleAtPointConstraint( if(e2e){//we need second point int pointId = getPointId(geoId2, pos2); if (pointId < 0 || pointId >= int(Points.size())){ - assert(0); Base::Console().Error("addAngleAtPointConstraint: point index out of range.\n"); return -1; } @@ -1660,7 +1654,7 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1, if (Geoms[geoIdRay1].type == Point || Geoms[geoIdRay2].type == Point){ - assert(0);//point is not a curve. Not applicable! + Base::Console().Error("addSnellsLawConstraint: point is not a curve. Not applicable!\n"); return -1; } @@ -1668,7 +1662,6 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1, GCS::Curve* ray2 =getGCSCurveByGeoId(geoIdRay2); GCS::Curve* boundary =getGCSCurveByGeoId(geoIdBnd); if (!ray1 || !ray2 || !boundary) { - assert(0); Base::Console().Error("addSnellsLawConstraint: getGCSCurveByGeoId returned NULL!\n"); return -1; } @@ -1677,7 +1670,6 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1, int pointId2 = getPointId(geoIdRay2, posRay2); if ( pointId1 < 0 || pointId1 >= int(Points.size()) || pointId2 < 0 || pointId2 >= int(Points.size()) ){ - assert(0); Base::Console().Error("addSnellsLawConstraint: point index out of range.\n"); return -1; } diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 418ab4f0e2ef..c7a938aa898b 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -245,8 +245,9 @@ int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toP Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const { - assert(GeoId == H_Axis || GeoId == V_Axis || - (GeoId <= getHighestCurveIndex() && GeoId >= -getExternalGeometryCount()) ); + if(!(GeoId == H_Axis || GeoId == V_Axis + || (GeoId <= getHighestCurveIndex() && GeoId >= -getExternalGeometryCount()) )) + throw Base::Exception("SketchObject::getPoint. Invalid GeoId was supplied."); const Part::Geometry *geo = getGeometry(GeoId); if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) { const Part::GeomPoint *p = dynamic_cast(geo); @@ -1731,7 +1732,7 @@ int SketchObject::delExternal(int ExtGeoId) if (copiedConstr->Third < GeoId && copiedConstr->Third != Constraint::GeoUndef) copiedConstr->Third += 1; - + newConstraints.push_back(copiedConstr); } } @@ -2638,7 +2639,7 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze) bool SketchObject::AutoLockTangencyAndPerpty(Constraint *cstr, bool bForce, bool bLock) { try{ - assert ( cstr->Type == Tangent || cstr->Type == Perpendicular); + //assert ( cstr->Type == Tangent || cstr->Type == Perpendicular); if(cstr->Value != 0.0 && ! bForce) /*tangency type already set. If not bForce - don't touch.*/ return true; if(!bLock){ @@ -2683,7 +2684,6 @@ bool SketchObject::AutoLockTangencyAndPerpty(Constraint *cstr, bool bForce, bool } } catch (Base::Exception& e){ //failure to determine tangency type is not a big deal, so a warning. - assert(0);//but it shouldn't happen (failure to determine tangency type)! Base::Console().Warning("Error in AutoLockTangency. %s \n", e.what()); return false; }