ADD_SUBDIRECTORY (src/FeaturesAPI)
ADD_SUBDIRECTORY (src/ParametersAPI)
ADD_SUBDIRECTORY (src/PartSetAPI)
+ADD_SUBDIRECTORY (src/PrimitivesAPI)
ADD_SUBDIRECTORY (src/SketchAPI)
IF(${HAVE_SALOME})
--- /dev/null
+## 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)
--- /dev/null
+// 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
--- /dev/null
+/* 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"
--- /dev/null
+// 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
--- /dev/null
+// 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
--- /dev/null
+// 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_
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
#ifndef PRIMITIVESPLUGIN_H
#define PRIMITIVESPLUGIN_H
//=================================================================================================
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));
//=================================================================================================
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;
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
TestFeatures.py
TestFeaturesExtrusion.py
TestFeaturesRevolution.py
+
+ TestPrimitivesBox.py
TestMakeBrick1.py
TestMakeBrick2.py
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"))
--- /dev/null
+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()
# Creating the base of the box
-extension.addBox( mypart, 10, 20, 30 )
+extension.addBoxScript( mypart, 10, 20, 30 )
model.end()
"""User-defined features.
"""
-from box import addBox
\ No newline at end of file
+from box import addBoxScript
\ No newline at end of file
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.
from features import *
from parameter import *
from partset import *
+from primitives import *
--- /dev/null
+"""Package for Primitives plugin for the Parametric Geometry API of the Modeler.
+"""
+
+from PrimitivesAPI import addBox