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
{
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();
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()))
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)
}
/// 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();
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;
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;
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 =
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);
}
}
/// 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
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)
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;
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
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
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
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);
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);
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);
}
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;
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
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;
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;
//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"));
}
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;
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());
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)
{
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)
{
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;
/// \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
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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
#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"
#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"
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);
}
//**************************************************************
-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)
}
//**************************************************************
-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())
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);
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()) {
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);
}
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++) { \
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);
/// 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
<file>pictures/eyeclosed.png</file>
<file>pictures/eyemiclosed.png</file>
<file>pictures/eyeopen.png</file>
+
+ <file>pictures/transparency.png</file>
</qresource>
</RCC>