]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implemetation of AutoColor
authorJérôme <jerome.lucas@cesgenslab.fr>
Wed, 4 Nov 2020 17:37:19 +0000 (18:37 +0100)
committerNicolas Rechatin <nicolas.rechatin@cea.fr>
Mon, 30 Aug 2021 12:55:51 +0000 (14:55 +0200)
src/XGUI/XGUI_ColorDialog.cpp
src/XGUI/XGUI_ColorDialog.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index a3cabb6ff7250c02679f6a224f97d55b3abd66fa..3cbcca53977dcc52b4d3b00463b0ab861188adaf 100644 (file)
@@ -189,3 +189,10 @@ std::vector<int> XGUI_ColorDialog::getRandomColor() const
   }
   return aValues;
 }
+
+std::vector<int> XGUI_ColorDialog::randomColor()
+{
+  std::vector<int> aValues;
+  findRandomColor(aValues);
+  return aValues;
+}
index fc4ea08991a0f04a6a323e62bfd4779fba5baa6b..172e1840f406c4bbfde89afa5cdd4dbded75018b 100644 (file)
@@ -64,6 +64,12 @@ public:
   /// \return a vector of values
   std::vector<int> getRandomColor() const;
 
+  /// Returns a container with the current color value.
+  /// These are tree int values for RGB definition.
+  /// It returns the next random color.
+  /// \return a vector of values
+  static std::vector<int> randomColor();
+
 private:
   QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice
   QtxColorButton* myColorButton; /// a control to select a color
index 6e1d82e5dc8bb97059d40fcdac5d7760bef14b58..0786609f5a2aeee15107fc0ee48398252714e439 100644 (file)
@@ -114,6 +114,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("Auto color"), aDesktop);
+  addAction("AUTOCOLOR_CMD", aAction);
+
   aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
   addAction("DEFLECTION_CMD", aAction);
 
@@ -506,6 +509,8 @@ 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("AUTOCOLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("AUTOCOLOR_CMD"));
+
   #ifdef _DEBUG
     #ifdef TINSPECTOR
       action("TINSPECTOR_VIEW")->setEnabled(true);
@@ -685,10 +690,31 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("DELETE_CMD"));
   myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
   // Group menu
-  myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
   myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
   // Result part menu
   myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
+
+  aList.clear();
+  aList.append(action("WIREFRAME_CMD"));
+  aList.append(action("SHADING_CMD"));
+  aList.append(mySeparator1); // this separator is not shown as this action is added after show only
+  // qt list container contains only one instance of the same action
+  aList.append(action("SHOW_CMD"));
+  aList.append(action("HIDE_CMD"));
+  aList.append(action("SHOW_ONLY_CMD"));
+  aList.append(mySeparator2);
+  aList.append(action("AUTOCOLOR_CMD"));
+  aList.append(action("RENAME_CMD"));
+  aList.append(action("COLOR_CMD"));
+  aList.append(action("DEFLECTION_CMD"));
+  aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(action("SHOW_ISOLINES_CMD"));
+  aList.append(action("ISOLINES_CMD"));
+  aList.append(action("SHOW_FEATURE_CMD"));
+  aList.append(mySeparator3);
+  aList.append(action("DELETE_CMD"));
+  // Group menu
+  myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
   //-------------------------------------
   // Feature menu
   aList.clear();
index 79ccfdc050b47a5b90a3c7cfcbb27b9f24df7b30..6208ca5eb731ea9217db4559867258cfdb966472 100644 (file)
 #include <QSpinBox>
 #include <QDialogButtonBox>
 
+#include <sstream>
 #include <iterator>
 
 #ifdef TINSPECTOR
@@ -1740,6 +1741,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     moveObjects(theId == "MOVE_SPLIT_CMD");
   else if (theId == "COLOR_CMD")
     changeColor(aObjects);
+  else if (theId == "AUTOCOLOR_CMD")
+    changeAutoColor(aObjects);
   else if (theId == "ISOLINES_CMD")
     changeIsoLines(aObjects);
   else if (theId == "SHOW_ISOLINES_CMD") {
@@ -2429,6 +2432,15 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
 
     return hasResults(aObjects, aTypes);
   }
+  if (theActionName == "AUTOCOLOR_CMD") {
+
+    QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+
+    std::set<std::string> aTypes;
+    aTypes.insert(ModelAPI_ResultGroup::group());
+
+    return hasResults(aObjects, aTypes);
+  }
   return false;
 }
 
@@ -2521,6 +2533,62 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   myViewerProxy->update();
 }
 
+//**************************************************************
+void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
+{
+  if (!abortAllOperations())
+  return;
+
+  std::vector<int> aColor = XGUI_ColorDialog::randomColor();
+
+  // abort the previous operation and start a new one
+  SessionPtr aMgr = ModelAPI_Session::get();
+  QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text();
+  aMgr->startOperation(aDescription.toStdString());
+
+  Config_Prop* aProp = Config_PropManager::findProp("Visualization", "result_group_color");
+
+  if( aDescription == tr("Disable auto color"))
+  {
+     contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color") );
+
+    aProp->setValue(ModelAPI_ResultGroup::DEFAULT_COLOR());
+
+  }else{
+    std::stringstream streamColor;
+    streamColor<< aColor[0] <<","<< aColor[1] <<"," <<aColor[2];
+
+    /*Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
+                                                          Config_Prop::Color, streamColor.str());*/
+
+    aProp->setValue(streamColor.str());
+
+    /* set the value to all results
+    foreach(ObjectPtr anObj, theObjects) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+      if (aResult.get() != NULL) {
+        //aResult->setAutocolor(true); 
+        //ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+        ResultBodyPtr aBodyResult = ModelAPI_Tools::bodyOwner(aResult,true);
+        if (aBodyResult.get() != NULL) { // change colors for all sub-solids
+          std::list<ResultPtr> allRes;
+          ModelAPI_Tools::allSubs(aBodyResult, allRes);
+          for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+            //(*aRes)->setAutocolor(true); 
+            ModelAPI_Tools::setColor(*aRes,  aColor);
+          }
+        }
+        ModelAPI_Tools::setColor(aResult, aColor);
+      }
+    }*/
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    aMgr->finishOperation();
+    updateCommandStatus();
+    myViewerProxy->update();
+    contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color") );
+  }
+}
+
 //**************************************************************
 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
 {
index 7b996aaa49268e6292d1770014f5284fd971163e..0190b0c581e91cf2f47b8ea8afff3f73f887294b 100644 (file)
@@ -203,6 +203,11 @@ Q_OBJECT
   /// theObjects a list of selected objects
   void changeColor(const QObjectPtrList& theObjects);
 
+  /// Change Autocolor of the results if it is possible
+  /// The operation is available for group results
+  /// theObjects a list of selected objects
+  void changeAutoColor(const QObjectPtrList& theObjects);
+
   /// 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