]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2925: Provide transparency for objects presentation
authorvsv <vsv@opencascade.com>
Tue, 18 Jun 2019 14:28:48 +0000 (17:28 +0300)
committervsv <vsv@opencascade.com>
Tue, 18 Jun 2019 14:29:00 +0000 (17:29 +0300)
12 files changed:
src/ModelAPI/ModelAPI_Session.cpp
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/color.png [deleted file]
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_PropertyDialog.cpp
src/XGUI/XGUI_TransparencyWidget.cpp
src/XGUI/XGUI_TransparencyWidget.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/color.png [new file with mode: 0644]

index b085ed52c36efbe6713c1d052bf13a11c751edcb..fb455eb4c0b11d16402de323992f965048c5a0b8 100644 (file)
@@ -80,6 +80,9 @@ std::shared_ptr<ModelAPI_Session> ModelAPI_Session::get()
                                      Config_Prop::Double,
                                      ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
 
+    Config_PropManager::registerProp("Visualization", "default_transparency",
+      "Default transparency", Config_Prop::Double, "0");
+
   }
   return MY_MANAGER;
 }
index 99819d90e0a46189e1330a9a98e6ae6bb5af53a7..98eb992f780647158b987c3ca4bb39f31134a84e 100644 (file)
@@ -2,7 +2,6 @@
  <qresource>
      <file>icons/activate.png</file>
      <file>icons/angle_32x32.png</file>
-     <file>icons/color.png</file>
      <file>icons/concealed_on.png</file>
      <file>icons/concealed_off.png</file>
      <file>icons/deactivate.png</file>
diff --git a/src/PartSet/icons/color.png b/src/PartSet/icons/color.png
deleted file mode 100644 (file)
index 0d43799..0000000
Binary files a/src/PartSet/icons/color.png and /dev/null differ
index 536c1b0d8bdcda75521741ce73af4361c7846bb3..c48b8a8ef7c12ce1525b71662db4351392b2f3bc 100644 (file)
@@ -109,11 +109,9 @@ void XGUI_ContextMenuMgr::createActions()
   aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
   addAction("DEFLECTION_CMD", aAction);
 
-#ifdef USE_TRANSPARENCY
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
                                            tr("Transparency..."), aDesktop);
   addAction("TRANSPARENCY_CMD", aAction);
-#endif
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
   addAction("SHOW_CMD", aAction);
@@ -476,9 +474,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
 
   action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
   action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
-#endif
   #ifdef _DEBUG
     #ifdef TINSPECTOR
       action("TINSPECTOR_VIEW")->setEnabled(true);
@@ -582,10 +578,8 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
   if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
     action("DEFLECTION_CMD")->setEnabled(true);
 
-#ifdef USE_TRANSPARENCY
   if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
     action("TRANSPARENCY_CMD")->setEnabled(true);
-#endif
 
   action("DELETE_CMD")->setEnabled(true);
 }
@@ -618,9 +612,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("RENAME_CMD"));
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   aList.append(action("TRANSPARENCY_CMD"));
-#endif
   aList.append(action("SHOW_FEATURE_CMD"));
   aList.append(mySeparator2);
   aList.append(action("DELETE_CMD"));
@@ -640,9 +632,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("RENAME_CMD"));
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   aList.append(action("TRANSPARENCY_CMD"));
-#endif
   aList.append(action("SHOW_FEATURE_CMD"));
   aList.append(mySeparator3);
   aList.append(action("DELETE_CMD"));
@@ -694,9 +684,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(mySeparator1);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   aList.append(action("TRANSPARENCY_CMD"));
-#endif
   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
   // Result part menu
   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
@@ -711,9 +699,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(mySeparator2);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   aList.append(action("TRANSPARENCY_CMD"));
-#endif
   myViewerMenu[ModelAPI_ResultBody::group()] = aList;
   // Group menu
   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
@@ -755,9 +741,7 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
       //aActions.append(action("MOVE_CMD"));
       aActions.append(action("COLOR_CMD"));
       aActions.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
       aActions.append(action("TRANSPARENCY_CMD"));
-#endif
       aActions.append(action("CLEAN_HISTORY_CMD"));
       aActions.append(action("DELETE_CMD"));
   }
@@ -813,9 +797,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
   aActions.append(action("HIDEALL_CMD"));
   aActions.append(action("COLOR_CMD"));
   aActions.append(action("DEFLECTION_CMD"));
-#ifdef USE_TRANSPARENCY
   aActions.append(action("TRANSPARENCY_CMD"));
-#endif
   theMenu->addActions(aActions);
 
   QMap<int, QAction*> aMenuActions;
index 316d3cd73bf6a5c2d280133ef9457c8361f1f6f3..1ce2a99021150a53dae61bcb45297cde23b35a17 100644 (file)
@@ -135,7 +135,7 @@ double getTransparency(const ResultPtr& theResult)
 
 double getDefaultTransparency(const ResultPtr& theResult)
 {
-  return 0;
+  return Config_PropManager::real("Visualization", "default_transparency");
 }
 
 XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
index 226d73a7d3cfdbadb1480ca70e3ae93a7d874e40..8e872a3d82f345b9285f39e33e935bfd0eb68b9a 100644 (file)
@@ -17,7 +17,8 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <XGUI_PropertyDialog.h>
+#include "XGUI_PropertyDialog.h"
+#include <ModuleBase_Tools.h>
 
 #include <QDialogButtonBox>
 #include <QLabel>
index 0814a34467bff6d4ac195177f8a46a2afb759719..a9283cad61155dba720f308accb30722060d22b8 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <QCheckBox>
 #include <QDoubleSpinBox>
+#include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QSlider>
 XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent, const QString& theLabelText)
   : QWidget(theParent)
 {
-  QHBoxLayout* aLay = new QHBoxLayout(this);
+  QVBoxLayout* aLay = new QVBoxLayout(this);
   aLay->setContentsMargins(0, 0, 0, 0);
 
-  mySpinValue = new QDoubleSpinBox(this);
-  mySpinValue->setRange(0, 1);
-  mySpinValue->setSingleStep(0.1);
-  mySliderValue = new QSlider(Qt::Horizontal, this);
-  mySliderValue->setRange(0, 100);
+  QWidget* aInfoWgt = new QWidget(this);
+  QHBoxLayout* aInfoLay = new QHBoxLayout(aInfoWgt);
+  aInfoLay->setContentsMargins(0, 0, 0, 0);
+
+  aInfoLay->addWidget(new QLabel(tr("Opaque")));
+
+  myValLbl = new QLabel("0%", aInfoWgt);
+  myValLbl->setAlignment(Qt::AlignCenter);
+  aInfoLay->addWidget(myValLbl, 1);
 
-  myPreview = new QCheckBox("Preview", this);
-  myPreview->setChecked(true);
+  aInfoLay->addWidget(new QLabel(tr("Transparent")));
+  aLay->addWidget(aInfoWgt);
 
-  if (!theLabelText.isEmpty())
-    aLay->addWidget(new QLabel(theLabelText, this));
-  aLay->addWidget(mySpinValue);
+  mySliderValue = new QSlider(Qt::Horizontal, this);
+  mySliderValue->setRange(0, 100);
   aLay->addWidget(mySliderValue);
-  aLay->addWidget(myPreview);
 
-  connect(mySpinValue, SIGNAL(valueChanged(double)), this, SLOT(onSpinValueChanged(double)));
   connect(mySliderValue, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
-  connect(myPreview, SIGNAL(toggled(bool)), this, SIGNAL(previewStateChanged()));
 }
 
 void XGUI_TransparencyWidget::setValue(double theValue)
 {
-  bool isSpinBlocked = mySpinValue->blockSignals(true);
   bool isSliderBlocked = mySliderValue->blockSignals(true);
-
-  mySpinValue->setValue(theValue);
-  mySliderValue->setValue(theValue * 100);
-
-  mySpinValue->blockSignals(isSpinBlocked);
+  int aVal = theValue * 100;
+  mySliderValue->setValue(aVal);
+  myValLbl->setText(QString("%1%").arg(aVal));
   mySliderValue->blockSignals(isSliderBlocked);
 }
 
 double XGUI_TransparencyWidget::getValue() const
 {
-  return mySpinValue->value();
-}
-
-bool XGUI_TransparencyWidget::isPreviewNeeded() const
-{
-  return myPreview->isChecked();
-}
-
-void XGUI_TransparencyWidget::onSpinValueChanged(double theValue)
-{
-  setValue(theValue);
-  emit transparencyValueChanged();
+  return mySliderValue->value() / 100.;
 }
 
 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
 {
-  setValue((double)theValue / 100);
+  myValLbl->setText(QString("%1%").arg(theValue));
   emit transparencyValueChanged();
 }
index a3f5b23b0245aed38ea39d34c303d49a2a238d73..8de0d715bfe559f58e3805f113771d6521440d4a 100644 (file)
@@ -24,9 +24,8 @@
 
 #include <QWidget>
 
-class QDoubleSpinBox;
 class QSlider;
-class QCheckBox;
+class QLabel;
 
 /**
 * \ingroup GUI
@@ -52,27 +51,17 @@ public:
   /// \return value
   double getValue() const;
 
-  /// Returns true if the value should be applyed immediatelly
-  /// \return state of preview check control
-  bool isPreviewNeeded() const;
-
 signals:
   void transparencyValueChanged();
-  void previewStateChanged();
 
 private slots:
-  /// Update slider value by spin value
-  /// \param theValue the new spin value
-  void onSpinValueChanged(double theValue);
-
   /// Update spin value by slider value
   /// \param theValue the new slider value
   void onSliderValueChanged(int theValue);
 
 private:
-  QDoubleSpinBox* mySpinValue; /// value control
   QSlider* mySliderValue; /// slider to select value
-  QCheckBox* myPreview; /// do preview immediatelly
+  QLabel* myValLbl;
 };
 
 #endif
index 4bb612a5d48f67d7f6c33675473b85c1c1994221..6a3e370350bec353c9ec482f364bd304b566ca44 100644 (file)
@@ -1571,10 +1571,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     changeColor(aObjects);
   else if (theId == "DEFLECTION_CMD")
     changeDeflection(aObjects);
-#ifdef USE_TRANSPARENCY
   else if (theId == "TRANSPARENCY_CMD")
     changeTransparency(aObjects);
-#endif
   else if (theId == "SHOW_CMD") {
     showObjects(aObjects, true);
     mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
@@ -2201,11 +2199,8 @@ bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
 {
   if (theActionName == "COLOR_CMD" ||
-      theActionName == "DEFLECTION_CMD"
-#ifdef USE_TRANSPARENCY
-      || theActionName == "TRANSPARENCY_CMD"
-#endif
-      ) {
+      theActionName == "DEFLECTION_CMD" ||
+      theActionName == "TRANSPARENCY_CMD") {
     QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
 
     std::set<std::string> aTypes;
@@ -2428,16 +2423,6 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
     if (aResult.get()) {
       aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
     }
-    else {
-      // TODO: remove the obtaining a property from the AIS object
-      // this does not happen never because:
-      // 1. The property can be changed only on results
-      // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
-      AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
-      if (anAISObj.get()) {
-        aCurrentValue = anAISObj->getDeflection();
-      }
-    }
     if (aCurrentValue > 0)
       break;
   }
@@ -2445,7 +2430,7 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
     return;
 
   if (!abortAllOperations())
-  return;
+    return;
 
   // 2. show the dialog to change the value
   XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
@@ -2453,8 +2438,6 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
   XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
   connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
           this, SLOT(onTransparencyValueChanged()));
-  connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
-          this, SLOT(onPreviewStateChanged()));
   aDlg->setContent(aTransparencyWidget);
   aTransparencyWidget->setValue(aCurrentValue);
 
@@ -2463,9 +2446,7 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
   QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
   aMgr->startOperation(aDescription.toStdString());
 
-  aDlg->move(QCursor::pos());
-  bool isDone = aDlg->exec() == QDialog::Accepted;
-  if (!isDone)
+  if (aDlg->exec() != QDialog::Accepted)
     return;
 
   // 4. set the value to all results
@@ -2480,19 +2461,7 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
 void XGUI_Workshop::onTransparencyValueChanged()
 {
   XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
-  if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
-    return;
-
-  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
-  setTransparency(aTransparencyWidget->getValue(), anObjects);
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-}
-
-//**************************************************************
-void XGUI_Workshop::onPreviewStateChanged()
-{
-  XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
-  if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
+  if (!aTransparencyWidget)
     return;
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
index e7da8532dcd743467b9c989041ec890d42d66be9..525d99ae9bb237f525bb5f2fe42b3605fe1a272e 100644 (file)
@@ -409,9 +409,6 @@ signals:
   /// Apply the current transparency value if preview in transparency dialog is switched on
   void onTransparencyValueChanged();
 
-  /// Switch on/off preview of transparency change
-  void onPreviewStateChanged();
-
  protected:
   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
   /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
index c499b468f6c8a9b97441fb0f79326ad51ed55565..4520529f1d7589cc97492240e2d63ce8e59c722e 100644 (file)
@@ -83,5 +83,6 @@
      <file>pictures/arrow-up.png</file>
      <file>pictures/arrow-down.png</file>
      <file>pictures/configure_toolbars.png</file>
+     <file>pictures/color.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/color.png b/src/XGUI/pictures/color.png
new file mode 100644 (file)
index 0000000..0d43799
Binary files /dev/null and b/src/XGUI/pictures/color.png differ