From: isn Date: Fri, 3 Aug 2018 13:03:00 +0000 (+0300) Subject: refs #1806 (lot 7) X-Git-Tag: HYDRO_V2_0_0~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a0136de3bb5cc4b13af3bf76ee90705da04a83e;p=modules%2Fhydro.git refs #1806 (lot 7) Signed-off-by: isn --- diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index a4289856..17cc1e0b 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -1583,3 +1584,38 @@ void HYDROData_PolylineXY::Interpolate() { ImportShape( GetShape(), true, NULL ); } + +void HYDROData_PolylineXY::SetDBFInfo( const QStringList& theDBFTable ) +{ + int i = 1; + Handle_TDataStd_ExtStringArray TExtStrArr = + TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_DBFTableInfo), 1, theDBFTable.size() ); + foreach (QString val, theDBFTable) + { + std::string StdVal = val.toStdString(); + const char* aCVal = StdVal.c_str(); + TExtStrArr->SetValue(i, TCollection_ExtendedString(aCVal)); + i++; + } +} + +bool HYDROData_PolylineXY::GetDBFInfo(QStringList& theDBFTable) const +{ + TDF_Label aLabel = myLab.FindChild( DataTag_DBFTableInfo, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_ExtStringArray) anExtStrArr; + if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) ) + { + for (int i = anExtStrArr->Lower(); i <= anExtStrArr->Upper(); i++ ) + { + Standard_ExtString str = anExtStrArr->Value(i).ToExtString(); + TCollection_AsciiString aText (str); + theDBFTable << QString(aText.ToCString()); + } + } + } + else + return false; + return true; +} diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 8375616b..14aeaff9 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -42,6 +42,7 @@ protected: { DataTag_First = HYDROData_IPolyline::DataTag_First + 100, ///< first tag, to reserve DataTag_GeomObjectEntry, ///< study entry of the imported GEOM object + DataTag_DBFTableInfo }; public: @@ -300,6 +301,10 @@ public: */ HYDRODATA_EXPORT void Transform( const QTransform& theTrsf ); + HYDRODATA_EXPORT void SetDBFInfo(const QStringList& theDBFTable); + + HYDRODATA_EXPORT bool GetDBFInfo(QStringList& theDBFTable) const; + protected: /** diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index a9605ebd..ae491956 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -152,6 +152,8 @@ set(PROJECT_HEADERS HYDROGUI_ZoneTool.h HYDROGUI_RegenerateRegionColorsOp.h HYDROGUI_ZoneSetColorOp.h + HYDROGUI_PolyAttrDlg.h + HYDROGUI_ShowAttrPolyOp.h ) QT_WRAP_MOC(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -306,6 +308,8 @@ set(PROJECT_SOURCES HYDROGUI_ZoneTool.cxx HYDROGUI_RegenerateRegionColorsOp.cxx HYDROGUI_ZoneSetColorOp.cxx + HYDROGUI_PolyAttrDlg.cxx + HYDROGUI_ShowAttrPolyOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx index e7faee11..257352f1 100644 --- a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx @@ -92,6 +92,80 @@ void HYDROGUI_ImportPolylineOp::onApply() NCollection_Sequence theEntities; int aShapeTypeOfFile = -1; int aStat = anImporter.ImportPolylines(doc(), aFileName, theEntities, aShapeTypeOfFile ); + if (aStat == 1 || aStat == 2) + { + //try to import DBF + QString aDBFFileName; + aDBFFileName = aFileName.simplified().replace( aFileName.simplified().size() - 4, 4, ".dbf"); + bool DBF_Stat = anImporter.DBF_OpenDBF(aDBFFileName); + if (DBF_Stat) + { + QStringList aFieldList = anImporter.DBF_GetFieldList(); + int nbRecords = anImporter.DBF_GetNbRecords(); + assert (theEntities.Length() == nbRecords); + if (theEntities.Length() == nbRecords) + { + int indNameAttrFound = -1; + int k = 0; + bool bUseNameAttrFound = false; + for (QStringList::iterator it = aFieldList.begin(); it != aFieldList.end(); it++, k++) + if (QString::compare(*it, "name", Qt::CaseInsensitive) == 0) + { + indNameAttrFound = k; + break; + } + + if (indNameAttrFound != -1) + bUseNameAttrFound = SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "IMPORT_POLYLINE" ), + tr( "IMPORT_POLYLINE_USE_NAME_ATTR" ), + QMessageBox::Yes | QMessageBox::No, + SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes; + + std::vector> anAttrVV; + for (int i = 0; i < aFieldList.size(); i++) + { + std::vector anAttrV; + anAttrVV.push_back(anAttrV); + anImporter.DBF_GetAttributeList(i, anAttrVV[i] ); + } + + int indNULL = 1; + for (int i = 1; i <= theEntities.Length(); i++) + { + Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theEntities(i) ); + QStringList aDBFinfo; + aDBFinfo << aFieldList; //first, the table header + for (int j = 0; j < aFieldList.size(); j++) + { + QString attr; + const HYDROData_ShapeFile::DBF_AttrValue& attrV = anAttrVV[j][i-1]; + if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_String) + aDBFinfo << attrV.myStrVal; + else if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_Integer) + aDBFinfo << QString::number(attrV.myIntVal); + else if (attrV.myFieldType == HYDROData_ShapeFile::DBF_FieldType_Double) + aDBFinfo << QString::number(attrV.myDoubleVal); + else + aDBFinfo << ""; + } + assert (aDBFinfo.size() / 2 == aFieldList.size()); + aPolylineXY->SetDBFInfo(aDBFinfo); + if (bUseNameAttrFound) + { + QString nameOfPoly = aDBFinfo[aDBFinfo.size() / 2 + indNameAttrFound]; + if (!nameOfPoly.isEmpty()) + aPolylineXY->SetName(nameOfPoly); + else + { + aPolylineXY->SetName("null_name_" + QString::number(indNULL)); + indNULL++; + } + } + } + } + } + } if (aStat == 1) UpdateView(theEntities); else if (aStat == 2) diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 03a78832..54d2a851 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -662,6 +662,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( SplitPolylinesId ) ); theMenu->addAction( action( MergePolylinesId ) ); theMenu->addSeparator(); + theMenu->addAction( action( ShowAttrPolylinesId ) ); + theMenu->addSeparator(); } else if( anIsPolyline3D ) { diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index a3631f1a..b5d318aa 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -75,6 +75,7 @@ #include "HYDROGUI_RegenerateRegionColorsOp.h" #include "HYDROGUI_PolylineStyleOp.h" #include "HYDROGUI_ZoneSetColorOp.h" +#include #include #include #include @@ -245,6 +246,8 @@ void HYDROGUI_Module::createActions() createAction( SplitPolylinesId, "SPLIT_POLYLINES", "SPLIT_POLYLINES_ICO" ); createAction( MergePolylinesId, "MERGE_POLYLINES", "MERGE_POLYLINES_ICO" ); + createAction( ShowAttrPolylinesId, "SHOWATTR_POLYLINES"); + createAction( LandCoverScalarMapModeOnId, "LC_SCALARMAP_COLORING_ON" ); createAction( LandCoverScalarMapModeOffId, "LC_SCALARMAP_COLORING_OFF" ); @@ -797,6 +800,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case MergePolylinesId: anOp = new HYDROGUI_MergePolylinesOp( aModule ); break; + case ShowAttrPolylinesId: + anOp = new HYDROGUI_ShowAttrPolyOp( aModule ); + break; case LandCoverScalarMapModeOnId: case LandCoverScalarMapModeOffId: anOp = new HYDROGUI_LandCoverColoringOp( aModule, theId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 519c68a7..42e9ab9d 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -135,6 +135,8 @@ enum OperationId SplitPolylinesId, MergePolylinesId, + ShowAttrPolylinesId, + LandCoverScalarMapModeOnId, LandCoverScalarMapModeOffId, diff --git a/src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx new file mode 100644 index 00000000..aaade7c0 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.cxx @@ -0,0 +1,62 @@ +// 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_PolyAttrDlg.h" +#include +#include + +HYDROGUI_PolyAttrDlg::HYDROGUI_PolyAttrDlg( QWidget* theParent, const QStringList& theDBFData ) + : QDialog( theParent ) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin(5); + aMainLayout->setSpacing(5); + int nbcol = theDBFData.size()/2; + myDBFDataTable = new QTableWidget(1, nbcol); + //myDBFDataTable->setEditTriggers(QAbstractItemView:NoEditTriggers); + + QStringList header; + for (int i = 0; i < nbcol; i++) + header << theDBFData[i]; + myDBFDataTable->setHorizontalHeaderLabels(header); + myDBFDataTable->setShowGrid(true); + + for (int i = theDBFData.size()/2; i < theDBFData.size(); i++) + { + QTableWidgetItem* item = new QTableWidgetItem(theDBFData[i]); + item->setFlags(item->flags() ^ Qt::ItemIsEditable); + myDBFDataTable->setItem(0, i-theDBFData.size()/2, item); + } + + aMainLayout->addWidget(myDBFDataTable); + + QPushButton* anOkButton = new QPushButton( tr("OK"), this ); + anOkButton->setDefault( true ); + aMainLayout->addWidget( anOkButton ); + + connect( anOkButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); + + setLayout(aMainLayout); + +} + +HYDROGUI_PolyAttrDlg::~HYDROGUI_PolyAttrDlg() +{ +} + + diff --git a/src/HYDROGUI/HYDROGUI_PolyAttrDlg.h b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.h new file mode 100644 index 00000000..dad41e5b --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PolyAttrDlg.h @@ -0,0 +1,41 @@ +// 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_POLYATTRDLG_H +#define HYDROGUI_POLYATTRDLG_H + +#include +#include + +class HYDROGUI_PolyAttrDlg : public QDialog +{ + Q_OBJECT + +public: + + HYDROGUI_PolyAttrDlg( QWidget* theParent, const QStringList& theDBFData ); + virtual ~HYDROGUI_PolyAttrDlg(); + +private: + QTableWidget* myDBFDataTable; + +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx new file mode 100644 index 00000000..3429e916 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.cxx @@ -0,0 +1,66 @@ +// 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_ShowAttrPolyOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_Module.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +HYDROGUI_ShowAttrPolyOp::HYDROGUI_ShowAttrPolyOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ), + myPolyAttrDlg( 0 ) +{ + setName( tr( "SHOWATTR_POLYLINE" ) ); +} + +HYDROGUI_ShowAttrPolyOp::~HYDROGUI_ShowAttrPolyOp() +{ +} + +void HYDROGUI_ShowAttrPolyOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects(module()); + Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(aSeq(1)); + QStringList aDbflist; + if (aPolyXY->GetDBFInfo(aDbflist)) + { + myPolyAttrDlg = new HYDROGUI_PolyAttrDlg( module()->getApp()->desktop(), aDbflist ); + myPolyAttrDlg->setModal( true ); + myPolyAttrDlg->setWindowTitle(getName()); + myPolyAttrDlg->exec(); + } + else + SUIT_MessageBox::information( module()->getApp()->desktop(), getName(), tr("SHOWATTR_POLY_NO_ATTR")); + + HYDROGUI_Operation::abort(); +} + diff --git a/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h new file mode 100644 index 00000000..71d147d9 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ShowAttrPolyOp.h @@ -0,0 +1,44 @@ +// 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_SHOWATTRPOLYOP_H +#define HYDROGUI_SHOWATTRPOLYOP_H + +#include "HYDROGUI_Operation.h" + +#include + +class HYDROGUI_PolyAttrDlg; + +class HYDROGUI_ShowAttrPolyOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_ShowAttrPolyOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_ShowAttrPolyOp(); + +protected: + virtual void startOperation(); + +private: + + HYDROGUI_PolyAttrDlg* myPolyAttrDlg; +}; + +#endif \ No newline at end of file diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 0ca06e8a..0ba175c3 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1079,6 +1079,10 @@ Would you like to remove all references from the image? DSK_MERGE_POLYLINES Merge polylines + + DSK_SHOWATTR_POLYLINES + Show DBF attributes + DSK_UNDO Undo @@ -1468,6 +1472,10 @@ Would you like to remove all references from the image? MEN_MERGE_POLYLINES Merge polylines + + MEN_SHOWATTR_POLYLINES + Show DBF attributes + MEN_UNDO Undo @@ -1808,6 +1816,10 @@ Would you like to remove all references from the image? STB_MERGE_POLYLINES Merge polylines + + STB_SHOWATTR_POLYLINES + Show DBF attributes + STB_UNDO Undo @@ -2480,6 +2492,10 @@ file cannot be correctly imported for an Obstacle definition. IMPORT_POLYLINE Import Polyline + + IMPORT_POLYLINE_USE_NAME_ATTR + DBF file contains 'name' field. Would you like to use the value of this field as a name of polyline? + POLYLINE_FILTER Shape files (*.shp) @@ -3486,6 +3502,18 @@ Polyline should consist from one not closed curve. + + HYDROGUI_ShowAttrPolyOp + + SHOWATTR_POLYLINE + DBF attributes of polyline + + + SHOWATTR_POLY_NO_ATTR + This polyline does not contain DBF information + + + HYDROGUI_SplitPolylinesDlg