|
From: <dhu...@us...> - 2007-02-09 13:17:01
|
Revision: 299
http://svn.sourceforge.net/qcell/?rev=299&view=rev
Author: dhubleizh
Date: 2007-02-09 05:16:59 -0800 (Fri, 09 Feb 2007)
Log Message:
-----------
- supported Import function in menu
- make import call parsers, like LIF
Modified Paths:
--------------
trunk/qcell/parsers/parsers.pro
trunk/qcell/visgui/MainWindow.cpp
trunk/qcell/visgui/MainWindow.h
trunk/qcell/visgui/MainWindow.ui
trunk/qcell/visgui/main.cpp
trunk/qcell/visgui/visgui.pro
Modified: trunk/qcell/parsers/parsers.pro
===================================================================
--- trunk/qcell/parsers/parsers.pro 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/parsers/parsers.pro 2007-02-09 13:16:59 UTC (rev 299)
@@ -5,4 +5,5 @@
REAK \
LTFL \
ZIFW \
- ZIFWP
+ ZIFWP \
+ Life-1.05
Modified: trunk/qcell/visgui/MainWindow.cpp
===================================================================
--- trunk/qcell/visgui/MainWindow.cpp 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/visgui/MainWindow.cpp 2007-02-09 13:16:59 UTC (rev 299)
@@ -262,6 +262,14 @@
world_parsers[extension] = iParser;
}
}
+ if (type == "Import")
+ {
+ file_types = iParser->fileTypes("Import");
+ foreach(QString extension, file_types)
+ {
+ import_parsers[extension] = iParser;
+ }
+ }
}
}
}
@@ -529,6 +537,69 @@
setupWorld();
}
+ else if (type == "Import")
+ {
+ if (!import_parsers.contains(subtype))
+ {
+ qDebug(tr("The file extensions %1 isn't supported.")
+ .arg(subtype)
+ .toAscii()
+ );
+ return;
+ }
+
+ // Not every file will provide all the elements of CA, so let's warn the user
+ QString warning;
+
+ // Try to parse Neighbourhood
+ neighbourhood = new Neighbourhood;
+ if (neighbourhood->fromXmlString(&neighbourhood_parsers[subtype]->parse(file_content, "Neighbourhood", subtype)))
+ {
+ setupNeighbourhood();
+ }
+ else
+ {
+ warning.append(tr("The imported file didn't contain Neighbourhood specification.\n"));
+ delete neighbourhood;
+ }
+
+ // Try to parse LocalFunction
+ local_function = new LocalFunction();
+ if (local_function->fromXmlString(&function_parsers[subtype]->parse(file_content, "LocalFunction", subtype)))
+ {
+ setupLocalFunction();
+ }
+ else
+ {
+ warning.append(tr("The imported file didn't contain LocalFunction specification.\n"));
+ delete local_function;
+ }
+
+ // And try to parse the World
+ CalculationData *tempCD = new CalculationData();
+ if(tempCD->setFromXmlString(&world_parsers[subtype]->parse(file_content, "World", subtype)))
+ {
+ data.clear();
+ data.append(tempCD);
+
+ setupWorld();
+ }
+ else
+ {
+ warning.append(tr("The imported file didn't contain World specification."));
+ delete tempCD;
+ }
+
+ if ((neighbourhood == NULL) || (local_function == NULL) || (tempCD == NULL))
+ {
+ qDebug(warning.toAscii());
+ }
+ else if ((neighbourhood == NULL) && (local_function == NULL) && (tempCD == NULL))
+ {
+ qCritical(warning.toAscii());
+ return;
+ }
+ }
else
{
qDebug(tr("Unsupported file type to parse.").toAscii());
@@ -1007,6 +1078,55 @@
}
}
+void MainWindow::on_action_Import_activated()
+{
+ if(import_parsers.count() == 0)
+ {
+ QMessageBox::warning(
+ /*parent*/ this,
+ /*title*/ tr("Plugins warning"),
+ /*message*/ tr("There are no plugins loaded to handle importing.")
+ );
+
+ return;
+
+ }
+
+ QFileDialog fd(
+ /*parent*/ this,
+ /*cation*/ tr("Import"),
+ /*dir*/ "."
+ );
+
+ fd.setFileMode(QFileDialog::ExistingFile);
+
+ QStringList filters;
+ QString default_filter(tr("Supported files"));
+ default_filter.append(" (");
+ QString filter;
+ // Add filter in format %{name} files (*.%{name})
+ foreach(QString key, import_parsers.keys())
+ {
+ // Don't shorten this, as it is made for translations
+ // purposes
+ default_filter.append("*." + key + ' ');
+ filter = key + " " + tr("files") + " (*." + key + ")";
+ filters << filter;
+ }
+ default_filter.append(')');
+ filters.prepend(default_filter);
+ fd.setFilters(filters);
+
+ if(fd.exec())
+ {
+ if(!fd.selectedFiles().isEmpty())
+ {
+ callParser(fd.selectedFiles().first(), "Import");
+ }
+
+ }
+}
+
QByteArray MainWindow::serialize()
{
QDomDocument doc;
@@ -1344,3 +1464,4 @@
action_World_save->setEnabled(true);
}
+
Modified: trunk/qcell/visgui/MainWindow.h
===================================================================
--- trunk/qcell/visgui/MainWindow.h 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/visgui/MainWindow.h 2007-02-09 13:16:59 UTC (rev 299)
@@ -56,6 +56,7 @@
void on_action_Neighbourhood_activated();
void on_action_Function_activated();
void on_action_World_activated();
+ void on_action_Import_activated();
void on_action_World_save_activated();
void on_action_Neighbourhood_save_activated();
@@ -90,6 +91,7 @@
QMap<QString, ParserInterface*> neighbourhood_parsers;
QMap<QString, ParserInterface*> function_parsers;
QMap<QString, ParserInterface*> world_parsers;
+ QMap<QString, ParserInterface*> import_parsers;
void callParser(QString filename, QString type);
void callSaver(const QString filename, const QString type);
Modified: trunk/qcell/visgui/MainWindow.ui
===================================================================
--- trunk/qcell/visgui/MainWindow.ui 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/visgui/MainWindow.ui 2007-02-09 13:16:59 UTC (rev 299)
@@ -101,6 +101,7 @@
<addaction name="menu_Open" />
<addaction name="action_Open_experiment" />
<addaction name="action_Continue_experiment" />
+ <addaction name="action_Import" />
<addaction name="menu_Save" />
<addaction name="action_Save_experiment" />
<addaction name="separator" />
@@ -322,6 +323,17 @@
<string>&Function</string>
</property>
</action>
+ <action name="action_Import" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="text" >
+ <string>&Import</string>
+ </property>
+ <property name="statusTip" >
+ <string>Imports experiments from other programs.</string>
+ </property>
+ </action>
</widget>
<resources/>
<connections/>
Modified: trunk/qcell/visgui/main.cpp
===================================================================
--- trunk/qcell/visgui/main.cpp 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/visgui/main.cpp 2007-02-09 13:16:59 UTC (rev 299)
@@ -16,6 +16,7 @@
Q_IMPORT_PLUGIN(LTFLFileParser);
Q_IMPORT_PLUGIN(ZIFWFileParser);
//Q_IMPORT_PLUGIN(ZIFWPFileParser);
+Q_IMPORT_PLUGIN(Life105FileParser);
/**
* @brief Displays all debug messages in GUI
Modified: trunk/qcell/visgui/visgui.pro
===================================================================
--- trunk/qcell/visgui/visgui.pro 2007-02-09 13:16:03 UTC (rev 298)
+++ trunk/qcell/visgui/visgui.pro 2007-02-09 13:16:59 UTC (rev 299)
@@ -71,7 +71,7 @@
../basesources/functiontable.cpp \
../basesources/neigborhoodtools.cpp
-LIBS = -L../libs -lN -lFQT -lKI -lREAK -lLTFL -lZIFW -lZIFWP
+LIBS = -L../libs -lN -lFQT -lKI -lREAK -lLTFL -lZIFW -lZIFWP -lLife105
TRANSLATIONS = visgui_pl.ts
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|