Salome HOME
lots 3,8 - corrections
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index ff078d9f2e359c6313b7c77d59fef09538a22743..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>
@@ -214,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 );
@@ -231,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() );
@@ -246,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 );
@@ -265,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.
@@ -293,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 );
 }
 
@@ -375,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;
@@ -489,6 +512,8 @@ 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;
@@ -567,6 +592,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       case KIND_VISUAL_STATE:
         theMenu->addAction( action( SaveVisualStateId ) );
         break;
+      case KIND_BC_POLYGON:
+        theMenu->addAction( action( ImportBCPolygonId ) );
+        break;
       }
       theMenu->addSeparator();
     }
@@ -640,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 )
       {
@@ -728,6 +758,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       }
       else if (anIsZone)
         theMenu->addAction( action( ZoneSetColorId ) );
+      else if (anIsBCPolygon)
+        theMenu->addAction( action( SetBoundaryTypePolygonId ) );
 
       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
       {
@@ -777,7 +809,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       anIsImmersibleZone || anIsZone || anIsRegion ||
       anIsBathymetry || anIsObstacle || anIsStream ||
       anIsChannel || anIsDigue || anIsDummyObject3D ||
-      anIsValidProfile || anIsGroup || anIsLandCoverMap )
+      anIsValidProfile || anIsGroup || anIsLandCoverMap ||
+      anIsBCPolygon)
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -888,7 +921,9 @@ void HYDROGUI_Module::createPreferences()
   addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
                  LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
 
-  addPreference( tr( "PREF_VIEWER_AUTOMATIC_ZOOM" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "automatic_zoom" );
+  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,
@@ -948,40 +983,34 @@ void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QStri
           getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
       }
     }
-    else if (theSection == "HYDRO" && thePref == "automatic_zoom")
+    else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
+    {
+      bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
+      setAutoZoomToAllViewManagers(!aZoomShutoff);
+    }
+    else if (theSection == "HYDRO" && thePref == "chained_panning")
     {
-      bool anAutoZoom = resMgr->booleanValue( "HYDRO", "automatic_zoom" );
+      bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
+      if (!aChainedPan)
+        resetViewState();
       ViewManagerList aViewManagers = getApp()->viewManagers();
       foreach (SUIT_ViewManager* aVMgr, aViewManagers)
       {
-        if (aVMgr)
-        {
-          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(anAutoZoom);
-                for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
-                {
-                  OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
-                  if (aV)
-                    aV->setAutomaticZoom(anAutoZoom);
-                }
-              }
-              OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
-              if (anOCCViewWindow)
-                anOCCViewWindow->setAutomaticZoom(true);
-            }
-          }
-        }
+        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
@@ -1056,6 +1085,10 @@ void HYDROGUI_Module::update( const int flags )
 
   setUpdateEnabled( true );
 
+  preferencesChanged( "HYDRO", "zoom_shutoff" );
+
+  preferencesChanged( "HYDRO", "chained_panning" );
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -1617,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* ) ) );
@@ -1697,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 );
@@ -1969,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;
@@ -2030,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);
+    }
+  }
+}
+