Salome HOME
Draft of transparency
authornds <nds@opencascade.com>
Tue, 31 Oct 2017 12:18:03 +0000 (15:18 +0300)
committernds <nds@opencascade.com>
Tue, 31 Oct 2017 12:18:03 +0000 (15:18 +0300)
21 files changed:
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/Model/Model_ResultPart.cpp
src/ModelAPI/ModelAPI_Result.cpp
src/ModelAPI/ModelAPI_Result.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_CustomPrs.h
src/XGUI/XGUI_PropertyDialog.cpp [new file with mode: 0644]
src/XGUI/XGUI_PropertyDialog.h [new file with mode: 0644]
src/XGUI/XGUI_TransparencyWidget.cpp [new file with mode: 0644]
src/XGUI/XGUI_TransparencyWidget.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/transparency.png [new file with mode: 0644]

index f25ab2e7c22311da4825cbd08aebd9692c2d0cda..a94c7b4255f3c6a289a233030f82d7d8ce1326d9 100644 (file)
@@ -428,6 +428,39 @@ double GeomAPI_AISObject::getDeflection() const
   return aDeflection;
 }
 
+bool GeomAPI_AISObject::setTransparency(const double theTransparency)
+{
+  bool isModified = false;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!anAISShape.IsNull()) {
+      Standard_Real aPreviousValue = anAISShape->Transparency();
+      if (fabs(aPreviousValue - theTransparency) > Precision::Confusion()) {
+        anAISShape->SetTransparency(theTransparency);
+        //>SetOwnDeviationCoefficient(theTransparency);
+        isModified = true;
+        // redisplay is necessary here to update presentation in all modes
+        // Standard True flag. Displayer uses Standard False flag. If it will be changed in
+        // displayer, redisplay here will not be necessary. But performance should be checked.
+        anAISShape->Redisplay(Standard_True);
+      }
+    }
+  }
+  return isModified;
+}
+
+double GeomAPI_AISObject::getTransparency() const
+{
+  double aTransparency = 0;
+
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    aTransparency = anAIS->Transparency();
+  }
+  return aTransparency;
+}
+
 
 bool GeomAPI_AISObject::empty() const
 {
index 5a4cd78e98bc30304d48eab3c85c828d5a4572d9..54c6840b2197707f2e1883c2b920ab93486c7c38 100644 (file)
@@ -148,6 +148,18 @@ class GeomAPI_AISObject : public GeomAPI_Interface
   GEOMAPI_EXPORT
   double getDeflection() const;
 
+  /** \brief Assigns the transparency to the shape
+   *  \param[in] theTransparency value of transparency
+   */
+  GEOMAPI_EXPORT
+  bool setTransparency(const double theTransparency);
+
+  /** \brief Returns deflection for the shape
+   *  \return double value
+   */
+  GEOMAPI_EXPORT
+  double getTransparency() const;
+
   /// \return Current width of the lines of shape
   GEOMAPI_EXPORT
   double width();
index ddac1acb2a1099999b4d4ce7e31f281b7e5ac011..255f5e3802ce81352513e45182dd92b5dad70178 100644 (file)
@@ -54,6 +54,7 @@ void Model_ResultPart::initAttributes()
   data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
   data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId());
   data()->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId());
 
   if (aDocRef->isInitialized() && // initialized immideately means already exist and will be loaded
       !Model_Application::getApplication()->hasDocument(aDocRef->docId()))
index 6569136a672e789abffecc1f4441154fcd0ccae6..4aac574bf7b69ead9335ebb8b6a25f46892abdc9 100644 (file)
@@ -37,6 +37,7 @@ void ModelAPI_Result::initAttributes()
   DataPtr aData = data();
   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
   aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
+  aData->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId());
 }
 
 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
index 5036b12fba5ea2ff73721394a299dbb5531c9baa..c418e7ac70c85286387f7b407f6d17f24089cbb9 100644 (file)
@@ -49,13 +49,21 @@ class ModelAPI_Result : public ModelAPI_Object
   }
 
   /// Reference to the deflection of the result.
-  /// The double value is used. The values is in [0, 1] range
+  /// The double value is used. The value is in [0, 1] range
   inline static const std::string& DEFLECTION_ID()
   {
     static const std::string MY_DEFLECTION_ID("Deflection");
     return MY_DEFLECTION_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& TRANSPARENCY_ID()
+  {
+    static const std::string MY_TRANSPARENCY_ID("Transparency");
+    return MY_TRANSPARENCY_ID;
+  }
+
   /// Returns true if the result is concealed from the data tree (referenced by other objects)
   MODELAPI_EXPORT virtual bool isConcealed();
 
index c005e37f024c72b879ab113212078447dcae4955..ba329d412e4b3783596f73ed44c772cf372cff4c 100644 (file)
@@ -474,6 +474,15 @@ void ModelHighAPI_Dumper::dumpEntitySetName()
         myDumpBuffer << ".setDeflection(" << aDeflectionAttr->value() << ")" << std::endl;
       }
     }
+    // set result transparency
+    if (!isDefaultTransparency(*aResIt)) {
+      AttributeDoublePtr aTransparencyAttr =
+        (*aResIt)->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+      if(aTransparencyAttr.get() && aTransparencyAttr->isInitialized()) {
+        *this << *aResIt;
+        myDumpBuffer << ".setTransparency(" << aTransparencyAttr->value() << ")" << std::endl;
+      }
+    }
   }
 
   myNames[aLastDumped.myEntity].myIsDumped = true;
@@ -534,6 +543,15 @@ bool ModelHighAPI_Dumper::isDefaultDeflection(const ResultPtr& theResult) const
   return fabs(aCurrent - aDefault) < 1.e-12;
 }
 
+bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) const
+{
+  AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+  if(!anAttribute || !anAttribute->isInitialized()) {
+    return true;
+  }
+  return fabs(anAttribute->value()) < 1.e-12;
+}
+
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
 {
   myDumpBuffer << theChar;
@@ -674,7 +692,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity
     std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
     for (; aResIt != aResults.end(); ++aResIt) {
       if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt) ||
-          !isDefaultDeflection(*aResIt))
+          !isDefaultDeflection(*aResIt) || !isDefaultTransparency(*aResIt))
         aResultsWithNameOrColor.push_back(*aResIt);
 
       ResultCompSolidPtr aCompSolid =
@@ -684,7 +702,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity
         for (int i = 0; i < aNbSubs; ++i) {
           ResultPtr aCurRes = aCompSolid->subResult(i);
           if (!myNames[aCurRes].myIsDefault || !isDefaultColor(aCurRes) ||
-              !isDefaultDeflection(aCurRes))
+              !isDefaultDeflection(aCurRes) || !isDefaultTransparency(aCurRes))
             aResultsWithNameOrColor.push_back(aCurRes);
         }
       }
index b9478e61c2c00321c44acf6730943678c62adde0..c2fe0cd54de1bb6734d24f182989a7007e7ac565 100644 (file)
@@ -278,6 +278,9 @@ private:
   /// Check the result feature has default deflection
   bool isDefaultDeflection(const ResultPtr& theResult) const;
 
+  /// Check the result feature has default transparency
+  bool isDefaultTransparency(const ResultPtr& theResult) const;
+
 private:
   struct EntityName {
     std::string myCurrentName; ///< default name of current feature
index 60017e8cc972e35af3e319f019f6d01744058b4b..0eb6c78c27b23106dae089b83f34bd8220b8569c 100644 (file)
@@ -155,6 +155,17 @@ void ModelHighAPI_Selection::setDeflection(double theValue)
   aDeflectionAttr->setValue(theValue);
 }
 
+void ModelHighAPI_Selection::setTransparency(double theValue)
+{
+  if (myVariantType != VT_ResultSubShapePair)
+    return;
+
+  AttributeDoublePtr aTransparencyAttr =
+    myResultSubShapePair.first->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+
+  aTransparencyAttr->setValue(theValue);
+}
+
 int ModelHighAPI_Selection::numberOfSubs() const
 {
   if (myVariantType != VT_ResultSubShapePair)
index c89b414fb8fe56c33cf750c97c596bbba6806c12..1aa1788e862cf813b14edfe0ac79324979939922 100644 (file)
@@ -104,6 +104,10 @@ public:
   MODELHIGHAPI_EXPORT
   void setDeflection(double theValue);
 
+  /// Change result's transparency
+  MODELHIGHAPI_EXPORT
+  void setTransparency(double theValue);
+
   /// Returns the number of sub-elements.
   MODELHIGHAPI_EXPORT
   int numberOfSubs() const;
index 1bc373d68798e5fb488e122c1bef4ce13db68f87..9663e386aaa7d07f0f1d15f9ebc2b3e4511d3881 100644 (file)
@@ -44,12 +44,14 @@ SET(PROJECT_HEADERS
     XGUI_ModuleConnector.h
     XGUI_ObjectsBrowser.h
     XGUI_OperationMgr.h
+    XGUI_PropertyDialog.h
     XGUI_PropertyPanel.h
     XGUI_QtEvents.h
     XGUI_SalomeConnector.h
     XGUI_Selection.h
     XGUI_SelectionMgr.h
     XGUI_Tools.h
+    XGUI_TransparencyWidget.h
     XGUI_ViewerProxy.h
     XGUI_Workshop.h
     XGUI_WorkshopListener.h
@@ -68,8 +70,10 @@ SET(PROJECT_MOC_HEADERS
     XGUI_ModuleConnector.h
     XGUI_ObjectsBrowser.h
     XGUI_OperationMgr.h
+    XGUI_PropertyDialog.h
     XGUI_PropertyPanel.h
     XGUI_SelectionMgr.h
+    XGUI_TransparencyWidget.h
     XGUI_ViewerProxy.h
     XGUI_Workshop.h
     XGUI_WorkshopListener.h
@@ -95,12 +99,14 @@ SET(PROJECT_SOURCES
     XGUI_ModuleConnector.cpp
     XGUI_ObjectsBrowser.cpp
     XGUI_OperationMgr.cpp
+    XGUI_PropertyDialog.cpp
     XGUI_PropertyPanel.cpp
     XGUI_QtEvents.cpp
     XGUI_SalomeConnector.cpp
     XGUI_Selection.cpp
     XGUI_SelectionMgr.cpp
     XGUI_Tools.cpp
+    XGUI_TransparencyWidget.cpp
     XGUI_ViewerProxy.cpp
     XGUI_Workshop.cpp
     XGUI_WorkshopListener.cpp
index d0ee1667c6196630a1f434424ef9febada2dfc60..1a986b377ff86155065408fccb672b9f0b999a34 100644 (file)
@@ -107,6 +107,12 @@ 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);
 
@@ -346,12 +352,11 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
     action("SHOW_ONLY_CMD")->setEnabled(false);
   }
 
-  if (myWorkshop->canChangeColor())
-    action("COLOR_CMD")->setEnabled(true);
-
-  if (myWorkshop->canChangeDeflection())
-    action("DEFLECTION_CMD")->setEnabled(true);
-
+  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);
@@ -449,12 +454,17 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
   if (aModule)
     aModule->updateViewerMenu(myActions);
 
-  if (myWorkshop->canChangeColor())
+  if (myWorkshop->canChangeProperty("COLOR_CMD"))
     action("COLOR_CMD")->setEnabled(true);
 
-  if (myWorkshop->canChangeDeflection())
+  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);
 }
 
@@ -486,6 +496,9 @@ 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"));
   myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
 
@@ -503,6 +516,9 @@ 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"));
   myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
   // Group menu
@@ -539,6 +555,9 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(mySeparator);
   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;
@@ -553,6 +572,9 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(mySeparator);
   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;
@@ -589,7 +611,9 @@ 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"));
   }
@@ -645,7 +669,9 @@ 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 cc12b80903cb17464d15ce58e17164f45946a333..fe9fbfcdcca1d35c1e1f0cc282f3f7c7fe78fa0c 100644 (file)
@@ -42,7 +42,7 @@
 double getDeflection(const ResultPtr& theResult)
 {
   double aDeflection = -1;
-  // get color from the attribute of the result
+  // get deflection from the attribute of the result
   if (theResult.get() != NULL &&
       theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) {
     AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
@@ -118,6 +118,27 @@ double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject)
   return aDeflection;
 }
 
+double getTransparency(const ResultPtr& theResult)
+{
+  double aDeflection = -1;
+  // get transparency from the attribute of the result
+  if (theResult.get() != NULL &&
+      theResult->data()->attribute(ModelAPI_Result::TRANSPARENCY_ID()).get() != NULL) {
+    AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+    if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) {
+      double aValue = aDoubleAttr->value();
+      if (aValue > 0) /// zero value should not be used as a transparency(previous studies)
+        aDeflection = aDoubleAttr->value();
+    }
+  }
+  return aDeflection;
+}
+
+double getDefaultTransparency(const ResultPtr& theResult)
+{
+  return 0;
+}
+
 XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
 : myWorkshop(theWorkshop)
 {
@@ -138,6 +159,14 @@ double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult)
   return aDeflection;
 }
 
+double XGUI_CustomPrs::getResultTransparency(const ResultPtr& theResult)
+{
+  double aTransparency = getTransparency(theResult);
+  if (aTransparency < 0)
+    aTransparency = getDefaultTransparency(theResult);
+  return aTransparency;
+}
+
 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
 {
@@ -158,6 +187,8 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the
     aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
 
     aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized;
+
+    aCustomized = thePrs->setTransparency(getResultTransparency(theResult)) | aCustomized;
   }
   ModuleBase_IModule* aModule = myWorkshop->module();
   aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized;
index 7b5e2e1845a516c0ef672da90419b808334d7334..6a2af267c0e7d73b876b162f7aa9a22c2bb439c0 100644 (file)
@@ -55,6 +55,11 @@ public:
   /// \return theDeflection a real value
   static double getResultDeflection(const ResultPtr& theResult);
 
+  /// Returns transparency of a result object
+  /// \param theResult a result object
+  /// \return theTransparency a real value
+  static double getResultTransparency(const ResultPtr& theResult);
+
   /// Returns the default object color. It obtains colorConfigInfo of the object
   /// and find it in preferences. If there are no this color in preference and an empty
   /// color is interpreted as invalid, it shows error message
diff --git a/src/XGUI/XGUI_PropertyDialog.cpp b/src/XGUI/XGUI_PropertyDialog.cpp
new file mode 100644 (file)
index 0000000..ab15ae8
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include <XGUI_PropertyDialog.h>
+
+#include <QDialogButtonBox>
+#include <QLabel>
+#include <QGridLayout>
+
+XGUI_PropertyDialog::XGUI_PropertyDialog(QWidget* theParent)
+: QDialog(theParent), myContentWidget(0)
+{
+  myLayout = new QGridLayout(this);
+
+  QDialogButtonBox* aButtons = new QDialogButtonBox(
+    QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
+  connect(aButtons, SIGNAL(accepted()), this, SLOT(accept()));
+  connect(aButtons, SIGNAL(rejected()), this, SLOT(reject()));
+
+  myLayout->addWidget(aButtons, 1, 0);
+}
+
+void XGUI_PropertyDialog::setContent(QWidget* theWidget)
+{
+  myLayout->addWidget(theWidget, 0, 0);
+}
diff --git a/src/XGUI/XGUI_PropertyDialog.h b/src/XGUI/XGUI_PropertyDialog.h
new file mode 100644 (file)
index 0000000..647340f
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef XGUI_PropertyDialog_H
+#define XGUI_PropertyDialog_H
+
+#include "XGUI.h"
+
+#include <QDialog>
+
+class QGridLayout;
+/**
+* \ingroup GUI
+* A dialog that contains property widget and accept/reject buttons.
+*/
+class XGUI_PropertyDialog : public QDialog
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent a parent widget for the dialog
+  XGUI_EXPORT XGUI_PropertyDialog(QWidget* theParent);
+
+  XGUI_EXPORT virtual ~XGUI_PropertyDialog() {};
+
+  /// Set content of the dialog
+  /// \param theWidget a content widget
+  void setContent(QWidget* theWidget);
+
+private:
+  QGridLayout* myLayout; /// grid layout where the first row is reserved for content widget,
+  /// the second row contains dialog buttons
+  QWidget* myContentWidget; /// content widget of the dialog
+};
+
+#endif
diff --git a/src/XGUI/XGUI_TransparencyWidget.cpp b/src/XGUI/XGUI_TransparencyWidget.cpp
new file mode 100644 (file)
index 0000000..76ec83d
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "XGUI_TransparencyWidget.h"
+
+#include <QCheckBox>
+#include <QDoubleSpinBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSlider>
+
+XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent, const QString& theLabelText)
+  : QWidget(theParent)
+{
+  QHBoxLayout* aLay = new QHBoxLayout(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);
+
+  myPreview = new QCheckBox("Preview", this);
+  myPreview->setChecked(true);
+
+  if (!theLabelText.isEmpty())
+    aLay->addWidget(new QLabel(theLabelText, this));
+  aLay->addWidget(mySpinValue);
+  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);
+  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();
+}
+
+void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
+{
+  setValue((double)theValue / 100);
+  emit transparencyValueChanged();
+}
diff --git a/src/XGUI/XGUI_TransparencyWidget.h b/src/XGUI/XGUI_TransparencyWidget.h
new file mode 100644 (file)
index 0000000..006d129
--- /dev/null
@@ -0,0 +1,79 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef XGUI_TransparencyWidget_H
+#define XGUI_TransparencyWidget_H
+
+#include "XGUI.h"
+
+#include <QWidget>
+
+class QDoubleSpinBox;
+class QSlider;
+class QCheckBox;
+
+/**
+* \ingroup GUI
+* A class of a widget to chose transparency. range of values is [0, 1],
+* where 0 - there is no transparency, 1 - the object is fully transparent.
+*/
+class XGUI_TransparencyWidget : public QWidget
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent a parent widget for the dialog
+  /// \param theLabelText if not empty, the information label will be shown in the widget
+  XGUI_EXPORT XGUI_TransparencyWidget(QWidget* theParent,
+                                      const QString& theLabelText = QString());
+  XGUI_EXPORT virtual ~XGUI_TransparencyWidget() {};
+
+  /// Initializes the dialog with the given value.
+  /// \param theValue transparency value
+  void setValue(double theValue);
+
+  /// Returns the current transparency value.
+  /// \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
+};
+
+#endif
index 7a11ee1bb221fce84b09df16ff07c921c5b6fce3..737d28e91f7ef3f5120228cf6f9320c036e94234 100755 (executable)
@@ -24,6 +24,7 @@
 #include "XGUI_MenuMgr.h"
 #include "XGUI_ColorDialog.h"
 #include "XGUI_DeflectionDialog.h"
+#include "XGUI_TransparencyWidget.h"
 #include "XGUI_ContextMenuMgr.h"
 #include "XGUI_Displayer.h"
 #include "XGUI_ErrorDialog.h"
@@ -32,6 +33,7 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_OperationMgr.h"
 #include "XGUI_PropertyPanel.h"
+#include "XGUI_PropertyDialog.h"
 #include "XGUI_SalomeConnector.h"
 #include "XGUI_Selection.h"
 #include "XGUI_SelectionMgr.h"
@@ -1354,6 +1356,10 @@ 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);
@@ -1851,17 +1857,25 @@ bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
 }
 
 //**************************************************************
-bool XGUI_Workshop::canChangeColor() const
+bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
 {
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+  if (theActionName == "COLOR_CMD" ||
+      theActionName == "DEFLECTION_CMD"
+#ifdef USE_TRANSPARENCY
+      || theActionName == "TRANSPARENCY_CMD"
+#endif
+      ) {
+    QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
 
-  std::set<std::string> aTypes;
-  aTypes.insert(ModelAPI_ResultGroup::group());
-  aTypes.insert(ModelAPI_ResultConstruction::group());
-  aTypes.insert(ModelAPI_ResultBody::group());
-  aTypes.insert(ModelAPI_ResultPart::group());
+    std::set<std::string> aTypes;
+    aTypes.insert(ModelAPI_ResultGroup::group());
+    aTypes.insert(ModelAPI_ResultConstruction::group());
+    aTypes.insert(ModelAPI_ResultBody::group());
+    aTypes.insert(ModelAPI_ResultPart::group());
 
-  return hasResults(aObjects, aTypes);
+    return hasResults(aObjects, aTypes);
+  }
+  return false;
 }
 
 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
@@ -1948,19 +1962,6 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 }
 
 //**************************************************************
-bool XGUI_Workshop::canChangeDeflection() const
-{
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
-
-  std::set<std::string> aTypes;
-  aTypes.insert(ModelAPI_ResultGroup::group());
-  aTypes.insert(ModelAPI_ResultConstruction::group());
-  aTypes.insert(ModelAPI_ResultBody::group());
-  aTypes.insert(ModelAPI_ResultPart::group());
-
-  return hasResults(aObjects, aTypes);
-}
-
 void setDeflection(ResultPtr theResult, const double theDeflection)
 {
   if (!theResult.get())
@@ -1971,13 +1972,41 @@ void setDeflection(ResultPtr theResult, const double theDeflection)
     aDeflectionAttr->setValue(theDeflection);
 }
 
+//**************************************************************
+void setTransparency(ResultPtr theResult, double theTransparency)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+  if (anAttribute.get() != NULL)
+    anAttribute->setValue(theTransparency);
+}
+
+//**************************************************************
+void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
+{
+  foreach(ObjectPtr anObj, theObjects) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL) {
+      ResultCompSolidPtr aCompsolidResult =
+        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+      if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
+        for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
+          setTransparency(aCompsolidResult->subResult(i), theTransparency);
+        }
+      }
+      setTransparency(aResult, theTransparency);
+    }
+  }
+}
 
 //**************************************************************
 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
 {
   AttributeDoublePtr aDoubleAttr;
-  // 1. find the current color of the object. This is a color of AIS presentation
-  // The objects are iterated until a first valid color is found
+  // 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 aDeflection = -1;
   foreach(ObjectPtr anObject, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
@@ -1985,9 +2014,9 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
       aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
     }
     else {
-      // TODO: remove the obtaining a color from the AIS object
+      // TODO: remove the obtaining a property from the AIS object
       // this does not happen never because:
-      // 1. The color can be changed only on results
+      // 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()) {
@@ -2022,7 +2051,7 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
     if (aResult.get() != NULL) {
       ResultCompSolidPtr aCompsolidResult =
         std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-      if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
+      if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
         for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
           setDeflection(aCompsolidResult->subResult(i), aDeflection);
         }
@@ -2034,6 +2063,90 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
   updateCommandStatus();
 }
 
+//**************************************************************
+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));
+}
+
 //**************************************************************
 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
index 0f0c350fd4cd455a1662df74bce6472c3e2881c8..871e2df122e9c1792de47a06f0aaf3b9beaa24f7 100755 (executable)
@@ -211,23 +211,25 @@ Q_OBJECT
   bool canBeShaded(const ObjectPtr& theObject) const;
 
   //! Returns true if there is at least one selected body/construction/group result
+  //! \param theActionName text of the checked action
   //! \return boolean value
-  bool canChangeColor() const;
+  bool canChangeProperty(const QString& theActionName) const;
 
   //! Change color of the results if it is possible
   //! The operation is available for construction, body and group results
   //! theObjects a list of selected objects
   void changeColor(const QObjectPtrList& theObjects);
 
-  //! Returns true if there is at least one selected body/construction/group result
-  //! \return boolean value
-  bool canChangeDeflection() const;
-
   //! Change deflection of the results if it is possible
   //! The operation is available for construction, body and group results
   //! theObjects a list of selected objects
   void changeDeflection(const QObjectPtrList& theObjects);
 
+  //! Change transparency of the results if it is possible
+  //! The operation is available for construction, body and group results
+  //! theObjects a list of selected objects
+  void changeTransparency(const QObjectPtrList& theObjects);
+
   //! Show the given features in 3d Viewer
   void showObjects(const QObjectPtrList& theList, bool isVisible);
 
@@ -423,6 +425,11 @@ signals:
   /// Activates/deactivates the trihedron in the viewer AIS context
   void onTrihedronVisibilityChanged(bool theState);
 
+  /// 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
index 222dfd208af47fb5b1cf90f762e6f12026980708..d2f9f767e9b3b78a12f0140004ff3f5c5856298f 100644 (file)
@@ -60,5 +60,7 @@
      <file>pictures/eyeclosed.png</file>
      <file>pictures/eyemiclosed.png</file>
      <file>pictures/eyeopen.png</file>
+
+     <file>pictures/transparency.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/transparency.png b/src/XGUI/pictures/transparency.png
new file mode 100644 (file)
index 0000000..774160e
Binary files /dev/null and b/src/XGUI/pictures/transparency.png differ