From: Jérôme Date: Wed, 4 Nov 2020 17:37:19 +0000 (+0100) Subject: Implemetation of AutoColor X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ba4b1dc43e40aaf795890023887eeca7f77bb984;p=modules%2Fshaper.git Implemetation of AutoColor --- diff --git a/src/XGUI/XGUI_ColorDialog.cpp b/src/XGUI/XGUI_ColorDialog.cpp index a0f6a620e..471867ca3 100644 --- a/src/XGUI/XGUI_ColorDialog.cpp +++ b/src/XGUI/XGUI_ColorDialog.cpp @@ -189,3 +189,10 @@ std::vector XGUI_ColorDialog::getRandomColor() const } return aValues; } + +std::vector XGUI_ColorDialog::randomColor() +{ + std::vector aValues; + findRandomColor(aValues); + return aValues; +} diff --git a/src/XGUI/XGUI_ColorDialog.h b/src/XGUI/XGUI_ColorDialog.h index 150d178f7..69a7b6eb3 100644 --- a/src/XGUI/XGUI_ColorDialog.h +++ b/src/XGUI/XGUI_ColorDialog.h @@ -64,6 +64,12 @@ public: /// \return a vector of values std::vector 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 randomColor(); + private: QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice QtxColorButton* myColorButton; /// a control to select a color diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index d5b9bf15a..b701a7627 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5ca15dc33..3552f833f 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -151,6 +151,7 @@ #include #include +#include #include #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 aTypes; + aTypes.insert(ModelAPI_ResultGroup::group()); + + return hasResults(aObjects, aTypes); + } return false; } @@ -2490,6 +2502,62 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) myViewerProxy->update(); } +//************************************************************** +void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects) +{ + if (!abortAllOperations()) + return; + + std::vector 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] <<"," <setValue(streamColor.str()); + + /* set the value to all results + foreach(ObjectPtr anObj, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) { + //aResult->setAutocolor(true); + //ResultBodyPtr aBodyResult = std::dynamic_pointer_cast(aResult); + ResultBodyPtr aBodyResult = ModelAPI_Tools::bodyOwner(aResult,true); + if (aBodyResult.get() != NULL) { // change colors for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + for(std::list::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) { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index c503990f9..cf2e42e0c 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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