From 8317cfef5ebf2ce9ae8e1c9a3a441c5d30a2850e Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 15 Jun 2016 14:35:35 +0300 Subject: [PATCH] Added CPP High API for FeaturesPlugin_Revolution --- src/FeaturesAPI/CMakeLists.txt | 2 + src/FeaturesAPI/FeaturesAPI.i | 2 + src/FeaturesAPI/FeaturesAPI_Extrusion.cpp | 6 +- src/FeaturesAPI/FeaturesAPI_Revolution.cpp | 166 ++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Revolution.h | 126 +++++++++++++ src/FeaturesAPI/FeaturesAPI_swig.h | 1 + .../FeaturesPlugin_Extrusion.cpp | 4 +- src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 14 ++ .../FeaturesPlugin_Revolution.cpp | 4 +- .../FeaturesPlugin_Revolution.h | 14 ++ src/PythonAPI/Test/TestFeaturesExtrusion.py | 68 +++---- src/PythonAPI/Test/TestFeaturesRevolution.py | 118 ++++++------- 12 files changed, 422 insertions(+), 103 deletions(-) create mode 100644 src/FeaturesAPI/FeaturesAPI_Revolution.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_Revolution.h diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index 0809f3fe6..ec14e58de 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -8,6 +8,7 @@ SET(PROJECT_HEADERS FeaturesAPI_Extrusion.h FeaturesAPI_Group.h FeaturesAPI_Placement.h + FeaturesAPI_Revolution.h FeaturesAPI_Rotation.h FeaturesAPI_Translation.h ) @@ -18,6 +19,7 @@ SET(PROJECT_SOURCES FeaturesAPI_Group.cpp FeaturesAPI_Placement.cpp FeaturesAPI_Rotation.cpp + FeaturesAPI_Revolution.cpp FeaturesAPI_Translation.cpp ) diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 7801850d1..6fc57716f 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -23,6 +23,7 @@ %shared_ptr(FeaturesAPI_Extrusion) %shared_ptr(FeaturesAPI_Group) %shared_ptr(FeaturesAPI_Placement) +%shared_ptr(FeaturesAPI_Revolution) %shared_ptr(FeaturesAPI_Rotation) %shared_ptr(FeaturesAPI_Translation) @@ -31,5 +32,6 @@ %include "FeaturesAPI_Extrusion.h" %include "FeaturesAPI_Group.h" %include "FeaturesAPI_Placement.h" +%include "FeaturesAPI_Revolution.h" %include "FeaturesAPI_Rotation.h" %include "FeaturesAPI_Translation.h" diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp index 8bb243a02..7c993db0b 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp @@ -128,7 +128,7 @@ void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirect void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize, const ModelHighAPI_Double& theFromSize) { - fillAttribute("BySizes", mycreationMethod); + fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); fillAttribute(theToSize, mytoSize); fillAttribute(theFromSize, myfromSize); @@ -138,7 +138,7 @@ void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize, //================================================================================================== void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize) { - fillAttribute("BySizes", mycreationMethod); + fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod); fillAttribute(theSize, mytoSize); fillAttribute(ModelHighAPI_Double(), myfromSize); @@ -151,7 +151,7 @@ void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& th const ModelHighAPI_Selection& theFromObject, const ModelHighAPI_Double& theFromOffset) { - fillAttribute("ByPlanesAndOffsets", mycreationMethod); + fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod); fillAttribute(theToObject, mytoObject); fillAttribute(theToOffset, mytoOffset); fillAttribute(theFromObject, myfromObject); diff --git a/src/FeaturesAPI/FeaturesAPI_Revolution.cpp b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp new file mode 100644 index 000000000..bae189abf --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp @@ -0,0 +1,166 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Revolution.cpp +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#include "FeaturesAPI_Revolution.h" + +#include +#include + +//================================================================================================== +FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theAngle) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theBaseObjects, mybaseObjects); + fillAttribute(theAxis, myaxis); + setAngles(theAngle, ModelHighAPI_Double()); + } +} + +//================================================================================================== +FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theToAngle, + const ModelHighAPI_Double& theFromAngle) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theBaseObjects, mybaseObjects); + fillAttribute(theAxis, myaxis); + setAngles(theToAngle, theFromAngle); + } +} + +//================================================================================================== +FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theBaseObjects, mybaseObjects); + fillAttribute(theAxis, myaxis); + setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset); + } +} + +//================================================================================================== +FeaturesAPI_Revolution::~FeaturesAPI_Revolution() +{ + +} + +//================================================================================================== +void FeaturesAPI_Revolution::setBase(const std::list& theBaseObjects) +{ + fillAttribute(theBaseObjects, mybaseObjects); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis) +{ + fillAttribute(theAxis, myaxis); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle, + const ModelHighAPI_Double& theFromAngle) +{ + fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod); + fillAttribute(theToAngle, mytoAngle); + fillAttribute(theFromAngle, myfromAngle); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle) +{ + fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod); + fillAttribute(theAngle, mytoAngle); + fillAttribute(ModelHighAPI_Double(), myfromAngle); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset) +{ + fillAttribute("ByPlanesAndOffsets", mycreationMethod); + fillAttribute(theToObject, mytoObject); + fillAttribute(theToOffset, mytoOffset); + fillAttribute(theFromObject, myfromObject); + fillAttribute(theFromOffset, myfromOffset); + + execute(); +} + +// TODO(spo): make add* as static functions of the class +//================================================================================================== +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theAngle) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID()); + return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle)); +} + +//================================================================================================== +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theToAngle, + const ModelHighAPI_Double& theFromAngle) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID()); + return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, + theBaseObjects, + theAxis, + theToAngle, + theFromAngle)); +} + +//================================================================================================== +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID()); + return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, + theBaseObjects, + theAxis, + theToObject, + theToOffset, + theFromObject, + theFromOffset)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Revolution.h b/src/FeaturesAPI/FeaturesAPI_Revolution.h new file mode 100644 index 000000000..a7c0a096c --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Revolution.h @@ -0,0 +1,126 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Revolution.h +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_Revolution_H_ +#define FeaturesAPI_Revolution_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Revolution +/// \ingroup CPPHighAPI +/// \brief Interface for Revolution feature. +class FeaturesAPI_Revolution: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Revolution(const std::shared_ptr& theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theAngle); + + /// Constructor with values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theToAngle, + const ModelHighAPI_Double& theFromAngle); + + /// Constructor with values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Revolution(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_Revolution(); + + INTERFACE_10(FeaturesPlugin_Revolution::ID(), + baseObjects, FeaturesPlugin_CompositeSketch::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */, + axis, FeaturesPlugin_Revolution::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis */, + creationMethod, FeaturesPlugin_Revolution::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, + toAngle, FeaturesPlugin_Revolution::TO_ANGLE_ID(), ModelAPI_AttributeDouble, /** To angle */, + fromAngle, FeaturesPlugin_Revolution::FROM_ANGLE_ID(), ModelAPI_AttributeDouble, /** From angle */, + toObject, FeaturesPlugin_Revolution::TO_OBJECT_ID(), ModelAPI_AttributeSelection, /** To object */, + toOffset, FeaturesPlugin_Revolution::TO_OFFSET_ID(), ModelAPI_AttributeDouble, /** To offset */, + fromObject, FeaturesPlugin_Revolution::FROM_OBJECT_ID(), ModelAPI_AttributeSelection, /** From object */, + fromOffset, FeaturesPlugin_Revolution::FROM_OFFSET_ID(), ModelAPI_AttributeDouble, /** From offset */, + sketchLauncher, FeaturesPlugin_CompositeSketch::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */) + + /// Modify base attribute of the feature. + FEATURESAPI_EXPORT + void setBase(const std::list& theBaseObjects); + + /// Modify axis_object attribute of the feature. + FEATURESAPI_EXPORT + void setAxis(const ModelHighAPI_Selection& theAxis); + + /// Modify CreationMethod, to_angle, from_angle attributes of the feature. + FEATURESAPI_EXPORT + void setAngles(const ModelHighAPI_Double& theToAngle, const ModelHighAPI_Double& theFromAngle); + + /// Modify CreationMethod, to_angle, from_angle attributes of the feature. + FEATURESAPI_EXPORT + void setAngle(const ModelHighAPI_Double& theAngle); + + /// Modify CreationMethod, to_object, to_offset, from_object, from_offset attributes of the feature. + FEATURESAPI_EXPORT + void setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset); +}; + +/// Pointer on Revolution object. +typedef std::shared_ptr RevolutionPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Revolution feature. +FEATURESAPI_EXPORT +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theAngle); + +/// \ingroup CPPHighAPI +/// \brief Create Revolution feature. +FEATURESAPI_EXPORT +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theToAngle, + const ModelHighAPI_Double& theFromAngle); + +/// \ingroup CPPHighAPI +/// \brief Create Revolution feature. +FEATURESAPI_EXPORT +RevolutionPtr addRevolution(const std::shared_ptr& thePart, + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Selection& theToObject, + const ModelHighAPI_Double& theToOffset, + const ModelHighAPI_Selection& theFromObject, + const ModelHighAPI_Double& theFromOffset); + +#endif // FeaturesAPI_Revolution_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index bc9c57a24..8caf40e97 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -14,6 +14,7 @@ #include "FeaturesAPI_Extrusion.h" #include "FeaturesAPI_Group.h" #include "FeaturesAPI_Placement.h" + #include "FeaturesAPI_Revolution.h" #include "FeaturesAPI_Rotation.h" #include "FeaturesAPI_Translation.h" diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 225e3cf48..8238b1743 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -100,7 +100,7 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, double aToSize = 0.0; double aFromSize = 0.0; - if(string(CREATION_METHOD())->value() == "BySizes") { + if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_SIZES()) { aToSize = real(TO_SIZE_ID())->value(); aFromSize = real(FROM_SIZE_ID())->value(); } else { @@ -112,7 +112,7 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, GeomShapePtr aToShape; GeomShapePtr aFromShape; - if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") { + if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) { aSelection = selection(TO_OBJECT_ID()); if(aSelection.get()) { aToShape = std::dynamic_pointer_cast(aSelection->value()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index f2a8fc177..aa2b48361 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -40,6 +40,20 @@ public: return MY_CREATION_METHOD_ID; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_SIZES() + { + static const std::string MY_CREATION_METHOD_ID("BySizes"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_PLANES() + { + static const std::string MY_CREATION_METHOD_ID("ByPlanesAndOffsets"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name of an object to which the extrusion grows. inline static const std::string& DIRECTION_OBJECT_ID() { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index 12e053e32..53e4e5328 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -103,7 +103,7 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, double aToAngle = 0.0; double aFromAngle = 0.0; - if(string(CREATION_METHOD())->value() == "ByAngles") { + if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_ANGLES()) { aToAngle = real(TO_ANGLE_ID())->value(); aFromAngle = real(FROM_ANGLE_ID())->value(); } else { @@ -115,7 +115,7 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, GeomShapePtr aToShape; GeomShapePtr aFromShape; - if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") { + if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) { aSelection = selection(TO_OBJECT_ID()); if(aSelection.get()) { aToShape = std::dynamic_pointer_cast(aSelection->value()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.h b/src/FeaturesPlugin/FeaturesPlugin_Revolution.h index f31e4c917..2ebbf84a3 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.h @@ -35,6 +35,20 @@ public: return MY_CREATION_METHOD_ID; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_ANGLES() + { + static const std::string MY_CREATION_METHOD_ID("ByAngles"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_PLANES() + { + static const std::string MY_CREATION_METHOD_ID("ByPlanesAndOffsets"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name of an revolution axis. inline static const std::string& AXIS_OBJECT_ID() { diff --git a/src/PythonAPI/Test/TestFeaturesExtrusion.py b/src/PythonAPI/Test/TestFeaturesExtrusion.py index 0405e58d8..ce3935cd9 100644 --- a/src/PythonAPI/Test/TestFeaturesExtrusion.py +++ b/src/PythonAPI/Test/TestFeaturesExtrusion.py @@ -30,7 +30,7 @@ class FeaturesExtrusionFixture(FeaturesAddExtrusionFixture): circle = sketch.addCircle(0, 0, 10) model.do() - base = sketch.selectFace(circle.result()) + base = sketch.selectFace() self.extrusion = model.addExtrusion(self.part, base, 10, 0) model.do() @@ -47,17 +47,17 @@ class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture): circle = sketch.addCircle(0, 0, 10) model.do() - base = sketch.selectFace(circle.result()) + base = sketch.selectFace() extrusion = model.addExtrusion(self.part, base, 10, 0) model.do() - self.assertEqual(extrusion.getCreationMethod().value(), "BySizes") - self.assertEqual(extrusion.getToSize().value(), 10) - self.assertEqual(extrusion.getFromSize().value(), 0) - self.assertEqual(extrusion.getToObject().context(), None) - self.assertEqual(extrusion.getToOffset().value(), 0) - self.assertEqual(extrusion.getFromObject().context(), None) - self.assertEqual(extrusion.getFromOffset().value(), 0) + self.assertEqual(extrusion.creationMethod().value(), "BySizes") + self.assertEqual(extrusion.toSize().value(), 10) + self.assertEqual(extrusion.fromSize().value(), 0) + self.assertEqual(extrusion.toObject().context(), None) + self.assertEqual(extrusion.toOffset().value(), 0) + self.assertEqual(extrusion.fromObject().context(), None) + self.assertEqual(extrusion.fromOffset().value(), 0) def test_add_extrusion_by_face_and_planes(self): # base @@ -76,22 +76,22 @@ class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture): model.do() - base = base_sketch.selectFace(base_circle.result()) - to_object = to_sketch.selectFace(to_circle.result())[0] - from_object = from_sketch.selectFace(from_circle.result())[0] + base = base_sketch.selectFace() + to_object = to_sketch.selectFace()[0] + from_object = from_sketch.selectFace()[0] extrusion = model.addExtrusion(self.part, base, to_object, 15, from_object, 20) - self.assertEqual(extrusion.getCreationMethod().value(), "ByPlanesAndOffsets") - self.assertEqual(extrusion.getToSize().value(), 0) - self.assertEqual(extrusion.getFromSize().value(), 0) + self.assertEqual(extrusion.creationMethod().value(), "ByPlanesAndOffsets") + self.assertEqual(extrusion.toSize().value(), 0) + self.assertEqual(extrusion.fromSize().value(), 0) # self.assertEqual(extrusion.getToObject().context(), # to_sketch.result()) - self.assertEqual(extrusion.getToOffset().value(), 15) + self.assertEqual(extrusion.toOffset().value(), 15) # self.assertEqual(extrusion.getFromObject().context(), # from_sketch.result()) - self.assertEqual(extrusion.getFromOffset().value(), 20) + self.assertEqual(extrusion.fromOffset().value(), 20) class FeaturesExtrusionTestCase(FeaturesExtrusionFixture): @@ -102,32 +102,32 @@ class FeaturesExtrusionTestCase(FeaturesExtrusionFixture): def test_extrusion_get_attribute(self): # call method of the feature - self.assertTrue(isinstance(self.extrusion.getBase(), + self.assertTrue(isinstance(self.extrusion.baseObjects(), ModelAPI.ModelAPI_AttributeSelectionList)) - self.assertTrue(isinstance(self.extrusion.getCreationMethod(), + self.assertTrue(isinstance(self.extrusion.creationMethod(), ModelAPI.ModelAPI_AttributeString)) - self.assertTrue(isinstance(self.extrusion.getToSize(), + self.assertTrue(isinstance(self.extrusion.toSize(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.extrusion.getFromSize(), + self.assertTrue(isinstance(self.extrusion.fromSize(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.extrusion.getToObject(), + self.assertTrue(isinstance(self.extrusion.toObject(), ModelAPI.ModelAPI_AttributeSelection)) - self.assertTrue(isinstance(self.extrusion.getToOffset(), + self.assertTrue(isinstance(self.extrusion.toOffset(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.extrusion.getFromObject(), + self.assertTrue(isinstance(self.extrusion.fromObject(), ModelAPI.ModelAPI_AttributeSelection)) - self.assertTrue(isinstance(self.extrusion.getFromOffset(), + self.assertTrue(isinstance(self.extrusion.fromOffset(), ModelAPI.ModelAPI_AttributeDouble)) def test_extrusion_set_sizes(self): self.extrusion.setSizes(15, 20) - self.assertEqual(self.extrusion.getCreationMethod().value(), "BySizes") - self.assertEqual(self.extrusion.getToSize().value(), 15) - self.assertEqual(self.extrusion.getFromSize().value(), 20) - self.assertEqual(self.extrusion.getToObject().context(), None) - self.assertEqual(self.extrusion.getToOffset().value(), 0) - self.assertEqual(self.extrusion.getFromObject().context(), None) - self.assertEqual(self.extrusion.getFromOffset().value(), 0) + self.assertEqual(self.extrusion.creationMethod().value(), "BySizes") + self.assertEqual(self.extrusion.toSize().value(), 15) + self.assertEqual(self.extrusion.fromSize().value(), 20) + self.assertEqual(self.extrusion.toObject().context(), None) + self.assertEqual(self.extrusion.toOffset().value(), 0) + self.assertEqual(self.extrusion.fromObject().context(), None) + self.assertEqual(self.extrusion.fromOffset().value(), 0) def test_extrusion_set_planes_and_offsets(self): # to @@ -143,8 +143,8 @@ class FeaturesExtrusionTestCase(FeaturesExtrusionFixture): model.do() - to_object = to_sketch.selectFace(to_circle.result())[0] - from_object = from_sketch.selectFace(from_circle.result())[0] + to_object = to_sketch.selectFace()[0] + from_object = from_sketch.selectFace()[0] self.extrusion.setPlanesAndOffsets(to_object, 15, from_object, 20) diff --git a/src/PythonAPI/Test/TestFeaturesRevolution.py b/src/PythonAPI/Test/TestFeaturesRevolution.py index a7fbfde5a..1c2084183 100644 --- a/src/PythonAPI/Test/TestFeaturesRevolution.py +++ b/src/PythonAPI/Test/TestFeaturesRevolution.py @@ -36,9 +36,9 @@ class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture): model.do() - base = base_sketch.selectFace(circle.lastResult()) - axis_object = Selection(axis_sketch.firstResult(), - line.firstResult().shape()) + base = base_sketch.selectFace() + axis_object = Selection(axis_sketch.result()[0], + line.result()[0]) self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180) @@ -64,66 +64,62 @@ class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture): # base base_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) circle = base_sketch.addCircle(0, 0, 10) - # axis - axis_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) - line = axis_sketch.addLine(20, -10, 20, 10) model.do() - base = base_sketch.selectFace(circle.lastResult()) - axis_object = Selection(axis_sketch.firstResult(), - line.firstResult().shape()) + base = base_sketch.selectFace() + axis_point1 = model.addPoint(self.part, 20, -10, 0) + axis_point2 = model.addPoint(self.part, 20, 10, 0) + axis_object = model.addAxis(self.part, axis_point1.result()[0], axis_point2.result()[0]).result()[0] revolution = model.addRevolution(self.part, base, axis_object, 0, 180) - self.assertEqual(revolution.getCreationMethod().value(), "ByAngles") - self.assertEqual(revolution.getToAngle().value(), 0) - self.assertEqual(revolution.getFromAngle().value(), 180) - self.assertEqual(revolution.getToObject().context(), None) - self.assertEqual(revolution.getToOffset().value(), 0) - self.assertEqual(revolution.getFromObject().context(), None) - self.assertEqual(revolution.getFromOffset().value(), 0) + self.assertEqual(revolution.creationMethod().value(), "ByAngles") + self.assertEqual(revolution.toAngle().value(), 0) + self.assertEqual(revolution.fromAngle().value(), 180) + self.assertEqual(revolution.toObject().context(), None) + self.assertEqual(revolution.toOffset().value(), 0) + self.assertEqual(revolution.fromObject().context(), None) + self.assertEqual(revolution.fromOffset().value(), 0) def test_add_revolution_by_face_and_planes(self): # base base_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) base_circle = base_sketch.addCircle(0, 0, 10) - # axis - axis_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) - line = axis_sketch.addLine(20, -10, 20, 10) # to to_plane = model.defaultPlane("XOY") - to_plane.location().setZ(10) + to_plane.origin().setZ(10) to_sketch = model.addSketch(self.part, to_plane) to_circle = to_sketch.addCircle(0, 0, 10) # from from_plane = model.defaultPlane("XOY") - from_plane.location().setZ(-10) + from_plane.origin().setZ(-10) from_sketch = model.addSketch(self.part, from_plane) from_circle = from_sketch.addCircle(0, 0, 10) model.do() - base = base_sketch.selectFace(base_circle.result()) - axis_object = Selection(axis_sketch.firstResult(), - line.firstResult().shape()) - to_obejct = to_sketch.selectFace(to_circle.result())[0] - from_object = from_sketch.selectFace(from_circle.result())[0] + base = base_sketch.selectFace() + axis_point1 = model.addPoint(self.part, 20, -10, 0) + axis_point2 = model.addPoint(self.part, 20, 10, 0) + axis_object = model.addAxis(self.part, axis_point1.result()[0], axis_point2.result()[0]).result()[0] + to_obejct = to_sketch.selectFace()[0] + from_object = from_sketch.selectFace()[0] revolution = model.addRevolution(self.part, base, axis_object, to_obejct, 15, from_object, 20) - self.assertEqual(revolution.getCreationMethod().value(), "ByPlanesAndOffsets") - self.assertEqual(revolution.getToAngle().value(), 0) - self.assertEqual(revolution.getFromAngle().value(), 0) + self.assertEqual(revolution.creationMethod().value(), "ByPlanesAndOffsets") + self.assertEqual(revolution.toAngle().value(), 0) + self.assertEqual(revolution.fromAngle().value(), 0) # self.assertEqual(revolution.getToObject().context(), # to_sketch.result()) - self.assertEqual(revolution.getToOffset().value(), 15) + self.assertEqual(revolution.toOffset().value(), 15) # self.assertEqual(revolution.getFromObject().context(), # from_sketch.result()) - self.assertEqual(revolution.getFromOffset().value(), 20) + self.assertEqual(revolution.fromOffset().value(), 20) class FeaturesRevolutionTestCase(FeaturesRevolutionFixture): @@ -134,70 +130,68 @@ class FeaturesRevolutionTestCase(FeaturesRevolutionFixture): def test_revolution_get_attribute(self): # call method of the feature - self.assertTrue(isinstance(self.revolution.getBase(), + self.assertTrue(isinstance(self.revolution.base(), ModelAPI.ModelAPI_AttributeSelectionList)) - self.assertTrue(isinstance(self.revolution.getAxisObject(), + self.assertTrue(isinstance(self.revolution.axisObject(), ModelAPI.ModelAPI_AttributeSelection)) - self.assertTrue(isinstance(self.revolution.getCreationMethod(), + self.assertTrue(isinstance(self.revolution.creationMethod(), ModelAPI.ModelAPI_AttributeString)) - self.assertTrue(isinstance(self.revolution.getToAngle(), + self.assertTrue(isinstance(self.revolution.toAngle(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.revolution.getFromAngle(), + self.assertTrue(isinstance(self.revolution.fromAngle(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.revolution.getToObject(), + self.assertTrue(isinstance(self.revolution.toObject(), ModelAPI.ModelAPI_AttributeSelection)) - self.assertTrue(isinstance(self.revolution.getToOffset(), + self.assertTrue(isinstance(self.revolution.toOffset(), ModelAPI.ModelAPI_AttributeDouble)) - self.assertTrue(isinstance(self.revolution.getFromObject(), + self.assertTrue(isinstance(self.revolution.fromObject(), ModelAPI.ModelAPI_AttributeSelection)) - self.assertTrue(isinstance(self.revolution.getFromOffset(), + self.assertTrue(isinstance(self.revolution.fromOffset(), ModelAPI.ModelAPI_AttributeDouble)) def test_revolution_set_angles(self): self.revolution.setAngles(90, 270) - self.assertEqual(self.revolution.getCreationMethod().value(), "ByAngles") - self.assertEqual(self.revolution.getToAngle().value(), 90) - self.assertEqual(self.revolution.getFromAngle().value(), 270) - self.assertEqual(self.revolution.getToObject().context(), None) - self.assertEqual(self.revolution.getToOffset().value(), 0) - self.assertEqual(self.revolution.getFromObject().context(), None) - self.assertEqual(self.revolution.getFromOffset().value(), 0) + self.assertEqual(self.revolution.creationMethod().value(), "ByAngles") + self.assertEqual(self.revolution.toAngle().value(), 90) + self.assertEqual(self.revolution.fromAngle().value(), 270) + self.assertEqual(self.revolution.toObject().context(), None) + self.assertEqual(self.revolution.toOffset().value(), 0) + self.assertEqual(self.revolution.fromObject().context(), None) + self.assertEqual(self.revolution.fromOffset().value(), 0) def test_revolution_set_planes_and_offsets(self): # base base_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) base_circle = base_sketch.addCircle(0, 0, 10) - # axis - axis_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) - line = axis_sketch.addLine(20, -10, 20, 10) # to to_plane = model.defaultPlane("XOY") - to_plane.location().setZ(10) + to_plane.origin().setZ(10) to_sketch = model.addSketch(self.part, to_plane) to_circle = to_sketch.addCircle(0, 0, 10) # from from_plane = model.defaultPlane("XOY") - from_plane.location().setZ(-10) + from_plane.origin().setZ(-10) from_sketch = model.addSketch(self.part, from_plane) from_circle = from_sketch.addCircle(0, 0, 10) model.do() - base = base_sketch.selectFace(base_circle.result()) - axis_object = Selection(axis_sketch.firstResult(), - line.firstResult().shape()) - to_obejct = to_sketch.selectFace(to_circle.result())[0] - from_object = from_sketch.selectFace(from_circle.result())[0] + base = base_sketch.selectFace() + axis_point1 = model.addPoint(self.part, 20, -10, 0) + axis_point2 = model.addPoint(self.part, 20, 10, 0) + axis_object = model.addAxis(self.part, axis_point1.result()[0], axis_point2.result()[0]).result()[0] + to_obejct = to_sketch.selectFace()[0] + from_object = from_sketch.selectFace()[0] self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20) - self.assertEqual(self.revolution.getCreationMethod().value(), "ByPlanesAndOffsets") - self.assertEqual(self.revolution.getToAngle().value(), 0) - self.assertEqual(self.revolution.getFromAngle().value(), 0) + self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets") + self.assertEqual(self.revolution.toAngle().value(), 0) + self.assertEqual(self.revolution.fromAngle().value(), 0) # self.assertEqual(self.revolution.getToObject().context(), None) - self.assertEqual(self.revolution.getToOffset().value(), 15) + self.assertEqual(self.revolution.toOffset().value(), 15) # self.assertEqual(self.revolution.getFromObject().context(), None) - self.assertEqual(self.revolution.getFromOffset().value(), 20) + self.assertEqual(self.revolution.fromOffset().value(), 20) if __name__ == "__main__": -- 2.39.2