#include <QDir>#include <QDesktopWidget>#include <QFileDialog>#include <QSettings>#include <GeopsyCore.h>#include <GeopsyGui.h>#include <QGpGuiTools.h>#include "GeopsyMainWindow.h"#include "Engine.h"#include "ToolFactory.h"#include "FFTW.h"#include "GeopsyAbout.h"#include "geopsyVersion.h"#include "geopsyInstallPath.h"Functions | |
| bool | checkRemainingArguments (int argc, char **argv) |
| SignalFileFormat | getExportFormat (QString fStr) |
| SignalFileFormat | getImportFormat (QString fStr) |
| ApplicationHelp * | help () |
| bool | listExportFormats () |
| bool | listImportFormats () |
| void | loadSignals (int &argc, char **argv) |
| SubSignalPool | loadSignals (bool viewFiles) |
| int | main (int argc, char **argv) |
| int | modeExport (int argc, char **argv, QString exportFile) |
| int | modeGroupList (int argc, char **argv) |
| int | modeGui (int argc, char **argv, bool seedlinkView) |
| int | modeTool (int argc, char **argv, QString toolName) |
| int | modeWaveform (int argc, char **argv, QString exportFile) |
| PACKAGE_INFO (geopsy, GEOPSY) | |
| int | showGroups () |
Variables | |
| QString | database |
| bool | debugStream = false |
| QString | format |
| QString | groupName |
| QByteArray | serverAddress = "localhost" |
| qint16 | serverPort = 18000 |
| QStringList | signalFiles |
| QString | streamSelection |
| bool checkRemainingArguments | ( | int | argc, |
| char ** | argv | ||
| ) |
| SignalFileFormat getExportFormat | ( | QString | fStr | ) |
References QGpCoreTools::endl(), format, GeopsyCore::SignalFileFormat::id(), GeopsyCore::SignalFileFormat::isReadOnly(), and QGpCoreTools::tr().
Referenced by modeExport().
{
SignalFileFormat format=SignalFileFormat::fromString(fStr);
if(format.id()==SignalFileFormat::Unknown) {
App::stream() << tr("geopsy: unknown file format %1").arg(fStr) << endl;
exit(2);
} else if(format.isReadOnly()) {
App::stream() << tr("geopsy: file format %1 is not supported for export.").arg(fStr) << endl;
exit(2);
}
return format;
}
| SignalFileFormat getImportFormat | ( | QString | fStr | ) |
References QGpCoreTools::endl(), format, GeopsyCore::SignalFileFormat::id(), and QGpCoreTools::tr().
Referenced by loadSignals().
| ApplicationHelp* help | ( | ) |
| bool listExportFormats | ( | ) |
References GeopsyCore::GeopsyCoreEngine::customFileFormats(), format, GeopsyCore::geopsyCore, GeopsyCore::SignalFileFormat::isReadOnly(), GeopsyCore::CustomFileFormats::list(), GeopsyCore::SignalFileFormat::toString(), and TRACE.
Referenced by main().
{
TRACE;
GeopsyCoreEngine gp; // Get access to formats defined by plugins
QStringList formats;
for(int i=1; i<SignalFileFormat::FormatCount; i++) {
SignalFileFormat format((SignalFileFormat::Format)i);
if(!format.isReadOnly()) {
formats << format.toString();
}
}
QList<SignalFileFormat> customList= geopsyCore->customFileFormats()->list();
for(QList<SignalFileFormat>::iterator it=customList.begin(); it!=customList.end(); it++) {
SignalFileFormat& format=*it;
if(!format.isReadOnly()) {
formats.append(format.toString());
}
}
qSort(formats);
printf( "# File formats Geopsy can export:\n");
int n=formats.count();
for(int i=0;i<n;i++) {
printf( " %s\n",formats.at(i).toAscii().data());
}
return 0;
}
| bool listImportFormats | ( | ) |
References GeopsyCore::GeopsyCoreEngine::customFileFormats(), format, GeopsyCore::geopsyCore, GeopsyCore::CustomFileFormats::list(), GeopsyCore::SignalFileFormat::toString(), and TRACE.
Referenced by main().
{
TRACE;
GeopsyCoreEngine gp; // Get access to formats defined by plugins
QStringList formats;
for(int i=1; i<SignalFileFormat::FormatCount; i++) {
formats << SignalFileFormat((SignalFileFormat::Format)i).toString();
}
QList<SignalFileFormat> customList= geopsyCore->customFileFormats()->list();
for(QList<SignalFileFormat>::iterator it=customList.begin(); it!=customList.end(); it++) {
SignalFileFormat& format=*it;
formats.append(format.toString());
}
qSort(formats);
formats.prepend("Automatic");
printf( "# File formats Geopsy can import:\n");
int n=formats.count();
for(int i=0;i<n;i++) {
printf( " %s\n",formats.at(i).toAscii().data());
}
return 0;
}
| void loadSignals | ( | int & | argc, |
| char ** | argv | ||
| ) |
Must be called after all other option parsing. Only non-option arguments are extracted.
References signalFiles.
Referenced by modeExport(), modeGui(), modeTool(), and modeWaveform().
{
// Get file list from non-option arguments
int j=1;
for(int i=1;i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]!='-') {
signalFiles.append(argv[i] );
} else if(arg=="--") {
for(i++;i<argc; i++) {
argv[j++]=argv[i];
}
break;
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
}
| SubSignalPool loadSignals | ( | bool | viewFiles | ) |
References GeopsyCore::GeopsyCoreEngine::currentDB(), database, QGpCoreTools::endl(), GeopsyCore::SignalDB::findGroup(), format, GeopsyCore::geopsyCore, getImportFormat(), group(), groupName, GeopsyCore::SubSignalPool::isEmpty(), GeopsyCore::GeopsyCoreEngine::load(), GeopsyCore::SignalDB::open(), GeopsyCore::GeopsyCoreEngine::showLoadedSignals(), signalFiles, GeopsyCore::AbstractSignalGroup::subPool(), and QGpCoreTools::tr().
{
SubSignalPool subPool;
if(!database.isEmpty()) {
SignalDB * db=geopsyCore->currentDB();
db->open(database);
if(!groupName.isEmpty()) {
AbstractSignalGroup * group=db->findGroup(groupName);
if(!group) {
App::stream() << tr("geopsy: unknown group of signals (%1), see -groups").arg(groupName) << endl;
exit(2);
}
subPool=group->subPool();
if(viewFiles && !subPool.isEmpty()) {
geopsyCore->showLoadedSignals(subPool);
}
}
}
if(!signalFiles.isEmpty()) {
if(subPool.isEmpty()) {
subPool=geopsyCore->load(signalFiles, getImportFormat(format), viewFiles);
} else {
geopsyCore->load(signalFiles, getImportFormat(format), viewFiles);
}
}
return subPool;
}
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
References database, debugStream, QGpCoreTools::endl(), format, groupName, help(), listExportFormats(), listImportFormats(), mode, modeExport(), modeGroupList(), modeGui(), modeTool(), modeWaveform(), serverAddress, serverPort, QGpGuiTools::Application::setConsoleMessage(), QGpCoreTools::CoreApplicationPrivate::showHelp(), signalFiles, streamSelection, and QGpCoreTools::tr().
{
Application a(argc, argv, 0); // help delayed as it needs fully constructed QApplication to show tool helps
a.setConsoleMessage();
// Basic options: selection of the main modes and short returning options
enum Mode {Gui, Tool, Export, Waveform, GroupList, SeedlinkView};
Mode mode=Gui;
QString toolName, exportFile, waveformFile;
int j=1;
for(int i=1; i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]=='-') {
if(arg=="-help" || arg=="--help" || arg=="-h") { // help delayed as it needs fully constructed QApplication to show tool helps
a.showHelp(i, argc, argv, help);
return 0;
} else if(arg=="-db") {
CoreApplication::checkOptionArg(i, argc, argv);
database=argv[i];
} else if(arg=="-file") {
App::stream() << tr("geopsy: option '-file' is obsolete, files to import are specified without option, see -help.") << endl;
CoreApplication::checkOptionArg(i, argc, argv);
signalFiles.append(argv[i] );
} else if(arg=="-import-format") {
CoreApplication::checkOptionArg(i, argc, argv);
format=argv[i];
} else if(arg=="-group") {
CoreApplication::checkOptionArg(i, argc, argv);
groupName=argv[i];
} else if(arg=="-tool") {
CoreApplication::checkOptionArg(i, argc, argv);
toolName=argv[i];
mode=Tool;
} else if(arg=="-export") {
CoreApplication::checkOptionArg(i, argc, argv);
exportFile=argv[i];
mode=Export;
} else if(arg=="-waveform") {
CoreApplication::checkOptionArg(i, argc, argv);
waveformFile=argv[i];
mode=Waveform;
} else if(arg=="-groups") {
mode=GroupList;
} else if(arg=="-export-formats") {
return listExportFormats();
} else if(arg=="-import-formats") {
return listImportFormats();
} else if(arg=="-debug-stream") {
debugStream=true;
} else if(arg=="-debug-tools") {
printf("-- Testing available tools --\n");
GeopsyCoreEngine gp(true);
return 0;
} else if(arg=="-clear-tools") {
QSettings reg;
reg.remove( "Plugins" );
} else if(arg=="-add-tool-path") {
CoreApplication::checkOptionArg(i, argc, argv);
QSettings reg;
QStringList paths=reg.value( "Plugins/Paths" ).toStringList();
paths.append(argv[i]);
reg.setValue( "Plugins/Paths", paths);
} else if(arg=="-server") {
CoreApplication::checkOptionArg(i, argc, argv);
mode=SeedlinkView;
serverAddress=argv[i];
} else if(arg=="-port") {
CoreApplication::checkOptionArg(i, argc, argv);
mode=SeedlinkView;
serverPort=atoi(argv[i]);
} else if(arg=="-streams") {
CoreApplication::checkOptionArg(i, argc, argv);
mode=SeedlinkView;
streamSelection=argv[i];
} else {
argv[j++]=argv[i];
}
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
switch(mode) {
case GroupList:
return modeGroupList(argc, argv);
case SeedlinkView:
case Gui:
return modeGui(argc, argv, mode==SeedlinkView);
case Export:
return modeExport(argc, argv, exportFile);
case Waveform:
return modeWaveform(argc, argv, waveformFile);
case Tool:
return modeTool(argc, argv, toolName);
};
return 0;
}
| int modeExport | ( | int | argc, |
| char ** | argv, | ||
| QString | exportFile | ||
| ) |
References checkRemainingArguments(), QGpCoreTools::endl(), getExportFormat(), GeopsyCore::SubSignalPool::isEmpty(), loadSignals(), GeopsyCore::SubSignalPool::save(), GeopsyCore::GeopsyCoreEngine::setConsoleProgress(), and QGpCoreTools::tr().
Referenced by main().
{
// Other options
bool showProgress=false;
bool useOriginalBaseName=false;
int maximumSignalsPerFile=0;
SignalFileFormat exportFormat;
// Check geopsy main arguments
int j=1;
for(int i=1; i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]=='-') {
if(arg=="-export-format") {
CoreApplication::checkOptionArg(i, argc, argv);
exportFormat=getExportFormat(argv[i] );
} else if(arg=="-export-base-name") {
useOriginalBaseName=true;
} else if(arg=="-export-max-signal") {
CoreApplication::checkOptionArg(i, argc, argv);
maximumSignalsPerFile=atoi(argv[i]);
if(maximumSignalsPerFile<1) {
App::stream() << tr("geopsy: maximum number of signals per file must be greater than 0") << endl;
return 2;
}
} else if(arg=="-progress") {
showProgress=true;
} else if(arg=="-format") {
App::stream() << tr("geopsy: option '-format' is obsolete, replace it by '-export-format'") << endl;
CoreApplication::checkOptionArg(i, argc, argv);
exportFormat=getExportFormat(argv[i] );
} else {
argv[j++]=argv[i];
}
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
if(exportFile.isEmpty()) {
App::stream() << tr("geopsy: export file name is empty, see -h") << endl;
return 2;
}
Engine gp;
gp.setConsoleProgress(showProgress);
loadSignals(argc, argv);
SubSignalPool subPool=loadSignals(false);
if(!checkRemainingArguments(argc,argv)) {
return 2;
}
// Check if there are signals
if(subPool.isEmpty()) {
App::stream() << tr("geopsy: no signal available, check options -file, -db or -group, see -h for help") << endl;
return 2;
}
return subPool.save(exportFile, useOriginalBaseName, exportFormat, maximumSignalsPerFile);
}
| int modeGroupList | ( | int | argc, |
| char ** | argv | ||
| ) |
References checkRemainingArguments(), GeopsyCore::GeopsyCoreEngine::currentDB(), database, QGpCoreTools::endl(), GeopsyCore::SignalDB::masterGroup(), GeopsyCore::SignalDB::open(), GeopsyCore::AbstractSignalGroup::printList(), and QGpCoreTools::tr().
Referenced by main().
{
if(!checkRemainingArguments(argc,argv)) {
return 2;
}
GeopsyCoreEngine gp;
if(!database.isEmpty()) {
gp.currentDB()->open(database);
gp.currentDB()->masterGroup()->printList("");
return 0;
} else {
App::stream() << tr("geopsy: no database selected, see -h") << endl;
return 2;
}
}
| int modeGui | ( | int | argc, |
| char ** | argv, | ||
| bool | seedlinkView | ||
| ) |
References checkRemainingArguments(), debugStream, loadSignals(), GeopsyAbout::painted(), GeopsyMainWindow::refreshLists(), GeopsyMainWindow::seedlink(), serverAddress, serverPort, Engine::setMainWindow(), GeopsyMainWindow::startupPreferences(), streamSelection, and w.
{
loadSignals(argc, argv);
if(!checkRemainingArguments(argc,argv)) {
return 2;
}
Application::instance()->setGuiMessage();
SciFigsGlobal s;
// Splash screen with licence
GeopsyAbout * splash=new GeopsyAbout(0, Qt::SplashScreen | Qt::WindowStaysOnTopHint);
splash->setAttribute(Qt::WA_DeleteOnClose);
splash->setAttribute(Qt::WA_PaintOnScreen);
QRect rootRect=QApplication::desktop() ->geometry();
QPoint p=rootRect.center();
splash->move(p.x() - splash->width()/2, p.y() - splash->height()/2);
splash->show();
while( !splash->painted()) {
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
}
qApp->connect(qApp, SIGNAL(aboutToQuit()), splash, SLOT(close()));
// Create engine
Engine gp;
// Create main widget
GeopsyMainWindow* w=new GeopsyMainWindow;
w->setObjectName("geopsy");
Settings::getRect(w, "geopsy");
if(debugStream) {
Application::instance()->setStream(new StandardStream(stdout));
}
gp.setMainWindow(w);
w->show();
w->startupPreferences();
if(seedlinkView) {
w->seedlink(serverAddress, serverPort, streamSelection);
} else {
loadSignals(true);
}
w->refreshLists();
int appReturn=qApp->exec();
Settings::setRect(w, "geopsy");
gp.setMainWindow(0);
delete w;
return appReturn;
}
| int modeTool | ( | int | argc, |
| char ** | argv, | ||
| QString | toolName | ||
| ) |
References checkRemainingArguments(), QGpCoreTools::endl(), ToolFactory::exec(), GeopsyCore::SubSignalPool::isEmpty(), loadSignals(), GeopsyCore::GeopsyCoreEngine::setConsoleProgress(), ToolFactory::tool(), Engine::tools(), and QGpCoreTools::tr().
Referenced by main().
{
// Other options
int toolSlot=0;
bool showProgress=false;
// Check geopsy main arguments
int j=1;
for(int i=1; i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]=='-') {
if(arg=="-slot") {
CoreApplication::checkOptionArg(i, argc, argv);
toolSlot=atoi(argv[i]);
} else if(arg=="-progress") {
showProgress=true;
} else {
argv[j++]=argv[i];
}
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
SciFigsGlobal s;
Engine gp;
new FFTW;
gp.setConsoleProgress(showProgress);
loadSignals(argc, argv);
SubSignalPool subPool=loadSignals(false);
// Check if there are signals
if(subPool.isEmpty()) {
App::stream() << tr("geopsy: no signal available, check options -file, -db or -group, see -h for help") << endl;
return 2;
}
GeopsyGuiInterface * tool=gp.tools()->tool(toolName);
if(!tool) {
App::stream() << tr("geopsy: unknow tool tag (%1), see -h").arg(toolName) << endl;
return 2;
}
CoreApplication::instance()->debugUserInterrupts(false);
int ret=gp.tools()->exec(&subPool, tool, toolSlot, argc, argv);
CoreApplication::instance()->debugUserInterrupts(true);
if(!checkRemainingArguments(argc,argv)) {
return 2;
}
return ret;
}
| int modeWaveform | ( | int | argc, |
| char ** | argv, | ||
| QString | exportFile | ||
| ) |
References checkRemainingArguments(), QGpCoreTools::endl(), GeopsyCore::SubSignalPool::isEmpty(), loadSignals(), GeopsyCore::SignalProcessScript::run(), GeopsyCore::SignalProcess::setCurrentSubPool(), and QGpCoreTools::tr().
Referenced by main().
{
// Other options
bool showProgress=false;
// Check geopsy main arguments
int j=1;
for(int i=1; i<argc; i++) {
QByteArray arg=argv[i];
if(arg[0]=='-') {
if(arg=="-progress") {
showProgress=true;
} else {
argv[j++]=argv[i];
}
} else {
argv[j++]=argv[i];
}
}
if(j < argc) {
argv[j]=0;
argc=j;
}
if(waveformFile.isEmpty()) {
App::stream() << tr("geopsy: waveform script file name is empty, see -h") << endl;
return 2;
}
GeopsyCoreEngine gp;
loadSignals(argc, argv);
SubSignalPool subPool=loadSignals(false);
if(!checkRemainingArguments(argc,argv)) {
return 2;
}
// Check if there are signals
if(subPool.isEmpty()) {
App::stream() << tr("geopsy: no signal available, check options -file, -db or -group, see -h for help") << endl;
return 2;
}
QFile f(waveformFile);
if( ! f.open(QIODevice::ReadOnly) ) {
App::stream() << tr("geopsy: cannot open file %1").arg(waveformFile) << endl;
return 2;
}
SignalProcessScript process;
process.setCurrentSubPool(&subPool);
return process.run(f.readAll()) ? 0 : 2;
}
| PACKAGE_INFO | ( | geopsy | , |
| GEOPSY | |||
| ) |
| int showGroups | ( | ) |
| QString database |
Referenced by loadSignals(), main(), GeopsyCore::SubSignalPool::merge(), and modeGroupList().
| bool debugStream = false |
| QString format |
Referenced by GeopsyGui::GeopsyGuiEngine::askLoadFormat(), GeopsyCore::GeopsyCoreEngine::askLoadFormat(), crft(), GeopsyMainWindow::exportSignal(), getExportFormat(), getImportFormat(), GeopsyCore::SignalFileFormat::importList(), listExportFormats(), listImportFormats(), loadSignals(), main(), QGpCoreTools::DateTimeParser::parse(), pcno3(), psv1d(), rcft(), QGpCoreTools::Matrix< Complex >::toUserString(), writec_ascii1(), writer_ascii1(), and writer_ascii2().
| QString groupName |
Referenced by loadSignals(), and main().
| QByteArray serverAddress = "localhost" |
| qint16 serverPort = 18000 |
Referenced by main(), modeGui(), and GeopsySLinkGui::SeedLinkLoader::setServer().
| QStringList signalFiles |
Referenced by loadSignals(), and main().
| QString streamSelection |