template<class TTableAttr> 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 */
}
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)