]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add support for RefAttr attribute, create setCoincedent constraint
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 9 Jun 2016 13:05:10 +0000 (16:05 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:05 +0000 (14:41 +0300)
17 files changed:
src/ConstructionAPI/CMakeLists.txt
src/ExchangeAPI/CMakeLists.txt
src/ExchangeAPI/Test/TestExchange.py
src/GeomDataAPI/GeomDataAPI_swig.h
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_Macro.h
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_RefAttr.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/ModelHighAPI/ModelHighAPI_swig.h
src/ModelHighAPI/Test/TestRefAttr.py [new file with mode: 0644]
src/PythonAPI/Test/TestSketcherSetCoincident.py
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/Test/TestSketch.py

index c5ff9c9d3647164ad1334e678332ee561cbefce0..68342d5eb6146b2e45abf85ef741e7b7eca19828 100644 (file)
@@ -28,6 +28,8 @@ INCLUDE_DIRECTORIES(
 INCLUDE_DIRECTORIES(
   # TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers
   ${PROJECT_SOURCE_DIR}/src/GeomAPI
+  # TODO(spo): it is for *_swig.h files. Can we eliminate it?
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/ConstructionPlugin
 )
 
index b520552f57b87387425dbf437d3597e8e8ea4625..4647616c3f739529990f9603f83509a62f6ac261 100644 (file)
@@ -26,8 +26,9 @@ INCLUDE_DIRECTORIES(
 
 # Plugin headers dependency
 INCLUDE_DIRECTORIES(
-  # TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers
+  # TODO(spo): modify ExchangePlugin headers to remove dependency on GeomAPI headers
   ${PROJECT_SOURCE_DIR}/src/GeomAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/ExchangePlugin
 )
 
index 5f1576c77f84b3902ece81d7a38ff930defd3adc..0e73c2dcf9d9e8dff56f66dfb1c7fb146c7bb9dc 100644 (file)
@@ -3,7 +3,7 @@ import unittest
 import ModelAPI
 import ExchangeAPI
 
-class PointTestCase(unittest.TestCase):
+class ExchangeTestCase(unittest.TestCase):
 
     def setUp(self):
         self.session = ModelAPI.ModelAPI_Session.get()
index c24d49360bf43cbe5b1c29ab34a057fc50057a2c..aecd5ce2ba3c40e18d9bd003dddbbf2acada3514 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef SRC_GEOMDATAAPI_GEOMDATAAPI_SWIG_H_
 #define SRC_GEOMDATAAPI_GEOMDATAAPI_SWIG_H_
 
-  #include "ModelAPI_swig.h"
+  #include <ModelAPI_swig.h>
 
   #include "GeomDataAPI.h"
   #include "GeomDataAPI_Point.h"
index 4a68b50e08dd0515efab4397e8a8b88c3d539eea..ec80ab7cff408f532fc7bd93b641c9702c92d710 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
   ModelHighAPI_Integer.h
   ModelHighAPI_Interface.h
   ModelHighAPI_Macro.h
+  ModelHighAPI_RefAttr.h
   ModelHighAPI_Selection.h
   ModelHighAPI_Tools.h
 )
@@ -16,6 +17,7 @@ SET(PROJECT_SOURCES
   ModelHighAPI_Double.cpp
   ModelHighAPI_Integer.cpp
   ModelHighAPI_Interface.cpp
+  ModelHighAPI_RefAttr.cpp
   ModelHighAPI_Selection.cpp
   ModelHighAPI_Tools.cpp
 )
@@ -76,6 +78,7 @@ INCLUDE(UnitTest)
 ADD_UNIT_TESTS(
   TestDouble.py
   TestInteger.py
+  TestRefAttr.py
 )
 
 # ADD_SUBDIRECTORY (Test)
index f8d01f872eb1544d156e585f2dfe208065a81416..30bb59da35246e02bc326bc065ac6813e9f73c26 100644 (file)
@@ -7,6 +7,10 @@
 
 %include "doxyhelp.i"
 
+// import other modules
+%import "ModelAPI.i"
+%import "GeomDataAPI.i"
+
 // to avoid error on this
 #define MODELHIGHAPI_EXPORT
 
@@ -34,7 +38,6 @@
     return NULL;
   }
 }
-
 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & {
   $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input)) ? 1 : 0;
 }
     return NULL;
   }
 }
-
 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & {
   $1 = (PyInt_Check($input) || PyString_Check($input)) ? 1 : 0;
 }
 
+%typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
+  std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  int newmem = 0;
+  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+    temp = ModelHighAPI_RefAttr(*temp_attribute);
+    if (newmem & SWIG_CAST_NEW_MEMORY) {
+      delete temp_attribute;
+    }
+    $1 = &temp;
+  } else
+  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+    temp = ModelHighAPI_RefAttr(*temp_object);
+    if (newmem & SWIG_CAST_NEW_MEMORY) {
+      delete temp_object;
+    }
+    $1 = &temp;
+  } else
+  if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+  } else {
+    PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Double, float, int or string.");
+    return NULL;
+  }
+}
+
 // all supported interfaces
 %include "ModelHighAPI_Double.h"
 %include "ModelHighAPI_Integer.h"
 %include "ModelHighAPI_Interface.h"
 %include "ModelHighAPI_Macro.h"
+%include "ModelHighAPI_RefAttr.h"
 %include "ModelHighAPI_Selection.h"
 %include "ModelHighAPI_Tools.h"
-
-// std::list -> []
-%template(SelectionList) std::list<ModelHighAPI_Selection>;
index 4d2e9e5b91ccc38be53f69a7f4f790358c56597b..e62c89ba411f4bd64df87b6e064a33cf4c2a03a8 100644 (file)
@@ -7,6 +7,10 @@
 #ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_
 #define SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_
 
+//--------------------------------------------------------------------------------------
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeDocRef.h>
diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
new file mode 100644 (file)
index 0000000..098308b
--- /dev/null
@@ -0,0 +1,50 @@
+// Name   : ModelHighAPI_RefAttr.cpp
+// Purpose: 
+//
+// History:
+// 08/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_RefAttr.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+//--------------------------------------------------------------------------------------
+#include <iostream>
+//--------------------------------------------------------------------------------------
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
+{
+}
+
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
+    const std::shared_ptr<ModelAPI_Attribute> & theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
+    const std::shared_ptr<ModelAPI_Object> & theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
+{
+}
+
+//--------------------------------------------------------------------------------------
+struct fill_visitor : boost::static_visitor<void>
+{
+  mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
+
+  fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
+  : myAttribute(theAttribute) {}
+
+  void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
+  void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
+};
+
+void ModelHighAPI_RefAttr::fillAttribute(
+    const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
+{
+  boost::apply_visitor(fill_visitor(theAttribute), myValue);
+}
diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.h b/src/ModelHighAPI/ModelHighAPI_RefAttr.h
new file mode 100644 (file)
index 0000000..14fcc55
--- /dev/null
@@ -0,0 +1,55 @@
+// Name   : ModelHighAPI_RefAttr.h
+// Purpose: 
+//
+// History:
+// 08/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_
+#define SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI.h"
+
+#include <memory>
+#include <string>
+
+#include <boost/variant.hpp>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Attribute;
+class ModelAPI_AttributeRefAttr;
+class ModelAPI_Object;
+//--------------------------------------------------------------------------------------
+/**\class ModelHighAPI_RefAttr
+ * \ingroup CPPHighAPI
+ * \brief Class for filling ModelAPI_AttributeRefAttr
+ */
+class ModelHighAPI_RefAttr
+{
+public:
+  /// Default constructor
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_RefAttr();
+  /// Constructor for attribute
+  MODELHIGHAPI_EXPORT
+  explicit ModelHighAPI_RefAttr(const std::shared_ptr<ModelAPI_Attribute> & theValue);
+  /// Constructor for object
+  MODELHIGHAPI_EXPORT
+  explicit ModelHighAPI_RefAttr(const std::shared_ptr<ModelAPI_Object> & theValue);
+  /// Destructor
+  MODELHIGHAPI_EXPORT
+  virtual ~ModelHighAPI_RefAttr();
+
+  /// Fill attribute values
+  MODELHIGHAPI_EXPORT
+  virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const;
+
+private:
+  boost::variant<
+    std::shared_ptr<ModelAPI_Attribute>,
+    std::shared_ptr<ModelAPI_Object>
+  > myValue;
+};
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_ */
index 4e7efcac7ae9c8a640126fa0c770c7a3cff35958..dc74b7ae1ce99274e6b241cca5375182e19de878 100644 (file)
@@ -30,6 +30,7 @@
 //--------------------------------------------------------------------------------------
 #include "ModelHighAPI_Double.h"
 #include "ModelHighAPI_Integer.h"
+#include "ModelHighAPI_RefAttr.h"
 #include "ModelHighAPI_Selection.h"
 
 //--------------------------------------------------------------------------------------
@@ -80,6 +81,13 @@ void fillAttribute(const ModelHighAPI_Integer & theValue,
   theValue.fillAttribute(theAttribute);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const ModelHighAPI_RefAttr & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
+{
+  theValue.fillAttribute(theAttribute);
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
index 0dc48aa93ac93104f643fe67f776db32645c20c8..17d7f0523221a7faf5e7d2a7a756bd436d7b9801 100644 (file)
@@ -37,6 +37,7 @@ class ModelAPI_AttributeString;
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Double;
 class ModelHighAPI_Integer;
+class ModelHighAPI_RefAttr;
 class ModelHighAPI_Selection;
 //--------------------------------------------------------------------------------------
 MODELHIGHAPI_EXPORT
@@ -68,6 +69,10 @@ MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Integer & theValue,
                    const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
 
+MODELHIGHAPI_EXPORT
+void fillAttribute(const ModelHighAPI_RefAttr & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute);
+
 MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
index 284d46f1936cd4e341be19ab70b605b1fb2ba4c6..01d0afd43255b3323e5bc30bb4a0474876c30c1a 100644 (file)
@@ -7,13 +7,15 @@
 #ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_
 #define SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_
 
-  #include <ModelAPI.h>
+  #include <ModelAPI_swig.h>
+  #include <GeomDataAPI_swig.h>
 
   #include "ModelHighAPI.h"
   #include "ModelHighAPI_Double.h"
   #include "ModelHighAPI_Integer.h"
   #include "ModelHighAPI_Interface.h"
   #include "ModelHighAPI_Macro.h"
+  #include "ModelHighAPI_RefAttr.h"
   #include "ModelHighAPI_Selection.h"
   #include "ModelHighAPI_Tools.h"
 
diff --git a/src/ModelHighAPI/Test/TestRefAttr.py b/src/ModelHighAPI/Test/TestRefAttr.py
new file mode 100644 (file)
index 0000000..a57ce92
--- /dev/null
@@ -0,0 +1,39 @@
+import unittest
+
+import ModelAPI
+import ModelHighAPI
+import model
+
+class FeaturesFixture(unittest.TestCase):
+
+    def setUp(self):
+        model.begin()
+        # Create part
+        partset = model.moduleDocument()
+        self.part = model.addPart(partset).document()
+        model.do()
+        self.feature = model.addPoint(self.part, 0, 0, 0)
+
+    def tearDown(self):
+        model.end()
+        model.reset()
+
+
+class RefAttrTestCase(FeaturesFixture):
+
+    def test_create_default(self):
+        ModelHighAPI.ModelHighAPI_RefAttr()
+
+    def test_create_from_attribute(self):
+        print(self.feature.x())
+        ModelHighAPI.ModelHighAPI_RefAttr(self.feature.x())
+
+    def test_create_from_object(self):
+        ModelHighAPI.ModelHighAPI_RefAttr(self.feature.feature())
+
+    def test_create_from_None(self):
+        ModelHighAPI.ModelHighAPI_RefAttr(None)
+
+
+if __name__ == "__main__":
+    unittest.main()
index 8f75d13939ff92e21a0744ed5a49446a9a67861e..09518cf8008ee52e14d977e3e34537b69e9dbbdd 100644 (file)
@@ -2,18 +2,18 @@ import unittest
 import model
 from TestSketcher import SketcherTestCase
 
-class SketcherSetCoincident(SketcherTestCase):   
+class SketcherSetCoincident(SketcherTestCase):
     def test_set_coincident(self):
         l1 = self.sketch.addLine(0, 0, 0, 1)
         l2 = self.sketch.addLine(0, 1, 1, 1)
         self.sketch.setCoincident(l1.endPoint(), l2.startPoint())
         model.do()
-    
-    def test_none_type_arguments(self):
-        l2 = self.sketch.addLine(0, 1, 1, 1)
-        with self.assertRaises(TypeError):
-            self.sketch.setCoincident(None, l2.startPoint())
-        
+
+    def test_none_type_arguments(self):
+        l2 = self.sketch.addLine(0, 1, 1, 1)
+        with self.assertRaises(TypeError):
+            self.sketch.setCoincident(None, l2.startPoint())
+
     def test_empty_arguments(self):
         l1 = self.sketch.addLine(0, 0, 0, 1)
         with self.assertRaises(TypeError):
index e16966ecac78be584ec5413fa2cf7d8a442fa686..57c01c05d5e7a6feceabfaac6fd410f222900539 100644 (file)
@@ -7,6 +7,25 @@
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Sketch.h"
 //--------------------------------------------------------------------------------------
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintAngle.h>
+//#include <SketchPlugin_ConstraintBase.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintFillet.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
+#include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_ConstraintVertical.h>
+//--------------------------------------------------------------------------------------
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelHighAPI_Tools.h>
 #include "SketchAPI_Line.h"
@@ -109,3 +128,23 @@ std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & th
 }
 
 //--------------------------------------------------------------------------------------
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
+    const ModelHighAPI_RefAttr & thePoint1,
+    const ModelHighAPI_RefAttr & thePoint2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+  fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
+  fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+  aFeature->execute();
+  return aFeature;
+}
+
+//--------------------------------------------------------------------------------------
+void SketchAPI_Sketch::setValue(
+    const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+    const ModelHighAPI_Double & theValue)
+{
+  fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
+}
+
+//--------------------------------------------------------------------------------------
index 26ea81b9d7706961a9652d923531e137f562564a..ecde2ce28b3278d108efd33508c2a0c69902826d 100644 (file)
@@ -18,6 +18,7 @@
 //--------------------------------------------------------------------------------------
 class ModelAPI_CompositeFeature;
 class ModelHighAPI_Double;
+class ModelHighAPI_RefAttr;
 class ModelHighAPI_Selection;
 class SketchAPI_Line;
 //--------------------------------------------------------------------------------------
@@ -82,10 +83,24 @@ public:
   // TODO(spo): addCircle
   // TODO(spo): addArc
 
+  /// Set coincident
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setCoincident(
+      // TODO(spo): should it be more concrete type (e.g. ModelAPI_Object)?
+      const ModelHighAPI_RefAttr & thePoint1,
+      const ModelHighAPI_RefAttr & thePoint2);
+
   // TODO(spo): set* (constraints)
 
-  // TODO(spo): setValue
-  // TODO(spo): setText
+  // TODO(spo): addMirror
+
+  /// Set value
+  SKETCHAPI_EXPORT
+  void setValue(
+      const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+      const ModelHighAPI_Double & theValue);
+
+  // TODO(spo): setText. Is it necessary as setValue accepts text expressions?
 
 protected:
   std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
index 5f1576c77f84b3902ece81d7a38ff930defd3adc..091554acd808b003d779c1ab5dd5adf918e6d3c0 100644 (file)
@@ -1,9 +1,9 @@
 import unittest
 
 import ModelAPI
-import ExchangeAPI
+import SketchAPI
 
-class PointTestCase(unittest.TestCase):
+class SketchTestCase(unittest.TestCase):
 
     def setUp(self):
         self.session = ModelAPI.ModelAPI_Session.get()
@@ -12,15 +12,7 @@ class PointTestCase(unittest.TestCase):
     def tearDown(self):
         self.session.closeAll()
 
-    def test_addImport(self):
-        self.session.startOperation()
-        self.feature = ExchangeAPI.addImport(self.doc, "file_path")
-        self.session.finishOperation()
-
-    def test_addExport(self):
-        self.session.startOperation()
-        self.feature = ExchangeAPI.exportToFile(self.doc, "file_path", "file_format", [])
-        self.session.finishOperation()
+# TODO(spo): add tests.
 
 if __name__ == "__main__":
     unittest.main()