From: isn Date: Mon, 22 Jun 2015 12:32:59 +0000 (+0300) Subject: SHP Poly 1 X-Git-Tag: v1.4.2~34^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a6d084b170797d6b566e9e99af54a8f0d1d5785f;p=modules%2Fhydro.git SHP Poly 1 --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 4be75c78..f67ce656 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -37,6 +37,8 @@ set(PROJECT_HEADERS HYDROGUI_ImportImageDlg.h HYDROGUI_ImportImageOp.h HYDROGUI_ImportPolylineOp.h + HYDROGUI_ImportLandCoverOp.h + HYDROGUI_ImportLandCoverDlg.h HYDROGUI_ImportSinusXOp.h HYDROGUI_ExportSinusXOp.h HYDROGUI_ExportSinusXDlg.h @@ -170,6 +172,8 @@ set(PROJECT_SOURCES HYDROGUI_ImportImageOp.cxx HYDROGUI_ImportPolylineOp.cxx HYDROGUI_ImportSinusXOp.cxx + HYDROGUI_ImportLandCoverOp.cxx + HYDROGUI_ImportLandCoverDlg.cxx HYDROGUI_ExportSinusXOp.cxx HYDROGUI_ExportSinusXDlg.cxx HYDROGUI_InputPanel.cxx diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx new file mode 100644 index 00000000..447cddf6 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx @@ -0,0 +1,79 @@ +// 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_ImportLandCoverDlg.h" + +#include + +#include +#include +#include +#include +#include + +HYDROGUI_ImportLandCoverDlg::HYDROGUI_ImportLandCoverDlg( std::vector theSHPObjects, std::map& theWItemToSObjectMap, QWidget* theParent ) +: QtxDialog( theParent, false, true, QtxDialog::YesNo ) +{ + setWindowTitle( tr( "IMPORT_LANDCOVER_OBJECTS" ) ); + setButtonPosition( Left, Yes ); + setButtonPosition( Right, No ); + + QLabel* anIconLabelLabel = new QLabel( mainFrame() ); + anIconLabelLabel->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) ); + anIconLabelLabel->setScaledContents( false ); + anIconLabelLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + + myObjectsLabel = new QLabel( tr( "CONFIRM_SELECTION" ), mainFrame() ); + + myListW = new QListWidget(mainFrame()); + for (int i = 1 ; i <= theSHPObjects.size(); i++) + { + myListW->addItem("Polygon_" + QString::number(i)); + } + myListW->setSelectionMode(QAbstractItemView::ExtendedSelection); + + QGridLayout* aLayout = new QGridLayout( mainFrame() ); + aLayout->setMargin( 5 ); + aLayout->setSpacing( 5 ); + aLayout->addWidget( anIconLabelLabel, 0, 0 ); + aLayout->addWidget( myObjectsLabel, 0, 1 ); + + aLayout->addWidget( myListW, 1, 0, 1, 2 ); + + if ( QPushButton* aYesBtn = ::qobject_cast( button( Yes ) ) ) + { + setFocusProxy( aYesBtn ); + aYesBtn->setAutoDefault( true ); + aYesBtn->setDefault( true ); + } + if ( QPushButton* aNoBtn = ::qobject_cast( button( No ) ) ) + { + aNoBtn->setAutoDefault( true ); + } + + setMinimumSize( 350, 450 ); +} + +HYDROGUI_ImportLandCoverDlg::~HYDROGUI_ImportLandCoverDlg() +{ +} + +QList HYDROGUI_ImportLandCoverDlg::GetSelectedItems() +{ + return myListW->selectedItems(); +} diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h new file mode 100644 index 00000000..db99f74f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h @@ -0,0 +1,53 @@ +// 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_ImportLandCoverDlg_H +#define HYDROGUI_ImportLandCoverDlg_H + +#include + +class QLabel; +class QTextEdit; +class QListWidget; +class QListWidgetItem; + +#include + +class HYDROGUI_ImportLandCoverDlg : public QtxDialog +{ + Q_OBJECT + +public: + HYDROGUI_ImportLandCoverDlg( std::vector theSHPObjects, + std::map& theWItemToSObjectMap, QWidget* = 0 ); + virtual ~HYDROGUI_ImportLandCoverDlg(); + +public: + QList GetSelectedItems(); + +private: + QLabel* myObjectsLabel; + QListWidget* myListW; + +public: + + int GetSeleItemsSize(); +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx new file mode 100644 index 00000000..8dc04c47 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx @@ -0,0 +1,206 @@ +// 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 +// +// 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_ImportLandCoverOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_ImportLandCoverDlg.h" + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ) +{ + setName( tr( "IMPORT_LANDCOVER" ) ); +} + +HYDROGUI_ImportLandCoverOp::~HYDROGUI_ImportLandCoverOp() +{ +} + +void HYDROGUI_ImportLandCoverOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); + myFileDlg->setWindowTitle( getName() ); + myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles ); + myFileDlg->setFilter( tr("LANDCOVER_FILTER") ); + + connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) ); + connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); + + myFileDlg->exec(); +} + +void HYDROGUI_ImportLandCoverOp::onApply() +{ + if ( !myFileDlg ) + { + abort(); + return; + } + + QString aFileName = myFileDlg->selectedFile(); + if ( aFileName.isEmpty() ) + { + abort(); + return; + } + + QString anExt = aFileName.split('.', QString::SplitBehavior::SkipEmptyParts).back(); + + if (anExt == "shp") + { + SHPHandle aHSHP; + aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" ); + Parse(aHSHP); + std::map aWItemToSObjectMap; + HYDROGUI_ImportLandCoverDlg anImportLandCoverDlg( mySHPObjects, aWItemToSObjectMap, module()->getApp()->desktop() ); + if ( anImportLandCoverDlg.exec() == HYDROGUI_ImportLandCoverDlg::Accepted ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + + startDocOperation(); + + int T = anImportLandCoverDlg.GetSelectedItems().size(); + + TopoDS_Compound cmp; + BRep_Builder BB; + BB.MakeCompound(cmp); + TopoDS_Face F; + if (aHSHP->nShapeType == 5) + { + for (int i = 0; i < this->mySHPObjects.size(); i++) { + ProcessSHP(mySHPObjects[i], i, F); + BB.Add(cmp, F); + } + ///to hydro_landcover + // BRepTools::Write(cmp, "d:/h1.brep"); + } + else + SUIT_MessageBox::warning( module()->getApp()->desktop(), "Import Land cover", "Cannot land cover;\nThe shape type is not polygon" ); + commitDocOperation(); + commit(); + } + + for (size_t i = 0; i < mySHPObjects.size(); i++ ) + free (mySHPObjects[i]); + + mySHPObjects.clear(); + SHPClose(aHSHP); + } + + module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init ); + + QApplication::restoreOverrideCursor(); +} + + + +void HYDROGUI_ImportLandCoverOp::Parse(SHPHandle theHandle) +{ + int aShapeType; + mySHPObjects.clear(); + SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); + if (aShapeType == 5) + { + for (int i = 0; i < theHandle->nRecords; i++) + mySHPObjects.push_back(SHPReadObject(theHandle, i)); + } +} + +void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F) +{ + TopoDS_Wire W; + TopoDS_Edge E; + int nParts = anObj->nParts; + gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + BRepBuilderAPI_MakeFace aFBuilder(pln); + for ( int i = 0 ; i < nParts ; i++ ) + { + BRepBuilderAPI_MakeWire aBuilder; + int StartIndex = anObj->panPartStart[i]; + int EndIndex; + if (i != nParts - 1) + EndIndex = anObj->panPartStart[i + 1]; + else + EndIndex = anObj->nVertices; + + for ( int k = StartIndex; k < EndIndex - 1 ; k++ ) + { + gp_Pnt2d P1 (anObj->padfX[k], anObj->padfY[k]); + gp_Pnt2d P2 (anObj->padfX[k+1], anObj->padfY[k+1]); + BRepBuilderAPI_MakeEdge2d aMakeEdge(P1, P2); + aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape())); + } + aBuilder.Build(); + W = TopoDS::Wire(aBuilder.Shape()); + aFBuilder.Add(W); + } + + aFBuilder.Build(); + F = aFBuilder.Face(); + + //TODO build curve 3d + + /*aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); + aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) ); + + aPolylineXY->Update(); + + size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); + if ( anActiveViewId == 0 ) + anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); + + module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); + + module()->setIsToUpdate( aPolylineXY );*/ +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h new file mode 100644 index 00000000..b81e621e --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h @@ -0,0 +1,55 @@ +// 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 +// +// 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_IMPORTLANDCOVER_H +#define HYDROGUI_IMPORTLANDCOVER_H + +#include "HYDROGUI_Operation.h" +#include + +//extern "C" { +#include +//}; + +class SUIT_FileDlg; +class TopoDS_Face; + +class HYDROGUI_ImportLandCoverOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_ImportLandCoverOp(); + +protected: + virtual void startOperation(); + virtual void onApply(); + void Parse(SHPHandle theHandle); + void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F); + +private: + SUIT_FileDlg* myFileDlg; + std::vector mySHPObjects; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 57d8f818..62707523 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -66,6 +66,7 @@ #include "HYDROGUI_ExportSinusXOp.h" #include "HYDROGUI_MergePolylinesOp.h" #include "HYDROGUI_SplitPolylinesOp.h" +#include "HYDROGUI_ImportLandCoverOp.h" #include #include @@ -130,6 +131,7 @@ void HYDROGUI_Module::createActions() createAction( ImportPolylineId, "IMPORT_POLYLINE", "IMPORT_POLYLINE_ICO" ); createAction( ImportSinusXId, "IMPORT_SINUSX", "IMPORT_SINUSX_ICO" ); createAction( ExportSinusXId, "EXPORT_SINUSX", "EXPORT_SINUSX_ICO" ); + createAction( ImportLandcoverId, "IMPORT_LANDCOVER", "IMPORT_LANDCOVER_ICO" ); createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" ); createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" ); @@ -235,6 +237,7 @@ void HYDROGUI_Module::createMenus() createMenu( ImportPolylineId, aHydroId, -1, -1 ); createMenu( ImportSinusXId, aHydroId, -1, -1 ); createMenu( ExportSinusXId, aHydroId, -1, -1 ); + createMenu( ImportLandcoverId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( ImportStricklerTableFromFileId, aHydroId, -1, -1 ); @@ -287,6 +290,7 @@ void HYDROGUI_Module::createToolbars() createTool( ImportPolylineId, aToolBar ); createTool( ImportSinusXId, aToolBar ); createTool( ExportSinusXId, aToolBar ); + createTool( ImportLandcoverId, aToolBar ); createTool( ImportBathymetryId, aToolBar ); createTool( CreatePolylineId, aToolBar ); @@ -468,6 +472,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case ExportPolylineId: anOp = new HYDROGUI_ExportFileOp( aModule ); break; + case ImportLandcoverId: + anOp = new HYDROGUI_ImportLandCoverOp( aModule ); + break; case RemoveImageRefsId: anOp = new HYDROGUI_RemoveImageRefsOp( aModule ); break; diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index b03423b9..9b8c09eb 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -112,9 +112,9 @@ enum OperationId ImportPolylineId, ImportSinusXId, ExportSinusXId, - ExportPolylineId, + ImportLandcoverId, ImportStricklerTableFromFileId, ExportStricklerTableFromFileId, diff --git a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx index 5b948492..860d361e 100644 --- a/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx +++ b/src/HYDROGUI/HYDROGUI_RecognizeContoursOp.cxx @@ -467,9 +467,9 @@ void HYDROGUI_RecognizeContoursOp::onViewerSelectionChanged() return; } - Handle(AIS_InteractiveContext) aCtx = NULL; OCCViewer_ViewManager* aViewManager = getPreviewManager(); + Handle(AIS_InteractiveContext) aCtx = NULL; if ( aViewManager ) { if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { aCtx = aViewer->getAISContext(); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 6c1803c9..8a74c2ec 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -926,6 +926,10 @@ Would you like to remove all references from the image? DSK_IMPORT_POLYLINE Import polyline from file(s) + + DSK_IMPORT_LANDCOVER + Import land cover from file(s) + DSK_IMPORT_SINUSX Import from SinusX @@ -1230,6 +1234,10 @@ Would you like to remove all references from the image? MEN_IMPORT_POLYLINE Import polyline + + MEN_IMPORT_LANDCOVER + Import land cover from file(s) + MEN_IMPORT_SINUSX Import from SinusX @@ -1511,6 +1519,10 @@ Would you like to remove all references from the image? STB_IMPORT_POLYLINE Import polyline + + STB_IMPORT_LANDCOVER + Import land cover from file(s) + STB_IMPORT_SINUSX Import from SinusX @@ -2174,6 +2186,27 @@ file cannot be correctly imported for an Obstacle definition. + + HYDROGUI_ImportLandcoverOp + + IMPORT_LANDCOVER + Import Land cover + + + LANDCOVER_FILTER + Shape files (*.shp) + + + BAD_IMPORTED_LANDCOVER_FILES + Land cover import error + + + NO_ONE_LANDCOVER_IMPORTED + Land cover cannot be read from seleted file + + + + HYDROGUI_ImportSinusXOp