From: isn Date: Tue, 23 Jun 2015 07:36:25 +0000 (+0300) Subject: SHP poly 2 X-Git-Tag: v1.4.2~34^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b065fea005c70b9c7393b90c0b1bb4f0efb0f63;p=modules%2Fhydro.git SHP poly 2 --- diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx index 447cddf6..b997bd4f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx @@ -18,62 +18,170 @@ #include "HYDROGUI_ImportLandCoverDlg.h" -#include - -#include +#include +#include +#include #include #include -#include -#include +#include +#include +#include +#include + -HYDROGUI_ImportLandCoverDlg::HYDROGUI_ImportLandCoverDlg( std::vector theSHPObjects, std::map& theWItemToSObjectMap, QWidget* theParent ) -: QtxDialog( theParent, false, true, QtxDialog::YesNo ) +HYDROGUI_ImportLandCoverDlg::HYDROGUI_ImportLandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ) { - setWindowTitle( tr( "IMPORT_LANDCOVER_OBJECTS" ) ); - setButtonPosition( Left, Yes ); - setButtonPosition( Right, No ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QLabel* anIconLabelLabel = new QLabel( mainFrame() ); - anIconLabelLabel->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) ); - anIconLabelLabel->setScaledContents( false ); - anIconLabelLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + // Import bathymetry from file + myFileNameGroup = new QGroupBox( tr( "IMPORT_POLYGON_FROM_FILE" ) ); - myObjectsLabel = new QLabel( tr( "CONFIRM_SELECTION" ), mainFrame() ); + QLabel* aFileNameLabel = new QLabel( tr( "LANCOVER_NAME" ), myFileNameGroup ); - myListW = new QListWidget(mainFrame()); - for (int i = 1 ; i <= theSHPObjects.size(); i++) - { - myListW->addItem("Polygon_" + QString::number(i)); - } - myListW->setSelectionMode(QAbstractItemView::ExtendedSelection); + myFileName = new QLineEdit( myFileNameGroup ); + myFileName->setReadOnly( true ); + + QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup ); + aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); + + QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup ); + aFileNameLayout->setMargin( 5 ); + aFileNameLayout->setSpacing( 5 ); + aFileNameLayout->addWidget( aFileNameLabel ); + aFileNameLayout->addWidget( myFileName ); + aFileNameLayout->addWidget( aBrowseBtn ); + + // Bathymetry name + myObjectNameGroup = new QGroupBox( tr( "FILE_NAME" ) ); + + QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup ); + myObjectName = new QLineEdit( myObjectNameGroup ); + + QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup ); + aBathymetryNameLayout->setMargin( 5 ); + aBathymetryNameLayout->setSpacing( 5 ); + aBathymetryNameLayout->addWidget( aBathymetryNameLabel ); + aBathymetryNameLayout->addWidget( myObjectName ); + + // List of recognized polylines + QGroupBox* aPolylinesGroup = new QGroupBox( tr( "FOUND_POLYGONS_OF_SHP_FILE" ), mainFrame() ); + myPolylines = new QListWidget( aPolylinesGroup ); + myPolylines->setSelectionMode( QListWidget::ExtendedSelection ); + myPolylines->setEditTriggers( QListWidget::NoEditTriggers ); + myPolylines->setViewMode( QListWidget::ListMode ); + myPolylines->setSortingEnabled( false ); + + QBoxLayout* aPolylinesLayout = new QVBoxLayout; + aPolylinesLayout->addWidget( myPolylines ); + aPolylinesGroup->setLayout( aPolylinesLayout ); - QGridLayout* aLayout = new QGridLayout( mainFrame() ); - aLayout->setMargin( 5 ); - aLayout->setSpacing( 5 ); - aLayout->addWidget( anIconLabelLabel, 0, 0 ); - aLayout->addWidget( myObjectsLabel, 0, 1 ); + // Layout + addWidget( myFileNameGroup ); + addWidget( myObjectNameGroup ); + addWidget( aPolylinesGroup ); + + // Conections + connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); + connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); +} - aLayout->addWidget( myListW, 1, 0, 1, 2 ); +HYDROGUI_ImportLandCoverDlg::~HYDROGUI_ImportLandCoverDlg() +{ +} - if ( QPushButton* aYesBtn = ::qobject_cast( button( Yes ) ) ) - { - setFocusProxy( aYesBtn ); - aYesBtn->setAutoDefault( true ); - aYesBtn->setDefault( true ); +void HYDROGUI_ImportLandCoverDlg::setImageName( const QString& theName ) +{ + myImageName->setText( theName ); +} + +void HYDROGUI_ImportLandCoverDlg::reset() +{ + myImageName->clear(); + myPolylines->clear(); +} + +void HYDROGUI_ImportLandCoverDlg::setPolylineNames( const QStringList& theNames ) +{ + myPolylines->clear(); + myPolylines->addItems( theNames ); +} + +void HYDROGUI_ImportLandCoverDlg::removePolylineNames( const QStringList& theNames ) +{ + QList aFoundItems; + + foreach ( const QString& aName, theNames ) { + aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly ); + foreach ( QListWidgetItem* anItem, aFoundItems ) { + anItem = myPolylines->takeItem( myPolylines->row( anItem ) ); + delete anItem; + } + } +} + +void HYDROGUI_ImportLandCoverDlg::setSelectedPolylineNames( const QStringList& theNames ) +{ + myPolylines->clearSelection(); + + foreach( const QString aName, theNames ) { + QList anItems = myPolylines->findItems( aName, Qt::MatchExactly ); + if ( anItems.count() == 1 ) { + anItems.first()->setSelected( true ); + } } - if ( QPushButton* aNoBtn = ::qobject_cast( button( No ) ) ) +} + +void HYDROGUI_ImportLandCoverDlg::onItemSelectionChanged() +{ + emit selectionChanged( getSelectedtPolylineNames() ); +} + +QStringList HYDROGUI_ImportLandCoverDlg::getSelectedtPolylineNames() const +{ + QStringList aSelectedNames; + + QList aSelectedItems = myPolylines->selectedItems(); + foreach( const QListWidgetItem* anItem, aSelectedItems ) { + aSelectedNames << anItem->text(); + } + + return aSelectedNames; +} + + +void HYDROGUI_ImportLandCoverDlg::onBrowse() +{ + QString aFilter( tr( "LANDCOVER_FILTER" ) ); + QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVER_FROM_FILE" ), true ); + + if( !aFileName.isEmpty() ) { - aNoBtn->setAutoDefault( true ); + setFileName( aFileName ); + emit FileSelected( aFileName ); } +} - setMinimumSize( 350, 450 ); +void HYDROGUI_ImportLandCoverDlg::setObjectName( const QString& theName ) +{ + myObjectName->setText( theName ); + myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() ); } -HYDROGUI_ImportLandCoverDlg::~HYDROGUI_ImportLandCoverDlg() +QString HYDROGUI_ImportLandCoverDlg::getObjectName() const { + return myObjectName->text(); } -QList HYDROGUI_ImportLandCoverDlg::GetSelectedItems() +void HYDROGUI_ImportLandCoverDlg::setFileName( const QString& theFileName ) { - return myListW->selectedItems(); + myFileName->setText( theFileName ); + + if ( !myObjectNameGroup->isEnabled() ) + myObjectNameGroup->setEnabled( !theFileName.isEmpty() ); } + +QString HYDROGUI_ImportLandCoverDlg::getFileName() const +{ + return myFileName->text(); +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h index db99f74f..c9df0432 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h @@ -20,34 +20,62 @@ #ifndef HYDROGUI_ImportLandCoverDlg_H #define HYDROGUI_ImportLandCoverDlg_H -#include +#include "HYDROGUI_InputPanel.h" -class QLabel; -class QTextEdit; class QListWidget; -class QListWidgetItem; +class QLineEdit; +class QGroupBox; -#include - -class HYDROGUI_ImportLandCoverDlg : public QtxDialog +class HYDROGUI_ImportLandCoverDlg : public HYDROGUI_InputPanel { Q_OBJECT public: - HYDROGUI_ImportLandCoverDlg( std::vector theSHPObjects, - std::map& theWItemToSObjectMap, QWidget* = 0 ); + HYDROGUI_ImportLandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_ImportLandCoverDlg(); + void setImageName( const QString& theName ); -public: - QList GetSelectedItems(); + void reset(); -private: - QLabel* myObjectsLabel; - QListWidget* myListW; + void setPolylineNames( const QStringList& theNames ); + void removePolylineNames( const QStringList& theNames ); + + void setSelectedPolylineNames( const QStringList& theNames ); + + QStringList getSelectedtPolylineNames() const; + + void setObjectName( const QString& theName ); + QString getObjectName() const; + + void setFileName( const QString& theFileName ); + QString getFileName() const; + +signals: + void FileSelected( const QString& theFileName ); + +protected slots: + void onBrowse(); + +signals: + void selectionChanged( const QStringList& ); + +public slots: + void onItemSelectionChanged(); public: + + QLineEdit* myFileName; //temp +private: + QLineEdit* myImageName; + QGroupBox* myFileNameGroup; +// QLineEdit* myFileName; + + QListWidget* myPolylines; + + QGroupBox* myObjectNameGroup; + QLineEdit* myObjectName; + - int GetSeleItemsSize(); }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx index 8dc04c47..56ca8395 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx @@ -53,6 +53,7 @@ #include #include #include +#include HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule ) @@ -69,7 +70,7 @@ void HYDROGUI_ImportLandCoverOp::startOperation() { HYDROGUI_Operation::startOperation(); - myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); + /*myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); myFileDlg->setWindowTitle( getName() ); myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles ); myFileDlg->setFilter( tr("LANDCOVER_FILTER") ); @@ -77,67 +78,23 @@ void HYDROGUI_ImportLandCoverOp::startOperation() connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) ); connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); - myFileDlg->exec(); + 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(); +HYDROGUI_InputPanel* HYDROGUI_ImportLandCoverOp::createInputPanel() const +{ + HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportLandCoverDlg( module(), getName() ); - 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(); + connect( aPanel, SIGNAL( FileSelected( const QString& ) ), SLOT( onFileSelected() ) ); - 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]); + connect( aPanel, SIGNAL( selectionChanged( const QStringList& ) ), this, SLOT( onSelectionChanged( const QStringList& ) ) ); - mySHPObjects.clear(); - SHPClose(aHSHP); - } + return aPanel; +} +void HYDROGUI_ImportLandCoverOp::onApply() +{ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init ); QApplication::restoreOverrideCursor(); @@ -203,4 +160,72 @@ void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); module()->setIsToUpdate( aPolylineXY );*/ -} \ No newline at end of file +} + +void HYDROGUI_ImportLandCoverOp::onFileSelected() +{ + HYDROGUI_ImportLandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QString anObjectName = aPanel->getObjectName().simplified(); + anObjectName = aPanel->getFileName(); + if ( !anObjectName.isEmpty() ) { + anObjectName = QFileInfo( anObjectName ).baseName(); + } + + if ( anObjectName.isEmpty() ) { + anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_BATHYMETRY_NAME" ) ); + } + aPanel->setObjectName( anObjectName ); + + QString aFileName = aPanel->myFileName->text(); + 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); + + startDocOperation(); + QStringList aPolygonsList; + for (int i = 0; i < mySHPObjects.size(); i++) + aPolygonsList.append("polygon_" + QString::number(i)); + aPanel->setPolylineNames(aPolygonsList); + + TopoDS_Compound cmp; + BRep_Builder BB; + BB.MakeCompound(cmp); + TopoDS_Face F; + if (aHSHP->nShapeType == 5) + { + for (int i = 0; i < 10/*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(); + + for (size_t i = 0; i < mySHPObjects.size(); i++ ) + free (mySHPObjects[i]); + + mySHPObjects.clear(); + SHPClose(aHSHP); + } + +} + + + diff --git a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h index b81e621e..f8b95c5e 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h @@ -33,6 +33,7 @@ class SUIT_FileDlg; class TopoDS_Face; + class HYDROGUI_ImportLandCoverOp : public HYDROGUI_Operation { Q_OBJECT @@ -44,11 +45,15 @@ public: protected: virtual void startOperation(); virtual void onApply(); + HYDROGUI_InputPanel* createInputPanel() const; void Parse(SHPHandle theHandle); void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F); + +protected slots: + void onFileSelected(); private: - SUIT_FileDlg* myFileDlg; + //SUIT_FileDlg* myFileDlg; std::vector mySHPObjects; }; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 8a74c2ec..0490b1e6 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2187,7 +2187,7 @@ file cannot be correctly imported for an Obstacle definition. - HYDROGUI_ImportLandcoverOp + HYDROGUI_ImportLandCoverDlg IMPORT_LANDCOVER Import Land cover @@ -2251,7 +2251,7 @@ file cannot be correctly imported for an Obstacle definition. - + HYDROGUI_GeoreferencementDlg