From ddc98ff4c07102d02c70572766261560a0a34e95 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 21 Jan 2011 12:20:52 +0000 Subject: [PATCH] 0021136: EDF 1748 SMESH: SetAutoColor has no effect in a python script --- src/SMESHGUI/SMESHGUI.cxx | 11 ++-------- src/SMESH_I/SMESH_Mesh_i.cxx | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index f314db7f8..7ef1989b4 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -695,20 +695,13 @@ if( aMainObject->_is_nil() ) return; - aMainObject->SetAutoColor( true ); - - QList aReservedColors; + aMainObject->SetAutoColor( true ); // mesh groups are re-colored here SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups(); for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) { SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i]; - SALOMEDS::Color aCurrentColor = aGroupObject->GetColor(); - - SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors ); - aGroupObject->SetColor( aColor ); - aReservedColors.append( aColor ); - + SALOMEDS::Color aColor = aGroupObject->GetColor(); _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject); if (aGroupSObject) { if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) { diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 1733a315e..1019e5273 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -2302,6 +2302,36 @@ CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard() throw(SALOME::SALOME_Ex return _impl->HasModificationsToDiscard(); } +static SALOMEDS::Color getUniqueColor( const std::list& theReservedColors ) +{ + const int MAX_ATTEMPTS = 100; + int cnt = 0; + double tolerance = 0.5; + SALOMEDS::Color col; + + bool ok = false; + while ( !ok ) { + // generate random color + double red = (double)rand() / RAND_MAX; + double green = (double)rand() / RAND_MAX; + double blue = (double)rand() / RAND_MAX; + // check existence in the list of the existing colors + bool matched = false; + std::list::const_iterator it; + for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) { + SALOMEDS::Color color = *it; + double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue ); + matched = tol < tolerance; + } + if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2; + ok = ( ++cnt == MAX_ATTEMPTS ) || !matched; + col.R = red; + col.G = green; + col.B = blue; + } + return col; +} + //============================================================================= /*! * @@ -2311,6 +2341,15 @@ void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOM { Unexpect aCatch(SALOME_SalomeException); _impl->SetAutoColor(theAutoColor); + + std::list aReservedColors; + map::iterator it = _mapGroups.begin(); + for ( ; it != _mapGroups.end(); it++ ) { + if ( CORBA::is_nil( it->second )) continue; + SALOMEDS::Color aColor = getUniqueColor( aReservedColors ); + it->second->SetColor( aColor ); + aReservedColors.push_back( aColor ); + } } //=============================================================================