]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add Integer attribute support
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 8 Jun 2016 13:17:36 +0000 (16:17 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:05 +0000 (14:41 +0300)
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_Integer.cpp [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Integer.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/ModelHighAPI/ModelHighAPI_swig.h
src/ModelHighAPI/Test/TestDouble.py
src/ModelHighAPI/Test/TestInteger.py [new file with mode: 0644]
src/SketchAPI/SketchAPI_Line.h
src/SketchAPI/SketchAPI_Sketch.h

index c495be0d1ee2198e34aea89cc60260ef20574834..4a68b50e08dd0515efab4397e8a8b88c3d539eea 100644 (file)
@@ -5,6 +5,7 @@ INCLUDE(Common)
 SET(PROJECT_HEADERS
   ModelHighAPI.h
   ModelHighAPI_Double.h
+  ModelHighAPI_Integer.h
   ModelHighAPI_Interface.h
   ModelHighAPI_Macro.h
   ModelHighAPI_Selection.h
@@ -13,6 +14,7 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
   ModelHighAPI_Double.cpp
+  ModelHighAPI_Integer.cpp
   ModelHighAPI_Interface.cpp
   ModelHighAPI_Selection.cpp
   ModelHighAPI_Tools.cpp
@@ -73,6 +75,7 @@ INCLUDE(UnitTest)
 
 ADD_UNIT_TESTS(
   TestDouble.py
+  TestInteger.py
 )
 
 # ADD_SUBDIRECTORY (Test)
index 63199a34b4957b1afa32ee4c89dbea6f6b1d186d..f8d01f872eb1544d156e585f2dfe208065a81416 100644 (file)
@@ -20,6 +20,7 @@
 %shared_ptr(ModelHighAPI_Interface)
 
 // typemaps
+
 %typemap(in) const ModelHighAPI_Double & (ModelHighAPI_Double temp) {
   if (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) {
     temp = ModelHighAPI_Double(PyFloat_AsDouble($input));
   $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input)) ? 1 : 0;
 }
 
+%typemap(in) const ModelHighAPI_Integer & (ModelHighAPI_Integer temp) {
+  if (PyInt_Check($input)) {
+    temp = ModelHighAPI_Integer(static_cast<int>(PyInt_AsLong($input)));
+    $1 = &temp;
+  } else if (PyString_Check($input)) {
+    temp = ModelHighAPI_Integer(PyString_AsString($input));
+    $1 = &temp;
+  } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+  } else {
+    PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Integer, int or string.");
+    return NULL;
+  }
+}
+
+%typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & {
+  $1 = (PyInt_Check($input) || PyString_Check($input)) ? 1 : 0;
+}
+
 // all supported interfaces
 %include "ModelHighAPI_Double.h"
+%include "ModelHighAPI_Integer.h"
 %include "ModelHighAPI_Interface.h"
 %include "ModelHighAPI_Macro.h"
 %include "ModelHighAPI_Selection.h"
diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.cpp b/src/ModelHighAPI/ModelHighAPI_Integer.cpp
new file mode 100644 (file)
index 0000000..68a6123
--- /dev/null
@@ -0,0 +1,49 @@
+// Name   : ModelHighAPI_Integer.cpp
+// Purpose: 
+//
+// History:
+// 29/03/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_Integer.h"
+
+#include <ModelAPI_AttributeInteger.h>
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+ModelHighAPI_Integer::ModelHighAPI_Integer(int theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_Integer::ModelHighAPI_Integer(const std::string & theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_Integer::ModelHighAPI_Integer(const char * theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_Integer::~ModelHighAPI_Integer()
+{
+}
+
+//--------------------------------------------------------------------------------------
+struct fill_visitor : boost::static_visitor<void>
+{
+  mutable std::shared_ptr<ModelAPI_AttributeInteger> myAttribute;
+
+  fill_visitor(const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
+  : myAttribute(theAttribute) {}
+
+  void operator()(int theValue) const { myAttribute->setValue(theValue); }
+  void operator()(const std::string & theValue) const { myAttribute->setText(theValue); }
+};
+
+void ModelHighAPI_Integer::fillAttribute(
+    const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute) const
+{
+  boost::apply_visitor(fill_visitor(theAttribute), myValue);
+}
diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.h b/src/ModelHighAPI/ModelHighAPI_Integer.h
new file mode 100644 (file)
index 0000000..7650b12
--- /dev/null
@@ -0,0 +1,50 @@
+// Name   : ModelHighAPI_Integer.h
+// Purpose: 
+//
+// History:
+// 29/03/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_INTEGER_H_
+#define SRC_MODELHIGHAPI_MODELHIGHAPI_INTEGER_H_
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI.h"
+
+#include <memory>
+#include <string>
+
+#include <boost/variant.hpp>
+//--------------------------------------------------------------------------------------
+class ModelAPI_AttributeInteger;
+//--------------------------------------------------------------------------------------
+/**\class ModelHighAPI_Integer
+ * \ingroup CPPHighAPI
+ * \brief Class for filling ModelAPI_AttributeInteger
+ */
+class ModelHighAPI_Integer
+{
+public:
+  /// Constructor for int
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Integer(int theValue = 0.);
+  /// Constructor for std::string
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Integer(const std::string & theValue);
+  /// Constructor for char *
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Integer(const char * theValue);
+  /// Destructor
+  MODELHIGHAPI_EXPORT
+  virtual ~ModelHighAPI_Integer();
+
+  /// Fill attribute values
+  MODELHIGHAPI_EXPORT
+  virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute) const;
+
+private:
+  boost::variant<int, std::string> myValue;
+};
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_INTEGER_H_ */
index 46bf241bd0ad867b36057eaacec6b8ae94624c75..4e7efcac7ae9c8a640126fa0c770c7a3cff35958 100644 (file)
@@ -29,6 +29,7 @@
 #include <ModelAPI_AttributeString.h>
 //--------------------------------------------------------------------------------------
 #include "ModelHighAPI_Double.h"
+#include "ModelHighAPI_Integer.h"
 #include "ModelHighAPI_Selection.h"
 
 //--------------------------------------------------------------------------------------
@@ -72,6 +73,13 @@ void fillAttribute(const ModelHighAPI_Double & theValue,
   theValue.fillAttribute(theAttribute);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const ModelHighAPI_Integer & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
+{
+  theValue.fillAttribute(theAttribute);
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
index 91163898d444ffe37b36aa66877d77ec9d689b82..0dc48aa93ac93104f643fe67f776db32645c20c8 100644 (file)
@@ -36,6 +36,7 @@ class ModelAPI_AttributeSelectionList;
 class ModelAPI_AttributeString;
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Double;
+class ModelHighAPI_Integer;
 class ModelHighAPI_Selection;
 //--------------------------------------------------------------------------------------
 MODELHIGHAPI_EXPORT
@@ -63,6 +64,10 @@ MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Double & theValue,
                    const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute);
 
+MODELHIGHAPI_EXPORT
+void fillAttribute(const ModelHighAPI_Integer & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
+
 MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
index 7fa918cd0bc6852943a627f0c8c3d46a54317187..284d46f1936cd4e341be19ab70b605b1fb2ba4c6 100644 (file)
@@ -11,6 +11,7 @@
 
   #include "ModelHighAPI.h"
   #include "ModelHighAPI_Double.h"
+  #include "ModelHighAPI_Integer.h"
   #include "ModelHighAPI_Interface.h"
   #include "ModelHighAPI_Macro.h"
   #include "ModelHighAPI_Selection.h"
index d34c8d420be008d9f9b7653a0ddf8f265f4449d4..6735af347bbd7ce6d3f5dc64d5798444f77a25b3 100644 (file)
@@ -9,12 +9,10 @@ class DoubleTestCase(unittest.TestCase):
 
     def test_create_from_double(self):
         from_double = ModelHighAPI.ModelHighAPI_Double(100.)
-#         self.assertEqual(100., from_double.value())
 
     def test_create_from_text(self):
         from_string = ModelHighAPI.ModelHighAPI_Double("200 + x")
-#         self.assertEqual("200 + x", from_string.text())
-    
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/src/ModelHighAPI/Test/TestInteger.py b/src/ModelHighAPI/Test/TestInteger.py
new file mode 100644 (file)
index 0000000..c20b264
--- /dev/null
@@ -0,0 +1,18 @@
+import unittest
+
+import ModelHighAPI
+
+class IntegerTestCase(unittest.TestCase):
+
+    def test_create_default(self):
+        default = ModelHighAPI.ModelHighAPI_Integer()
+
+    def test_create_from_integer(self):
+        from_integer = ModelHighAPI.ModelHighAPI_Integer(100)
+
+    def test_create_from_text(self):
+        from_string = ModelHighAPI.ModelHighAPI_Integer("200 + x")
+
+
+if __name__ == "__main__":
+    unittest.main()
index bdedb921b911ef0d4f64a95e224b4a3c85a345b9..c2f3d98f5dc866d4cae2c8b0f70cd734e3986555 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <SketchPlugin_Line.h>
 
-#include <SketchAPI_SketchEntity.h>
+#include "SketchAPI_SketchEntity.h"
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Selection;
 //--------------------------------------------------------------------------------------
index cc8e3f64e86b8db451e1fe64a69fc830c7883aac..26ea81b9d7706961a9652d923531e137f562564a 100644 (file)
@@ -17,6 +17,7 @@
 #include <ModelHighAPI_Macro.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_CompositeFeature;
+class ModelHighAPI_Double;
 class ModelHighAPI_Selection;
 class SketchAPI_Line;
 //--------------------------------------------------------------------------------------