Salome HOME
Fix sketch Unit Tests
authorazv <azv@opencascade.com>
Tue, 16 Aug 2016 13:39:36 +0000 (16:39 +0300)
committerazv <azv@opencascade.com>
Tue, 16 Aug 2016 13:47:05 +0000 (16:47 +0300)
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/SketchAPI/SketchAPI.i
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp
src/SketchPlugin/Test/TestSketchArcCircle.py
src/SketchPlugin/Test/TestSketchPointLine.py

index c9ff7f1f41a7eeb8c08827883e70d59c0f7aeefa..917af05babfd456423181a548f98a10ce0257dea 100644 (file)
@@ -33,6 +33,8 @@
 #include <TopoDS_Shape.hxx>
 #include <TopExp_Explorer.hxx>
 
+#include <ios>
+
 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<GeomAPI_Shape>&
   // output the main characteristics
   aResult<<"Volume: "<<setprecision(2)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
-  aResult<<"Center of mass: "
+  aResult<<"Center of mass: "<<std::fixed<<setprecision(7)
     <<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
   return aResult.str();
 }
index c81ea84ef360c2dcc4d99014a0617ec36df6adf4..734b87599f0247aeb07cf4c5d15b1f4aa92681c8 100644 (file)
   }
 }
 
+%typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * 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<ModelAPI_Object> *), 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<ModelHighAPI_Interface> *), 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"
index 2161806ebd3a21c805f4d2661645e482e216cda1..d63c196a4e754a309447dc41ea979276079a1451 100755 (executable)
@@ -229,23 +229,20 @@ void SketchPlugin_ConstraintMirror::erase()
   SketchPlugin_ConstraintBase::erase();
 }
 
+#include <ModelAPI_AttributeRefAttrList.h>
 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<ModelAPI_AttributeRefList>(
           data()->attribute(SketchPlugin_Constraint::ENTITY_C()));
       std::list<ObjectPtr> aTargetList = aRefListOfMirrored->list();
-      std::list<ObjectPtr>::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<ModelAPI_ResultConstruction>(*aTargetIter);
-        DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr();
-        FeaturePtr aFeature =  aDoc ? aDoc->feature(aRC) : FeaturePtr();
+      std::list<ObjectPtr>::reverse_iterator aTargetIter = aTargetList.rbegin();
+      for (; aTargetIter != aTargetList.rend(); aTargetIter++) {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter);
         if (aFeature)
           aDoc->removeFeature(aFeature);
       }
index d853339c43f5d348295719ce382bb192946f7069..897e9bb779a14c4c9cc9402bb77d6b52d6e0e915 100644 (file)
@@ -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)
index 55414c9c8f9c811b93bf8cb6aa2634dd9fdb62a6..f7880bf34108b227bbb1e2769fbe0956093f822e 100644 (file)
@@ -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.)