]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
LCM // Import/Export of SHP p.6
authorisn <isn@opencascade.com>
Thu, 5 Nov 2015 09:54:26 +0000 (12:54 +0300)
committerisn <isn@opencascade.com>
Thu, 5 Nov 2015 09:54:26 +0000 (12:54 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx

index bad3d009d434f55a4b79bdbbfb1c17cd06bfd96b..e2ff679f256708204588327a8cb500f2229dfa17 100644 (file)
@@ -207,7 +207,7 @@ int HYDROData_LandCoverMap::GetLCCount() const
 bool HYDROData_LandCoverMap::IsEmpty() const
 {
   Iterator anIt( *this );
-  if ( anIt.More() )
+  if ( !anIt.More() )
     return true;
   else
     return false;
index 969bba9c286e53e64f5465888772ca3384cd7de5..b8b3effd5bf74d6a2af4ed318e95c6400d448e3b 100644 (file)
@@ -64,7 +64,6 @@ HYDROData_ShapeFile::~HYDROData_ShapeFile()
 void HYDROData_ShapeFile::Export(const QString& aFileName, 
   NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
   NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
-  const Handle_HYDROData_LandCoverMap& aLCM,
   QStringList& aNonExpList)
 {
   SHPHandle hSHPHandle;
@@ -74,7 +73,6 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
     for (int i = 1; i <= aPolyXYSeq.Size(); i++)
       if (WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(i)) != 1)
         aNonExpList.append(aPolyXYSeq(i)->GetName());
-
   }
   else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
   {
@@ -83,7 +81,22 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
       if (WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i)) != 1)
         aNonExpList.append(aPoly3DSeq(i)->GetName());
   }
-  else if (aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty() && !aLCM->IsEmpty())
+  if (hSHPHandle->nRecords > 0)
+    SHPClose( hSHPHandle );
+  else
+  {
+    SHPClose( hSHPHandle );
+    QString aFN = aFileName.simplified();
+    remove (aFN.toStdString().c_str());
+    remove (aFN.replace( ".shp", ".shx", Qt::CaseInsensitive).toStdString().c_str());
+  }
+}
+
+void HYDROData_ShapeFile::Export(const QString& aFileName,
+  const Handle_HYDROData_LandCoverMap& aLCM, QStringList& aNonExpList)
+{
+  SHPHandle hSHPHandle;
+  if ( !aLCM.IsNull() && !aLCM->IsEmpty())
   {
     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
     HYDROData_LandCoverMap::Iterator It( aLCM );
@@ -93,9 +106,6 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
       if (WriteObjectPolygon(hSHPHandle, aFace) != 1)
         aNonExpList.append(aLCM->GetName() + "_" +  QString::number(It.Index()));
     }
-    /*for (int i = 1; i <= aLCSeq.Size(); i++)
-      if (WriteObjectLC(hSHPHandle, aLCSeq(i)) != 1)
-        aNonExpList.append(aLCSeq(i)->GetName());*/
   }
   if (hSHPHandle->nRecords > 0)
     SHPClose( hSHPHandle );
@@ -108,6 +118,7 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
   }
 }
 
+
 int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
 {
   SHPObject    *aSHPObj;
index 4704d91a88b6c1b5dbf67f537bb6d5a006643483..ec7b0ff3602caf610bfc6fbb30c7f696ec31e864 100644 (file)
@@ -84,24 +84,39 @@ public:
   HYDRODATA_EXPORT void Export(const QString& aFileName, 
                                NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
                                NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
+                               QStringList& aNonExpList);
+
+  HYDRODATA_EXPORT void Export(const QString& aFileName,
                                const Handle_HYDROData_LandCoverMap& aLCM,
                                QStringList& aNonExpList);
+
   int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
+
   int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
+
   int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape );
   //Import
   bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile);
   //Import Landcover
   void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F);
-  HYDRODATA_EXPORT int ImportPolygons(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile);
+
+  HYDRODATA_EXPORT int ImportPolygons(const QString theFileName, 
+                                      QStringList& thePolygonsList, 
+                                      TopTools_SequenceOfShape& theFaces, 
+                                      int& theShapeTypeOfFile);
+
   HYDRODATA_EXPORT void Free();
+
   //Import Polyline
   void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
-                        int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+                     int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+
   void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
-                        int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+                     int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+
   HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, 
-                       NCollection_Sequence<Handle_HYDROData_Entity>& theEntities, int& theShapeTypeOfFile);
+                                       NCollection_Sequence<Handle_HYDROData_Entity>& theEntities, int& theShapeTypeOfFile);
+
   HYDRODATA_EXPORT QString GetShapeTypeName(int theType);
 
   //DBF I/O Methods
@@ -117,7 +132,9 @@ public:
 
 private:
   void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
+
   int TryOpenShapeFile(QString theFileName);
+
 private:
   std::vector<SHPObject*> mySHPObjects;
   SHPHandle myHSHP;
index 84fd272ef38dfcd153b0e488b243dbd954341f4c..72915e5d7d2bd5bb15c6d035fa20e8dcfa2f86e2 100644 (file)
@@ -71,9 +71,7 @@ void HYDROGUI_ExportFileOp::startOperation()
   Handle(HYDROData_Polyline3D) aPoly3D;
   NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
   NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
-  // TODO
-  Handle_HYDROData_LandCoverMap aLCSeq;
-  
+  //
   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
   for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
   {
@@ -100,8 +98,17 @@ void HYDROGUI_ExportFileOp::startOperation()
     {
       QStringList aNonExpList;
       HYDROData_ShapeFile anExporter;
-      // TODO
-      anExporter.Export(aFileName,  aPolyXYSeq, aPoly3DSeq, aLCSeq, aNonExpList);
+      if (!aPolyXYSeq.IsEmpty() || !aPolyXYSeq.IsEmpty())
+        //Export polylines
+        anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
+      else
+      {
+        //Export polygons
+        //aSeq.Size() <= 1
+        Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
+        anExporter.Export(aFileName, aLCM, aNonExpList);
+      }
+
       if (!aNonExpList.empty())
       {
         QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n";
index 14c7e04ba85e2ea04369a3453788e270d2de1088..45f345fbb955864a9112126134a9c82d651fea43 100644 (file)
@@ -68,6 +68,8 @@
 #include <HYDROData_LandCoverMap.h>
 
 //TODO add definitions into TS file
+//TODO check if LCM name is already exists..
+//rename it
 HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
 {
@@ -207,7 +209,7 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
       aPanel->setPolygonNames(QStringList());
       aPanel->setObjectName("");
       QApplication::restoreOverrideCursor();
-      QString aMess = "Cannot import content of this file as land cover map;\n";
+      QString aMess = "Cannot import land cover;\n";
       if (aStat == -1)
         aMess += "Cannot open SHP file";
       else if (aStat == -2)
@@ -245,7 +247,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
   if ( !aPanel ) 
     return false;
 
-  myLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
+  myLCM =  Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
   HYDROData_MapOfFaceToStricklerType aMapFace2ST;
 
   QStringList aAttrV_T;
@@ -400,12 +402,16 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
       HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
       for( ; It.More(); It.Next() )
       {
-        Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );      
+        Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+        QString TT  = aStricklerTableObj->GetAttrName();
         if ( !aStricklerTableObj.IsNull())
         {
           const QStringList& aStricklerList = aStricklerTableObj->GetTypes();
           foreach (QString aStr, aStricklerList)
+          {
+            QString AttVal = aStricklerTableObj->GetAttrValue(aStr);
             aSTSet << aStr;
+          }
         }
       }
     }
index 168dc17f92b772ad30112b81b1c39e33c4b11878..f8baa64dad4958f33f13aca77f8a121ee9a141ef 100644 (file)
@@ -679,6 +679,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SplitLandCoverId ) );
         theMenu->addAction( action( MergeLandCoverId ) );
         theMenu->addSeparator();
+        //
+        theMenu->addAction( action( ExportToShapeFileID ) );
       }      
       else if( anIsVisualState && anIsObjectBrowser )
       {
@@ -705,7 +707,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     }
 
     bool anIsPoly = anIsPolyline || anIsPolyline3D;
-    if ((anIsPoly && !anIsLandCoverMap) || (!anIsPoly && anIsLandCoverMap))
+    if (anIsPoly && !anIsLandCoverMap)
       theMenu->addAction( action( ExportToShapeFileID ) );
 
     // Add copy action