From cb660529ca8aa55bc8aa04595fb118fc1c8e7b67 Mon Sep 17 00:00:00 2001 From: caremoli Date: Thu, 9 Dec 2010 14:24:20 +0000 Subject: [PATCH] CCAR: optimize SOCC_Viewer setColor, setTransparency and switchRepresentation speed by using entry2aisobjects map to get fast access to ais objects --- src/SOCC/SOCC_ViewModel.cxx | 72 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/SOCC/SOCC_ViewModel.cxx b/src/SOCC/SOCC_ViewModel.cxx index 968a03536..ab5e2829f 100755 --- a/src/SOCC/SOCC_ViewModel.cxx +++ b/src/SOCC/SOCC_ViewModel.cxx @@ -207,21 +207,21 @@ bool SOCC_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& obj ) void SOCC_Viewer::setColor( const Handle(SALOME_InteractiveObject)& obj, const QColor& color, bool update ) { - AIS_ListOfInteractive List; - getAISContext()->DisplayedObjects(List); - - AIS_ListIteratorOfListOfInteractive ite(List); - for ( ; ite.More(); ite.Next() ) - { - Handle(SALOME_InteractiveObject) anObj = - Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() ); + if(obj.IsNull() || !obj->hasEntry() ) + return; - if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) ) + if(entry2aisobjects.count(obj->getEntry())>0) { - OCCViewer_Viewer::setColor( ite.Value(), color, update ); - return; + // get context + Handle (AIS_InteractiveContext) ic = getAISContext(); + std::vector& List = entry2aisobjects[obj->getEntry()]; + for( unsigned int ind = 0; ind < List.size(); ind++ ) + { + Handle(AIS_InteractiveObject) anAIS=List[ind]; + if( !anAIS.IsNull() && ic->IsDisplayed(anAIS)) + OCCViewer_Viewer::setColor( anAIS, color, update ); + } } - } } /*! @@ -233,21 +233,21 @@ void SOCC_Viewer::setColor( const Handle(SALOME_InteractiveObject)& obj, void SOCC_Viewer::switchRepresentation( const Handle(SALOME_InteractiveObject)& obj, int mode, bool update ) { - AIS_ListOfInteractive List; - getAISContext()->DisplayedObjects(List); - - AIS_ListIteratorOfListOfInteractive ite(List); - for ( ; ite.More(); ite.Next() ) - { - Handle(SALOME_InteractiveObject) anObj = - Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() ); + if(obj.IsNull() || !obj->hasEntry() ) + return; - if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) ) + if(entry2aisobjects.count(obj->getEntry())>0) { - OCCViewer_Viewer::switchRepresentation( ite.Value(), mode, update ); - return; + // get context + Handle (AIS_InteractiveContext) ic = getAISContext(); + std::vector& List = entry2aisobjects[obj->getEntry()]; + for( unsigned int ind = 0; ind < List.size(); ind++ ) + { + Handle(AIS_InteractiveObject) anAIS=List[ind]; + if( !anAIS.IsNull() && ic->IsDisplayed(anAIS)) + OCCViewer_Viewer::switchRepresentation( anAIS, mode, update ); + } } - } } /*! @@ -259,21 +259,21 @@ void SOCC_Viewer::switchRepresentation( const Handle(SALOME_InteractiveObject)& void SOCC_Viewer::setTransparency( const Handle(SALOME_InteractiveObject)& obj, float trans, bool update ) { - AIS_ListOfInteractive List; - getAISContext()->DisplayedObjects( List ); - - AIS_ListIteratorOfListOfInteractive ite( List ); - for ( ; ite.More(); ite.Next() ) - { - Handle(SALOME_InteractiveObject) anObj = - Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() ); + if(obj.IsNull() || !obj->hasEntry() ) + return; - if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) ) + if(entry2aisobjects.count(obj->getEntry())>0) { - OCCViewer_Viewer::setTransparency( ite.Value(), trans, update ); - return; + // get context + Handle (AIS_InteractiveContext) ic = getAISContext(); + std::vector& List = entry2aisobjects[obj->getEntry()]; + for( unsigned int ind = 0; ind < List.size(); ind++ ) + { + Handle(AIS_InteractiveObject) anAIS=List[ind]; + if( !anAIS.IsNull() && ic->IsDisplayed(anAIS)) + OCCViewer_Viewer::setTransparency( anAIS, trans, update ); + } } - } } /*! -- 2.39.2