Salome HOME
lots 3,8 - corrections
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 3a3d2b642aa51a645537b710c5f555b7a8b54097..f9bdea57ac2d9310178b7d135e9bb59d22673a77 100644 (file)
@@ -41,7 +41,7 @@
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ShowHideOp.h"
 #include "HYDROGUI_Overview.h"
-
+#include <HYDROGUI_ProfileDlg.h>
 #include <HYDROData_Tool.h>
 #include <HYDROData_Image.h>
 #include <HYDROData_Stream.h>
@@ -49,6 +49,8 @@
 #include <HYDROData_Lambert93.h>
 #include <HYDROData_Polyline3D.h>
 #include <HYDROData_StricklerTable.h>
+#include <HYDROData_ArtificialObject.h>
+#include <HYDROData_NaturalObject.h>
 
 #include <HYDROData_OperationsFactory.h>
 
@@ -212,13 +214,19 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   ViewManagerList anOCCViewManagers;
   anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
 
-  foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers )
+  foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
   {
     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
              this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
     connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ), 
              this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
 
+    OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
+    if( occ_mgr )
+    {
+      occ_mgr->setChainedOperations( true );//TODO: via preferences
+    }
+
     foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
     {
       OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
@@ -229,6 +237,10 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
     }
   }
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   // Load GEOM data
   SalomeApp_Study* aStudy = 
     dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
@@ -244,6 +256,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
     }
   }
 
+
 //  SUIT_DataBrowser* ob = getApp()->objectBrowser();
 //  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
 //  treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
@@ -263,9 +276,17 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 
   ViewManagerList anOCCViewManagers;
   getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
-  foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
+  foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
+  {
     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
                 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
+
+    OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
+    if( occ_mgr )
+    {
+      occ_mgr->setChainedOperations( false );
+      setAutoZoom( occ_mgr, true );
+    }
   }
 
   /* Issues ## 68, 88.
@@ -291,6 +312,9 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
 
   myActiveOperationMap.clear();
+
+  myViewManagerMap.clear();
+
   return LightApp_Module::deactivateModule( theStudy );
 }
 
@@ -373,6 +397,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsObjectCanBeColored = false;
   bool isRoot = false;
   bool isStreamHasBottom = false;
+  bool anIsBCPolygon = false;
 
   SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
   SUIT_DataOwnerPtrList anOwners;
@@ -487,13 +512,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsStricklerTable = true;
       else if( anObjectKind == KIND_LAND_COVER_MAP )
         anIsLandCoverMap = true;
+      else if (anObjectKind == KIND_BC_POLYGON)
+        anIsBCPolygon = true;
       else if( anObjectKind == KIND_STREAM )
       {
         anIsStream = true;
         Handle(HYDROData_Stream) aStream = 
           Handle(HYDROData_Stream)::DownCast( anObject );
         if ( !aStream.IsNull() )
-            isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
+          isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
       }
       else if( anObjectKind == KIND_CHANNEL )
         anIsChannel = true;
@@ -511,7 +538,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   // Check if all selected objects are profiles
   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
-                     ( aNbOfSelectedProfiles == aSeq.Length() );
+    ( aNbOfSelectedProfiles == aSeq.Length() );
 
   // check the selected partitions
   if( !anIsSelectedDataObjects && anIsObjectBrowser )
@@ -521,53 +548,64 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     {
       switch( aSelectedPartition )
       {
-        case KIND_IMAGE:
-          theMenu->addAction( action( ImportImageId ) );
-          break;
-        case KIND_BATHYMETRY:
-          theMenu->addAction( action( ImportBathymetryId ) );
-          break;
-        case KIND_ARTIFICIAL_OBJECT:
-          theMenu->addAction( action( CreateChannelId ) );
-          theMenu->addAction( action( CreateDigueId ) );
-          break;
-        case KIND_NATURAL_OBJECT:
-          theMenu->addAction( action( CreateImmersibleZoneId ) );
-          theMenu->addAction( action( CreateStreamId ) );
-          break;
-        case KIND_OBSTACLE:
-          theMenu->addAction( action( ImportObstacleFromFileId ) );
-          theMenu->addAction( action( CreateBoxId ) );
-          theMenu->addAction( action( CreateCylinderId ) );
-          break;
-        case KIND_STRICKLER_TABLE:
-          theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
-          break;
-        case KIND_LAND_COVER_MAP:
-          theMenu->addAction( action( CreateLandCoverMapId ) ); 
-          theMenu->addAction( action( ImportLandCoverMapId ) ); 
-          break;
-        case KIND_CALCULATION:
-          theMenu->addAction( action( CreateCalculationId ) );
-          break;
-        case KIND_POLYLINEXY:
-          theMenu->addAction( action( ImportPolylineId ) );
-          theMenu->addAction( action( CreatePolylineId ) );
-          break;
-        case KIND_POLYLINE:
-          theMenu->addAction( action( CreatePolyline3DId ) );
-          break;
-        case KIND_PROFILE:
-          theMenu->addAction( action( CreateProfileId ) );
-          theMenu->addAction( action( ImportProfilesId ) );
-          theMenu->addAction( action( AllGeoreferencementId ) );
-          break;
-        case KIND_VISUAL_STATE:
-          theMenu->addAction( action( SaveVisualStateId ) );
-          break;
+      case KIND_IMAGE:
+        theMenu->addAction( action( ImportImageId ) );
+        break;
+      case KIND_BATHYMETRY:
+        theMenu->addAction( action( ImportBathymetryId ) );
+        break;
+      case KIND_ARTIFICIAL_OBJECT:
+        theMenu->addAction( action( CreateChannelId ) );
+        theMenu->addAction( action( CreateDigueId ) );
+        break;
+      case KIND_NATURAL_OBJECT:
+        theMenu->addAction( action( CreateImmersibleZoneId ) );
+        theMenu->addAction( action( CreateStreamId ) );
+        break;
+      case KIND_OBSTACLE:
+        theMenu->addAction( action( ImportObstacleFromFileId ) );
+        theMenu->addAction( action( CreateBoxId ) );
+        theMenu->addAction( action( CreateCylinderId ) );
+        break;
+      case KIND_STRICKLER_TABLE:
+        theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
+        break;
+      case KIND_LAND_COVER_MAP:
+        theMenu->addAction( action( CreateLandCoverMapId ) ); 
+        theMenu->addAction( action( ImportLandCoverMapId ) ); 
+        break;
+      case KIND_CALCULATION:
+        theMenu->addAction( action( CreateCalculationId ) );
+        break;
+      case KIND_POLYLINEXY:
+        theMenu->addAction( action( ImportPolylineId ) );
+        theMenu->addAction( action( CreatePolylineId ) );
+        break;
+      case KIND_POLYLINE:
+        theMenu->addAction( action( CreatePolyline3DId ) );
+        break;
+      case KIND_PROFILE:
+        theMenu->addAction( action( CreateProfileId ) );
+        theMenu->addAction( action( ImportProfilesId ) );
+        theMenu->addAction( action( AllGeoreferencementId ) );
+        break;
+      case KIND_VISUAL_STATE:
+        theMenu->addAction( action( SaveVisualStateId ) );
+        break;
+      case KIND_BC_POLYGON:
+        theMenu->addAction( action( ImportBCPolygonId ) );
+        break;
       }
       theMenu->addSeparator();
     }
+    else
+    {
+      Handle(HYDROData_CalculationCase) aCalcCase;
+      QString outStr;
+      HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
+      if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
+        theMenu->addAction( action( RegenerateRegionColorsId ) );
+    }
   }
 
   if( anIsSelectedDataObjects )
@@ -630,6 +668,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitPolylinesId ) );
         theMenu->addAction( action( MergePolylinesId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( ShowAttrPolylinesId ) );
+        theMenu->addSeparator();
       }
       else if( anIsPolyline3D )
       {
@@ -658,8 +698,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( EditStreamId ) );
         if ( action( RiverBottomContextId ) )
         {
-            theMenu->addAction( action( RiverBottomContextId ) );
-            action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
+          theMenu->addAction( action( RiverBottomContextId ) );
+          action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
         }
         theMenu->addAction( action( ProfileInterpolateId ) );
         theMenu->addSeparator();
@@ -716,6 +756,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( LoadVisualStateId ) );
         theMenu->addSeparator();
       }
+      else if (anIsZone)
+        theMenu->addAction( action( ZoneSetColorId ) );
+      else if (anIsBCPolygon)
+        theMenu->addAction( action( SetBoundaryTypePolygonId ) );
 
       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
       {
@@ -736,7 +780,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SetTransparencyId ) );
         theMenu->addSeparator();
       }
-    } else if ( anAllAreProfiles ) {
+    } 
+    else if ( anAllAreProfiles )
+    {
+      theMenu->addAction( action( EditProfileId ) );
       theMenu->addAction( action( SelectedGeoreferencementId ) );
       theMenu->addSeparator();
     }
@@ -759,10 +806,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
 
     if( anIsImage || anIsPolyline || anIsPolyline3D || 
-        anIsImmersibleZone || anIsZone || anIsRegion ||
-        anIsBathymetry || anIsObstacle || anIsStream ||
-        anIsChannel || anIsDigue || anIsDummyObject3D ||
-        anIsValidProfile || anIsGroup || anIsLandCoverMap )
+      anIsImmersibleZone || anIsZone || anIsRegion ||
+      anIsBathymetry || anIsObstacle || anIsStream ||
+      anIsChannel || anIsDigue || anIsDummyObject3D ||
+      anIsValidProfile || anIsGroup || anIsLandCoverMap ||
+      anIsBCPolygon)
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -796,7 +844,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addAction( action( HideAllId ) );
     theMenu->addSeparator();
   }
-  
+
   if ( anIsOCCView || anIsVTKView )
   {
     theMenu->addSeparator();
@@ -810,13 +858,32 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   {
     if( aSeq.Size() > 0 )
     {
-      Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
+      Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
+      Handle(HYDROData_Object) anObject;
+      Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
+      Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
+
+      if (!anAObject.IsNull())
+        anObject = anAObject;
+      if (!aNObject.IsNull())
+        anObject = aNObject;
+
       if( !anObject.IsNull() )
       {
         theMenu->addSeparator();
-        theMenu->addAction( action( SubmersibleId ) );
-        action( SubmersibleId )->setCheckable( true );
-        action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
+        bool IsSubmersible = anObject->IsSubmersible();
+        if (!IsSubmersible)
+        {
+          theMenu->addAction( action( SubmersibleId ) );
+          action( SubmersibleId )->setCheckable(true);
+          action( SubmersibleId )->setChecked(true);
+        }
+        else
+        {
+          theMenu->addAction( action( UnSubmersibleId ) );
+          action( UnSubmersibleId )->setCheckable(true);
+          action( UnSubmersibleId )->setChecked(true);
+        }
       }
     }
   }
@@ -854,6 +921,10 @@ void HYDROGUI_Module::createPreferences()
   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
 
+  addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
+
+  addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
+
   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
                                             LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
@@ -912,8 +983,34 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
       }
     }
+    else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
+    {
+      bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
+      setAutoZoomToAllViewManagers(!aZoomShutoff);
+    }
+    else if (theSection == "HYDRO" && thePref == "chained_panning")
+    {
+      bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
+      if (!aChainedPan)
+        resetViewState();
+      ViewManagerList aViewManagers = getApp()->viewManagers();
+      foreach (SUIT_ViewManager* aVMgr, aViewManagers)
+      {
+        OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
+        if (anOCCViewMgr)
+          anOCCViewMgr->setChainedOperations( aChainedPan );
+      }
+      
+      QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
+      foreach (QDockWidget* qw, docW)
+      {
+        HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
+        if (pdlg)
+          pdlg->viewManager()->setChainedOperations(aChainedPan);
+      }
+    }
     else
-        LightApp_Module::preferencesChanged( theSection, thePref );
+      LightApp_Module::preferencesChanged( theSection, thePref );
 }
 
 QCursor HYDROGUI_Module::getPrefEditCursor() const
@@ -988,6 +1085,10 @@ void HYDROGUI_Module::update( const int flags )
 
   setUpdateEnabled( true );
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -1549,7 +1650,7 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
   else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
   {
     OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
-    mgr->setChainedOperations( true );//TODO: via preferences
+    //mgr->setChainedOperations( true );
 
     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
@@ -1629,7 +1730,6 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
       aViewFrame->onTopView();
 
       HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
-
       OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
       if ( aViewPort ) {
         aViewPort->installEventFilter( this );
@@ -1716,6 +1816,7 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
   while( anIdIter.hasNext() )
   {
     theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
+    myOverview->setTopView();
   }
 }
 
@@ -1900,6 +2001,67 @@ void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn
   update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
 }
 
+bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
+{
+  return true;
+}
+
+bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
+{
+
+  return true;
+}
+
+void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                                   const int row, Qt::DropAction action )
+{
+  if ( action != Qt::CopyAction && action != Qt::MoveAction )
+    return; 
+
+  if (row == -1)
+    return;
+
+  if (where->level() < 2 )
+    return;  
+
+  DataObjectList::ConstIterator it = what.constBegin();
+  for (;it != what.constEnd();++it) 
+  {
+    if ((*it)->parent() != where)
+      return;
+  }
+
+  it = what.constBegin();
+
+  int i=0;
+  for (;it != what.constEnd();++it) 
+  {
+    SUIT_DataObject* objWhat = *it;
+
+    DataObjectList objInSect = where->children();
+
+    //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
+    int ind = objInSect.indexOf(objWhat);
+    if (ind != -1)
+    {
+      HYDROGUI_DataModel* aModel = getDataModel();
+      int pos = -1;
+      if (ind >= row)
+      {
+        pos = row + i;
+        i++;
+      }
+      else
+        pos = row - 1;
+      where->moveChildPos(objWhat, pos);
+      //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
+    }  
+  }
+
+  getApp()->updateObjectBrowser(true);
+  
+}
+
 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
 {
   Handle(HYDROData_StricklerTable) aTable;
@@ -1961,3 +2123,38 @@ void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
 
   myOverview->setMainView( occwnd );
 }
+
+void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
+{
+  ViewManagerList aViewManagers = getApp()->viewManagers();
+  foreach (SUIT_ViewManager* aVMgr, aViewManagers)
+    setAutoZoom(aVMgr, bAutoZoom);
+}
+
+void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
+{
+  if (!aVMgr)
+    return;
+  QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
+  foreach (SUIT_ViewWindow* aView, aViews)
+  {
+    if (aView)
+    {
+      OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
+      if (anOCCViewFrame)
+      {
+        anOCCViewFrame->setAutomaticZoom(bAutoZoom);
+        for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
+        {
+          OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
+          if (aV)
+            aV->setAutomaticZoom(bAutoZoom);
+        }
+      }
+      OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
+      if (anOCCViewWindow)
+        anOCCViewWindow->setAutomaticZoom(bAutoZoom);
+    }
+  }
+}
+