Salome HOME
++ shapefil
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportPolylineOp.cxx
index 1d02a454ce772bb972d0064c67b08a427a622b9d..a3c7f833205e32a8f7d36fafb8656da35172235a 100644 (file)
@@ -41,7 +41,7 @@
 #include <QApplication>
 #include <QFile>
 #include <QFileInfo>
-#include <QMessageBox>
+#include <SUIT_MessageBox.h>
 
 
 HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
@@ -77,82 +77,91 @@ void HYDROGUI_ImportPolylineOp::onApply()
     return;
   }
 
-  QString aFileName = myFileDlg->selectedFile();
-  if ( aFileName.isEmpty() )
+  QStringList aFileNames = myFileDlg->selectedFiles();
+  
+  QApplication::setOverrideCursor( Qt::WaitCursor );  
+  startDocOperation();
+
+  foreach (QString aFileName, aFileNames) 
   {
-    abort();
-    return;
-  }
+    if ( aFileName.isEmpty() )
+      continue;
 
-  QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
+    QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
 
-  if (anExt == "shp")
-  {
-    SHPHandle aHSHP;
-    aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
-    Parse(aHSHP);
-    
-    QApplication::setOverrideCursor( Qt::WaitCursor );
-    
-    startDocOperation();
+    if (anExt == "shp")
+    {
+      SHPHandle aHSHP;
+      aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
+      Parse(aHSHP);
 
-    HYDROData_Iterator anIter( doc() );
-    int anInd = 0;
-    QStringList anExistingNames;
-    std::vector<int> anAllowedIndexes;
-    for( ; anIter.More(); anIter.Next() )
-      anExistingNames.push_back(anIter.Current()->GetName());
+      HYDROData_Iterator anIter( doc() );
+      int anInd = 0;
+      QStringList anExistingNames;
+      std::vector<int> anAllowedIndexes;
+      for( ; anIter.More(); anIter.Next() )
+        anExistingNames.push_back(anIter.Current()->GetName());
 
-    QFileInfo aFileInfo(aFileName);
-    QString aBaseFileName = aFileInfo.baseName();
+      QFileInfo aFileInfo(aFileName);
+      QString aBaseFileName = aFileInfo.baseName();
 
-    if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23)
-    {
-      anInd = 0;
-      for (;anAllowedIndexes.size() < mySHPObjects.size();)
+      if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23)
       {
-        if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)))
+        anInd = 0;
+        for (;anAllowedIndexes.size() < mySHPObjects.size();)
         {
-          anAllowedIndexes.push_back(anInd);
-          anInd++;
+          if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)))
+          {
+            anAllowedIndexes.push_back(anInd);
+            anInd++;
+          }
+          else
+            anInd++;
+        }
+        
+        for (size_t i = 0; i < mySHPObjects.size(); i++ )
+        {
+          ProcessSHPPolyXY(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]);
         }
-        else
-          anInd++;
-      }
-      
-      for (size_t i = 0; i < mySHPObjects.size(); i++ )
-      {
-        ProcessSHPPolyXY(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]);
       }
-    }
-    else if (aHSHP->nShapeType == 13)
-    {
-      anInd = 0;
-      for (;anAllowedIndexes.size() < mySHPObjects.size();)
+      else if (aHSHP->nShapeType == 13)
       {
-        if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) &&
-            !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) &&
-            !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd)))
+        anInd = 0;
+        for (;anAllowedIndexes.size() < mySHPObjects.size();)
         {
-          anAllowedIndexes.push_back(anInd);
-          anInd++;
+          if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) &&
+              !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) &&
+              !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd)))
+          {
+            anAllowedIndexes.push_back(anInd);
+            anInd++;
+          }
+          else
+            anInd++;
         }
-        else
-          anInd++;
+        for (size_t i = 0; i < mySHPObjects.size(); i++ )
+          ProcessSHPPoly3D(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]);
       }
+      else  
+      {
+        SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), "Cannot import polyline;\nThe shape type is incorrect" );
+      }
+    
       for (size_t i = 0; i < mySHPObjects.size(); i++ )
-        ProcessSHPPoly3D(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]);
+        free (mySHPObjects[i]);
+
+      mySHPObjects.clear();
+      SHPClose(aHSHP);
     }
+  }
+  if (!aFileNames.empty())
+  {
     commitDocOperation();
     commit();
-    
-    for (size_t i = 0; i < mySHPObjects.size(); i++ )
-      free (mySHPObjects[i]);
-
-    mySHPObjects.clear();
-    SHPClose(aHSHP);
+    module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
   }
-  module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+  else
+    abort();
   
   QApplication::restoreOverrideCursor();
 }