Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportLandCoverOp.cxx
index ef7756b15720b2be003a86871067a96a3eca9395..d7ff002410ddb3ea3a1f19ba40ccb32c2da843ad 100644 (file)
@@ -160,10 +160,10 @@ bool HYDROGUI_ImportLandCoverOp::processApply( int& theUpdateFlags,
       for( ;HYDROGUI_Tool::FindObjectByName(module(), aLCName); i++)
         aLCName = aPanel->getObjectName() + "_polygon_" + QString::number(i);
       aLC->SetName( aLCName );
-      aLC->SetFillingColor( HYDROData_LandCover::DefaultFillingColor() );
-      aLC->SetBorderColor( HYDROData_LandCover::DefaultBorderColor() );
+      aLC->SetFillingColor( aLC->DefaultFillingColor() );
+      aLC->SetBorderColor( aLC->DefaultBorderColor() );
       
-      aLC->setShape(aResShape);
+      aLC->SetShape(aResShape);
       aLC->Show();
             
       //erasePreview();
@@ -215,18 +215,18 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected()
     TopTools_SequenceOfShape aFaces;
     HYDROData_ShapeFile anImporter;
 
-    if (anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces))
-    {
-      aPanel->setPolygonNames(aPolygonsList);
-
-      SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
-      if ( !aStudy ) {
-        return;
-      }
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
+    if ( !aStudy )
+      return;
 
-      erasePreview();
+    erasePreview();
 
-      Handle(AIS_InteractiveContext) aCtx = NULL;
+    Handle(AIS_InteractiveContext) aCtx = NULL;
+    int aShapeTypeOfFile = -1;
+    int aStat = anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces, aShapeTypeOfFile);
+    if (aStat == 1)
+    {
+      aPanel->setPolygonNames(aPolygonsList);
 
       LightApp_Application* anApp = module()->getApp();
       if ( !getPreviewManager() )
@@ -247,14 +247,14 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected()
       {
         TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i ));
 
-        aLC->setShape( aFace );      
+        aLC->SetShape( aFace );      
         
         if ( aViewManager && !aCtx.IsNull() )
         {
           HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
 
-          aShape->setFillingColor( HYDROData_LandCover::DefaultFillingColor(), false, false );
-          aShape->setBorderColor( HYDROData_LandCover::DefaultBorderColor(), false, false );
+          aShape->setFillingColor( aLC->DefaultFillingColor(), false, false );
+          aShape->setBorderColor( aLC->DefaultBorderColor(), false, false );
           if( !aFace.IsNull() )
             aShape->setShape( aLC->GetShape() );
           myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape);
@@ -273,10 +273,20 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected()
     }
     else
     {
-      SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
-        
+      erasePreview();
+      aPanel->setPolygonNames(QStringList());
+      aPanel->setObjectName("");
       QApplication::restoreOverrideCursor();
-      abort();
+      QString aMess = "Cannot import land cover;\n";
+      if (aStat == -1)
+        aMess += "Cannot open SHP file";
+      else if (aStat == -2)
+        aMess += "Cannot open SHX file";
+      else 
+        aMess += "The shape type of file is " + anImporter.GetShapeTypeName(aShapeTypeOfFile);
+      SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), aMess);
+      commitDocOperation();
+      //abort();
     }
     anImporter.Free();