Salome HOME
Issue #3140: Add show/hide Isos menu item.
authorvsv <vsv@opencascade.com>
Fri, 14 Feb 2020 14:00:38 +0000 (17:00 +0300)
committervsv <vsv@opencascade.com>
Fri, 14 Feb 2020 14:00:38 +0000 (17:00 +0300)
src/Model/Model_Data.cpp
src/ModelAPI/ModelAPI_Result.cpp
src/ModelAPI/ModelAPI_Result.h
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_msg_fr.ts

index ecafd0c205aa3ba99940aa7c8651440c12127d6f..7995c85fde2b441764e25ddc9332c1f3f19ac640 100644 (file)
@@ -438,7 +438,7 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     // trim: need to redisplay or set color in the python script
     if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" ||
       theAttr->id() == "Transparency" || theAttr->id() == "Deflection" ||
-      theAttr->id() == "Iso_lines")) {
+      theAttr->id() == "Iso_lines" || theAttr->id() == "Show_Iso_lines")) {
       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
       ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
     }
index b3d3dc574a5731da280aa7f220bdbff995d8d04a..32d04da6bc450a44c15bf0ee0eec3319066aab62 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
 
 #include <Events_Loop.h>
 
@@ -38,6 +39,7 @@ void ModelAPI_Result::initAttributes()
   aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
   aData->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
   aData->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false);
+  aData->addAttribute(SHOW_ISO_LINES_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
 }
 
 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
index a53c1e04fd8b4fdce4811494a1a6fb0bad0d96dd..f242ce3d300a0acdd5fa6f358de29fd52b309a20 100644 (file)
@@ -71,6 +71,14 @@ class ModelAPI_Result : public ModelAPI_Object
     return MY_ISO_LINES_ID;
   }
 
+  /// Reference to the transparency of the result.
+  /// The double value is used. The value is in [0, 1] range
+  inline static const std::string& SHOW_ISO_LINES_ID()
+  {
+    static const std::string MY_SHOW_ISO_LINES_ID("Show_Iso_lines");
+    return MY_SHOW_ISO_LINES_ID;
+  }
+
   /// Returns true if the result is concealed from the data tree (referenced by other objects)
   MODELAPI_EXPORT virtual bool isConcealed();
 
index 0c312f3955c162af9e8bbc0ddeb993efa422d02e..64c47797219a3e20d51df9d06354d968168aa7d9 100644 (file)
@@ -31,6 +31,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeBoolean.h>
 #include <list>
 #include <map>
 #include <iostream>
@@ -850,23 +851,31 @@ void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int
 }
 
 //******************************************************
-void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int>& theNbLines)
+void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
+  bool& isVisible, std::vector<int>& theNbLines)
 {
   theNbLines.clear();
+  isVisible = false;
+  if (!theResult.get())
+    return;
   if (theResult->groupName() == ModelAPI_ResultConstruction::group()) {
     theNbLines.push_back(0);
     theNbLines.push_back(0);
   }
   else {
     // get color from the attribute of the result
-    if (theResult.get() != NULL &&
-      theResult->data()->attribute(ModelAPI_Result::ISO_LINES_ID()).get() != NULL) {
-      AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
-      if (aAttr.get() && aAttr->size()) {
+    AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
+    if (aAttr.get()) {
+      if (aAttr->size()) {
         theNbLines.push_back(aAttr->value(0));
         theNbLines.push_back(aAttr->value(1));
       }
     }
+    AttributeBooleanPtr aBoolAttr =
+      theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID());
+    if (aBoolAttr.get()) {
+      isVisible = aBoolAttr->value();
+    }
   }
 }
 
@@ -886,6 +895,31 @@ void setIsoLines(ResultPtr theResult, const std::vector<int>& theIso)
   }
 }
 
+//******************************************************
+void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeBooleanPtr aAttr = theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID());
+  if (aAttr.get() != NULL) {
+    aAttr->setValue(theShow);
+  }
+}
+
+//******************************************************
+bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult)
+{
+  if (!theResult.get())
+    return false;
+
+  AttributeBooleanPtr aAttr = theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID());
+  if (aAttr.get() != NULL) {
+    return aAttr->value();
+  }
+  return false;
+}
+
 //**************************************************************
 void setTransparency(ResultPtr theResult, double theTransparency)
 {
index f9502dc823ca62cf1546ca1f12abde88afa19ff8..e34b8aa6cbfaca9a1538b1a20f17e807df6c6332 100644 (file)
@@ -242,7 +242,7 @@ MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
 * \param[out] theNbLines values of iso-lines
 */
 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
-  std::vector<int>& theNbLines);
+  bool& isVisible, std::vector<int>& theNbLines);
 
 /*! Set number of iso-lines of the result
 * \param[in] theResult a result object
@@ -251,6 +251,14 @@ MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResu
 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
   const std::vector<int>& theIso);
 
+/*! Set visibility of Iso lines
+* \param[in] theResult a result object
+* \param[in] theShow is a visibility flag
+*/
+MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
+
+MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
+
 /*! Returns current transparency in the given result
 * \param theResult a result object
 * \return a transparency value or -1 if it was not defined
index 5fb170087ad61bfb8dd7d0603edb859ba8d49f5a..f94b65780416ef08c19eb73621c68de7733dc6b5 100644 (file)
@@ -88,10 +88,17 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   Color(aColor);
 
   std::vector<int> aIsoValues;
-  ModelAPI_Tools::getIsoLines(myResult, aIsoValues);
-  if (aIsoValues.size() == 0) {
-    aIsoValues.push_back(1);
-    aIsoValues.push_back(1);
+  bool isIsoVisible;
+  ModelAPI_Tools::getIsoLines(myResult, isIsoVisible, aIsoValues);
+  if (isIsoVisible) {
+    if (aIsoValues.size() == 0) {
+      aIsoValues.push_back(1);
+      aIsoValues.push_back(1);
+    }
+  }
+  else {
+    aIsoValues.push_back(0);
+    aIsoValues.push_back(0);
   }
   myUIsoAspect = new Prs3d_IsoAspect(aColor, Aspect_TOL_SOLID, 1, aIsoValues[0]);
   myVIsoAspect = new Prs3d_IsoAspect(aColor, Aspect_TOL_SOLID, 1, aIsoValues[1]);
@@ -469,3 +476,30 @@ void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_Presentatio
       thePM->AddToImmediateList(aHilightPrs);
   }
 }
+
+
+//********************************************************************
+void ModuleBase_ResultPrs::updateIsoLines()
+{
+  std::vector<int> aIsoValues;
+  bool isIsoVisible;
+  ModelAPI_Tools::getIsoLines(myResult, isIsoVisible, aIsoValues);
+  if (isIsoVisible) {
+    if (aIsoValues.size() == 0) {
+      aIsoValues.push_back(1);
+      aIsoValues.push_back(1);
+    }
+  }
+  else {
+    if (aIsoValues.size() == 0) {
+      aIsoValues.push_back(0);
+      aIsoValues.push_back(0);
+    }
+    else {
+      aIsoValues[0] = 0;
+      aIsoValues[1] = 0;
+    }
+  }
+  myUIsoAspect->SetNumber(aIsoValues[0]);
+  myVIsoAspect->SetNumber(aIsoValues[1]);
+}
index a93089e98dbca8b8c5e09686d4e5469410747554..a1f40f9fedd134a65a3c322734281f9d96ca3714 100644 (file)
@@ -119,22 +119,7 @@ public:
   /// Returns True if the original shape is substituted by a corresponded shell
   Standard_EXPORT bool isSubstituted() const { return myIsSubstituted; }
 
-  /// Set number of Iso-lines
-  /// \param theU a number of U Iso-lines
-  /// \param theV a number of V Iso-lines
-  Standard_EXPORT void setIsolinesNumber(int theU, int theV) {
-    myUIsoAspect->SetNumber(theU); myVIsoAspect->SetNumber(theV);
-  }
-
-  /// Returns number of U Iso-lines
-  Standard_EXPORT int UIsoLines() const {
-    return myUIsoAspect->Number();
-  }
-
-  /// Returns number of V Iso-lines
-  Standard_EXPORT int VIsoLines() const {
-    return myVIsoAspect->Number();
-  }
+  Standard_EXPORT void updateIsoLines();
 
   DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape)
 
index 3c5146ffcfaffd7f49285e134e6a20363b00bbc8..c36f9cef5bec48b891b07ae90d3f22ed7819654c 100644 (file)
@@ -140,10 +140,14 @@ void XGUI_ContextMenuMgr::createActions()
                                            aDesktop);
   addAction("WIREFRAME_CMD", aAction);
 
-  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Iso-lines..."),
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
                                            aDesktop);
   addAction("ISOLINES_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos..."), aDesktop);
+  aAction->setCheckable(true);
+  addAction("SHOW_ISOLINES_CMD", aAction);
+
   mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
   mySeparator1->setSeparator(true);
 
@@ -306,22 +310,25 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
     //Process Feature
     if (aSelected == 1) { // single selection
       ObjectPtr aObject = aObjects.first();
+      ResultPtr aResult;
+      if (hasResult)
+        aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
       if (aObject) {
         if (hasResult && myWorkshop->canBeShaded(aObject)) {
           XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
           if (aMode != XGUI_Displayer::NoMode) {
             action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
             action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
-            action("ISOLINES_CMD")->setEnabled(true);
           } else {
             action("WIREFRAME_CMD")->setEnabled(true);
             action("SHADING_CMD")->setEnabled(true);
-            action("ISOLINES_CMD")->setEnabled(true);
           }
+          action("SHOW_ISOLINES_CMD")->setEnabled(true);
+          action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
+          action("ISOLINES_CMD")->setEnabled(true);
         }
         if (!hasFeature) {
-          bool aHasSubResults = ModelAPI_Tools::hasSubResults(
-                                            std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
+          bool aHasSubResults = ModelAPI_Tools::hasSubResults(aResult);
           if (aHasSubResults) {
             action("HIDE_CMD")->setEnabled(true);
             action("SHOW_CMD")->setEnabled(true);
@@ -358,6 +365,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
         action("SHOW_ONLY_CMD")->setEnabled(true);
         action("SHADING_CMD")->setEnabled(true);
         action("WIREFRAME_CMD")->setEnabled(true);
+        action("SHOW_ISOLINES_CMD")->setEnabled(false);
         action("ISOLINES_CMD")->setEnabled(true);
       }
       if (hasFeature && myWorkshop->canMoveFeature()) {
@@ -544,11 +552,18 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
         if (aMode != XGUI_Displayer::NoMode) {
           action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
           action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
-          action("ISOLINES_CMD")->setEnabled(true);
         } else {
           action("WIREFRAME_CMD")->setEnabled(true);
           action("SHADING_CMD")->setEnabled(true);
-          action("ISOLINES_CMD")->setEnabled(true);
+        }
+        action("ISOLINES_CMD")->setEnabled(true);
+
+        if (aPrsList.size() == 1) {
+          ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+          if (aResult.get()) {
+            action("SHOW_ISOLINES_CMD")->setEnabled(true);
+            action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
+          }
         }
       }
       action("SHOW_ONLY_CMD")->setEnabled(true);
@@ -664,6 +679,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(action("SHOW_ISOLINES_CMD"));
   aList.append(action("ISOLINES_CMD"));
   aList.append(action("SHOW_FEATURE_CMD"));
   aList.append(mySeparator3);
@@ -740,6 +756,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(action("SHOW_ISOLINES_CMD"));
   aList.append(action("ISOLINES_CMD"));
   aList.append(mySeparator3);
   aList.append(action("SET_VIEW_NORMAL_CMD"));
@@ -794,6 +811,7 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
       aActions.append(action("COLOR_CMD"));
       aActions.append(action("DEFLECTION_CMD"));
       aActions.append(action("TRANSPARENCY_CMD"));
+      aActions.append(action("SHOW_ISOLINES_CMD"));
       aActions.append(action("ISOLINES_CMD"));
       aActions.append(action("CLEAN_HISTORY_CMD"));
       aActions.append(action("DELETE_CMD"));
index da590b502d1aee301e32b733e4464c46b66ab039..00360a96defc2743b9c8edb97c976c1f76507aaa 100644 (file)
@@ -316,13 +316,9 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
         aAISObj->setTransparency(aTransparency);
 
       // Set Iso-Lines
-      std::vector<int> aIsoValues;
-      ModelAPI_Tools::getIsoLines(aResult, aIsoValues);
-      if (aIsoValues.size() > 0) {
-        Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO);
-        if (!aResPrs.IsNull())
-          aResPrs->setIsolinesNumber(aIsoValues[0], aIsoValues[1]);
-      }
+      Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO);
+      if (!aResPrs.IsNull())
+        aResPrs->updateIsoLines();
     }
     myWorkshop->module()->storeSelection();
 
index ac03c11b233e6c6b352e23bbc15a4864288b232d..c2d44a802fdb9c12bcda36c9bebccae28005effb 100644 (file)
@@ -1698,6 +1698,15 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     changeColor(aObjects);
   else if (theId == "ISOLINES_CMD")
     changeIsoLines(aObjects);
+  else if (theId == "SHOW_ISOLINES_CMD") {
+    foreach(ObjectPtr aObj, aObjects) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+      if (aResult.get())
+        ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult));
+    }
+    mySelector->clearSelection();
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  }
   else if (theId == "DEFLECTION_CMD")
     changeDeflection(aObjects);
   else if (theId == "TRANSPARENCY_CMD")
@@ -3186,10 +3195,11 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
     return;
 
   std::vector<int> aValues;
+  bool isVisible;
   if (theObjects.size() == 1) {
     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObjects.first());
     if (aRes.get())
-      ModelAPI_Tools::getIsoLines(aRes, aValues);
+      ModelAPI_Tools::getIsoLines(aRes, isVisible, aValues);
     else
       return;
   }
@@ -3233,6 +3243,7 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects)
         ModelAPI_Tools::setIsoLines(aRes, aValues);
       }
     }
+    mySelector->clearSelection();
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
     aMgr->finishOperation();
     updateCommandStatus();
index 666c304585009f6888dc79de39ba9872133a9b77..270adced61a4e837f85effc7226b2349ed546eb9 100644 (file)
     </message>
     <message>
         <source>Iso-lines...</source>
-        <translation>Iso-lines...</translation>
+        <translation type="vanished">Iso-lines...</translation>
+    </message>
+    <message>
+        <source>Define Isos...</source>
+        <translation>Définir l&apos;Isos...</translation>
+    </message>
+    <message>
+        <source>Show Isos...</source>
+        <translation>Show Isos...</translation>
     </message>
 </context>
 <context>