-// 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
#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 <HYDROData_PolylineXY.h>
#include <HYDROData_Polyline3D.h>
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Bathymetry.h>
-#include <HYDROData_LandCover.h>
+#include <HYDROData_LandCoverMap.h>
+
+#include <HYDROData_StricklerTable.h>
#include <HYDROData_Profile.h>
#include <TopoDS_Edge.hxx>
#include <BRep_Tool.hxx>
#include <Precision.hxx>
-#include <Handle_Geom_Curve.hxx>
-#include <Handle_Geom_Line.hxx>
-#include <Handle_Geom_TrimmedCurve.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_TrimmedCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <HYDROData_ShapeFile.h>
+#include <SUIT_Desktop.h>
+#include <SalomeApp_Study.h>
+#include <HYDROData_Iterator.h>
+
+#include <LightApp_Application.h>
+#include <QSet>
HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
Handle(HYDROData_PolylineXY) aPolyXY;
Handle(HYDROData_Polyline3D) aPoly3D;
- Handle(HYDROData_LandCover) aLC;
- NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
- NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
- NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq;
-
+ NCollection_Sequence<Handle(HYDROData_PolylineXY)> aPolyXYSeq;
+ NCollection_Sequence<Handle(HYDROData_Polyline3D)> aPoly3DSeq;
+ //
HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
{
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())
aName = aPolyXYSeq(1)->GetName();
if (aPoly3DSeq.Size() == 1 && aPolyXYSeq.IsEmpty())
aName = aPoly3DSeq(1)->GetName();
- if (aLCSeq.Size() == 1 && aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
- aName = aLCSeq(1)->GetName();
QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false );
if (!aFileName.isEmpty())
{
QStringList aNonExpList;
HYDROData_ShapeFile anExporter;
- anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aLCSeq, aNonExpList);
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+ if (!aPolyXYSeq.IsEmpty() || !aPolyXYSeq.IsEmpty())
+ //Export polylines
+ anExporter.Export(aDoc, aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
+ else
+ {
+ //Export polygons
+ //Extract all attribute names from all strickler tables
+ QSet<QString> 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(aDoc, 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;
+ }
+
+ }
+
if (!aNonExpList.empty())
{
QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n";