Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Displayer.cxx
index e53d6bc7a3cc6f1275c9311b41b4389ce4232c40..045b7db3c5e904f43d05d5d7f27497ac51058f89 100644 (file)
 #include "HYDROGUI_Prs.h"
 #include "HYDROGUI_PrsImageDriver.h"
 #include "HYDROGUI_PrsPolylineDriver.h"
+#include "HYDROGUI_PrsZoneDriver.h"
 #include "HYDROGUI_Tool.h"
 
 #include <GraphicsView_Viewer.h>
 #include <GraphicsView_ViewPort.h>
 
 HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
-: myModule( theModule )
+: HYDROGUI_AbstractDisplayer( theModule )
 {
 }
 
@@ -44,7 +45,7 @@ HYDROGUI_Displayer::~HYDROGUI_Displayer()
 void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
                                       const int theViewerId )
 {
-  GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+  GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
   if( !aViewer )
     return;
 
@@ -55,7 +56,7 @@ void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs
   GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
   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;
 
@@ -64,18 +65,9 @@ void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs
   }
 }
 
-void HYDROGUI_Displayer::UpdateAll( const int theViewerId,
-                                    const bool theIsInit,
-                                    const bool theIsForced )
-{
-  if( theIsInit )
-    EraseAll( theViewerId );
-  DisplayAll( theViewerId, theIsForced );
-}
-
 void HYDROGUI_Displayer::EraseAll( const int theViewerId )
 {
-  GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+  GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
   if( !aViewer )
     return;
 
@@ -94,43 +86,10 @@ void HYDROGUI_Displayer::EraseAll( const int theViewerId )
   }
 }
 
-void HYDROGUI_Displayer::DisplayAll( const int theViewerId,
-                                     const bool theIsForced )
-{
-  HYDROData_SequenceOfObjects aSeq;
-  HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq );
-  Update( aSeq, theViewerId, theIsForced );
-}
-
-void HYDROGUI_Displayer::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 );
-}
-
 void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
                                 const int theViewerId )
 {
-  GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+  GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
   if( !aViewer )
     return;
 
@@ -138,17 +97,18 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
   if( !aViewPort )
     return;
 
-  HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
+  HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)module()->dataModel();
   if( aModel ) 
   {
     GraphicsView_ObjectList anObjectList = HYDROGUI_Tool::GetPrsList( aViewPort );
     for( int i = 1, n = theObjs.Length(); i <= n; i++ )
     {
       // the object may be null or dead
-      const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
+      const Handle(HYDROData_Entity)& anObj = theObjs.Value( i );
       if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
       {
         aViewPort->removeItem( aPrs );
+        anObjectList.removeAll( aPrs );
         delete aPrs;
       }
     }
@@ -157,9 +117,10 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
 
 void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
                                   const int theViewerId,
-                                  const bool theIsForced )
+                                  const bool theIsForced,
+                                  const bool theDoFitAll)
 {
-  GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+  GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
   if( !aViewer )
     return;
 
@@ -171,7 +132,7 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
   GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
   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;
 
@@ -189,17 +150,21 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
 
     if( aPrs )
     {
-      bool anIsVisible = anObj->IsVisible( (size_t)aViewer );
+      bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
       aPrs->setVisible( anIsVisible );
     }
   }
 
-  aViewPort->fitAll();
+  aViewPort->onBoundingRectChanged(); // specific of HYDRO module
+  if ( theDoFitAll )
+  {
+    aViewPort->fitAll();
+  }
 }
 
 void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
 {
-  GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+  GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
   if( !aViewer )
     return;
 
@@ -212,7 +177,7 @@ void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
   {
     if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
     {
-      Handle(HYDROData_Object) anObject = aPrs->getObject();
+      Handle(HYDROData_Entity) anObject = aPrs->getObject();
       if( !anObject.IsNull() && anObject->IsRemoved() )
       {
         aViewPort->removeItem( aPrs );
@@ -222,7 +187,7 @@ void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
   }
 }
 
-HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object)& theObj )
+HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity)& theObj )
 {
   HYDROGUI_PrsDriver* aDriver = NULL;
   ObjectKind aKind = theObj->GetKind();
@@ -235,15 +200,25 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object
     {
       case KIND_IMAGE:
         aDriver = new HYDROGUI_PrsImageDriver();
-        myPrsDriversMap[ aKind ] = aDriver;
         break;
       case KIND_POLYLINE:
         aDriver = new HYDROGUI_PrsPolylineDriver();
-        myPrsDriversMap[ aKind ] = aDriver;
+        break;
+      case KIND_ZONE:
+        aDriver = new HYDROGUI_PrsZoneDriver();
         break;
       default:
         break;
     }
+
+    if ( aDriver )
+      myPrsDriversMap[ aKind ] = aDriver;
   }
+
   return aDriver;
 }
+
+QString HYDROGUI_Displayer::GetType() const
+{
+  return GraphicsView_Viewer::Type();
+}