From: <dhu...@us...> - 2007-02-12 09:17:39
|
Revision: 306 http://svn.sourceforge.net/qcell/?rev=306&view=rev Author: dhubleizh Date: 2007-02-12 01:17:38 -0800 (Mon, 12 Feb 2007) Log Message: ----------- - function saving is back and seems to work, even with LIF files Modified Paths: -------------- trunk/qcell/parsers/FQT/FQTParserPlugin.cpp trunk/qcell/visgui/MainWindow.cpp trunk/qcell/visgui/MainWindow.ui Modified: trunk/qcell/parsers/FQT/FQTParserPlugin.cpp =================================================================== --- trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-02-11 21:54:12 UTC (rev 305) +++ trunk/qcell/parsers/FQT/FQTParserPlugin.cpp 2007-02-12 09:17:38 UTC (rev 306) @@ -313,42 +313,81 @@ // Generic type to parse XML request LocalFunction lf; + lf.fromXmlString(&content); // 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()); +// if(!lf.fromXmlString(&content)); +// { +// qDebug(tr("Unable to parse out internal data!").toAscii()); +// +// return QByteArray(); +// } - return QByteArray(); - } - // Header - result.append("FQT"); - result.append('\n'); + result.append("FQT\n"); // Second line // Num of args - result.append(lf.getNumberOfArgs()); + result.append(QString::number(lf.getNumberOfArgs()).toAscii()); result.append(' '); // Num of arg values - result.append(lf.getAlphabetSize()); + result.append(QString::number(lf.getAlphabetSize()).toAscii()); result.append(' '); // Num of return values - result.append(lf.getMaxReturnValues()); - result.append(' '); + result.append(QString::number(lf.getAlphabetSize()).toAscii()); result.append('\n'); // Third line - summed args foreach(int arg, lf.getSummedArguments()) { - result.append(QString::number(arg)[0].toAscii()); + result.append(QString::number(arg+1).toAscii()); result.append(','); } // Get rid of the penging `,' result.chop(1); - result.append('\n'); +// result.append('\n'); - /// @todo Main function writing + /// @todo Get it right next time - this is ugly! + QMap<QString, QString> fqt; + QDomDocument doc; + doc.setContent(content); + QDomElement root = doc.firstChild().toElement(); + 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(); + values_txt.chop(1); + foreach(QString sum_line, values_txt.split(";\n")) + { + QStringList tokens = sum_line.split('='); + QStringList sum_and_free = tokens[0].split('+'); + QString sum = sum_and_free.takeFirst(); + + if (!fqt.contains(sum)) + { + fqt[sum] = QString(num_combinations, fill_value); + } + + index = num_combinations-1; + for (int i = 0; i < sum_and_free.size(); i++) + { + index -= sum_and_free[i].toInt() * (pow(lf.getAlphabetSize(), (free_args - i)) - 1); + } + fqt[sum][index] = tokens[1][0]; + } + + foreach(QString key, fqt.keys()) + { + result.append(QString("%1: %2\n") + .arg(key) + .arg(fqt[key]) + .toAscii() + ); + } + return result; } Modified: trunk/qcell/visgui/MainWindow.cpp =================================================================== --- trunk/qcell/visgui/MainWindow.cpp 2007-02-11 21:54:12 UTC (rev 305) +++ trunk/qcell/visgui/MainWindow.cpp 2007-02-12 09:17:38 UTC (rev 306) @@ -1026,7 +1026,50 @@ void MainWindow::on_action_Function_save_activated() { + if(function_parsers.count() == 0) + { + QMessageBox::warning( + /*parent*/ this, + /*title*/ tr("Plugins warning"), + /*message*/ tr("There are no plugins loaded to handle LocalFunction saving.") + ); + return; + + } + + QFileDialog fd( + /*parent*/ this, + /*cation*/ tr("Save Local Function"), + /*dir*/ "." + ); + + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + + QStringList filters; + QString filter; + // Add filter in format %{name} files (*.%{name}) + foreach(QString key, function_parsers.keys()) + { + // Don't shorten this, as it is made for translations + // purposes + filter = key + " " + tr("files") + " (*." + key + ")"; + filters << filter; + } + fd.setFilters(filters); + fd.setDefaultSuffix("FQT"); + + if(fd.exec()) + { + if(!fd.selectedFiles().isEmpty()) + { + callSaver(fd.selectedFiles().first(), "LocalFunction"); + + } + + } + } void MainWindow::on_action_Save_experiment_activated() @@ -1391,7 +1434,27 @@ NewWorldWizard nww; if (nww.exec()) { - /// @todo emit some signal here + data.clear(); + CalculationData *tmp = new CalculationData(); + + if (nww.spinBox3D->isEnabled()) + { + tmp->resizeData(nww.spinBox1D->value(), nww.spinBox2D->value(), nww.spinBox3D->value()); + } + else if (nww.spinBox2D->isEnabled()) + { + tmp->resizeData(nww.spinBox1D->value(), nww.spinBox2D->value()); + } + else if (nww.spinBox1D->isEnabled()) + { + tmp->resizeData(nww.spinBox1D->value()); + } + + tmp->fillData(0); + data.append(tmp); + + setupWorld(); + unlockExperiment(); } } @@ -1400,7 +1463,9 @@ NewNeighbourhoodWizard nnw; if (nnw.exec()) { - /// @todo emit some signal here + /// @todo Wait for Neighbourhood to be initializable +// neighbourhood = new Neighbourhood N(); + } } Modified: trunk/qcell/visgui/MainWindow.ui =================================================================== --- trunk/qcell/visgui/MainWindow.ui 2007-02-11 21:54:12 UTC (rev 305) +++ trunk/qcell/visgui/MainWindow.ui 2007-02-12 09:17:38 UTC (rev 306) @@ -67,17 +67,6 @@ <property name="title" > <string>&File</string> </property> - <widget class="QMenu" name="menu_Save" > - <property name="enabled" > - <bool>false</bool> - </property> - <property name="title" > - <string>&Save</string> - </property> - <addaction name="action_World_save" /> - <addaction name="action_Neighbourhood_save" /> - <addaction name="action_Function_save" /> - </widget> <widget class="QMenu" name="menu_Open" > <property name="statusTip" > <string>Opens experiment data.</string> @@ -97,6 +86,17 @@ <addaction name="action_New_Neighbourhood" /> <addaction name="action_New_Function" /> </widget> + <widget class="QMenu" name="menu_Save" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="title" > + <string>&Save</string> + </property> + <addaction name="action_World_save" /> + <addaction name="action_Neighbourhood_save" /> + <addaction name="action_Function_save" /> + </widget> <addaction name="menu_New" /> <addaction name="menu_Open" /> <addaction name="action_Open_experiment" /> @@ -289,6 +289,9 @@ <property name="text" > <string>&Function</string> </property> + <property name="visible" > + <bool>true</bool> + </property> </action> <action name="action_Save_experiment" > <property name="enabled" > @@ -318,11 +321,17 @@ <property name="text" > <string>&Neighbourhood</string> </property> + <property name="visible" > + <bool>false</bool> + </property> </action> <action name="action_New_Function" > <property name="text" > <string>&Function</string> </property> + <property name="visible" > + <bool>false</bool> + </property> </action> <action name="action_Import" > <property name="enabled" > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |