Salome HOME
Issue #1385: Fixed GeomAlgoAPI_ShapeTools::volume
authordbv <dbv@opencascade.com>
Fri, 8 Apr 2016 15:32:33 +0000 (18:32 +0300)
committerdbv <dbv@opencascade.com>
Fri, 8 Apr 2016 15:32:33 +0000 (18:32 +0300)
src/ExchangePlugin/Test/TestExport.py
src/ExchangePlugin/Test/TestImport.py
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp

index 6836c5fe4ca78107f993a7040d4bf62fb4359bb3..50b8fc8839ec76366eb596c60e7983aa16f0501d 100644 (file)
@@ -31,46 +31,46 @@ def removeFile(theFileName):
 # Common test function
 #=========================================================================
 def testExport(theType, theFormat, theFile, theVolume, theDelta):
-    # Import a reference part 
+    # Import a reference part
     aSession.startOperation("Add part")
     aPartFeature = aSession.moduleDocument().addFeature("Part")
     aSession.finishOperation()
     aPart = aSession.activeDocument()
-    
+
     aSession.startOperation("Import screw")
     anImportFeature = aPart.addFeature("Import")
     anImportFeature.string("file_path").setValue("Data/screw.step")
     anImportFeature.execute()
     aSession.finishOperation()
-    
+
     removeFile(theFile)
     # Export a part
     aSession.startOperation("Export part")
     aFeatureKind = "Export"
     anExportFeature = aPart.addFeature(aFeatureKind)
     assert anExportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
-    
+
     aFormatAttrName = "file_format"
     aFormatAttr = anExportFeature.string(aFormatAttrName)
     assert aFormatAttr, "{0}: Can not receive string field {1}".format(theType, aFormatAttrName)
     aFormatAttr.setValue(theFormat)
-    
+
     aFileAttrName = "file_path"
     aFileAttr = anExportFeature.string(aFileAttrName)
     assert aFileAttr, "{0}: Can not receive string field {1}".format(theType, aFileAttrName)
     aFileAttr.setValue(theFile)
-    
+
     aSelectionListAttrName = "selection_list"
     aSelectionListAttr = anExportFeature.selectionList(aSelectionListAttrName)
     assert aSelectionListAttr, "{0}: Can not receive selection list field {1}".format(theType, aSelectionListAttrName)
     aSelectionListAttr.setSelectionType("solids")
     aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
-    
+
     anExportFeature.execute()
     aSession.finishOperation()
-    
+
     assert os.path.exists(theFile), "{0}: Can not find exported file {1}".format(theType, theFile)
-    
+
     # Test exported file by importing
     testImport(theType, theFile, theVolume, theDelta)
 
@@ -78,21 +78,21 @@ if __name__ == '__main__':
 #=========================================================================
 # Export a shape into BREP
 #=========================================================================
-    aRealVolume = 3.78827059338e-06
+    aRealVolume = 3.78827401738e-06
     testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17)
     testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17)
 #=========================================================================
 # Export a shape into STEP
 #=========================================================================
-    testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.7882546512e-06, 10 ** -17)
-    testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.7882546512e-06, 10 ** -17)
+    testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.78825807533e-06, 10 ** -17)
+    testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.78825807533e-06, 10 ** -17)
 #=========================================================================
 # Export a shape into IGES
 #=========================================================================
-    testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78827190923e-06, 10 ** -17)
-    testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78827190923e-06, 10 ** -17)
-    testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827060085e-06, 10 ** -17)
-    testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827060085e-06, 10 ** -17)
+    testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17)
+    testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17)
+    testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17)
+    testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17)
 #=========================================================================
 # End of test
 #=========================================================================
index 5756228a69e34be3da665bb97ab06622e5f92711..624f7f31867132550a84c3c5f3ec0c72530b2e9f 100644 (file)
@@ -24,7 +24,7 @@ def testImport(theType, theFile, theVolume, theDelta):
     aPartFeature = aSession.moduleDocument().addFeature("Part")
     aSession.finishOperation()
     aPart = aSession.activeDocument()
-    
+
     aSession.startOperation("Import file")
     aFeatureKind = "Import"
     anImportFeature = aPart.addFeature(aFeatureKind)
@@ -35,7 +35,7 @@ def testImport(theType, theFile, theVolume, theDelta):
     file.setValue(theFile)
     anImportFeature.execute()
     aSession.finishOperation()
-    
+
     # Check results
     assert anImportFeature.error() == '', "{0}: The error after execution: {1}".format(theType, anImportFeature.error())
     assert len(anImportFeature.results()) == 1, "{0}: Wrong number of results: expected = 1, real = {1}".format(theType, len(anImportFeature.results()))
@@ -43,7 +43,7 @@ def testImport(theType, theFile, theVolume, theDelta):
     assert aResultBody, "{0}: The result is not a body".format(theType)
     aShape = aResultBody.shape()
     assert aShape, "{0}: The body does not have a shape".format(theType)
-    
+
     # Check shape volume
     aRefVolume = theVolume
     aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape)
@@ -53,18 +53,18 @@ if __name__ == '__main__':
 #=========================================================================
 # Create a shape imported from BREP
 #=========================================================================
-    testImport("BREP", "Data/solid.brep", 259982.29715, 10 ** -5)
-    testImport("BRP", "Data/solid.brp", 259982.29715, 10 ** -5)
+    testImport("BREP", "Data/solid.brep", 259982.297176, 10 ** -5)
+    testImport("BRP", "Data/solid.brp", 259982.297176, 10 ** -5)
 #=========================================================================
 # Create a shape imported from STEP
 #=========================================================================
-    testImport("STP", "Data/screw.stp", 3.78827059338e-06, 10 ** -17)
-    testImport("STEP", "Data/screw.step", 3.78827059338e-06, 10 ** -17)
+    testImport("STP", "Data/screw.stp", 3.78827401738e-06, 10 ** -17)
+    testImport("STEP", "Data/screw.step", 3.78827401738e-06, 10 ** -17)
 #=========================================================================
 # Create a shape imported from IGES
 #=========================================================================
-    testImport("IGES", "Data/bearing.iges", 6.86980756235e-14, 10 ** -25)
-    testImport("IGS", "Data/bearing.igs", 6.86980756235e-14, 10 ** -25)
+    testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25)
+    testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25)
 #=========================================================================
 # End of test
 #=========================================================================
index 09eb5254907057ea5707baeca960d23d28eafa74..fda821e1f4eb5ee5d578ab6ae6acbdc70d990617 100644 (file)
 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
   GProp_GProps aGProps;
-  if(!theShape) {
+  if(!theShape.get()) {
     return 0.0;
   }
   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
   if(aShape.IsNull()) {
     return 0.0;
   }
-  BRepGProp::VolumeProperties(aShape, aGProps);
+  const Standard_Real anEps = 1.e-6;
+  BRepGProp::VolumeProperties(aShape, aGProps, anEps);
   return aGProps.Mass();
 }