From 0a03bb22304839a6454de777d4c10c26f40784b9 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 13 Sep 2012 08:17:44 +0000 Subject: [PATCH] 0021786: [CEA 620] AutoColor fails - Add code to enable auto-color for all sub-shapes (currenly disabled) - Add code to use simplified auto-coloring algorithm (currenly disabled) --- src/GEOMGUI/GEOM_Displayer.cxx | 106 ++++++++++++++++------------ src/GEOMGUI/GEOM_Displayer.h | 1 + src/GEOMToolsGUI/GEOMToolsGUI_1.cxx | 15 +++- 3 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 926532302..7edbae5b2 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -114,9 +114,12 @@ #include #endif -// if the next macro is defined, autocolor feature works for all sub-shapes; +// If the next macro is defined, autocolor feature works for all sub-shapes; // if it is undefined, autocolor feature works for groups only //#define GENERAL_AUTOCOLOR +// Below macro, when uncommented, switches on simplified (more performant) algorithm +// of auto-color picking up +//#define SIMPLE_AUTOCOLOR //================================================================ // Function : getActiveStudy @@ -1827,6 +1830,40 @@ int GEOM_Displayer::UnsetDisplayMode() return aPrevMode; } +SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor() +{ + static QList colors; + + if ( colors.isEmpty() ) { + const int rfactor = 4; // red color component split factor, must be > 0 + const int gfactor = 4; // green color component split factor, must be > 0 + const int bfactor = 3; // blue color component split factor, must be > 0 + // - + // total number of pre-defined colors is defined as + // nbcolors = rfactor * gfactor * bfactor + // NB: all three factors should not have same values + // otherwise all colors will be greyish + + for ( int g = 0; g < gfactor; g++ ) { + for ( int r = 0; r < rfactor; r++ ) { + for ( int b = 0; b < bfactor; b++ ) + colors.append( QColor( qRgb( r * 255 / (rfactor-1), g * 255 / (gfactor-1), b * 255 / (bfactor-1) ) ) ); + } + } + } + + static int currentColor = 0; + + SALOMEDS::Color color; + color.R = (double)colors[currentColor].red() / 255.0; + color.G = (double)colors[currentColor].green() / 255.0; + color.B = (double)colors[currentColor].blue() / 255.0; + + currentColor = (currentColor+1) % colors.count(); + + return color; +} + SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& theReservedColors ) { int aHue = -1; @@ -2018,51 +2055,27 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; if ( !hasColor ) { #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes - GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape(); - if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) { - QList aReservedColors; - CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); - _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) ); - if ( aMainSObject ) { - _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); - for ( ; it->More(); it->Next() ) { - _PTR(SObject) aChildSObject( it->Value() ); - GEOM::GEOM_Object_var aChildObject = - GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); - if ( CORBA::is_nil( aChildObject ) ) - continue; - - SALOMEDS::Color aReservedColor = aChildObject->GetColor(); - if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 ) - aReservedColors.append( aReservedColor ); - } - } - aSColor = getUniqueColor( aReservedColors ); - hasColor = true; - } -#else // auto-color for groups only - if ( theGeomObject->GetType() == GEOM_GROUP ) { - GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen(); - GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() ); - GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject ); - if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() ) - { - QList aReservedColors; - - CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); - if ( strcmp(IOR.in(), "") != 0 ) - { - _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) ); + bool general_autocolor = true; +#else // auto-color for groups only + bool general_autocolor = false; +#endif // GENERAL_AUTOCOLOR + if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) { + GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape(); + if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) { +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + aSColor = getPredefinedUniqueColor(); + hasColor = true; +#else // old algorithm for auto-colors + QList aReservedColors; + CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); + _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) ); + if ( aMainSObject ) { _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); - for( ; it->More(); it->Next() ) - { + for ( ; it->More(); it->Next() ) { _PTR(SObject) aChildSObject( it->Value() ); GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); - if( CORBA::is_nil( aChildObject ) ) - continue; - - if( aChildObject->GetType() != GEOM_GROUP ) + if ( CORBA::is_nil( aChildObject ) ) continue; SALOMEDS::Color aReservedColor = aChildObject->GetColor(); @@ -2070,12 +2083,11 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo aReservedColors.append( aReservedColor ); } } - - aSColor = getUniqueColor( aReservedColors ); - hasColor = true; - } + aSColor = getUniqueColor( aReservedColors ); + hasColor = true; +#endif // SIMPLE_AUTOCOLOR + } } -#endif } } } diff --git a/src/GEOMGUI/GEOM_Displayer.h b/src/GEOMGUI/GEOM_Displayer.h index 07305f66b..656612776 100644 --- a/src/GEOMGUI/GEOM_Displayer.h +++ b/src/GEOMGUI/GEOM_Displayer.h @@ -169,6 +169,7 @@ public: SalomeApp_Study* getStudy() const; static SALOMEDS::Color getUniqueColor( const QList& ); + static SALOMEDS::Color getPredefinedUniqueColor(); static PropMap getDefaultPropertyMap(const QString& viewer_type); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index cd95307a6..a0885473f 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -109,6 +109,13 @@ // VTK includes #include +// If the next macro is defined, autocolor feature works for all sub-shapes; +// if it is undefined, autocolor feature works for groups only +//#define GENERAL_AUTOCOLOR +// Below macro, when uncommented, switches on simplified (more performant) algorithm +// of auto-color picking up +//#define SIMPLE_AUTOCOLOR + void GEOMToolsGUI::OnCheckGeometry() { SalomeApp_Application* app = @@ -163,12 +170,18 @@ void GEOMToolsGUI::OnAutoColor() if( CORBA::is_nil( aChildObject ) ) continue; +#ifndef GENERAL_AUTOCOLOR // auto-color for groups only if( aChildObject->GetType() != GEOM_GROUP ) continue; +#endif // GENERAL_AUTOCOLOR +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor(); +#else // old algorithm for auto-colors SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors ); - aChildObject->SetColor( aColor ); aReservedColors.append( aColor ); +#endif // SIMPLE_AUTOCOLOR + aChildObject->SetColor( aColor ); QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) ); -- 2.39.2