]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1530 The arcs representation is not fine enough
authornds <nds@opencascade.com>
Thu, 2 Jun 2016 12:45:48 +0000 (15:45 +0300)
committernds <nds@opencascade.com>
Thu, 2 Jun 2016 12:46:16 +0000 (15:46 +0300)
src/ModuleBase/ModuleBase_Tools.cpp
src/XGUI/XGUI_Displayer.cpp

index 11842fe9bc844e58f969937cad1bf3b20ccbeb07..6b83432a85131b859b5f7ac4116080022575021c 100755 (executable)
@@ -35,6 +35,7 @@
 #include <TopoDS_Iterator.hxx>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_ShapeExplorer.h>
 #include <Events_Error.h>
 
 #include <Config_PropManager.h>
@@ -54,6 +55,7 @@
 #include <string>
 
 const double tolerance = 1e-7;
+const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
 
 //#define DEBUG_ACTIVATE_WINDOW
 //#define DEBUG_SET_FOCUS
@@ -557,14 +559,34 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
   }
 }
 
+bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
+{
+  if (!theGeomShape.get())
+    return false;
+  // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+  // correction of deviation for them should not influence to the application performance
+  GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
+  bool anEmpty = anExp.empty();
+  return !anExp.more();
+}
+
 void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
                                     const Handle(Prs3d_Drawer)& theDrawer)
 {
   if (!theResult.get())
     return;
-
-  if (theResult->groupName() == ModelAPI_ResultConstruction::group())
-    theDrawer->SetDeviationCoefficient(1.e-4);
+  bool aUseDeviation = false;
+
+  std::string aResultGroup = theResult->groupName();
+  if (aResultGroup == ModelAPI_ResultConstruction::group())
+    aUseDeviation = true;
+  else if (aResultGroup == ModelAPI_ResultBody::group()) {
+    GeomShapePtr aGeomShape = theResult->shape();
+    if (aGeomShape.get())
+      aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
+  }
+  if (aUseDeviation)
+    theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
 }
 
 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
@@ -572,9 +594,11 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
 {
   if (theShape.IsNull())
     return;
-  TopAbs_ShapeEnum aType = theShape.ShapeType();
-  if ((aType == TopAbs_EDGE) || (aType == TopAbs_WIRE)) 
-    theDrawer->SetDeviationCoefficient(1.e-4);
+
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
+  aGeomShape->setImpl(new TopoDS_Shape(theShape));
+  if (setDefaultDeviationCoefficient(aGeomShape))
+    theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
 }
 
 Quantity_Color color(const std::string& theSection,
index 95d58996690c83bd5a5147984df7d7556a5b64d0..851f977a1036ddbe49a6b1016900b789321c0b87 100644 (file)
@@ -149,6 +149,18 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
     bool isShading = false;
     if (aPrs.get() != NULL) {
       anAIS = aPrs->getAISObject(anAIS);
+      if (anAIS.get()) {
+        // correct deviation coefficient for 
+        Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
+        if (!anAISPrs.IsNull()) {
+          Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
+          if (!aShapePrs.IsNull()) {
+            TopoDS_Shape aShape = aShapePrs->Shape();
+            if (!aShape.IsNull())
+              ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
+          }
+        }
+      }
     } else {
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (aResult.get() != NULL) {