From: lucasjerome Date: Wed, 23 Dec 2020 11:38:23 +0000 (+0100) Subject: #20500 : Update Geometry calculation and fix translation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=833a89695f2b643fcd417c2ff9126444b14cc121;p=modules%2Fshaper.git #20500 : Update Geometry calculation and fix translation --- diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp index 9bf0ae406..666489e0a 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 getGeometryCalculation(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject) { FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_GeometryCalculation::ID()); @@ -37,8 +38,8 @@ 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}) - res.push_back( aResult->value(i)); + 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..b1b6cb312 100644 --- a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h +++ b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h @@ -29,9 +29,9 @@ class ModelAPI_Document; class ModelHighAPI_Selection; /// \ingroup CPPHighAPI -/// \brief get the basic properties (lenght, Surface area, volume) +/// \brief get the geometry calculation (length, Surface area, volume) FEATURESAPI_EXPORT -std::list getBasicProperties(const std::shared_ptr& thePart, - const ModelHighAPI_Selection& theObject); +std::list getGeometryCalculation(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject); #endif // FeaturesAPI_GeometryCalculation_H_ \ No newline at end of file diff --git a/src/FeaturesPlugin/Bounding_Box_widget.xml b/src/FeaturesPlugin/Bounding_Box_widget.xml index 0dc8a0d12..b9a5e6f5a 100644 --- a/src/FeaturesPlugin/Bounding_Box_widget.xml +++ b/src/FeaturesPlugin/Bounding_Box_widget.xml @@ -1,5 +1,5 @@ - - selection(FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID()) ->setValue( selection(OBJECTS_LIST_ID())->context(), selection(OBJECTS_LIST_ID())->value() ); - + AttributeDoubleArrayPtr aValuesFeatures = - std::dynamic_pointer_cast(myCreateFeature->attribute(RESULT_VALUES_ID())); + std::dynamic_pointer_cast + (myCreateFeature->attribute(RESULT_VALUES_ID())); AttributeDoubleArrayPtr aValues = std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); for (int anI=0; anI < 6; anI++) diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h index cb1f1aacd..509df64e6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h @@ -44,7 +44,7 @@ public: /// Attribute name for object selected. inline static const std::string& OBJECTS_LIST_ID() { - static const std::string MY_OBJECTS_LIST_ID("main_objects"); + static const std::string MY_OBJECTS_LIST_ID("main_object"); return MY_OBJECTS_LIST_ID; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp index fc5f5cf64..9baee5543 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp @@ -106,7 +106,7 @@ void FeaturesPlugin_CreateBoundingBox::updateValues() if (!anIsCompute->value()) { myShape = aShape; anIsCompute->setValue(true); - } + } if (aShape && !aShape->isEqual(myShape)) { double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax; diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h index cac4347ea..fd942b9f4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h @@ -44,7 +44,7 @@ public: /// Attribute name for object selected. inline static const std::string& OBJECTS_LIST_ID() { - static const std::string MY_OBJECTS_LIST_ID("main_objects"); + static const std::string MY_OBJECTS_LIST_ID("main_object"); return MY_OBJECTS_LIST_ID; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp index c16bc78a3..6a349920b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp @@ -29,37 +29,38 @@ #include #include -#include -#include -#include +#include #include #include +//================================================================================================= FeaturesPlugin_GeometryCalculation::FeaturesPlugin_GeometryCalculation() { } +//================================================================================================= void FeaturesPlugin_GeometryCalculation::initAttributes() { // attribute for point selected data()->addAttribute(OBJECT_SELECTED_ID(), ModelAPI_AttributeSelection::typeId()); // attributes for result message and values - data()->addAttribute(LENGHT_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(AREA_ID(), ModelAPI_AttributeString::typeId()); 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, - aTolerance, - aLength, - aSurfArea, - aVolume, - aError) ) + if (!getGeometryCalculation(aShape, + aTolerance, + aLength, + aSurfArea, + aVolume, + 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(LENGTH_ID())->setValue(streamL.str()); + string(AREA_ID())->setValue(streamA.str()); + string(VOLUME_ID())->setValue(streamV.str()); } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h index a41e85365..bd90966f8 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; @@ -52,11 +52,11 @@ public: return MY_OBJECT_SELECTED_ID; } - /// Attribute name for lenght - inline static const std::string& LENGHT_ID() + /// Attribute name for length + inline static const std::string& LENGTH_ID() { - static const std::string MY_LENGHT_ID("lenght"); - return MY_LENGHT_ID; + static const std::string MY_LENGTH_ID("length"); + return MY_LENGTH_ID; } /// Attribute name for area @@ -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/FeaturesPlugin_msg_fr.ts b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts index 6f821a2e2..46fd40148 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts +++ b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts @@ -115,6 +115,14 @@ Angular Copy Copie angulaire + + Bounding box + Boite englobante + + + Geometry calculation + Calcul de la géométrie + Linear copy Copie linéaire @@ -140,7 +148,30 @@ Translation - + + + + BoundingBox + + BoundingBox + Boite englobante + + + Create box + Créer la boite + + + + BoundingBoxMacro + + BoundingBox + Boite englobante + + + Create box + Créer la boite + + Chamfer @@ -4327,7 +4358,73 @@ Pas pour la direction angulaire + + + BoundingBoxMacro + + Bounding box + Boîte englobante + + + + BoundingBoxMacro:main_object + + Object + Objet + + + + BoundingBoxMacro:createbox + + Create box + Créer la boite + + + + BoundingBox + + Bounding box + Boîte englobante + + + + BoundingBox:main_object + + Object + Objet + + + + + GeometryCalculation + + Geometry calculation + Calcul de la géometrie + + + + GeometryCalculation:main_object + + Object + Objet + + + + GeometryCalculation + + Length = + Longueur = + + + Area = + Surface = + + + Volume = + Volume = + + LinearCopy diff --git a/src/FeaturesPlugin/Test/TestBoundingBox.py b/src/FeaturesPlugin/Test/TestBoundingBox.py index 426a6df16..673445e86 100644 --- a/src/FeaturesPlugin/Test/TestBoundingBox.py +++ b/src/FeaturesPlugin/Test/TestBoundingBox.py @@ -52,7 +52,7 @@ def test_Bounding_Box(): model.end() myDelta = 1e-6 - Props = model.getBasicProperties(Part_1_doc,model.selection("SOLID", "BoundingBox_1_1")) + Props = model.getGeometryCalculation(Part_1_doc,model.selection("SOLID", "BoundingBox_1_1")) print(" Basic Properties:") print(" Wires length: ", Props[0]) diff --git a/src/FeaturesPlugin/Test/TestGeometryCalculation.py b/src/FeaturesPlugin/Test/TestGeometryCalculation.py new file mode 100644 index 000000000..a3e1f1ec2 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestGeometryCalculation.py @@ -0,0 +1,80 @@ +# Copyright (C) 2014-2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +""" + Unit test of ... +""" +#========================================================================= +# Initialization of the test +#========================================================================= + +import salome + +import os +import math + +from ModelAPI import * +from salome.shaper import model + + + +__updated__ = "2020-11-12" + + +#========================================================================= +# test Geometry calculation +#========================================================================= +def test_Geometry_Calculation(): + + model.begin() + file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep") + partSet = model.moduleDocument() + Part_1 = model.addPart(partSet) + Part_1_doc = Part_1.document() + Import_1 = model.addImport(Part_1_doc,file_path) + model.do() + + myDelta = 1e-6 + Props = model.getGeometryCalculation(Part_1_doc,model.selection("SOLID", "box1_1")) + + print(" Geometry calculation:") + print(" Wires length: ", Props[0]) + print(" Surface area: ", Props[1]) + print(" Volume : ", Props[2]) + + aReflength = 2400 + aReslength = Props[0] + assert (math.fabs(aReslength - aReflength) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aReflength, aReslength) + + aRefSurface = 240000 + aResSurface = Props[1] + assert (math.fabs(aResSurface - aRefSurface) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface) + + aRefVolume = 8000000 + aResVolume = Props[2] + assert (math.fabs(aResVolume - aRefVolume) < myDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefVolume, aResVolume) + + +if __name__ == '__main__': + + test_Geometry_Calculation() + + #========================================================================= + # End of test + #========================================================================= diff --git a/src/FeaturesPlugin/doc/FeaturesPlugin.rst b/src/FeaturesPlugin/doc/FeaturesPlugin.rst index b63fb696d..5304756f4 100644 --- a/src/FeaturesPlugin/doc/FeaturesPlugin.rst +++ b/src/FeaturesPlugin/doc/FeaturesPlugin.rst @@ -24,6 +24,7 @@ Features plug-in provides a set of common topological operations. It implements importResultFeature.rst linearCopyFeature.rst measurementFeature.rst + geometryCalculationFeature.rst boundingBoxFeature.rst pipeFeature.rst placementFeature.rst diff --git a/src/FeaturesPlugin/doc/TUI_geometry_calculation.rst b/src/FeaturesPlugin/doc/TUI_geometry_calculation.rst new file mode 100644 index 000000000..43a8f06a8 --- /dev/null +++ b/src/FeaturesPlugin/doc/TUI_geometry_calculation.rst @@ -0,0 +1,12 @@ + + .. _tui_geometry_calculation: + +Get Geometry Calculation +======================== + +.. literalinclude:: examples/geometry_calculation.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/FeaturesPlugin/doc/examples/geometry_calculation.py b/src/FeaturesPlugin/doc/examples/geometry_calculation.py new file mode 100644 index 000000000..e1e340a3b --- /dev/null +++ b/src/FeaturesPlugin/doc/examples/geometry_calculation.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.getGeometryCalculation(Part_1_doc,model.selection("SOLID", "Box_1_1")) +print(" length: ", 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 new file mode 100644 index 000000000..2487d5317 --- /dev/null +++ b/src/FeaturesPlugin/doc/geometryCalculationFeature.rst @@ -0,0 +1,38 @@ +.. |GeometryCalculation.icon| image:: images/geometryCalculation.png + +Geometry calculation +==================== + +The **Geometry calculation** feature displays basic properties of sub-elements of a geometrical object (shape). + +The geometry calculation displayed in the property panel are length, area and volume. + +**Apply** button does not generate any result and has the same effect as **Cancel** for this feature. + +To display geometry calculation in the active part: + +#. select in the Main Menu *Inspection - > Geometry calculation* item or +#. click |GeometryCalculation.icon| **Geometry calculation** button in the toolbar + +The geometry calculation can be displayed for a selected object in the property panel : + +.. figure:: images/geometryCalculationPropertyPanel.png + :align: center + + Geometry calculation + +Input fields: + +- **Object** contains an object selected in 3D OCC viewer or object browser. + +The geometry calculation displayed can be selected. + +**TUI Command**: + +.. py:function:: model.getGeometryCalculation(Part_doc, shape) + + :param part: The current part object. + :param object: A shape in format *model.selection("type", shape)*. + :return: list containing length, area and volume. + +**See Also** a sample TUI Script of :ref:`tui_geometry_calculation` operation. \ No newline at end of file diff --git a/src/FeaturesPlugin/doc/images/geometryCalculation.png b/src/FeaturesPlugin/doc/images/geometryCalculation.png new file mode 100644 index 000000000..f46c0da7a Binary files /dev/null and b/src/FeaturesPlugin/doc/images/geometryCalculation.png differ diff --git a/src/FeaturesPlugin/doc/images/geometryCalculationPropertyPanel.png b/src/FeaturesPlugin/doc/images/geometryCalculationPropertyPanel.png new file mode 100644 index 000000000..17f8cd7ef Binary files /dev/null and b/src/FeaturesPlugin/doc/images/geometryCalculationPropertyPanel.png differ diff --git a/src/FeaturesPlugin/geometry_calculation_widget.xml b/src/FeaturesPlugin/geometry_calculation_widget.xml new file mode 100644 index 000000000..55979378c --- /dev/null +++ b/src/FeaturesPlugin/geometry_calculation_widget.xml @@ -0,0 +1,13 @@ + + + + +