]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #728
authorisn <isn@opencascade.com>
Thu, 19 Nov 2015 09:46:49 +0000 (12:46 +0300)
committerisn <isn@opencascade.com>
Thu, 19 Nov 2015 09:55:38 +0000 (12:55 +0300)
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx

index 42936173613dedc144156dc450b255dd39fbd97a..51ca1b02c5ab08692fce0b120709fed0eb170a96 100644 (file)
@@ -711,6 +711,11 @@ int HYDROData_ShapeFile::TryOpenShapeFile(QString theFileName)
 {
   QString aSHPfile = theFileName.simplified();
   QString aSHXfile = theFileName.simplified().replace( theFileName.simplified().size() - 4, 4, ".shx");
+
+  QString anExt = theFileName.split('.', QString::SkipEmptyParts).back();
+  if (anExt.toLower() != "shp")
+    return -3;
+
   FILE* pFileSHP = NULL;
   pFileSHP = fopen (aSHPfile.toAscii().data(), "r");
   FILE* pFileSHX = NULL;
index e8797abf390d31fac2ad239f10ec94fb69003e01..403a22634b0a72b8ccb03b995849078091a385cf 100644 (file)
@@ -113,106 +113,102 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
     return;
   }
 
-  QString anExt = myFileName.split('.', QString::SkipEmptyParts).back();
-
-  if (anExt == "shp")
-  {     
-    startDocOperation();    
-    QApplication::setOverrideCursor(Qt::WaitCursor);
-    
-    QStringList aPolygonsList;
-    myPolygonFaces.Clear();
-    myImporter.Free();
+  startDocOperation();    
+  QApplication::setOverrideCursor(Qt::WaitCursor);
+  
+  QStringList aPolygonsList;
+  myPolygonFaces.Clear();
+  myImporter.Free();
 
-    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;
-    int aShapeTypeOfFile = -1;
+  Handle(AIS_InteractiveContext) aCtx = NULL;
+  int aShapeTypeOfFile = -1;
 
-    //Import polygons from SHP file as faces
-    //This faces should be added to the new LCM object
+  //Import polygons from SHP file as faces
+  //This faces should be added to the new LCM object
 
-    int aStat = myImporter.ImportPolygons(myFileName, aPolygonsList, myPolygonFaces, aShapeTypeOfFile);
-    if (aStat == 1)
-    {
-      aPanel->setPolygonNames(aPolygonsList);
+  int aStat = myImporter.ImportPolygons(myFileName, aPolygonsList, myPolygonFaces, 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 ( aViewManager )
+    {
+      if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
       {
-        if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
-        {
-          aCtx = aViewer->getAISContext();
-          connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
-        }
+        aCtx = aViewer->getAISContext();
+        connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
       }
+    }
 
-      for ( int i = 1; i <= myPolygonFaces.Length(); i++ ) 
+    for ( int i = 1; i <= myPolygonFaces.Length(); i++ ) 
+    {
+      TopoDS_Face aFace = TopoDS::Face(myPolygonFaces.Value( i ));
+      if ( aViewManager && !aCtx.IsNull() )
       {
-        TopoDS_Face aFace = TopoDS::Face(myPolygonFaces.Value( i ));
-        if ( aViewManager && !aCtx.IsNull() )
-        {
-          HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
-          //Preview color is grey
-          aShape->setFillingColor(QColor(50,50,50), false, false);
-          aShape->setBorderColor(QColor(50,50,50), false, false);
-          if( !aFace.IsNull() )
-            aShape->setShape( aFace);
-
-          myPolygonName2PrsShape.insert( tr( "DEF_POLYGON_NAME" ) + "_" + QString::number(i), aShape);
-        }
+        HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+        //Preview color is grey
+        aShape->setFillingColor(QColor(50,50,50), false, false);
+        aShape->setBorderColor(QColor(50,50,50), false, false);
+        if( !aFace.IsNull() )
+          aShape->setShape( aFace);
+
+        myPolygonName2PrsShape.insert( tr( "DEF_POLYGON_NAME" ) + "_" + QString::number(i), aShape);
       }
+    }
 
-      if ( !aCtx.IsNull() ) 
-      {
-        UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
-        aCtx->UpdateCurrentViewer();
-      }
-      //
-      QApplication::restoreOverrideCursor();
-      aPanel->setFirstPageState(true); 
-      //
-      //Try to load DBF-database...
-      QString aDBFFileName;
-      aDBFFileName = myFileName.simplified().replace( myFileName.simplified().size() - 4, 4, ".dbf");
-      bool DBF_Stat = myImporter.DBF_OpenDBF(aDBFFileName);
-      // TODO:
-      // add MSG BOX if stat is bad
-      if (DBF_Stat)
-      {
-        myFieldList = myImporter.DBF_GetFieldList();
-        aPanel->setAttributeNames(myFieldList);
-      }
-      aPanel->setDbfState(DBF_Stat);
+    if ( !aCtx.IsNull() ) 
+    {
+      UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
+      aCtx->UpdateCurrentViewer();
     }
-    else
+    //
+    QApplication::restoreOverrideCursor();
+    aPanel->setFirstPageState(true); 
+    //
+    //Try to load DBF-database...
+    QString aDBFFileName;
+    aDBFFileName = myFileName.simplified().replace( myFileName.simplified().size() - 4, 4, ".dbf");
+    bool DBF_Stat = myImporter.DBF_OpenDBF(aDBFFileName);
+    // TODO:
+    // add MSG BOX if stat is bad
+    if (DBF_Stat)
     {
-      erasePreview();
-      aPanel->setPolygonNames(QStringList());
-      aPanel->setObjectName("");
-      QApplication::restoreOverrideCursor();
-      QString aMess = tr( "CANNT_IMPORT_LCM" ) + "\n"; 
-      if (aStat == -1)
-        aMess += tr( "CANNT_OPEN_SHP" );
-      else if (aStat == -2)
-        aMess += tr( "CANNT_OPEN_SHX" );
-      else 
-        aMess += tr ("SHP_TYPEFORMAT_MESS") + myImporter.GetShapeTypeName(aShapeTypeOfFile);
-      SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER_MAP" ), aMess);
-      commitDocOperation();
-      myImporter.Free();
-      //abort();
-      aPanel->setFirstPageState(false);
+      myFieldList = myImporter.DBF_GetFieldList();
+      aPanel->setAttributeNames(myFieldList);
     }
+    aPanel->setDbfState(DBF_Stat);
+  }
+  else
+  {
+    erasePreview();
+    aPanel->setPolygonNames(QStringList());
+    aPanel->setObjectName("");
+    QApplication::restoreOverrideCursor();
+    QString aMess = tr( "CANNT_IMPORT_LCM" ) + "\n"; 
+    if (aStat == -1)
+      aMess += tr( "CANNT_OPEN_SHP" );
+    else if (aStat == -2)
+      aMess += tr( "CANNT_OPEN_SHX" );
+    else 
+      aMess += tr ("SHP_TYPEFORMAT_MESS") + myImporter.GetShapeTypeName(aShapeTypeOfFile);
+    SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER_MAP" ), aMess);
+    commitDocOperation();
+    myImporter.Free();
+    //abort();
+    aPanel->setFirstPageState(false);
   }
+
 }
 
 HYDROGUI_InputPanel* HYDROGUI_ImportLandCoverMapOp::createInputPanel() const