Salome HOME
Merge branch 'BR_LCM_COMP' into HEAD
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index d684d927846e2ee1a89c3f978727d74ec3f421bf..f861ac792105ff447509003d9ee25772dd21dba8 100644 (file)
@@ -46,6 +46,7 @@
 #include <HYDROData_Profile.h>
 #include <HYDROData_Lambert93.h>
 #include <HYDROData_Polyline3D.h>
+#include <HYDROData_StricklerTable.h>
 
 #include <HYDROData_OperationsFactory.h>
 
@@ -337,7 +338,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsZone = false;
   bool anIsObstacle = false;
   bool anIsStricklerTable = false;
-  bool anIsLandCover = false;
+  bool anIsLandCoverMap = false;
   bool anIsStream = false;
   bool anIsChannel = false;
   bool anIsDigue = false;
@@ -398,7 +399,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       anIsVisibleInSelection |= aVisibility;
       anIsHiddenInSelection |= !aVisibility;
 
-      if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
+      if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
       {
         anIsMustObjectBeUpdated = true;
       }
@@ -458,8 +459,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsObstacle = true;
       else if( anObjectKind == KIND_STRICKLER_TABLE )
         anIsStricklerTable = true;
-      else if( anObjectKind == KIND_LAND_COVER )
-        anIsLandCover = true;
+      else if( anObjectKind == KIND_LAND_COVER_MAP )
+        anIsLandCoverMap = true;
       else if( anObjectKind == KIND_STREAM )
       {
         anIsStream = true;
@@ -479,7 +480,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     }
 
     if ( !anIsObjectCanBeColored )
-      anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
+      anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
   }
 
   // Check if all selected objects are profiles
@@ -516,13 +517,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         case KIND_STRICKLER_TABLE:
           theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
           break;
-        case KIND_LAND_COVER:
-          theMenu->addAction( action( CreateLandCoverId ) );          
+        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:
@@ -585,6 +588,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( CutImagesId ) );
         theMenu->addAction( action( SplitImageId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( RecognizeContoursId ) );
+        theMenu->addSeparator();
       }
       else if( anIsBathymetry )
       {
@@ -596,6 +601,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       {
         theMenu->addAction( action( EditPolylineId ) );
         theMenu->addSeparator();
+        theMenu->addAction( action( SplitPolylinesId ) );
+        theMenu->addAction( action( MergePolylinesId ) );
+        theMenu->addSeparator();
       }
       else if( anIsPolyline3D )
       {
@@ -651,11 +659,29 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( ExportStricklerTableFromFileId ) );
         theMenu->addAction( action( DuplicateStricklerTableId ) );
         theMenu->addSeparator();
+
+        Handle(HYDROData_StricklerTable) aTable = 
+          Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
+        QString aCurrentTable = 
+          HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
+        bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
+
+        if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
+          theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
+          theMenu->addSeparator();
+        }
       }
-      else if( anIsLandCover )
+      else if( anIsLandCoverMap )
       {
-        theMenu->addAction( action( EditLandCoverId ) );
+        theMenu->addAction( action( AddLandCoverId ) );
+        theMenu->addAction( action( RemoveLandCoverId ) );
+        theMenu->addSeparator();
+        theMenu->addAction( action( SplitLandCoverId ) );
+        theMenu->addAction( action( MergeLandCoverId ) );
+        theMenu->addAction( action( ChangeLandCoverTypeId ) );
         theMenu->addSeparator();
+        //
+        theMenu->addAction( action( ExportToShapeFileID ) );
       }      
       else if( anIsVisualState && anIsObjectBrowser )
       {
@@ -666,7 +692,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
       if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
       {
-        theMenu->addAction( action( PolylineExtraction ) );
+        theMenu->addAction( action( PolylineExtractionId ) );
         theMenu->addSeparator();
       }
 
@@ -674,6 +700,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       if ( anIsObjectCanBeColored )
       {
         theMenu->addAction( action( SetColorId ) );
+        if ( anIsLandCoverMap )
+          theMenu->addAction( action( SetTransparencyId ) );
         theMenu->addSeparator();
       }
     } else if ( anAllAreProfiles ) {
@@ -681,8 +709,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       theMenu->addSeparator();
     }
 
-    if (anIsPolyline || anIsPolyline3D)
-      theMenu->addAction( action( ExportPolylineId ) );
+    bool anIsPoly = anIsPolyline || anIsPolyline3D;
+    if (anIsPoly && !anIsLandCoverMap)
+      theMenu->addAction( action( ExportToShapeFileID ) );
 
     // Add copy action
     QAction* aCopyAction = action( CopyId );
@@ -701,7 +730,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         anIsImmersibleZone || anIsZone || anIsRegion ||
         anIsBathymetry || anIsObstacle || anIsStream ||
         anIsChannel || anIsDigue || anIsDummyObject3D ||
-        anIsValidProfile || anIsGroup || anIsLandCover )
+        anIsValidProfile || anIsGroup || anIsLandCoverMap )
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -722,6 +751,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
     theMenu->addAction( action( SetZLevelId ) );
     theMenu->addSeparator();
+
+    if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
+      theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
+      theMenu->addSeparator();
+    }
   }
 
   if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
@@ -785,7 +819,7 @@ void HYDROGUI_Module::createPreferences()
 
   int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
   int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
-                                            LightApp_Preferences::DblSpin, "HYDRO", "default_strickler_coefficient" );
+                                            LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
   setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
   setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
   setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
@@ -1053,6 +1087,12 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId,
         if ( visState != Qtx::UnpresentableState )
             treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
     }
+
+    if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
+      setLandCoversScalarMapModeOff( theViewId );
+    } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
+      getOCCDisplayer()->SetToUpdateColorScale();
+    }
   }
 }
 
@@ -1461,8 +1501,11 @@ void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
     if ( anOCCViewManager )
     {
       OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
-      if ( anOCCViewer )
-        removeViewShapes( (size_t)anOCCViewer );
+      if ( anOCCViewer ) {
+        int aViewerId = (size_t)anOCCViewer;
+        removeViewShapes( aViewerId );
+        setLandCoversScalarMapModeOff( aViewerId );
+      }
     }
 
     if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
@@ -1770,3 +1813,52 @@ void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn
 
   update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
 }
+
+Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
+{
+  Handle(HYDROData_StricklerTable) aTable;
+
+  if ( myLandCoverColoringMap.contains( theViewId ) ) {
+    aTable = myLandCoverColoringMap.value( theViewId );
+  }
+
+  return aTable;
+}
+
+void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
+                                                 const Handle(HYDROData_StricklerTable)& theTable )
+{
+  if ( !theTable.IsNull() ) {
+    myLandCoverColoringMap.insert( theViewId, theTable );
+  }
+}
+
+void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
+{
+  myLandCoverColoringMap.remove( theViewId );
+}
+
+bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
+{
+  return myLandCoverColoringMap.contains( theViewId );
+}
+
+void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
+{
+  if ( theObject.IsNull() || !theObject->IsRemoved() ) {
+    return;
+  }
+
+  if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
+    Handle(HYDROData_StricklerTable) aTable = 
+      Handle(HYDROData_StricklerTable)::DownCast( theObject );
+    QList<int> aViewIds;
+    QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
+    while ( anIter.hasNext() ) {
+      if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) == 
+           HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
+        anIter.remove();
+      }
+    }
+  }
+}