Salome HOME
Issue #18398(Tuleap): Restore visual properties change functionality
authorvsv <vsv@opencascade.com>
Wed, 4 Dec 2019 08:59:03 +0000 (11:59 +0300)
committervsv <vsv@opencascade.com>
Wed, 4 Dec 2019 08:59:29 +0000 (11:59 +0300)
src/Model/Model_Data.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_FacesPanel.cpp
src/XGUI/XGUI_FacesPanel.h
src/XGUI/XGUI_Workshop.cpp

index 45798a12fc36a93d98911e2e3cc0cfa6b8c0a38f..e5641930e1b1253ab05e0a83f5afbd1ab8c34137 100644 (file)
@@ -431,7 +431,8 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     }
   } else {
     // trim: need to redisplay or set color in the python script
-    if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color")) {
+    if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" ||
+      theAttr->id() == "Transparency" || theAttr->id() == "Deflection")) {
       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
       ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
     }
index fd4fae9d704fb2c1ff00116a3f0ea9642a3c995d..d793a0501e2599d8fb5b71ff154bb5f3f144a788 100644 (file)
@@ -293,45 +293,30 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
   }
 
   if (!aAISIO.IsNull()) {
-    // Check that the visualized shape is the same and the redisplay is not necessary
-    // Redisplay of AIS object leads to this object selection compute and the selection
-    // in the browser is lost
-    // this check is not necessary anymore because the selection store/restore is realized
-    // before and after the values modification.
-    // Moreother, this check avoids customize and redisplay presentation if the presentable
-    // parameter is changed.
-    //bool isEqualShapes = false;
-    //ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    //if (aResult.get() != NULL) {
-    //  Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
-    //  if (!aShapePrs.IsNull()) {
-    //    std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-    //    if (aShapePtr.get()) {
-    //      const TopoDS_Shape& aOldShape = aShapePrs->Shape();
-    //      if (!aOldShape.IsNull())
-    //        isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
-    //    }
-    //  }
-    //}
-    // Customization of presentation
-    //bool isCustomized = customizeObject(theObject);
-    #ifdef DEBUG_FEATURE_REDISPLAY
-      qDebug(QString("Redisplay: %1, isEqualShapes=%2").
-        arg(!isEqualShapes/* || isCustomized*/).arg(isEqualShapes)
-        .toStdString().c_str());
-    #endif
-    //if (!isEqualShapes/* || isCustomized*/) {
-    //  /// if shapes are equal and presentation are customized, selection should be restored
-    //  bool aNeedToRestoreSelection = isEqualShapes/* && isCustomized*/;
-    //  if (aNeedToRestoreSelection)
-      if (aAISObj.get() && myWorkshop->facesPanel())
-        myWorkshop->facesPanel()->customizeObject(theObject, aAISObj);
-
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aResult.get()) {
+      // Set color
+      std::vector<int> aColor;
+      ModelAPI_Tools::getColor(aResult, aColor);
+      if (aColor.size() > 0) {
+        aAISIO->SetColor(Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB));
+      }
+      // Set deflection
+      double aDeflection = ModelAPI_Tools::getDeflection(aResult);
+      if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection()))
+        aAISObj->setDeflection(aDeflection);
+
+      // Set transparency
+      double aTransparency = ModelAPI_Tools::getTransparency(aResult);
+      if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency()))
+        aAISObj->setTransparency(aTransparency);
+    }
     myWorkshop->module()->storeSelection();
 
 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
     myWorkshop->selector()->deselectPresentation(aAISIO);
 #endif
+
     if (aContext->IsDisplayed(aAISIO))
       aContext->Redisplay(aAISIO, false);
     else {
index 28a35884cae02eeadc21c594ddc2d29d952ee136..f79eb6dbafb25c03de80c90fc8dbd9a68df0a804 100644 (file)
@@ -529,13 +529,6 @@ void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent)
   emit closed();
 }
 
-//********************************************************************
-bool XGUI_FacesPanel::customizeObject(const ObjectPtr& theObject,
-  const AISObjectPtr& thePresentation)
-{
-  return myItems.size() > 0;
-}
-
 //********************************************************************
 void XGUI_FacesPanel::onDeleteItem()
 {
index 68a3ce53bd71b7be1b39341eb9648767052f85d7..d442ee6b87f174b51cfc1a7e0f138f9f882fbfd8 100644 (file)
@@ -122,18 +122,6 @@ public:
   /// \param theEvent an event
   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
 
-  /// Hide/show faces of the object if:
-  /// - face selector is active
-  /// - object is mentioned in the list of selected elements
-  /// If the object is displayed, all panel faces selected on it will be moved into presentation
-  /// or, if redisplayed, fuction return if the object should be redisplayed or not
-  /// \param theObject a customized object
-  /// \param thePresentation visualized presentation of the object
-  /// \return true if the presentation is customized
-  bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject,
-    const std::shared_ptr<GeomAPI_AISObject>& thePresentation);
-
-
   XGUI_Workshop* workshop() const { return myWorkshop; }
 
 
index fcee5e38ad8f2cfd77b6046f1885e560bc77bd74..75c1a932fcc1fa29dab87119ee74ef244f415a21 100644 (file)
@@ -91,6 +91,7 @@
 #include <ExchangePlugin_ImportPart.h>
 
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_IViewer.h>
@@ -2334,9 +2335,28 @@ void setColor(ResultPtr theResult, const std::vector<int>& theColor)
     aColorAttr->setValue(1, theColor[1]);
     aColorAttr->setValue(2, theColor[2]);
   }
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+}
+
+//**************************************************************
+void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+  std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get default color from the preferences manager for the given result
+  if (theColor.empty()) {
+    std::string aSection, aName, aDefault;
+    theObject->colorConfigInfo(aSection, aName, aDefault);
+    if (!aSection.empty() && !aName.empty()) {
+      theColor = Config_PropManager::color(aSection, aName);
+    }
+  }
+  if (!isEmptyColorValid && theColor.empty()) {
+    // all AIS objects, where the color is not set, are in black.
+    // The color should be defined in XML or set in the attribute
+    theColor = Config_PropManager::color("Visualization", "object_default_color");
+    Events_InfoMessage("XGUI_CustomPrs",
+      "A default color is not defined in the preferences for this kind of result").send();
+  }
 }
 
 //**************************************************************
@@ -2351,6 +2371,8 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       ModelAPI_Tools::getColor(aResult, aColor);
+      if (aColor.empty())
+        getDefaultColor(aResult, false, aColor);
     }
     else {
       // TODO: remove the obtaining a color from the AIS object
@@ -2402,8 +2424,10 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
       setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
+  myViewerProxy->update();
 }
 
 //**************************************************************
@@ -2413,11 +2437,9 @@ void setDeflection(ResultPtr theResult, const double theDeflection)
     return;
 
   AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
-  if (aDeflectionAttr.get() != NULL)
+  if (aDeflectionAttr.get() != NULL) {
     aDeflectionAttr->setValue(theDeflection);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  }
 }
 
 //**************************************************************
@@ -2427,11 +2449,9 @@ void setTransparency(ResultPtr theResult, double theTransparency)
     return;
 
   AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
-  if (anAttribute.get() != NULL)
+  if (anAttribute.get() != NULL) {
     anAttribute->setValue(theTransparency);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  }
 }
 
 //**************************************************************
@@ -2444,7 +2464,8 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
       if (aBodyResult.get() != NULL) { // change property for all sub-solids
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
-        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+        std::list<ResultPtr>::iterator aRes;
+        for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
           setTransparency(*aRes, theTransparency);
         }
       }
@@ -2453,6 +2474,34 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
   }
 }
 
+//**************************************************************
+double getDefaultDeflection(const ObjectPtr& theObject)
+{
+  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");
+    else
+      aDeflection = Config_PropManager::real("Visualization", "body_deflection");
+  }
+  return aDeflection;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
 {
@@ -2464,6 +2513,8 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       aDeflection = ModelAPI_Tools::getDeflection(aResult);
+      if (aDeflection < 0)
+        aDeflection = getDefaultDeflection(aResult);
     }
     else {
       // TODO: remove the obtaining a property from the AIS object
@@ -2512,10 +2563,17 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
       setDeflection(aResult, aDeflection);
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
 }
 
+//**************************************************************
+double getDefaultTransparency(const ResultPtr& theResult)
+{
+  return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
 {
@@ -2527,6 +2585,8 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
+      if (aCurrentValue < 0)
+        aCurrentValue = getDefaultTransparency(aResult);
     }
     if (aCurrentValue > 0)
       break;
@@ -2573,7 +2633,11 @@ void XGUI_Workshop::onTransparencyValueChanged()
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   setTransparency(aTransparencyWidget->getValue(), anObjects);
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  static const Events_ID kRedisplayEvent =
+    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  Events_Loop::loop()->flush(kRedisplayEvent);
+
+  myViewerProxy->update();
 }