]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1660 Ability to change the deflection coefficient
authornds <nds@opencascade.com>
Thu, 28 Jul 2016 12:05:55 +0000 (15:05 +0300)
committernds <nds@opencascade.com>
Thu, 28 Jul 2016 12:05:55 +0000 (15:05 +0300)
src/GeomAPI/GeomAPI_AISObject.cpp
src/ModelAPI/ModelAPI_ResultBody.h
src/ModelAPI/ModelAPI_ResultConstruction.h
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/PartSet/PartSet_ResultSketchPrs.cpp
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Workshop.cpp

index 74c1e1344d81dc480eccc437576e87e86785fb4d..8510cdca30a9d27329f1e4019ec416314125db90 100644 (file)
@@ -379,13 +379,16 @@ bool GeomAPI_AISObject::setDeflection(const double theDeflection)
   bool isModified = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
-    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
-    if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) {
-      aDrawer->SetDeviationCoefficient(theDeflection);
-      isModified = true;
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!anAISShape.IsNull()) {
+      Standard_Real aCoefficient, aPreviousCoefficient;
+      anAISShape->OwnDeviationCoefficient(aCoefficient, aPreviousCoefficient);
+      if (fabs(aCoefficient-theDeflection) > Precision::Confusion()) {
+        isModified = true;
+        anAISShape->SetOwnDeviationCoefficient(theDeflection);
+      }
     }
   }
-
   return isModified;
 }
 
index 119978c6f5a896a0cc24f2c2259f6344be9f1471..6847000c493c548b703129d7d1356d9f5a745142 100644 (file)
@@ -44,6 +44,12 @@ public:
     return RESULT_BODY_COLOR;
   }
 
+  /// default deflection for a result body
+  inline static const std::string DEFAULT_DEFLECTION()
+  {
+    return "0.001";
+  }
+
   /// Iternal enumeration for storage the information of connected topology flag
   enum ConnectedTopologyFlag {
     ConnectionNotComputed, ///< not yet computed
index 41d74975c1960e82ce44ad175510b70ed73d3db0..4704bc43bd9af48f2dd9a100870645831aa2a7fa 100644 (file)
@@ -40,6 +40,12 @@ class ModelAPI_ResultConstruction : public ModelAPI_Result
     return RESULT_CONSTRUCTION_COLOR;
   }
 
+  /// default deflection for a result construction
+  inline static const std::string DEFAULT_DEFLECTION()
+  {
+    return "0.0001";
+  }
+
   /// Sets the result
   virtual void setShape(std::shared_ptr<GeomAPI_Shape> theShape) = 0;
 
index 09c65829a570da2f5a372d1da2cd6526d3f8ae11..49e1dc691715737cf3f9029d4bb33e92c3f03358 100755 (executable)
@@ -81,7 +81,7 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
       Set(myOriginalShape);
   }
   // change deviation coefficient to provide more precise circle
-  ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
+  //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 
   if (!aReadyToDisplay) {
index 305d2dfd1a8c5af1f3996482a4c2b4ac81494b27..6ca02d6acd6cea45a69c99366a96f59377920fb5 100755 (executable)
@@ -582,7 +582,7 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
   }
 }
 
-bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
+/*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
 {
   if (!theGeomShape.get())
     return false;
@@ -591,9 +591,9 @@ bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
   GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
   bool anEmpty = anExp.empty();
   return !anExp.more();
-}
+}*/
 
-void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
+/*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
                                     const Handle(Prs3d_Drawer)& theDrawer)
 {
   if (!theResult.get())
@@ -611,7 +611,7 @@ void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theR
   if (aUseDeviation)
     theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
 }
-
+*/
 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
                                     const Handle(Prs3d_Drawer)& theDrawer)
 {
@@ -620,8 +620,21 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
 
   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
   aGeomShape->setImpl(new TopoDS_Shape(theShape));
-  if (setDefaultDeviationCoefficient(aGeomShape))
-    theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
+
+  // 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(aGeomShape, GeomAPI_Shape::FACE);
+  bool isConstruction = !anExp.more();
+
+  double aDeflection;
+  if (isConstruction)
+    aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
+                                           ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
+  else
+    aDeflection = Config_PropManager::real("Visualization", "body_deflection",
+                                           ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+
+  theDrawer->SetDeviationCoefficient(aDeflection);
 }
 
 Quantity_Color color(const std::string& theSection,
index 244afca4c685e59c9e049100fb7a461421f36941..3e250f5c37dc1e2459e83a728b3d8fde81374139 100755 (executable)
@@ -164,9 +164,9 @@ MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasR
 /// It provides 1.e-4 for results of construction type
 /// \param theResult a result object to define the deviation coeffient
 /// \param theDrawer a drawer
-MODULEBASE_EXPORT void setDefaultDeviationCoefficient(
-                           const std::shared_ptr<ModelAPI_Result>& theResult,
-                           const Handle(Prs3d_Drawer)& theDrawer);
+//MODULEBASE_EXPORT void setDefaultDeviationCoefficient(
+//                           const std::shared_ptr<ModelAPI_Result>& theResult,
+//                           const Handle(Prs3d_Drawer)& theDrawer);
 
 /// Sets the default coeffient into the driver calculated accordingly the shape type.
 /// It provides 1.e-4 for a shape withe Edge shape type
index ccf60f8ae03f377030bd71253211166e982b2e4e..dba8a45ac9ef23deff754767627875e1e5be26cb 100755 (executable)
@@ -91,7 +91,7 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)
   setAuxiliaryPresentationStyle(false);
 
   // change deviation coefficient to provide more precise circle
-  ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
+  //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 
   if (!myAuxiliaryCompound.IsNull()) {
@@ -136,6 +136,7 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)
     return;
 
   bool aShapeIsChanged = false;
+  double aPrevDeviation = Attributes()->DeviationCoefficient();
   if (aMode == SketcherPrs_Tools::Sel_Sketch_Face ||
       aMode == SketcherPrs_Tools::Sel_Sketch_Wire) {
     aMode = (aMode == SketcherPrs_Tools::Sel_Sketch_Face) ? AIS_Shape::SelectionMode(TopAbs_FACE)
@@ -163,6 +164,9 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)
     debugInfo(aComp, TopAbs_FACE); // 2
 #endif
     Set(aComp);
+    double aBodyDefDeflection = Config_PropManager::real("Visualization", "body_deflection",
+                                                         ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+    Attributes()->SetDeviationCoefficient(aBodyDefDeflection);
     aShapeIsChanged = true;
   }
   else
@@ -178,8 +182,10 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)
 
   AIS_Shape::ComputeSelection(aSelection, aMode);
 
-  if (aShapeIsChanged)
+  if (aShapeIsChanged) {
+    Attributes()->SetDeviationCoefficient(aPrevDeviation);
     Set(myOriginalShape);
+  }
 }
 
 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
index 373eb2fe6e4569b712544d41efa8ddd7cdff16bc..fc9b7fb08fdff7bd0f9214188f340fe28bf15a64 100644 (file)
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAPI_ShapeExplorer.h>
+
 #include <Config_PropManager.h>
 
 #include <Events_InfoMessage.h>
@@ -27,8 +32,11 @@ double getDeflection(const ResultPtr& theResult)
   if (theResult.get() != NULL &&
       theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) {
     AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
-    if (aDoubleAttr.get() && aDoubleAttr->isInitialized())
-      aDeflection = aDoubleAttr->value();
+    if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) {
+      double aValue = aDoubleAttr->value();
+      if (aValue > 0) /// zero value should not be used as a deflection(previous studies)
+        aDeflection = aDoubleAttr->value();
+    }
   }
   return aDeflection;
 }
@@ -70,7 +78,31 @@ void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColo
 
 double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject)
 {
-  return Config_PropManager::real("Visualization", "result_deflection", "0.001");
+  double aDeflection = -1;
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aResult.get()) {
+    bool isConstruction = false;
+
+    std::string aResultGroup = aResult->groupName();
+    if (aResultGroup == ModelAPI_ResultConstruction::group())
+      isConstruction = true;
+    else if (aResultGroup == ModelAPI_ResultBody::group()) {
+      GeomShapePtr aGeomShape = aResult->shape();
+      if (aGeomShape.get()) {
+        // 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(aGeomShape, GeomAPI_Shape::FACE);
+        isConstruction = !anExp.more();
+      }
+    }
+    if (isConstruction)
+      aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
+                                             ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
+    else
+      aDeflection = Config_PropManager::real("Visualization", "body_deflection",
+                                             ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+  }
+  return aDeflection;
 }
 
 XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
index 87dfcee80d01d46780443ce4ae6e7d72eee0b1e6..24e7b9eb6f740d8dce04b28d42172ace6b21faea 100644 (file)
@@ -154,15 +154,15 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
       anAIS = aPrs->getAISObject(anAIS);
       if (anAIS.get()) {
         // correct deviation coefficient for 
-        Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
+        /*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());
+              //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
           }
-        }
+        }*/
       }
     } else {
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
index 6fe42a6101b6edc439e9b10233570f47f8aeb846..800e590289aff7db1617eb84eec9adfcb6e8252c 100755 (executable)
@@ -208,8 +208,11 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
                                    Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
 
-  Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection",
-                                   Config_Prop::Double, "0.001");
+  Config_PropManager::registerProp("Visualization", "body_deflection", "Body deflection coefficient",
+                                   Config_Prop::Double, ModelAPI_ResultBody::DEFAULT_DEFLECTION());//"0.001");
+
+  Config_PropManager::registerProp("Visualization", "construction_deflection", "Construction deflection coefficient",
+                                   Config_Prop::Double, ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());//"0.0001");
 
   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
     myViewerSelMode.append(TopAbs_FACE);