Salome HOME
Fix for the bug #255: VTK viewer is not updated after modification of objects.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OCCDisplayer.cxx
index 8be446e4555cf90efa0fb637b9aaec86989e9f9b..39810702fbeaccabbfdbc72d8898469c6b6a041b 100644 (file)
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
 
-#include <QApplication>
-
 HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule )
-: myModule( theModule )
+: HYDROGUI_AbstractDisplayer( theModule )
 {
 }
 
@@ -49,17 +47,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 +65,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;
 
@@ -170,11 +124,11 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
 
   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() || 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 +141,30 @@ 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 );
     }
   }
 
-  OCCViewer_ViewManager* aViewManager
-    = ::qobject_cast<OCCViewer_ViewManager*>( aViewer->getViewManager() );
-  if ( aViewManager )
+  if ( theDoFitAll )
   {
-    OCCViewer_ViewWindow* aViewWindow = 
-      ::qobject_cast<OCCViewer_ViewWindow*>( aViewManager->getActiveView() );
-    if ( aViewWindow )
+    OCCViewer_ViewManager* aViewManager
+      = ::qobject_cast<OCCViewer_ViewManager*>( aViewer->getViewManager() );
+    if ( aViewManager )
     {
-      QApplication::processEvents(); //Process the draw events for viewer
-      aViewWindow->onFitAll();
+      OCCViewer_ViewWindow* aViewWindow = 
+        ::qobject_cast<OCCViewer_ViewWindow*>( 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 +182,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();
+}