]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Parametric API high level for the primitive "Box".
authorClarisse Genrault <clarisse.genrault@cea.fr>
Fri, 1 Jul 2016 10:06:58 +0000 (12:06 +0200)
committerdbv <dbv@opencascade.com>
Thu, 7 Jul 2016 09:39:43 +0000 (12:39 +0300)
18 files changed:
CMakeLists.txt
src/PrimitivesAPI/CMakeLists.txt [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI.h [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI.i [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_Box.cpp [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_Box.h [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_swig.h [new file with mode: 0644]
src/PrimitivesPlugin/PrimitivesPlugin.h
src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp
src/PrimitivesPlugin/PrimitivesPlugin_Box.h
src/PythonAPI/CMakeLists.txt
src/PythonAPI/Test/TestFeatures.py
src/PythonAPI/Test/TestPrimitivesBox.py [new file with mode: 0644]
src/PythonAPI/examples/MakeBrick3.py
src/PythonAPI/extension/__init__.py
src/PythonAPI/extension/box.py
src/PythonAPI/model/__init__.py
src/PythonAPI/model/primitives/__init__.py [new file with mode: 0644]

index f0884dbda87cb77e4d803fb79745b15eec9a73f5..b24566bcb43c9e442d11299ec41ec8d3c6c412e0 100644 (file)
@@ -118,6 +118,7 @@ ADD_SUBDIRECTORY (src/ExchangeAPI)
 ADD_SUBDIRECTORY (src/FeaturesAPI)
 ADD_SUBDIRECTORY (src/ParametersAPI)
 ADD_SUBDIRECTORY (src/PartSetAPI)
+ADD_SUBDIRECTORY (src/PrimitivesAPI)
 ADD_SUBDIRECTORY (src/SketchAPI)
 
 IF(${HAVE_SALOME})
diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e97ba19
--- /dev/null
@@ -0,0 +1,76 @@
+## Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+INCLUDE(Common)
+
+SET(PROJECT_HEADERS
+  PrimitivesAPI.h
+  PrimitivesAPI_Box.h
+)
+
+SET(PROJECT_SOURCES
+  PrimitivesAPI_Box.cpp
+)
+
+SET(PROJECT_LIBRARIES
+  ModelAPI
+  ModelHighAPI
+)
+
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src/Events
+  ${PROJECT_SOURCE_DIR}/src/ModelAPI
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+)
+
+# Plugin headers dependency
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src/GeomAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+  ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
+)
+
+#TODO(spo): is ${CAS_DEFINITIONS} necessary?
+ADD_DEFINITIONS(-DPRIMITIVESAPI_EXPORTS ${CAS_DEFINITIONS})
+ADD_LIBRARY(PrimitivesAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(PrimitivesAPI ${PROJECT_LIBRARIES})
+
+# SWIG wrapper
+
+INCLUDE(PythonAPI)
+
+SET_SOURCE_FILES_PROPERTIES(PrimitivesAPI.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(PrimitivesAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+
+#TODO(spo): is ModelAPI necessary or it could be received by INTERFACE_ (may require modern CMake)?
+SET(SWIG_LINK_LIBRARIES
+  PrimitivesAPI
+  ModelHighAPI
+  ModelAPI
+  ${PYTHON_LIBRARIES}
+)
+
+SET(SWIG_MODULE_PrimitivesAPI_EXTRA_DEPS ${SWIG_MODULE_PrimitivesAPI_EXTRA_DEPS}
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i
+  doxyhelp.i
+  ${PROJECT_HEADERS}
+)
+
+SWIG_ADD_MODULE(PrimitivesAPI python PrimitivesAPI.i ${PROJECT_HEADERS})
+SWIG_LINK_LIBRARIES(PrimitivesAPI ${SWIG_LINK_LIBRARIES})
+
+IF(WIN32)
+  SET_TARGET_PROPERTIES(_PrimitivesAPI PROPERTIES DEBUG_OUTPUT_NAME _PrimitivesAPI_d)
+ENDIF(WIN32)
+
+INSTALL(TARGETS _PrimitivesAPI DESTINATION ${SHAPER_INSTALL_SWIG})
+INSTALL(TARGETS PrimitivesAPI DESTINATION ${SHAPER_INSTALL_BIN})
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/PrimitivesAPI.py DESTINATION ${SHAPER_INSTALL_SWIG})
+
+# Tests
+INCLUDE(UnitTest)
+
+ADD_UNIT_TESTS(
+)
+
+# ADD_SUBDIRECTORY (Test)
diff --git a/src/PrimitivesAPI/PrimitivesAPI.h b/src/PrimitivesAPI/PrimitivesAPI.h
new file mode 100644 (file)
index 0000000..5ef0b78
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+#ifndef PRIMITIVESAPI_H
+#define PRIMITIVESAPI_H
+
+#if defined PRIMITIVESAPI_EXPORTS
+#if defined WIN32
+#define PRIMITIVESAPI_EXPORT __declspec( dllexport )
+#else
+#define PRIMITIVESAPI_EXPORT
+#endif
+#else
+#if defined WIN32
+#define PRIMITIVESAPI_EXPORT __declspec( dllimport )
+#else
+#define PRIMITIVESAPI_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/PrimitivesAPI/PrimitivesAPI.i b/src/PrimitivesAPI/PrimitivesAPI.i
new file mode 100644 (file)
index 0000000..a84b85a
--- /dev/null
@@ -0,0 +1,25 @@
+/* PrimitivesAPI.i */
+
+%module PrimitivesAPI
+
+%{
+  #include "PrimitivesAPI_swig.h"
+%}
+
+%include "doxyhelp.i"
+
+// import other modules
+%import "ModelHighAPI.i"
+
+// to avoid error on this
+#define PRIMITIVESAPI_EXPORT
+
+// standard definitions
+%include "typemaps.i"
+%include "std_shared_ptr.i"
+
+// shared pointers
+%shared_ptr(PrimitivesAPI_Box)
+
+// all supported interfaces
+%include "PrimitivesAPI_Box.h"
diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.cpp b/src/PrimitivesAPI/PrimitivesAPI_Box.cpp
new file mode 100644 (file)
index 0000000..2c2e016
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
+
+// File:        PrimitivesAPI_Box.cpp
+// Created:     28 June 2016
+// Author:      Clarisse Genrault
+
+#include "PrimitivesAPI_Box.h"
+
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+//==================================================================================================
+PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const ModelHighAPI_Double & theDx,
+                                     const ModelHighAPI_Double & theDy,
+                                     const ModelHighAPI_Double & theDz)
+: ModelHighAPI_Interface(theFeature)
+{
+  if (initialize())
+    setDimensions(theDx, theDy, theDz);
+}
+
+//==================================================================================================
+PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const ModelHighAPI_Selection& theFirstPoint,
+                                     const ModelHighAPI_Selection& theSecondPoint)
+: ModelHighAPI_Interface(theFeature)
+{
+  if (initialize())
+    setPoints(theFirstPoint, theSecondPoint);
+}
+
+//==================================================================================================
+PrimitivesAPI_Box::~PrimitivesAPI_Box()
+{
+
+}
+
+//==================================================================================================
+void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
+                                      const ModelHighAPI_Double& theDy,
+                                      const ModelHighAPI_Double& theDz)
+{
+  fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
+  fillAttribute(theDx, dx());
+  fillAttribute(theDy, dy());
+  fillAttribute(theDz, dz());
+
+  execute();
+}
+
+//==================================================================================================
+void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
+                                  const ModelHighAPI_Selection& theSecondPoint)
+{
+  fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
+  fillAttribute(theFirstPoint, firstPoint());
+  fillAttribute(theSecondPoint, secondPoint());
+
+  execute();
+}
+
+//==================================================================================================
+BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
+              const ModelHighAPI_Double& theDx,
+              const ModelHighAPI_Double& theDy,
+              const ModelHighAPI_Double& theDz)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
+  return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
+}
+
+//==================================================================================================
+BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
+              const ModelHighAPI_Selection& theFirstPoint,
+              const ModelHighAPI_Selection& theSecondPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
+  return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));
+}
\ No newline at end of file
diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.h b/src/PrimitivesAPI/PrimitivesAPI_Box.h
new file mode 100644 (file)
index 0000000..fc08496
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
+
+// File:        PrimitivesAPI_Box.h
+// Created:     28 June 2016
+// Author:      Clarisse Genrault (CEA)
+
+#ifndef PrimitivesAPI_Box_H_
+#define PrimitivesAPI_Box_H_
+
+#include "PrimitivesAPI.h"
+
+#include <PrimitivesPlugin_Box.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Double;
+class ModelHighAPI_Selection;
+
+/// \class PrimitivesPlugin_Box
+/// \ingroup CPPHighAPI
+/// \brief Interface for primitive Box feature.
+class PrimitivesAPI_Box: public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+  
+  /// Constructor with values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                             const ModelHighAPI_Double& theDx,
+                             const ModelHighAPI_Double& theDy,
+                             const ModelHighAPI_Double& theDz);
+  
+  /// Constructor with values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                             const ModelHighAPI_Selection& theFirstPoint,
+                             const ModelHighAPI_Selection& theSecondPoint);
+  
+  /// Destructor.
+  PRIMITIVESAPI_EXPORT
+  virtual ~PrimitivesAPI_Box();
+  
+  INTERFACE_6(PrimitivesPlugin_Box::ID(), 
+             creationMethod, PrimitivesPlugin_Box::CREATION_METHOD(),
+             ModelAPI_AttributeString, /** Creation method */,
+             dx, PrimitivesPlugin_Box::DX_ID(), ModelAPI_AttributeDouble, /** Dimension in X */,
+             dy, PrimitivesPlugin_Box::DY_ID(), ModelAPI_AttributeDouble, /** Dimension in Y */,
+             dz, PrimitivesPlugin_Box::DZ_ID(), ModelAPI_AttributeDouble, /** Dimension in Z */,
+             firstPoint, PrimitivesPlugin_Box::POINT_FIRST_ID(), ModelAPI_AttributeSelection, /** First point */,
+             secondPoint, PrimitivesPlugin_Box::POINT_SECOND_ID(), ModelAPI_AttributeSelection, /** Second point */)
+  
+  /// Set dimensions
+  PRIMITIVESAPI_EXPORT
+  void setDimensions(const ModelHighAPI_Double& theDx,
+                     const ModelHighAPI_Double& theDy,
+                     const ModelHighAPI_Double& theDz);
+  
+  /// Set points
+  PRIMITIVESAPI_EXPORT
+  void setPoints(const ModelHighAPI_Selection& theFirstPoint,
+                 const ModelHighAPI_Selection& theSecondPoint);
+};
+
+/// Pointer on primitive Box object
+typedef std::shared_ptr<PrimitivesAPI_Box> BoxPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Box feature.
+PRIMITIVESAPI_EXPORT
+BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
+              const ModelHighAPI_Double& theDx,
+              const ModelHighAPI_Double& theDy,
+              const ModelHighAPI_Double& theDz);
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Box feature.
+PRIMITIVESAPI_EXPORT
+BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
+              const ModelHighAPI_Selection& theFirstPoint,
+              const ModelHighAPI_Selection& theSecondPoint);
+
+#endif // PrimitivesAPI_Box_H_
\ No newline at end of file
diff --git a/src/PrimitivesAPI/PrimitivesAPI_swig.h b/src/PrimitivesAPI/PrimitivesAPI_swig.h
new file mode 100644 (file)
index 0000000..c3bbe6d
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File:    PrimitivesAPI_swig.h
+// Created: 28 June 2016
+// Author:  Clarisse Genrault (CEA)
+
+#ifndef PrimitivesAPI_swig_H_
+#define PrimitivesAPI_swig_H_
+
+  #include <ModelHighAPI_swig.h>
+  
+  #include "PrimitivesAPI_Box.h"
+
+
+#endif // PrimitivesAPI_swig_H_
index a2996d38da92a6215b0b06cc14a823cd713f73e4..5b616dc1eabeee774e0e1071be7b03526ce26ac4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
 
 #ifndef PRIMITIVESPLUGIN_H
 #define PRIMITIVESPLUGIN_H
index 734d87d8f0593c8a67dbadc09e1ca7e365a862fd..8f150802e728eff70e36841e75a2ea400345a99e 100644 (file)
@@ -24,35 +24,35 @@ PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiati
 //=================================================================================================
 void PrimitivesPlugin_Box::initAttributes()
 {
-  data()->addAttribute(PrimitivesPlugin_Box::METHOD(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::CREATION_METHOD(), ModelAPI_AttributeString::typeId());
 
-  data()->addAttribute(PrimitivesPlugin_Box::DX(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(PrimitivesPlugin_Box::DY(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(PrimitivesPlugin_Box::DZ(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::DX_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::DY_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::DZ_ID(), ModelAPI_AttributeDouble::typeId());
 
-  data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST(), ModelAPI_AttributeSelection::typeId());
-  data()->addAttribute(PrimitivesPlugin_Box::POINT_SECOND(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::POINT_SECOND_ID(), ModelAPI_AttributeSelection::typeId());
 }
 
 //=================================================================================================
 void PrimitivesPlugin_Box::execute()
 {
-  AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Box::METHOD());
+  AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Box::CREATION_METHOD());
   std::string aMethodType = aMethodTypeAttr->value();
   
-  if (aMethodType == "BoxByDimensions"
+  if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()
     createBoxByDimensions();
   
-  if (aMethodType == "BoxByTwoPoints"
+  if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()
     createBoxByTwoPoints();
 }
 
 //=================================================================================================
 void PrimitivesPlugin_Box::createBoxByDimensions()
 {
-  double aDx = real(PrimitivesPlugin_Box::DX())->value();
-  double aDy = real(PrimitivesPlugin_Box::DY())->value();
-  double aDz = real(PrimitivesPlugin_Box::DZ())->value();
+  double aDx = real(PrimitivesPlugin_Box::DX_ID())->value();
+  double aDy = real(PrimitivesPlugin_Box::DY_ID())->value();
+  double aDz = real(PrimitivesPlugin_Box::DZ_ID())->value();
 
   std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo(new GeomAlgoAPI_Box(aDx,aDy,aDz));
   
@@ -85,8 +85,8 @@ void PrimitivesPlugin_Box::createBoxByDimensions()
 //=================================================================================================
 void PrimitivesPlugin_Box::createBoxByTwoPoints() 
 {
-  AttributeSelectionPtr aRef1 = data()->selection(PrimitivesPlugin_Box::POINT_FIRST());
-  AttributeSelectionPtr aRef2 = data()->selection(PrimitivesPlugin_Box::POINT_SECOND());
+  AttributeSelectionPtr aRef1 = data()->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
+  AttributeSelectionPtr aRef2 = data()->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
   
   std::shared_ptr<GeomAlgoAPI_BoxPoints> aBoxAlgo;
   
index 7672d2fb8413fc3c9e2c0055055a419316cad58d..8db0d54174d155331bde900fd55b8bce4e1df61e 100644 (file)
@@ -33,46 +33,60 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature
     return MY_BOX_ID;
   }
 
-  /// attribute name for creation method
-  inline static const std::string& METHOD()
+  /// Attribute name for creation method
+  inline static const std::string& CREATION_METHOD()
   {
-    static const std::string METHOD_ATTR("CreationMethod");
-    return METHOD_ATTR;
+    static const std::string MY_CREATION_METHOD_ID("CreationMethod");
+    return MY_CREATION_METHOD_ID;
+  }
+  
+  /// Attribute name for creation method
+  inline static const std::string& CREATION_METHOD_BY_DIMENSIONS()
+  {
+    static const std::string MY_CREATION_METHOD_ID("BoxByDimensions");
+    return MY_CREATION_METHOD_ID;
+  }
+  
+  /// Attribute name for creation method
+  inline static const std::string& CREATION_METHOD_BY_TWO_POINTS()
+  {
+    static const std::string MY_CREATION_METHOD_ID("BoxByTwoPoints");
+    return MY_CREATION_METHOD_ID;
   }
 
-  /// attribute name of first point
-  inline static const std::string& POINT_FIRST()
+  /// Attribute name of first point
+  inline static const std::string& POINT_FIRST_ID()
   {
-    static const std::string MY_POINT_FIRST("FirstPoint");
-    return MY_POINT_FIRST;
+    static const std::string MY_POINT_FIRST_ID("FirstPoint");
+    return MY_POINT_FIRST_ID;
   }
 
-  /// attribute name of second point
-  inline static const std::string& POINT_SECOND()
+  /// Attribute name of second point
+  inline static const std::string& POINT_SECOND_ID()
   {
-    static const std::string MY_POINT_SECOND("SecondPoint");
-    return MY_POINT_SECOND;
+    static const std::string MY_POINT_SECOND_ID("SecondPoint");
+    return MY_POINT_SECOND_ID;
   }
 
-  /// attribute first coordinate
-  inline static const std::string& DX()
+  /// Attribute first coordinate
+  inline static const std::string& DX_ID()
   {
-    static const std::string MY_DX("dx");
-    return MY_DX;
+    static const std::string MY_DX_ID("dx");
+    return MY_DX_ID;
   }
 
-  /// attribute second coordinate
-  inline static const std::string& DY()
+  /// Attribute second coordinate
+  inline static const std::string& DY_ID()
   {
-    static const std::string MY_DY("dy");
-    return MY_DY;
+    static const std::string MY_DY_ID("dy");
+    return MY_DY_ID;
   }
 
-  /// attribute third coordinate
-  inline static const std::string& DZ()
+  /// Attribute third coordinate
+  inline static const std::string& DZ_ID()
   {
-    static const std::string MY_DZ("dz");
-    return MY_DZ;
+    static const std::string MY_DZ_ID("dz");
+    return MY_DZ_ID;
   }
 
   /// Returns the kind of a feature
index f3431c6220270c3a0dd61bca89b689a3fc64da62..2e53fd8fb03c11d8086fa8afba4058caa45b4aed 100644 (file)
@@ -34,6 +34,8 @@ ADD_UNIT_TESTS(
   TestFeatures.py
   TestFeaturesExtrusion.py
   TestFeaturesRevolution.py
+  
+  TestPrimitivesBox.py
 
   TestMakeBrick1.py
   TestMakeBrick2.py
index d991e3e13ec933f0e7acaa59013021182e99d56e..35ff9679ed2a1f4db704c3447597ad29e6a98182 100644 (file)
@@ -72,6 +72,9 @@ class FeaturesTestCase(FeaturesFixture):
         FeaturesAPI.FeaturesAPI_Rotation(self.part.addFeature("Rotation"))
         FeaturesAPI.FeaturesAPI_Translation(self.part.addFeature("Translation"))
         FeaturesAPI.FeaturesAPI_Group(self.part.addFeature("Group"))
+        
+        import PrimitivesAPI
+        PrimitivesAPI.PrimitivesAPI_Box(self.part.addFeature("Box"))
 
         import ParametersAPI
         ParametersAPI.ParametersAPI_Parameter(self.part.addFeature("Parameter"))
diff --git a/src/PythonAPI/Test/TestPrimitivesBox.py b/src/PythonAPI/Test/TestPrimitivesBox.py
new file mode 100644 (file)
index 0000000..e78b131
--- /dev/null
@@ -0,0 +1,43 @@
+import unittest
+
+import ModelAPI
+
+import model
+
+class PrimitivesAddBox(unittest.TestCase):
+
+    def setUp(self):
+        model.begin()
+        # Create part
+        partset = model.moduleDocument()
+        self.part = model.addPart(partset).document()
+        model.do()
+
+    def tearDown(self):
+        model.end()
+        model.reset()
+        
+#-----------------------------------------------------------------------------
+# TestCases
+
+class PrimitivesAddBoxTestCase(PrimitivesAddBox):
+
+    def test_add_box_by_dimensions(self):
+        box = model.addBox(self.part, 50, 20, 10)
+        model.do()
+        self.assertEqual(box.creationMethod().value(),"BoxByDimensions")
+        self.assertEqual(box.dx().value(),50)
+        self.assertEqual(box.dy().value(),20)
+        self.assertEqual(box.dz().value(),10)
+
+    def test_add_box_by_two_points(self):
+        point1 = model.addPoint(self.part,0,0,0).result()
+        point2 = model.addPoint(self.part,10,10,10).result()
+        box = model.addBox(self.part, point1[0], point2[0])
+        model.do()
+        self.assertEqual(box.creationMethod().value(),"BoxByTwoPoints")
+        self.assertEqual(box.firstPoint().context().shape().isVertex(),True)
+        self.assertEqual(box.secondPoint().context().shape().isVertex(),True)
+        
+if __name__ == "__main__":
+    unittest.main()
index 94fa252d20037501bc537b2cbb0f6e85423a4dea..edfc0b3e5857079d31b8066809435d0e2f1361d9 100644 (file)
@@ -19,6 +19,6 @@ mypart = model.addPart(mypartset).document()
 
 # Creating the base of the box
 
-extension.addBox( mypart, 10, 20, 30 )
+extension.addBoxScript( mypart, 10, 20, 30 )
 model.end()
 
index b57f516a153db5d92ce347bbc0406bdcadf51905..1429590dc81c24aea7ff3b1f56c31001d70c9242 100644 (file)
@@ -1,4 +1,4 @@
 """User-defined features.
 """
 
-from box import addBox
\ No newline at end of file
+from box import addBoxScript
\ No newline at end of file
index 9d4d66ce9822695874efedcfdbc0d093cf513dca..5897da2c52486ecd5cc36a11a572113de470be78 100644 (file)
@@ -7,7 +7,7 @@ from model import Interface
 from macros.box.feature import BoxFeature as MY
 
 
-def addBox(part, *args):
+def addBoxScript(part, *args):
     """Add Box feature to the part and return Box.
 
     Pass all args to Box __init__ function.
index e359630fe0edde98b3261e296a4f70c6dd6adbd6..58ddaac9994c1eec692fbba35cbcb39b525e09b8 100644 (file)
@@ -20,3 +20,4 @@ from exchange import *
 from features import *
 from parameter import *
 from partset import *
+from primitives import *
diff --git a/src/PythonAPI/model/primitives/__init__.py b/src/PythonAPI/model/primitives/__init__.py
new file mode 100644 (file)
index 0000000..aeb61cd
--- /dev/null
@@ -0,0 +1,4 @@
+"""Package for Primitives plugin for the Parametric Geometry API of the Modeler.
+"""
+
+from PrimitivesAPI import addBox