From: vsr Date: Mon, 10 Sep 2012 14:53:02 +0000 (+0000) Subject: 0021786: [CEA 620] AutoColor fails X-Git-Tag: V6_6_0a1~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ca71ca22553f4daf184d388a34de348ffcc0b39;p=modules%2Fgeom.git 0021786: [CEA 620] AutoColor fails Add code to enable auto-color feature for all sub-shapes (disabled currently) --- diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 15f36281d..926532302 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -114,6 +114,10 @@ #include #endif +// 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 + //================================================================ // Function : getActiveStudy // Purpose : Get active study, returns 0 if no open study frame @@ -2003,48 +2007,75 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo hasColor = false; SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); + SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( app && !theGeomObject->_is_nil()) { SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); if ( study ) { + _PTR(Study) aStudy = study->studyDS(); aSColor = theGeomObject->GetColor(); hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; - if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for 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() ) - { + 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; - - SalomeApp_Application* app = dynamic_cast( app ); + CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); if ( strcmp(IOR.in(), "") != 0 ) - { - _PTR(Study) aStudy = study->studyDS(); - _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) ); - _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; - - if( aChildObject->GetType() != GEOM_GROUP ) - continue; - - SALOMEDS::Color aReservedColor = aChildObject->GetColor(); - aReservedColors.append( aReservedColor ); - } - } - + { + _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) ); + _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; + + if( aChildObject->GetType() != GEOM_GROUP ) + continue; + + SALOMEDS::Color aReservedColor = aChildObject->GetColor(); + if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 ) + aReservedColors.append( aReservedColor ); + } + } + aSColor = getUniqueColor( aReservedColors ); hasColor = true; } + } +#endif } } }