Salome HOME
LCM // Import/Export of SHP p.2
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapOp.cxx
index 96655be197d5f11dbf5b83091812536e003adea8..3de085b925c4607feb2767621f983b080d944fc0 100644 (file)
 #include <HYDROData_PolylineXY.h>
 #include <HYDROData_Object.h>
 
+#include <TopoDS_Face.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+
 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
 : HYDROGUI_Operation( theModule ),
   myOperationId( theOperationId ),
@@ -120,9 +124,11 @@ void HYDROGUI_LandCoverMapOp::commitOperation()
 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& ) ) );
+  /*
   connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) );
   connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) );
   */
@@ -156,9 +162,12 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
     }
   }
 
-  // Get selected polyline/face
   Handle(HYDROData_PolylineXY) aPolyline;
   Handle(HYDROData_Object) aFace;
+
+  TopTools_ListOfShape aFacesSelectedInViewer;
+
+  // Get polyline/face selected in combo-box
   if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == SplitLandCoverId )
   {
     Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
@@ -170,6 +179,12 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
       return false;
     }
   }
+  // Get face(s) selected in the 3d viewer
+  else if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId )
+  {
+    // TODO:
+    //Fill in aFacesSelectedInViewer list
+  }
 
   // Get selected Strickler type
   QString aSelectedStricklerType;
@@ -190,6 +205,7 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
   // Set land cover map name
   aLandCoverMapObj->SetName( anObjectName );
   
+  // Add land cover to new / edited land cover map
   if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId )
   {
     bool aLandCoverAdded = false;
@@ -203,30 +219,69 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
       return false;
     }
   }
-    
-  /*TCollection_AsciiString anError;
-  if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() )
+
+  // Remove land cover from edited land cover map
+  if ( myOperationId == RemoveLandCoverId )
+  {
+    bool aLandCoverRemoved = false;
+    if ( !aFacesSelectedInViewer.IsEmpty() )
+    {
+      aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer );
+      if ( !aLandCoverRemoved )
+      {
+        theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" );
+        return false;
+      }
+    }
+  }
+
+  // Split land cover(s) inside edited land cover map
+  if ( myOperationId == SplitLandCoverId )
   {
-    if ( !anError.IsEmpty() ) {
-      theErrorMsg = HYDROGUI_Tool::ToQString( anError );
-    } else {
-      theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" );
+    bool aLandCoverSplitted = false;
+    if ( !aPolyline.IsNull() )
+      aLandCoverSplitted = aLandCoverMapObj->Split( aPolyline );
+    else if ( !aFace.IsNull() )
+    {
+      // TODO:
+      //Get the complete boundary of the object face as the splitting polyline
+      Handle(HYDROData_PolylineXY) aBoundaryPolyline;
+      aLandCoverSplitted = aLandCoverMapObj->Split( aBoundaryPolyline );
     }
-    return false;
-  }*/  
+    if ( !aLandCoverSplitted )
+    {
+      theErrorMsg = tr( "LAND_COVER_NOT_SPLITTED" );
+      return false;
+    }
+  }
 
+  // Merge land covers inside edited land cover map
+  if ( myOperationId == MergeLandCoverId )
+  {
+    bool aLandCoverMerged = false;
+    if ( !aFacesSelectedInViewer.IsEmpty() )
+    {
+      aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType );
+      if ( !aLandCoverMerged )
+      {
+        theErrorMsg = tr( "LAND_COVER_NOT_MERGED" );
+        return false;
+      }
+    }
+  }
+    
   /*if ( myOperationId == CreateLandCoverMapId )
   {    
     aLandCoverMapObj->SetFillingColor( aLandCoverMapObj->DefaultFillingColor() );
     aLandCoverMapObj->SetBorderColor( aLandCoverMapObj->DefaultBorderColor() );
   }*/
 
-  //aLandCoverMapObj->SetPolylines( aZonePolylines );
-  //aLandCoverMapObj->SetStricklerType( aSelectedStricklerType );
+  // Update land cover map object and close preview
   aLandCoverMapObj->Update();
 
   closePreview();
 
+  // Publish the newly created land cover map in the Object Browser
   module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true );
   if ( myOperationId == CreateLandCoverMapId )
   {
@@ -234,6 +289,7 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
     theBrowseObjectsEntries.append( anEntry );
   }
 
+  // Update presentation of land cover object in the 3d viewer
   module()->setIsToUpdate( aLandCoverMapObj );
   module()->getOCCDisplayer()->SetToUpdateColorScale();
 
@@ -242,7 +298,22 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
   return true;
 }
 
-void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineNames )
+void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
+{
+  // If the edited land cover map was changed in the combo-box, update myEditedObject
+  if ( myOperationId != CreateLandCoverMapId )
+  {
+    myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
+    if ( !myEditedObject.IsNull() )
+    {
+      // Show preview of the newly selected land cover map
+      QStringList aPolylineFaceNames;
+      onCreatePreview( aPolylineFaceNames );
+    }
+  }
+}
+
+void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFaceNames )
 {
   /*
   HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverDlg*>( inputPanel() );