X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_OCCDisplayer.cxx;h=3dbe862ccf5f9ab5d9b88fc8a76b5a526482f7dc;hb=f34b90e9e4e02ba65419134d5d37a2e42aecfabf;hp=8be446e4555cf90efa0fb637b9aaec86989e9f9b;hpb=ca0e09c1e1bb19c9855e2f3839243da36097ee1c;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 8be446e4..3dbe862c 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -31,14 +31,14 @@ #include #include +#include + #include #include #include -#include - HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule ) -: myModule( theModule ) +: HYDROGUI_AbstractDisplayer( theModule ) { } @@ -49,17 +49,17 @@ HYDROGUI_OCCDisplayer::~HYDROGUI_OCCDisplayer() void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId ) { - OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId ); + OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId ); if( !aViewer ) return; for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; - HYDROGUI_Shape* anObjShape = myModule->getObjectShape( (size_t)aViewer, anObj ); + HYDROGUI_Shape* anObjShape = module()->getObjectShape( (size_t)aViewer, anObj ); if ( !anObjShape ) continue; @@ -67,100 +67,56 @@ void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theO } } -void HYDROGUI_OCCDisplayer::UpdateAll( const int theViewerId, - const bool theIsInit, - const bool theIsForced ) -{ - if ( theIsInit ) - EraseAll( theViewerId ); - - DisplayAll( theViewerId, theIsForced ); -} - void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId ) { - OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId ); + OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId ); if( !aViewer ) return; - myModule->removeViewShapes( (size_t)aViewer ); -} - -void HYDROGUI_OCCDisplayer::DisplayAll( const int theViewerId, - const bool theIsForced ) -{ - HYDROData_SequenceOfObjects aSeq; - HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq ); - Update( aSeq, theViewerId, theIsForced ); -} - -void HYDROGUI_OCCDisplayer::Update( const HYDROData_SequenceOfObjects& theObjs, - const int theViewerId, - const bool theIsForced ) -{ - // First of all, kill all bad presentations - purgeObjects( theViewerId ); - - // Now dig in the data model - HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay; - - for( int i = 1, n = theObjs.Length(); i <= n; i++ ) - { - const Handle(HYDROData_Object)& anObj = theObjs.Value( i ); - if( anObj.IsNull() ) - anObjectsToErase.Append( anObj ); - else - anObjectsToDisplay.Append( anObj ); - } - - if( anObjectsToErase.Length() ) - Erase( anObjectsToErase, theViewerId ); - if( anObjectsToDisplay.Length() ) - Display( anObjectsToDisplay, theViewerId, theIsForced ); + module()->removeViewShapes( (size_t)aViewer ); } void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId ) { - OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId ); + OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId ); if( !aViewer ) return; for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); if( anObj.IsNull() ) continue; - myModule->removeObjectShape( (size_t)aViewer, anObj ); + module()->removeObjectShape( (size_t)aViewer, anObj ); } + aViewer->update(); } HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId, const Handle(AIS_InteractiveContext)& theContext, - const Handle(HYDROData_Object)& theObject ) + const Handle(HYDROData_Entity)& theObject ) { HYDROGUI_Shape* aResShape = NULL; if ( theContext.IsNull() || theObject.IsNull() ) return aResShape; - ObjectKind anObjectKind = theObject->GetKind(); - if ( anObjectKind != KIND_IMAGE && - anObjectKind != KIND_POLYLINE && - anObjectKind != KIND_ZONE ) + if ( !HYDROGUI_Tool::IsObjectHasPresentation( theObject, OCCViewer_Viewer::Type() ) ) return aResShape; aResShape = new HYDROGUI_Shape( theContext, theObject ); - myModule->setObjectShape( theViewerId, theObject, aResShape ); + module()->setObjectShape( theViewerId, theObject, aResShape ); return aResShape; } void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId, - const bool theIsForced ) + const bool theIsForced, + const bool theDoFitAll ) { - OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId ); + OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId ); if( !aViewer ) return; @@ -168,13 +124,37 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( aCtx.IsNull() ) return; - for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) + // Sort objects by display order ( needed for Z layers assignment only ) + HYDROData_SequenceOfObjects anObjects; + int aMaxIndex = -1; + for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { + Handle(HYDROData_Entity) anObj = theObjs.Value( i ); + if ( anObj.IsNull() || anObj->IsRemoved() ) { + continue; + } + + int aDisplayOrderIndex = module()->getObjectDisplayOrder( (size_t)aViewer, anObj ); + if ( aDisplayOrderIndex > aMaxIndex ) { + anObjects.Append( anObj ); + aMaxIndex = aDisplayOrderIndex; + } else { + anObjects.Prepend( anObj ); + } + } + + // Get existing Z layers + TColStd_SequenceOfInteger anExistingZLayers; + aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers ); + int aNbLayers = anExistingZLayers.Length(); + + // Display + for ( int i = 1, n = anObjects.Length(); i <= n; i++ ) { - Handle(HYDROData_Object) anObj = theObjs.Value( i ); + Handle(HYDROData_Entity) anObj = anObjects.Value( i ); if ( anObj.IsNull() || anObj->IsRemoved() ) continue; - HYDROGUI_Shape* anObjShape = myModule->getObjectShape( (size_t)aViewer, anObj ); + HYDROGUI_Shape* anObjShape = module()->getObjectShape( (size_t)aViewer, anObj ); if ( !anObjShape || anObjShape->getIsToUpdate() || theIsForced ) { @@ -187,28 +167,44 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, if ( anObjShape ) { - bool anIsVisible = myModule->isObjectVisible( (size_t)aViewer, anObj ); + bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj ); anObjShape->setVisible( anIsVisible, false ); + + // Set Z layer + Standard_Integer aLayerId = -1; + if ( i <= aNbLayers ) { + aLayerId = anExistingZLayers.Value( i ); + } else { + Standard_Integer aNewId = -1; + if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) { + aLayerId = aNewId; + } + } + if ( aLayerId >= 0 ) { + aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId ); + } } } - OCCViewer_ViewManager* aViewManager - = ::qobject_cast( aViewer->getViewManager() ); - if ( aViewManager ) + if ( theDoFitAll ) { - OCCViewer_ViewWindow* aViewWindow = - ::qobject_cast( aViewManager->getActiveView() ); - if ( aViewWindow ) + OCCViewer_ViewManager* aViewManager + = ::qobject_cast( aViewer->getViewManager() ); + if ( aViewManager ) { - QApplication::processEvents(); //Process the draw events for viewer - aViewWindow->onFitAll(); + OCCViewer_ViewWindow* aViewWindow = + ::qobject_cast( aViewManager->getActiveView() ); + if ( aViewWindow ) + { + aViewWindow->onFitAll(); + } } } } void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) { - OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId ); + OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId ); if( !aViewer ) return; @@ -226,11 +222,14 @@ void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId ) if ( aPrsObj.IsNull() ) continue; - Handle(HYDROData_Object) anOwnerObj = - Handle(HYDROData_Object)::DownCast( aPrsObj->GetOwner() ); + Handle(HYDROData_Entity) anOwnerObj = + Handle(HYDROData_Entity)::DownCast( aPrsObj->GetOwner() ); if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() ) - myModule->removeObjectShape( (size_t)aViewer, anOwnerObj ); + module()->removeObjectShape( (size_t)aViewer, anOwnerObj ); } } - +QString HYDROGUI_OCCDisplayer::GetType() const +{ + return OCCViewer_Viewer::Type(); +}