]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
0021786: [CEA 620] AutoColor fails
authorvsr <vsr@opencascade.com>
Mon, 10 Sep 2012 14:53:02 +0000 (14:53 +0000)
committervsr <vsr@opencascade.com>
Mon, 10 Sep 2012 14:53:02 +0000 (14:53 +0000)
Add code to enable auto-color feature for all sub-shapes (disabled currently)

src/GEOMGUI/GEOM_Displayer.cxx

index 15f36281d67895429c2b57ed8cf5df29377ad803..926532302b9cb41ed0b2422ba960cd6c57cd3d09 100644 (file)
 #include <Graphic3d_HArray1OfBytes.hxx>
 #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<SalomeApp_Application*>( session->activeApplication() );
 
   if ( app && !theGeomObject->_is_nil()) {
     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( 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<SALOMEDS::Color> 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<SALOMEDS::Color> aReservedColors;
-
-            SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( 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
       }
     }
   }