]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #669, #671: implementation of change land cover type operation, set default...
authormkr <mkr@opencascade.com>
Thu, 12 Nov 2015 09:03:53 +0000 (12:03 +0300)
committermkr <mkr@opencascade.com>
Thu, 12 Nov 2015 09:03:53 +0000 (12:03 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapOp.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/resources/HYDROGUI_images.ts
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index bc0f1551e9f3193c5bc0cbf9faca4394a591f827..d33d90de40047b6a2053e075817cdea06352a0af 100644 (file)
@@ -646,6 +646,37 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the
   return aResult;
 }
 
+/**
+  Change Strickler type for the list of faces to the given one
+  @param theFaces the faces to change type
+  @param theType the Strickler type for the given land cover(s)
+  @return if the change type operation is successful
+*/
+bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType )
+{
+  HYDROData_MapOfFaceToStricklerType aFacesToChangeType;
+  TopTools_ListIteratorOfListOfShape aFIt( theFaces );
+  for( ; aFIt.More(); aFIt.Next() )
+  {
+    TopoDS_Shape aShape = aFIt.Value();
+    if( aShape.ShapeType()==TopAbs_FACE )
+      aFacesToChangeType.Add( TopoDS::Face( aShape ), "" );
+  }
+
+  int aNbChanges = 0;
+  Iterator anIt( *this );
+  for( ; anIt.More(); anIt.Next() )
+    if( aFacesToChangeType.Contains( anIt.Face() ) )
+    {
+      anIt.SetStricklerType( theType );
+      aNbChanges++;
+    }
+  if ( aNbChanges != theFaces.Extent() )
+    return false;
+
+  return true;
+}
+
 /**
   Get the shape of the land cover map
 */
@@ -654,6 +685,26 @@ TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
   return HYDROData_Entity::GetShape( DataTag_Shape );
 }
 
+/**
+  Get Strickler type of the given land cover
+  @param theLandCover the land cover to get Strickler type of
+  @return name of Strickler type
+*/
+QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const
+{
+  QString aType = "";
+
+  Iterator anIt( *this );
+  for( ; anIt.More(); anIt.Next() )
+    if( anIt.Face().IsEqual( theLandCover) )
+    {
+      aType = anIt.StricklerType();
+      break;
+    }
+
+  return aType;
+}
+
 /**
   Set the shape of the land cover map
   @param theShape the new shape for the land cover map
index 9ab0276ca002a1c80995644357afe2f8b1d11055..9ce1613ef125614fd2d7ba5101b750f179af351b 100644 (file)
@@ -109,10 +109,14 @@ public:
   HYDRODATA_EXPORT bool Split( const TopoDS_Shape& );
   HYDRODATA_EXPORT bool Merge( const TopTools_ListOfShape&, const QString& theType );
 
+  HYDRODATA_EXPORT bool ChangeType( const TopTools_ListOfShape&, const QString& theType );
+
   HYDRODATA_EXPORT TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const;
 
   HYDRODATA_EXPORT TopoDS_Shape GetShape() const;
 
+  HYDRODATA_EXPORT QString StricklerType( const TopoDS_Face& ) const;
+
   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
   HYDRODATA_EXPORT int GetLCCount() const;
index ec2a3e5cf07b00f5df48a5ab6dd0dad1f0a416e8..57bcaff7f1760f529b5ee8e4ebbbdfa7ce3cef70 100644 (file)
@@ -203,9 +203,5 @@ void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
       anEmptyPolylineFaceName = getPolylineFaceName().isEmpty();
 
     setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName );
-
-    // TODO:
-    //if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId ) => enable Apply,
-    //Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
   }
 }
index a498b8679a13b7dfe15b3c209a701f952c4f1b5b..2ec102f4eca6d1fed78a5da5a79eb589144f0025 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>
@@ -205,18 +206,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 +215,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 +307,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();
@@ -385,7 +392,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 +416,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 +452,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 +467,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 );
+    }
+  }
+}
index f73126af6c807f6972fbef536d158caf6fa10ff3..55cc12df0f950cb5b640a33ee13ad0f3a49137b1 100644 (file)
@@ -54,6 +54,8 @@ private:
   void                           closePreview();
 
   Handle(AIS_InteractiveContext) getInteractiveContext();
+  void                           getSelectedShapes( TopTools_ListOfShape& theSelectedShapes,
+                                                    Handle(AIS_InteractiveContext)& theCtx );
 
 private:
   int                             myOperationId;
index f8baa64dad4958f33f13aca77f8a121ee9a141ef..05e583ab67e0917e511d2a0b4ff3f6447d39cf0f 100644 (file)
@@ -678,6 +678,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addSeparator();
         theMenu->addAction( action( SplitLandCoverId ) );
         theMenu->addAction( action( MergeLandCoverId ) );
+        theMenu->addAction( action( ChangeLandCoverTypeId ) );
         theMenu->addSeparator();
         //
         theMenu->addAction( action( ExportToShapeFileID ) );
index 84804add839e9cdf86445bd55c0b6764bbe117f0..b88069dba3c66c5ea9d318be21c5ea42a63bc148 100644 (file)
@@ -569,8 +569,6 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case RemoveLandCoverId:
   case SplitLandCoverId:
   case MergeLandCoverId:
-    anOp = new HYDROGUI_LandCoverMapOp( aModule, theId );
-    break;
   case ChangeLandCoverTypeId:
     anOp = new HYDROGUI_LandCoverMapOp( aModule, theId );
     break;
index cec1aa6ef63d39653142559fbac02de2ab5ee668..207f77794191cadb59dc2b9643fb913f34891648 100644 (file)
       <source>MERGE_LAND_COVER_ICO</source>
       <translation>icon_merge_land_cover.png</translation>
     </message>
+    <message>
+      <source>CHANGE_LAND_COVER_TYPE_ICO</source>
+      <translation>icon_change_land_cover_type.png</translation>
+    </message>
 
     <message>
       <source>IMPORT_OBSTACLE_FROM_FILE_ICO</source>
index 756d258ce3d8bd2b360e3d29e46b3aa761ec9bc2..1c10d4f41c615f2ce19844b0134d730dcefc471d 100644 (file)
@@ -876,6 +876,10 @@ Would you like to remove all references from the image?</translation>
       <source>DSK_MERGE_LAND_COVER</source>
       <translation>Merge land covers</translation>
     </message>
+    <message>
+      <source>DSK_CHANGE_LAND_COVER_TYPE</source>
+      <translation>Change land cover(s) type</translation>
+    </message>
     <message>
       <source>DSK_COPY</source>
       <translation>Copy</translation>
@@ -1177,6 +1181,10 @@ Would you like to remove all references from the image?</translation>
       <source>MEN_MERGE_LAND_COVER</source>
       <translation>Merge land covers</translation>
     </message>
+    <message>
+      <source>MEN_CHANGE_LAND_COVER_TYPE</source>
+      <translation>Change land cover(s) type</translation>
+    </message>
     <message>
       <source>MEN_CUT_IMAGES</source>
       <translation>Cut images</translation>
@@ -1514,6 +1522,10 @@ Would you like to remove all references from the image?</translation>
       <source>STB_MERGE_LAND_COVER</source>
       <translation>Merge land covers</translation>
     </message>
+    <message>
+      <source>STB_CHANGE_LAND_COVER_TYPE</source>
+      <translation>Change land cover(s) type</translation>
+    </message>
     <message>
       <source>STB_COPY</source>
       <translation>Copy</translation>
@@ -2880,6 +2892,10 @@ Polyline should consist from one not closed curve.</translation>
       <source>MERGE_LAND_COVER</source>
       <translation>Merge land covers inside the land cover map</translation>
     </message>
+    <message>
+      <source>CHANGE_LAND_COVER_TYPE</source>
+      <translation>Change Strickler type(s) assigned to the land cover(s) inside the land cover map</translation>
+    </message>
     <message>
       <source>POLYLINE_FACE_NOT_DEFINED</source>
       <translation>Polyline / Face object should be defined.</translation>
@@ -2904,6 +2920,10 @@ Polyline should consist from one not closed curve.</translation>
       <source>LAND_COVER_NOT_MERGED</source>
       <translation>Land cover can not be merged.</translation>
     </message>
+    <message>
+      <source>LAND_COVER_TYPE_NOT_CHANGED</source>
+      <translation>Strickler type can not be changed for all selected land covers.</translation>
+    </message>
     <message>
       <source>LAND_COVER_OBJECT_CANNOT_BE_CREATED</source>
       <translation>Land Cover object can not be created</translation>