X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ExportFileOp.cxx;h=b256ba4f28d70a4b9376bde57cff4aef3c63ecd7;hb=e91225b4527adcbf95b59d83f1d5ea26197b7582;hp=b52e18b030b71a5ed8ee813e60beab4de588545e;hpb=ac939ad4e77e0fe3facca2a640e14b90457aaa6f;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index b52e18b0..b256ba4f 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 @@ -25,12 +21,15 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_UpdateFlags.h" -#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Tool2.h" +#include "HYDROGUI_ExportLandCoverMapDlg.h" #include #include #include #include -#include +#include + +#include #include @@ -46,9 +45,20 @@ #include #include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -68,11 +78,9 @@ void HYDROGUI_ExportFileOp::startOperation() Handle(HYDROData_PolylineXY) aPolyXY; Handle(HYDROData_Polyline3D) aPoly3D; - Handle(HYDROData_LandCover) aLC; NCollection_Sequence aPolyXYSeq; NCollection_Sequence aPoly3DSeq; - NCollection_Sequence aLCSeq; - + // HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { @@ -83,44 +91,108 @@ void HYDROGUI_ExportFileOp::startOperation() aPoly3D = Handle(HYDROData_Polyline3D)::DownCast( aSeq.Value( anIndex )); if (!aPoly3D.IsNull()) aPoly3DSeq.Append(aPoly3D); - - aLC = Handle(HYDROData_LandCover)::DownCast( aSeq.Value( anIndex )); - if (!aLC.IsNull()) - aLCSeq.Append(aLC); } if (!aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty()) - SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export Polyline", "Cannot export polylines of different kind"); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), tr("ERROR_POLYLINES_OF_DIFF_KIND")); else { - QString aPolyName = ""; + QString aName = ""; if (aPolyXYSeq.Size() == 1 && aPoly3DSeq.IsEmpty()) - aPolyName = aPolyXYSeq(1)->GetName(); + aName = aPolyXYSeq(1)->GetName(); if (aPoly3DSeq.Size() == 1 && aPolyXYSeq.IsEmpty()) - aPolyName = aPoly3DSeq(1)->GetName(); - QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aPolyName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false ); + aName = aPoly3DSeq(1)->GetName(); + QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false ); if (!aFileName.isEmpty()) { - SHPHandle hSHPHandle; - if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty()) + QStringList aNonExpList; + HYDROData_ShapeFile anExporter; + if (!aPolyXYSeq.IsEmpty() || !aPolyXYSeq.IsEmpty()) + //Export polylines + anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList); + else { - hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARC ); - for (int i = 1; i <= aPolyXYSeq.Size(); i++) - WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(i)); - } - else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty()) - { - hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARCZ ); - for (int i = 1; i <= aPoly3DSeq.Size(); i++) - WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i)); + //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; + + QStringList SortedListOfAttr = anAttrNames.toList(); + SortedListOfAttr.sort(); + // + Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) ); + bool IsLinear = aLCM->CheckLinear(); + HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), IsLinear, SortedListOfAttr); + if ( aDlg.exec() == HYDROGUI_ExportLandCoverMapDlg::Accepted ) + { + //In our case : aSeq.Size() == 1 + //Export of multiple landcover maps into the one shp-file is disallowed. + 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, false, !IsLinear, aDlg.getDeflValue()); + 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() && !aDlg.getCurrentItem().isEmpty(); + 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; + } + } - else if (aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty() && !aLCSeq.IsEmpty()) + + if (!aNonExpList.empty()) { - hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON ); - for (int i = 1; i <= aLCSeq.Size(); i++) - WriteObjectLC(hSHPHandle, aLCSeq(i)); + QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n"; + foreach (QString anNonExpEntName, aNonExpList) + aMessage += anNonExpEntName + "\n"; + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), aMessage); } - SHPClose( hSHPHandle ); commit(); } else @@ -129,137 +201,3 @@ void HYDROGUI_ExportFileOp::startOperation() } -void HYDROGUI_ExportFileOp::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly ) -{ - SHPObject *aSHPObj; - std::vector x, y; - std::vector anPartStart; - - for (int i = 0; i < thePoly->NbSections(); i++) - { - anPartStart.push_back(x.size()); - HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPoints(i); - for (int j = 1; j <= aPointList.Size(); j++) - { - x.push_back( aPointList(j).X()); - y.push_back( aPointList(j).Y()); - } - if (thePoly->IsClosedSection(i)) - { - x.push_back( aPointList(1).X()); - y.push_back( aPointList(1).Y()); - } - } - - aSHPObj = SHPCreateObject( SHPT_ARC, -1, thePoly->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL ); - SHPWriteObject( theShpHandle, -1, aSHPObj ); - SHPDestroyObject( aSHPObj ); -} - -void HYDROGUI_ExportFileOp::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ) -{ - SHPObject *aSHPObj; - std::vector x, y, z; - std::vector anPartStart; - - for (int i = 0; i < thePoly->GetPolylineXY()->NbSections(); i++) - { - anPartStart.push_back(x.size()); - HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPolylineXY()->GetPoints(i); - for (int j = 1; j <= aPointList.Size(); j++) - { - x.push_back( aPointList(j).X()); - y.push_back( aPointList(j).Y()); - z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(j).X(), aPointList(j).Y()))); - } - if ( thePoly->GetPolylineXY()->IsClosedSection(i)) - { - x.push_back( aPointList(1).X()); - y.push_back( aPointList(1).Y()); - z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(1).X(), aPointList(1).Y()))); - - } - } - - aSHPObj = SHPCreateObject( SHPT_ARCZ, -1, thePoly->GetPolylineXY()->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], &z[0], NULL ); - SHPWriteObject( theShpHandle, -1, aSHPObj ); - SHPDestroyObject( aSHPObj ); -} - -void HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC ) -{ - - TopoDS_Shape aSh = theLC->GetShape(); - if (aSh.IsNull()) - return; - if (aSh.ShapeType() == TopAbs_FACE) - { - ProcessFace(TopoDS::Face(aSh), theShpHandle); - } - else if (aSh.ShapeType() == TopAbs_COMPOUND) - { - TopExp_Explorer Ex(aSh, TopAbs_FACE); - for (; Ex.More(); Ex.Next()) - { - TopoDS_Face aF = TopoDS::Face(Ex.Current()); - if (aF.IsNull()) - continue; - ProcessFace(aF, theShpHandle); - } - } - else - return; - -} - -void HYDROGUI_ExportFileOp::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle) -{ - SHPObject *aSHPObj; - std::vector x, y; - std::vector anPartStart; - if (theFace.ShapeType() == TopAbs_FACE) - { - TopExp_Explorer Ex(theFace, TopAbs_WIRE); - int NbWires = 0; - for (; Ex.More(); Ex.Next()) - { - TopoDS_Wire aW = TopoDS::Wire(Ex.Current()); - if (aW.IsNull()) - continue; - NbWires++; - anPartStart.push_back(x.size()); - TopExp_Explorer aVEx(aW, TopAbs_VERTEX); - NCollection_Sequence aPnts; - for (; aVEx.More(); aVEx.Next()) - { - TopoDS_Vertex aV = TopoDS::Vertex(aVEx.Current()); - if (aV.IsNull()) - continue; - gp_Pnt P = BRep_Tool::Pnt(aV); - aPnts.Append(gp_Pnt2d(P.X(), P.Y())); - } - NCollection_Sequence aNPnts; - aNPnts.Append(aPnts.First()); - for (int j = 1; j <= aPnts.Size() - 1; j++) - { - if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion())) - aNPnts.Append(aPnts(j + 1)); - } - - for (int j = 1; j <= aNPnts.Size(); j++) - { - x.push_back( aNPnts(j).X()); - y.push_back( aNPnts(j).Y()); - } - //x.push_back( aNPnts(1).X()); - //y.push_back( aNPnts(1).Y()); - - } - - aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL ); - SHPWriteObject( theShpHandle, -1, aSHPObj ); - SHPDestroyObject( aSHPObj ); - } - else - return; -}