From 5e10b8b59af9cc394ae9067dfa1049463b9cec77 Mon Sep 17 00:00:00 2001 From: dish Date: Sun, 17 Dec 2023 15:45:09 +0000 Subject: [PATCH] [bos #35154][EDF](2023-T1) Edge thickness. Add edge thickness option for results and groups. --- src/Model/Model_ResultPart.cpp | 1 + src/ModelAPI/ModelAPI_Result.cpp | 2 + src/ModelAPI/ModelAPI_Result.h | 8 ++ src/ModelAPI/ModelAPI_Session.cpp | 3 + src/ModelAPI/ModelAPI_Tools.cpp | 26 ++++++ src/ModelAPI/ModelAPI_Tools.h | 13 +++ src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 26 +++++- src/ModelHighAPI/ModelHighAPI_Dumper.h | 3 + src/ModelHighAPI/ModelHighAPI_Selection.cpp | 11 +++ src/ModelHighAPI/ModelHighAPI_Selection.h | 4 + src/PartSet/PartSet_Tools.cpp | 6 +- src/PartSet/PartSet_Tools.h | 5 ++ src/SHAPERGUI/resources/LightApp.xml.in | 1 + src/XGUI/CMakeLists.txt | 3 + src/XGUI/XGUI_ContextMenuMgr.cpp | 15 ++++ src/XGUI/XGUI_Displayer.cpp | 16 ++++ src/XGUI/XGUI_EdgeThicknessWidget.cpp | 55 ++++++++++++ src/XGUI/XGUI_EdgeThicknessWidget.h | 58 ++++++++++++ src/XGUI/XGUI_Workshop.cpp | 97 ++++++++++++++++++++- src/XGUI/XGUI_Workshop.h | 7 ++ src/XGUI/XGUI_msg_fr.ts | 7 ++ 21 files changed, 361 insertions(+), 6 deletions(-) create mode 100644 src/XGUI/XGUI_EdgeThicknessWidget.cpp create mode 100644 src/XGUI/XGUI_EdgeThicknessWidget.h diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 4712ab625..43bc45c12 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -62,6 +62,7 @@ void Model_ResultPart::initAttributes() data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId()); data()->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(EDGE_THICKNESS_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId()); if (aDocRef->isInitialized() && // initialized immediately means already exist and will be loaded diff --git a/src/ModelAPI/ModelAPI_Result.cpp b/src/ModelAPI/ModelAPI_Result.cpp index 2c3bdc9f9..5de7bb1d9 100644 --- a/src/ModelAPI/ModelAPI_Result.cpp +++ b/src/ModelAPI/ModelAPI_Result.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ void ModelAPI_Result::initAttributes() aData->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false); aData->addAttribute(SHOW_ISO_LINES_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false); aData->addAttribute(SHOW_EDGES_DIRECTION_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false); + aData->addAttribute(EDGE_THICKNESS_ID(), ModelAPI_AttributeInteger::typeId()); // Add the "Bring To Front" attribute to the Result base class, as we may support it in the future // for all type of results. Actually, only ResultGroups are supported. aData->addAttribute(BRING_TO_FRONT_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false); diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index e82ea2f35..a9478c878 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -89,6 +89,14 @@ class ModelAPI_Result : public ModelAPI_Object return MY_SHOW_EDGES_DIRECTION_ID; } + /// Reference to the edge thickness of the result. + /// The integer value is used. The value is in [1, 5] range + inline static const std::string& EDGE_THICKNESS_ID() + { + static const std::string MY_EDGE_THICKNESS_ID("Edge_Thickness"); + return MY_EDGE_THICKNESS_ID; + } + /// Reference to the BringToFront flag of the result. /// The bool value is used. inline static const std::string& BRING_TO_FRONT_ID() diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp index d00c9e50f..e9ed94a80 100644 --- a/src/ModelAPI/ModelAPI_Session.cpp +++ b/src/ModelAPI/ModelAPI_Session.cpp @@ -83,6 +83,9 @@ std::shared_ptr ModelAPI_Session::get() Config_PropManager::registerProp("Visualization", "shaper_default_transparency", "Default transparency (%)", Config_Prop::IntSpin, "0", "0", "100"); + Config_PropManager::registerProp("Visualization", "shaper_default_edge_thickness", + "Default edge thickness (pt)", Config_Prop::IntSpin, "3", "1", "5"); + } return MY_MANAGER; } diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 508ca38e8..2c076b288 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1194,6 +1195,31 @@ bool isShowEdgesDirection(std::shared_ptr theResult) return false; } +//************************************************************** +int getEdgeThickness(const std::shared_ptr& theResult) +{ + int aThickness = -1; + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::EDGE_THICKNESS_ID()).get() != NULL) { + AttributeIntegerPtr aIntAttr = theResult->data()->integer(ModelAPI_Result::EDGE_THICKNESS_ID()); + if (aIntAttr.get() && aIntAttr->isInitialized()) { + aThickness = aIntAttr->value(); + } + } + return aThickness; +} + +void setEdgeThickness(ResultPtr theResult, int theEdgeThickness) +{ + if (!theResult.get()) + return; + + AttributeIntegerPtr anAttribute = theResult->data()->integer(ModelAPI_Result::EDGE_THICKNESS_ID()); + if (anAttribute.get() != NULL) { + anAttribute->setValue(theEdgeThickness); + } +} + //****************************************************** void bringToFront(std::shared_ptr theResult, bool theFlag) { diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index beb380f86..f7eac8c7f 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -312,6 +312,19 @@ MODELAPI_EXPORT void showEdgesDirection(std::shared_ptr theResu MODELAPI_EXPORT bool isShowEdgesDirection(std::shared_ptr theResult); +/*! Returns current edge thickness in the given result +* \param theResult a result object +* \return an egde thickness value or -1 if it was not defined +*/ +MODELAPI_EXPORT int getEdgeThickness(const std::shared_ptr& theResult); + +/*! Set edge thickness for the given result +* \param theResult a result object +* \param theEdgeThickness edge thickness value +*/ +MODELAPI_EXPORT void setEdgeThickness(std::shared_ptr theResult, + int theEdgeThickness); + /*! Set flag to bring result in front of other results * \param[in] theResult a result object * \param[in] theFlag is a flag diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index cc22e0d1c..f6d07c88b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -952,6 +952,15 @@ void ModelHighAPI_Dumper::dumpEntitySetName() *myDumpStorage << ".setTransparency(" << aTransparencyAttr->value() << ")\n"; } } + // set result edge thickness + if (isEdgeThicknessDefined(*aResIt)) { + const auto aAttr = + (*aResIt)->data()->integer(ModelAPI_Result::EDGE_THICKNESS_ID()); + if(aAttr.get() && aAttr->isInitialized()) { + *this << *aResIt; + *myDumpStorage << ".setEdgeThickness(" << aAttr->value() << ")\n"; + } + } } myNames[aLastDumped.myEntity].myIsDumped = true; @@ -1076,6 +1085,15 @@ bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) cons return fabs(anAttribute->value()) < 1.e-12; } +bool ModelHighAPI_Dumper::isEdgeThicknessDefined(const ResultPtr& theResult) const +{ + const auto anAttribute = theResult->data()->integer(ModelAPI_Result::EDGE_THICKNESS_ID()); + if(!anAttribute || !anAttribute->isInitialized()) { + return false; + } + return true; +} + bool ModelHighAPI_Dumper::dumpCommentBeforeFeature(const FeaturePtr& theFeature) const { // currently, the comment should not be dumped only before the filters @@ -1317,18 +1335,18 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity if (!myNames[theEntity].myIsDumped) { bool isUserDefinedName = !myNames[theEntity].myIsDefault; // store results if they have user-defined names or colors - std::list aResultsWithNameOrColor; + std::list aResultsWithNonDefaultAttr; std::list allRes; ModelAPI_Tools::allResults(theEntity, allRes); for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) || - !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes)) - aResultsWithNameOrColor.push_back(*aRes); + !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes) || isEdgeThicknessDefined(*aRes)) + aResultsWithNonDefaultAttr.push_back(*aRes); } // store just dumped entity to stack if (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theEntity) myEntitiesStack.push( - LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor)); + LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNonDefaultAttr)); } // remove entity from the list of not dumped items diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index c7286289c..b98a91dea 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -412,6 +412,9 @@ private: /// Check the result feature has default transparency bool isDefaultTransparency(const ResultPtr& theResult) const; + /// Check the result feature has edge thickness attribute + bool isEdgeThicknessDefined(const ResultPtr& theResult) const; + /// Dump postponed entities void dumpPostponed(bool theDumpFolders = false); diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index 160925e8b..862b81817 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -20,6 +20,7 @@ #include "ModelHighAPI_Selection.h" #include +#include #include #include #include @@ -257,6 +258,16 @@ void ModelHighAPI_Selection::setTransparency(double theValue) } // LCOV_EXCL_STOP +void ModelHighAPI_Selection::setEdgeThickness(int theValue) { + if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get()) + return; + + const auto attr = + myResultSubShapePair.first->data()->integer(ModelAPI_Result::EDGE_THICKNESS_ID()); + + attr->setValue(theValue); +} + int ModelHighAPI_Selection::numberOfSubs() const { if (myVariantType != VT_ResultSubShapePair) diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index dc27c474f..444b36359 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -144,6 +144,10 @@ public: MODELHIGHAPI_EXPORT void setTransparency(double theValue); + /// Change edge thickness of result + MODELHIGHAPI_EXPORT + void setEdgeThickness(int theValue); + /// Returns the number of sub-elements. MODELHIGHAPI_EXPORT int numberOfSubs() const; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index fd71ff50b..1ff60a85f 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -899,12 +899,16 @@ double PartSet_Tools::getDefaultDeflection(const ObjectPtr& theObject) return aDeflection; } - double PartSet_Tools::getDefaultTransparency() { return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; } +int PartSet_Tools::getDefaultEdgeThickness() +{ + return Config_PropManager::integer("Visualization", "shaper_default_edge_thickness"); +} + QCursor PartSet_Tools::getOperationCursor() { int aId = Config_PropManager::integer(SKETCH_TAB_NAME, "operation_cursor"); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index f8ae5dba7..ebf7a1198 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -331,6 +331,11 @@ public: */ static double getDefaultTransparency(); + /** + * Returns user-defined default edge thickness value + */ + static int getDefaultEdgeThickness(); + /** * Returns cursor according to (SKETCH_TAB_NAME, "operation_cursor") property value */ diff --git a/src/SHAPERGUI/resources/LightApp.xml.in b/src/SHAPERGUI/resources/LightApp.xml.in index 06636c0fb..f6873c917 100644 --- a/src/SHAPERGUI/resources/LightApp.xml.in +++ b/src/SHAPERGUI/resources/LightApp.xml.in @@ -52,6 +52,7 @@ + diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index dd690533e..136034ef5 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -39,6 +39,7 @@ SET(PROJECT_HEADERS XGUI_DataModel.h XGUI_DeflectionDialog.h XGUI_Displayer.h + XGUI_EdgeThicknessWidget.h XGUI_ErrorDialog.h XGUI_ErrorMgr.h XGUI_FacesPanel.h @@ -76,6 +77,7 @@ SET(PROJECT_MOC_HEADERS XGUI_DataModel.h XGUI_DeflectionDialog.h XGUI_Displayer.h + XGUI_EdgeThicknessWidget.h XGUI_ErrorDialog.h XGUI_ErrorMgr.h XGUI_FacesPanel.h @@ -106,6 +108,7 @@ SET(PROJECT_SOURCES XGUI_DataModel.cpp XGUI_DeflectionDialog.cpp XGUI_Displayer.cpp + XGUI_EdgeThicknessWidget.cpp XGUI_ErrorDialog.cpp XGUI_ErrorMgr.cpp XGUI_FacesPanel.cpp diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 5b4365658..d83ac4cb7 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -133,6 +133,9 @@ void XGUI_ContextMenuMgr::createActions() tr("Transparency..."), aDesktop); addAction("TRANSPARENCY_CMD", anAction); + anAction = ModuleBase_Tools::createAction(QIcon(), tr("Edge Thickness..."), aDesktop); + addAction("EDGE_THICKNESS_CMD", anAction); + anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop); addAction("SHOW_CMD", anAction); @@ -553,6 +556,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD")); action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD")); action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD")); + action("EDGE_THICKNESS_CMD")->setEnabled(myWorkshop->canChangeProperty("EDGE_THICKNESS_CMD")); action("AUTOCOLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("AUTOCOLOR_CMD")); #ifdef _DEBUG @@ -683,6 +687,9 @@ void XGUI_ContextMenuMgr::updateViewerMenu() if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD")) action("TRANSPARENCY_CMD")->setEnabled(true); + + if (myWorkshop->canChangeProperty("EDGE_THICKNESS_CMD")) + action("EDGE_THICKNESS_CMD")->setEnabled(true); action("DELETE_CMD")->setEnabled(true); } @@ -717,6 +724,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(action("SHOW_FEATURE_CMD")); aList.append(mySeparator2); aList.append(action("DELETE_CMD")); @@ -738,6 +746,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(action("SHOW_FEATURE_CMD")); @@ -768,6 +777,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(action("SHOW_FEATURE_CMD")); @@ -827,6 +837,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(mySeparator3); aList.append(action("SET_VIEW_NORMAL_CMD")); aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD")); @@ -846,6 +857,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(mySeparator3); @@ -869,6 +881,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("EDGE_THICKNESS_CMD")); aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(mySeparator3); @@ -925,6 +938,7 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const anActions.append(action("COLOR_CMD")); anActions.append(action("DEFLECTION_CMD")); anActions.append(action("TRANSPARENCY_CMD")); + anActions.append(action("EDGE_THICKNESS_CMD")); anActions.append(action("SHOW_ISOLINES_CMD")); anActions.append(action("ISOLINES_CMD")); anActions.append(action("CLEAN_HISTORY_CMD")); @@ -978,6 +992,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const anActions.append(action("COLOR_CMD")); anActions.append(action("DEFLECTION_CMD")); anActions.append(action("TRANSPARENCY_CMD")); + anActions.append(action("EDGE_THICKNESS_CMD")); anActions.append(mySeparator1); anActions.append(action("SHOW_ONLY_CMD")); anActions.append(action("HIDE_CMD")); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 477544490..7ec56af30 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -278,6 +278,15 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, // appear "behind" the Groups. aContext->SetDisplayPriority(anAISIO, FRONT_DISPLAY_PRIORITY); } + + // Set edge thickness, if deserialization is done before Shaper is activated. + { + int aThickness = ModelAPI_Tools::getEdgeThickness(aResult); + if (aThickness == -1) + aThickness = Config_PropManager::integer("Visualization", "shaper_default_edge_thickness"); + + aContext->SetWidth(anAISIO, aThickness, theUpdateViewer); + } #ifdef TINSPECTOR if (getCallBack()) getCallBack()->Display(anAISIO); #endif @@ -392,6 +401,13 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency())) aAISObj->setTransparency(aTransparency); + // Set edge thickness + const int aEdgeThickness = ModelAPI_Tools::getEdgeThickness(aResult); + std::cout << "aEdgeThickness " << aEdgeThickness << "\t"; + std::cout << "aAISObj->width() " << aAISObj->width() << std::endl; + if ((aEdgeThickness > 0) && (aEdgeThickness != aAISObj->width())) + aAISObj->setWidth(aEdgeThickness); + // Set Iso-Lines Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO); if (!aResPrs.IsNull()) diff --git a/src/XGUI/XGUI_EdgeThicknessWidget.cpp b/src/XGUI/XGUI_EdgeThicknessWidget.cpp new file mode 100644 index 000000000..7f86083cf --- /dev/null +++ b/src/XGUI/XGUI_EdgeThicknessWidget.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2014-2023 CEA, EDF +// +// 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 +// + +#include "XGUI_EdgeThicknessWidget.h" + + +#include +#include + + +XGUI_EdgeThicknessWidget::XGUI_EdgeThicknessWidget(QWidget* theParent) + : QWidget(theParent) +{ + auto aLayout = new QHBoxLayout(this); + aLayout->setContentsMargins(0, 0, 0, 0); + + mySpinBox = new SalomeApp_IntSpinBox(); + mySpinBox->setRange(1, 5); + mySpinBox->setDefaultValue(1); + mySpinBox->setSingleStep(1); + mySpinBox->setObjectName("EdgeThicknessSpinBox"); + mySpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + mySpinBox->setValue(1); + aLayout->addWidget(mySpinBox, 0, Qt::AlignCenter); + + connect(mySpinBox, SIGNAL(valueChanged(int)), this, SLOT(thicknessValueChanged(int))); +} + +void XGUI_EdgeThicknessWidget::setValue(int theValue) +{ + bool isSpinBoxBlocked = mySpinBox->blockSignals(true); + mySpinBox->setValue(theValue); + mySpinBox->blockSignals(isSpinBoxBlocked); +} + +int XGUI_EdgeThicknessWidget::getValue() const +{ + return mySpinBox->value(); +} \ No newline at end of file diff --git a/src/XGUI/XGUI_EdgeThicknessWidget.h b/src/XGUI/XGUI_EdgeThicknessWidget.h new file mode 100644 index 000000000..be3786ae5 --- /dev/null +++ b/src/XGUI/XGUI_EdgeThicknessWidget.h @@ -0,0 +1,58 @@ +// Copyright (C) 2014-2023 CEA, EDF +// +// 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 +// + +#ifndef XGUI_EdgeThicknessWidget_H +#define XGUI_EdgeThicknessWidget_H + +#include "XGUI.h" +#include + +class SalomeApp_IntSpinBox; + +/** +* \ingroup GUI +* A class of a widget to chose edge thickness. Range of values is Natural:[0; 5]. +*/ +class XGUI_EdgeThicknessWidget : 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_EdgeThicknessWidget(QWidget* theParent); + XGUI_EXPORT ~XGUI_EdgeThicknessWidget() = default; + + /// Initializes the dialog with the given value. + /// \param theValue edge thickness value + void setValue(int theValue); + + /// Returns the current edge thickness value. + /// \return value + int getValue() const; + + signals: + void thicknessValueChanged(); + +private: + SalomeApp_IntSpinBox* mySpinBox; +}; + +#endif // XGUI_EdgeThicknessWidget_H \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0df895c85..28975c9e5 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -26,6 +26,7 @@ #include "XGUI_ColorDialog.h" #include "XGUI_DeflectionDialog.h" #include "XGUI_TransparencyWidget.h" +#include "XGUI_EdgeThicknessWidget.h" #include "XGUI_ContextMenuMgr.h" #include "XGUI_Displayer.h" #include "XGUI_ErrorDialog.h" @@ -1812,6 +1813,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) changeDeflection(anObjects); else if (theId == "TRANSPARENCY_CMD") changeTransparency(anObjects); + else if (theId == "EDGE_THICKNESS_CMD") + changeEdgeThickness(anObjects); else if (theId == "SHOW_CMD") { showObjects(anObjects, true); mySelector->updateSelectionBy(ModuleBase_ISelection::Browser); @@ -2517,7 +2520,8 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const { if (theActionName == "COLOR_CMD" || theActionName == "DEFLECTION_CMD" || - theActionName == "TRANSPARENCY_CMD") { + theActionName == "TRANSPARENCY_CMD" || + theActionName == "EDGE_THICKNESS_CMD") { QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); std::set aTypes; @@ -2866,6 +2870,97 @@ void XGUI_Workshop::onTransparencyValueChanged() myViewerProxy->update(); } +//************************************************************** + +/// Returns user-defined default edge thickness. +int getDefaultEdgeThickness() +{ + return Config_PropManager::integer("Visualization", "shaper_default_edge_thickness"); +} + +//************************************************************** +void setEdgeThickness(int theThickness, const QObjectPtrList& theObjects) +{ + foreach(ObjectPtr anObj, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) { + ResultBodyPtr aBodyResult = std::dynamic_pointer_cast(aResult); + if (aBodyResult.get() != NULL) { // change property for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + std::list::iterator aRes; + for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + ModelAPI_Tools::setEdgeThickness(*aRes, theThickness); + } + } + ModelAPI_Tools::setEdgeThickness(aResult, theThickness); + } + } +} + +//************************************************************** +void XGUI_Workshop::changeEdgeThickness(const QObjectPtrList& theObjects) +{ + AttributeIntegerPtr aDoubleAttr; + // 1. Get current value. + int aCurrentValue = -1; + foreach(ObjectPtr anObject, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) { + aCurrentValue = ModelAPI_Tools::getEdgeThickness(aResult); + if (aCurrentValue < 0) + aCurrentValue = getDefaultEdgeThickness(); + } + if (aCurrentValue > 0) + break; + } + if (aCurrentValue < 0) + return; + + if (!abortAllOperations()) + return; + + // 2. Show the dialog. + XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop()); + aDlg->setWindowTitle(tr("Edge Thickness")); + XGUI_EdgeThicknessWidget* aEdgeThicknessWidget = new XGUI_EdgeThicknessWidget(aDlg); + connect(aEdgeThicknessWidget, SIGNAL(thicknessValueChanged()), this, SLOT(onEdgeThicknessValueChanged())); + aDlg->setContent(aEdgeThicknessWidget); + aEdgeThicknessWidget->setValue(aCurrentValue); + + // 3. Abort the previous operation and start a new one. + SessionPtr aMgr = ModelAPI_Session::get(); + QString aDescription = contextMenuMgr()->action("EDGE_THICKNESS_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); + + if (aDlg->exec() == QDialog::Accepted) { + // 4. Set the value to all results. + aCurrentValue = aEdgeThicknessWidget->getValue(); + setEdgeThickness(aCurrentValue, theObjects); + aMgr->finishOperation(); + } else { + aMgr->abortOperation(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + + updateCommandStatus(); +} + +//************************************************************** +void XGUI_Workshop::onEdgeThicknessValueChanged() +{ + XGUI_EdgeThicknessWidget* aWidget = (XGUI_EdgeThicknessWidget*)sender(); + if (!aWidget) + return; + + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); + setEdgeThickness(aWidget->getValue(), anObjects); + static const Events_ID kRedisplayEvent = + Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + Events_Loop::loop()->flush(kRedisplayEvent); + + myViewerProxy->update(); +} //****************************************************** void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index e0d97cbae..213e09275 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -221,6 +221,11 @@ Q_OBJECT /// theObjects a list of selected objects void changeTransparency(const QObjectPtrList& theObjects); + /// Change edge thickness of the results if it is possible. + /// The operation is available for construction, body and group results. + /// \param theObjects refers to selected objects. + void changeEdgeThickness(const QObjectPtrList& theObjects); + /// Change number of iso-lines for the given objects /// theObjects a list of selected objects void changeIsoLines(const QObjectPtrList& theObjects); @@ -452,6 +457,8 @@ signals: /// Apply the current transparency value if preview in transparency dialog is switched on void onTransparencyValueChanged(); + + void onEdgeThicknessValueChanged(); protected: /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index 9d89050d2..e0fb26b7f 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -128,6 +128,10 @@ Transparency... Transparence... + + Edge Thickness... + Epaisseur Des Aretes... + Show Voir @@ -563,6 +567,9 @@ Transparent + + XGUI_EdgeThicknessWidget + XGUI_Workshop -- 2.39.2