All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Protected Attributes
GeopsyCore::GeopsyCoreEngine Class Reference

#include <GeopsyCoreEngine.h>

Inheritance diagram for GeopsyCore::GeopsyCoreEngine:
QGpCoreTools::GlobalObject GeopsyGui::GeopsyGuiEngine Engine

List of all members.

Public Member Functions

virtual SignalFileFormat askLoadFormat (const QString &signalFileName)
virtual bool askRD3LogParameter (int &nSamples, double &sampFreq, double &t0)
virtual bool askTimeReference (double &t0, QDateTime &timeRef, const QDateTime &timeTrue)
Cachecache ()
void clear ()
SignalDBcurrentDB ()
CustomFileFormatscustomFileFormats ()
SignalDBdatabase (QString path)
SignalFilefile (QString fileName)
 GeopsyCoreEngine (bool debug=false)
virtual void increaseProgressValue (int val=1)
SubSignalPool load (QString fileName, SignalFileFormat format=SignalFileFormat::Unknown, bool viewFile=false)
SubSignalPool load (QStringList fileNames, SignalFileFormat format=SignalFileFormat::Unknown, bool viewFiles=false)
GeopsyPluginsplugins ()
GeopsyPreferencespreferences ()
virtual int progressMaximum ()
virtual int progressValue ()
void setConsoleProgress (bool s)
virtual void setProgressMaximum (int val)
virtual void setProgressValue (int val)
virtual void showLoadedSignals (const SubSignalPool &)
virtual void showMessage (QString s)
void showSignal (const DoubleSignal *sig, const QString &name=QString::null, const QString &comments=QString::null)
void showSignal (const KeepSignal *sig, const QString &name=QString::null, const QString &comments=QString::null)
virtual bool useProgress ()
virtual ~GeopsyCoreEngine ()

Protected Attributes

Cache_cache
SignalDB_currentDB
CustomFileFormats_customFileFormats
QList< SignalDB * > _databases
GeopsyPlugins_plugins
GeopsyPreferences_preferences
ConsoleProgress_progress

Constructor & Destructor Documentation

References _cache, _currentDB, _customFileFormats, _databases, _plugins, _preferences, _progress, GeopsyCore::GeopsyPreferences::cacheSize(), GeopsyCore::GeopsyPreferences::cacheSwapDir(), GeopsyCore::geopsyCore, GeopsyCore::GeopsyPlugins::polish(), QGpCoreTools::Cache::setSize(), QGpCoreTools::Cache::setSwapDir(), and TRACE.

{
  TRACE;
  // Make sure geopsyCore is NULL, stop if two GeopsyCoreEngine objects are created
  ASSERT(!geopsyCore);
  geopsyCore=this;

  _progress=0;
  _plugins=0;
  _preferences=0;
  _cache=0;
  _currentDB=0;
#ifndef NO_FFT
  new DFFTPack;
#endif

  _customFileFormats=new CustomFileFormats;
  // Plugins required before preferences
  _plugins=new GeopsyPlugins(debug);
  _preferences=new GeopsyPreferences;
  // Cache requires preferences
  _cache=new Cache;
  _cache->setSize(_preferences->cacheSize());
  _cache->setSwapDir(_preferences->cacheSwapDir());

  _currentDB=new SignalDB;  // create default database
  _databases.append(_currentDB);

  _plugins->polish(); // post initialization of plugins
}

Member Function Documentation

SignalFileFormat GeopsyCore::GeopsyCoreEngine::askLoadFormat ( const QString &  signalFileName) [virtual]

Ask for file format through terminal

The value returned is the same as the one returned by the GUI implementation (see Combo Box order!)

This function re-implemented in GeopsyCoreEngineGui with a dialog box

Reimplemented in GeopsyGui::GeopsyGuiEngine.

References QGpCoreTools::endl(), QGpCoreTools::flush(), format, GeopsyCore::SignalFileFormat::importList(), and QGpCoreTools::tr().

Referenced by load().

{
  // Build the list of possible formats (alphabetically sorted)
  QList< QPair<QString, SignalFileFormat> > formats=SignalFileFormat::importList();

  QTextStream mesg(stdout);
  QTextStream rep(stdin);
  QSettings reg;
  reg.beginGroup("DialogOptions");
  reg.beginGroup("LoadFormat");
  int formatIndex=reg.value("fileFormat").toInt();
  if(formatIndex>=formats.count() || formatIndex<0) formatIndex=0;
  SignalFileFormat format=formats.at(formatIndex).second;
  if(reg.value("again").toBool()) {
    CoreApplication::instance()->debugUserInterrupts(false);
    mesg << tr("File Format ") << endl;
    mesg << tr("Possible file formats:\n") << endl;
    for(int i=0; i<formats.count(); i++) {
      mesg << QString("%1.  ").arg(i) << formats.at(i).first << endl;
    }
    mesg << tr("File format (0...%1)? [default=%2] ").arg(formats.count()-1).arg(formatIndex) << flush;
    bool ok;
    int formatIndex=rep.readLine().toInt(&ok);
    if(ok) {
      if(formatIndex>=formats.count() || formatIndex<0) formatIndex=0;
      reg.setValue("fileFormat", formatIndex);
      format=formats.at(formatIndex).second;
      mesg << tr("Ask for file format next time? [y]/n ") << flush;
      if(rep.readLine().toLower()=="n") {
        reg.setValue("again", false);
      }
    }
    CoreApplication::instance()->debugUserInterrupts(true);
  }
  return format;
}
bool GeopsyCore::GeopsyCoreEngine::askRD3LogParameter ( int &  nSamples,
double &  sampFreq,
double &  t0 
) [virtual]

Reimplemented in GeopsyGui::GeopsyGuiEngine.

References QGpCoreTools::endl(), QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  CoreApplication::instance()->debugUserInterrupts(false);
  QTextStream mesg(stdout);
  QTextStream rep(stdin);
  QSettings reg;
  reg.beginGroup("DialogOptions");
  reg.beginGroup("RD3LogParameter");
  mesg << tr("RD3 Default log parameters") << endl;
  bool ok;

  int defI=reg.value("numSamp", 1024).toInt();
  mesg << tr("Number of samples ? [default=%1] ").arg(defI) << endl;
  int repI=rep.readLine().toInt(&ok);
  if(ok) {
    nSamples=repI;
    reg.setValue( "numSamp", repI);
  }

  double defD=reg.value("sampFreq", 578).toDouble();
  mesg << tr("Sampling frequency ? [default=%1] ").arg(defD) << endl;
  double repD=rep.readLine().toDouble(&ok);
  if(ok) {
    sampFreq=repD;
    reg.setValue("sampFreq", repD);
  }

  defD=reg.value("t0", 1024).toInt();
  mesg << tr("T0 ? [default=%1] ").arg(defD) << endl;
  repD=rep.readLine().toDouble(&ok);
  if(ok) {
    t0=repD;
    reg.setValue("t0", repD);
  }
  CoreApplication::instance()->debugUserInterrupts(true);
  return true;
}
bool GeopsyCore::GeopsyCoreEngine::askTimeReference ( double &  t0,
QDateTime &  timeRef,
const QDateTime &  timeTrue 
) [virtual]

Reimplemented in GeopsyGui::GeopsyGuiEngine.

References QGpCoreTools::endl(), QGpCoreTools::flush(), str, QGpCoreTools::tr(), and TRACE.

Referenced by GeopsyCore::SignalFile::setTimeReference().

{
  TRACE;
  QSettings reg;
  reg.beginGroup("DialogOptions");
  reg.beginGroup("TimeReference");
  QString str;

  timeRef=QDateTime::fromString(reg.value("refDateTime", "01/01/2000 00:00:00").toString(), "dd/MM/yyyy hh:mm:ss");
  if(timeTrue.isValid()) {
    t0+=(double)timeRef.secsTo(timeTrue);
  }

  if(reg.value( "again" ).toBool()) {
    CoreApplication::instance()->debugUserInterrupts(false);
    QTextStream mesg(stdout);
    QTextStream rep(stdin);
    mesg << tr("Setting Time Reference") << endl;
    mesg << tr("You are about to open a signal file containning date and time information.") << endl;
    if(timeTrue.isValid()) {
      str=timeTrue.toString("dd/MM/yyyy hh:mm:ss");
    } else str=tr("###");
    mesg << tr("The initial time of your signal is %1" ).arg(str) << endl;
    mesg << tr("To compare different signals recorded at the same time it is necessary to choose a common time reference (e.g. 1 per day).") << endl;
    mesg << tr("Time reference (dd/MM/yyyy hh:mm:ss)? [default=%1] ").arg(timeRef.toString("dd/MM/yyyy hh:mm:ss")) << flush;
    QDateTime repTimeRef;
    str=rep.readLine();
    if(str.isEmpty()) repTimeRef=timeRef;
    else repTimeRef=QDateTime::fromString(str, "dd/MM/yyyy hh:mm:ss");
    if(timeTrue.isValid() && repTimeRef.isValid()) {
      reg.setValue( "refDateTime", repTimeRef.toString("dd/MM/yyyy hh:mm:ss"));
      t0 += (double) repTimeRef.secsTo(timeTrue);
      str=QString::number(t0);
      timeRef=repTimeRef;
    } else {
      str=tr("###");
    }
    mesg << tr("Calculated t0=%1").arg(str) << endl;
    mesg << tr("Ask for time reference next time? [y]/n ") << flush;
    if(rep.readLine().toLower()=="n") {
      reg.setValue("again", false);
    }
    CoreApplication::instance()->debugUserInterrupts(true);
  }
  return true;
}

Clears all databases

References _databases, and TRACE.

Referenced by TitanProcess::fileCreated(), and Process::run().

{
  TRACE;
  for(QList<SignalDB *>::iterator it=_databases.begin(); it!=_databases.end(); it++) {
    (*it)->clear();
  }
}

Returns the database living in file name. If none is found in already open databases, it tried to open if from disk.

References _databases, GeopsyCore::SignalDB::open(), QGpCoreTools::tr(), and TRACE.

Referenced by GeopsyCore::XMLSignal::xml_setProperty().

{
  TRACE;
  // Before searching for an already open database we must make sure that its path was translated or not
  // Before 20120613, this check was after searching all open database leading to multiple re-opening of
  // databases with translated paths.
  QFileInfo fi(name);
  if (!fi.exists()) {
    name=CoreApplication::instance()->translatePath(name, tr("Opening GeopsyCoreBase database ..."),
                                                          tr("geopsy database (%1)"));
    if(name.isEmpty()) return 0;
    fi.setFile(name);
    if(!fi.exists()) return 0;
  }
  for(QList<SignalDB *>::iterator it=_databases.begin(); it!=_databases.end(); ++it) {
    if(name==(*it)->name()) return *it;
  }
  // The requested database is not opened, so try to find it
  SignalDB * db=new SignalDB;

  if(db->open(fi.absoluteFilePath())) {
    _databases.append(db);
    return db;
  } else {
    delete db;
    return 0;
  }
}

Return the file pointer corresponding to fileName. The current database is first searched. In case of multiple matches, the first one is returned.

References _databases, currentDB(), GeopsyCore::SignalDB::filePool(), GeopsyCore::SignalFilePool::find(), and TRACE.

{
  TRACE;
  SignalFile * f;
  if(currentDB()) {
    f=currentDB()->filePool().find(fileName);
    if(f) return f;
  }
  for(QList<SignalDB *>::iterator it=_databases.begin();it==_databases.end();++it) {
    SignalFile * f=( *it)->filePool().find(fileName);
    if(f) return f;
  }
  return 0;
}
virtual void GeopsyCore::GeopsyCoreEngine::increaseProgressValue ( int  val = 1) [inline, virtual]

Reimplemented in Engine.

SubSignalPool GeopsyCore::GeopsyCoreEngine::load ( QString  fileName,
SignalFileFormat  format = SignalFileFormat::Unknown,
bool  viewFile = false 
)

Overloaded function for convenience, load only one signal file

References TRACE.

Referenced by GeopsyMainWindow::dropEvent(), GeopsyMainWindow::load(), GeopsyMainWindow::loadFilePattern(), loadSignals(), Station::raw(), and Process::run().

{
  TRACE;
  QFileInfo fi(fileName);
  QStringList fileList;
  fileList.append(fi.absoluteFilePath());
  return load(fileList, format, viewFile);
}
SubSignalPool GeopsyCore::GeopsyCoreEngine::load ( QStringList  fileNames,
SignalFileFormat  format = SignalFileFormat::Unknown,
bool  viewFiles = false 
)

Import signal files into current database

References GeopsyCore::SubSignalPool::addFile(), GeopsyCore::GeopsyPreferences::askForFormat(), askLoadFormat(), currentDB(), QGpCoreTools::endl(), GeopsyCore::GeopsyPreferences::fileFormat(), GeopsyCore::SignalDB::filePool(), GeopsyCore::geopsyCore, GeopsyCore::SignalFileFormat::id(), GeopsyCore::SubSignalPool::isEmpty(), GeopsyCore::SignalFilePool::last(), GeopsyCore::SignalFilePool::load(), GeopsyCore::GeopsyPreferences::maxNofFiles(), GeopsyCore::GeopsyPreferences::oneWindowPerFile(), preferences(), setProgressMaximum(), setProgressValue(), showLoadedSignals(), QGpCoreTools::tr(), TRACE, GeopsyCore::SignalFileFormat::Unknown, and GeopsyCore::GeopsyPreferences::viewIfFewFiles().

{
  TRACE;
  if(fileNames.isEmpty()) {
    QSettings * reg=new QSettings;
    reg->beginGroup("DialogOptions");
    if(preferences()->askForFormat()) {
      reg->setValue("LoadFormat/again", (bool) true);
    }
    reg->setValue("TimeReference/again", (bool) true);
    delete reg;
    fileNames=Message::getOpenFileNames(tr("Load Signals"), tr("Signal file (*)"));
  }

  SubSignalPool subPool;
  if(!fileNames.isEmpty()) {
    fileNames=File::expand(fileNames);
    if(format.id()==SignalFileFormat::Unknown && !preferences()->askForFormat()) {
      format=preferences()->fileFormat();
    }
    SignalFilePool& fpool=geopsyCore->currentDB()->filePool();
    fileNames.sort();
    bool retLoad=false;
    if(viewFiles) {
      viewFiles=!preferences()->viewIfFewFiles() ||
                  (preferences()->viewIfFewFiles() &&
                    (int) fileNames.count() < preferences() ->maxNofFiles());
    }
    setProgressMaximum(fileNames.count()-1);
    int iProgress=0;
    for(QStringList::Iterator it=fileNames.begin();it!=fileNames.end();++it) {
      setProgressValue(iProgress++);
      if(preferences()->askForFormat()) format=askLoadFormat(*it);
      retLoad=fpool.load( *it, format);
      if(retLoad) {
        App::stream() << *it << endl;
        subPool.addFile(fpool.last());
        if(viewFiles && preferences()->oneWindowPerFile()) {
          SubSignalPool subPool;
          subPool.addFile(fpool.last());
          showLoadedSignals(subPool);
        }
      }
    }
    if(viewFiles && !preferences()->oneWindowPerFile() && !subPool.isEmpty()) {
      showLoadedSignals(subPool);
    }
  }
  return subPool;
}

Referenced by ToolFactory::ToolFactory().

{return _plugins;}
virtual int GeopsyCore::GeopsyCoreEngine::progressMaximum ( ) [inline, virtual]

Reimplemented in Engine.

{if(_progress) return _progress->maximum(); else return 0;}
virtual int GeopsyCore::GeopsyCoreEngine::progressValue ( ) [inline, virtual]

Reimplemented in Engine.

{if(_progress) return _progress->value(); else return 0;}

References _progress, QGpCoreTools::ConsoleProgress::begin(), and TRACE.

Referenced by modeExport(), and modeTool().

{
  TRACE;
  if(s) {
    if(!_progress) {
      _progress=new ConsoleProgress;
      _progress->begin();
    }
  } else {
    delete _progress;
    _progress=0;
  }
}
virtual void GeopsyCore::GeopsyCoreEngine::setProgressValue ( int  val) [inline, virtual]
virtual void GeopsyCore::GeopsyCoreEngine::showLoadedSignals ( const SubSignalPool ) [inline, virtual]

Reimplemented in Engine.

Referenced by load(), loadSignals(), and GeopsyGui::CityLoader::on_loadBut_clicked().

{}
void GeopsyCore::GeopsyCoreEngine::showMessage ( QString  s) [virtual]
void GeopsyCore::GeopsyCoreEngine::showSignal ( const DoubleSignal sig,
const QString &  name = QString::null,
const QString &  comments = QString::null 
)

Mainly used for debug to display an internal signal. A copy of sig is made and added to current database

References _currentDB, GeopsyCore::DoubleSignal::deltaT(), GeopsyCore::SignalTemplate< sampleType >::nSamples(), GeopsyCore::Signal::setComments(), GeopsyCore::Signal::setDeltaT(), GeopsyCore::Signal::setName(), GeopsyCore::Signal::setNSamples(), GeopsyCore::DoubleSignal::setType(), TRACE, and GeopsyCore::DoubleSignal::type().

{
  TRACE;
  Signal * gsig=new Signal(_currentDB);
  gsig->setNSamples(sig->nSamples());
  gsig->setType(sig->type());
  gsig->setDeltaT(sig->deltaT());
  gsig->DoubleSignal::copySamplesFrom(sig);
  gsig->setName(name);
  gsig->setComments(comments);
}
void GeopsyCore::GeopsyCoreEngine::showSignal ( const KeepSignal sig,
const QString &  name = QString::null,
const QString &  comments = QString::null 
)

Mainly used for debug to display an internal signal. A copy of sig is made and added to current database

References _currentDB, CONST_LOCK_SAMPLES, GeopsyCore::KeepSignal::deltaT(), LOCK_SAMPLES, GeopsyCore::SignalTemplate< sampleType >::nSamples(), GeopsyCore::Signal::setComments(), GeopsyCore::Signal::setDeltaT(), GeopsyCore::Signal::setName(), GeopsyCore::Signal::setNSamples(), GeopsyCore::Signal::setT0(), GeopsyCore::DoubleSignal::setType(), GeopsyCore::KeepSignal::t0(), TRACE, UNLOCK_SAMPLES, and GeopsyCore::DoubleSignal::Waveform.

{
  TRACE;
  Signal * gsig=new Signal(_currentDB);
  gsig->setNSamples(sig->nSamples());
  gsig->setDeltaT(sig->deltaT());
  gsig->setType(Signal::Waveform);
  gsig->setT0(sig->t0());
  LOCK_SAMPLES(double, gsigSamples, gsig)
    CONST_LOCK_SAMPLES(int, sigSamples, sig)
      int n=sig->nSamples();
      for(int i=0; i<n; i++) {
        gsigSamples[i]=sigSamples[i];
      }
    UNLOCK_SAMPLES(sig)
  UNLOCK_SAMPLES(gsig)
  gsig->setName(name);
  gsig->setComments(comments);
}
virtual bool GeopsyCore::GeopsyCoreEngine::useProgress ( ) [inline, virtual]

Reimplemented in Engine.

{return _progress;}

Member Data Documentation

Referenced by GeopsyCoreEngine(), and showSignal().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines