From: skl Date: Wed, 17 Mar 2010 09:37:10 +0000 (+0000) Subject: Implementation of Import/Export CSV tables (0020664). X-Git-Tag: V5_1_main_20100318 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfcfc32d645e5076c462f422ea9e056f8a7cc8ff;p=modules%2Fvisu.git Implementation of Import/Export CSV tables (0020664). --- diff --git a/doc/salome/gui/VISU/images/exporttables1.png b/doc/salome/gui/VISU/images/exporttables1.png new file mode 100644 index 00000000..8f13bb00 Binary files /dev/null and b/doc/salome/gui/VISU/images/exporttables1.png differ diff --git a/doc/salome/gui/VISU/images/exporttables2.png b/doc/salome/gui/VISU/images/exporttables2.png new file mode 100644 index 00000000..07093b17 Binary files /dev/null and b/doc/salome/gui/VISU/images/exporttables2.png differ diff --git a/doc/salome/gui/VISU/images/importtables.png b/doc/salome/gui/VISU/images/importtables.png new file mode 100644 index 00000000..8b903c2b Binary files /dev/null and b/doc/salome/gui/VISU/images/importtables.png differ diff --git a/doc/salome/gui/VISU/input/importing_exporting_tables_page.doc b/doc/salome/gui/VISU/input/importing_exporting_tables_page.doc index 84de7c94..9b9a4fd1 100644 --- a/doc/salome/gui/VISU/input/importing_exporting_tables_page.doc +++ b/doc/salome/gui/VISU/input/importing_exporting_tables_page.doc @@ -10,10 +10,14 @@ select Table from File item.
  • From the following standard dialog box: -\image html importtablefromfile.png +\image html importtables.png + +choose the necessary *.txt, *.tab or *.csv file containing tables and +click \b Open button. + +Checkbox "Use first string as title" is checked if it is needed to use +information from first string of file as titles of columns of table. -choose the necessary *.txt or *.tab file containing tables and -click \b Open button.
  • In the Object Browser \b Post-Pro will create a new folder having @@ -30,7 +34,13 @@ tables.
  • contain your exported table, and click \b OK button. Your table will be exported. -\image html exporttable.png +You can perform export table to *.txt or *.tab file + +\image html exporttables1.png + +Or you can perform export table to *.csv file + +\image html exporttables2.png diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index 8946a982..dded558f 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -2167,9 +2167,10 @@ module VISU { ViewManager GetViewManager(); /*! - * Imports tables from a file and create TableAttribute in Sudy + * Imports tables from a file and create TableAttribute in Study */ - SALOMEDS::SObject ImportTables(in string theFileName); + SALOMEDS::SObject ImportTables(in string theFileName, + in boolean theFirstStrAsTitle); /*! * Export table to a file diff --git a/src/CONVERTOR/VISU_TableReader.cxx b/src/CONVERTOR/VISU_TableReader.cxx index cb431dab..50d21b1b 100644 --- a/src/CONVERTOR/VISU_TableReader.cxx +++ b/src/CONVERTOR/VISU_TableReader.cxx @@ -135,18 +135,107 @@ namespace return !theStmIn.eof(); } + + //======================================================================= + //function : findNextCell + //purpose : auxilary for ImportCSVTable + //======================================================================= + bool findNextCell(std::ifstream& aStmIn, QString& aStr, + QString& aCell, const char theSeparator) + { + aCell = ""; + int index, tmpind = 0; + if( aStr.at(0) == theSeparator ) { + aStr.remove(0,1); + aStr = aStr.trimmed(); + if(aStr.size()==0) return true; + } + QString aTmp = aStr; + if( aTmp.at(0) == '"' ) { + // find closed " + while( !aStmIn.eof() ) { + tmpind = aTmp.indexOf('"',1); + if( tmpind < 0 ) { + while( !aStmIn.eof() ) { + aCell.push_back(aTmp); + aCell.push_back('\n'); + ::getLine( aStmIn, aTmp ); + tmpind = aTmp.indexOf('"',1); + if( tmpind >= 0 ) { + break; + } + } + } + if(tmpind < 0) + return false; + // read next symbol + if( aTmp.at(tmpind+1) == '"' ) { + // "" is found => need to continue + aCell.push_back(aTmp.left(tmpind+1)); + aTmp = aTmp.mid(tmpind+2); + } + else if( aTmp.at(tmpind+1) == theSeparator ) { + index = tmpind+1; + break; + } + else { + return false; + } + } + } + else { + // find index for separator + index = aTmp.indexOf( theSeparator ); + } + if( index < 0 ) { + aCell += aTmp; + aStr = ""; + } + else { + if(index>0) aCell += aTmp.left(index); + aStr = aTmp.mid(index).trimmed(); + } + if( aCell.size()>0 && aCell.at(0) == '"' ) { + // remove first and last symbols + int last = aCell.size()-1; + aCell.remove(last,1); + aCell.remove(0,1); + } + // replace "" to " in aCell + QChar ctmp = '"'; + QString tmp(ctmp); + tmp += ctmp; + index = aCell.indexOf(tmp); + while(index>=0) { + aCell.remove(index,1); + index = aCell.indexOf(tmp); + } + return true; + } + } //--------------------------------------------------------------- void -VISU::ImportTables( const char* theFileName, TTableContainer& theContainer ) +VISU::ImportTables( const char* theFileName, TTableContainer& theContainer, + bool theFirstStrAsTitle) { std::ifstream aStmIn; QFileInfo aFileInfo( theFileName ); if( !aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size() ) return; + QString tmp(theFileName); + tmp = tmp.trimmed(); + tmp = tmp.right(3).trimmed(); + + if( tmp == QString("csv") ) { + const char separator = ','; + ImportCSVTable(theFileName, theContainer, theFirstStrAsTitle, separator); + return; + } + aStmIn.open( theFileName ); QString aTmp; do { @@ -157,6 +246,7 @@ VISU::ImportTables( const char* theFileName, TTableContainer& theContainer ) TTable2D& aTable2D = *aTableIDMapper; if(MYDEBUG) std::cout << "New table is found" << std::endl; + bool IsFirst = true; while( !aStmIn.eof() && aTmp.trimmed() != "" ){ QString data = aTmp.trimmed(); QString cmt = ""; @@ -231,20 +321,31 @@ VISU::ImportTables( const char* theFileName, TTableContainer& theContainer ) else { TTable2D::TRow aRow; if(MYDEBUG) std::cout << "...New row is found: " << std::endl; - if ( !cmt.isEmpty() ) { - aRow.myTitle = cmt.toLatin1().constData(); - if(MYDEBUG) std::cout << "......ROW TITLE is: " << cmt.toLatin1().constData() << std::endl; - } QString datar1 = data.replace(QRegExp("\t"), " "); QStringList aValList = datar1.split( " ", QString::SkipEmptyParts ); - for ( int i = 0; i < aValList.count(); i++ ) { - if ( aValList[i].trimmed() != "" ) { - TTable2D::TValue aVal = aValList[i].trimmed().toLatin1().constData(); - aRow.myValues.push_back( aVal ); + if( aTable2D.myColumnTitles.size()==0 && IsFirst && theFirstStrAsTitle ) { + for ( int i = 0; i < aValList.count(); i++ ) { + QString tmpstr = aValList[ i ].trimmed(); + aTable2D.myColumnTitles.push_back( tmpstr.toLatin1().constData() ); } } - if( aRow.myValues.size() > 0 ) - aTable2D.myRows.push_back( aRow ); + else { + if ( !cmt.isEmpty() ) { + aRow.myTitle = cmt.toLatin1().constData(); + if(MYDEBUG) std::cout << "......ROW TITLE is: " << cmt.toLatin1().constData() << std::endl; + } + //QString datar1 = data.replace(QRegExp("\t"), " "); + //QStringList aValList = datar1.split( " ", QString::SkipEmptyParts ); + for ( int i = 0; i < aValList.count(); i++ ) { + if ( aValList[i].trimmed() != "" ) { + TTable2D::TValue aVal = aValList[i].trimmed().toLatin1().constData(); + aRow.myValues.push_back( aVal ); + } + } + if( aRow.myValues.size() > 0 ) + aTable2D.myRows.push_back( aRow ); + } + IsFirst = false; // ************** OLD CODE ****************** /* TValue aVal; @@ -271,6 +372,81 @@ VISU::ImportTables( const char* theFileName, TTableContainer& theContainer ) } +//======================================================================= +//function : ImportCSVTable +//purpose : +//======================================================================= +void VISU::ImportCSVTable(const char* theFileName, TTableContainer& theContainer, + bool theFirstStrAsTitle, const char theSeparator) +{ + std::ifstream aStmIn; + QFileInfo aFileInfo( theFileName ); + if( !aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size() ) + return; + aStmIn.open( theFileName ); + QString aTmp; + do { + // find beginning of table (tables are separated by empty lines) + while( ::getLine( aStmIn, aTmp ) && aTmp.trimmed() == ""); + + PTableIDMapper aTableIDMapper( new TTableIDMapper() ); + TTable2D& aTable2D = *aTableIDMapper; + if(MYDEBUG) std::cout << "New table is found" << std::endl; + + bool IsFirst = true; + QStringList aValList; + + while( !aStmIn.eof() ) { + QString aCell = ""; + if( !(::findNextCell(aStmIn, aTmp, aCell, theSeparator)) ) { + return; + } + if( aTmp.size()==0 ) { + // make table row + aValList.push_back(aCell); + if( IsFirst && theFirstStrAsTitle ) { + for ( int i = 0; i < aValList.count(); i++ ) { + aTable2D.myColumnTitles.push_back( aValList[i].trimmed().toLatin1().constData() ); + } + } + else { + TTable2D::TRow aRow; + for ( int i = 0; i < aValList.count(); i++ ) { + if ( aValList[i].trimmed() != "" ) { + TTable2D::TValue aVal = aValList[i].trimmed().toLatin1().constData(); + aRow.myValues.push_back( aVal ); + } + else { + aRow.myValues.push_back( "Empty" ); + } + } + if( aRow.myValues.size() > 0 ) { + aTable2D.myRows.push_back( aRow ); + } + } + // clear list of values and read next string + aValList.clear(); + ::getLine( aStmIn, aTmp ); + IsFirst = false; + } + else { + // put value to table cell + aValList.push_back(aCell); + } + } + + if( aTable2D.Check() ) { + if(MYDEBUG) std::cout << "aTable2D is checked OK " << aTable2D.myTitle << std::endl; + theContainer.push_back( aTableIDMapper ); + } + + } while ( !aStmIn.eof() ); + aStmIn.close(); + + if(MYDEBUG) std::cout << "After close" << std::endl; +} + + //--------------------------------------------------------------- VISU::TTableIDMapper ::TTableIDMapper(): @@ -404,3 +580,4 @@ VISU::TTableIDMapper myOutput->ShallowCopy( aFilter->GetOutput() ); aFilter->Delete(); } + diff --git a/src/CONVERTOR/VISU_TableReader.hxx b/src/CONVERTOR/VISU_TableReader.hxx index d01d916d..4e6c5114 100644 --- a/src/CONVERTOR/VISU_TableReader.hxx +++ b/src/CONVERTOR/VISU_TableReader.hxx @@ -102,8 +102,13 @@ namespace VISU //--------------------------------------------------------------- typedef std::vector TTableContainer; VISU_CONVERTOR_EXPORT - void ImportTables( const char* theFileName, TTableContainer& theContainer ); + void ImportTables( const char* theFileName, TTableContainer& theContainer, + bool theFirstStrAsTitle = false); + void ImportCSVTable(const char* theFileName, + TTableContainer& theContainer, + bool theFirstStrAsTitle, + const char theSeparator); //--------------------------------------------------------------- } diff --git a/src/ENGINE/VISU_Engine_i.cc b/src/ENGINE/VISU_Engine_i.cc index 2d0f66ad..117e5473 100644 --- a/src/ENGINE/VISU_Engine_i.cc +++ b/src/ENGINE/VISU_Engine_i.cc @@ -165,8 +165,10 @@ namespace VISU{ } - SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){ - return myVisuGen->ImportTables(theFileName); + SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName, + bool theFirstStrAsTitle) + { + return myVisuGen->ImportTables(theFileName,theFirstStrAsTitle); } diff --git a/src/ENGINE/VISU_Engine_i.hh b/src/ENGINE/VISU_Engine_i.hh index 950246d3..97cff3cd 100644 --- a/src/ENGINE/VISU_Engine_i.hh +++ b/src/ENGINE/VISU_Engine_i.hh @@ -57,8 +57,10 @@ namespace VISU virtual ViewManager_ptr GetViewManager(); - virtual SALOMEDS::SObject_ptr ImportTables(const char* theFileName); - virtual CORBA::Boolean ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName); + virtual SALOMEDS::SObject_ptr ImportTables(const char* theFileName, + bool theFirstStrAsTitle = false); + virtual CORBA::Boolean ExportTableToFile(SALOMEDS::SObject_ptr theTable, + const char* theFileName); //Create Result virtual Result_ptr ImportFile(const char* theFileName); @@ -68,15 +70,18 @@ namespace VISU virtual Result_ptr ImportMedField(SALOME_MED::FIELD_ptr theField); //Create Presentation Of Submeshes - virtual Mesh_ptr MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity); + virtual Mesh_ptr MeshOnEntity(Result_ptr theResult, const char* theMeshName, + VISU::Entity theEntity); virtual Mesh_ptr FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, const char* theFamilyName); - virtual Mesh_ptr GroupMesh(Result_ptr theResult, const char* theMeshName, const char* theGroupName); + virtual Mesh_ptr GroupMesh(Result_ptr theResult, const char* theMeshName, + const char* theGroupName); //Rename Presentation Of Submeshes virtual void RenameEntityInStudy(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, const char* theNewName); - virtual void RenameFamilyInStudy(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, + virtual void RenameFamilyInStudy(Result_ptr theResult, const char* theMeshName, + VISU::Entity theEntity, const char* theFamilyName, const char* theNewName); virtual void RenameGroupInStudy (Result_ptr theResult, const char* theMeshName, const char* theGroupName, const char* theNewName); diff --git a/src/VISUGUI/VISU_msg_en.ts b/src/VISUGUI/VISU_msg_en.ts index d6fa0e1c..22d1baf4 100644 --- a/src/VISUGUI/VISU_msg_en.ts +++ b/src/VISUGUI/VISU_msg_en.ts @@ -987,7 +987,7 @@ Please, refer to the documentation. FLT_TABLE_FILES - Tables (*.txt *.tab) + Tables (*.txt *.tab *.csv) IMPORT_FROM_FILE @@ -1388,6 +1388,10 @@ Please, refer to the documentation. USE_BUILD_PROGRESS Use build progress + + FIRST_STR_AS_TITLE + Use first string as title + MEN_LOAD_COMPONENT_DATA Load Component Data diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 792634a7..97ba5489 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -327,14 +327,32 @@ VisuGUI aFilter.append( tr("FLT_TABLE_FILES") ); aFilter.append( tr("FLT_ALL_FILES") ); - QString anInitialPath = ""; - if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) - anInitialPath = QDir::currentPath(); - - QStringList aFiles = SUIT_FileDlg::getOpenFileNames(GetDesktop(this), - anInitialPath, - aFilter, - tr("TLT_IMPORT_TABLE")); + //QString anInitialPath = ""; + //if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) + // anInitialPath = QDir::currentPath(); + + //QStringList aFiles = SUIT_FileDlg::getOpenFileNames(GetDesktop(this), + // anInitialPath, + // aFilter, + // tr("TLT_IMPORT_TABLE")); + + SUIT_ResourceMgr* aResourceMgr = GetResourceMgr(); + bool aFirstStrAsTitle = aResourceMgr->booleanValue("VISU", "first_str_as_title", false); + + SalomeApp_CheckFileDlg fd( GetDesktop(this), true, tr("FIRST_STR_AS_TITLE") ); + fd.setWindowTitle( tr( "IMPORT_FROM_FILE" ) ); + fd.setFileMode( SalomeApp_CheckFileDlg::ExistingFiles ); + fd.setFilters( aFilter ); + fd.SetChecked( aFirstStrAsTitle ); + if ( SalomeApp_CheckFileDlg::getLastVisitedPath().isEmpty() ) + fd.setDirectory( QDir::currentPath() ); + + QStringList aFiles; + if ( !fd.exec() ) + return; // cancelled, return + aFiles = fd.selectedFiles(); + aFirstStrAsTitle = fd.IsChecked(); + if ( aFiles.count() == 0 ) return; // nothing selected @@ -351,7 +369,9 @@ VisuGUI QString anInfo( tr("TLT_IMPORT_TABLE") + " " + aFileInfo.filePath() + " ..." ); application()->putInfo( anInfo ); - CORBA::Object_var anObject = GetVisuGen(this)->ImportTables(aFileInfo.filePath().toLatin1().constData()); + CORBA::Object_var anObject = + GetVisuGen(this)->ImportTables(aFileInfo.filePath().toLatin1().constData(), + aFirstStrAsTitle); if (CORBA::is_nil(anObject.in())) { errors.append( QString( "%1 :\n\t%2" ).arg( aFileInfo.filePath() ). @@ -444,6 +464,7 @@ VisuGUI // get name for the file QStringList aFilter; aFilter.append("Table Files (*.txt *.tab)"); + aFilter.append("CSV Table Files (*.csv)"); QFileInfo aFileInfo = SUIT_FileDlg::getFileName(GetDesktop(this), diff --git a/src/VISU_I/VISU_DumpPython.cc b/src/VISU_I/VISU_DumpPython.cc index e07a785f..b8356d85 100644 --- a/src/VISU_I/VISU_DumpPython.cc +++ b/src/VISU_I/VISU_DumpPython.cc @@ -1662,8 +1662,13 @@ namespace VISU if (aTypeName == "ImportTables") { QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist); if(anIsExist){ - std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap); - theStr<GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil(); - SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument); + SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument, + theFirstStrAsTitle); SALOMEDS::Study_var aStudy = aRes->GetStudy(); SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aRes); diff --git a/src/VISU_I/VISU_Gen_i.hh b/src/VISU_I/VISU_Gen_i.hh index 32eec815..951688c9 100644 --- a/src/VISU_I/VISU_Gen_i.hh +++ b/src/VISU_I/VISU_Gen_i.hh @@ -78,7 +78,7 @@ namespace VISU virtual SALOMEDS::SObject_ptr - ImportTables(const char* theFileName); + ImportTables(const char* theFileName, bool theFirstStrAsTitle = false); virtual CORBA::Boolean diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index fa9e334a..7b1f7a0e 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -1196,13 +1196,14 @@ SALOMEDS::SObject_var VISU::Container_i::GetSObject() } SALOMEDS::SObject_var -VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy) +VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy, + bool theFirstStrAsTitle) { // Set "C" numeric locale to import numbers correctly Kernel_Utils::Localizer loc; TTableContainer aContainer; - ImportTables( theFileName, aContainer ); + ImportTables( theFileName, aContainer, theFirstStrAsTitle ); if ( aContainer.empty() ) return SALOMEDS::SObject::_nil(); @@ -1217,10 +1218,10 @@ VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy) anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeString"); SALOMEDS::AttributeString_var aComment = SALOMEDS::AttributeString::_narrow(anAttr); QString aString; - aString.sprintf("myComment=ImportTables;myFileName=%s", - aFileInfo.absoluteFilePath().toLatin1().data()); + aString.sprintf("myComment=ImportTables;myFileName=%s;myFirstStrAsTitle=%d", + aFileInfo.absoluteFilePath().toLatin1().data(),theFirstStrAsTitle); aComment->SetValue(aString.toLatin1().data()); - for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++){ + for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++) { PTableIDMapper aTableIDMapper = aContainer[i]; const TTable2D& aTable2D = *aTableIDMapper; SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject); @@ -1229,7 +1230,8 @@ VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy) if(MYDEBUG) MESSAGE("aTable2D.myTitle = "<SetValue(aTable2D.myTitle.c_str()); - } else { + } + else { QString aNewName; aNewName.sprintf("Table:%d",i); aName->SetValue(aNewName.toLatin1().data()); @@ -1242,10 +1244,10 @@ VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy) aTable2D.getColumns(aNewTable2D); int kEnd = aNewTable2D.myRows[0].myValues.size(); aTableOfReal->SetNbColumns(kEnd); - for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++){ + for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) { if(MYDEBUG) MESSAGE("j = "<=0) { + aStr.insert(index,'"'); + if( index+2 >= aStr.size() ) break; + index = aStr.indexOf('"',index+2); + } + index = aStr.indexOf(aSep); + if(index>=0) { + // current string contains separator => need to use "..." + aStr.insert(0,'"'); + aStr.push_back('"'); + } +} + + +//======================================================================= +//function : ExportTableToFile +//purpose : +//======================================================================= template bool ExportTableToFile(const TTableAttr& aTabAttr, const char* theFileName) { @@ -1284,6 +1312,49 @@ template bool ExportTableToFile(const TTableAttr& aTabAttr, SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles(); + //-------------------------------------------------- + // write as *.csv file if it is needed + //-------------------------------------------------- + QString tmp(theFileName); + tmp = tmp.trimmed(); + tmp = tmp.right(3).trimmed(); + if( tmp == QString("csv") ) { + const char aSep = ','; + // write column titles + QString aLine(aRowTitles[0]); + updateStrForCSV(aLine,aSep); + for(int i=1; iHasValue(j,1)) { + aLine = aValue.sprintf("%.16g",(double)aTabAttr->GetValue(1,j)); + } + for (int i = 2; i <= aRowsNb; i++) { + if(aTabAttr->HasValue(i,j)) { + aLine += aSep + aValue.sprintf("%.16g",(double)aTabAttr->GetValue(i,j)); + } + else aLine += aSep; + } + aLine += "\n"; + aFile.write(aLine.toLatin1() ); + } + + aFile.close(); + return true; + } + //-------------------------------------------------- + // end of writing as *.csv file + //-------------------------------------------------- + /* The given table is rare (some cells is empty) or not? */ bool isRareTable = false; for (int i = 1; i <= aRowsNb; i++) @@ -1312,7 +1383,13 @@ template bool ExportTableToFile(const TTableAttr& aTabAttr, /* COLUMN_TITLES */ if ( anAbscissTitle.length() || anOrdinate.length() ) { - aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate + "\n"; + aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate; + int tmpind = aLine.indexOf("\n"); + while(tmpind>=0) { + aLine.remove(tmpind,1); + tmpind = aLine.indexOf("\n"); + } + aLine += "\n"; aFile.write(aLine.toLatin1() ); } @@ -1352,17 +1429,21 @@ template bool ExportTableToFile(const TTableAttr& aTabAttr, QString aUnitsSep = ""; QString aTitlesStr = "#COLUMN_TITLES: "; QString aUnitsStr = "#COLUMN_UNITS: "; - for (int i = 1; i <= aRowsNb; i++) - { - if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) { - aTitlesStr += (aTitlesSep + aRowTitles[i-1]); - if (aTitlesSep.isEmpty()) aTitlesSep = " | "; - } - if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) { - aUnitsStr += (aUnitsSep + aRowUnits[i-1]); - if (aUnitsSep.isEmpty()) aUnitsSep = " "; - } + for (int i = 1; i <= aRowsNb; i++) { + if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) { + aTitlesStr += (aTitlesSep + aRowTitles[i-1]); + if (aTitlesSep.isEmpty()) aTitlesSep = " | "; + } + if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) { + aUnitsStr += (aUnitsSep + aRowUnits[i-1]); + if (aUnitsSep.isEmpty()) aUnitsSep = " "; } + } + int tmpind = aTitlesStr.indexOf("\n"); + while(tmpind>=0) { + aTitlesStr.remove(tmpind,1); + tmpind = aTitlesStr.indexOf("\n"); + } aTitlesStr += "\n"; aUnitsStr += "\n"; aFile.write(aTitlesStr.toLatin1()); @@ -1370,22 +1451,20 @@ template bool ExportTableToFile(const TTableAttr& aTabAttr, /* CURVE COORDINATES */ QString aSep, aValue, aColTitle; - for (int j = 1; j <= aColNb; j++) - { - aLine = ""; aSep = ""; - for (int i = 1; i <= aRowsNb; i++) - { - aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j)))); - if (aSep.isEmpty()) aSep = " "; - } - if (!aLine.trimmed().isEmpty()) { - aColTitle = aColumnTitles[j-1]; - if (!aColTitle.trimmed().isEmpty()) - aLine = aLine + " #TITLE: " + aColTitle; - aLine += "\n"; - aFile.write(aLine.toLatin1()); - } + for (int j = 1; j <= aColNb; j++) { + aLine = ""; aSep = ""; + for (int i = 1; i <= aRowsNb; i++) { + aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j)))); + if (aSep.isEmpty()) aSep = " "; } + if (!aLine.trimmed().isEmpty()) { + aColTitle = aColumnTitles[j-1]; + if (!aColTitle.trimmed().isEmpty()) + aLine = aLine + " #TITLE: " + aColTitle; + aLine += "\n"; + aFile.write(aLine.toLatin1()); + } + } } //end of else aFile.close(); @@ -1396,17 +1475,15 @@ bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFile { //Find table SALOMEDS::GenericAttribute_var anAttr ; - if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) - { - SALOMEDS::AttributeTableOfReal_var aTabAttr = SALOMEDS::AttributeTableOfReal ::_narrow(anAttr); - return ExportTableToFile ( aTabAttr , theFileName); - - } + if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) { + SALOMEDS::AttributeTableOfReal_var aTabAttr = + SALOMEDS::AttributeTableOfReal ::_narrow(anAttr); + return ExportTableToFile ( aTabAttr , theFileName); + } else if (theTable->FindAttribute(anAttr, "AttributeTableOfInteger")) { - - SALOMEDS::AttributeTableOfInteger_var aTabAttr = SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr); + SALOMEDS::AttributeTableOfInteger_var aTabAttr = + SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr); return ExportTableToFile ( aTabAttr , theFileName); - } return false; } diff --git a/src/VISU_I/VISU_Table_i.hh b/src/VISU_I/VISU_Table_i.hh index 4303f6b6..78c6776a 100644 --- a/src/VISU_I/VISU_Table_i.hh +++ b/src/VISU_I/VISU_Table_i.hh @@ -84,7 +84,8 @@ namespace VISU{ virtual std::string GetObjectEntry(); }; - SALOMEDS::SObject_var ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy); + SALOMEDS::SObject_var ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy, + bool theFirstStrAsTitle = false); bool ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName); //============================================================================== class VISU_I_EXPORT Curve_i : public virtual POA_VISU::Curve,