Salome HOME
refs #640: correct width for non-georeferenced profile
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportLandCoverOp.cxx
index d492a66823ff830d3c4ebbac903cb06306d97494..6b026e90349e3693d935514f2b18808b5a64e80a 100644 (file)
@@ -215,67 +215,79 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected()
     TopTools_SequenceOfShape aFaces;
     HYDROData_ShapeFile anImporter;
 
-    if (!anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces))
-    {
-      SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
-      abort();
-    }
-
-    aPanel->setPolygonNames(aPolygonsList);
-
     SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
-    if ( !aStudy ) {
+    if ( !aStudy )
       return;
-    }
 
     erasePreview();
 
     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() )
-      setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
-    OCCViewer_ViewManager* aViewManager = getPreviewManager();
+      LightApp_Application* anApp = module()->getApp();
+      if ( !getPreviewManager() )
+        setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+      OCCViewer_ViewManager* aViewManager = getPreviewManager();
 
-    if ( aViewManager )
-    {
-      if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+      if ( aViewManager )
       {
-        aCtx = aViewer->getAISContext();
-        connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+        if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+        {
+          aCtx = aViewer->getAISContext();
+          connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+        }
       }
-    }
-
 
-    QApplication::restoreOverrideCursor();
-
-    Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );
-    for ( int i = 1; i <= aFaces.Length(); i++ ) 
-    {
-      TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i ));
-
-      aLC->setShape( aFace );      
-      
-      if ( aViewManager && !aCtx.IsNull() )
+      Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );
+      for ( int i = 1; i <= aFaces.Length(); i++ ) 
       {
-        HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+        TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i ));
+
+        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 );
+          if( !aFace.IsNull() )
+            aShape->setShape( aLC->GetShape() );
+          myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape);
+        }
+      }
+      aLC->Remove();
 
-        aShape->setFillingColor( HYDROData_LandCover::DefaultFillingColor(), false, false );
-        aShape->setBorderColor( HYDROData_LandCover::DefaultBorderColor(), false, false );
-        if( !aFace.IsNull() )
-          aShape->setShape( aLC->GetShape() );
-        myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape);
+      if ( !aCtx.IsNull() ) 
+      {
+        UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
+        aCtx->UpdateCurrentViewer();
       }
+      
+      QApplication::restoreOverrideCursor();
+      commitDocOperation();
     }
-    aLC->Remove();
-
-    if ( !aCtx.IsNull() ) {
-      UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
-      aCtx->UpdateCurrentViewer();
+    else
+    {
+      erasePreview();
+      aPanel->setPolygonNames(QStringList());
+      aPanel->setObjectName("");
+      QApplication::restoreOverrideCursor();
+      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();
     }
-
-    commitDocOperation();
-
     anImporter.Free();
 
   }