From 5c0a47f396c68b7d9544d93942281a95f04aef9b Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 17 Nov 2015 16:17:20 +0300 Subject: [PATCH] Use discretization to write non-linear borders of LCM to SHP file // p.4 --- src/HYDROData/HYDROData_LandCoverMap.cxx | 33 +++++++++++++++++++ src/HYDROData/HYDROData_LandCoverMap.h | 2 ++ src/HYDROData/HYDROData_ShapeFile.cxx | 32 +++--------------- src/HYDROData/HYDROData_ShapeFile.h | 1 + src/HYDROGUI/HYDROGUI_ExportFileOp.cxx | 7 ++-- .../HYDROGUI_ExportLandCoverMapDlg.cxx | 22 ++++++++++++- src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h | 8 ++++- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 9 +++++ 8 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 33a705cd..3976299f 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -55,6 +55,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -828,6 +832,10 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co QString aSType = anIt.StricklerType(); //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl; TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() ); + + // + TopTools_ListOfShape aGen = aBuilder.Generated( anIt.Face() ); + // if( aModified.Extent() == 0 ) aModified.Append( anIt.Face() ); @@ -1059,3 +1067,28 @@ bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUse return false; } +bool HYDROData_LandCoverMap::CheckLinear() +{ + TopoDS_Shape InpShape = GetShape(); + TopExp_Explorer anEdgeEx(InpShape, TopAbs_EDGE); + for (; anEdgeEx.More(); anEdgeEx.Next()) + { + TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current()); + double aFP, aLP; + Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP); + Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur); + if (aLine.IsNull()) + { + Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur); + if (!aTC.IsNull()) + { + Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve()); + if (aLine.IsNull()) + return false; + } + else + return false; + } + } + return true; +} diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index c2437d8c..c6535eec 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -143,6 +143,8 @@ public: HYDRODATA_EXPORT TopoDS_Shape RemoveInternal(const TopoDS_Shape& InSh); + HYDRODATA_EXPORT bool CheckLinear(); + protected: void SetShape( const TopoDS_Shape& ); diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 8b0711f8..508ddec7 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -105,8 +105,11 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, } void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, - QStringList& aNonExpList, bool bUseDiscr, double theDefl) + QStringList& aNonExpList, bool bCheckLinear, bool bUseDiscr, double theDefl) { + if (bCheckLinear && !aLCM->CheckLinear()) + return; + // SHPHandle hSHPHandle; if ( !aLCM.IsNull() && !aLCM->IsEmpty()) { @@ -204,9 +207,6 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS if (theInputShape.IsNull()) return 0; - if (!bUseDiscr && !CheckLinear(theInputShape)) - return -1; - if (theInputShape.ShapeType() == TopAbs_FACE) { ProcessFace(TopoDS::Face(theInputShape), theShpHandle, bUseDiscr, theDefl); @@ -990,27 +990,3 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co } -bool HYDROData_ShapeFile::CheckLinear(const TopoDS_Shape& theInpShape) -{ - TopExp_Explorer anEdgeEx(theInpShape, TopAbs_EDGE); - for (; anEdgeEx.More(); anEdgeEx.Next()) - { - TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current()); - double aFP, aLP; - Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP); - Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur); - if (aLine.IsNull()) - { - Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur); - if (!aTC.IsNull()) - { - Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve()); - if (aLine.IsNull()) - return false; - } - else - return false; - } - } - return true; -} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index 95a8b175..16d92ad1 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -89,6 +89,7 @@ public: HYDRODATA_EXPORT void Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, QStringList& aNonExpList, + bool bCheckLinear = true, bool bUseDiscr = false, double theDefl = 0.1); diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index bd4825e3..9b17e6a7 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx @@ -132,12 +132,13 @@ void HYDROGUI_ExportFileOp::startOperation() return; // - HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), anAttrNames.toList()); + Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) ); + bool IsLinear = aLCM->CheckLinear(); + HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), IsLinear, 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; { @@ -151,7 +152,7 @@ void HYDROGUI_ExportFileOp::startOperation() } //export shape-data - anExporter.Export(aFileName, aLCM, aNonExpList); + 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. diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx index 9da8db36..28533ef7 100644 --- a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx @@ -23,8 +23,10 @@ #include #include #include +#include +#include -HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& theAttrItems ) +HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, bool IsLinear, const QStringList& theAttrItems ) : QtxDialog( theParent, false, true, QtxDialog::OKCancel ) { setWindowTitle( tr( "EXPORT_LANDCOVERMAP" ) ); @@ -43,6 +45,19 @@ HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* thePare aLayout->addWidget( myAttrCheckBox, 0, 0 ); aLayout->addWidget( myAvFields, 1, 0, 1, 2 ); + if(!IsLinear) + { + myDiscrLabel = new QLabel( tr( "LCM_DISCR_LABEL" ), mainFrame() ); + myDeflSpinBox = new QDoubleSpinBox( mainFrame() ); + myDeflSpinBox->setRange(0.001, 2); + myDeflSpinBox->setDecimals(3); + myDeflSpinBox->setSingleStep(0.001); + myDeflLabel = new QLabel ( tr( "LCM_DEFL_LABEL" ), mainFrame() ); + aLayout->addWidget( myDiscrLabel, 2, 0 ); + aLayout->addWidget( myDeflLabel, 3, 0, 1, 1 ); + aLayout->addWidget( myDeflSpinBox, 3, 1, 2, 2 ); + } + setMinimumSize( 300, 100 ); connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool))); @@ -70,3 +85,8 @@ bool HYDROGUI_ExportLandCoverMapDlg::getAttrCheckBoxState() { return myAttrCheckBox->isChecked(); } + +double HYDROGUI_ExportLandCoverMapDlg::getDeflValue() const +{ + return myDeflSpinBox->value(); +} diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h index eda646f5..005914f2 100644 --- a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h @@ -24,13 +24,15 @@ class QCheckBox; class QComboBox; +class QLabel; +class QDoubleSpinBox; class HYDROGUI_ExportLandCoverMapDlg : public QtxDialog { Q_OBJECT public: - HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent = 0, const QStringList& theAttrItems = QStringList()); + HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent = 0, bool IsLinear = false, const QStringList& theAttrItems = QStringList()); virtual ~HYDROGUI_ExportLandCoverMapDlg(); protected slots: @@ -39,10 +41,14 @@ protected slots: public: QString getCurrentItem() const; bool getAttrCheckBoxState(); + double getDeflValue() const; private: QCheckBox* myAttrCheckBox; QComboBox* myAvFields; + QLabel* myDiscrLabel; + QLabel* myDeflLabel; + QDoubleSpinBox* myDeflSpinBox; }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 16d67a97..b6fe4bde 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2433,6 +2433,15 @@ file cannot be correctly imported for an Obstacle definition. WRITE_ST_AS_ATTRS_TO_DBF Write Strickler Types as attributes values to DBF file + + LCM_DISCR_LABEL + Current Land Cover Map contains at least one non-linear border. It will be exported in the discretization mode + + + LCM_DEFL_LABEL + Enter a deflection value: + + -- 2.39.2