From: dbv Date: Wed, 3 Aug 2016 07:06:47 +0000 (+0300) Subject: Issue #1650: Added CPP High API for feature Axis; X-Git-Tag: V_2.5.0~145 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfc15aa51a371ab820f3c06300699e766ea7f1f5;p=modules%2Fshaper.git Issue #1650: Added CPP High API for feature Axis; Added test cases for Axis. --- diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.cpp b/src/ConstructionAPI/ConstructionAPI_Axis.cpp index 18e114af3..ab3cf13b1 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Axis.cpp @@ -4,93 +4,123 @@ // History: // 15/06/16 - Sergey POKHODENKO - Creation of the file -//-------------------------------------------------------------------------------------- #include "ConstructionAPI_Axis.h" -//-------------------------------------------------------------------------------------- + #include -//-------------------------------------------------------------------------------------- -ConstructionAPI_Axis::ConstructionAPI_Axis( - const std::shared_ptr & theFeature) + +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) { initialize(); } -ConstructionAPI_Axis::ConstructionAPI_Axis( - const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2) +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2) : ModelHighAPI_Interface(theFeature) { - if (initialize()) - setPoints(thePoint1, thePoint2); + if(initialize()) { + GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1); + GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2); + if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::VERTEX) { + setByPoints(theObject1, theObject2); + } else if (aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) { + setByPlaneAndPoint(theObject1, theObject2); + } else if (aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) { + setByTwoPlanes(theObject1, theObject2); + } + } } -ConstructionAPI_Axis::ConstructionAPI_Axis( - const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & theCylindricalFace) +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject) : ModelHighAPI_Interface(theFeature) { - if (initialize()) - setCylindricalFace(theCylindricalFace); + if(initialize()) { + GeomAPI_Shape::ShapeType aType = getShapeType(theObject); + if(aType == GeomAPI_Shape::EDGE) { + setByLine(theObject); + } else if(aType == GeomAPI_Shape::FACE) { + setByCylindricalFace(theObject); + } + } } -ConstructionAPI_Axis::ConstructionAPI_Axis( - const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ) +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePoint, + const ModelHighAPI_Double& theX, + const ModelHighAPI_Double& theY, + const ModelHighAPI_Double& theZ) : ModelHighAPI_Interface(theFeature) { - if (initialize()) - setPointAndDirection(thePoint, theX, theY, theZ); + if(initialize()) { + setByPointAndDirection(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) +//================================================================================================== +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); + if(initialize()) { + setByDimensions(theDX, theDY, theDZ); + } } -ConstructionAPI_Axis::~ConstructionAPI_Axis() +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +: ModelHighAPI_Interface(theFeature) { + if(initialize()) { + setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2, theOffset2, theReverseOffset2); + } +} +//================================================================================================== +ConstructionAPI_Axis::~ConstructionAPI_Axis() +{ } -//-------------------------------------------------------------------------------------- -void ConstructionAPI_Axis::setPoints( - const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2) +//================================================================================================== +void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1, + const ModelHighAPI_Selection& thePoint2) { - fillAttribute("AxisByPointsCase", creationMethod()); + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod()); fillAttribute(thePoint1, firstPoint()); fillAttribute(thePoint2, secondPoint()); execute(); } -void ConstructionAPI_Axis::setCylindricalFace( - const ModelHighAPI_Selection & theCylindricalFace) +//================================================================================================== +void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace) { - fillAttribute("AxisByCylindricalFaceCase", creationMethod()); + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod()); fillAttribute(theCylindricalFace, cylindricalFace()); execute(); } -void ConstructionAPI_Axis::setPointAndDirection( - const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ) +//================================================================================================== +void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint, + const ModelHighAPI_Double& theX, + const ModelHighAPI_Double& theY, + const ModelHighAPI_Double& theZ) { - fillAttribute("AxisByPointAndDirection", creationMethod()); + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(), creationMethod()); fillAttribute(thePoint, firstPoint()); fillAttribute(theX, xDirection()); fillAttribute(theY, yDirection()); @@ -99,12 +129,12 @@ void ConstructionAPI_Axis::setPointAndDirection( execute(); } -void ConstructionAPI_Axis::setDimensions( - const ModelHighAPI_Double & theDX, - const ModelHighAPI_Double & theDY, - const ModelHighAPI_Double & theDZ) +//================================================================================================== +void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX, + const ModelHighAPI_Double& theDY, + const ModelHighAPI_Double& theDZ) { - fillAttribute("AxisByDimensionsCase", creationMethod()); + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod()); fillAttribute(theDX, xDimension()); fillAttribute(theDY, yDimension()); fillAttribute(theDZ, zDimension()); @@ -112,41 +142,113 @@ void ConstructionAPI_Axis::setDimensions( execute(); } -//-------------------------------------------------------------------------------------- -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2) +//================================================================================================== +void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod()); + fillAttribute(theLine, line()); + + execute(); +} + +//================================================================================================== +void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane, + const ModelHighAPI_Selection& thePoint) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod()); + fillAttribute(thePlane, plane()); + fillAttribute(thePoint, point()); + + execute(); +} + +//================================================================================================== +void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod()); + fillAttribute(thePlane1, plane1()); + fillAttribute("", useOffset1()); + fillAttribute(thePlane2, plane2()); + fillAttribute("", useOffset2()); + + execute(); +} + +//================================================================================================== +void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod()); + fillAttribute(thePlane1, plane1()); + fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1()); + fillAttribute(theOffset1, offset1()); + fillAttribute(theReverseOffset1, reverseOffset1()); + fillAttribute(thePlane2, plane2()); + fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2()); + fillAttribute(theOffset2, offset2()); + fillAttribute(theReverseOffset2, reverseOffset2()); + + execute(); +} + +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint1, + const ModelHighAPI_Selection& thePoint2) { // TODO(spo): check that thePart is not empty std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint1, thePoint2)); } -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & theCylindricalFace) +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject) { // TODO(spo): check that thePart is not empty std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); - return AxisPtr(new ConstructionAPI_Axis(aFeature, theCylindricalFace)); + return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject)); } -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ) +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint, + const ModelHighAPI_Double& theX, + const ModelHighAPI_Double& theY, + const ModelHighAPI_Double& theZ) { // TODO(spo): check that thePart is not empty 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) +//================================================================================================== +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)); } + +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); + return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1, + thePlane2, theOffset2, theReverseOffset2)); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.h b/src/ConstructionAPI/ConstructionAPI_Axis.h index ed8f4bc62..0b62587a6 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.h +++ b/src/ConstructionAPI/ConstructionAPI_Axis.h @@ -10,126 +10,177 @@ #ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ #define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ -//-------------------------------------------------------------------------------------- #include "ConstructionAPI.h" #include #include #include -//-------------------------------------------------------------------------------------- + class ModelHighAPI_Double; class ModelHighAPI_Selection; -//-------------------------------------------------------------------------------------- -/**\class ConstructionAPI_Axis - * \ingroup CPPHighAPI - * \brief Interface for Axis feature - */ -class ConstructionAPI_Axis : public ModelHighAPI_Interface + +/// \class ConstructionAPI_Axis +/// \ingroup CPPHighAPI +/// \brief Interface for Axis feature +class ConstructionAPI_Axis: public ModelHighAPI_Interface { public: /// Constructor without values CONSTRUCTIONAPI_EXPORT - explicit ConstructionAPI_Axis(const std::shared_ptr & theFeature); + explicit ConstructionAPI_Axis(const std::shared_ptr& theFeature); + /// Constructor with values CONSTRUCTIONAPI_EXPORT - ConstructionAPI_Axis(const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2); + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2); + /// Constructor with values CONSTRUCTIONAPI_EXPORT - ConstructionAPI_Axis(const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & theCylindricalFace); + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject); + /// Constructor with values CONSTRUCTIONAPI_EXPORT - ConstructionAPI_Axis(const std::shared_ptr & theFeature, - const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ); + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePoint, + 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); + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theDX, + const ModelHighAPI_Double& theDY, + const ModelHighAPI_Double& theDZ); + + /// Constructor with values + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); + /// Destructor CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Axis(); - 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 */, - xDimension, ConstructionPlugin_Axis::DX(), ModelAPI_AttributeDouble, /** X dimension */, - yDimension, ConstructionPlugin_Axis::DY(), ModelAPI_AttributeDouble, /** Y dimension */, - zDimension, ConstructionPlugin_Axis::DZ(), ModelAPI_AttributeDouble, /** Z dimension */ - ) + INTERFACE_21(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 */, + xDimension, ConstructionPlugin_Axis::DX(), ModelAPI_AttributeDouble, /** X dimension */, + yDimension, ConstructionPlugin_Axis::DY(), ModelAPI_AttributeDouble, /** Y dimension */, + zDimension, ConstructionPlugin_Axis::DZ(), ModelAPI_AttributeDouble, /** Z dimension */, + line, ConstructionPlugin_Axis::LINE(), ModelAPI_AttributeSelection, /** Line */, + plane, ConstructionPlugin_Axis::PLANE(), ModelAPI_AttributeSelection, /** Plane */, + point, ConstructionPlugin_Axis::POINT(), ModelAPI_AttributeSelection, /** Point */, + plane1, ConstructionPlugin_Axis::PLANE1(), ModelAPI_AttributeSelection, /** Plane 1 */, + useOffset1, ConstructionPlugin_Axis::USE_OFFSET1(), ModelAPI_AttributeString, /** Use offset 1 */, + offset1, ConstructionPlugin_Axis::OFFSET1(), ModelAPI_AttributeDouble, /** Offset 1 */, + reverseOffset1, ConstructionPlugin_Axis::REVERSE_OFFSET1(), ModelAPI_AttributeBoolean, /** Reverse offset 1 */, + plane2, ConstructionPlugin_Axis::PLANE2(), ModelAPI_AttributeSelection, /** Plane 2 */, + useOffset2, ConstructionPlugin_Axis::USE_OFFSET2(), ModelAPI_AttributeString, /** Use offset 2 */, + offset2, ConstructionPlugin_Axis::OFFSET2(), ModelAPI_AttributeDouble, /** Offset 2 */, + reverseOffset2, ConstructionPlugin_Axis::REVERSE_OFFSET2(), ModelAPI_AttributeBoolean, /** Reverse offset 2 */) /// Set points CONSTRUCTIONAPI_EXPORT - void setPoints(const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2); + void setByPoints(const ModelHighAPI_Selection& thePoint1, + const ModelHighAPI_Selection& thePoint2); /// Set cylindrical face CONSTRUCTIONAPI_EXPORT - void setCylindricalFace(const ModelHighAPI_Selection & theCylindricalFace); + void setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace); /// Set direction CONSTRUCTIONAPI_EXPORT - void setPointAndDirection(const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ); - + void setByPointAndDirection(const ModelHighAPI_Selection& thePoint, + 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); + void setByDimensions(const ModelHighAPI_Double& theDX, + const ModelHighAPI_Double& theDY, + const ModelHighAPI_Double& theDZ); + + /// Set by line + CONSTRUCTIONAPI_EXPORT + void setByLine(const ModelHighAPI_Selection& theCylindricalFace); + + /// Set by plane and point + CONSTRUCTIONAPI_EXPORT + void setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane, + const ModelHighAPI_Selection& thePoint); + + /// Set by two planes + CONSTRUCTIONAPI_EXPORT + void setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2); + + /// Set by two planes + CONSTRUCTIONAPI_EXPORT + void setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); }; -//! Pointer on Axis object +/// Pointer on Axis object typedef std::shared_ptr AxisPtr; -/**\ingroup CPPHighAPI - * \brief Create Axis feature - */ +/// \ingroup CPPHighAPI +/// \brief Create Axis feature CONSTRUCTIONAPI_EXPORT -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & thePoint1, - const ModelHighAPI_Selection & thePoint2); +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2); -/**\ingroup CPPHighAPI - * \brief Create Axis feature - */ +/// \ingroup CPPHighAPI +/// \brief Create Axis feature CONSTRUCTIONAPI_EXPORT -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & theCylindricalFace); +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject); -/**\ingroup CPPHighAPI - * \brief Create Axis feature - */ +/// \ingroup CPPHighAPI +/// \brief Create Axis feature CONSTRUCTIONAPI_EXPORT -AxisPtr addAxis(const std::shared_ptr & thePart, - const ModelHighAPI_Selection & thePoint, - const ModelHighAPI_Double & theX, - const ModelHighAPI_Double & theY, - const ModelHighAPI_Double & theZ); - -/**\ingroup CPPHighAPI - * \brief Create Axis feature - */ +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint, + const ModelHighAPI_Double& theX, + 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); + +/// \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); +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ */ diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 511eb42f1..c503c16fa 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -11,11 +11,6 @@ #include #include -#include - -/*static GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr); -static GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection);*/ - //================================================================================================== ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) @@ -169,64 +164,4 @@ PointPtr addPoint(const std::shared_ptr & thePart, // TODO(spo): check that thePart is not empty std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2)); -} - -//================================================================================================== -GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr) -{ - GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; - - std::string aShapeTypeStr = theShapeTypeStr; - std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower); - - if(theShapeTypeStr == "compound") { - aShapeType = GeomAPI_Shape::COMPOUND; - } else if(theShapeTypeStr == "compsolid") { - aShapeType = GeomAPI_Shape::COMPSOLID; - } else if(theShapeTypeStr == "solid") { - aShapeType = GeomAPI_Shape::SOLID; - } else if(theShapeTypeStr == "shell") { - aShapeType = GeomAPI_Shape::SHELL; - } else if(theShapeTypeStr == "face") { - aShapeType = GeomAPI_Shape::FACE; - } else if(theShapeTypeStr == "wire") { - aShapeType = GeomAPI_Shape::WIRE; - } else if(theShapeTypeStr == "edge") { - aShapeType = GeomAPI_Shape::EDGE; - } else if(theShapeTypeStr == "vertex") { - aShapeType = GeomAPI_Shape::VERTEX; - } else if(theShapeTypeStr == "shape") { - aShapeType = GeomAPI_Shape::SHAPE; - } - - return aShapeType; -} - -//================================================================================================== -GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection) -{ - GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; - - switch(theSelection.variantType()) { - case ModelHighAPI_Selection::VT_ResultSubShapePair: { - ResultSubShapePair aPair = theSelection.resultSubShapePair(); - GeomShapePtr aShape = aPair.second; - if(!aShape.get()) { - aShape = aPair.first->shape(); - } - if(!aShape.get()) { - return aShapeType; - } - aShapeType = aShape->shapeType(); - break; - } - case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: { - TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair(); - std::string aType = aPair.first; - aShapeType = shapeTypeByStr(aType); - break; - } - } - - return aShapeType; }*/ diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index d1335f646..1317356de 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -291,13 +291,13 @@ void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); std::string aMethodType = aMethodTypeAttr->value(); - if (aMethodType == "AxisByPointsCase") { + if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) { createAxisByTwoPoints(); - } else if (aMethodType == "AxisByCylindricalFaceCase") { + } else if (aMethodType == CREATION_METHOD_BY_CYLINDRICAL_FACE()) { createAxisByCylindricalFace(); - } else if (aMethodType == "AxisByPointAndDirection") { + } else if (aMethodType == CREATION_METHOD_BY_POINT_AND_DIRECTION()) { createAxisByPointAndDirection(); - } else if (aMethodType == "AxisByDimensionsCase") { + } else if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) { createAxisByDimensions(); } else if(aMethodType == CREATION_METHOD_BY_LINE()) { createAxisByLine(); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index 438effd1f..afd1e45fc 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -42,6 +42,34 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP return METHOD_ATTR; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_TWO_POINTS() + { + static const std::string METHOD_ATTR("AxisByPointsCase"); + return METHOD_ATTR; + } + + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_CYLINDRICAL_FACE() + { + static const std::string METHOD_ATTR("AxisByCylindricalFaceCase"); + return METHOD_ATTR; + } + + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_POINT_AND_DIRECTION() + { + static const std::string METHOD_ATTR("AxisByPointAndDirection"); + return METHOD_ATTR; + } + + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_DIMENSIONS() + { + static const std::string METHOD_ATTR("AxisByDimensionsCase"); + return METHOD_ATTR; + } + /// Attribute name for creation method. inline static const std::string& CREATION_METHOD_BY_LINE() { diff --git a/src/ConstructionPlugin/Test/TestAxisCreation.py b/src/ConstructionPlugin/Test/TestAxisCreation.py index def1153d3..86ce8bc37 100644 --- a/src/ConstructionPlugin/Test/TestAxisCreation.py +++ b/src/ConstructionPlugin/Test/TestAxisCreation.py @@ -8,6 +8,8 @@ from GeomAPI import * import math from ModelAPI import * +import model + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() @@ -134,3 +136,55 @@ aSession.finishOperation() assert (len(anAxisFeature.results()) > 0) anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult()) assert (anAxisResult is not None) + +# Create a sketch with line +aSession.startOperation() +anOrigin = GeomAPI_Pnt(0, 0, 0) +aDirX = GeomAPI_Dir(1, 0, 0) +aNorm = GeomAPI_Dir(0, 0, 1) +aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) +aSketchLine = aSketch.addLine(0, 0, 100, 100) +aSession.finishOperation() + +# Test an axis by line +aSession.startOperation() +anAxis = model.addAxis(aPart, aSketchLine.result()[0]) +aSession.finishOperation() +assert (len(anAxis.result()) > 0) + +# Create plane +aSession.startOperation() +aPlane1 = model.addPlane(aPart, 1, 1, 1, 0) +aSession.finishOperation() + +# Create a sketch with point +aSession.startOperation() +anOrigin = GeomAPI_Pnt(0, 0, 0) +aDirX = GeomAPI_Dir(1, 0, 0) +aNorm = GeomAPI_Dir(0, 0, 1) +aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) +aSketchPoint = aSketch.addPoint(50, 50) +aSession.finishOperation() + +# Test an axis by plane and point +aSession.startOperation() +anAxis = model.addAxis(aPart, aPlane1.result()[0], aSketchPoint.result()[0]) +aSession.finishOperation() +assert (len(anAxis.result()) > 0) + +# Create plane +aSession.startOperation() +aPlane2 = model.addPlane(aPart, 0, 1, 1, 0) +aSession.finishOperation() + +# Test an axis by two planes +aSession.startOperation() +anAxis = model.addAxis(aPart, aPlane1.result()[0], aPlane2.result()[0]) +aSession.finishOperation() +assert (len(anAxis.result()) > 0) + +# Test an axis by two planes and offsets +aSession.startOperation() +anAxis = model.addAxis(aPart, aPlane1.result()[0], 50, False, aPlane2.result()[0], 100, True) +aSession.finishOperation() +assert (len(anAxis.result()) > 0) diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index ac192ec6e..d675d5624 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -4,6 +4,11 @@ + + + + + - - - - - - - - - - + + + + + + //-------------------------------------------------------------------------------------- void fillAttribute(const std::shared_ptr & theValue, const std::shared_ptr & theAttribute) @@ -146,4 +148,64 @@ void fillAttribute(const char * theValue, theAttribute->setValue(theValue); } +//================================================================================================== +GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr) +{ + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; + + std::string aShapeTypeStr = theShapeTypeStr; + std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower); + + if(theShapeTypeStr == "compound") { + aShapeType = GeomAPI_Shape::COMPOUND; + } else if(theShapeTypeStr == "compsolid") { + aShapeType = GeomAPI_Shape::COMPSOLID; + } else if(theShapeTypeStr == "solid") { + aShapeType = GeomAPI_Shape::SOLID; + } else if(theShapeTypeStr == "shell") { + aShapeType = GeomAPI_Shape::SHELL; + } else if(theShapeTypeStr == "face") { + aShapeType = GeomAPI_Shape::FACE; + } else if(theShapeTypeStr == "wire") { + aShapeType = GeomAPI_Shape::WIRE; + } else if(theShapeTypeStr == "edge") { + aShapeType = GeomAPI_Shape::EDGE; + } else if(theShapeTypeStr == "vertex") { + aShapeType = GeomAPI_Shape::VERTEX; + } else if(theShapeTypeStr == "shape") { + aShapeType = GeomAPI_Shape::SHAPE; + } + + return aShapeType; +} + +//================================================================================================== +GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection) +{ + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; + + switch(theSelection.variantType()) { + case ModelHighAPI_Selection::VT_ResultSubShapePair: { + ResultSubShapePair aPair = theSelection.resultSubShapePair(); + GeomShapePtr aShape = aPair.second; + if(!aShape.get()) { + aShape = aPair.first->shape(); + } + if(!aShape.get()) { + return aShapeType; + } + aShapeType = aShape->shapeType(); + break; + } + case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: { + TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair(); + std::string aType = aPair.first; + aShapeType = shapeTypeByStr(aType); + break; + } + } + + return aShapeType; +} + //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index dc3378df2..d731086b1 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -10,6 +10,8 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI.h" +#include + #include #include #include @@ -105,6 +107,12 @@ MODELHIGHAPI_EXPORT void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr); + +MODELHIGHAPI_EXPORT +GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection); + //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_TOOLS_H_ */