From: lucasjerome Date: Wed, 20 Jan 2021 11:26:04 +0000 (+0100) Subject: Refactoring code X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCEA_2020%2FLot_2_NormalToFace;p=modules%2Fshaper.git Refactoring code --- diff --git a/src/FeaturesAPI/FeaturesAPI_NormalToFace.cpp b/src/FeaturesAPI/FeaturesAPI_NormalToFace.cpp index fbc7bd650..6906d4cad 100644 --- a/src/FeaturesAPI/FeaturesAPI_NormalToFace.cpp +++ b/src/FeaturesAPI/FeaturesAPI_NormalToFace.cpp @@ -26,8 +26,8 @@ #include //================================================================================================= -FeaturesAPI_NormalToFace:: - FeaturesAPI_NormalToFace(const std::shared_ptr& theFeature) +FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace( + const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) { initialize(); @@ -37,7 +37,7 @@ FeaturesAPI_NormalToFace:: FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace( const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theBaseFace, - const ModelHighAPI_Selection& theOptionnelPoint ) + const ModelHighAPI_Selection& theOptionnelPoint) :ModelHighAPI_Interface(theFeature) { if (initialize()) { @@ -94,8 +94,7 @@ NormalPtr getNormal(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theOptionnelPoint) { - FeaturePtr aFeature = - thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID()); + FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID()); NormalPtr aNormalToface; @@ -109,8 +108,7 @@ NormalPtr getNormal(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBaseFace) { - FeaturePtr aFeature = - thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID()); + FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID()); NormalPtr aNormalToface; diff --git a/src/FeaturesAPI/FeaturesAPI_NormalToFace.h b/src/FeaturesAPI/FeaturesAPI_NormalToFace.h index f7c1facc0..3756ffdac 100644 --- a/src/FeaturesAPI/FeaturesAPI_NormalToFace.h +++ b/src/FeaturesAPI/FeaturesAPI_NormalToFace.h @@ -43,7 +43,7 @@ public: FEATURESAPI_EXPORT explicit FeaturesAPI_NormalToFace(const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theBaseFace, - const ModelHighAPI_Selection& theOptionnelPoint ); + const ModelHighAPI_Selection& theOptionnelPoint); FEATURESAPI_EXPORT explicit FeaturesAPI_NormalToFace(const std::shared_ptr& theFeature, diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 0375dd1d0..4b6004472 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -159,8 +159,8 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml - NormalToFace_widget.xml - CreateNormalToFace_widget.xml + normal_to_face_widget.xml + create_normal_to_face_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml diff --git a/src/FeaturesPlugin/CreateNormalToFace_widget.xml b/src/FeaturesPlugin/CreateNormalToFace_widget.xml deleted file mode 100644 index f7fc96d17..000000000 --- a/src/FeaturesPlugin/CreateNormalToFace_widget.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.cpp index 14c8848ca..cc245368c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.cpp @@ -63,8 +63,7 @@ void FeaturesPlugin_CreateNormalToFace::execute() GeomShapePtr aShape; GeomShapePtr aShapePoint; - if(!string(VERTEX_OPTION_ID())->value().empty()) - { + if (!string(VERTEX_OPTION_ID())->value().empty()) { if (aSelectionPoint && aSelectionPoint->isInitialized()) { aShapePoint = aSelectionPoint->value(); if (!aShapePoint && aSelectionPoint->context()) @@ -81,7 +80,7 @@ void FeaturesPlugin_CreateNormalToFace::execute() if (aShape) { std::string aError; std::shared_ptr theNormal(new GeomAPI_Edge); - if( !GeomAlgoAPI_NormalToFace::normal(aShape, + if (!GeomAlgoAPI_NormalToFace::normal(aShape, aShapePoint, theNormal, aError)) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.h b/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.h index 83210022b..f7afaa1cc 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateNormalToFace.h @@ -39,12 +39,6 @@ public: return MY_ID; } - /// \return the kind of a feature. - virtual const std::string& getKind() - { - return ID(); - } - /// Attribute name for face selected. inline static const std::string& FACE_SELECTED_ID() { @@ -66,6 +60,12 @@ public: return MY_VERTEX_OPTION_ID; } + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + /// Performs the algorithm and stores results it in the data structure. FEATURESPLUGIN_EXPORT virtual void execute(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.cpp b/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.cpp index a70e8fd79..78bed7973 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.cpp @@ -85,7 +85,7 @@ void FeaturesPlugin_NormalToFace::execute() if (aShape) { std::string aError; std::shared_ptr theNormal(new GeomAPI_Edge); - if( !GeomAlgoAPI_NormalToFace::normal(aShape, + if (!GeomAlgoAPI_NormalToFace::normal(aShape, aShapePoint, theNormal, aError)) @@ -149,16 +149,16 @@ void FeaturesPlugin_NormalToFace::createNormal() void FeaturesPlugin_NormalToFace::updateNormal() { myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::FACE_SELECTED_ID()) - ->setValue( selection(FACE_SELECTED_ID())->context() , - selection(FACE_SELECTED_ID())->value() ); + ->setValue(selection(FACE_SELECTED_ID())->context() , + selection(FACE_SELECTED_ID())->value()); myCreateFeature->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID()) - ->setValue( string(VERTEX_OPTION_ID())->value()); + ->setValue(string(VERTEX_OPTION_ID())->value()); if (!string(VERTEX_OPTION_ID())->value().empty()) { myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID()) - ->setValue( selection(VERTEX_SELECTED_ID())->context() , - selection(VERTEX_SELECTED_ID())->value() ); + ->setValue(selection(VERTEX_SELECTED_ID())->context() , + selection(VERTEX_SELECTED_ID())->value()); } myCreateFeature->execute(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.h b/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.h index 261b29770..a165e5196 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.h +++ b/src/FeaturesPlugin/FeaturesPlugin_NormalToFace.h @@ -39,12 +39,6 @@ public: return MY_ID; } - /// \return the kind of a feature. - virtual const std::string& getKind() - { - return ID(); - } - /// Attribute name for face selected. inline static const std::string& FACE_SELECTED_ID() { @@ -73,6 +67,12 @@ public: return MY_VERTEX_OPTION_ID; } + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + /// Performs the algorithm and stores results it in the data structure. FEATURESPLUGIN_EXPORT virtual void execute(); @@ -90,9 +90,11 @@ public: FeaturesPlugin_NormalToFace(); private: - + /// Create normal in feature void createNormal(); + /// Update normal in feature void updateNormal(); + /// Feature to create normal FeaturePtr myCreateFeature; }; diff --git a/src/FeaturesPlugin/NormalToFace_widget.xml b/src/FeaturesPlugin/NormalToFace_widget.xml deleted file mode 100644 index a0b818a56..000000000 --- a/src/FeaturesPlugin/NormalToFace_widget.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - diff --git a/src/FeaturesPlugin/create_normal_to_face_widget.xml b/src/FeaturesPlugin/create_normal_to_face_widget.xml new file mode 100644 index 000000000..82ee3be95 --- /dev/null +++ b/src/FeaturesPlugin/create_normal_to_face_widget.xml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/src/FeaturesPlugin/doc/TUI_NormalToFaceFeature.rst b/src/FeaturesPlugin/doc/TUI_NormalToFaceFeature.rst deleted file mode 100644 index eb8b036f8..000000000 --- a/src/FeaturesPlugin/doc/TUI_NormalToFaceFeature.rst +++ /dev/null @@ -1,22 +0,0 @@ - - .. _tui_create_Normal_To_Face: - -Create Normal to a face -======================= - -.. literalinclude:: examples/createNormalToFace.py - :linenos: - :language: python - -:download:`Download this script ` - - .. _tui_create_Normal_To_Face_At_Vertex: - -Create Normal to a face at vertex -================================= - -.. literalinclude:: examples/createNormalToFaceAtVertex.py - :linenos: - :language: python - -:download:`Download this script ` \ No newline at end of file diff --git a/src/FeaturesPlugin/doc/TUI_normalToFaceFeature.rst b/src/FeaturesPlugin/doc/TUI_normalToFaceFeature.rst new file mode 100644 index 000000000..2ae1c6dc3 --- /dev/null +++ b/src/FeaturesPlugin/doc/TUI_normalToFaceFeature.rst @@ -0,0 +1,22 @@ + + .. _tui_create_normal_to_face: + +Create normal to a face +======================= + +.. literalinclude:: examples/createNormalToFace.py + :linenos: + :language: python + +:download:`Download this script ` + + .. _tui_create_normal_to_face_at_vertex: + +Create normal to a face at vertex +================================= + +.. literalinclude:: examples/createNormalToFaceAtVertex.py + :linenos: + :language: python + +:download:`Download this script ` \ No newline at end of file diff --git a/src/FeaturesPlugin/doc/normalToFaceFeature.rst b/src/FeaturesPlugin/doc/normalToFaceFeature.rst index b4f9b16b2..cf498b72d 100644 --- a/src/FeaturesPlugin/doc/normalToFaceFeature.rst +++ b/src/FeaturesPlugin/doc/normalToFaceFeature.rst @@ -46,7 +46,7 @@ Result of **Normal to a face**. Normal to a face -**See Also** a sample TUI Script of :ref:`tui_create_Normal_To_Face` operation. +**See Also** a sample TUI Script of :ref:`tui_create_normal_to_face` operation. **TUI Command**: @@ -68,4 +68,4 @@ Result of **Normal to aface** where **Vertex** is selecteted. Normal to a face at vertex -**See Also** a sample TUI Script of :ref:`tui_create_Normal_To_Face_At_Vertex` operation. \ No newline at end of file +**See Also** a sample TUI Script of :ref:`tui_create_normal_to_face_at_vertex` operation. \ No newline at end of file diff --git a/src/FeaturesPlugin/normal_to_face_widget.xml b/src/FeaturesPlugin/normal_to_face_widget.xml new file mode 100644 index 000000000..71cde51e1 --- /dev/null +++ b/src/FeaturesPlugin/normal_to_face_widget.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 4a480d18f..9885f4df2 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -181,11 +181,11 @@ - + - + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.cpp index b39bbc8c3..a4e81513d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.cpp @@ -40,7 +40,7 @@ * \param theShape The shape to get type of. * \retval TopAbs_ShapeEnum Return type of shape for explode. */ -TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape) +TopAbs_ShapeEnum GetTypeOfSimplePart(const TopoDS_Shape& theShape) { TopAbs_ShapeEnum aType = theShape.ShapeType(); if (aType == TopAbs_VERTEX) return TopAbs_VERTEX; @@ -64,7 +64,7 @@ TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape) * Axes of the LCS are obtained from shape's location or, * if the shape is a planar face, from position of its plane. */ -gp_Ax3 GetPosition (const TopoDS_Shape& theShape) +gp_Ax3 GetPosition(const TopoDS_Shape& theShape) { gp_Ax3 aResult; @@ -81,8 +81,7 @@ gp_Ax3 GetPosition (const TopoDS_Shape& theShape) aResult = aPln.Position(); // In case of reverse orinetation of the face invert the plane normal // (the face's normal does not mathc the plane's normal in this case) - if(theShape.Orientation() == TopAbs_REVERSED) - { + if (theShape.Orientation() == TopAbs_REVERSED) { gp_Dir Vx = aResult.XDirection(); gp_Dir N = aResult.Direction().Mirrored(Vx); gp_Pnt P = aResult.Location(); @@ -98,8 +97,7 @@ gp_Ax3 GetPosition (const TopoDS_Shape& theShape) if (aShType == TopAbs_VERTEX) { aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape)); - } - else { + } else { if (aShType == TopAbs_COMPOUND) { aShType = GetTypeOfSimplePart(theShape); } @@ -138,8 +136,8 @@ static bool GeomAlgoAPI_NormalToFace::normal(GeomShapePtr theFace, TopoDS_Shape aShape = theFace->impl(); if (aShape.ShapeType() != TopAbs_FACE) { - theError = "Shape for normale calculation is not a face"; - return false; + theError = "Shape for normale calculation is not a face"; + return false; } TopoDS_Face aFace = TopoDS::Face(aShape); @@ -149,93 +147,89 @@ static bool GeomAlgoAPI_NormalToFace::normal(GeomShapePtr theFace, if (theOptionnelPoint.get()) { TopoDS_Shape anOptPnt = theOptionnelPoint->impl(); - if (anOptPnt.IsNull()){ + if (anOptPnt.IsNull()) { theError = "Invalid shape given for point argument"; return false; } p1 = BRep_Tool::Pnt(TopoDS::Vertex(anOptPnt)); - } - else - { - gp_Ax3 aPos = GetPosition(aFace); - p1 = aPos.Location(); + } else { + gp_Ax3 aPos = GetPosition(aFace); + p1 = aPos.Location(); } - // Point parameters on surface - Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); - Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf); - gp_Pnt2d pUV = aSurfAna->ValueOfUV(p1, Precision::Confusion()); - - // Normal direction - gp_Vec Vec1,Vec2; - BRepAdaptor_Surface SF (aFace); - SF.D1(pUV.X(), pUV.Y(), p1, Vec1, Vec2); - if (Vec1.Magnitude() < Precision::Confusion()) { - gp_Vec tmpV; - gp_Pnt tmpP; - SF.D1(pUV.X(), pUV.Y()-0.1, tmpP, Vec1, tmpV); - } - else if (Vec2.Magnitude() < Precision::Confusion()) { - gp_Vec tmpV; - gp_Pnt tmpP; - SF.D1(pUV.X()-0.1, pUV.Y(), tmpP, tmpV, Vec2); - } + // Point parameters on surface + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf); + gp_Pnt2d pUV = aSurfAna->ValueOfUV(p1, Precision::Confusion()); + + // Normal direction + gp_Vec Vec1,Vec2; + BRepAdaptor_Surface SF (aFace); + SF.D1(pUV.X(), pUV.Y(), p1, Vec1, Vec2); + if (Vec1.Magnitude() < Precision::Confusion()) { + gp_Vec tmpV; + gp_Pnt tmpP; + SF.D1(pUV.X(), pUV.Y()-0.1, tmpP, Vec1, tmpV); + } + else if (Vec2.Magnitude() < Precision::Confusion()) { + gp_Vec tmpV; + gp_Pnt tmpP; + SF.D1(pUV.X()-0.1, pUV.Y(), tmpP, tmpV, Vec2); + } - gp_Vec V = Vec1.Crossed(Vec2); - Standard_Real mod = V.Magnitude(); - if (mod < Precision::Confusion()) - Standard_NullObject::Raise("Normal vector of a face has null magnitude"); - - // Set length of normal vector to average radius of curvature - Standard_Real radius = 0.0; - GeomLProp_SLProps aProperties (aSurf, pUV.X(), pUV.Y(), 2, Precision::Confusion()); - if (aProperties.IsCurvatureDefined()) { - Standard_Real radius1 = Abs(aProperties.MinCurvature()); - Standard_Real radius2 = Abs(aProperties.MaxCurvature()); - if (Abs(radius1) > Precision::Confusion()) { - radius = 1.0 / radius1; - if (Abs(radius2) > Precision::Confusion()) { - radius = (radius + 1.0 / radius2) / 2.0; - } + gp_Vec V = Vec1.Crossed(Vec2); + Standard_Real mod = V.Magnitude(); + if (mod < Precision::Confusion()) + Standard_NullObject::Raise("Normal vector of a face has null magnitude"); + + // Set length of normal vector to average radius of curvature + Standard_Real radius = 0.0; + GeomLProp_SLProps aProperties (aSurf, pUV.X(), pUV.Y(), 2, Precision::Confusion()); + if (aProperties.IsCurvatureDefined()) { + Standard_Real radius1 = Abs(aProperties.MinCurvature()); + Standard_Real radius2 = Abs(aProperties.MaxCurvature()); + if (Abs(radius1) > Precision::Confusion()) { + radius = 1.0 / radius1; + if (Abs(radius2) > Precision::Confusion()) { + radius = (radius + 1.0 / radius2) / 2.0; } - else { - if (Abs(radius2) > Precision::Confusion()) { - radius = 1.0 / radius2; - } + } else { + if (Abs(radius2) > Precision::Confusion()) { + radius = 1.0 / radius2; } } + } - // Set length of normal vector to average dimension of the face - // (only if average radius of curvature is not appropriate) - if (radius < Precision::Confusion()) { - Bnd_Box B; - Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax; - BRepBndLib::Add(aFace, B); - B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); - radius = ((Xmax - Xmin) + (Ymax - Ymin) + (Zmax - Zmin)) / 3.0; - } - - if (radius < Precision::Confusion()) - radius = 1.0; + // Set length of normal vector to average dimension of the face + // (only if average radius of curvature is not appropriate) + if (radius < Precision::Confusion()) { + Bnd_Box B; + Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax; + BRepBndLib::Add(aFace, B); + B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); + radius = ((Xmax - Xmin) + (Ymax - Ymin) + (Zmax - Zmin)) / 3.0; + } - V *= radius / mod; + if (radius < Precision::Confusion()) + radius = 1.0; - // consider the face orientation - if (aFace.Orientation() == TopAbs_REVERSED || - aFace.Orientation() == TopAbs_INTERNAL) { - V = - V; - } + V *= radius / mod; - // Edge - gp_Pnt p2 = p1.Translated(V); - BRepBuilderAPI_MakeEdge aBuilder (p1, p2); - if (!aBuilder.IsDone()) - Standard_NullObject::Raise("Vector construction failed"); - aShape = aBuilder.Shape(); + // consider the face orientation + if (aFace.Orientation() == TopAbs_REVERSED || + aFace.Orientation() == TopAbs_INTERNAL) { + V = - V; + } - theNormal->setImpl(new TopoDS_Shape(aShape)); + // Edge + gp_Pnt p2 = p1.Translated(V); + BRepBuilderAPI_MakeEdge aBuilder (p1, p2); + if (!aBuilder.IsDone()) + Standard_NullObject::Raise("Vector construction failed"); + aShape = aBuilder.Shape(); - return true; + theNormal->setImpl(new TopoDS_Shape(aShape)); + return true; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.h b/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.h index 5bf44a3d1..e12b49f24 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_NormalToFace.h @@ -22,9 +22,7 @@ #include #include -#include #include -#include /**\class GeomAlgoAPI_NormalToFace * \ingroup DataAlgo @@ -34,9 +32,11 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_NormalToFace { public: - /// get the boundin box of theshape. + /// get the normal to face-shapes /// \param theface the face /// \param theOptionnelPoint the optionnel point + /// \param theNormal the normal + /// \param theError the error static bool GeomAlgoAPI_NormalToFace::normal(GeomShapePtr theFace, GeomShapePtr theOptionnelPoint, GeomEdgePtr theNormal,