From e73111098d5c15e6a27f1be9303511d9a3799b80 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 16 Aug 2016 16:39:36 +0300 Subject: [PATCH] Fix sketch Unit Tests --- .../ModelHighAPI_FeatureStore.cpp | 4 +- src/SketchAPI/SketchAPI.i | 47 +++++++++++++++++++ .../SketchPlugin_ConstraintMirror.cpp | 13 ++--- src/SketchPlugin/Test/TestSketchArcCircle.py | 9 ---- src/SketchPlugin/Test/TestSketchPointLine.py | 6 --- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index c9ff7f1f4..917af05ba 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -33,6 +33,8 @@ #include #include +#include + ModelHighAPI_FeatureStore::ModelHighAPI_FeatureStore(FeaturePtr theFeature) { storeData(theFeature->data(), myAttrs); // iterate results to store @@ -256,7 +258,7 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr& // output the main characteristics aResult<<"Volume: "< aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape); - aResult<<"Center of mass: " + aResult<<"Center of mass: "<x()<<" "<y()<<" "<z()< > & (std::list > temp) { + std::shared_ptr * temp_object; + std::shared_ptr * temp_interface; + ModelHighAPI_Selection* temp_selection; + int newmem = 0; + if (PySequence_Check($input)) { + for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) { + PyObject * item = PySequence_GetItem($input, i); + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_selection) { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object."); + return NULL; + } + temp.push_back(temp_selection->resultSubShapePair().first); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_selection; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_object) { + PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object."); + return NULL; + } + temp.push_back(*temp_object); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_object; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_interface) { + PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object."); + return NULL; + } + temp.push_back((*temp_interface)->defaultResult()); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_interface; + } + } + Py_DECREF(item); + } + $1 = &temp; + } else { + PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); + return NULL; + } +} + // all supported interfaces (the order is very important according dependencies: base class first) %include "SketchAPI_SketchEntity.h" %include "SketchAPI_Point.h" diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index 2161806eb..d63c196a4 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -229,23 +229,20 @@ void SketchPlugin_ConstraintMirror::erase() SketchPlugin_ConstraintBase::erase(); } +#include void SketchPlugin_ConstraintMirror::attributeChanged(const std::string& theID) { if (theID == MIRROR_LIST_ID()) { AttributeRefListPtr aMirrorObjectRefs = reflist(MIRROR_LIST_ID()); if (aMirrorObjectRefs->size() == 0) { + DocumentPtr aDoc = document(); // Clear list of objects AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast( data()->attribute(SketchPlugin_Constraint::ENTITY_C())); std::list aTargetList = aRefListOfMirrored->list(); - std::list::iterator aTargetIter = aTargetList.begin(); - for (; aTargetIter != aTargetList.end(); aTargetIter++) { - aRefListOfMirrored->remove(*aTargetIter); - // remove the corresponding feature from the sketch - ResultConstructionPtr aRC = - std::dynamic_pointer_cast(*aTargetIter); - DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr(); - FeaturePtr aFeature = aDoc ? aDoc->feature(aRC) : FeaturePtr(); + std::list::reverse_iterator aTargetIter = aTargetList.rbegin(); + for (; aTargetIter != aTargetList.rend(); aTargetIter++) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter); if (aFeature) aDoc->removeFeature(aFeature); } diff --git a/src/SketchPlugin/Test/TestSketchArcCircle.py b/src/SketchPlugin/Test/TestSketchArcCircle.py index d853339c4..897e9bb77 100644 --- a/src/SketchPlugin/Test/TestSketchArcCircle.py +++ b/src/SketchPlugin/Test/TestSketchArcCircle.py @@ -96,19 +96,13 @@ assert (len(aSketchReflist.list()) == 0) aSketchArc = aSketchFeature.addFeature("SketchArc") assert (aSketchArc.getKind() == "SketchArc") anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter")) -assert (anArcCentr.x() == 0) -assert (anArcCentr.y() == 0) assert (not anArcCentr.isInitialized()) anArcCentr.setValue(10., 10.) anArcStartPoint = geomDataAPI_Point2D( aSketchArc.attribute("ArcStartPoint")) -assert (anArcStartPoint.x() == 0) -assert (anArcStartPoint.y() == 0) assert (not anArcStartPoint.isInitialized()) anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) -assert (anArcEndPoint.x() == 0) -assert (anArcEndPoint.y() == 0) assert (not anArcEndPoint.isInitialized()) anArcEndPoint.setValue(50., 0.) aSession.finishOperation() @@ -177,14 +171,11 @@ assert (len(aSketchReflist.list()) == 1) aSketchCircle = aSketchFeature.addFeature("SketchCircle") assert (aSketchCircle.getKind() == "SketchCircle") anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) -assert (anCircleCentr.x() == 0) -assert (anCircleCentr.y() == 0) assert (not anCircleCentr.isInitialized()) aCircleRadius = aSketchCircle.real("CircleRadius") assert (type(aCircleRadius) == ModelAPI_AttributeDouble) # ModelAPI_AttributeDouble.typeId() is checked in ModelAPI_TestConstants assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.typeId()) -assert (aCircleRadius.value() == 0) anCircleCentr.setValue(-25., -25) aCircleRadius.setValue(25.) assert (anCircleCentr.x() == -25) diff --git a/src/SketchPlugin/Test/TestSketchPointLine.py b/src/SketchPlugin/Test/TestSketchPointLine.py index 55414c9c8..f7880bf34 100644 --- a/src/SketchPlugin/Test/TestSketchPointLine.py +++ b/src/SketchPlugin/Test/TestSketchPointLine.py @@ -47,8 +47,6 @@ assert (len(aSketchReflist.list()) == 0) aSketchPoint = aSketchFeature.addFeature("SketchPoint") assert (aSketchPoint.getKind() == "SketchPoint") coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordindates")) -assert (coords.x() == 0) -assert (coords.y() == 0) assert (not coords.isInitialized()) # Simulate SketchPlugin_Point::move(...) coords.setValue(10., 10.) @@ -72,11 +70,7 @@ assert (aSketchReflist.size() == 2) assert (len(aSketchReflist.list()) == 2) aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) -assert (aLineStartPoint.x() == 0) -assert (aLineStartPoint.y() == 0) assert (not aLineStartPoint.isInitialized()) -assert (aLineEndPoint.x() == 0) -assert (aLineEndPoint.y() == 0) assert (not aLineEndPoint.isInitialized()) # Simulate SketchPlugin_Line::move(...) aLineStartPoint.setValue(50., 50.) -- 2.39.2