+//**************************************************************
+void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
+{
+ AttributeDoublePtr aDoubleAttr;
+ // 1. find the current property of the object. This is a property of AIS presentation
+ // The objects are iterated until a first valid property is found
+ double aCurrentValue = -1;
+ foreach(ObjectPtr anObject, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ 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;
+ }
+ if (aCurrentValue < 0)
+ return;
+
+ if (!abortAllOperations())
+ return;
+
+ // 2. show the dialog to change the value
+ XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
+ aDlg->setWindowTitle("Transparency");
+ 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);
+
+ // 3. abort the previous operation and start a new one
+ SessionPtr aMgr = ModelAPI_Session::get();
+ QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+
+ aDlg->move(QCursor::pos());
+ bool isDone = aDlg->exec() == QDialog::Accepted;
+ if (!isDone)
+ return;
+
+ // 4. set the value to all results
+ aCurrentValue = aTransparencyWidget->getValue();
+ setTransparency(aCurrentValue, theObjects);
+
+ aMgr->finishOperation();
+ updateCommandStatus();
+}
+
+//**************************************************************
+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())
+ return;
+
+ QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+ setTransparency(aTransparencyWidget->getValue(), anObjects);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+