| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_MOLEQUEUE_INPUTGENERATORWIDGET_H |
| 7 |
#define AVOGADRO_MOLEQUEUE_INPUTGENERATORWIDGET_H |
| 8 |
|
| 9 |
#include <QtCore/QJsonObject> |
| 10 |
#include <QtWidgets/QWidget> |
| 11 |
|
| 12 |
#include <avogadro/qtgui/jsonwidget.h> |
| 13 |
#include "inputgenerator.h" |
| 14 |
|
| 15 |
class QJsonValue; |
| 16 |
class QTextEdit; |
| 17 |
class QWidget; |
| 18 |
class QFormLayout; |
| 19 |
|
| 20 |
namespace Avogadro { |
| 21 |
namespace QtGui { |
| 22 |
class Molecule; |
| 23 |
} |
| 24 |
|
| 25 |
namespace MoleQueue { |
| 26 |
class JobObject; |
| 27 |
namespace Ui { |
| 28 |
class InputGeneratorWidget; |
| 29 |
} |
| 30 |
class BatchJob; |
| 31 |
/** |
| 32 |
* @class InputGeneratorWidget inputgeneratorwidget.h |
| 33 |
* <avogadro/molequeue/inputgeneratorwidget.h> |
| 34 |
* @brief The InputGeneratorWidget class provides a user interface for |
| 35 |
* configuring, saving, editing, and running input files produced by |
| 36 |
* InputGenerator scripts. |
| 37 |
* @sa InputGenerator InputGeneratorDialog |
| 38 |
* |
| 39 |
* The InputGeneratorWidget creates a GUI to represent the options given by an |
| 40 |
* input generator script, and has some utilities for job submission through |
| 41 |
* MoleQueue. |
| 42 |
* |
| 43 |
* By default, the widget will configure input files for a single molecule, |
| 44 |
* which can be either written to disk or submitted for processing with |
| 45 |
* MoleQueue. |
| 46 |
* |
| 47 |
* By enabling batch mode (setBatchMode()), the current molecule is used to |
| 48 |
* configure a calculation for submission to MoleQueue, and the parameters are |
| 49 |
* saved. These may be used to configure and submit jobs for other molecules. |
| 50 |
*/ |
| 51 |
class AVOGADROMOLEQUEUE_EXPORT InputGeneratorWidget : public QtGui::JsonWidget |
| 52 |
{ |
| 53 |
Q_OBJECT |
| 54 |
|
| 55 |
public: |
| 56 |
/** |
| 57 |
* Construct a widget that dynamically generates a GUI to configure the |
| 58 |
* InputGenerator script specified by scriptFilePath. |
| 59 |
*/ |
| 60 |
explicit InputGeneratorWidget(QWidget* parent_ = nullptr); |
| 61 |
~InputGeneratorWidget() override; |
| 62 |
|
| 63 |
/** |
| 64 |
* Use the input generator script pointed to by scriptFilePath. |
| 65 |
* @param scriptFilePath Absolute path to generator script. |
| 66 |
*/ |
| 67 |
void setInputGeneratorScript(const QString& scriptFilePath); |
| 68 |
|
| 69 |
/** |
| 70 |
* Re-fetch options from the underlying script and rebuild the GUI. |
| 71 |
* Call this after configuring the interpreter (e.g. for package mode). |
| 72 |
*/ |
| 73 |
void reloadOptions(); |
| 74 |
|
| 75 |
/** |
| 76 |
* Access to the underlying input generator object. @{ |
| 77 |
*/ |
| 78 |
InputGenerator& inputGenerator() { return m_inputGenerator; } |
| 79 |
const InputGenerator& inputGenerator() const { return m_inputGenerator; } |
| 80 |
|
| 81 |
/** |
| 82 |
* @return True if the widget is in batch mode. See the class documentation |
| 83 |
* for details. Default is false. |
| 84 |
*/ |
| 85 |
bool batchMode() const { return m_batchMode; } |
| 86 |
|
| 87 |
/** |
| 88 |
* Collect the current calculation parameters and prompt for MoleQueue |
| 89 |
* options. Both option sets are stored in @a batch. |
| 90 |
*/ |
| 91 |
bool configureBatchJob(BatchJob& batch) const; |
| 92 |
|
| 93 |
void setMolecule(QtGui::Molecule* mol) override; |
| 94 |
|
| 95 |
public slots: |
| 96 |
/** |
| 97 |
* Enable/disable 'template mode'. See the class documentation for details. |
| 98 |
* Default is off. |
| 99 |
*/ |
| 100 |
void setBatchMode(bool m); |
| 101 |
|
| 102 |
signals: |
| 103 |
/** |
| 104 |
* @brief closeClicked is emitted when the close button is clicked. |
| 105 |
*/ |
| 106 |
void closeClicked(); |
| 107 |
|
| 108 |
/** |
| 109 |
* Emitted when the user requests that a job's output be loaded in Avogadro. |
| 110 |
*/ |
| 111 |
void openJobOutput(const JobObject& job); |
| 112 |
|
| 113 |
protected: |
| 114 |
/** |
| 115 |
* Reimplemented to update preview text. Hidden dialogs will wait until they |
| 116 |
* are reshown to update the text to prevent overwriting any modified buffers. |
| 117 |
*/ |
| 118 |
void showEvent(QShowEvent* e) override; |
| 119 |
|
| 120 |
void updateOptions() override; |
| 121 |
|
| 122 |
private slots: |
| 123 |
/** |
| 124 |
* Update the input files. This method is throttled, and will only call the |
| 125 |
* generator script once every 250 milliseconds. |
| 126 |
*/ |
| 127 |
void updatePreviewText() override; |
| 128 |
|
| 129 |
/** |
| 130 |
* Immediately update the input files, bypassing (and resetting) the throttle |
| 131 |
* mechanism. |
| 132 |
*/ |
| 133 |
void updatePreviewTextImmediately(); |
| 134 |
|
| 135 |
/** |
| 136 |
* Triggered when the user resets the default values. |
| 137 |
*/ |
| 138 |
void defaultsClicked(); |
| 139 |
|
| 140 |
/** |
| 141 |
* Triggered when the user requests that the files are written to disk. |
| 142 |
*/ |
| 143 |
void generateClicked(); |
| 144 |
|
| 145 |
/** |
| 146 |
* Triggered when the user requests that the simulation is submitted to |
| 147 |
* MoleQueue. |
| 148 |
*/ |
| 149 |
void computeClicked(); |
| 150 |
|
| 151 |
/** |
| 152 |
* Show the user an warning. These are messages returned by the input |
| 153 |
* generator script. |
| 154 |
*/ |
| 155 |
void setWarning(const QString& warn); |
| 156 |
|
| 157 |
/** |
| 158 |
* Toggle the visibility of the warning text. |
| 159 |
*/ |
| 160 |
void toggleWarningText(); |
| 161 |
|
| 162 |
/** |
| 163 |
* Show the warning text. |
| 164 |
*/ |
| 165 |
void showWarningText(); |
| 166 |
|
| 167 |
/** |
| 168 |
* Hide the warning text. |
| 169 |
*/ |
| 170 |
void hideWarningText(); |
| 171 |
|
| 172 |
/** |
| 173 |
* Hide the warning widget. |
| 174 |
*/ |
| 175 |
void resetWarningDisplay(); |
| 176 |
|
| 177 |
/** |
| 178 |
* Show the user an error message. These are errors that have occurred |
| 179 |
* in this extension, not necessarily in the input generator script. |
| 180 |
*/ |
| 181 |
void showError(const QString& err); |
| 182 |
|
| 183 |
/** |
| 184 |
* Triggered when an input file's text edit is modified. |
| 185 |
*/ |
| 186 |
void textEditModified(); |
| 187 |
|
| 188 |
/** |
| 189 |
* Generate a job title automatically. |
| 190 |
*/ |
| 191 |
void updateTitlePlaceholder(); |
| 192 |
|
| 193 |
private: |
| 194 |
/** |
| 195 |
* Generate a QSettings key with the given identifier that is unique to this |
| 196 |
* input generator's display name. |
| 197 |
* @param identifier Setting key, e.g. "outputPath" |
| 198 |
* @return Script-specific key, e.g. "quantumInput/GAMESS/outputPath" |
| 199 |
* @todo Display names are not necessarily unique, but paths are too long. |
| 200 |
* Maybe add a namespace qualifier to the script display names? |
| 201 |
*/ |
| 202 |
QString settingsKey(const QString& identifier) const; |
| 203 |
|
| 204 |
/** |
| 205 |
* Write the input file(s) to disk. Prompts user for target location. |
| 206 |
* @{ |
| 207 |
*/ |
| 208 |
void saveSingleFile(const QString& fileName); |
| 209 |
void saveDirectory(); |
| 210 |
/**@}*/ |
| 211 |
|
| 212 |
/** Get batch job options from MoleQueueDialog. */ |
| 213 |
QJsonObject promptForBatchJobOptions() const; |
| 214 |
|
| 215 |
/** |
| 216 |
* Make signal/slot connections. |
| 217 |
*/ |
| 218 |
void connectButtons(); |
| 219 |
|
| 220 |
Ui::InputGeneratorWidget* m_ui; |
| 221 |
bool m_updatePending; |
| 222 |
QList<QTextEdit*> m_dirtyTextEdits; |
| 223 |
InputGenerator m_inputGenerator; |
| 224 |
}; |
| 225 |
|
| 226 |
} // namespace MoleQueue |
| 227 |
} // namespace Avogadro |
| 228 |
|
| 229 |
#endif // AVOGADRO_MOLEQUEUE_INPUTGENERATORWIDGET_H |