const QStringList& theDBFValues,
const QStringList& theStricklerTypes) const
{
+ if (theDBFValues.size() != theStricklerTypes.size())
+ return;
HYDROData_ShapeFile anExporter;
std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
Iterator anIt( *this );
else
aCurAttrV.myIsNull = true;
}
-
- anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, true);
+ //use actual str value; not the raw value
+ anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
}
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <BRep_Tool.hxx>
+#include <BRepTools.hxx>
#include <Precision.hxx>
#include <Handle_Geom_Curve.hxx>
#include <Handle_Geom_Line.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <QColor>
#include <BRepTopAdaptor_FClass2d.hxx>
+#include <TopExp.hxx>
#ifdef WIN32
#pragma warning( disable: 4996 )
void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
{
+ if (theFace.ShapeType() != TopAbs_FACE)
+ return;
SHPObject *aSHPObj;
std::vector<double> x, y;
std::vector<int> anPartStart;
- if (theFace.ShapeType() == TopAbs_FACE)
+ TopoDS_Wire OuterW = BRepTools::OuterWire(theFace);
+ NCollection_Sequence<TopoDS_Wire> aWires;
+
+ //write an outer wire first
+ aWires.Append(OuterW);
+ TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ for (; Ex.More(); Ex.Next())
{
- TopExp_Explorer Ex(theFace, TopAbs_WIRE);
- int NbWires = 0;
- for (; Ex.More(); Ex.Next())
+ TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
+ if (aW.IsEqual(OuterW))
+ continue;
+ aWires.Append(aW);
+ }
+
+ //TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ int NbWires = 0;
+ for (int k = 1; k <= aWires.Length(); k++)
+ {
+ TopoDS_Wire aW = aWires(k);
+ if (aW.IsNull())
+ continue;
+ NbWires++;
+ // Try to reorder edges
+ Handle(ShapeFix_Wire) aSFW = new ShapeFix_Wire( aW, theFace, Precision::Confusion() );
+ aSFW->FixReorder();
+ Handle(ShapeExtend_WireData) aSEWD = aSFW->WireData();
+ Standard_Integer nbE = aSEWD->NbEdges();
+ //
+ anPartStart.push_back(x.size());
+ NCollection_Sequence<gp_Pnt2d> aPnts;
+ for (Standard_Integer i = 1; i <= nbE; i++)
{
- TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
- if (aW.IsNull())
+ TopoDS_Edge E = aSEWD->Edge(i);
+ TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
+ if (aV.IsNull())
continue;
- NbWires++;
- anPartStart.push_back(x.size());
- TopExp_Explorer aVEx(aW, TopAbs_VERTEX);
- NCollection_Sequence<gp_Pnt2d> 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<gp_Pnt2d> 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));
- }
+ gp_Pnt P = BRep_Tool::Pnt(aV);
+ aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+ }
+ NCollection_Sequence<gp_Pnt2d> 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));
+ }
+ if (k == 1)
+ {
+ //an outer wire
+ //clockwise direction
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());
+ x.push_back( aNPnts(1).X());
+ y.push_back( aNPnts(1).Y());
+ }
+ else
+ {
+ //holes
+ //counter-clockwise direction
+ for (int j = aNPnts.Size(); j > 0; j--)
+ {
+ x.push_back( aNPnts(j).X());
+ y.push_back( aNPnts(j).Y());
+ }
+ x.push_back( aNPnts(aNPnts.Size()).X());
+ y.push_back( aNPnts(aNPnts.Size()).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;
+
+ aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
+ SHPWriteObject( theShpHandle, -1, aSHPObj );
+ SHPDestroyObject( aSHPObj );
+
}
bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile)
HYDROGUI_ImportSinusXOp.h
HYDROGUI_ExportSinusXOp.h
HYDROGUI_ExportSinusXDlg.h
+ HYDROGUI_ExportLandCoverMapDlg.h
HYDROGUI_InputPanel.h
HYDROGUI_LandCoverMapDlg.h
HYDROGUI_LandCoverMapOp.h
HYDROGUI_ImportBathymetryOp.cxx
HYDROGUI_ImportImageDlg.cxx
HYDROGUI_ImportImageOp.cxx
- HYDROGUI_ImportLandCoverMapOp.cxx
- HYDROGUI_ImportLandCoverMapDlg.cxx
+ HYDROGUI_ImportLandCoverMapOp.cxx
+ HYDROGUI_ImportLandCoverMapDlg.cxx
HYDROGUI_ImportPolylineOp.cxx
HYDROGUI_ImportSinusXOp.cxx
HYDROGUI_ExportSinusXOp.cxx
HYDROGUI_ExportSinusXDlg.cxx
+ HYDROGUI_ExportLandCoverMapDlg.cxx
HYDROGUI_InputPanel.cxx
HYDROGUI_LandCoverMapDlg.cxx
HYDROGUI_LandCoverMapOp.cxx
#include "HYDROGUI_Module.h"
#include "HYDROGUI_UpdateFlags.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_ExportLandCoverMapDlg.h"
#include <HYDROData_PolylineXY.h>
#include <HYDROData_Polyline3D.h>
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Bathymetry.h>
#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_StricklerTable.h>
+
#include <HYDROData_Profile.h>
#include <SUIT_Desktop.h>
#include <Handle_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 )
else
{
//Export polygons
- //aSeq.Size() <= 1
- Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
- anExporter.Export(aFileName, aLCM, aNonExpList);
+ //Extract all attribute names from all strickler tables
+ Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+ QSet<QString> AttrNames;
+ //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 It( aDoc, KIND_STRICKLER_TABLE );
+ for( ; It.More(); It.Next() )
+ {
+ Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+ if ( !aStricklerTableObj.IsNull())
+ AttrNames << aStricklerTableObj->GetAttrName();
+ }
+ }
+ else
+ return;
+
+ //
+ HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), AttrNames.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 CItem = aDlg.getCurrentItem();
+ Handle(HYDROData_StricklerTable) StricklerTableObj;
+ {
+ HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
+ for( ; It.More(); It.Next() )
+ {
+ StricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+ if ( !StricklerTableObj.IsNull() && StricklerTableObj->GetAttrName() == CItem)
+ break;
+ }
+ }
+
+ //export shape-data
+ anExporter.Export(aFileName, aLCM, aNonExpList);
+ QString DBFFileName = 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 (DBFFileName.toStdString().c_str());
+ bool ToSaveAttrInfo = aDlg.getAttrCheckBoxState();
+ if (ToSaveAttrInfo)
+ {
+ //export attribute info
+ QStringList AttrValues;
+ QStringList StricklerTypes;
+ if (aNonExpList.empty())
+ {
+ HYDROData_LandCoverMap::Iterator It( aLCM );
+ for( ; It.More(); It.Next() )
+ {
+ QString ST = It.StricklerType();
+ AttrValues << StricklerTableObj->GetAttrValue(ST);
+ StricklerTypes << ST;
+ }
+ }
+ aLCM->ExportDBF(DBFFileName, CItem, AttrValues, StricklerTypes);
+ }
+ }
+ else
+ {
+ abort();
+ return;
+ }
+
}
if (!aNonExpList.empty())
--- /dev/null
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ExportLandCoverMapDlg.h"
+
+#include <SUIT_MessageBox.h>
+
+#include <QCheckBox>
+#include <QVBoxLayout>
+#include <QComboBox>
+
+HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& AttrItems )
+ : QtxDialog( theParent, false, true, QtxDialog::OKCancel )
+{
+ setWindowTitle( tr( "EXPORT_LANDCOVERMAP" ) );
+ setButtonPosition( Left, OK );
+ setButtonPosition( Right, Cancel );
+
+ myAttrCheckBox = new QCheckBox( tr( "Write Strickler Types as attributes values to DBF file" ), mainFrame() );
+ myAttrCheckBox->setChecked(false);
+ myAvFields = new QComboBox( mainFrame() );
+ myAvFields->setEnabled(false);
+ myAvFields->addItems( AttrItems );
+
+ QGridLayout* aLayout = new QGridLayout( mainFrame() );
+ aLayout->setMargin( 5 );
+ aLayout->setSpacing( 5 );
+ aLayout->addWidget( myAttrCheckBox, 0, 0 );
+ aLayout->addWidget( myAvFields, 1, 0, 1, 2 );
+
+ setMinimumSize( 300, 100 );
+
+ connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool)));
+
+}
+
+HYDROGUI_ExportLandCoverMapDlg::~HYDROGUI_ExportLandCoverMapDlg()
+{
+}
+
+void HYDROGUI_ExportLandCoverMapDlg::onAttrCBChecked( bool theState )
+{
+ if (theState)
+ myAvFields->setEnabled(true);
+ else
+ myAvFields->setEnabled(false);
+}
+
+QString HYDROGUI_ExportLandCoverMapDlg::getCurrentItem() const
+{
+ return myAvFields->currentText();
+}
+
+bool HYDROGUI_ExportLandCoverMapDlg::getAttrCheckBoxState()
+{
+ return myAttrCheckBox->isChecked();
+}
--- /dev/null
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+
+#ifndef HYDROGUI_ExportLandCoverMapDlg_H
+#define HYDROGUI_ExportLandCoverMapDlg_H
+
+#include <QtxDialog.h>
+
+class QCheckBox;
+class QComboBox;
+
+class HYDROGUI_ExportLandCoverMapDlg : public QtxDialog
+{
+ Q_OBJECT
+
+public:
+ HYDROGUI_ExportLandCoverMapDlg( QWidget* = 0, const QStringList& AttrItems = QStringList());
+ virtual ~HYDROGUI_ExportLandCoverMapDlg();
+
+protected slots:
+ void onAttrCBChecked(bool theState);
+
+public:
+ QString getCurrentItem() const;
+ bool getAttrCheckBoxState();
+
+private:
+ QCheckBox* myAttrCheckBox;
+ QComboBox* myAvFields;
+};
+
+#endif
void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn,
const QStringList& theSecondColumn,
+ const QVector<int> theDefCBIndices,
const QVector<QColor> theColors)
{
- int FCSize = theFirstColumn.size();
- int SCSize = theSecondColumn.size();
+ int FCSize = theFirstColumn.size(); // == theDefCBIndices.size() !
+ int SCSize = theSecondColumn.size();
myStrColors = theColors;
myTableW->setHorizontalHeaderItem(0, Header_1);
myTableW->setHorizontalHeaderItem(1, Header_2);
myTableW->setHorizontalHeaderItem(2, Header_3);
+ myTableW->horizontalHeader()->setResizeMode(QHeaderView::ResizeMode::ResizeToContents);
//
for (int i = 0; i < FCSize; i++)
{
connect(aCB, SIGNAL(currentIndexChanged(int)), signalMap, SLOT(map()));
signalMap->setMapping(aCB, i);
aCB->addItems(theSecondColumn);
+ aCB->setCurrentIndex(theDefCBIndices[i]);
myTableW->setCellWidget(i, 1, aCB);
}
connect(signalMap, SIGNAL(mapped(int)), this, SLOT(OnComboBoxColorChanged(int)));
+
//
for (int i = 0; i < FCSize; i++)
{
myTableW->setItem(i, 2, new QTableWidgetItem);
//take the first color from array; this color corresponds to the first item in the combo box
- myTableW->item(i, 2)->setBackground(myStrColors[0]);
+ myTableW->item(i, 2)->setBackground(myStrColors[theDefCBIndices[i]]);
}
}
case 1:
{
if (myDBFAttr->selectedItems().empty())
+ {
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Attribute isn't selected");
return false;
+ }
break;
}
default:
void setAttributeNames( const QStringList& theAttrNames );
void FillCorrTable(const QStringList& theFirstColumn,
const QStringList& theSecondColumn,
+ const QVector<int> theDefCBIndices,
const QVector<QColor> theColors);
QStringList getSelectedPolygonNames() const;
#include "HYDROGUI_Tool.h"
#include "HYDROGUI_ImportLandCoverMapDlg.h"
#include "HYDROGUI_Shape.h"
-#include <HYDROData_LandCoverMap.h>
#include <HYDROGUI_ZLayers.h>
-
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Iterator.h>
#include <HYDROData_ShapeFile.h>
#include <HYDROData_Profile.h>
+#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_StricklerTable.h>
#include <SUIT_Desktop.h>
#include <SUIT_FileDlg.h>
-#include <LightApp_Application.h>
-
-#include <QApplication>
-#include <QFile>
-#include <QFileInfo>
#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewManager.h>
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewModel.h>
#include <SalomeApp_Study.h>
-
#include <LightApp_Application.h>
#include <LightApp_DataOwner.h>
#include <LightApp_Displayer.h>
#include <LightApp_SelectionMgr.h>
-#include <HYDROData_StricklerTable.h>
-
-#include <SUIT_Desktop.h>
-#include <SUIT_ViewManager.h>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
+
#include <QSet>
+#include <QFile>
+#include <QFileInfo>
-#include <HYDROData_LandCoverMap.h>
+#include <QApplication>
+
+#define MAX_LCM_NAME_INDEX 1000
//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 )
{
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;
aST = aSTL.at(StricklerTypesInd);
}
// else => ST is empty
- aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW
+ aMapFace2ST.Add( TopoDS::Face( aShape ), aST );
}
//
QString ObjName;
if ( !aPanel->getFileName().isEmpty() )
ObjName = aPanel->getObjectName();
+
+ Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+
+ //check if name of LCM is already exists
+ QSet<QString> aNameList;
+ if (aDoc)
+ {
+ HYDROData_Iterator It( aDoc, KIND_LAND_COVER_MAP );
+ for( ; It.More(); It.Next() )
+ aNameList << It.Current()->GetName();
+ }
+
+ QString NewName = ObjName;
+ for ( int i = 1; i < MAX_LCM_NAME_INDEX && aNameList.contains(NewName); i++)
+ NewName = ObjName + "_" + QString::number(i);
if( !myLCM.IsNull() )
{
- myLCM->SetName( ObjName );
+ myLCM->SetName( NewName );
myLCM->SetColor( Qt::gray );
myLCM->Show();
module()->setIsToUpdate( myLCM );
void HYDROGUI_ImportLandCoverMapOp::abortOperation()
{
LightApp_Application* anApp = module()->getApp();
- if ( anApp ) {
+ if ( anApp )
anApp->disconnect( this );
- }
erasePreview();
myImporter.Free();
//Collect all strickler_types
QSet<QString> aSTSet;
Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+ Handle(HYDROData_StricklerTable) DefStricklerTableObj;
if ( aDoc )
{
HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
for( ; It.More(); It.Next() )
{
Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
- QString TT = aStricklerTableObj->GetAttrName();
+ if (DefStricklerTableObj.IsNull())
+ DefStricklerTableObj = aStricklerTableObj;
if ( !aStricklerTableObj.IsNull())
{
const QStringList& aStricklerList = aStricklerTableObj->GetTypes();
foreach (QString aStr, aStricklerList)
- {
- QString AttVal = aStricklerTableObj->GetAttrValue(aStr);
aSTSet << aStr;
- }
}
}
}
STColors.append (col);
}
- aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, STColors);
+ //add an empty Strickler type
+ aSTSetList.prepend("");
+ STColors.prepend(QColor(Qt::gray));
+
+ QVector<int> aCurCBIndices(SetOfAttrValuesList.size());
+ if (DefStricklerTableObj->GetAttrName() == aPanel->getSelectedFieldName())
+ {
+ for (int i = 0; i < SetOfAttrValuesList.size(); i++)
+ {
+ QString ST = DefStricklerTableObj->GetType(SetOfAttrValuesList[i]);
+ int IndofSt = aSTSetList.indexOf(ST);
+ aCurCBIndices[i] = IndofSt;
+ }
+ }
+ else
+ {
+ //TODO add warning ???
+ for (int i = 0; i < SetOfAttrValuesList.size(); i++)
+ aCurCBIndices[i] = 0;
+ }
+
+ aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, aCurCBIndices, STColors);
}
}