]> 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:40:25 +0000 (18:40 +0100)
committerJérôme <jerome.lucas@cesgenslab.fr>
Wed, 4 Nov 2020 17:40:25 +0000 (18:40 +0100)
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 a0f6a620e2523be397c922ebe17f1e60e953b68c..471867ca32238fe8760cd7fc234d8bb6337f8ac2 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 150d178f73194becaec816f846b3aa482f354fcd..69a7b6eb3f019142792e528e2cb20bf96bb766aa 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 d5b9bf15a782ee514f2f9a709c650e6fd01d5e3b..b701a7627899627d11052ce968754cca3b78a9c5 100644 (file)
@@ -112,6 +112,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);
 
@@ -502,6 +505,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);
@@ -681,10 +686,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 5ca15dc330cc3de54f38762468c5379594d7e8c6..2b6faca0f92bd7c0f61410fa4e4c01cd373751c4 100644 (file)
 #include <QSpinBox>
 #include <QDialogButtonBox>
 
+#include <sstream>
 #include <iterator>
 
 #ifdef TINSPECTOR
@@ -1704,6 +1705,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") {
@@ -2393,6 +2396,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;
 }
 
@@ -2490,6 +2502,41 @@ 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];
+
+    aProp->setValue(streamColor.str());
+
+    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 c503990f9671babb5fb79093e419705d31d0d3f5..cf2e42e0cc9a082f1619ca6f5cb7f249e2a244c5 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