]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #35154][EDF](2023-T1) Edge thickness.
authordish <dmitrii.shvydkoi@opencascade.com>
Fri, 8 Mar 2024 13:51:34 +0000 (13:51 +0000)
committerdish <dmitrii.shvydkoi@opencascade.com>
Wed, 5 Jun 2024 12:39:33 +0000 (12:39 +0000)
Add preview.

src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_EdgeThicknessWidget.cpp
src/XGUI/XGUI_EdgeThicknessWidget.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 7ec56af30ee18fbbc3c1fdb29d39ba7270693ba9..3783346ad88e674a10fa96617b50638eddf155fc 100644 (file)
@@ -403,8 +403,8 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
 
       // Set edge thickness
       const int aEdgeThickness = ModelAPI_Tools::getEdgeThickness(aResult);
-      std::cout << "aEdgeThickness " << aEdgeThickness << "\t";
-      std::cout << "aAISObj->width() " << aAISObj->width() << std::endl;
+      // std::cout << "aEdgeThickness " << aEdgeThickness << "\t";
+      // std::cout << "aAISObj->width() " << aAISObj->width() << std::endl;
       if ((aEdgeThickness > 0) && (aEdgeThickness != aAISObj->width()))
         aAISObj->setWidth(aEdgeThickness);
 
index 7f86083cfb13817fdc1190e55911423682048b0a..7fb5e7d21afe459712ef85fa341311c64a4d47c2 100644 (file)
@@ -33,13 +33,13 @@ XGUI_EdgeThicknessWidget::XGUI_EdgeThicknessWidget(QWidget* theParent)
   mySpinBox = new SalomeApp_IntSpinBox();
   mySpinBox->setRange(1, 5);
   mySpinBox->setDefaultValue(1);
-  mySpinBox->setSingleStep(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)));
+  connect(mySpinBox, SIGNAL(valueChanged(int)), this, SIGNAL(thicknessValueChanged(int)));
 }
 
 void XGUI_EdgeThicknessWidget::setValue(int theValue)
index be3786ae52a6708d943b5729ce67dfb4ed5ffc40..8b18221458438658642815daa72e10e1f0da047d 100644 (file)
@@ -48,7 +48,7 @@ public:
   /// \return value
   int getValue() const;
 
-  signals:
+signals:
   void thicknessValueChanged();
 
 private:
index ff3149b52887d0dbc8b3dca957c426bf3d2c18b8..0e2aaa05ef85119d208e8480807a0d7e8f78e7c5 100644 (file)
 #include <sstream>
 #include <iterator>
 
+#include <iostream>
+
 #ifdef TINSPECTOR
 #include <Model_Session.h>
 #include <TDocStd_Application.hxx>
@@ -956,6 +958,49 @@ void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
   aFOperation->setGrantedOperationIds(aGrantedIds);
 }
 
+//******************************************************
+void XGUI_Workshop::applyEdgeThicknessToCanvas(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects, int theThickness)
+{
+  const bool isSubShapeWithEdgeThickness = Config_PropManager::boolean("Visualization", "result_subshape_with_edge_thickness");
+
+  // 3. Abort previous operation and start a new one.
+  SessionPtr session = ModelAPI_Session::get();
+  QString description = contextMenuMgr()->action("EDGE_THICKNESS_CMD")->text();
+  session->startOperation(description.toStdString());
+
+  // 4. Set new value to all results and subshapes of results.
+  foreach(ResultPtr result, theSelectedObjects.keys()) {
+    if (!result)
+      continue;
+
+    ResultBodyPtr bodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(result);
+    foreach(GeomShapePtr shape, theSelectedObjects[result]) {
+      if (result->shape()->impl<TopoDS_Shape>().IsEqual(shape->impl<TopoDS_Shape>()) || !isSubShapeWithEdgeThickness) {
+        if (result) {
+          // Change edge thickness for all sub-solids.
+          std::list<ResultPtr> allSubResults;
+          ModelAPI_Tools::allSubs(bodyResult, allSubResults);
+          for (auto itSubRes = allSubResults.begin(); itSubRes != allSubResults.end(); itSubRes++) {
+            ModelAPI_Tools::setEdgeThickness(*itSubRes, theThickness);
+          }
+
+          ModelAPI_Tools::setEdgeThickness(result, theThickness);
+        }
+
+        if (!isSubShapeWithEdgeThickness)
+          break;
+      }
+      else if (!shape->isNull())
+        ModelAPI_Tools::setSubShapeEdgeThickness(result, shape, theThickness);
+    }
+  }
+
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  session->finishOperation();
+  updateCommandStatus();
+  myViewerProxy->update();
+}
+
 //******************************************************
 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
 {
@@ -2944,55 +2989,21 @@ void XGUI_Workshop::changeEdgeThickness(const QMap<ResultPtr, QList<GeomShapePtr
   const auto dialog = new XGUI_PropertyDialog(desktop());
   dialog->setWindowTitle(tr("Edge Thickness"));
   XGUI_EdgeThicknessWidget* edgeThicknessWidget = new XGUI_EdgeThicknessWidget(dialog);
-  connect(edgeThicknessWidget, SIGNAL(thicknessValueChanged()), this, SLOT(onEdgeThicknessValueChanged()));
+  mySelectedObjects = theSelectedObjects;
+  connect(edgeThicknessWidget, SIGNAL(thicknessValueChanged(int)), this, SLOT(onEdgeThicknessValueChanged(int)));
   dialog->setContent(edgeThicknessWidget);
   edgeThicknessWidget->setValue(thickness);
 
   if (dialog->exec() != QDialog::Accepted)
-    return;
-
-  // 3. Abort previous operation and start a new one.
-  SessionPtr session = ModelAPI_Session::get();
-  QString description = contextMenuMgr()->action("EDGE_THICKNESS_CMD")->text();
-  session->startOperation(description.toStdString());
-
-  // 4. Set new value to all results and subshapes of results.
-  int newThickness = edgeThicknessWidget->getValue();
-  foreach(ResultPtr result, theSelectedObjects.keys()) {
-    if (!result)
-      continue;
-
-    ResultBodyPtr bodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(result);
-    foreach(GeomShapePtr shape, theSelectedObjects[result]) {
-      if (result->shape()->impl<TopoDS_Shape>().IsEqual(shape->impl<TopoDS_Shape>()) || !isSubShapeWithEdgeThickness) {
-        if (result) {
-          // Change edge thickness for all sub-solids.
-          std::list<ResultPtr> allSubResults;
-          ModelAPI_Tools::allSubs(bodyResult, allSubResults);
-          for (auto itSubRes = allSubResults.begin(); itSubRes != allSubResults.end(); itSubRes++) {
-            ModelAPI_Tools::setEdgeThickness(*itSubRes, newThickness);
-          }
-
-          ModelAPI_Tools::setEdgeThickness(result, newThickness);
-        }
-
-        if (!isSubShapeWithEdgeThickness)
-          break;
-      }
-      else if (!shape->isNull())
-        ModelAPI_Tools::setSubShapeEdgeThickness(result, shape, newThickness);
-    }
-  }
-
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  session->finishOperation();
-  updateCommandStatus();
-  myViewerProxy->update();
+    applyEdgeThicknessToCanvas(theSelectedObjects, thickness);
 }
 
 //**************************************************************
-void XGUI_Workshop::onEdgeThicknessValueChanged()
+void XGUI_Workshop::onEdgeThicknessValueChanged(int theThickness)
 {
+  // std::cout << "XGUI_Workshop::onEdgeThicknessValueChanged(" << theThickness << ")" << std::endl;
+
+  /*
   XGUI_EdgeThicknessWidget* aWidget = (XGUI_EdgeThicknessWidget*)sender();
   if (!aWidget)
     return;
@@ -3003,6 +3014,10 @@ void XGUI_Workshop::onEdgeThicknessValueChanged()
   Events_Loop::loop()->flush(kRedisplayEvent);
 
   myViewerProxy->update();
+  */
+
+
+  applyEdgeThicknessToCanvas(mySelectedObjects, theThickness);
 }
 
 //******************************************************
index 09ea4c266d4cb192aa76499034ca0a29c4996381..f631f3f9e318efd5c61232eb93179ac210638f11 100644 (file)
@@ -458,7 +458,7 @@ signals:
   /// Apply the current transparency value if preview in transparency dialog is switched on
   void onTransparencyValueChanged();
 
-  void onEdgeThicknessValueChanged();
+  void onEdgeThicknessValueChanged(int theThickness);
 
  protected:
   /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
@@ -467,6 +467,8 @@ signals:
   void setGrantedFeatures(ModuleBase_Operation* theOperation);
 
 private:
+  void applyEdgeThicknessToCanvas(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects, int theThickness);
+
   /// Display results from document
   /// \param theDoc a document
   void displayDocumentResults(DocumentPtr theDoc);
@@ -599,6 +601,8 @@ private:
   Config_DataModelReader* myDataModelXMLReader; ///< XML reader of data model
   XGUI_InspectionPanel* myInspectionPanel; ///< container of feature attributes widgets
   QTemporaryDir myTmpDir; ///< a direcory for uncompressed files
+
+  QMap<std::shared_ptr<ModelAPI_Result>, QList<std::shared_ptr<GeomAPI_Shape>>> mySelectedObjects;
 };
 
 #endif