From 6187cf508a2e62a3f87dd97c057afa8f6e1451c0 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 18 Jun 2019 17:28:48 +0300 Subject: [PATCH] Issue #2925: Provide transparency for objects presentation --- src/ModelAPI/ModelAPI_Session.cpp | 3 + src/PartSet/PartSet_icons.qrc | 1 - src/XGUI/XGUI_ContextMenuMgr.cpp | 18 ------ src/XGUI/XGUI_CustomPrs.cpp | 2 +- src/XGUI/XGUI_PropertyDialog.cpp | 3 +- src/XGUI/XGUI_TransparencyWidget.cpp | 53 +++++++----------- src/XGUI/XGUI_TransparencyWidget.h | 15 +---- src/XGUI/XGUI_Workshop.cpp | 41 ++------------ src/XGUI/XGUI_Workshop.h | 3 - src/XGUI/XGUI_pictures.qrc | 1 + .../icons => XGUI/pictures}/color.png | Bin 11 files changed, 34 insertions(+), 106 deletions(-) rename src/{PartSet/icons => XGUI/pictures}/color.png (100%) diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp index b085ed52c..fb455eb4c 100644 --- a/src/ModelAPI/ModelAPI_Session.cpp +++ b/src/ModelAPI/ModelAPI_Session.cpp @@ -80,6 +80,9 @@ std::shared_ptr 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; } diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 99819d90e..98eb992f7 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -2,7 +2,6 @@ icons/activate.png icons/angle_32x32.png - icons/color.png icons/concealed_on.png icons/concealed_off.png icons/deactivate.png diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 536c1b0d8..c48b8a8ef 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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 aMenuActions; diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 316d3cd73..1ce2a9902 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -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) diff --git a/src/XGUI/XGUI_PropertyDialog.cpp b/src/XGUI/XGUI_PropertyDialog.cpp index 226d73a7d..8e872a3d8 100644 --- a/src/XGUI/XGUI_PropertyDialog.cpp +++ b/src/XGUI/XGUI_PropertyDialog.cpp @@ -17,7 +17,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include +#include "XGUI_PropertyDialog.h" +#include #include #include diff --git a/src/XGUI/XGUI_TransparencyWidget.cpp b/src/XGUI/XGUI_TransparencyWidget.cpp index 0814a3446..a9283cad6 100644 --- a/src/XGUI/XGUI_TransparencyWidget.cpp +++ b/src/XGUI/XGUI_TransparencyWidget.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -28,59 +29,45 @@ 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(); } diff --git a/src/XGUI/XGUI_TransparencyWidget.h b/src/XGUI/XGUI_TransparencyWidget.h index a3f5b23b0..8de0d715b 100644 --- a/src/XGUI/XGUI_TransparencyWidget.h +++ b/src/XGUI/XGUI_TransparencyWidget.h @@ -24,9 +24,8 @@ #include -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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4bb612a5d..6a3e37035 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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 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(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index e7da8532d..525d99ae9 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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. diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index c499b468f..4520529f1 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -83,5 +83,6 @@ pictures/arrow-up.png pictures/arrow-down.png pictures/configure_toolbars.png + pictures/color.png diff --git a/src/PartSet/icons/color.png b/src/XGUI/pictures/color.png similarity index 100% rename from src/PartSet/icons/color.png rename to src/XGUI/pictures/color.png -- 2.39.2