]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
CEA : Lot2 - Geometry calculation
authorcg246364 <clarisse.genrault@cea.fr>
Wed, 6 Jan 2021 06:54:13 +0000 (07:54 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Wed, 20 Jan 2021 14:22:42 +0000 (15:22 +0100)
27 files changed:
src/FeaturesAPI/CMakeLists.txt
src/FeaturesAPI/FeaturesAPI.i
src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp [new file with mode: 0644]
src/FeaturesAPI/FeaturesAPI_GeometryCalculation.h [new file with mode: 0644]
src/FeaturesAPI/FeaturesAPI_swig.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts
src/FeaturesPlugin/Test/TestGeometryCalculation.py [new file with mode: 0644]
src/FeaturesPlugin/doc/FeaturesPlugin.rst
src/FeaturesPlugin/doc/TUI_geometryCalculation.rst [new file with mode: 0644]
src/FeaturesPlugin/doc/examples/geometry_calculation.py [new file with mode: 0644]
src/FeaturesPlugin/doc/geometryCalculationFeature.rst [new file with mode: 0644]
src/FeaturesPlugin/doc/images/geometryCalculation.png [new file with mode: 0644]
src/FeaturesPlugin/doc/images/geometryCalculationPropertyPanel.png [new file with mode: 0644]
src/FeaturesPlugin/geometry_calculation_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/icons/geometryCalculation.png [new file with mode: 0644]
src/FeaturesPlugin/plugin-Features.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetLabel.cpp
src/ModuleBase/ModuleBase_WidgetLabel.h
src/PythonAPI/model/features/__init__.py
src/SHAPERGUI/resources/LightApp.xml.in

index 78b18e83f76aecf08c3cdbe1df0eff60321d33f0..844baeb00a8ebe37a3c5d22a0fa70197384e8243 100644 (file)
@@ -52,6 +52,7 @@ SET(PROJECT_HEADERS
   FeaturesAPI_ImportResult.h
   FeaturesAPI_Defeaturing.h
   FeaturesAPI_PointCoordinates.h
+  FeaturesAPI_GeometryCalculation.h
 )
 
 SET(PROJECT_SOURCES
@@ -86,6 +87,7 @@ SET(PROJECT_SOURCES
   FeaturesAPI_ImportResult.cpp
   FeaturesAPI_Defeaturing.cpp
   FeaturesAPI_PointCoordinates.cpp
+  FeaturesAPI_GeometryCalculation.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 5324158dc0eb9bc1cb596f9ee185e73684381d90..4a63d049b89615ef434b00e13a1fc46c555a0bbf 100644 (file)
 %include "FeaturesAPI_Copy.h"
 %include "FeaturesAPI_ImportResult.h"
 %include "FeaturesAPI_PointCoordinates.h"
+%include "FeaturesAPI_GeometryCalculation.h"
diff --git a/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp b/src/FeaturesAPI/FeaturesAPI_GeometryCalculation.cpp
new file mode 100644 (file)
index 0000000..666489e
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2018-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
+//
+
+#include "FeaturesAPI_GeometryCalculation.h"
+
+#include <FeaturesPlugin_GeometryCalculation.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelHighAPI_Services.h>
+#include <ModelHighAPI_Tools.h>
+
+//=================================================================================================
+std::list<double> getGeometryCalculation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                         const ModelHighAPI_Selection& theObject)
+{
+  FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_GeometryCalculation::ID());
+
+  fillAttribute(theObject, aPointCoodFeat
+                      ->selection(FeaturesPlugin_GeometryCalculation::OBJECT_SELECTED_ID()));
+  std::list<double> res;
+
+  // obtain result
+  AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
+      aPointCoodFeat->attribute(FeaturesPlugin_GeometryCalculation::RESULT_VALUES_ID()));
+
+  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
new file mode 100644 (file)
index 0000000..b1b6cb3
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (C) 2018-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
+//
+
+#ifndef FeaturesAPI_GeometryCalculation_H_
+#define FeaturesAPI_GeometryCalculation_H_
+
+#include "FeaturesAPI.h"
+
+#include <list>
+#include <memory>
+
+class ModelAPI_Document;
+class ModelHighAPI_Selection;
+
+/// \ingroup CPPHighAPI
+/// \brief get the geometry calculation (length, Surface area, volume)
+FEATURESAPI_EXPORT
+std::list<double> getGeometryCalculation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                         const ModelHighAPI_Selection& theObject);
+
+#endif // FeaturesAPI_GeometryCalculation_H_
\ No newline at end of file
index c2a5c5a83a21d1fc3aad0b6cf99f57afb3f79aa7..1ad19edc162025c00261c70ff8fc02af74a0c9f7 100644 (file)
@@ -54,5 +54,6 @@
   #include "FeaturesAPI_Copy.h"
   #include "FeaturesAPI_ImportResult.h"
   #include "FeaturesAPI_PointCoordinates.h"
+  #include "FeaturesAPI_GeometryCalculation.h"
 
 #endif // FeaturesAPI_swig_H_
index ce50f9d33bb76f37947513331613656a64bdf99a..1e14a62895a6e28f66b10f4155ebb52b4caf123d 100644 (file)
@@ -68,6 +68,7 @@ SET(PROJECT_HEADERS
     FeaturesPlugin_Defeaturing.h
     FeaturesPlugin_VersionedChFi.h
     FeaturesPlugin_PointCoordinates.h
+    FeaturesPlugin_GeometryCalculation.h
 )
 
 SET(PROJECT_SOURCES
@@ -116,6 +117,7 @@ SET(PROJECT_SOURCES
     FeaturesPlugin_Defeaturing.cpp
     FeaturesPlugin_VersionedChFi.cpp
     FeaturesPlugin_PointCoordinates.cpp
+    FeaturesPlugin_GeometryCalculation.cpp
 )
 
 SET(XML_RESOURCES
@@ -153,6 +155,7 @@ SET(XML_RESOURCES
   import_result_widget.xml
   defeaturing_widget.xml
   point_coordinates_widget.xml
+  geometry_calculation_widget.xml
 )
 
 SET(TEXT_RESOURCES
@@ -694,4 +697,5 @@ ADD_UNIT_TESTS(TestExtrusion.py
                Test20245_3.py
                Test20247.py
                TestPointCoordinates.py
+               TestGeometryCalculation.py
 )
diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp
new file mode 100644 (file)
index 0000000..2f94c04
--- /dev/null
@@ -0,0 +1,110 @@
+// Copyright (C) 2018-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
+//
+
+#include "FeaturesPlugin_GeometryCalculation.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+
+#include <Config_PropManager.h>
+
+#include <GeomAPI_Shape.h>
+#include <GeomAlgoAPI_GeometryCalculation.h>
+
+
+#include <iomanip>
+#include <sstream>
+
+//=================================================================================================
+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(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()) {
+
+    AttributeSelectionPtr aSelection = selection(OBJECT_SELECTED_ID());
+    AttributeDoubleArrayPtr aValues =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+    std::stringstream streamL;
+    std::stringstream streamA;
+    std::stringstream streamV;
+    GeomShapePtr aShape;
+
+    if (aSelection && aSelection->isInitialized()) {
+      aShape = aSelection->value();
+      if (!aShape && aSelection->context())
+        aShape = aSelection->context()->shape();
+    }
+
+    if (aShape) {
+      double aTolerance = 0.0001;
+      double aLength;
+      double aSurfArea;
+      double aVolume;
+      std::string aError;
+      if (!getGeometryCalculation(aShape,
+                                  aTolerance,
+                                  aLength,
+                                  aSurfArea,
+                                  aVolume,
+                                  aError))
+         setError("Error in Geometry calculation :" +  aError);
+
+      streamL << std::setprecision(14) << aLength;
+      aValues->setValue(0, aLength);
+      streamA << std::setprecision(14) << aSurfArea;
+      aValues->setValue(1, aSurfArea);
+      streamV << std::setprecision(14) << aVolume;
+      aValues->setValue(2, aVolume);
+    }
+
+    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
new file mode 100644 (file)
index 0000000..bd90966
--- /dev/null
@@ -0,0 +1,101 @@
+// Copyright (C) 2018-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
+//
+
+#ifndef FeaturesPlugin_GeometryCalculation_H_
+#define FeaturesPlugin_GeometryCalculation_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_IScreenParams.h>
+
+/// \class FeaturesPlugin_GeometryCalculation
+/// \ingroup Plugins
+/// \brief Feature for geometry calculation.
+
+class FeaturesPlugin_GeometryCalculation : public ModelAPI_Feature
+{
+public:
+  inline static const std::string& ID()
+  {
+    static const std::string MY_ID("GeometryCalculation");
+    return MY_ID;
+  }
+
+  /// \return the kind of a feature.
+  virtual const std::string& getKind()
+  {
+    return ID();
+  }
+
+  /// Attribute name for object selected.
+  inline static const std::string& OBJECT_SELECTED_ID()
+  {
+    static const std::string MY_OBJECT_SELECTED_ID("main_object");
+    return MY_OBJECT_SELECTED_ID;
+  }
+
+  /// Attribute name for length
+  inline static const std::string& LENGTH_ID()
+  {
+    static const std::string MY_LENGTH_ID("length");
+    return MY_LENGTH_ID;
+  }
+
+  /// Attribute name for area
+  inline static const std::string& AREA_ID()
+  {
+    static const std::string MY_AREA_ID("area");
+    return MY_AREA_ID;
+  }
+
+  /// Attribute name for volume.
+  inline static const std::string& VOLUME_ID()
+  {
+    static const std::string MY_VOLUME_ID("volume");
+    return MY_VOLUME_ID;
+  }
+
+  /// Attribute name for values of result.
+  inline static const std::string& RESULT_VALUES_ID()
+  {
+    static const std::string MY_RESULT_VALUES_ID("result_values");
+    return MY_RESULT_VALUES_ID;
+  }
+
+  /// Performs the algorithm and stores results it in the data structure.
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+  FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_GeometryCalculation();
+
+};
+
+#endif
index fdd2beeea9194fc972b94bf6cb6da6f3152bc5f9..8419057e24c8e54d51522416643debcf3b3fa572 100644 (file)
@@ -31,6 +31,7 @@
 #include <FeaturesPlugin_ExtrusionFuse.h>
 #include <FeaturesPlugin_Fillet.h>
 #include <FeaturesPlugin_Fillet1D.h>
+#include <FeaturesPlugin_GeometryCalculation.h>
 #include <FeaturesPlugin_Intersection.h>
 #include <FeaturesPlugin_Measurement.h>
 #include <FeaturesPlugin_PointCoordinates.h>
@@ -200,6 +201,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new FeaturesPlugin_Defeaturing);
   } else if (theFeatureID == FeaturesPlugin_PointCoordinates::ID()) {
     return FeaturePtr(new FeaturesPlugin_PointCoordinates);
+  } else if (theFeatureID == FeaturesPlugin_GeometryCalculation::ID()) {
+    return FeaturePtr(new FeaturesPlugin_GeometryCalculation);
   }
 
 
index 798f86a53b27fe961019663d100d9b4939af442d..ff2645663d07385590a993e1f792780c4f31052c 100644 (file)
       <source>Point coordinates</source>
       <translation>Coordonnées d'un point</translation>
     </message>
+    <message>
+      <source>Geometry calculation</source>
+      <translation>Calcul de la géométrie</translation>
+    </message>
     <message>
       <source>Placement</source>
       <translation>Placement</translation>
       <translation>Coordonnées d'un point</translation>
     </message>
   </context>
+  <!--Geometry calculation-->
+  <context>
+    <name>GeometryCalculation</name>
+    <message>
+      <source>Geometry calculation</source>
+      <translation>Calcul de la géometrie</translation>
+    </message>
+  </context>
+  <context>
+    <name>GeometryCalculation:main_object</name>
+    <message>
+      <source>Object</source>
+      <translation>Objet</translation>
+    </message>
+  </context>
+  <context>
+    <name>GeometryCalculation</name>
+    <message>
+      <source>Length = </source>
+      <translation>Longueur = </translation>
+    </message>
+    <message>
+      <source>Area = </source>
+      <translation>Surface = </translation>
+    </message>
+    <message>
+      <source>Volume = </source>
+      <translation>Volume = </translation>
+    </message>
+  </context>
   <!-- Measurement -->
   <context>
     <name>Measurement</name>
diff --git a/src/FeaturesPlugin/Test/TestGeometryCalculation.py b/src/FeaturesPlugin/Test/TestGeometryCalculation.py
new file mode 100644 (file)
index 0000000..a3e1f1e
--- /dev/null
@@ -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
+    #=========================================================================
index dd4f0810729acfc35b72f3c9f0da264b016d05f1..23cfb1f5c4bedca923e999f59506428a972142b8 100644 (file)
@@ -21,6 +21,7 @@ Features plug-in provides a set of common topological operations. It implements
    fillet1dFeature.rst
    filletFeature.rst
    fuseFeatureFaces.rst
+   geometryCalculationFeature.rst
    importResultFeature.rst
    linearCopyFeature.rst
    measurementFeature.rst
diff --git a/src/FeaturesPlugin/doc/TUI_geometryCalculation.rst b/src/FeaturesPlugin/doc/TUI_geometryCalculation.rst
new file mode 100644 (file)
index 0000000..43a8f06
--- /dev/null
@@ -0,0 +1,12 @@
+
+  .. _tui_geometry_calculation:
+
+Get Geometry Calculation
+========================
+
+.. literalinclude:: examples/geometry_calculation.py 
+    :linenos:
+    :language: python
+
+:download:`Download this script <examples/geometry_calculation.py>`
+   
diff --git a/src/FeaturesPlugin/doc/examples/geometry_calculation.py b/src/FeaturesPlugin/doc/examples/geometry_calculation.py
new file mode 100644 (file)
index 0000000..e1e340a
--- /dev/null
@@ -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 (file)
index 0000000..2487d53
--- /dev/null
@@ -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 (file)
index 0000000..f46c0da
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 (file)
index 0000000..17f8cd7
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 (file)
index 0000000..5597937
--- /dev/null
@@ -0,0 +1,13 @@
+<source>
+  <shape_selector id="main_object"
+                  label="Object"
+                  tooltip="Select a object"
+                  shape_types="edges faces solids compsolids"
+                  default=""
+                  geometrical_selection="true">
+    <validator id="GeomValidators_ShapeType" parameters="line,edge,wire,face,shell,solid,compsolid,compound"/>
+  </shape_selector>
+  <label id="length" label="Length = " isSelectable = "true"/>
+  <label id="area" label="Area = " isSelectable = "true"/>
+  <label id="volume" label="Volume = " isSelectable = "true"/>
+</source>
diff --git a/src/FeaturesPlugin/icons/geometryCalculation.png b/src/FeaturesPlugin/icons/geometryCalculation.png
new file mode 100644 (file)
index 0000000..f46c0da
Binary files /dev/null and b/src/FeaturesPlugin/icons/geometryCalculation.png differ
index a45dbce5d4ff64df6c9202d4e81498c246ecee8f..2ee03397712e6b750fbd9f76916fd9fffefe6196 100644 (file)
       </feature>
     </group>
     <group id="Calculation">
+     <feature id="GeometryCalculation" title="Geometry calculation" tooltip="Calculate properties of objects"
+               icon="icons/Features/geometryCalculation.png" helpfile="geometryCalculationFeature.html" abort_confirmation="false">
+        <source path="geometry_calculation_widget.xml"/>
+      </feature>
       <feature id="Measurement" title="Measurement" tooltip="Calculate properties of objects"
                icon="icons/Features/measurement.png" helpfile="measurementFeature.html" abort_confirmation="false">
         <source path="measurement_widget.xml"/>
index a03ae213f7537d4a1653bfbd2bf1183de71810a5..0aaebb2197613b74b6d33b7b3bb86519c4513013 100644 (file)
@@ -88,6 +88,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_Projection.h
     GeomAlgoAPI_Chamfer.h
     GeomAlgoAPI_Defeaturing.h
+    GeomAlgoAPI_GeometryCalculation.h
 )
 
 SET(PROJECT_SOURCES
@@ -155,6 +156,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_Projection.cpp
     GeomAlgoAPI_Chamfer.cpp
     GeomAlgoAPI_Defeaturing.cpp
+    GeomAlgoAPI_GeometryCalculation.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp
new file mode 100644 (file)
index 0000000..43af83c
--- /dev/null
@@ -0,0 +1,75 @@
+// 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
+//
+
+#include "GeomAlgoAPI_GeometryCalculation.h"
+
+#include <GProp_GProps.hxx>
+#include <TopoDS_Shape.hxx>
+#include <BRepGProp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <Standard_ErrorHandler.hxx>
+
+//=================================================================================================
+bool getGeometryCalculation(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                            const double theTolerance,
+                            Standard_Real& theLength,
+                            Standard_Real& theSurfArea,
+                            Standard_Real& theVolume,
+                            std::string& theError)
+{
+
+  #ifdef _DEBUG
+  std::cout << "getGeometryCalculation " << std::endl;
+  #endif
+
+  if (!theShape.get()) {
+    theError = "getGeometryCalculation : An invalid argument";
+    return false;
+  }
+
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+
+  //Compute the parameters
+  GProp_GProps aLProps, aSProps;
+  Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
+  try {
+    OCC_CATCH_SIGNALS;
+    BRepGProp::LinearProperties(aShape, aLProps, Standard_True);
+    theLength = aLProps.Mass();
+
+    BRepGProp::SurfaceProperties(aShape, aSProps, anEps, Standard_True);
+    theSurfArea = aSProps.Mass();
+
+    theVolume = 0.0;
+    if (aShape.ShapeType() < TopAbs_SHELL) {
+      for (TopExp_Explorer anExp (aShape, TopAbs_SOLID); anExp.More(); anExp.Next()) {
+        GProp_GProps aVProps;
+        BRepGProp::VolumeProperties(anExp.Current(), aVProps, anEps, Standard_True);
+        theVolume += aVProps.Mass();
+      }
+    }
+  }
+  catch (Standard_Failure& aFail) {
+    theError = aFail.GetMessageString();
+    return false;
+  }
+
+  return true;
+
+}
\ No newline at end of file
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h b/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h
new file mode 100644 (file)
index 0000000..df1f2f2
--- /dev/null
@@ -0,0 +1,42 @@
+// 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
+//
+
+#ifndef GeomAlgoAPI_GeometryCalculation_H_
+#define GeomAlgoAPI_GeometryCalculation_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <Standard_TypeDef.hxx>
+
+/// Run chamfer operation with two distances or with a distance and an angle .
+  /// \param theShape      the shape
+  /// \param theTolerance  tolerance desirated
+  /// \param theLength     length calculated
+  /// \param theSurfArea   Surface Area calculated
+  /// \param theVolume     Volume calculated
+  /// \param theError      error
+GEOMALGOAPI_EXPORT
+bool getGeometryCalculation(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                            const Standard_Real theTolerance,
+                            Standard_Real& theLength,
+                            Standard_Real& theSurfArea,
+                            Standard_Real& theVolume,
+                            std::string& theError);
+
+#endif
index 7e3f86de0ab80bdf75d1b2397dfeb846dd64de43..1f4d511e2298ef15aa1233b166fe0033d5d1c82b 100644 (file)
@@ -37,6 +37,9 @@ ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
 : ModuleBase_ModelWidget(theParent, theData)
 {
   QString aText = translate(theData->getProperty("title"));
+
+  myPrefix  = theData->getProperty(ATTR_LABEL);
+
   bool aIsHtml = theData->getBooleanAttribute(ATTR_HTML_STYLE, false);
 
   QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
@@ -99,7 +102,11 @@ bool ModuleBase_WidgetLabel::restoreValueCustom()
         aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
       }
     }
-    myLabel->setText(aText);
+    if (myPrefix == "") {
+      myLabel->setText(aText);
+    } else {
+      myLabel->setText(ModuleBase_Tools::translate(myFeature->getKind(), myPrefix) + aText);
+    }
   }
   return true;
 }
index be90456c0c49989f467758f874bb8d37fdfc4592..83ebd2ea24e88bf356dc515625a408b2d4e4e55a 100644 (file)
@@ -61,6 +61,8 @@ protected:
 
   /// A label control
   QLabel* myLabel;
+  /// A prefix for label
+  std::string myPrefix;
 };
 
 #endif
index 41f3e1e8e66bd2d0042284791c782cff13284a20..84b7b656213016e7ec9e71aae5a3415bd90f2888 100644 (file)
@@ -30,7 +30,7 @@ from FeaturesAPI import addRecover
 from FeaturesAPI import addFillet, addChamfer
 from FeaturesAPI import addFusionFaces
 from FeaturesAPI import measureLength, measureDistance, measureRadius, measureAngle
-from FeaturesAPI import getPointCoordinates
+from FeaturesAPI import getPointCoordinates, getGeometryCalculation
 from FeaturesAPI import addRemoveResults
 from FeaturesAPI import addCopy, addImportResult
 from FeaturesAPI import addDefeaturing
index 33908724f1de83403969f09bfd6e7ce62a43e555..6d303a073013d42b4201ccdc9bd49faba4b430e8 100644 (file)
@@ -22,6 +22,9 @@
     <parameter name="PartSet" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
     <parameter name="XGUI" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
   </section>
+  <section name="Sketch">
+    <parameter name="operation_cursor" value="1"/>
+  </section>
   <section name="Viewer" >
     <!-- Viewer preferences -->
     <parameter name="face-selection" value="true" />