SET(PROJECT_HEADERS
ModelHighAPI.h
ModelHighAPI_Double.h
+ ModelHighAPI_Integer.h
ModelHighAPI_Interface.h
ModelHighAPI_Macro.h
ModelHighAPI_Selection.h
SET(PROJECT_SOURCES
ModelHighAPI_Double.cpp
+ ModelHighAPI_Integer.cpp
ModelHighAPI_Interface.cpp
ModelHighAPI_Selection.cpp
ModelHighAPI_Tools.cpp
ADD_UNIT_TESTS(
TestDouble.py
+ TestInteger.py
)
# ADD_SUBDIRECTORY (Test)
%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"
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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_ */
#include <ModelAPI_AttributeString.h>
//--------------------------------------------------------------------------------------
#include "ModelHighAPI_Double.h"
+#include "ModelHighAPI_Integer.h"
#include "ModelHighAPI_Selection.h"
//--------------------------------------------------------------------------------------
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)
class ModelAPI_AttributeString;
//--------------------------------------------------------------------------------------
class ModelHighAPI_Double;
+class ModelHighAPI_Integer;
class ModelHighAPI_Selection;
//--------------------------------------------------------------------------------------
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);
#include "ModelHighAPI.h"
#include "ModelHighAPI_Double.h"
+ #include "ModelHighAPI_Integer.h"
#include "ModelHighAPI_Interface.h"
#include "ModelHighAPI_Macro.h"
#include "ModelHighAPI_Selection.h"
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()
--- /dev/null
+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()
#include <SketchPlugin_Line.h>
-#include <SketchAPI_SketchEntity.h>
+#include "SketchAPI_SketchEntity.h"
//--------------------------------------------------------------------------------------
class ModelHighAPI_Selection;
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Macro.h>
//--------------------------------------------------------------------------------------
class ModelAPI_CompositeFeature;
+class ModelHighAPI_Double;
class ModelHighAPI_Selection;
class SketchAPI_Line;
//--------------------------------------------------------------------------------------