#include "HYDROGUI_ImportLandCoverDlg.h"
-#include <SUIT_MessageBox.h>
-
-#include <QTextEdit>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
#include <QListWidget>
#include <QVBoxLayout>
-#include <QLabel>
-#include <QPushButton>
+#include <QToolButton>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SUIT_FileDlg.h>
+
-HYDROGUI_ImportLandCoverDlg::HYDROGUI_ImportLandCoverDlg( std::vector<SHPObject*> theSHPObjects, std::map<QListWidgetItem*, SHPObject*>& 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<QPushButton*>( 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<QListWidgetItem*> 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<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
+ if ( anItems.count() == 1 ) {
+ anItems.first()->setSelected( true );
+ }
}
- if ( QPushButton* aNoBtn = ::qobject_cast<QPushButton*>( button( No ) ) )
+}
+
+void HYDROGUI_ImportLandCoverDlg::onItemSelectionChanged()
+{
+ emit selectionChanged( getSelectedtPolylineNames() );
+}
+
+QStringList HYDROGUI_ImportLandCoverDlg::getSelectedtPolylineNames() const
+{
+ QStringList aSelectedNames;
+
+ QList<QListWidgetItem*> 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<QListWidgetItem*> 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
#ifndef HYDROGUI_ImportLandCoverDlg_H
#define HYDROGUI_ImportLandCoverDlg_H
-#include <QtxDialog.h>
+#include "HYDROGUI_InputPanel.h"
-class QLabel;
-class QTextEdit;
class QListWidget;
-class QListWidgetItem;
+class QLineEdit;
+class QGroupBox;
-#include <shapelib/shapefil.h>
-
-class HYDROGUI_ImportLandCoverDlg : public QtxDialog
+class HYDROGUI_ImportLandCoverDlg : public HYDROGUI_InputPanel
{
Q_OBJECT
public:
- HYDROGUI_ImportLandCoverDlg( std::vector<SHPObject*> theSHPObjects,
- std::map<QListWidgetItem*, SHPObject*>& theWItemToSObjectMap, QWidget* = 0 );
+ HYDROGUI_ImportLandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle );
virtual ~HYDROGUI_ImportLandCoverDlg();
+ void setImageName( const QString& theName );
-public:
- QList<QListWidgetItem*> 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
#include <gp_Pnt2d.hxx>
#include <BRepTools.hxx>
#include <gp_Pln.hxx>
+#include <QLineEdit>
HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule )
{
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") );
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<QListWidgetItem*, SHPObject*> 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();
module()->setObjectVisible( anActiveViewId, aPolylineXY, true );
module()->setIsToUpdate( aPolylineXY );*/
-}
\ No newline at end of file
+}
+
+void HYDROGUI_ImportLandCoverOp::onFileSelected()
+{
+ HYDROGUI_ImportLandCoverDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverDlg*>( 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);
+ }
+
+}
+
+
+