]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add Mirror and fix tests
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 16 Jun 2016 09:00:17 +0000 (12:00 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:10 +0000 (14:41 +0300)
13 files changed:
src/ModelHighAPI/ModelHighAPI_Interface.cpp
src/ModelHighAPI/ModelHighAPI_Interface.h
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/PythonAPI/Test/TestSketcherAddMirror.py
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Mirror.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Mirror.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_swig.h

index 4fd119a3a9f384e9bba7eb682fb596a7fcbfe231..e200c9c65e5d438fa8455d9519c1953c83cfba81 100644 (file)
@@ -55,6 +55,11 @@ std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
   return aSelectionList;
 }
 
+std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
+{
+  return feature()->lastResult();
+}
+
 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
 {
   Events_Error::send(theDescription);
index fd536ca333427158dcc0a7fa7970814688700fad..97084a50bc2223434188c0c49fdbe0d11bc01bd7 100644 (file)
@@ -15,6 +15,7 @@
 #include <string>
 //--------------------------------------------------------------------------------------
 class ModelAPI_Feature;
+class ModelAPI_Result;
 class ModelHighAPI_Selection;
 //--------------------------------------------------------------------------------------
 /**\class ModelHighAPI_Interface
@@ -43,10 +44,15 @@ public:
   MODELHIGHAPI_EXPORT
   void execute();
 
+  // TODO(spo): rename to selectAll()
   /// Return all objects of the feature
   MODELHIGHAPI_EXPORT
   virtual std::list<ModelHighAPI_Selection> result() const;
 
+  /// Return default result. Default implementation feature()->lastResult()
+  MODELHIGHAPI_EXPORT
+  virtual std::shared_ptr<ModelAPI_Result> defaultResult() const;
+
   /// Throw exception to event loop
   MODELHIGHAPI_EXPORT
   void throwException(const std::string & theDescription);
index 4f00429c14ce22dcd6cfd0572d303d1c0b9327a3..85b4b7acb1b423bee3159e7d95bb015b3d6418f1 100644 (file)
@@ -13,8 +13,6 @@
 #include <ModelAPI_Result.h>
 #include "ModelHighAPI_Interface.h"
 //--------------------------------------------------------------------------------------
-#include <iostream>
-//--------------------------------------------------------------------------------------
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
 {
 }
@@ -33,9 +31,8 @@ ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
 
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
-: myValue(std::shared_ptr<ModelAPI_Object>(theValue->feature()->firstResult()))
+: myValue(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
 {
-  // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
 }
 
 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
index 9250494b128f5356883ca93bca3c18a7a551e69e..2c300e15ccf65463bb12f384bdb5f4e66bdadd80 100644 (file)
@@ -102,6 +102,15 @@ void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
     it->appendToList(theAttribute);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    theAttribute->append(*it);
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
index ae35740a39108c8779212149c42c2b2780cc08e5..f53e37a1b79f168d0f1d599b429fedcb7b604d53 100644 (file)
@@ -34,6 +34,7 @@ class ModelAPI_AttributeRefList;
 class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
 class ModelAPI_AttributeString;
+class ModelAPI_Object;
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Double;
 class ModelHighAPI_Integer;
@@ -81,6 +82,10 @@ MODELHIGHAPI_EXPORT
 void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
                    const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute);
 
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute);
+
 MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
index 8fc614670041bd836ba6cc5341392dba397b124b..e74b8ea3f1a22303da1ab817ad3d59d1a739230b 100644 (file)
@@ -14,15 +14,13 @@ class SketcherAddLine(SketcherTestCase):
         model.do()
 
     def test_add_mirror(self):
-        mirror = self.sketch.addMirror(
-            self.line.result(), self.circle_1.result()
-            )
+        mirror = self.sketch.addMirror(self.line, [self.circle_1])
         model.do()
         mirrored_objects = mirror.mirroredObjects()
         mirrored_circle = mirrored_objects.object(0)
         circle_feature = ModelAPI_Feature.feature(mirrored_circle)
         center = geomDataAPI_Point2D(circle_feature.attribute("CircleCenter"))
-        self.assertEqual(center.x(), -30, msg="%s" % center.x())
+        self.assertEqual(center.x(), -30)
         # dir(mirrored_circle)
         # center = geomDataAPI_Point2D(mirrored_circle.data().attribute("CircleCenter"))
         # self.assertEqual(center.x(), -30, msg="%s"%(dir(mirrored_circle)))
index 57792bb13bab5bbd004b035aa754ffe931d0b933..9d6ded27cd0643dbf1b289d71f3b8cff398d0b4b 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
   SketchAPI_Arc.h
   SketchAPI_Circle.h
   SketchAPI_Line.h
+  SketchAPI_Mirror.h
   SketchAPI_Sketch.h
   SketchAPI_SketchEntity.h
   SketchAPI_Point.h
@@ -16,6 +17,7 @@ SET(PROJECT_SOURCES
   SketchAPI_Arc.cpp
   SketchAPI_Circle.cpp
   SketchAPI_Line.cpp
+  SketchAPI_Mirror.cpp
   SketchAPI_Sketch.cpp
   SketchAPI_SketchEntity.cpp
   SketchAPI_Point.cpp
index 7cbd61f4c14e0874281591957b2205e9e3f406f5..7359f1d9a74b22fc19527eea0be07c60095ae588 100644 (file)
 %shared_ptr(SketchAPI_Arc)
 %shared_ptr(SketchAPI_Circle)
 %shared_ptr(SketchAPI_Line)
+%shared_ptr(SketchAPI_Mirror)
 %shared_ptr(SketchAPI_Sketch)
 %shared_ptr(SketchAPI_SketchEntity)
 %shared_ptr(SketchAPI_Point)
 
-// fix compilarion error: ‘res2’ was not declared in this scope
+// TODO(spo): move typemaps into ModelHighAPI package
+
+// fix compilarion error: ‘res*’ was not declared in this scope
 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
+%typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
 
 %typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
   }
 }
 
+%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;
+  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_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 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 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"
 %include "SketchAPI_Line.h"
 %include "SketchAPI_Circle.h"
 %include "SketchAPI_Arc.h"
+%include "SketchAPI_Mirror.h"
 %include "SketchAPI_Sketch.h"
diff --git a/src/SketchAPI/SketchAPI_Mirror.cpp b/src/SketchAPI/SketchAPI_Mirror.cpp
new file mode 100644 (file)
index 0000000..d6166e7
--- /dev/null
@@ -0,0 +1,39 @@
+// Name   : SketchAPI_Mirror.cpp
+// Purpose: 
+//
+// History:
+// 16/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI_Mirror.h"
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+SketchAPI_Mirror::SketchAPI_Mirror(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_Mirror::SketchAPI_Mirror(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature,
+    const ModelHighAPI_RefAttr & theMirrorLine,
+    const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    fillAttribute(theMirrorLine, mirrorLine());
+    fillAttribute(theObjects, mirrorList());
+
+    execute();
+  }
+}
+
+SketchAPI_Mirror::~SketchAPI_Mirror()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
diff --git a/src/SketchAPI/SketchAPI_Mirror.h b/src/SketchAPI/SketchAPI_Mirror.h
new file mode 100644 (file)
index 0000000..9f3848d
--- /dev/null
@@ -0,0 +1,55 @@
+// Name   : SketchAPI_Mirror.h
+// Purpose: 
+//
+// History:
+// 16/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_
+#define SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+
+#include <list>
+
+#include <SketchPlugin_ConstraintMirror.h>
+
+#include "SketchAPI_SketchEntity.h"
+//--------------------------------------------------------------------------------------
+class ModelAPI_Object;
+class ModelHighAPI_RefAttr;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Mirror
+ * \ingroup CPPHighAPI
+ * \brief Interface for Mirror feature
+ */
+class SketchAPI_Mirror : public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_Mirror(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Mirror(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                   const ModelHighAPI_RefAttr & theMirrorLine,
+                   const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
+  /// Destructor
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_Mirror();
+
+  INTERFACE_4(SketchPlugin_ConstraintMirror::ID(),
+              mirrorLine, SketchPlugin_ConstraintMirror::ENTITY_A(), ModelAPI_AttributeRefAttr, /** Mirror line */,
+              mirrorList, SketchPlugin_ConstraintMirror::MIRROR_LIST_ID(), ModelAPI_AttributeRefList, /** Mirror list */,
+              sourceObjects, SketchPlugin_ConstraintMirror::ENTITY_B(), ModelAPI_AttributeRefList, /** Source objects */,
+              mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
+  )
+
+};
+
+//! Pointer on Mirror object
+typedef std::shared_ptr<SketchAPI_Mirror> MirrorPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_ */
index bf9fdd1c51395fe384334a6fad2192b507caa4a0..ab58eec605dce518dcb2a81f8c4eebf7392f9a9d 100644 (file)
@@ -34,6 +34,7 @@
 #include "SketchAPI_Arc.h"
 #include "SketchAPI_Circle.h"
 #include "SketchAPI_Line.h"
+#include "SketchAPI_Mirror.h"
 #include "SketchAPI_Point.h"
 //--------------------------------------------------------------------------------------
 SketchAPI_Sketch::SketchAPI_Sketch(
@@ -313,6 +314,15 @@ std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theE
   return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
 }
 
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
+    const ModelHighAPI_RefAttr & theMirrorLine,
+    const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
+  return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
     const ModelHighAPI_RefAttr & theLine1,
index 50d17a36474513071c154b054f35799498ffc1f9..8525b4388db1867e27fd635f018ce601f8e61bae 100644 (file)
 #include <ModelHighAPI_Macro.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_CompositeFeature;
+class ModelAPI_Object;
 class ModelHighAPI_Double;
 class ModelHighAPI_RefAttr;
 class ModelHighAPI_Selection;
 class SketchAPI_Arc;
 class SketchAPI_Circle;
 class SketchAPI_Line;
+class SketchAPI_Mirror;
 class SketchAPI_Point;
 //--------------------------------------------------------------------------------------
 /**\class SketchAPI_Sketch
@@ -181,6 +183,12 @@ public:
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
 
+  /// Add mirror
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Mirror> addMirror(
+      const ModelHighAPI_RefAttr & theMirrorLine,
+      const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
+
   /// Set angle
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelAPI_Feature> setAngle(
@@ -236,8 +244,6 @@ public:
       const ModelHighAPI_RefAttr & thePoint,
       const ModelHighAPI_RefAttr & theLine);
 
-  // TODO(spo): setMirror
-
   /// Set parallel
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelAPI_Feature> setParallel(
index 32a60738efe8c822190f51f50c50c8145ed72933..c65c853f27a0bc11e34e4f4e76e099b9b08fc519 100644 (file)
@@ -13,6 +13,7 @@
   #include "SketchAPI_Arc.h"
   #include "SketchAPI_Circle.h"
   #include "SketchAPI_Line.h"
+  #include "SketchAPI_Mirror.h"
   #include "SketchAPI_Sketch.h"
   #include "SketchAPI_SketchEntity.h"
   #include "SketchAPI_Point.h"