X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ExportFileOp.cxx;h=bd4825e3449723c3b465d359f484a6a9aa1c1f80;hb=80b3ef265c1b8564a52097094156256956017ae1;hp=2cfb54abf315d66b4378b9b2d6416801ec11be29;hpb=f169205c4f5f2d077a35ba9e1db8f143fbba70c3;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index 2cfb54ab..bd4825e3 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx @@ -1,8 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -26,12 +22,15 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_ExportLandCoverMapDlg.h" #include #include #include #include #include +#include + #include #include @@ -54,6 +53,12 @@ #include #include #include +#include +#include +#include + +#include +#include HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -75,9 +80,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++ ) { @@ -104,8 +107,82 @@ 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 + //Extract all attribute names from all strickler tables + Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); + QSet anAttrNames; + //use QSet to store attribute names. Yet it's not so good if the document contains two strickler types + //with the same name + if (aDoc) + { + HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); + if ( !aStricklerTableObj.IsNull()) + anAttrNames << aStricklerTableObj->GetAttrName(); + } + } + else + return; + + // + HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), anAttrNames.toList()); + if ( aDlg.exec() == HYDROGUI_ExportLandCoverMapDlg::Accepted ) + { + //In our case : aSeq.Size() == 1 + //Export of multiple landcover maps into the one shp-file is disallowed. + Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) ); + QString aCItem = aDlg.getCurrentItem(); + Handle(HYDROData_StricklerTable) aStricklerTableObj; + { + HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); + if ( !aStricklerTableObj.IsNull() && aStricklerTableObj->GetAttrName() == aCItem) + break; + } + } + + //export shape-data + anExporter.Export(aFileName, aLCM, aNonExpList); + QString aDBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive); + //Even if attribute-checkbox is unchecked, the .dbf-file should be removed. + //otherwise it may be used with wrong .shp-file. This is an incorrect behaivor. + remove (aDBFFileName.toStdString().c_str()); + bool bToSaveAttrInfo = aDlg.getAttrCheckBoxState(); + if (bToSaveAttrInfo) + { + //export attribute info + QStringList anAttrValues; + QStringList aStricklerTypes; + if (aNonExpList.empty()) + { + HYDROData_LandCoverMap::Explorer aLCMIt( aLCM ); + for( ; aLCMIt.More(); aLCMIt.Next() ) + { + QString aST = aLCMIt.StricklerType(); + anAttrValues << aStricklerTableObj->GetAttrValue(aST); + aStricklerTypes << aST; + } + } + aLCM->ExportDBF(aDBFFileName, aCItem, anAttrValues, aStricklerTypes); + } + } + else + { + abort(); + return; + } + + } + if (!aNonExpList.empty()) { QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n";