]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #35154][EDF](2023-T1) Edge thickness.
authordish <Dmitrii.SHVYDKOI@opencascade.com>
Sun, 17 Dec 2023 15:45:09 +0000 (15:45 +0000)
committerdish <dmitrii.shvydkoi@opencascade.com>
Wed, 5 Jun 2024 12:30:41 +0000 (12:30 +0000)
Add edge thickness option for results and groups.

21 files changed:
src/Model/Model_ResultPart.cpp
src/ModelAPI/ModelAPI_Result.cpp
src/ModelAPI/ModelAPI_Result.h
src/ModelAPI/ModelAPI_Session.cpp
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SHAPERGUI/resources/LightApp.xml.in
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_EdgeThicknessWidget.cpp [new file with mode: 0644]
src/XGUI/XGUI_EdgeThicknessWidget.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_msg_fr.ts

index 4712ab625679cb8504e7d6643ed930e33c93c363..43bc45c12996f53a62ab683e11daa7b519bed353 100644 (file)
@@ -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
index 2c3bdc9f9acaebbc921fc95b367c14249921db77..5de7bb1d9e333b3f7ad260402cc81ce294faae46 100644 (file)
@@ -21,6 +21,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeBoolean.h>
@@ -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);
index e82ea2f355d123eb0f36f26dd450ecac3567a876..a9478c8782a289c8de0786a7846ce144d2ecd38c 100644 (file)
@@ -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()
index d00c9e50f66e1c0de7ef2d9e1b7244d0dc9c19bc..e9ed94a8095b78fc1e19e68d714cbe616faaf641 100644 (file)
@@ -83,6 +83,9 @@ std::shared_ptr<ModelAPI_Session> 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;
 }
index 508ca38e8ed97fcdc92c6849bb28d7086ce012bf..2c076b288cbb1db49621b506b3684e739f266601 100644 (file)
@@ -22,6 +22,7 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeImage.h>
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Document.h>
@@ -1194,6 +1195,31 @@ bool isShowEdgesDirection(std::shared_ptr<ModelAPI_Result> theResult)
   return false;
 }
 
+//**************************************************************
+int getEdgeThickness(const std::shared_ptr<ModelAPI_Result>& 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<ModelAPI_Result> theResult, bool theFlag)
 {
index beb380f867d783603585ba9e5107744d543283ca..f7eac8c7fbd078a283c486aea96102cda1d8fc86 100644 (file)
@@ -312,6 +312,19 @@ MODELAPI_EXPORT void showEdgesDirection(std::shared_ptr<ModelAPI_Result> theResu
 
 MODELAPI_EXPORT bool isShowEdgesDirection(std::shared_ptr<ModelAPI_Result> 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<ModelAPI_Result>& 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<ModelAPI_Result> 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
index cc22e0d1c828fb2afed210bb98dced0c9127e24a..f6d07c88bba972c042f179945deacbaf1fdf2321 100644 (file)
@@ -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<ResultPtr> aResultsWithNameOrColor;
+    std::list<ResultPtr> aResultsWithNonDefaultAttr;
     std::list<ResultPtr> allRes;
     ModelAPI_Tools::allResults(theEntity, allRes);
     for(std::list<ResultPtr>::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
index c7286289c47fe8b7c9a5da2d2f0a63e095be2996..b98a91deab0757b75a560e8754e10820a39e1d63 100644 (file)
@@ -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);
 
index 160925e8b3fbc0c98286ffa86b2dcf126d3b33d0..862b81817b0fdebab445a56d092ec909d8473bfa 100644 (file)
@@ -20,6 +20,7 @@
 #include "ModelHighAPI_Selection.h"
 
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -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)
index dc27c474fce58e15dbb22f2446401bc859c29afe..444b36359f3ea40ba7e7c42f6b7241da28f384a3 100644 (file)
@@ -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;
index fd71ff50bbf7480c8eeda1ac1cf2d31f8b43564b..1ff60a85f9fe89e1f1a51ebae931fb9e8e12a55b 100644 (file)
@@ -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");
index f8ae5dba73f6ea7c68e53e44cb793ae20c6a3ba0..ebf7a11983a8e1e5872d7ff5cebaabe6ffd1cabd 100644 (file)
@@ -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
   */
index 06636c0fb0ff98d0067cd999add67d94f911da3c..f6873c91740d4639ff9432cddb93923767745e3a 100644 (file)
@@ -52,6 +52,7 @@
     <parameter name="scalar_bar_nb_intervals" value="20" />
     <parameter name="scalar_bar_text_color" value="#000000" />
     <parameter name="shaper_default_transparency" value="0"/>
+    <parameter name="shaper_default_edge_thickness" value="3"/>
     <parameter name="group_names_display" value="true" />
     <parameter name="group_names_font" value="Times-bold" />
     <parameter name="group_names_size" value="12" />
index dd690533ec0779ab317de4850a475a3edb703344..136034ef5aee0282a9378afcc08ea6b39065d786 100644 (file)
@@ -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
index 5b43656584e52835956c83072522196be2309908..d83ac4cb7a939ad62e2532b62d356d88cee4dc53 100644 (file)
@@ -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"));
index 4775444902facde04b55b7dd5a36b7b2d05f59af..7ec56af30ee18fbbc3c1fdb29d39ba7270693ba9 100644 (file)
@@ -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 (file)
index 0000000..7f86083
--- /dev/null
@@ -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 <QHBoxLayout>
+#include <SalomeApp_IntSpinBox.h>
+
+
+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 (file)
index 0000000..be3786a
--- /dev/null
@@ -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 <QWidget>
+
+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
index 0df895c850db18a1e6de7e1528bcddf0d0bdf874..28975c9e5331c7f330cfca2f13dbc8eea07761d3 100644 (file)
@@ -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<std::string> 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<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL) {
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change property for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        std::list<ResultPtr>::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<ModelAPI_Result>(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)
index e0d97cbae43f2f3d1d32645c17366114efe949d4..213e09275a2fdf3bef8bb55fb1f991ef8afa70a8 100644 (file)
@@ -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
index 9d89050d2aa3121ffd3d50b36e79987094369d23..e0fb26b7f1fee906863809bd154ac0f292d12703 100644 (file)
         <source>Transparency...</source>
         <translation>Transparence...</translation>
     </message>
+    <message>
+        <source>Edge Thickness...</source>
+        <translation>Epaisseur Des Aretes...</translation>
+    </message>
     <message>
         <source>Show</source>
         <translation>Voir</translation>
         <translation>Transparent</translation>
     </message>
 </context>
+<context>
+    <name>XGUI_EdgeThicknessWidget</name>
+</context>
 <context>
     <name>XGUI_Workshop</name>
     <message>