From 6e1c46973b9a36b063e4deff0201ff828af4fb8e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Thu, 3 Dec 2020 14:24:42 +0100 Subject: [PATCH] #20429 Fix issues --- .../FeaturesAPI_GeometryCalculation.cpp | 7 ++++--- .../FeaturesAPI_GeometryCalculation.h | 4 ++-- src/FeaturesPlugin/CMakeLists.txt | 3 +-- .../FeaturesPlugin_GeometryCalculation.cpp | 19 ++++++++++--------- .../FeaturesPlugin_GeometryCalculation.h | 4 ++-- .../doc/TUI_basic_properties.rst | 12 ++++++++++++ .../doc/examples/basic_properties.py | 13 +++++++++++++ .../doc/geometryCalculationFeature.rst | 10 ++++++++++ ...et.xml => geometry_calculation_widget.xml} | 2 +- src/FeaturesPlugin/plugin-Features.xml | 3 +-- .../GeomAlgoAPI_BasicProperties.cpp | 12 ++++++------ src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h | 12 ++++++------ src/ModelAPI/CMakeLists.txt | 5 ----- 13 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 src/FeaturesPlugin/doc/TUI_basic_properties.rst create mode 100644 src/FeaturesPlugin/doc/examples/basic_properties.py rename src/FeaturesPlugin/{GeometryCalculation_widget.xml => geometry_calculation_widget.xml} (87%) diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp index 9bf0ae406..a0067e55d 100644 --- a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp @@ -24,8 +24,9 @@ #include #include -std::list getBasicProperties(const std::shared_ptr& thePart, - const ModelHighAPI_Selection& theObject) +//================================================================================================= +std::list getBasicProperties(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject) { FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_GeometryCalculation::ID()); @@ -37,7 +38,7 @@ std::list getBasicProperties(const std::shared_ptr& AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast( aPointCoodFeat->attribute(FeaturesPlugin_GeometryCalculation::RESULT_VALUES_ID())); - for ( int i : {0, 1, 2}) + for (int i : {0, 1, 2}) res.push_back( aResult->value(i)); return res; diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h index abed69276..8b912eaa7 100644 --- a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h +++ b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h @@ -31,7 +31,7 @@ class ModelHighAPI_Selection; /// \ingroup CPPHighAPI /// \brief get the basic properties (lenght, Surface area, volume) FEATURESAPI_EXPORT -std::list getBasicProperties(const std::shared_ptr& thePart, - const ModelHighAPI_Selection& theObject); +std::list getBasicProperties(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject); #endif // FeaturesAPI_GeometryCalculation_H_ \ No newline at end of file diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index ab56bb256..83df4b493 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -24,7 +24,6 @@ INCLUDE(UseQtExt) # additional include directories INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ${PROJECT_SOURCE_DIR}/src/Locale - ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin ${QT_INCLUDES}) # additional preprocessor / compiler flags @@ -157,7 +156,7 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml - GeometryCalculation_widget.xml + geometry_calculation_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp index c16bc78a3..fb74e5f8a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp @@ -29,18 +29,18 @@ #include #include -#include -#include #include #include #include +//================================================================================================= FeaturesPlugin_GeometryCalculation::FeaturesPlugin_GeometryCalculation() { } +//================================================================================================= void FeaturesPlugin_GeometryCalculation::initAttributes() { // attribute for point selected @@ -51,15 +51,16 @@ void FeaturesPlugin_GeometryCalculation::initAttributes() data()->addAttribute(VOLUME_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId()); - data()->realArray(RESULT_VALUES_ID())->setSize(3); } +//================================================================================================= void FeaturesPlugin_GeometryCalculation::execute() { } +//================================================================================================= void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& theID) { if (theID == OBJECT_SELECTED_ID()) { @@ -77,18 +78,18 @@ void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& the if (!aShape && aSelection->context()) aShape = aSelection->context()->shape(); } - if (aShape){ + if (aShape) { double aTolerance = 0.0001; double aLength; double aSurfArea; double aVolume; std::string aError; - if( !GetBasicProperties( aShape, + if (!GetBasicProperties(aShape, aTolerance, aLength, aSurfArea, aVolume, - aError) ) + aError)) setError("Error in Geometry calculation :" + aError); streamL << std::setprecision(14) << aLength; @@ -99,9 +100,9 @@ void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& the aValues->setValue(2, aVolume); } - string(LENGHT_ID() )->setValue( "Lenght = " + streamL.str() ); - string(AREA_ID() )->setValue( "Area = " + streamA.str() ); - string(VOLUME_ID() )->setValue( "Volume = " + streamV.str() ); + string(LENGHT_ID())->setValue("Lenght = " + streamL.str()); + string(AREA_ID())->setValue("Area = " + streamA.str()); + string(VOLUME_ID())->setValue("Volume = " + streamV.str()); } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h index a41e85365..0eaeaa134 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h @@ -33,7 +33,7 @@ class FeaturesPlugin_GeometryCalculation : public ModelAPI_Feature { public: - inline static const std::string& ID() + inline static const std::string& ID() { static const std::string MY_ID("GeometryCalculation"); return MY_ID; @@ -73,7 +73,7 @@ public: return MY_VOLUME_ID; } - /// Attribute name for values of result. + /// Attribute name for values of result. inline static const std::string& RESULT_VALUES_ID() { static const std::string MY_RESULT_VALUES_ID("result_values"); diff --git a/src/FeaturesPlugin/doc/TUI_basic_properties.rst b/src/FeaturesPlugin/doc/TUI_basic_properties.rst new file mode 100644 index 000000000..8e6eeafa1 --- /dev/null +++ b/src/FeaturesPlugin/doc/TUI_basic_properties.rst @@ -0,0 +1,12 @@ + + .. _tui_basic_properties: + +Get basic properties +==================== + +.. literalinclude:: examples/basic_properties.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/FeaturesPlugin/doc/examples/basic_properties.py b/src/FeaturesPlugin/doc/examples/basic_properties.py new file mode 100644 index 000000000..68a1949e1 --- /dev/null +++ b/src/FeaturesPlugin/doc/examples/basic_properties.py @@ -0,0 +1,13 @@ +import os +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +properties = model.getBasicProperties(Part_1_doc,model.selection("SOLID", "Box_1_1")) +print(" lenght: ", properties[0]) +print(" area: ", properties[1]) +print(" volume: ", properties[2]) +model.end() \ No newline at end of file diff --git a/src/FeaturesPlugin/doc/geometryCalculationFeature.rst b/src/FeaturesPlugin/doc/geometryCalculationFeature.rst index a90d5bc8b..4018f219d 100644 --- a/src/FeaturesPlugin/doc/geometryCalculationFeature.rst +++ b/src/FeaturesPlugin/doc/geometryCalculationFeature.rst @@ -26,3 +26,13 @@ Input fields: - **Object** contains an object selected in 3D OCC viewer or object browser. The basic properties displayed can be selected. + +**TUI Command**: + +.. py:function:: model.GetBasicProperties(Part_doc, shape) + + :param part: The current part object. + :param object: A shape in format *model.selection("type", shape)*. + :return: list containing lenght, area and volume. + +**See Also** a sample TUI Script of :ref:`tui_basic_properties` operation. \ No newline at end of file diff --git a/src/FeaturesPlugin/GeometryCalculation_widget.xml b/src/FeaturesPlugin/geometry_calculation_widget.xml similarity index 87% rename from src/FeaturesPlugin/GeometryCalculation_widget.xml rename to src/FeaturesPlugin/geometry_calculation_widget.xml index 4b5913dc5..da30ff176 100644 --- a/src/FeaturesPlugin/GeometryCalculation_widget.xml +++ b/src/FeaturesPlugin/geometry_calculation_widget.xml @@ -2,7 +2,7 @@ diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 00dddaf5f..343c77567 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -172,11 +172,10 @@ - - + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.cpp index 2a7530383..10a540b8a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.cpp @@ -26,12 +26,12 @@ #include //================================================================================================= -bool GetBasicProperties( const std::shared_ptr& theShape, - const double theTolerance, - Standard_Real& theLength, - Standard_Real& theSurfArea, - Standard_Real& theVolume, - std::string& theError) +bool GetBasicProperties(const std::shared_ptr& theShape, + const double theTolerance, + Standard_Real& theLength, + Standard_Real& theSurfArea, + Standard_Real& theVolume, + std::string& theError) { #ifdef _DEBUG diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h b/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h index 5450ea726..4db5dc4f2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BasicProperties.h @@ -32,11 +32,11 @@ /// \param theVolume Volume calculated /// \param theError error GEOMALGOAPI_EXPORT -bool GetBasicProperties( const std::shared_ptr& theShape, - const Standard_Real theTolerance, - Standard_Real& theLength, - Standard_Real& theSurfArea, - Standard_Real& theVolume, - std::string& theError); +bool GetBasicProperties(const std::shared_ptr& theShape, + const Standard_Real theTolerance, + Standard_Real& theLength, + Standard_Real& theSurfArea, + Standard_Real& theVolume, + std::string& theError); #endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 7b7876165..0a49da695 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -117,7 +117,6 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config GeomAPI - ${OpenCASCADE_ApplicationFramework_LIBRARIES} ) SET(CMAKE_SWIG_FLAGS -threads -w325,321,362,383,302,403,451,473) ADD_DEFINITIONS(-DMODELAPI_EXPORTS) @@ -131,10 +130,6 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/Locale - ${OpenCASCADE_INCLUDE_DIR} - ${OpenCASCADE_DataExchange_LIBRARIES} - ${OpenCASCADE_ModelingAlgorithms_LIBRARIES} - ${OpenCASCADE_ApplicationFramework_LIBRARIES} ) -- 2.39.2