From 42d8ecf39798c037945ca4bb9073d8dc31c53008 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 27 Jul 2016 08:21:49 +0300 Subject: [PATCH] Issue #1660: Ability to change the deflection coefficient --- src/GeomAPI/GeomAPI_AISObject.cpp | 28 ++++++++ src/GeomAPI/GeomAPI_AISObject.h | 12 ++++ src/Model/Model_ResultBody.cpp | 8 --- src/Model/Model_ResultBody.h | 3 - src/Model/Model_ResultCompSolid.cpp | 8 --- src/Model/Model_ResultCompSolid.h | 3 - src/Model/Model_ResultConstruction.cpp | 8 --- src/Model/Model_ResultConstruction.h | 3 - src/Model/Model_ResultGroup.cpp | 8 --- src/Model/Model_ResultGroup.h | 2 - src/Model/Model_ResultPart.cpp | 2 + src/ModelAPI/ModelAPI_Result.cpp | 11 +++ src/ModelAPI/ModelAPI_Result.h | 10 ++- src/XGUI/CMakeLists.txt | 2 + src/XGUI/XGUI_ContextMenuMgr.cpp | 16 +++++ src/XGUI/XGUI_CustomPrs.cpp | 32 ++++++++- src/XGUI/XGUI_CustomPrs.h | 11 ++- src/XGUI/XGUI_DeflectionDialog.cpp | 45 +++++++++++++ src/XGUI/XGUI_DeflectionDialog.h | 44 ++++++++++++ src/XGUI/XGUI_Workshop.cpp | 93 +++++++++++++++++++++++++- src/XGUI/XGUI_Workshop.h | 11 ++- 21 files changed, 311 insertions(+), 49 deletions(-) create mode 100755 src/XGUI/XGUI_DeflectionDialog.cpp create mode 100755 src/XGUI/XGUI_DeflectionDialog.h diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 3f7646688..74c1e1344 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -374,6 +374,34 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB) theB = (int)(aColor.Blue()*255.); } +bool GeomAPI_AISObject::setDeflection(const double theDeflection) +{ + bool isModified = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) { + aDrawer->SetDeviationCoefficient(theDeflection); + isModified = true; + } + } + + return isModified; +} + +double GeomAPI_AISObject::getDeflection() const +{ + double aDeflection = -1; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + aDeflection = aDrawer->DeviationCoefficient(); + } + return aDeflection; +} + + bool GeomAPI_AISObject::empty() const { Handle(AIS_InteractiveObject) anAIS = const_cast(this) diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index 18fd8fa94..1030aa06b 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -122,6 +122,18 @@ class GeomAPI_AISObject : public GeomAPI_Interface GEOMAPI_EXPORT void getColor(int& theR, int& theG, int& theB); + /** \brief Assigns the deflection to the shape + * \param[in] theDeflection value of deflection + */ + GEOMAPI_EXPORT + bool setDeflection(const double theDeflection); + + /** \brief Returns deflection for the shape + * \return double value + */ + GEOMAPI_EXPORT + double getDeflection() const; + /// \return Current width of the lines of shape GEOMAPI_EXPORT double width(); diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 714d984e8..80bce61ab 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -22,13 +21,6 @@ Model_ResultBody::Model_ResultBody() myConnect = ConnectionNotComputed; } -void Model_ResultBody::initAttributes() -{ - // append the color attribute. It is empty, the attribute will be filled by a request - DataPtr aData = data(); - aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); -} - void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) { diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index be5ac8e1d..e0ae33367 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -34,9 +34,6 @@ class Model_ResultBody : public ModelAPI_ResultBody bool myWasConcealed; public: - /// Request for initialization of data model of the result: adding all attributes - virtual void initAttributes(); - /// Returns the parameters of color definition in the resources config manager MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault); diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index f7cbeba3c..00ca3915d 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -32,12 +30,6 @@ Model_ResultCompSolid::~Model_ResultCompSolid() updateSubs(std::shared_ptr()); // erase sub-results } -void Model_ResultCompSolid::initAttributes() -{ - DataPtr aData = data(); - aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); -} - void Model_ResultCompSolid::store(const std::shared_ptr& theShape) { ModelAPI_ResultCompSolid::store(theShape); diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index ba92674e8..60ab44b0d 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -31,9 +31,6 @@ public: /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultCompSolid(); - /// Request for initialization of data model of the object: adding all attributes - MODEL_EXPORT virtual void initAttributes(); - /// Stores the shape (called by the execution method). Creates sub-results for compsolid. MODEL_EXPORT virtual void store(const std::shared_ptr& theShape); diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index a882b99d6..c1fea0708 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -6,20 +6,12 @@ #include -#include #include #include #include #include #include -void Model_ResultConstruction::initAttributes() -{ - // append the color attribute. It is empty, the attribute will be filled by a request - DataPtr aData = data(); - aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); -} - void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) { diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index bddac21ee..837add0fb 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -27,9 +27,6 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction bool myIsInHistory; bool myIsInfinite; public: - /// Request for initialization of data model of the result: adding all attributes - virtual void initAttributes(); - /// Retuns the parameters of color definition in the resources config manager MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault); diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp index c952c8b9d..8b4a39d55 100644 --- a/src/Model/Model_ResultGroup.cpp +++ b/src/Model/Model_ResultGroup.cpp @@ -6,7 +6,6 @@ #include #include -#include #include @@ -17,13 +16,6 @@ Model_ResultGroup::Model_ResultGroup(std::shared_ptr theOwnerData myOwnerData = theOwnerData; } -void Model_ResultGroup::initAttributes() -{ - // append the color attribute. It is empty, the attribute will be filled by a request - DataPtr aData = data(); - aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); -} - void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) { diff --git a/src/Model/Model_ResultGroup.h b/src/Model/Model_ResultGroup.h index 2252d455e..e6e4a15b8 100644 --- a/src/Model/Model_ResultGroup.h +++ b/src/Model/Model_ResultGroup.h @@ -20,8 +20,6 @@ class Model_ResultGroup : public ModelAPI_ResultGroup { std::shared_ptr myOwnerData; ///< data of owner of this result public: - /// Request for initialization of data model of the result: adding all attributes - virtual void initAttributes(); /// Retuns the parameters of color definition in the resources config manager MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index d4d10de3b..c6d27798b 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ void Model_ResultPart::initAttributes() data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId())); data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId()); if (aDocRef->isInitialized() && // initialized immideately means already exist and will be loaded !Model_Application::getApplication()->hasDocument(aDocRef->docId())) diff --git a/src/ModelAPI/ModelAPI_Result.cpp b/src/ModelAPI/ModelAPI_Result.cpp index cefbd7af8..187a1fc82 100644 --- a/src/ModelAPI/ModelAPI_Result.cpp +++ b/src/ModelAPI/ModelAPI_Result.cpp @@ -8,12 +8,23 @@ #include #include #include +#include +#include + #include ModelAPI_Result::~ModelAPI_Result() { } +void ModelAPI_Result::initAttributes() +{ + // append the color attribute. It is empty, the attribute will be filled by a request + DataPtr aData = data(); + aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); + aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId()); +} + bool ModelAPI_Result::setDisabled(std::shared_ptr theThis, const bool theFlag) { if (myIsDisabled != theFlag) { diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index bf15dfeec..c0958c7c0 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -34,6 +34,14 @@ class ModelAPI_Result : public ModelAPI_Object return MY_COLOR_ID; } + /// Reference to the deflection of the result. + /// The double value is used. The values is in [0, 1] range + inline static const std::string& DEFLECTION_ID() + { + static const std::string MY_DEFLECTION_ID("Deflection"); + return MY_DEFLECTION_ID; + } + /// Returns true if the result is concealed from the data tree (referenced by other objects) MODELAPI_EXPORT virtual bool isConcealed(); @@ -53,7 +61,7 @@ class ModelAPI_Result : public ModelAPI_Object MODELAPI_EXPORT virtual bool isDisabled(); /// Request for initialization of data model of the result: adding all attributes - virtual void initAttributes() {}; + MODELAPI_EXPORT virtual void initAttributes(); /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Result(); diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 2a8561f4a..222f5d2aa 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS XGUI_ContextMenuMgr.h XGUI_CustomPrs.h XGUI_DataModel.h + XGUI_DeflectionDialog.h XGUI_Displayer.h XGUI_ErrorDialog.h XGUI_ErrorMgr.h @@ -41,6 +42,7 @@ SET(PROJECT_SOURCES XGUI_ContextMenuMgr.cpp XGUI_CustomPrs.cpp XGUI_DataModel.cpp + XGUI_DeflectionDialog.cpp XGUI_Displayer.cpp XGUI_ErrorDialog.cpp XGUI_ErrorMgr.cpp diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index d7a7d1579..7cca98e11 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -86,6 +86,9 @@ void XGUI_ContextMenuMgr::createActions() aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop); addAction("COLOR_CMD", aAction); + aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop); + addAction("DEFLECTION_CMD", aAction); + aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop); addAction("SHOW_CMD", aAction); @@ -322,6 +325,9 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() if (myWorkshop->canChangeColor()) action("COLOR_CMD")->setEnabled(true); + if (myWorkshop->canChangeDeflection()) + action("DEFLECTION_CMD")->setEnabled(true); + ModuleBase_IModule* aModule = myWorkshop->module(); if (aModule) aModule->updateObjectBrowserMenu(myActions); @@ -408,6 +414,9 @@ void XGUI_ContextMenuMgr::updateViewerMenu() if (myWorkshop->canChangeColor()) action("COLOR_CMD")->setEnabled(true); + if (myWorkshop->canChangeDeflection()) + action("DEFLECTION_CMD")->setEnabled(true); + action("DELETE_CMD")->setEnabled(true); } @@ -438,6 +447,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(mySeparator); aList.append(action("RENAME_CMD")); aList.append(action("COLOR_CMD")); + aList.append(action("DEFLECTION_CMD")); aList.append(action("SHOW_FEATURE_CMD")); myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList; @@ -454,6 +464,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(mySeparator); aList.append(action("RENAME_CMD")); aList.append(action("COLOR_CMD")); + aList.append(action("DEFLECTION_CMD")); aList.append(action("SHOW_FEATURE_CMD")); myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList; // Group menu @@ -488,6 +499,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("SHOW_ONLY_CMD")); aList.append(mySeparator); aList.append(action("COLOR_CMD")); + aList.append(action("DEFLECTION_CMD")); myViewerMenu[ModelAPI_ResultConstruction::group()] = aList; // Result part menu myViewerMenu[ModelAPI_ResultPart::group()] = aList; @@ -501,6 +513,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("SHOW_ONLY_CMD")); aList.append(mySeparator); aList.append(action("COLOR_CMD")); + aList.append(action("DEFLECTION_CMD")); myViewerMenu[ModelAPI_ResultBody::group()] = aList; // Group menu myViewerMenu[ModelAPI_ResultGroup::group()] = aList; @@ -535,6 +548,8 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const aActions.append(mySeparator); //aActions.append(action("MOVE_CMD")); aActions.append(action("COLOR_CMD")); + aActions.append(action("DEFLECTION_CMD")); + aActions.append(action("CLEAN_HISTORY_CMD")); aActions.append(action("DELETE_CMD")); } @@ -581,6 +596,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const // hide all is shown always even if selection in the viewer is empty aActions.append(action("HIDEALL_CMD")); aActions.append(action("COLOR_CMD")); + aActions.append(action("DEFLECTION_CMD")); theMenu->addActions(aActions); diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 5878f4635..373eb2fe6 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -19,8 +20,20 @@ #include #include +double getDeflection(const ResultPtr& theResult) +{ + double aDeflection = -1; + // get color 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()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) + aDeflection = aDoubleAttr->value(); + } + return aDeflection; +} -void getColor(ResultPtr theResult, std::vector& theColor) +void getColor(const ResultPtr& theResult, std::vector& theColor) { theColor.clear(); // get color from the attribute of the result @@ -55,18 +68,31 @@ void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColo } } +double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) +{ + return Config_PropManager::real("Visualization", "result_deflection", "0.001"); +} + XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop) { } -void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector& theColor) +void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector& theColor) { getColor(theResult, theColor); if (theColor.empty()) getDefaultColor(theResult, false, theColor); } +double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult) +{ + double aDeflection = getDeflection(theResult); + if (aDeflection < 0) + aDeflection = getDefaultDeflection(theResult); + return aDeflection; +} + bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs) { @@ -84,6 +110,8 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the aColor[2] = aNewColor.blue(); } aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); + + aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized; } ModuleBase_IModule* aModule = myWorkshop->module(); aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized; diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h index c7fe0bc0b..4859339ca 100644 --- a/src/XGUI/XGUI_CustomPrs.h +++ b/src/XGUI/XGUI_CustomPrs.h @@ -34,7 +34,12 @@ public: /// Returns color of a result object /// \param theResult a result object /// \param theColor a color in form of RGB vector - static void getResultColor(ResultPtr theResult, std::vector& theColor); + static void getResultColor(const ResultPtr& theResult, std::vector& theColor); + + /// Returns deflection of a result object + /// \param theResult a result object + /// \return theDeflection a real value + static double getResultDeflection(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 @@ -45,6 +50,10 @@ public: static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, std::vector& theColor); + /// Returns the default deflection value. The value is obtained from the application preferences + /// \param theObject an investigated object + /// \return deflection value + static double XGUI_EXPORT getDefaultDeflection(const ObjectPtr& theObject); protected: XGUI_Workshop* myWorkshop; ///< the current workshop diff --git a/src/XGUI/XGUI_DeflectionDialog.cpp b/src/XGUI/XGUI_DeflectionDialog.cpp new file mode 100755 index 000000000..11f93ff8d --- /dev/null +++ b/src/XGUI/XGUI_DeflectionDialog.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: XGUI_DeflectionDialog.cpp +// Created: 27 Jul 2016 +// Author: Natalia ERMOLAEVA + +#include + +#include + +#include + +#include +#include +#include +#include +#include + +XGUI_DeflectionDialog::XGUI_DeflectionDialog(QWidget* theParent) + : QDialog(theParent) +{ + setWindowTitle("Deflection"); + QGridLayout* aLay = new QGridLayout(this); + + myDeflection = new QDoubleSpinBox(this); + myDeflection->setRange(0, 1); + aLay->addWidget(new QLabel("Deviation", this), 0, 0); + aLay->addWidget(myDeflection, 0, 1); + + 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())); + aLay->addWidget(aButtons, 1, 0, 1, 2); +} + +void XGUI_DeflectionDialog::setDeflection(const double& theValue) +{ + myDeflection->setValue(theValue); +} + +double XGUI_DeflectionDialog::getDeflection() const +{ + return myDeflection->value(); +} diff --git a/src/XGUI/XGUI_DeflectionDialog.h b/src/XGUI/XGUI_DeflectionDialog.h new file mode 100755 index 000000000..0ec10abe5 --- /dev/null +++ b/src/XGUI/XGUI_DeflectionDialog.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: XGUI_DeflectionDialog.hxx +// Created: 27 Jul 2016 +// Author: Natalia ERMOLAEVA + +#ifndef XGUI_DeflectionDialog_H +#define XGUI_DeflectionDialog_H + +#include "XGUI.h" + +#include + +class QButtonGroup; +class QDoubleSpinBox; + +/** +* \ingroup GUI +* A class of dialog to chose a deflection value. The deflection value is in range [0, 1] +*/ +class XGUI_DeflectionDialog : public QDialog +{ + Q_OBJECT +public: + /// Constructor + /// \param theParent a parent widget for the dialog + XGUI_EXPORT XGUI_DeflectionDialog(QWidget* theParent); + + XGUI_EXPORT virtual ~XGUI_DeflectionDialog() {}; + + /// Initializes the dialog with the given value. + /// \param theValue the deflection value + void setDeflection(const double& theDeflection); + + /// Returns the current deflection value. + /// \return a double value + double getDeflection() const; + +private: + QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice + QDoubleSpinBox* myDeflection; /// a deflection value +}; + +#endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 72574632f..0aa4a019e 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -6,6 +6,7 @@ #include "XGUI_ActionsMgr.h" #include "XGUI_MenuMgr.h" #include "XGUI_ColorDialog.h" +#include "XGUI_DeflectionDialog.h" #include "XGUI_ContextMenuMgr.h" #include "XGUI_Displayer.h" #include "XGUI_ErrorDialog.h" @@ -36,6 +37,7 @@ #include #include +#include #include #include #include @@ -205,7 +207,10 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); - + + Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection", + Config_Prop::Double, "0.001"); + if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true)) myViewerSelMode.append(TopAbs_FACE); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true)) @@ -1774,6 +1779,92 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) updateCommandStatus(); } +//************************************************************** +bool XGUI_Workshop::canChangeDeflection() const +{ + QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + + std::set 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()) + return; + + AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if (aDeflectionAttr.get() != NULL) + aDeflectionAttr->setValue(theDeflection); +} + + +//************************************************************** +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 + double aDeflection = -1; + foreach(ObjectPtr anObject, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) { + aDeflection = XGUI_CustomPrs::getResultDeflection(aResult); + } + else { + // TODO: remove the obtaining a color from the AIS object + // this does not happen never because: + // 1. The color 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()) { + aDeflection = anAISObj->getDeflection(); + } + } + if (aDeflection > 0) + break; + } + if (aDeflection < 0) + return; + + if (!abortAllOperations()) + return; + // 2. show the dialog to change the value + XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop()); + aDlg->setDeflection(aDeflection); + aDlg->move(QCursor::pos()); + bool isDone = aDlg->exec() == QDialog::Accepted; + if (!isDone) + return; + + // 3. abort the previous operation and start a new one + SessionPtr aMgr = ModelAPI_Session::get(); + QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); + + // 4. set the value to all results + aDeflection = aDlg->getDeflection(); + foreach(ObjectPtr anObj, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) { + ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast(aResult); + if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids + for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) { + setDeflection(aCompsolidResult->subResult(i), aDeflection); + } + } + setDeflection(aResult, aDeflection); + } + } + aMgr->finishOperation(); + updateCommandStatus(); +} + //************************************************************** #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \ for (int i = 0; i < aDoc->size(aGroupName); i++) { \ diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 81f6d7a91..ba9814db7 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -196,11 +196,20 @@ Q_OBJECT //! \return boolean value bool canChangeColor() const; - //! Change color of the features if it is possible + //! 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); + //! Show the given features in 3d Viewer void showObjects(const QObjectPtrList& theList, bool isVisible); -- 2.39.2