From 6dd1807886655d96b021fbfb6ba736d79d49a492 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 5 Nov 2015 12:54:26 +0300 Subject: [PATCH] LCM // Import/Export of SHP p.6 --- src/HYDROData/HYDROData_LandCoverMap.cxx | 2 +- src/HYDROData/HYDROData_ShapeFile.cxx | 23 ++++++++++++----- src/HYDROData/HYDROData_ShapeFile.h | 25 ++++++++++++++++--- src/HYDROGUI/HYDROGUI_ExportFileOp.cxx | 17 +++++++++---- .../HYDROGUI_ImportLandCoverMapOp.cxx | 12 ++++++--- src/HYDROGUI/HYDROGUI_Module.cxx | 4 ++- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index bad3d009..e2ff679f 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -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; diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 969bba9c..b8b3effd 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -64,7 +64,6 @@ HYDROData_ShapeFile::~HYDROData_ShapeFile() void HYDROData_ShapeFile::Export(const QString& aFileName, NCollection_Sequence aPolyXYSeq, NCollection_Sequence 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; diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index 4704d91a..ec7b0ff3 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -84,24 +84,39 @@ public: HYDRODATA_EXPORT void Export(const QString& aFileName, NCollection_Sequence aPolyXYSeq, NCollection_Sequence 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& theEntities); + int theInd, NCollection_Sequence& theEntities); + void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities); + int theInd, NCollection_Sequence& theEntities); + HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, - NCollection_Sequence& theEntities, int& theShapeTypeOfFile); + NCollection_Sequence& 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 mySHPObjects; SHPHandle myHSHP; diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index 84fd272e..72915e5d 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx @@ -71,9 +71,7 @@ void HYDROGUI_ExportFileOp::startOperation() Handle(HYDROData_Polyline3D) aPoly3D; NCollection_Sequence aPolyXYSeq; NCollection_Sequence 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"; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 14c7e04b..45f345fb 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -68,6 +68,8 @@ #include //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; + } } } } diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 168dc17f..f8baa64d 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -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 -- 2.39.2