From: isn Date: Tue, 6 Sep 2016 18:37:47 +0000 (+0300) Subject: import of multi baths (draft; always fused) X-Git-Tag: v1.6~75^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c305a67ff4752ad6025962f5ec87e8db650325e0;p=modules%2Fhydro.git import of multi baths (draft; always fused) --- diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index db677852..b5a50b1b 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #ifndef LIGHT_MODE #include @@ -431,6 +433,19 @@ void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePa TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath ); } +void HYDROData_Bathymetry::SetFilePaths( const QStringList& theFilePaths ) +{ + int i = 1; + Handle_TDataStd_ExtStringArray TExtStrArr = TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_FilePaths ), 1, theFilePaths.size() ); + foreach (QString filepath, theFilePaths) + { + std::string sstr = filepath.toStdString(); + const char* Val = sstr.c_str(); + TExtStrArr->SetValue(i, TCollection_ExtendedString(Val)); + i++; + } +} + TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const { TCollection_AsciiString aRes; @@ -442,10 +457,42 @@ TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) aRes = anAsciiStr->Get(); } + else + { + aLabel = myLab.FindChild( DataTag_FilePaths, false ); + if ( !aLabel.IsNull() ) + { + Handle(TDataStd_ExtStringArray) anExtStrArr; + if ( aLabel.FindAttribute( TDataStd_ExtStringArray::GetID(), anExtStrArr ) ) + aRes = anExtStrArr->Value(1); //try take the first; convert extstring to asciistring + } + } return aRes; } +QStringList HYDROData_Bathymetry::GetFilePaths() const +{ + QStringList aResL; + + TDF_Label aLabel = myLab.FindChild( DataTag_FilePaths, 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); + aResL << QString(aText.ToCString()); + } + } + } + + return aResL; +} + void HYDROData_Bathymetry::SetAltitudesInverted( const bool theIsInverted, const bool theIsUpdate ) { @@ -490,46 +537,51 @@ bool HYDROData_Bathymetry::IsAltitudesInverted() const return aRes; } -bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName ) +bool HYDROData_Bathymetry::ImportFromFiles( const QStringList& theFileNames ) { - // Try to open the file - QFile aFile( theFileName.ToCString() ); - if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) - return false; + AltitudePoints AllPoints; + bool Stat = false; - bool aRes = false; + foreach (QString theFileName, theFileNames) + { + // Try to open the file + QFile aFile( theFileName ); + if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) + continue; - QString aFileSuf = QFileInfo( aFile ).suffix().toLower(); + QString aFileSuf = QFileInfo( aFile ).suffix().toLower(); - AltitudePoints aPoints; + AltitudePoints aPoints; - // Try to import the file - if ( aFileSuf == "xyz" ) - aRes = importFromXYZFile( aFile, aPoints ); - else if ( aFileSuf == "asc" ) - aRes = importFromASCFile( aFile, aPoints ); + // Try to import the file + if ( aFileSuf == "xyz" ) + Stat = Stat || importFromXYZFile( aFile, aPoints ); + else if ( aFileSuf == "asc" ) + Stat = Stat || importFromASCFile( aFile, aPoints ); - // Close the file - aFile.close(); - + // Close the file + aFile.close(); + + AllPoints.Append(aPoints); + } // Convert from global to local CS Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab ); - AltitudePoints::Iterator anIter( aPoints ); + AltitudePoints::Iterator anIter( AllPoints ); for ( ; anIter.More(); anIter.Next() ) { AltitudePoint& aPoint = anIter.ChangeValue(); aDoc->Transform( aPoint, true ); } - if ( aRes ) + if ( Stat ) { // Update file path and altitude points of this Bathymetry - SetFilePath( theFileName ); - SetAltitudePoints( aPoints ); + SetFilePaths (theFileNames ); + SetAltitudePoints( AllPoints ); } - return aRes && !aPoints.IsEmpty(); + return Stat && !AllPoints.IsEmpty(); } bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile, diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 1fed12a2..c7039c3c 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -58,6 +58,7 @@ protected: DataTag_First = HYDROData_IAltitudeObject::DataTag_First + 100, ///< first tag, to reserve DataTag_AltitudePoints, ///< altitude points, array of reals DataTag_FilePath, ///< bathymetry imported file path + DataTag_FilePaths, ///< bathymetry imported file paths DataTag_AltitudesInverted, ///< flag to invert z values }; @@ -120,11 +121,15 @@ public: */ HYDRODATA_EXPORT void SetFilePath( const TCollection_AsciiString& theFilePath ); + HYDRODATA_EXPORT void SetFilePaths( const QStringList& theFilePaths ); + /** * Returns uploaded bathymetry file path */ HYDRODATA_EXPORT TCollection_AsciiString GetFilePath() const; + HYDRODATA_EXPORT QStringList GetFilePaths() const; + /** * Set flag indicating needs to invert altitude values * \param theIsInverted new invert value @@ -144,7 +149,7 @@ public: * \param theFileName the path to file * \return \c true if file has been successfully read */ - HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName ); + HYDRODATA_EXPORT virtual bool ImportFromFiles( const QStringList& theFileNames ); HYDRODATA_EXPORT Handle_HYDROData_PolylineXY CreateBoundaryPolyline() const; diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx index 76ab3075..e4b67cab 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx @@ -24,14 +24,16 @@ #include #include +#include #include #include #include #include #include -#include +#include #include +//TODO add new checkbox ('FUSE INTO THE ONE')!!! HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) { @@ -42,18 +44,22 @@ HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* the QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup ); - myFileName = new QLineEdit( myFileNameGroup ); - myFileName->setReadOnly( true ); + myFileNames = new QListWidget( myFileNameGroup ); + myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents ); + //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus); //TODO + //myFileNames->setReadOnly( true ); - QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup ); + QPushButton* aBrowseBtn = new QPushButton( myFileNameGroup ); + // aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); + aBrowseBtn->setText("Load files(s)"); aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); - QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup ); + QBoxLayout* aFileNameLayout = new QVBoxLayout( myFileNameGroup ); aFileNameLayout->setMargin( 5 ); aFileNameLayout->setSpacing( 5 ); - aFileNameLayout->addWidget( aFileNameLabel ); - aFileNameLayout->addWidget( myFileName ); + aFileNameLayout->addWidget( aFileNameLabel ); aFileNameLayout->addWidget( aBrowseBtn ); + aFileNameLayout->addWidget( myFileNames ); // Bathymetry name myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) ); @@ -85,7 +91,7 @@ HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg() void HYDROGUI_ImportBathymetryDlg::reset() { - myFileName->clear(); + myFileNames->clear(); myObjectName->clear(); myObjectNameGroup->setEnabled( false ); } @@ -93,7 +99,7 @@ void HYDROGUI_ImportBathymetryDlg::reset() void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName ) { myObjectName->setText( theName ); - myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() ); + myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileNames->count() ); } QString HYDROGUI_ImportBathymetryDlg::getObjectName() const @@ -101,17 +107,24 @@ QString HYDROGUI_ImportBathymetryDlg::getObjectName() const return myObjectName->text(); } -void HYDROGUI_ImportBathymetryDlg::setFileName( const QString& theFileName ) +void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames ) { - myFileName->setText( theFileName ); + + myFileNames->addItems( theFileNames ); if ( !myObjectNameGroup->isEnabled() ) - myObjectNameGroup->setEnabled( !theFileName.isEmpty() ); + myObjectNameGroup->setEnabled( !theFileNames.isEmpty() ); } -QString HYDROGUI_ImportBathymetryDlg::getFileName() const +QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const { - return myFileName->text(); + QStringList stritems; + for(int i = 0; i < myFileNames->count(); ++i) + { + QListWidgetItem* item = myFileNames->item(i); + stritems << item->text(); + } + return stritems; } void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert ) @@ -127,12 +140,12 @@ bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const void HYDROGUI_ImportBathymetryDlg::onBrowse() { QString aFilter( tr( "BATHYMETRY_FILTER" ) ); - QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true ); + QStringList aFileNames = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true ); - if( !aFileName.isEmpty() ) + if( !aFileNames.isEmpty() ) { - setFileName( aFileName ); - emit FileSelected( aFileName ); + setFileNames( aFileNames ); + emit FileSelected( aFileNames ); } } diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h index d854e1bb..210c5e9d 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h @@ -26,6 +26,8 @@ class QGroupBox; class QLineEdit; class QCheckBox; +class QListWidget; +class QStringList; class HYDROGUI_ImportBathymetryDlg : public HYDROGUI_InputPanel { @@ -40,21 +42,21 @@ public: void setObjectName( const QString& theName ); QString getObjectName() const; - void setFileName( const QString& theFileName ); - QString getFileName() const; + void setFileNames( const QStringList& theFileName ); + QStringList getFileNames() const; void setInvertAltitudes( const bool theIsInvert ); bool isInvertAltitudes() const; signals: - void FileSelected( const QString& theFileName ); + void FileSelected( const QStringList& theFileName ); protected slots: void onBrowse(); private: QGroupBox* myFileNameGroup; - QLineEdit* myFileName; + QListWidget* myFileNames; QCheckBox* myInvertAltitudes; diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx index d8b3abbc..ca048674 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx @@ -65,11 +65,11 @@ void HYDROGUI_ImportBathymetryOp::startOperation() if( !myEditedObject.IsNull() ) { QString aName = myEditedObject->GetName(); - QString aFileName = HYDROGUI_Tool::ToQString( myEditedObject->GetFilePath() ); + QStringList aFileNames = myEditedObject->GetFilePaths(); bool anIsAltitudesInverted = myEditedObject->IsAltitudesInverted(); aPanel->setObjectName( aName ); - aPanel->setFileName( aFileName ); + aPanel->setFileNames( aFileNames ); aPanel->setInvertAltitudes( anIsAltitudesInverted ); } } @@ -89,7 +89,7 @@ HYDROGUI_InputPanel* HYDROGUI_ImportBathymetryOp::createInputPanel() const { HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportBathymetryDlg( module(), getName() ); - connect ( aPanel, SIGNAL( FileSelected( const QString& ) ), SLOT( onFileSelected() ) ); + connect ( aPanel, SIGNAL( FileSelected( const QStringList& ) ), SLOT( onFileSelected() ) ); return aPanel; } @@ -110,22 +110,30 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, return false; } - QString aFileName = aPanel->getFileName().simplified(); + QStringList aFileNames = aPanel->getFileNames(); //TODO simplified ?? + bool anIsInvertAltitudes = aPanel->isInvertAltitudes(); - if ( aFileName.isEmpty() ) + if ( aFileNames.isEmpty() ) { theErrorMsg = tr( "INCORRECT_FILE_NAME" ); return false; } - QFileInfo aFileInfo( aFileName ); - if ( !aFileInfo.exists() || !aFileInfo.isReadable() ) + QStringList DummyFileList; + foreach (QString aFileName, aFileNames ) { - theErrorMsg = tr( "FILE_NOT_EXISTS_OR_CANT_BE_READ" ).arg( aFileName ); - return false; + QFileInfo aFileInfo( aFileName ); + if ( !aFileInfo.exists() || !aFileInfo.isReadable() ) + { + theErrorMsg = tr( "FILE_NOT_EXISTS_OR_CANT_BE_READ" ).arg( aFileName ); + continue; + } + DummyFileList << aFileName; } + aFileNames = DummyFileList; + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) { // check that there are no other objects with the same name in the document @@ -150,13 +158,13 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if ( aBathymetryObj.IsNull() ) return false; - QString anOldFileName = HYDROGUI_Tool::ToQString( aBathymetryObj->GetFilePath() ); - if ( aFileName != anOldFileName ) + QStringList anOldFileName = aBathymetryObj->GetFilePaths(); + if ( aFileNames != anOldFileName ) { aBathymetryObj->SetAltitudesInverted( anIsInvertAltitudes, false ); - if ( !aBathymetryObj->ImportFromFile( HYDROGUI_Tool::ToAsciiString( aFileName ) ) ) + if ( !aBathymetryObj->ImportFromFiles( aFileNames ) ) { - theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileName ); + theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileNames.join("\n") ); return false; } } @@ -208,7 +216,7 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, return true; } - + void HYDROGUI_ImportBathymetryOp::onFileSelected() { HYDROGUI_ImportBathymetryDlg* aPanel = @@ -217,9 +225,9 @@ void HYDROGUI_ImportBathymetryOp::onFileSelected() return; QString anObjectName = aPanel->getObjectName().simplified(); - //if ( anObjectName.isEmpty() ) + if ( anObjectName.isEmpty() ) { - anObjectName = aPanel->getFileName(); + anObjectName = aPanel->getFileNames().join("\n"); //TODO temp if ( !anObjectName.isEmpty() ) { anObjectName = QFileInfo( anObjectName ).baseName(); } diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index e2302918..1708ba11 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -53,7 +53,7 @@ public: void SetAltitudesInverted( const bool theIsInverted, const bool theIsUpdate = true ); bool IsAltitudesInverted() const; - bool ImportFromFile( const TCollection_AsciiString& theFileName ); + bool ImportFromFiles( const QStringList& theFileNames ); protected: HYDROData_Bathymetry(); diff --git a/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx index 4a25258f..54b6631f 100644 --- a/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx +++ b/src/HYDRO_tests/test_HYDROData_Bathymetry.cxx @@ -125,7 +125,7 @@ void test_HYDROData_Bathymetry::testFileImport() if ( !createTestFile( aFileName ) ) return; // No file has been created - CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName.toStdString().c_str() ) ); + CPPUNIT_ASSERT( aBathymetry->ImportFromFiles( QStringList(aFileName)) ); HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints(); CPPUNIT_ASSERT_EQUAL( 2300, anAltitudePoints.Length() ); @@ -171,7 +171,7 @@ void test_HYDROData_Bathymetry::testCopy() if ( anIsFileCreated ) { - CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName.toStdString().c_str() ) ); + CPPUNIT_ASSERT( aBathymetry1->ImportFromFiles( QStringList(aFileName ) ) ); HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints(); CPPUNIT_ASSERT_EQUAL( 2300, anAltitudePoints.Length() );