Salome HOME
Create goups for stream.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 8c8396d6624b33cc60e44e61f42c8f56f2aaec70..81eabc1f0c87b4c71c0fdc1c53acac2711aa8099 100644 (file)
@@ -39,6 +39,8 @@
 #include "HYDROGUI_VTKPrsDisplayer.h"
 #include "HYDROGUI_AbstractDisplayer.h"
 #include "HYDROGUI_PolylineOp.h"
+#include "HYDROGUI_SetColorOp.h"
+#include "HYDROGUI_ImportGeomObjectOp.h"
 
 #include <HYDROData_Image.h>
 #include <HYDROData_Profile.h>
@@ -153,6 +155,38 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
                               HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
 #endif
 
+  // Remove defunct view managers from the map.
+  // It's essential to do this before "update( UF_All )" call!
+  QList<int> anObsoleteIds;
+  ViewManagerList anAllViewManagers = anApp->viewManagers();
+  ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
+  ViewManagerMapIterator anIter( myViewManagerMap );
+  while( anIter.hasNext() ) {
+    int anId = anIter.next().key();
+    const ViewManagerInfo& anInfo = anIter.value();
+  
+    aHydroViewManagers << anInfo.first;
+
+    if ( !anAllViewManagers.contains( anInfo.first ) ) {
+      anObsoleteIds << anId;
+    }
+  }
+  foreach ( const int anId, anObsoleteIds ) {
+    myViewManagerMap.remove( anId );
+    myObjectStateMap.remove( anId );
+    myShapesMap.remove( anId );
+    myVTKPrsMap.remove( anId );
+  }
+  // Replace the default selector for all view managers.
+  // Add view managers created outside of HYDRO module to the map.
+  foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
+    createSelector( aViewManager ); // replace the default selector
+    if ( !aHydroViewManagers.contains( aViewManager ) ) {
+      ViewManagerInfo anInfo( aViewManager, VMR_General );
+      myViewManagerMap.insert( ViewManagerId++, anInfo );
+    }
+  }
+
   update( UF_All );
 
   updateCommandsStatus();
@@ -180,11 +214,13 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 
 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 {
+  /* Issues ## 68, 88.
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
     if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
       getApp()->removeViewManager( aViewManager );
   myViewManagerMap.clear();
+  */
 
   ViewManagerList anOCCViewManagers;
   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
@@ -193,9 +229,11 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
   }
 
+  /* Issues ## 68, 88.
   myObjectStateMap.clear();
   myShapesMap.clear();
   myVTKPrsMap.clear();
+  */
 
   // clear the data model's list of copying objects
   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
@@ -225,7 +263,7 @@ void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 
 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
 {
-  theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
+  theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
 }
 
 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
@@ -253,7 +291,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsFusedImage = false;
   bool anIsCutImage = false;
   bool anIsSplittedImage = false;
-  bool anIsMustBeUpdatedImage = false;
+  bool anIsMustObjectBeUpdated = false;
   bool anIsPolyline = false;
   bool anIsPolyline3D = false;
   bool anIsProfile = false;
@@ -268,12 +306,34 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsObstacle = false;
   bool anIsStream = false;
   bool anIsChannel = false;
-  bool anIsGeomObject = false;
-
-  // check the selected GEOM objects
-  if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
-    theMenu->addAction( action( ImportGeomObjectId ) );
-    theMenu->addSeparator();
+  bool anIsDigue = false;
+  bool anIsDummyObject3D = false;
+  bool anIsObjectCanBeColored = false;
+
+  // Check the selected GEOM objects (take into account the Object Browser only)
+  if ( anIsObjectBrowser ) {
+    QList<GEOM::shape_type> anObstacleTypes = 
+      HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
+    QList<GEOM::shape_type> aPolylineTypes = 
+      HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
+
+    bool isCanBeImportedAsObstacle = 
+      !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
+    bool isCanBeImportedAsPolyline = 
+      !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
+
+    // Add import as obstacle action
+    if ( isCanBeImportedAsObstacle ) {
+      theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
+    }
+    // Add import as polyline action
+    if ( isCanBeImportedAsPolyline ) {
+      theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
+    }
+    // Add separator
+    if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
+      theMenu->addSeparator();
+    }
   }
 
   // check the selected data model objects
@@ -290,6 +350,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       anIsVisibleInSelection |= aVisibility;
       anIsHiddenInSelection |= !aVisibility;
 
+      if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
+      {
+        anIsMustObjectBeUpdated = true;
+      }
+
       ObjectKind anObjectKind = anObject->GetKind();
       if( anObjectKind == KIND_IMAGE )
       {
@@ -312,10 +377,6 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
                 anIsSplittedImage = true;
             }
           }
-          if ( anImage->IsMustBeUpdated() )
-          {
-            anIsMustBeUpdatedImage = true;
-          }
         }
       }
       else if( anObjectKind == KIND_POLYLINEXY )
@@ -351,9 +412,14 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsStream = true;
       else if( anObjectKind == KIND_CHANNEL )
         anIsChannel = true;
+      else if( anObjectKind == KIND_DIGUE )
+        anIsDigue = true;
+      else if( anObjectKind == KIND_DUMMY_3D )
+        anIsDummyObject3D = true;
     }
 
-    anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
+    if ( !anIsObjectCanBeColored )
+      anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
   }
 
   // Check if all selected objects are profiles
@@ -376,6 +442,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
           break;
         case KIND_ARTIFICIAL_OBJECT:
           theMenu->addAction( action( CreateChannelId ) );
+          theMenu->addAction( action( CreateDigueId ) );
           break;
         case KIND_NATURAL_OBJECT:
           theMenu->addAction( action( CreateImmersibleZoneId ) );
@@ -410,9 +477,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   if( anIsSelectedDataObjects )
   {
-    if ( anIsMustBeUpdatedImage )
+    if ( anIsMustObjectBeUpdated )
     {
-      theMenu->addAction( action( UpdateImageId ) );
+      theMenu->addAction( action( UpdateObjectId ) );
       theMenu->addSeparator();
     }
 
@@ -432,7 +499,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
             theMenu->addAction( action( EditSplittedImageId ) );
         }
 
-        theMenu->addAction( action( ObserveImageId ) );
+        //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
         theMenu->addAction( action( ExportImageId ) );
         theMenu->addSeparator();
 
@@ -447,6 +514,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitImageId ) );
         theMenu->addSeparator();
       }
+      else if( anIsBathymetry )
+      {
+        theMenu->addAction( action( EditImportedBathymetryId ) );
+        theMenu->addSeparator();
+      }
       else if( anIsPolyline )
       {
         theMenu->addAction( action( EditPolylineId ) );
@@ -484,6 +556,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( EditChannelId ) );
         theMenu->addSeparator();
       }
+      else if( anIsDigue )
+      {
+        theMenu->addAction( action( EditDigueId ) );
+        theMenu->addSeparator();
+      }
       else if( anIsVisualState && anIsObjectBrowser )
       {
         theMenu->addAction( action( SaveVisualStateId ) );
@@ -492,7 +569,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       }
 
       // Add set color action for geometrical objects
-      if ( anIsGeomObject )
+      if ( anIsObjectCanBeColored )
       {
         theMenu->addAction( action( SetColorId ) );
         theMenu->addSeparator();
@@ -502,13 +579,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       theMenu->addSeparator();
     }
 
-    theMenu->addAction( action( DeleteId ) );
+    if( !anIsDummyObject3D )
+      theMenu->addAction( action( DeleteId ) );
     theMenu->addSeparator();
 
     if( anIsImage || anIsPolyline || anIsPolyline3D || 
         anIsImmersibleZone || anIsZone || anIsRegion ||
         anIsBathymetry || anIsObstacle || anIsStream ||
-        anIsChannel || anIsValidProfile )
+        anIsChannel || anIsDigue || anIsDummyObject3D ||
+        anIsValidProfile )
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -843,25 +922,28 @@ void HYDROGUI_Module::setObjectVTKPrs( const int                       theViewId
   if( theObject.IsNull() )
     return;
 
-  // Compute the new global Z range from the added presentation and the old global Z range.
-  double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
-  double* aRange = theShape->getInternalZRange();
-  bool anIsUpdate = false;
-  if ( aRange[0] < aGlobalRange[0] )
-  {
-    aGlobalRange[0] = aRange[0];
-    anIsUpdate = true;
-  }
-  if ( aRange[1] > aGlobalRange[1] )
+  if( theShape && theShape->needScalarBar() )
   {
-    aGlobalRange[1] = aRange[1];
-    anIsUpdate = true;
-  }
+    // Compute the new global Z range from the added presentation and the old global Z range.
+    double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
+    double* aRange = theShape->getInternalZRange();
+    bool anIsUpdate = false;
+    if ( aRange[0] < aGlobalRange[0] )
+    {
+      aGlobalRange[0] = aRange[0];
+      anIsUpdate = true;
+    }
+    if ( aRange[1] > aGlobalRange[1] )
+    {
+      aGlobalRange[1] = aRange[1];
+      anIsUpdate = true;
+    }
 
-  //if ( anIsUpdate )
-  //{
-    updateVTKZRange( theViewId, aGlobalRange );
-  //}
+    //if ( anIsUpdate )
+    //{
+      updateVTKZRange( theViewId, aGlobalRange );
+    //}
+  }
 
   ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
   aViewShapes.append( theShape );
@@ -920,7 +1002,7 @@ void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
     for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
     {
       aShape = aViewShapes.at( i );
-      if ( aShape )
+      if ( aShape && aShape->needScalarBar() )
       {
         aShape->setZRange( theRange );
       }
@@ -1044,7 +1126,7 @@ void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
       SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
       if ( aVTKViewer )
       {
-        getVTKDisplayer()->DeleteScalarBar( anId );
+        getVTKDisplayer()->EraseScalarBar( anId, true );
         removeViewShapes( (size_t)aVTKViewer );
       }
     }