From 69c85630077c1d8aad5ede42b6d004d1a9602d5f Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 5 Apr 2016 08:44:30 +0300 Subject: [PATCH] Issue #1343 validators update --- src/FeaturesPlugin/CMakeLists.txt | 2 - .../FeaturesPlugin_CompositeSketch.cpp | 2 +- .../FeaturesPlugin_Extrusion.cpp | 25 ++- src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 11 +- .../FeaturesPlugin_Revolution.cpp | 10 +- .../FeaturesPlugin_ValidatorExtrusionBase.cpp | 31 ---- .../FeaturesPlugin_ValidatorExtrusionBase.h | 29 --- .../FeaturesPlugin_Validators.cpp | 170 ++++++++++++++++-- .../FeaturesPlugin_Validators.h | 46 ++++- src/FeaturesPlugin/extrusion_widget.xml | 3 +- src/FeaturesPlugin/extrusioncut_widget.xml | 3 +- src/FeaturesPlugin/extrusionfuse_widget.xml | 3 +- src/FeaturesPlugin/pipe_widget.xml | 2 +- src/FeaturesPlugin/revolution_widget.xml | 3 +- src/FeaturesPlugin/revolutioncut_widget.xml | 3 +- src/FeaturesPlugin/revolutionfuse_widget.xml | 3 +- src/GeomAPI/GeomAPI_Face.cpp | 28 +-- src/GeomAPI/GeomAPI_Face.h | 4 - src/GeomAPI/GeomAPI_PlanarEdges.cpp | 5 + src/GeomAPI/GeomAPI_PlanarEdges.h | 3 + src/GeomAPI/GeomAPI_Shape.cpp | 77 +++++++- src/GeomAPI/GeomAPI_Shape.h | 4 + src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp | 85 +++------ src/GeomAlgoAPI/GeomAlgoAPI_Pipe.h | 30 ++-- src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 147 +++++++++------ src/GeomAlgoAPI/GeomAlgoAPI_Prism.h | 64 +++++-- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 54 +++--- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h | 38 ++-- .../GeomValidators_ShapeType.cpp | 42 +++-- src/GeomValidators/GeomValidators_ShapeType.h | 3 +- 30 files changed, 592 insertions(+), 338 deletions(-) delete mode 100755 src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp delete mode 100755 src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 0ae589cc7..3f940c5c0 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -24,7 +24,6 @@ SET(PROJECT_HEADERS FeaturesPlugin_RevolutionBoolean.h FeaturesPlugin_RevolutionCut.h FeaturesPlugin_RevolutionFuse.h - FeaturesPlugin_ValidatorExtrusionBase.h FeaturesPlugin_ValidatorTransform.h FeaturesPlugin_Validators.h ) @@ -49,7 +48,6 @@ SET(PROJECT_SOURCES FeaturesPlugin_RevolutionBoolean.cpp FeaturesPlugin_RevolutionCut.cpp FeaturesPlugin_RevolutionFuse.cpp - FeaturesPlugin_ValidatorExtrusionBase.cpp FeaturesPlugin_ValidatorTransform.cpp FeaturesPlugin_Validators.cpp ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 0b5a103ce..8c5f797ca 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -220,7 +220,7 @@ bool FeaturesPlugin_CompositeSketch::isMakeShapeValid(const std::shared_ptrisDone()) { - setError("Error:" + getKind() + "algorithm failed."); + setError("Error: " + getKind() + " algorithm failed."); return false; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 20b7c254a..16333c306 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -14,6 +14,10 @@ #include +#include +#include +#include + //================================================================================================= FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion() { @@ -78,6 +82,23 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, // Getting base shapes. getBaseShapes(theBaseShapes); + //Getting direction. + std::shared_ptr aDir; + std::shared_ptr anEdge; + AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID()); + if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aSelection->value())); + } else if(aSelection->context().get() && + aSelection->context()->shape().get() && + aSelection->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aSelection->context()->shape())); + } + if(anEdge.get()) { + if(anEdge->isLine()) { + aDir = anEdge->line()->direction(); + } + } + // Getting sizes. double aToSize = 0.0; double aFromSize = 0.0; @@ -95,7 +116,7 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, GeomShapePtr aFromShape; if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") { - AttributeSelectionPtr aSelection = selection(TO_OBJECT_ID()); + aSelection = selection(TO_OBJECT_ID()); if(aSelection.get()) { aToShape = std::dynamic_pointer_cast(aSelection->value()); if(!aToShape.get() && aSelection->context().get()) { @@ -115,7 +136,7 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) { std::shared_ptr aBaseShape = *anIter; - std::shared_ptr aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, + std::shared_ptr aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir, aToShape, aToSize, aFromShape, aFromSize)); if(!isMakeShapeValid(aPrismAlgo)) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index baa8a1150..1de58f332 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -37,12 +36,14 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("FeaturesPlugin_ValidatorTransform", new FeaturesPlugin_ValidatorTransform); - aFactory->registerValidator("FeaturesPlugin_ValidatorExtrusionBase", - new FeaturesPlugin_ValidatorExtrusionBase); + aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncher", + new FeaturesPlugin_ValidatorCompositeLauncher); aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGeneration", new FeaturesPlugin_ValidatorBaseForGeneration); - aFactory->registerValidator("FeaturesPlugin_PipeLocationsValidator", - new FeaturesPlugin_PipeLocationsValidator); + aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations", + new FeaturesPlugin_ValidatorPipeLocations); + aFactory->registerValidator("FeaturesPlugin_ValidatorCanBeEmpty", + new FeaturesPlugin_ValidatorCanBeEmpty); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index fb3d594ad..ae67aa67a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -92,8 +92,14 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, anEdge = std::shared_ptr(new GeomAPI_Edge(aSelection->context()->shape())); } if(anEdge.get()) { - anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); + if(anEdge->isLine()) { + anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + } + } + + if(!anAxis.get()) { + return false; } // Getting angles. diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp deleted file mode 100755 index 00f2dc170..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#include "FeaturesPlugin_ValidatorExtrusionBase.h" - -#include "GeomValidators_FeatureKind.h" -#include "GeomValidators_ShapeType.h" - -#include "ModelAPI_AttributeSelectionList.h" -#include "ModelAPI_ResultPart.h" -#include "ModelAPI_ResultBody.h" -#include "ModelAPI_ResultCompSolid.h" -#include "ModelAPI_Session.h" - -bool FeaturesPlugin_ValidatorExtrusionBase::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const -{ - bool aValid = true; - - /*GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind(); - // check whether the selection is on the sketch - bool aFeatureKindValid = aValidator->isValid(theAttribute, theArguments, theError); - if (!aFeatureKindValid) { - // check if selection has Face selected - GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType(); - std::list anArguments; - anArguments.push_back("face"); - aValid = aShapeType->isValid(theAttribute, anArguments, theError); - }*/ - return aValid; -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h deleted file mode 100755 index 240718b21..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_ValidatorExtrusionBase.h -// Created: 16 Sep 2015 -// Author: Natalia ERMOLAEVA - -#ifndef FeaturesPlugin_ValidatorExtrusionBase_H -#define FeaturesPlugin_ValidatorExtrusionBase_H - -#include "ModelAPI_AttributeValidator.h" - -/** \class FeaturesPlugin_ValidatorExtrusionBase - * \ingroup Validators - * \brief A validator of selection - */ -class FeaturesPlugin_ValidatorExtrusionBase : public ModelAPI_AttributeValidator -{ - public: - /** \return true if attribute is valid - * \param theAttribute the checked attribute - * \param theArguments arguments of the attribute - * \param theError error message - */ - virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; -}; - -#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index f23ef720b..0c0e893ba 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -11,8 +11,10 @@ #include #include +#include + //================================================================================================= -bool FeaturesPlugin_PipeLocationsValidator::isValid(const std::shared_ptr& theFeature, +bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, std::string& theError) const { @@ -56,7 +58,7 @@ bool FeaturesPlugin_PipeLocationsValidator::isValid(const std::shared_ptr& theArguments, std::string& theError) const { + if(theArguments.empty()) { + theError = "Validator parameters is empty."; + return false; + } + // Checking attribute. - if(!isValidAttribute(theAttribute, theError)) { + if(!isValidAttribute(theAttribute, theArguments, theError)) { if(theError.empty()) { - theError = "Attribute contains shape with unacceptable type."; + theError = "Attribute contains unacceptable shape."; } return false; } @@ -79,6 +86,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA //================================================================================================= bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute, + const std::list& theArguments, std::string& theError) const { if(!theAttribute.get()) { @@ -91,7 +99,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast(theAttribute); for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { // If at least one attribute is invalid, the result is false. - if(!isValidAttribute(aListAttr->value(anIndex), theError)) { + if(!isValidAttribute(aListAttr->value(anIndex), theArguments, theError)) { return false; } } @@ -142,14 +150,15 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute } // Check that object is a shape with allowed type. - aShape = aContext->shape(); - GeomAPI_Shape::ShapeType aShapeType = aShape->shapeType(); - if(aShapeType != GeomAPI_Shape::VERTEX && - aShapeType != GeomAPI_Shape::EDGE && - aShapeType != GeomAPI_Shape::WIRE && - aShapeType != GeomAPI_Shape::FACE) { + GeomValidators_ShapeType aShapeTypeValidator; + if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) { theError = "Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, \ - whole sketch(if it has at least one face), and following objects: vertex, edge, wire, face."; + whole sketch(if it has at least one face), and whole objects with shape types: "; + std::list::const_iterator anIt = theArguments.cbegin(); + theError += *anIt; + for(++anIt; anIt != theArguments.cend(); ++anIt) { + theError += ", " + *anIt; + } return false; } @@ -159,4 +168,139 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute } return true; -} \ No newline at end of file +} + +//================================================================================================= +bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator; + + if(aBaseValidator.isValid(theAttribute, theArguments, theError)) { + return true; + } + + // Check that face selected. + GeomValidators_ShapeType aShapeType; + std::list anArguments; + anArguments.push_back("face"); + if(aShapeType.isValid(theAttribute, anArguments, theError)) { + return true; + } + + theError = "Selected shape is not suitable for this operation"; + + return false; +} + +//================================================================================================= +bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + std::string& theError) const +{ + if(theArguments.size() != 5 && theArguments.size() != 6) { + theError = "Validator should be used with 6 parameters for extrusion and with 5 for revolution."; + return false; + } + + std::list::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end(); + + std::string aSelectedMethod; + if(theFeature->string(*anArgsIt)) { + aSelectedMethod = theFeature->string(*anArgsIt)->value(); + } + ++anArgsIt; + std::string aCreationMethod = *anArgsIt; + ++anArgsIt; + + AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt); + ++anArgsIt; + + if(isShapesCanBeEmpty(aCheckAttribute, theError)) { + return true; + } + + if(aSelectedMethod == aCreationMethod) { + ++anArgsIt; + ++anArgsIt; + } + + for(; anArgsIt != theArguments.cend(); ++anArgsIt) { + AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt); + if(!aSelAttr.get()) { + theError = "Could not get selection attribute \"" + *anArgsIt + "\"."; + return false; + } + + GeomShapePtr aShape = aSelAttr->value(); + if(!aShape.get()) { + ResultPtr aContext = aSelAttr->context(); + if(!aContext.get()) { + theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; + return false; + } + + aShape = aContext->shape(); + } + + if(!aShape.get()) { + theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; + return false; + } + } + + return true; +} + +//================================================================================================= +bool FeaturesPlugin_ValidatorCanBeEmpty::isNotObligatory(std::string theFeature, std::string theAttribute) +{ + return false; +} + +//================================================================================================= +bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr& theAttribute, + std::string& theError) const +{ + if(!theAttribute.get()) { + return true; + } + + std::string anAttributeType = theAttribute->attributeType(); + if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast(theAttribute); + for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { + // If at least one attribute is invalid, the result is false. + if(!isShapesCanBeEmpty(aListAttr->value(anIndex), theError)) { + return false; + } + } + } else if(anAttributeType == ModelAPI_AttributeSelection::typeId()) { + // Getting context. + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); + ResultPtr aContext = anAttr->context(); + if(!aContext.get()) { + return false; + } + + GeomShapePtr aShape = anAttr->value(); + GeomShapePtr aContextShape = aContext->shape(); + if(!aShape.get()) { + aShape = aContextShape; + } + if(!aShape.get()) { + return false; + } + + if(aShape->shapeType() == GeomAPI_Shape::VERTEX || + aShape->shapeType() == GeomAPI_Shape::EDGE || + !aShape->isPlanar()) { + return false; + } + } else { + return false; + } + + return true; +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index 2e0978b91..e02b2ee63 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -10,10 +10,10 @@ #include #include -/// \class FeaturesPlugin_PipeLocationsValidator +/// \class FeaturesPlugin_ValidatorPipeLocations /// \ingroup Validators /// \brief Validator for the pipe locations. -class FeaturesPlugin_PipeLocationsValidator : public ModelAPI_FeatureValidator +class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_FeatureValidator { public: //! \return true if number of selected locations the same as number of selected bases, or empty. @@ -32,7 +32,7 @@ class FeaturesPlugin_PipeLocationsValidator : public ModelAPI_FeatureValidator /// \ingroup Validators /// \brief A validator for selection base for generation. Allows to select faces on sketch, /// whole sketch(if it has at least one face), and following objects: vertex, edge, wire, face. -class FeaturesPlugin_ValidatorBaseForGeneration : public ModelAPI_AttributeValidator +class FeaturesPlugin_ValidatorBaseForGeneration: public ModelAPI_AttributeValidator { public: //! Returns true if attribute has selection type listed in the parameter arguments. @@ -45,7 +45,47 @@ public: private: bool isValidAttribute(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +/// \class FeaturesPlugin_ValidatorCompositeLauncher +/// \ingroup Validators +/// \brief A validator for selection at composite feature start +class FeaturesPlugin_ValidatorCompositeLauncher: public ModelAPI_AttributeValidator +{ +public: + //! Returns true if attribute has selection type listed in the parameter arguments. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, std::string& theError) const; }; +/// \class FeaturesPlugin_ValidatorCanBeEmpty +/// \ingroup Validators +/// \brief A validator for extrusion direction attribute and bounding planes for extrusion and +/// revolution. Allows them to be empty if base objects are planar and do not contain +/// vertices and edges. +class FeaturesPlugin_ValidatorCanBeEmpty: public ModelAPI_FeatureValidator +{ +public: + //! Returns true if attribute listed in the parameter arguments are planar. + //! \param[in] theFeature the checked feature. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + std::string& theError) const; + + /// Returns true if the attribute in feature is not obligatory for the feature execution + virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); + +private: + bool isShapesCanBeEmpty(const AttributePtr& theAttribute, + std::string& theError) const; +}; + #endif diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 7a9043658..ccf8af3af 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -13,7 +13,7 @@ label="Base objects:" tooltip="Select a base objects" type_choice="faces objects"> - + + diff --git a/src/FeaturesPlugin/extrusioncut_widget.xml b/src/FeaturesPlugin/extrusioncut_widget.xml index fe01e3a41..1f894d223 100755 --- a/src/FeaturesPlugin/extrusioncut_widget.xml +++ b/src/FeaturesPlugin/extrusioncut_widget.xml @@ -15,7 +15,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces Objects"> - + + diff --git a/src/FeaturesPlugin/extrusionfuse_widget.xml b/src/FeaturesPlugin/extrusionfuse_widget.xml index 1d1d19fc6..eacd36c65 100644 --- a/src/FeaturesPlugin/extrusionfuse_widget.xml +++ b/src/FeaturesPlugin/extrusionfuse_widget.xml @@ -15,7 +15,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces Objects"> - + + diff --git a/src/FeaturesPlugin/pipe_widget.xml b/src/FeaturesPlugin/pipe_widget.xml index f964308cc..7535ac1b6 100644 --- a/src/FeaturesPlugin/pipe_widget.xml +++ b/src/FeaturesPlugin/pipe_widget.xml @@ -31,5 +31,5 @@ - + diff --git a/src/FeaturesPlugin/revolution_widget.xml b/src/FeaturesPlugin/revolution_widget.xml index ac18d203b..78df77f66 100644 --- a/src/FeaturesPlugin/revolution_widget.xml +++ b/src/FeaturesPlugin/revolution_widget.xml @@ -13,7 +13,7 @@ label="Base objects:" tooltip="Select a base objects" type_choice="faces objects"> - + + diff --git a/src/FeaturesPlugin/revolutioncut_widget.xml b/src/FeaturesPlugin/revolutioncut_widget.xml index a42e01027..d0ad1d37a 100644 --- a/src/FeaturesPlugin/revolutioncut_widget.xml +++ b/src/FeaturesPlugin/revolutioncut_widget.xml @@ -15,7 +15,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces Objects"> - + + diff --git a/src/FeaturesPlugin/revolutionfuse_widget.xml b/src/FeaturesPlugin/revolutionfuse_widget.xml index 03fd77ed7..56a417a9b 100644 --- a/src/FeaturesPlugin/revolutionfuse_widget.xml +++ b/src/FeaturesPlugin/revolutionfuse_widget.xml @@ -15,7 +15,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces Objects"> - + + diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index 826b8477a..e47070176 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -4,21 +4,19 @@ // Created: 2 Dec 2014 // Author: Artem ZHIDKOV -#include -#include -#include -#include +#include "GeomAPI_Face.h" + +#include "GeomAPI_Dir.h" +#include "GeomAPI_Pln.h" +#include "GeomAPI_Pnt.h" -#include -#include -#include #include #include #include -#include #include -#include #include +#include +#include GeomAPI_Face::GeomAPI_Face() : GeomAPI_Shape() @@ -63,18 +61,6 @@ bool GeomAPI_Face::isEqual(std::shared_ptr theFace) const return true; } -bool GeomAPI_Face::isPlanar() const -{ - const TopoDS_Shape& aShape = const_cast(this)->impl(); - Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape)); - Handle(Geom_RectangularTrimmedSurface) aTrimmed = - Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf); - if (!aTrimmed.IsNull()) - aSurf = aTrimmed->BasisSurface(); - GeomLib_IsPlanarSurface isPlanar(aSurf); - return isPlanar.IsPlanar() == Standard_True; -} - bool GeomAPI_Face::isCylindrical() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); diff --git a/src/GeomAPI/GeomAPI_Face.h b/src/GeomAPI/GeomAPI_Face.h index 413c03b81..c47bc036a 100644 --- a/src/GeomAPI/GeomAPI_Face.h +++ b/src/GeomAPI/GeomAPI_Face.h @@ -30,10 +30,6 @@ public: GEOMAPI_EXPORT virtual bool isEqual(const std::shared_ptr theFace) const; - /// Returns true if the face is a planar face - GEOMAPI_EXPORT - bool isPlanar() const; - /// Returns true if the face is a cylindrical face GEOMAPI_EXPORT bool isCylindrical() const; diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.cpp b/src/GeomAPI/GeomAPI_PlanarEdges.cpp index 9bb3fb994..e87ce4d89 100644 --- a/src/GeomAPI/GeomAPI_PlanarEdges.cpp +++ b/src/GeomAPI/GeomAPI_PlanarEdges.cpp @@ -91,6 +91,11 @@ std::shared_ptr GeomAPI_PlanarEdges::norm() const return std::shared_ptr(); } +bool GeomAPI_PlanarEdges::isPlanar() const +{ + return true; +} + void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, const std::shared_ptr& theNorm) diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.h b/src/GeomAPI/GeomAPI_PlanarEdges.h index 9ba13cd1a..5628f40e8 100644 --- a/src/GeomAPI/GeomAPI_PlanarEdges.h +++ b/src/GeomAPI/GeomAPI_PlanarEdges.h @@ -54,6 +54,9 @@ class GeomAPI_PlanarEdges : public GeomAPI_Shape /// Returns Z direction vector GEOMAPI_EXPORT std::shared_ptr norm() const; + /// Returns whether the shape is planar + GEOMAPI_EXPORT virtual bool isPlanar() const; + /// Set working plane /// \param theOrigin origin of the plane axis /// \param theDirX X direction of the plane axis diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index d00fe34db..3ae40cab1 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -4,13 +4,18 @@ // Created: 23 Apr 2014 // Author: Mikhail PONIKAROV -#include +#include "GeomAPI_Shape.h" -#include -#include +#include #include -#include +#include #include +#include +#include +#include +#include +#include +#include #include @@ -88,10 +93,72 @@ bool GeomAPI_Shape::isCompSolid() const return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPSOLID; } +bool GeomAPI_Shape::isPlanar() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + + if(aShape.IsNull()) { + return false; + } + + TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); + + if(aShapeType == TopAbs_VERTEX) { + return true; + } else if(aShapeType == TopAbs_EDGE || aShapeType == TopAbs_WIRE || aShapeType == TopAbs_SHELL) { + BRepBuilderAPI_FindPlane aFindPlane(aShape); + return aFindPlane.Found() == Standard_True; + } else if(aShapeType == TopAbs_FACE) { + const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(TopoDS::Face(aShape)); + Handle(Standard_Type) aType = aSurface->DynamicType(); + + if(aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { + Handle(Geom_RectangularTrimmedSurface) aTrimSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); + aType = aTrimSurface->BasisSurface()->DynamicType(); + } + return (aType == STANDARD_TYPE(Geom_Plane)); + } else { + return false; + } +} + GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const { const TopoDS_Shape& aShape = impl(); - return (ShapeType)aShape.ShapeType(); + + ShapeType aST = GeomAPI_Shape::SHAPE; + + switch(aShape.ShapeType()) { + case TopAbs_COMPOUND: + aST = GeomAPI_Shape::COMPOUND; + break; + case TopAbs_COMPSOLID: + aST = GeomAPI_Shape::COMPSOLID; + break; + case TopAbs_SOLID: + aST = GeomAPI_Shape::SOLID; + break; + case TopAbs_SHELL: + aST = GeomAPI_Shape::SHELL; + break; + case TopAbs_FACE: + aST = GeomAPI_Shape::FACE; + break; + case TopAbs_WIRE: + aST = GeomAPI_Shape::WIRE; + break; + case TopAbs_EDGE: + aST = GeomAPI_Shape::EDGE; + break; + case TopAbs_VERTEX: + aST = GeomAPI_Shape::VERTEX; + break; + case TopAbs_SHAPE: + aST = GeomAPI_Shape::SHAPE; + break; + } + + return aST; } std::string GeomAPI_Shape::shapeTypeStr() const diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 37ba2b462..7adf4da80 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -66,6 +66,10 @@ public: GEOMAPI_EXPORT virtual bool isCompSolid() const; + /// Returns whether the shape is planar + GEOMAPI_EXPORT + virtual bool isPlanar() const; + /// Returns the shape type GEOMAPI_EXPORT virtual ShapeType shapeType() const; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index 7761a5b9d..d8056eb15 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -24,14 +24,14 @@ static bool getBase(TopoDS_Shape& theBaseOut, TopAbs_ShapeEnum& theBaseTypeOut, - const std::shared_ptr theBaseShape); + const GeomShapePtr theBaseShape); static bool getPath(TopoDS_Wire& thePathOut, - const std::shared_ptr thePathShape); + const GeomShapePtr thePathShape); static bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder); //================================================================================================= -GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape) +GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape) : /*myIsPipeShellUsed(false),*/ myBaseShape(theBaseShape), myPathShape(thePathShape) @@ -40,9 +40,9 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const std::shared_ptr theBaseS } //================================================================================================= -GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape, - const std::shared_ptr theBiNormal) +GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape, + const GeomShapePtr theBiNormal) //: myIsPipeShellUsed(true) { build(theBaseShape, thePathShape, theBiNormal); @@ -51,15 +51,15 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const std::shared_ptr theBaseS //================================================================================================= GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, - const std::shared_ptr thePathShape) + const GeomShapePtr thePathShape) //: myIsPipeShellUsed(true) { build(theBaseShapes, theLocations, thePathShape); } //================================================================================================= -void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape) +void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape) { // Getting base shape. if(!theBaseShape.get()) { @@ -97,7 +97,7 @@ void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, this->initialize(aPipeBuilder); // Setting naming. - std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); + GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); this->addFromShape(aFromShape); @@ -105,16 +105,16 @@ void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, // Setting result. TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - std::shared_ptr aResultGeomShape(new GeomAPI_Shape()); + GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); this->setShape(aResultGeomShape); this->setDone(true); } //================================================================================================= -void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape, - const std::shared_ptr theBiNormal) +void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape, + const GeomShapePtr theBiNormal) { // Getting base shape. TopoDS_Shape aBaseShape; @@ -170,7 +170,7 @@ void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, } // Setting naming. - std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); + GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); this->addFromShape(aFromShape); @@ -178,7 +178,7 @@ void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, // Setting result. TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - std::shared_ptr aResultGeomShape(new GeomAPI_Shape()); + GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); this->setShape(aResultGeomShape); this->setDone(true); @@ -187,7 +187,7 @@ void GeomAlgoAPI_Pipe::build(const std::shared_ptr theBaseShape, //================================================================================================= void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, - const std::shared_ptr thePathShape) + const GeomShapePtr thePathShape) { if(theBaseShapes.empty() || (!theLocations.empty() && theLocations.size() != theBaseShapes.size())) { return; @@ -213,7 +213,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, ListOfShape::const_iterator aBaseIt = theBaseShapes.cbegin(); ListOfShape::const_iterator aLocIt = theLocations.cbegin(); while(aBaseIt != theBaseShapes.cend()) { - std::shared_ptr aBase = *aBaseIt; + GeomShapePtr aBase = *aBaseIt; TopoDS_Shape aBaseShape; TopAbs_ShapeEnum aBaseShapeType; if(!getBase(aBaseShape, aBaseShapeType, aBase)) { @@ -226,7 +226,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, } if(aHasLocations) { - std::shared_ptr aLocation = *aLocIt; + GeomShapePtr aLocation = *aLocIt; if(!aLocation.get() || aLocation->shapeType() != GeomAPI_Shape::VERTEX) { delete aPipeBuilder; return; @@ -261,7 +261,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, } // Setting naming. - std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); + GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); this->addFromShape(aFromShape); @@ -269,59 +269,24 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, // Setting result. TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - std::shared_ptr aResultGeomShape(new GeomAPI_Shape()); + GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); this->setShape(aResultGeomShape); this->setDone(true); } //================================================================================================= -void GeomAlgoAPI_Pipe::generated(const std::shared_ptr theShape, +void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, ListOfShape& theHistory) { GeomAlgoAPI_MakeShape::generated(theShape, theHistory); - - //if(myIsPipeShellUsed) { - // GeomAlgoAPI_MakeShape::generated(theShape, theHistory); - // return; - //} - - //BRepOffsetAPI_MakePipe* aMakePipe = implPtr(); - //const TopoDS_Shape& aProfile = theShape->impl(); - //const TopAbs_ShapeEnum aProfileShapeType = aProfile.ShapeType(); - //if(aProfileShapeType != TopAbs_VERTEX && aProfileShapeType != TopAbs_EDGE) { - // return; - //} - //const TopoDS_Shape& aBaseShape = myBaseShape->impl(); - //TopExp_Explorer anExp(aBaseShape, aProfileShapeType); - //Standard_Boolean ahasShape = Standard_False; - //for(; anExp.More(); anExp.Next()) { - // if(anExp.Current().IsSame(aProfile)) { - // ahasShape = Standard_True; - // break; - // } - //} - //if(!ahasShape) { - // return; - //} - //TopExp_Explorer aShapeExplorer(myPathShape->impl(), TopAbs_EDGE); - //for(; aShapeExplorer.More(); aShapeExplorer.Next ()) { - // const TopoDS_Shape& aSpine = aShapeExplorer.Current(); - // const TopoDS_Shape& aGeneratedShape = aMakePipe->Generated(aSpine, aProfile); - // if(aGeneratedShape.IsNull()) { - // continue; - // } - // std::shared_ptr aShape(new GeomAPI_Shape()); - // aShape->setImpl(new TopoDS_Shape(aGeneratedShape)); - // theHistory.push_back(aShape); - //} } // Auxilary functions: //================================================================================================= bool getBase(TopoDS_Shape& theBaseOut, TopAbs_ShapeEnum& theBaseTypeOut, - const std::shared_ptr theBaseShape) + const GeomShapePtr theBaseShape) { if(!theBaseShape.get()) { return false; @@ -350,7 +315,7 @@ bool getBase(TopoDS_Shape& theBaseOut, //================================================================================================= bool getPath(TopoDS_Wire& thePathOut, - const std::shared_ptr thePathShape) + const GeomShapePtr thePathShape) { if(!thePathShape.get()) { return false; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.h b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.h index 197e1be80..54f64c462 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.h @@ -26,17 +26,17 @@ public: /// \brief Creates extrusion for the given shape along a path. /// \param[in] theBaseShape base shape(vertex, edge, wire of face). /// \param[in] thePathShape path shape(edge or wire). - GEOMALGOAPI_EXPORT GeomAlgoAPI_Pipe(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape); /// \brief Creates extrusion for the given shape along a path. /// \param[in] theBaseShape base shape(vertex, edge, wire of face). /// \param[in] thePathShape path shape(edge or wire). /// \param[in] theBiNormal edge or wire to preserve the constant angle between the normal vector /// to the base object and the BiNormal vector. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Pipe(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape, - const std::shared_ptr theBiNormal); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape, + const GeomShapePtr theBiNormal); /// \brief Creates extrusion for the given shape along a path. /// \param[in] theBaseShapes base shape(vertex, edge, wire of face). @@ -45,30 +45,30 @@ public: /// to the base object and the BiNormal vector. GEOMALGOAPI_EXPORT GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, - const std::shared_ptr thePathShape); + const GeomShapePtr thePathShape); /// \return the list of shapes generated from theShape. /// \param[in] theShape base shape. /// \param[out] theHistory generated shapes. - GEOMALGOAPI_EXPORT void generated(const std::shared_ptr theShape, + GEOMALGOAPI_EXPORT void generated(const GeomShapePtr theShape, ListOfShape& theHistory); private: - void build(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape); + void build(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape); - void build(const std::shared_ptr theBaseShape, - const std::shared_ptr thePathShape, - const std::shared_ptr theBiNormal); + void build(const GeomShapePtr theBaseShape, + const GeomShapePtr thePathShape, + const GeomShapePtr theBiNormal); void build(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, - const std::shared_ptr thePathShape); + const GeomShapePtr thePathShape); private: //bool myIsPipeShellUsed; - std::shared_ptr myBaseShape; - std::shared_ptr myPathShape; + GeomShapePtr myBaseShape; + GeomShapePtr myPathShape; }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index f0a6690e2..9ec5b2738 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -19,8 +19,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -30,66 +32,101 @@ #include //================================================================================================= -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, - double theToSize, - double theFromSize) +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const double theToSize, + const double theFromSize) { - build(theBaseShape, std::shared_ptr(), theToSize, std::shared_ptr(), theFromSize); + build(theBaseShape, std::shared_ptr(), GeomShapePtr(), theToSize, GeomShapePtr(), theFromSize); } //================================================================================================= -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, - std::shared_ptr theToShape, - double theToSize, - std::shared_ptr theFromShape, - double theFromSize) +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const std::shared_ptr theDirection, + const double theToSize, + const double theFromSize) { - build(theBaseShape, theToShape, theToSize, theFromShape, theFromSize); + build(theBaseShape, theDirection, GeomShapePtr(), theToSize, GeomShapePtr(), theFromSize); } //================================================================================================= -void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape, - const std::shared_ptr& theToShape, - double theToSize, - const std::shared_ptr& theFromShape, - double theFromSize) +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const GeomShapePtr theToShape, + const double theToSize, + const GeomShapePtr theFromShape, + const double theFromSize) { - if(!theBaseShape || - (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape))) + build(theBaseShape, std::shared_ptr(), theToShape, theToSize, theFromShape, theFromSize); +} + +//================================================================================================= +GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const std::shared_ptr theDirection, + const GeomShapePtr theToShape, + const double theToSize, + const GeomShapePtr theFromShape, + const double theFromSize) +{ + build(theBaseShape, theDirection, theToShape, theToSize, theFromShape, theFromSize); +} + +//================================================================================================= +void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, + const std::shared_ptr theDirection, + const GeomShapePtr& theToShape, + const double theToSize, + const GeomShapePtr& theFromShape, + const double theFromSize) +{ + if(!theBaseShape.get() || + (((!theFromShape.get() && !theToShape.get()) || (theFromShape.get() && theToShape.get() && theFromShape->isEqual(theToShape))) && (theFromSize == -theToSize))) { return; } - // Getting base plane. + // Getting base shape. const TopoDS_Shape& aBaseShape = theBaseShape->impl(); - std::shared_ptr aBaseFace; - if(theBaseShape->shapeType() == GeomAPI_Shape::FACE) { - aBaseFace = std::shared_ptr(new GeomAPI_Face(theBaseShape)); - } else if(theBaseShape->shapeType() == GeomAPI_Shape::SHELL){ - GeomAPI_ShapeExplorer anExp(theBaseShape, GeomAPI_Shape::FACE); - if(anExp.more()) { - std::shared_ptr aFaceOnShell = anExp.current(); - aBaseFace = std::shared_ptr(new GeomAPI_Face(aFaceOnShell)); + + // Getting direction. + gp_Vec aDirVec; + std::shared_ptr aBaseLoc; + std::shared_ptr aBaseDir; + GeomShapePtr aBasePlane; + if(theDirection.get()) { + aDirVec = theDirection->impl(); + } else { + BRepBuilderAPI_FindPlane aFindPlane(aBaseShape); + if(aBaseShape.ShapeType() == TopAbs_VERTEX || + aBaseShape.ShapeType() == TopAbs_EDGE || + aFindPlane.Found() != Standard_True) { + return; } - } - if(!aBaseFace.get()) { - return; - } - std::shared_ptr aBasePln = aBaseFace->getPlane(); - std::shared_ptr aBaseDir = aBasePln->direction(); - std::shared_ptr aBaseLoc = aBasePln->location(); - std::shared_ptr aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir); + Handle(Geom_Plane) aPlane = aFindPlane.Plane(); + gp_Pnt aLoc = aPlane->Axis().Location(); + aDirVec = aPlane->Axis().Direction(); + + aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + aBaseDir.reset(new GeomAPI_Dir(aDirVec.X(), aDirVec.Y(), aDirVec.Z())); + aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir); + } - gp_Vec aBaseVec(aBaseDir->impl()); - const gp_Pnt& aBasePnt = aBaseLoc->impl(); + //std::shared_ptr aBaseFace; + //if(theBaseShape->shapeType() == GeomAPI_Shape::FACE) { + // aBaseFace = std::shared_ptr(new GeomAPI_Face(theBaseShape)); + //} else if(theBaseShape->shapeType() == GeomAPI_Shape::SHELL){ + // GeomAPI_ShapeExplorer anExp(theBaseShape, GeomAPI_Shape::FACE); + // if(anExp.more()) { + // GeomShapePtr aFaceOnShell = anExp.current(); + // aBaseFace = std::shared_ptr(new GeomAPI_Face(aFaceOnShell)); + // } + //} TopoDS_Shape aResult; bool isBoundingShapesSet = theFromShape || theToShape; if(!isBoundingShapesSet) { // Moving base shape. gp_Trsf aTrsf; - aTrsf.SetTranslation(aBaseVec * -theFromSize); + aTrsf.SetTranslation(aDirVec * -theFromSize); BRepBuilderAPI_Transform* aTransformBuilder = new BRepBuilderAPI_Transform(aBaseShape, aTrsf); if(!aTransformBuilder) { return; @@ -101,7 +138,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape TopoDS_Shape aMovedBase = aTransformBuilder->Shape(); // Making prism. - BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aBaseVec * (theFromSize + theToSize)); + BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aDirVec * (theFromSize + theToSize)); if(!aPrismBuilder) { return; } @@ -114,15 +151,15 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape // Setting naming. for(TopExp_Explorer anExp(aMovedBase, TopAbs_FACE); anExp.More(); anExp.Next()) { const TopoDS_Shape& aFace = anExp.Current(); - std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); + GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aPrismBuilder->FirstShape(aFace))); aToShape->setImpl(new TopoDS_Shape(aPrismBuilder->LastShape(aFace))); this->addFromShape(aFromShape); this->addToShape(aToShape); } } else { - std::shared_ptr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane; - std::shared_ptr aBoundingToShape = theToShape ? theToShape : aBasePlane; + GeomShapePtr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane; + GeomShapePtr aBoundingToShape = theToShape ? theToShape : aBasePlane; // Moving prism bounding faces according to "from" and "to" sizes. std::shared_ptr aFromFace(new GeomAPI_Face(aBoundingFromShape)); @@ -167,7 +204,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape IntAna_Quadric aBndFromQuadric(gp_Pln(aFromPnt->impl(), aFromDir->impl())); Standard_Real aMaxToDist = 0, aMaxFromDist = 0; for(int i = 0; i < 8; i++) { - gp_Lin aLine(aPoints[i], aBaseVec); + gp_Lin aLine(aPoints[i], aDirVec); IntAna_IntConicQuad aToIntAna(aLine, aBndToQuadric); IntAna_IntConicQuad aFromIntAna(aLine, aBndFromQuadric); if(aToIntAna.NbPoints() == 0 || aFromIntAna.NbPoints() == 0) { @@ -188,7 +225,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape // Moving base shape. gp_Trsf aTrsf; - aTrsf.SetTranslation(aBaseVec * -aPrismLength); + aTrsf.SetTranslation(aDirVec * -aPrismLength); BRepBuilderAPI_Transform* aTransformBuilder = new BRepBuilderAPI_Transform(aBaseShape, aTrsf); if(!aTransformBuilder) { return; @@ -200,7 +237,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape TopoDS_Shape aMovedBase = aTransformBuilder->Shape(); // Making prism. - BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aBaseVec * 2 * aPrismLength); + BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aDirVec * 2 * aPrismLength); if(!aPrismBuilder) { return; } @@ -213,30 +250,30 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape // Orienting bounding planes. std::shared_ptr aCentreOfMass = GeomAlgoAPI_ShapeTools::centreOfMass(theBaseShape); const gp_Pnt& aCentrePnt = aCentreOfMass->impl(); - gp_Lin aLine(aCentrePnt, aBaseVec); + gp_Lin aLine(aCentrePnt, aDirVec); IntAna_IntConicQuad aToIntAna(aLine, aBndToQuadric); IntAna_IntConicQuad aFromIntAna(aLine, aBndFromQuadric); Standard_Real aToParameter = aToIntAna.ParamOnConic(1); Standard_Real aFromParameter = aFromIntAna.ParamOnConic(1); if(aToParameter > aFromParameter) { gp_Vec aVec = aToDir->impl(); - if((aVec * aBaseVec) > 0) { + if((aVec * aDirVec) > 0) { aToDir->setImpl(new gp_Dir(aVec.Reversed())); aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir); } aVec = aFromDir->impl(); - if((aVec * aBaseVec) < 0) { + if((aVec * aDirVec) < 0) { aFromDir->setImpl(new gp_Dir(aVec.Reversed())); aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir); } } else { gp_Vec aVec = aToDir->impl(); - if((aVec * aBaseVec) < 0) { + if((aVec * aDirVec) < 0) { aToDir->setImpl(new gp_Dir(aVec.Reversed())); aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir); } aVec = aFromDir->impl(); - if((aVec * aBaseVec) > 0) { + if((aVec * aDirVec) > 0) { aFromDir->setImpl(new gp_Dir(aVec.Reversed())); aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir); } @@ -249,12 +286,12 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape const TopoDS_Shape& aFromShape = aBoundingFromShape->impl(); BRep_Builder aBoundingBuilder; aBoundingBuilder.MakeShell(aToShell); - aBoundingBuilder.MakeShell(aFromShell); aBoundingBuilder.Add(aToShell, aToShape); + aBoundingBuilder.MakeShell(aFromShell); aBoundingBuilder.Add(aFromShell, aFromShape); aBoundingBuilder.MakeSolid(aToSolid); - aBoundingBuilder.MakeSolid(aFromSolid); aBoundingBuilder.Add(aToSolid, aToShell); + aBoundingBuilder.MakeSolid(aFromSolid); aBoundingBuilder.Add(aFromSolid, aFromShell); // Cutting with to plane. @@ -266,7 +303,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); const TopTools_ListOfShape& aToShapes = aToCutBuilder->Modified(aToShape); for(TopTools_ListIteratorOfListOfShape anIt(aToShapes); anIt.More(); anIt.Next()) { - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); this->addToShape(aShape); } @@ -281,7 +318,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); const TopTools_ListOfShape& aFromShapes = aFromCutBuilder->Modified(aFromShape); for(TopTools_ListIteratorOfListOfShape anIt(aFromShapes); anIt.More(); anIt.Next()) { - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); this->addFromShape(aShape); } @@ -295,7 +332,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); } if(aResult.ShapeType() == TopAbs_COMPOUND) { - std::shared_ptr aCompound(new GeomAPI_Shape); + GeomShapePtr aCompound(new GeomAPI_Shape); aCompound->setImpl(new TopoDS_Shape(aResult)); ListOfShape aCompSolids, aFreeSolids; GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids); @@ -320,7 +357,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(aResult.IsNull()) { return; } - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); this->setShape(aShape); this->setDone(true); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index f286e6970..be17e8b7a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -7,9 +7,12 @@ #ifndef GeomAlgoAPI_Prism_H_ #define GeomAlgoAPI_Prism_H_ -#include +#include "GeomAlgoAPI.h" + +#include "GeomAlgoAPI_MakeSweep.h" + +#include #include -#include #include @@ -22,32 +25,57 @@ class GeomAlgoAPI_Prism : public GeomAlgoAPI_MakeSweep { public: /// \brief Creates extrusion for the given shape along the normal for this shape. - /// \param[in] theBaseShape face or wire to be extruded. + /// \param[in] theBaseShape planar face or wire to be extruded. + /// \param[in] theToSize offset for "to" plane. + /// \param[in] theFromSize offset for "from" plane. + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const double theToSize, + const double theFromSize); + + /// \brief Creates extrusion for the given shape along the normal for this shape. + /// \param[in] theBaseShape vertex, edge, wire, face or shell. + /// \param[in] theDirection direction of extrusion. Can be empty if theBaseShape is planar wire or face. /// \param[in] theToSize offset for "to" plane. /// \param[in] theFromSize offset for "from" plane. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, - double theToSize, - double theFromSize); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const std::shared_ptr theDirection, + const double theToSize, + const double theFromSize); + + /// \brief Creates extrusion for the given shape along the normal for this shape. + /// \param[in] theBaseShape planar face or wire to be extruded. + /// \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. + /// \param[in] theToSize offset for "to" plane. + /// \param[in] theFromShape bottom bounding shape. Can be empty. In this case offset will be applied to the basis. + /// \param[in] theFromSize offset for "from" plane. + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const GeomShapePtr theToShape, + const double theToSize, + const GeomShapePtr theFromShape, + const double theFromSize); /// \brief Creates extrusion for the given shape along the normal for this shape. - /// \param[in] theBaseShape face or wire to be extruded. - /// \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. + /// \param[in] theBaseShape planar face or wire to be extruded. + /// \param[in] theDirection direction of extrusion. Can be empty if theBaseShape is planar wire or face. + /// \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. /// \param[in] theToSize offset for "to" plane. /// \param[in] theFromShape bottom bounding shape. Can be empty. In this case offset will be applied to the basis. /// \param[in] theFromSize offset for "from" plane. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, - std::shared_ptr theToShape, - double theToSize, - std::shared_ptr theFromShape, - double theFromSize); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, + const std::shared_ptr theDirection, + const GeomShapePtr theToShape, + const double theToSize, + const GeomShapePtr theFromShape, + const double theFromSize); private: /// Builds resulting shape. - void build(const std::shared_ptr& theBaseShape, - const std::shared_ptr& theToShape, - double theToSize, - const std::shared_ptr& theFromShape, - double theFromSize); + void build(const GeomShapePtr& theBaseShape, + const std::shared_ptr theDirection, + const GeomShapePtr& theToShape, + const double theToSize, + const GeomShapePtr& theFromShape, + const double theFromSize); }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index cd3198a77..9e234c0ac 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -45,32 +45,32 @@ static TopoDS_Solid makeSolidFromShape(const TopoDS_Shape& theShape); static TopoDS_Shape findClosest(const TopoDS_Shape& theShape, const gp_Pnt& thePoint); //================================================================================================= -GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr theBaseShape, - std::shared_ptr theAxis, - double theToAngle, - double theFromAngle) +GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, + const std::shared_ptr theAxis, + const double theToAngle, + const double theFromAngle) { - build(theBaseShape, theAxis, std::shared_ptr(), theToAngle, std::shared_ptr(), theFromAngle); + build(theBaseShape, theAxis, GeomShapePtr(), theToAngle, GeomShapePtr(), theFromAngle); } //================================================================================================= -GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr theBaseShape, - std::shared_ptr theAxis, - std::shared_ptr theToShape, - double theToAngle, - std::shared_ptr theFromShape, - double theFromAngle) +GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, + const std::shared_ptr theAxis, + const GeomShapePtr theToShape, + const double theToAngle, + const GeomShapePtr theFromShape, + const double theFromAngle) { build(theBaseShape, theAxis, theToShape, theToAngle, theFromShape, theFromAngle); } //================================================================================================= -void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBaseShape, - const std::shared_ptr& theAxis, - const std::shared_ptr& theToShape, - double theToAngle, - const std::shared_ptr& theFromShape, - double theFromAngle) +void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseShape, + const std::shared_ptr& theAxis, + const GeomShapePtr& theToShape, + const double theToAngle, + const GeomShapePtr& theFromShape, + const double theFromAngle) { if(!theBaseShape || !theAxis || (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape))) @@ -86,7 +86,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase } else if(theBaseShape->shapeType() == GeomAPI_Shape::SHELL) { GeomAPI_ShapeExplorer anExp(theBaseShape, GeomAPI_Shape::FACE); if(anExp.more()) { - std::shared_ptr aFaceOnShell = anExp.current(); + GeomShapePtr aFaceOnShell = anExp.current(); aBaseFace = TopoDS::Face(aFaceOnShell->impl()); } } @@ -137,7 +137,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase // Setting naming. for(TopExp_Explorer anExp(aRotatedBase, TopAbs_FACE); anExp.More(); anExp.Next()) { const TopoDS_Shape& aFace = anExp.Current(); - std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); + GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aRevolBuilder->FirstShape(aFace))); aToShape->setImpl(new TopoDS_Shape(aRevolBuilder->LastShape(aFace))); this->addFromShape(aFromShape); @@ -217,7 +217,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); } if(aResult.ShapeType() == TopAbs_COMPOUND) { - std::shared_ptr aCompound(new GeomAPI_Shape); + GeomShapePtr aCompound(new GeomAPI_Shape); aCompound->setImpl(new TopoDS_Shape(aResult)); ListOfShape aCompSolids, aFreeSolids; GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids); @@ -247,12 +247,12 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace)); Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace)); if(aFaceSurface == aFromSurface) { - std::shared_ptr aFSHape(new GeomAPI_Shape); + GeomShapePtr aFSHape(new GeomAPI_Shape); aFSHape->setImpl(new TopoDS_Shape(aFaceOnResult)); this->addFromShape(aFSHape); } if(aFaceSurface == aToSurface) { - std::shared_ptr aTSHape(new GeomAPI_Shape); + GeomShapePtr aTSHape(new GeomAPI_Shape); aTSHape->setImpl(new TopoDS_Shape(aFaceOnResult)); this->addToShape(aTSHape); } @@ -322,7 +322,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase // Setting naming. const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace); for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) { - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape); } @@ -364,7 +364,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase const TopTools_ListOfShape& aBsShapes = aBaseCutBuilder->Modified(aBoundingFace); for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) { - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); isFromFaceSet ? this->addToShape(aShape) : this->addFromShape(aShape); } @@ -377,7 +377,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); } if(aResult.ShapeType() == TopAbs_COMPOUND) { - std::shared_ptr aCompound(new GeomAPI_Shape); + GeomShapePtr aCompound(new GeomAPI_Shape); aCompound->setImpl(new TopoDS_Shape(aResult)); ListOfShape aCompSolids, aFreeSolids; GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids); @@ -406,7 +406,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult)); Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace)); if(aFaceSurface == aBoundingSurface) { - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aFaceOnResult)); isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape); } @@ -417,7 +417,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBase if(aResult.IsNull()) { return; } - std::shared_ptr aShape(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); this->setShape(aShape); this->setDone(true); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h index 847435e0c..6a75f2e21 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h @@ -7,8 +7,10 @@ #ifndef GeomAlgoAPI_Revolution_H_ #define GeomAlgoAPI_Revolution_H_ -#include -#include +#include "GeomAlgoAPI.h" + +#include "GeomAlgoAPI_MakeSweep.h" + #include /// \class GeomAlgoAPI_Revolution @@ -29,10 +31,10 @@ public: /// \param[in] theAxis axis for revolution. /// \param[in] theToAngle to angle. /// \param[in] theFromAngle from angle. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(std::shared_ptr theBaseShape, - std::shared_ptr theAxis, - double theToAngle, - double theFromAngle); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, + const std::shared_ptr theAxis, + const double theToAngle, + const double theFromAngle); /// \brief Creates revolution for the given shape. /// \param[in] theBaseShape face for revolution. @@ -41,21 +43,21 @@ public: /// \param[in] theToAngle to angle. /// \param[in] theFromShape from bounding shape. Can be empty. In this case offset will be applied to the basis. /// \param[in] theFromAngle from angle. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(std::shared_ptr theBaseShape, - std::shared_ptr theAxis, - std::shared_ptr theToShape, - double theToAngle, - std::shared_ptr theFromShape, - double theFromAngle); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, + const std::shared_ptr theAxis, + const GeomShapePtr theToShape, + const double theToAngle, + const GeomShapePtr theFromShape, + const double theFromAngle); private: /// Builds resulting shape. - void build(const std::shared_ptr& theBaseShape, - const std::shared_ptr& theAxis, - const std::shared_ptr& theToShape, - double theToAngle, - const std::shared_ptr& theFromShape, - double theFromAngle); + void build(const GeomShapePtr& theBaseShape, + const std::shared_ptr& theAxis, + const GeomShapePtr& theToShape, + const double theToAngle, + const GeomShapePtr& theFromShape, + const double theFromAngle); }; #endif \ No newline at end of file diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 9b7df3693..5ad27fc38 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -30,6 +30,7 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const MyShapeTypes["edge"] = Edge; MyShapeTypes["line"] = Line; MyShapeTypes["circle"] = Circle; + MyShapeTypes["wire"] = Wire; MyShapeTypes["face"] = Face; MyShapeTypes["solid"] = Solid; MyShapeTypes["plane"] = Plane; @@ -197,31 +198,34 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, } else { switch (theShapeType) { + case Vertex: + aValid = theShape->isVertex(); + break; case Edge: aValid = theShape->isEdge(); break; - case Line: - aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle(); + case Line: + aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle(); break; - case Circle: - aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle(); + case Circle: + aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle(); break; - case Vertex: - aValid = theShape->isVertex(); + case Wire: + aValid = theShape->shapeType() == GeomAPI_Shape::WIRE; + break; + case Face: + aValid = theShape->isFace(); + break; + case Solid: + aValid = theShape->isSolid() || theShape->isCompSolid() || + theShape->isCompoundOfSolids(); + break; + case Compound: + aValid = theShape->isCompound(); + break; + default: + aValid = false; break; - case Solid: - aValid = theShape->isSolid() || theShape->isCompSolid() || - theShape->isCompoundOfSolids(); - break; - case Face: - aValid = theShape->isFace(); - break; - case Compound: - aValid = theShape->isCompound(); - break; - default: - aValid = false; - break; } } return aValid; diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index 57de14708..50be8a5ec 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -31,10 +31,11 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator Edge, Line, Circle, + Wire, Face, + Plane, Solid, Compound, - Plane, AnyShape }; -- 2.39.2