#include <TDataStd_RealArray.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_Integer.hxx>
+#include <TDataStd_ExtStringArray.hxx>
#include <QColor>
#include <QFile>
#include <QPointF>
#include <QPolygonF>
#include <QStringList>
+#include <QString>
#ifndef LIGHT_MODE
#include <vtkPoints.h>
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;
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 )
{
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,
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
};
*/
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
* \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;
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
+#include <QListWidget>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QPicture>
-#include <QToolButton>
+#include <QPushButton>
#include <QCheckBox>
+//TODO add new checkbox ('FUSE INTO THE ONE')!!!
HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle )
{
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" ) );
void HYDROGUI_ImportBathymetryDlg::reset()
{
- myFileName->clear();
+ myFileNames->clear();
myObjectName->clear();
myObjectNameGroup->setEnabled( false );
}
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
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 )
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 );
}
}
class QGroupBox;
class QLineEdit;
class QCheckBox;
+class QListWidget;
+class QStringList;
class HYDROGUI_ImportBathymetryDlg : public HYDROGUI_InputPanel
{
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;
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 );
}
}
{
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;
}
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
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;
}
}
return true;
}
-
+
void HYDROGUI_ImportBathymetryOp::onFileSelected()
{
HYDROGUI_ImportBathymetryDlg* aPanel =
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();
}
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();
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() );
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() );