00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef OPTBASE_H
00017 #define OPTBASE_H
00018
00019
00020 #ifdef WIN32
00021 #ifndef WIN32_LEAN_AND_MEAN
00022 #define WIN32_LEAN_AND_MEAN
00023 #endif // WIN32_LEAN_AND_MEAN
00024 #ifndef NOMINMAX
00025 #define NOMINMAX
00026 #endif // NOMINMAX
00027 #endif // WIN32
00028
00029 #include <QtCore/QObject>
00030 #include <QtCore/QMutex>
00031
00032 namespace GlobalSearch {
00033 class Structure;
00034 class Tracker;
00035 class Optimizer;
00036 class QueueManager;
00037 class QueueInterface;
00038 class SSHManager;
00039 class AbstractDialog;
00040
00053 class OptBase : public QObject
00054 {
00055 Q_OBJECT
00056
00057 public:
00063 explicit OptBase(AbstractDialog *parent);
00064
00068 virtual ~OptBase();
00069
00077 enum FailActions {
00079 FA_DoNothing = 0,
00081 FA_KillIt,
00083 FA_Randomize,
00085 FA_NewOffspring
00086 };
00087
00091 QString getIDString() {return m_idString;}
00092
00103 virtual Structure* replaceWithRandom(Structure *s,
00104 const QString & reason = "")
00105 {return 0;}
00106
00119 virtual Structure* replaceWithOffspring(Structure *s,
00120 const QString & reason = "")
00121 {return replaceWithRandom(s, reason);}
00122
00130 virtual bool checkLimits() = 0;
00131
00140 virtual bool checkStepOptimizedStructure(Structure *s, QString *err = NULL)
00141 {
00142 Q_UNUSED(s);
00143 Q_UNUSED(err);
00144 return true;
00145 }
00146
00181 static QList<double> getProbabilityList(const QList<Structure*> &structures);
00182
00193 virtual bool save(const QString & filename = "", bool notify = false);
00194
00198 virtual bool postSave(const QString &filename)
00199 {
00200 Q_UNUSED(filename);
00201 return true;
00202 }
00203
00213 virtual bool load(const QString & filename,
00214 const bool forceReadOnly = false) {
00215 Q_UNUSED(forceReadOnly);return false;};
00216
00230 virtual QString interpretTemplate(const QString & templateString,
00231 Structure* structure);
00232
00236 virtual QString getTemplateKeywordHelp() {
00237 return getTemplateKeywordHelp_base();};
00238
00242 AbstractDialog* dialog() {return m_dialog;};
00243
00247 Tracker* tracker() {return m_tracker;};
00248
00252 QueueManager* queue() {return m_queue;};
00253
00259 QueueInterface* queueInterface() {return m_queueInterface;};
00260
00266 Optimizer* optimizer() {return m_optimizer;};
00267
00271 SSHManager* ssh() {return m_ssh;};
00272
00274 bool limitRunningJobs;
00275
00277 uint runningJobLimit;
00278
00280 uint contStructs;
00281
00283 int cutoff;
00284
00286 bool testingMode;
00287
00289 uint test_nRunsStart;
00290
00292 uint test_nRunsEnd;
00293
00295 uint test_nStructs;
00296
00300 uint failLimit;
00301
00305 FailActions failAction;
00306
00308 QString filePath;
00309
00311 QString description;
00312
00314 QString host;
00315
00317 int port;
00318
00320 QString username;
00321
00324 QString rempath;
00325
00329 QMutex *sOBMutex;
00330
00333 QMutex *stateFileMutex;
00334
00336 QMutex *backTraceMutex;
00337
00339 bool usePreopt;
00340
00342 bool savePending;
00343
00345 bool isStarting;
00346
00348 bool readOnly;
00349
00350 signals:
00360 void startingSession();
00361
00371 void sessionStarted();
00372
00382 void readOnlySessionStarted();
00383
00389 void queueInterfaceChanged(QueueInterface*);
00390
00396 void optimizerChanged(Optimizer*);
00397
00408 void debugStatement(const QString &s);
00409
00420 void warningStatement(const QString &s);
00421
00432 void errorStatement(const QString &s);
00433
00441 void needBoolean(const QString &message, bool *ok);
00442
00452 void needPassword(const QString &message, QString *newPassword, bool *ok);
00453
00460 void refreshAllStructureInfo();
00461
00462
00464 void sig_setClipboard(const QString &text) const;
00466
00467 public slots:
00468
00473 virtual void reset();
00474
00475 #ifdef ENABLE_SSH
00476
00479 virtual bool createSSHConnections();
00480 #endif // ENABLE_SSH
00481
00485 virtual void startSearch() = 0;
00486
00491 virtual void generateNewStructure() {};
00492
00498 virtual void preoptimizeStructure(Structure *s) {}
00499
00511 void debug(const QString & s);
00512
00524 void warning(const QString & s);
00525
00537 void error(const QString & s);
00538
00547 void emitSessionStarted() {emit sessionStarted();};
00548
00557 void emitReadOnlySessionStarted() {emit readOnlySessionStarted();};
00558
00566 void emitStartingSession() {emit startingSession();};
00567
00572 void setIsStartingTrue() {isStarting = true;};
00573
00578 void setIsStartingFalse() {isStarting = false;};
00579
00584 void setReadOnlyTrue() {readOnly = true;};
00585
00590 void setReadOnlyFalse() {readOnly = false;};
00591
00595 void printBackTrace();
00596
00603 void setQueueInterface(QueueInterface *q);
00604
00612 void setOptimizer(Optimizer *o);
00613
00621 void promptForBoolean(const QString &message, bool *ok = 0);
00622
00632 void promptForPassword(const QString &message, QString *newPassword, bool *ok = 0);
00633
00640 void setClipboard(const QString &text) const;
00641
00642 protected slots:
00643
00645 void setClipboard_(const QString &text) const;
00647
00648 #ifdef ENABLE_SSH
00649 #ifndef USE_CLI_SSH
00650
00653 bool createSSHConnections_libssh();
00654
00655 #else // not USE_CLI_SSH
00656
00660 bool createSSHConnections_cli();
00661
00662 #endif // not USE_CLI_SSH
00663 #endif // ENABLE_SSH
00664 protected:
00667 QString m_idString;
00668
00671 SSHManager *m_ssh;
00672
00675 AbstractDialog *m_dialog;
00676
00679 Tracker *m_tracker;
00680
00682 QThread *m_queueThread;
00683
00686 QueueManager *m_queue;
00687
00690 QueueInterface *m_queueInterface;
00691
00696 Optimizer *m_optimizer;
00697
00699 void interpretKeyword_base(QString &keyword, Structure* structure);
00700
00702 QString getTemplateKeywordHelp_base();
00703
00705 unsigned int m_schemaVersion;
00706
00707
00708 bool m_isDestroying;
00709
00710 };
00711
00712 }
00713
00714 #endif