From db896272916fa3cc065dab5a202b3bd4854657a6 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Fri, 1 Jul 2016 12:03:27 +0200 Subject: [PATCH] Completion of the parametric API high level for the construction of an axis from dimensions. --- src/ConstructionAPI/CMakeLists.txt | 1 + src/ConstructionAPI/ConstructionAPI_Axis.cpp | 34 ++++++++++++++++++++ src/ConstructionAPI/ConstructionAPI_Axis.h | 31 ++++++++++++++++-- src/ConstructionAPI/Test/TestAxis.py | 26 +++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/ConstructionAPI/Test/TestAxis.py diff --git a/src/ConstructionAPI/CMakeLists.txt b/src/ConstructionAPI/CMakeLists.txt index 67cad0d49..edf38ae48 100644 --- a/src/ConstructionAPI/CMakeLists.txt +++ b/src/ConstructionAPI/CMakeLists.txt @@ -78,4 +78,5 @@ INCLUDE(UnitTest) ADD_UNIT_TESTS( TestPoint.py + TestAxis.py ) diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.cpp b/src/ConstructionAPI/ConstructionAPI_Axis.cpp index 352320e1d..18e114af3 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Axis.cpp @@ -47,6 +47,17 @@ ConstructionAPI_Axis::ConstructionAPI_Axis( setPointAndDirection(thePoint, theX, theY, theZ); } +ConstructionAPI_Axis::ConstructionAPI_Axis( + const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + setDimensions(theDX, theDY, theDZ); +} + ConstructionAPI_Axis::~ConstructionAPI_Axis() { @@ -88,6 +99,19 @@ void ConstructionAPI_Axis::setPointAndDirection( execute(); } +void ConstructionAPI_Axis::setDimensions( + const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ) +{ + fillAttribute("AxisByDimensionsCase", creationMethod()); + fillAttribute(theDX, xDimension()); + fillAttribute(theDY, yDimension()); + fillAttribute(theDZ, zDimension()); + + execute(); +} + //-------------------------------------------------------------------------------------- AxisPtr addAxis(const std::shared_ptr & thePart, const ModelHighAPI_Selection & thePoint1, @@ -116,3 +140,13 @@ AxisPtr addAxis(const std::shared_ptr & thePart, std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ)); } + +AxisPtr addAxis(const std::shared_ptr & thePart, + const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); + return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ)); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.h b/src/ConstructionAPI/ConstructionAPI_Axis.h index 49077c78b..ed8f4bc62 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.h +++ b/src/ConstructionAPI/ConstructionAPI_Axis.h @@ -1,8 +1,11 @@ +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D + // Name : ConstructionAPI_Axis.h // Purpose: // // History: // 15/06/16 - Sergey POKHODENKO - Creation of the file +// 24/06/16 - Clarisse GENRAULT (CEA) - Modification of the file #ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ #define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ @@ -44,18 +47,27 @@ public: const ModelHighAPI_Double & theX, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ); + /// Constructor with values + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Axis(const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ); /// Destructor CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Axis(); - INTERFACE_7(ConstructionPlugin_Axis::ID(), + INTERFACE_10(ConstructionPlugin_Axis::ID(), creationMethod, ConstructionPlugin_Axis::METHOD(), ModelAPI_AttributeString, /** Creation method */, firstPoint, ConstructionPlugin_Axis::POINT_FIRST(), ModelAPI_AttributeSelection, /** First point */, secondPoint, ConstructionPlugin_Axis::POINT_SECOND(), ModelAPI_AttributeSelection, /** Second point */, cylindricalFace, ConstructionPlugin_Axis::CYLINDRICAL_FACE(), ModelAPI_AttributeSelection, /** Cylindrical face */, xDirection, ConstructionPlugin_Axis::X_DIRECTION(), ModelAPI_AttributeDouble, /** X direction */, yDirection, ConstructionPlugin_Axis::Y_DIRECTION(), ModelAPI_AttributeDouble, /** Y direction */, - zDirection, ConstructionPlugin_Axis::Z_DIRECTION(), ModelAPI_AttributeDouble, /** Z direction */ + zDirection, ConstructionPlugin_Axis::Z_DIRECTION(), ModelAPI_AttributeDouble, /** Z direction */, + xDimension, ConstructionPlugin_Axis::DX(), ModelAPI_AttributeDouble, /** X dimension */, + yDimension, ConstructionPlugin_Axis::DY(), ModelAPI_AttributeDouble, /** Y dimension */, + zDimension, ConstructionPlugin_Axis::DZ(), ModelAPI_AttributeDouble, /** Z dimension */ ) /// Set points @@ -73,6 +85,12 @@ public: const ModelHighAPI_Double & theX, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ); + + /// Set dimensions + CONSTRUCTIONAPI_EXPORT + void setDimensions(const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ); }; //! Pointer on Axis object @@ -103,6 +121,15 @@ AxisPtr addAxis(const std::shared_ptr & thePart, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ); +/**\ingroup CPPHighAPI + * \brief Create Axis feature + */ +CONSTRUCTIONAPI_EXPORT +AxisPtr addAxis(const std::shared_ptr & thePart, + const ModelHighAPI_Double & theDX, + const ModelHighAPI_Double & theDY, + const ModelHighAPI_Double & theDZ); + //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ */ diff --git a/src/ConstructionAPI/Test/TestAxis.py b/src/ConstructionAPI/Test/TestAxis.py new file mode 100644 index 000000000..626ff62b7 --- /dev/null +++ b/src/ConstructionAPI/Test/TestAxis.py @@ -0,0 +1,26 @@ +import unittest + +import ModelAPI +import ConstructionAPI + +class AxisTestCase(unittest.TestCase): + + def setUp(self): + self.session = ModelAPI.ModelAPI_Session.get() + self.doc = self.session.moduleDocument() + self.session.startOperation() + self.feature = self.doc.addFeature("Axis") + self.feature.execute() + self.session.finishOperation() + + def tearDown(self): + self.session.closeAll() + + def test_ConstructorWithDimensions(self): + axis = ConstructionAPI.ConstructionAPI_Axis(self.feature, 10, 50, 100) + self.assertEqual(10,axis.xDimension().value()) + self.assertEqual(50,axis.yDimension().value()) + self.assertEqual(100,axis.zDimension().value()) + +if __name__ == "__main__": + unittest.main() -- 2.39.2