From: <dhu...@us...> - 2007-02-16 21:53:31
|
Revision: 335 http://svn.sourceforge.net/qcell/?rev=335&view=rev Author: dhubleizh Date: 2007-02-16 13:53:26 -0800 (Fri, 16 Feb 2007) Log Message: ----------- - REAK an ZIFW saving Modified Paths: -------------- trunk/qcell/baseheaders/LocalFunction.h trunk/qcell/parsers/FQT/FQTParserPlugin.cpp trunk/qcell/parsers/REAK/REAKParserPlugin.cpp trunk/qcell/parsers/ZIFW/ZIFWParserPlugin.cpp trunk/qcell/visgui/MainWindow.cpp Modified: trunk/qcell/baseheaders/LocalFunction.h =================================================================== --- trunk/qcell/baseheaders/LocalFunction.h 2007-02-16 19:32:47 UTC (rev 334) +++ trunk/qcell/baseheaders/LocalFunction.h 2007-02-16 21:53:26 UTC (rev 335) @@ -89,7 +89,6 @@ void valueTableFromString(QString *string); void sumArgumentsFromString(QString *string); - QVector<int> valueTranslation(int value); QString valueFormTableToString(int index); @@ -119,6 +118,7 @@ // void setScript(QString scriptData); + QVector<int> valueTranslation(int value); // method set type of function (normally function type is set automatically when setSumArguments, setProductArguments, setSwitchFunction or setScript methosd ar used) void setFunctonType(LocalFunction::FUNCTION_TYPE type); Modified: trunk/qcell/parsers/FQT/FQTParserPlugin.cpp =================================================================== --- trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-02-16 19:32:47 UTC (rev 334) +++ trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-02-16 21:53:26 UTC (rev 335) @@ -356,22 +356,34 @@ QDomDocument doc; doc.setContent(content); + qDebug(content.toAscii()); QDomElement root = doc.firstChild().toElement(); - root.removeChild(root.firstChild()); + if (root.firstChild().nodeName() == "LocalFunction") + { + root.removeChild(root.firstChild()); + } QDomElement values = root.firstChild().toElement(); int free_args = lf.getNumberOfArgs() - lf.getSummedArguments().count(); int num_combinations = pow(lf.getAlphabetSize(), free_args); QChar fill_value = values.attribute("FillValue")[0]; int index = 0; QString values_txt = values.text(); + qDebug() << values_txt; values_txt.chop(1); +qDebug() << values_txt; values_txt.remove(0, 1); +qDebug() << values_txt; foreach(QString sum_line, values_txt.split(";\n")) { + qDebug() << sum_line; QStringList tokens = sum_line.split('='); + qDebug() << tokens; QStringList sum_and_free = tokens[0].split('+'); + qDebug() << sum_and_free; QString sum = sum_and_free.takeFirst(); + qDebug() << sum; QStringList free = sum_and_free.first().split(','); + qDebug() << free; if (!fqt.contains(sum)) { Modified: trunk/qcell/parsers/REAK/REAKParserPlugin.cpp =================================================================== --- trunk/qcell/parsers/REAK/REAKParserPlugin.cpp 2007-02-16 19:32:47 UTC (rev 334) +++ trunk/qcell/parsers/REAK/REAKParserPlugin.cpp 2007-02-16 21:53:26 UTC (rev 335) @@ -246,150 +246,50 @@ QByteArray REAKParserPlugin::parseOut(QString content, const QString type, const QString subtype) { /// @todo Write parsing out of REAK - this WILL be hard -// // The resulting array to write to file by the end backend -// QByteArray result; -// // Generic class for parsing out XMLString -// Neighbourhood N; -// QVector<NContainer> neighbours; -// // Number of dimensions -// int dimensions; -// // Maximum found dimensions -// int max_x, max_y,max_z, min_x, min_y, min_z; -// // Needs to be set to 1, as there needs to be at least one of each -// // dimensions for this implementation -// max_x = max_y = max_z = min_x = min_y = min_z = 0; -// -// if(!N.fromXmlString(&content)) -// { -// qDebug(tr("Unable to parse out internal data!").toAscii()); -// } -// -// dimensions = N.getDimension(); -// -// // Filetype and dimensions declaration -// result.append('N'); -// result.append(QString::number(dimensions)); -// result.append('\n'); -// -// // Sizes of dimensions -// // Get out neighbours vector -// neighbours = N.getNeighbours(); -// //Determin the maximum of each supported dimension -// -// for(int i = 0; i < neighbours.size(); i++) -// { -// if(neighbours[i].x > max_x) -// { -// max_x = neighbours[i].x; -// } -// else if (neighbours[i].x < min_x) -// { -// min_x = neighbours[i].x; -// } -// if(dimensions > 1) -// { -// if(neighbours[i].y > max_y) -// { -// max_y = neighbours[i].y; -// } -// else if (neighbours[i].y < min_y) -// { -// min_y = neighbours[i].y; -// } -// } -// else -// { -// neighbours[i].y = 0; -// } -// if(dimensions == 3) -// { -// if (neighbours[i].z > max_z) -// { -// max_z = neighbours[i].z; -// } -// else if (neighbours[i].z < min_z) -// { -// min_z = neighbours[i].z; -// } -// } -// else -// { -// neighbours[i].z = 0; -// } -// } -// -// // Construct a space filled with '-' -// // At least one is needed always, even when the rest of dimensions is 0, -// // that's why the +1 everywhere -// QVector<QVector<QVector<char> > > table((abs(min_z)+max_z+1), -// QVector<QVector<char> >((abs(min_y)+max_y+1), -// QVector<char>((abs(min_x)+max_x+1), '-') -// ) -// ); -// -// // Adding dimensions declaration to file -// if (dimensions == 1) -// { -// result.append('0' + table[0][0].size()); -// } -// else -// { -// result.append('0' + table[0].size()); -// result.append(' '); -// result.append('0' + table[0][0].size()); -// -// if (dimensions == 3) -// { -// result.append(' '); -// result.append('0' + table.size()); -// } -// } -// // and number of neighbours -// result.append(' '); -// result.append(QString::number(N.getNeighbourNumber())); -// result.append('\n'); -// -// // Adding zero points coordinates -// int zero_x, zero_y, zero_z; -// zero_x = abs(min_x); -// zero_y = abs(min_y); -// zero_z = abs(min_z); -// -// result.append('0' + zero_x); -// if(dimensions > 1) -// { -// result.append(' '); -// result.append('0' + zero_y); -// } -// if (dimensions == 3) -// { -// result.append(' '); -// result.append('0' + zero_z); -// } -// result.append('\n'); -// -// // Filling default space with proper points -// for(int i = 0; i < neighbours.size(); i++) -// { -// table[zero_z+neighbours[i].z][zero_y+neighbours[i].y][zero_x+neighbours[i].x] = ('0' + i + 1); -// } -// -// // Creating proper result format -// for (int z = 0; z < table.size(); z++) -// { -// for (int y = 0; y < table[z].size(); y++) -// { -// for ( int x = 0; x < table[z][y].size(); x++) -// { -// result.append(table[z][y][x]); -// } -// -// result.append('\n'); -// } -// } -// - return QByteArray(); + // The resulting array to write to file by the end backend + QByteArray result; + // Generic class for parsing out XMLString + LocalFunction lf; + if(!lf.fromXmlString(&content)) + { + qDebug(tr("Unable to parse out internal data!").toAscii()); + return QByteArray(); + } + else if (lf.getFunctonType() != LocalFunction::SWITCH) + { + qDebug(tr("This format cannot store this function type.") + .toAscii() + ); + + return QByteArray(); + } + + // Filetype + result.append("REAK\n"); + // Function specyfication + result.append(QString("%1 %2\n") + .arg(lf.getAlphabetSize()) + .arg(lf.getNumberOfArgs()) + ); + + QVector<int> tmp_args; + for (int i = 0; i < lf.getValueTableSize(); i++) + { + if (lf.getValueAt(i) > -1) + { + tmp_args = lf.valueTranslation(i); + tmp_args.remove(0, 1); + for (int j = 0; j < tmp_args.count(); j++) + { + result.append(QString::number(tmp_args[j])); + } + + result.append(QString(" %1\n").arg(lf.getValueAt(i))); + } + } + + return result; } Q_EXPORT_PLUGIN2(REAKFileParser, REAKParserPlugin) Modified: trunk/qcell/parsers/ZIFW/ZIFWParserPlugin.cpp =================================================================== --- trunk/qcell/parsers/ZIFW/ZIFWParserPlugin.cpp 2007-02-16 19:32:47 UTC (rev 334) +++ trunk/qcell/parsers/ZIFW/ZIFWParserPlugin.cpp 2007-02-16 21:53:26 UTC (rev 335) @@ -6,7 +6,6 @@ * Last Update: czw lis 30 14:19:22 CET 2006 */ #include "ZIFWParserPlugin.h" -#include <QDebug> ZIFWParserPlugin::ZIFWParserPlugin() { @@ -260,48 +259,72 @@ QByteArray ZIFWParserPlugin::parseOut(QString content, const QString type, const QString subtype) { -// // The resulting array to write to file by the backend -// QByteArray result; -// // Generic type to parse XML request -// LocalFunction lf; -// -// // Check if we can use the generic type from the XML string -// if(!lf.fromXmlString(&content)); -// { -// qDebug(tr("Unable to parse out internal data!").toAscii()); -// -// return QByteArray(); -// } -// -// // Header -// result.append("ZIFW"); -// result.append('\n'); -// -// // Second line -// // Num of args -// result.append(lf.getNumberOfArgs()); -// result.append(' '); -// // Num of arg values -// result.append(lf.getAlphabetSize()); -// result.append(' '); -// // Num of return values -// result.append(lf.getMaxReturnValues()); -// result.append(' '); -// result.append('\n'); -// -// // Third line - summed args -// foreach(int arg, lf.getSummedArguments()) -// { -// result.append(QString::number(arg)[0].toAscii()); -// result.append(','); -// } -// // Get rid of the penging `,' -// result.chop(1); -// result.append('\n'); -// -// /// @todo Main function writing -// - return QByteArray(); + // The resulting array to write to file by the backend + QByteArray result; + // Generic type to parse XML request + LocalFunction lf; + // Multi Map to store this shit + QMultiMap<int, QVector<int> > function; + + // Check if we can use the generic type from the XML string + if(!lf.fromXmlString(&content)) + { + qDebug(tr("Unable to parse out internal data!").toAscii()); + + return QByteArray(); + } + else if (lf.getFunctonType() != LocalFunction::SWITCH) + { + qDebug(tr("This format cannot store this function type.") + .toAscii() + ); + + return QByteArray(); + } + + // Filetype + result.append("REAK\n"); + // Function specyfication + result.append(QString("%1 %2\n") + .arg(lf.getAlphabetSize()) + .arg(lf.getNumberOfArgs()) + ); + + // Map all the values to a map indexed by return value + QVector<int> tmp_args; + for (int i = 0; i < lf.getValueTableSize(); i++) + { + if (lf.getValueAt(i) > -1) + { + tmp_args = lf.valueTranslation(i); + tmp_args.remove(0, 1); + function.insert(lf.getValueAt(i), tmp_args); + } + } + + QVector<int> added_values; + foreach(int key, function.keys()) + { + if (added_values.contains(key)) + { + continue; + } + added_values.append(key); + result.append(QString("%1: {").arg(key)); + foreach(QVector<int> v, function.values(key)) + { + for (int i = 0; i < v.count(); i++) + { + result.append(QString::number(v[i])); + } + result.append(','); + } + // Remove pending ',' + result.chop(1); + result.append("}\n"); + } + + return result; } Q_EXPORT_PLUGIN2(ZIFWFileParser, ZIFWParserPlugin) Modified: trunk/qcell/visgui/MainWindow.cpp =================================================================== --- trunk/qcell/visgui/MainWindow.cpp 2007-02-16 19:32:47 UTC (rev 334) +++ trunk/qcell/visgui/MainWindow.cpp 2007-02-16 21:53:26 UTC (rev 335) @@ -652,6 +652,12 @@ } else if (type == "LocalFunction") { +// if (local_function->getFunctonType() != LocalFunction::SUM_AND_SWITCH) +// { +// qDebug(tr("Saving non FQT function is not implemented.").toAscii()); +// return; +// } + if (!function_parsers.contains(subtype)) { qDebug(tr("The file extensions %1 isn't supported.") @@ -1096,14 +1102,23 @@ filters << filter; } fd.setFilters(filters); - fd.setDefaultSuffix("FQT"); +// fd.setDefaultSuffix("FQT"); if(fd.exec()) { if(!fd.selectedFiles().isEmpty()) { - callSaver(fd.selectedFiles().first(), "LocalFunction"); - + QString extension = fd.selectedFilter(); + extension.remove(QRegExp(".*\\(\\*\\.")); + extension.chop(1); + if (!fd.selectedFiles().first().endsWith(extension)) + { + callSaver(fd.selectedFiles().first().append('.').append(extension), "LocalFunction"); + } + else + { + callSaver(fd.selectedFiles().first(), "LocalFunction"); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |