From 26054d91ead7683c07e810dad5f1cb9dd93476fd Mon Sep 17 00:00:00 2001 From: akl Date: Tue, 23 Dec 2008 07:27:12 +0000 Subject: [PATCH] Fix of 20028 bug: 'Table data tree changes after Export-Import, so you cannot create 3D table presentation'. Write the table without separating to 2D tables if it is NOT a rare one. --- src/VISU_I/VISU_Table_i.cc | 88 ++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index 1c799e5e..b9f99c27 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -1258,28 +1258,37 @@ VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy) template bool ExportTableToFile(const TTableAttr& aTabAttr, const char* theFileName) { - if (!CORBA::is_nil(aTabAttr)) { - QFile aFile(theFileName); - aFile.open(QIODevice::WriteOnly); + if (CORBA::is_nil(aTabAttr)) + return false; - /* extract the tabe info and write it into file */ + QFile aFile(theFileName); + aFile.open(QIODevice::WriteOnly); - QString aTitle(aTabAttr->GetTitle()); /*Table title*/ - int aRowsNb = aTabAttr->GetNbRows(); - int aColNb = aTabAttr->GetNbColumns(); + /* extract the table info and write it into file */ - SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles(); + QString aTitle(aTabAttr->GetTitle()); /*Table title*/ + int aRowsNb = aTabAttr->GetNbRows(); + int aColNb = aTabAttr->GetNbColumns(); + + SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles(); + SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); + SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles(); + + /* The given table is rare (some cells is empty) or not? */ + bool isRareTable = false; + for (int i = 1; i <= aRowsNb; i++) + for (int j = 1; j <= aColNb && !isRareTable; j++) + isRareTable = !aTabAttr->HasValue(i,j); + + QString aLine; + if (isRareTable) { + /* Separate the given table to 2D tables and write these ones to the file */ QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/ anAbscissTitle.trimmed(); - - SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); QString anAbscissUnit(aRowUnits[0]); anAbscissUnit.trimmed(); - - SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles(); if (aRowsNb > 2 && aTitle.length() ) aTitle = aTitle + " - "; - QString aLine; for (int i = 2; i <= aRowsNb; i++ ) { /* TITLE */ @@ -1321,10 +1330,55 @@ template bool ExportTableToFile(const TTableAttr& aTabAttr, } aFile.write("\n", 1); } - aFile.close(); - return true; - } - return false; + }//end of if (isRareTable) + else { + /* Write the table in the file without separating */ + /* TITLE */ + aLine = "#TITLE: " + aTitle + "\n"; + aFile.write(aLine.toLatin1()); + + /* COLUMN_TITLES and COLUMN_UNITS */ + QString aTitlesSep = ""; + 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 = " "; + } + } + aTitlesStr += "\n"; + aUnitsStr += "\n"; + aFile.write(aTitlesStr.toLatin1()); + aFile.write(aUnitsStr.toLatin1()); + + /* 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 + "\n"; + aFile.write(aLine.toLatin1()); + } + } + } //end of else + + aFile.close(); + return true; } bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName) -- 2.39.2