From: akl Date: Tue, 23 Dec 2008 07:23:45 +0000 (+0000) Subject: Fix of 20028 bug: 'Table data tree changes after Export-Import, so you cannot create... X-Git-Tag: V4_1_0_maintainance_20090206~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed10fe2b4026943f1c693055c7b5f8fcdd6a4a48;p=modules%2Fvisu.git 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. --- diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index 1f6f0127..4436d19c 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(IO_WriteOnly); + if (CORBA::is_nil(aTabAttr)) + return false; - /* extract the tabe info and write it into file */ + QFile aFile(theFileName); + aFile.open(IO_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.stripWhiteSpace(); - - SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); QString anAbscissUnit(aRowUnits[0]); anAbscissUnit.stripWhiteSpace(); - - 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.writeBlock("\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.writeBlock(aLine, aLine.length()); + + /* 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]).stripWhiteSpace().isEmpty()) { + aTitlesStr += (aTitlesSep + aRowTitles[i-1]); + if (aTitlesSep.isEmpty()) aTitlesSep = " | "; + } + if (!QString(aRowUnits[i-1]).stripWhiteSpace().isEmpty()) { + aUnitsStr += (aUnitsSep + aRowUnits[i-1]); + if (aUnitsSep.isEmpty()) aUnitsSep = " "; + } + } + aTitlesStr += "\n"; + aUnitsStr += "\n"; + aFile.writeBlock(aTitlesStr, aTitlesStr.length()); + aFile.writeBlock(aUnitsStr, aUnitsStr.length()); + + /* 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.stripWhiteSpace().isEmpty()) { + aColTitle = aColumnTitles[j-1]; + if (!aColTitle.stripWhiteSpace().isEmpty()) + aLine = aLine + " #TITLE: " + aColTitle + "\n"; + aFile.writeBlock(aLine, aLine.length()); + } + } + } //end of else + + aFile.close(); + return true; } bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName)