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