Salome HOME
bug fixes/improvements (678, 681, 679, etc..)
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapOp.cxx
index a498b8679a13b7dfe15b3c209a701f952c4f1b5b..a04f5a1ca1267a996e1a13c46627899fc7415722 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <LightApp_Application.h>
 
+#include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
@@ -117,8 +118,8 @@ void HYDROGUI_LandCoverMapOp::startOperation()
   aPanel->setObjectName( anObjectName );
 
   closePreview();
-  QStringList aPolylineFaceNames;
-  onCreatePreview( aPolylineFaceNames );
+  if ( myOperationId != CreateLandCoverMapId )
+    onCreatePreview();
 
   aPanel->blockSignals( false );
 
@@ -148,8 +149,6 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
   HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
   connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
            this, SLOT( onLandCoverMapChanged( const QString& ) ) );
-  connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ),
-           this,   SLOT( onCreatePreview( const QStringList& ) ) );
   return aPanel;
 }
 
@@ -205,18 +204,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
     if ( myPreviewPrs )
     {
       // Fill in aFacesSelectedInViewer list
-      Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
-      if ( !aCtx.IsNull() && aCtx->NbSelected() > 0 )
-      {
-        for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
-        {
-          TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
-          if ( aSelectedShape.IsNull() )
-            continue;
-
-          aFacesSelectedInViewer.Append( aSelectedShape );
-        }
-      }
+      Handle(AIS_InteractiveContext) aCtx;
+      getSelectedShapes( aFacesSelectedInViewer, aCtx );
     }
   }
 
@@ -224,7 +213,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
   QString aSelectedStricklerType;
   if ( myOperationId == CreateLandCoverMapId || 
        myOperationId == AddLandCoverId || 
-       myOperationId == MergeLandCoverId )
+       myOperationId == MergeLandCoverId ||
+       myOperationId == ChangeLandCoverTypeId )
   {
     aSelectedStricklerType = aPanel->getSelectedStricklerTypeName();
     if ( aSelectedStricklerType.isEmpty() )
@@ -315,6 +305,21 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
       }
     }
   }
+
+  // Change Strickler type for land cover(s) inside edited land cover map
+  if ( myOperationId == ChangeLandCoverTypeId )
+  {
+    bool aLandCoverChangeType = false;
+    if ( !aFacesSelectedInViewer.IsEmpty() )
+    {
+      aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType );
+      if ( !aLandCoverChangeType )
+      {
+        theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" );
+        return false;
+      }
+    }
+  }
     
   // Update land cover map object and close preview
   aLandCoverMapObj->Update();
@@ -348,13 +353,12 @@ void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
     {
       // Show preview of the newly selected land cover map
       closePreview();
-      QStringList aPolylineFaceNames;
-      onCreatePreview( aPolylineFaceNames );
+      onCreatePreview();
     }
   }
 }
 
-void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFaceNames )
+void HYDROGUI_LandCoverMapOp::onCreatePreview()
 {
   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
   if ( !aPanel )
@@ -385,7 +389,9 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFac
     TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape();
     if( !aLandCoverMapShape.IsNull() )
     {
-      if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId)
+      if ( myOperationId == RemoveLandCoverId ||
+           myOperationId == MergeLandCoverId ||
+           myOperationId == ChangeLandCoverTypeId )
         myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); 
       myPreviewPrs->setShape( aLandCoverMapShape );      
     }
@@ -407,10 +413,27 @@ void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
   {
     int aNbSelected = aCtx->NbSelected();
 
-    if ( myOperationId == RemoveLandCoverId )
+    if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
+      // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
       aPanel->setApplyEnabled( aNbSelected > 0 );
     else if ( myOperationId == MergeLandCoverId )
+      // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
       aPanel->setApplyEnabled( aNbSelected > 1 );
+
+    if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
+    {
+      if ( aNbSelected == 1 && !myEditedObject.IsNull() )
+      {
+        TopTools_ListOfShape aFacesSelectedInViewer;
+        getSelectedShapes( aFacesSelectedInViewer, aCtx );
+        if ( aFacesSelectedInViewer.Extent() == 1 )
+        {
+          QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
+          if ( !aType.isEmpty() )
+            aPanel->setSelectedStricklerTypeName( aType );
+        }
+      }
+    }
   }
 }
 
@@ -426,7 +449,7 @@ void HYDROGUI_LandCoverMapOp::closePreview()
   if ( !aPanel )
     return;
 
-  if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId )
+  if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
     aPanel->setApplyEnabled( false );
 }
 
@@ -441,3 +464,22 @@ Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
   }
   return aCtx;
 }
+
+void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes,
+                                                 Handle(AIS_InteractiveContext)& theCtx )
+{
+  if ( theCtx.IsNull() )
+    theCtx = getInteractiveContext();
+
+  if ( !theCtx.IsNull() && theCtx->NbSelected() > 0 )
+  {
+    for ( theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected() )
+    {
+      TopoDS_Shape aSelectedShape = theCtx->SelectedShape();
+      if ( aSelectedShape.IsNull() )
+        continue;
+
+      theSelectedShapes.Append( aSelectedShape );
+    }
+  }
+}