]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
SHP poly 2
authorisn <isn@opencascade.com>
Tue, 23 Jun 2015 07:36:25 +0000 (10:36 +0300)
committerisn <isn@opencascade.com>
Tue, 23 Jun 2015 08:27:12 +0000 (11:27 +0300)
src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverDlg.h
src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx
src/HYDROGUI/HYDROGUI_ImportLandcoverOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 447cddf6e6d0fd43483278a1cbedec12df6c88f4..b997bd4f084b329f724b4824b4fd7d14d7095b16 100644 (file)
 
 #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
index db99f74fcf8b711d6072a1083c5fe3664ecdeeb8..c9df043252c853f9221dd517d7aae634220caec7 100644 (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
index 8dc04c47e42385f4dbc43cf170f25b879bbd5599..56ca83951489b9fb50ce4201381885aef4dc6f8c 100644 (file)
@@ -53,6 +53,7 @@
 #include <gp_Pnt2d.hxx>
 #include <BRepTools.hxx>
 #include <gp_Pln.hxx>
+#include <QLineEdit>
 
 
 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<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();
@@ -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<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);
+  }
+  
+}
+
+
+
index b81e621e33cf5b17c5c6847e8433edd79fd46a78..f8b95c5eb637c2a7b14f07b424f32748cabc9e9d 100644 (file)
@@ -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<SHPObject*> mySHPObjects;
 };
 
index 8a74c2ecb5053640fc3323447a48f0aef20992d0..0490b1e6fe3a763283da15c410c2b008a34ac2bf 100644 (file)
@@ -2187,7 +2187,7 @@ file cannot be correctly imported for an Obstacle definition.</translation>
   </context>
 
  <context>
-    <name>HYDROGUI_ImportLandcoverOp</name>
+    <name>HYDROGUI_ImportLandCoverDlg</name>
     <message>
       <source>IMPORT_LANDCOVER</source>
       <translation>Import Land cover</translation>
@@ -2251,7 +2251,7 @@ file cannot be correctly imported for an Obstacle definition.</translation>
     </message>
   </context>
 
-   
+  
   <context>
     <name>HYDROGUI_GeoreferencementDlg</name>
     <message>