1 #include <DatabaseUtils/GUI/BasicEditorDisplay.h> 2 #include <DatabaseUtils/GUI/ConfigSelectionDialog.h> 3 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h> 4 #include <NovaDAQUtilities/EnvVarCache.h> 5 #include <boost/lexical_cast.hpp> 6 #include <QtGui/QInputDialog> 8 #include <QtGui/QMenuBar> 9 #include <QtGui/QMessageBox> 17 BasicEditorDisplay(QWidget *
parent) : QMainWindow(parent)
20 this->setGeometry(0, 0, 750, 468);
22 QMenu* fileMenu = menuBar()->addMenu(
tr(
"&File"));
24 QAction* reloadAction = fileMenu->addAction(
tr(
"&Reload"));
28 QAction* openAction = fileMenu->addAction(
tr(
"&Open"));
42 QAction* exitAction = fileMenu->addAction(
tr(
"E&xit"));
50 QMessageBox confirmBox(
this);
51 std::string msgText =
"There are changes that haven't been saved yet.";
52 confirmBox.setText(msgText.c_str());
54 msgText =
"Are you sure that you want to reload this dataset without ";
55 msgText.append(
"saving the existing changes to the database?");
56 confirmBox.setInformativeText(msgText.c_str());
58 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
59 confirmBox.setDefaultButton(QMessageBox::No);
60 int retCode = confirmBox.exec();
62 if (retCode == QMessageBox::No) {
return;}
74 IDSpec idSpec(globalConfigId, IDSpec::GLOBAL,
76 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
93 QMessageBox confirmBox(
this);
94 std::string msgText =
"There are changes that haven't been saved yet.";
95 confirmBox.setText(msgText.c_str());
97 msgText =
"Are you sure that you want to load a new dataset without ";
98 msgText.append(
"saving the existing changes to the database?");
99 confirmBox.setInformativeText(msgText.c_str());
101 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
102 confirmBox.setDefaultButton(QMessageBox::No);
103 int retCode = confirmBox.exec();
105 if (retCode == QMessageBox::No) {
return;}
109 isSlowControlsConfiguration() ?
110 IDSpec::SLOWCONTROLS : IDSpec::DAQ),
112 int retCode = selectDialog.exec();
113 if (retCode == QDialog::Rejected) {
117 boost::shared_ptr<dbutils::daqconfig::GlobalNameSpec> nameSpecPtr;
118 if (selectDialog.getSelectedTime()==NamedConfigUtils::LATEST_TIME_STRING) {
121 selectDialog.getSelectedDCMOpMode(),
127 selectDialog.getSelectedDCMOpMode(),
129 selectDialog.getSelectedTime()));
132 isSlowControlsConfiguration());
133 int64_t globalConfigId = -1;
134 if (! NamedConfigUtils::getGlobalConfigId((*nameSpecPtr),
139 IDSpec idSpec(globalConfigId, IDSpec::GLOBAL,
141 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
151 std::string msgText =
"The loading of the new dataset failed. ";
152 msgText.append(
"Depending on when the failure occurred, you may have an inconsistent set of data displayed in this editor. Please retry the loading of the new dataset until success is achieved before editing the data in the display.");
153 QMessageBox::critical(
this,
"Data Loading Error",
165 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
168 paramSet.
put(NamedConfigUtils::DESCRIPTION_COLUMN_NAME,
169 "New values from the Configuration Editor GUI.");
170 int64_t globalConfigId;
172 NamedConfigUtils::copyGlobalConfig(oldGlobalIdSpec,
true, paramSet,
173 "",
false, globalConfigId);
174 if (resultStatus.
code != NamedConfigUtils::COPY_SUCCEEDED) {
176 if (! userChoice) {
return;}
179 NamedConfigUtils::copyGlobalConfig(oldGlobalIdSpec,
true, paramSet,
180 "",
true, globalConfigId);
181 if (resultStatus.
code != NamedConfigUtils::COPY_SUCCEEDED) {
182 std::string msgText =
"Unable to create a copy of the named ";
183 msgText.append(
"global configuration with ID = ");
184 msgText.append(boost::lexical_cast<std::string>
186 msgText.append(
": ");
187 msgText.append(resultStatus.
message);
188 QMessageBox::critical(
this,
"Save Error", msgText.c_str());
196 boost::shared_ptr<dbutils::daqconfig::GlobalNameSpec>
202 isSlowControlsConfiguration());
203 IDSpec globalIdSpec(globalConfigId, IDSpec::GLOBAL,
205 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
206 if (
_doSaveChanges(oldGlobalIdSpec, globalIdSpec, (*nameSpecPtr))) {
207 if (NamedConfigUtils::markConfigDone(globalIdSpec,
true)) {
216 bool status = NamedConfigUtils::markConfigDone(globalIdSpec,
false);
218 std::string msgText =
"An error occurred when saving changes to ";
219 msgText.append(
"the database.<br/><br/>");
222 msgText.append(
"However, the new configuration was ");
223 msgText.append(
"successfully marked as Done (changes have ");
224 msgText.append(
"finished). Please try saving again in a few ");
225 msgText.append(
"minutes, but realize that you may need to ");
226 msgText.append(
"over-write the incomplete save that just ");
227 msgText.append(
"failed (the GUI will guide you through that).");
230 msgText.append(
"In addition, the new configuration was not ");
231 msgText.append(
"successfully marked as Done (so it still ");
232 msgText.append(
"appears that there is a change in progress ");
233 msgText.append(
"in the DB table). If so, you'll need ");
234 msgText.append(
"to use the ");
235 msgText.append(
"<a href=\"https://cdcvs.fnal.gov/redmine/projects/novadaq-config-mgmt/wiki/How_To_recover_from_a_failed_pedestal_upload_-_December_2011\">MarkConfigChangesDone</a> utility to mark the change as Done.");
236 msgText.append(
"In any case, please try saving again in a few ");
237 msgText.append(
"minutes - the GUI will guide you through any ");
238 msgText.append(
"extra steps that you need to take.");
241 QMessageBox::critical(
this,
"Save Error", msgText.c_str());
252 isSlowControlsConfiguration() ?
253 IDSpec::SLOWCONTROLS : IDSpec::DAQ),
259 if (globalNameMap.size() > 0) {
260 msg.append(
"<br/><br/>Recent choices for the name and the DCM ");
261 msg.append(
"operating mode include the following:<ul>");
262 NamedConfigUtils::GlobalNameSpecMap::const_iterator iter;
263 NamedConfigUtils::GlobalNameSpecMap::const_iterator iterEnd =
265 for (iter = globalNameMap.begin(); iter != iterEnd; ++iter) {
267 msg.append((*iter).first.getConfigName());
269 msg.append((*iter).first.getDCMOpMode());
274 QString newConfigName =
275 QInputDialog::getText(
this,
tr(
"Configuration Name"), msg.c_str(),
279 if (! status) {
return;}
281 msg =
"Please enter the new DCM operating mode.";
282 if (globalNameMap.size() > 0) {
283 msg.append(
"<br/><br/>Recent choices for the name and the DCM ");
284 msg.append(
"operating mode include the following:<ul>");
285 NamedConfigUtils::GlobalNameSpecMap::const_iterator iter;
286 NamedConfigUtils::GlobalNameSpecMap::const_iterator iterEnd =
288 for (iter = globalNameMap.begin(); iter != iterEnd; ++iter) {
290 msg.append((*iter).first.getConfigName());
292 msg.append((*iter).first.getDCMOpMode());
297 QString newDCMOpMode =
298 QInputDialog::getText(
this,
tr(
"DCM Operating Mode"), msg.c_str(),
302 if (! status) {
return;}
306 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
309 paramSet.
put(NamedConfigUtils::NAME_COLUMN_NAME,
310 newConfigName.toStdString());
311 paramSet.
put(NamedConfigUtils::DCMOPMODE_COLUMN_NAME,
312 newDCMOpMode.toStdString());
313 paramSet.
put(NamedConfigUtils::DESCRIPTION_COLUMN_NAME,
314 "New named configuration from the Configuration Editor GUI.");
315 int64_t globalConfigId;
317 NamedConfigUtils::copyGlobalConfig(oldGlobalIdSpec,
true, paramSet,
318 "",
false, globalConfigId);
319 if (resultStatus.
code != NamedConfigUtils::COPY_SUCCEEDED) {
321 if (! userChoice) {
return;}
324 NamedConfigUtils::copyGlobalConfig(oldGlobalIdSpec,
true, paramSet,
325 "",
true, globalConfigId);
326 if (resultStatus.
code != NamedConfigUtils::COPY_SUCCEEDED) {
327 std::string msgText =
"Unable to create a copy of the named ";
328 msgText.append(
"global configuration with ID = ");
329 msgText.append(boost::lexical_cast<std::string>
331 msgText.append(
": ");
332 msgText.append(resultStatus.
message);
333 QMessageBox::critical(
this,
"Save Error", msgText.c_str());
338 boost::shared_ptr<dbutils::daqconfig::GlobalNameSpec>
340 newDCMOpMode.toStdString(),
344 isSlowControlsConfiguration());
345 IDSpec globalIdSpec(globalConfigId, IDSpec::GLOBAL,
347 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
348 if (
_doSaveChanges(oldGlobalIdSpec, globalIdSpec, (*nameSpecPtr))) {
349 if (NamedConfigUtils::markConfigDone(globalIdSpec,
true)) {
358 NamedConfigUtils::markConfigDone(globalIdSpec,
false);
365 msgText.append(
"<ul>");
366 msgText.append(
"<li>To edit a value, double-click on it [left mouse button]. (A single mouse click simply selects the value, it doesn't enable editing.)</li>");
367 msgText.append(
"<li>Once you have edited a value, you should single-click on a different cell in the table to ensure that the editor captures your change. (Pressing the Tab or Enter key after you enter your change will also work.)</li>");
368 msgText.append(
"<li>For \"mask\" values, a bitmap editor is provided. To open the bitmap editor, right-mouse-click on the value that you want to edit, and select the \"Open bitmap editor\" option from the popup menu.</li>");
369 msgText.append(
"</ul>");
371 QMessageBox::information(
this,
"Configuration editor help",
380 if (dbUser !=
"nova_reader") {
397 if (!
hasChanges()) {
event->accept();
return;}
399 QMessageBox confirmBox(
this);
401 std::string msgText =
"There are changes that haven't been saved yet.";
402 confirmBox.setText(msgText.c_str());
404 msgText =
"Are you sure that you want to exit without saving ";
405 msgText.append(
"your changes to the database?");
406 confirmBox.setInformativeText(msgText.c_str());
408 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
409 confirmBox.setDefaultButton(QMessageBox::No);
410 int retCode = confirmBox.exec();
412 if (retCode == QMessageBox::Yes) {
event->accept();
return;}
413 else {
event->ignore();
return;}
422 QMessageBox confirmBox(
this);
424 std::string msgText =
"You are about to update the \"";
425 msgText.append(dbString);
426 msgText.append(
"\" database.");
427 confirmBox.setText(msgText.c_str());
429 msgText =
"Are you sure that you want to save your changes to the \"";
430 msgText.append(dbString);
431 msgText.append(
"\" database?");
432 confirmBox.setInformativeText(msgText.c_str());
434 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
435 confirmBox.setDefaultButton(QMessageBox::No);
436 int retCode = confirmBox.exec();
438 return (retCode == QMessageBox::Yes);
444 if (statusObj.
code ==
445 NamedConfigUtils::COPY_FOUND_UPDATE_IN_PROGRESS) {
446 std::string msgText =
"A problem was found when saving changes to ";
447 msgText.append(
"the database.<br/><br/>");
448 msgText.append(
"The creation of a configuration with the same ");
449 msgText.append(
"name and DCM operating mode is currently in ");
450 msgText.append(
"progress. (Attempting to copy global ");
451 msgText.append(
"configuration with ID ");
452 msgText.append(boost::lexical_cast<std::string>
454 msgText.append(
".)");
455 msgText.append(
"<ul><li>Detailed message: \"");
456 msgText.append(statusObj.
message);
457 msgText.append(
"\"</li></ul>");
458 msgText.append(
"Please try again in a few minutes, or if ");
459 msgText.append(
"this problem persists, use the ");
460 msgText.append(
"<a href=\"https://cdcvs.fnal.gov/redmine/projects/novadaq-config-mgmt/wiki/How_To_recover_from_a_failed_pedestal_upload_-_December_2011\">MarkConfigChangesDone</a> utility to fix the issue.");
461 msgText.append(
"<br/><br/>Another alternative is to save ");
462 msgText.append(
"this configuration dataset with a different ");
463 msgText.append(
"name (use File->Save As).");
464 QMessageBox::warning(
this,
"Save Warning", msgText.c_str());
468 else if (statusObj.
code ==
469 NamedConfigUtils::COPY_FOUND_INTERMEDIATE_UPDATE) {
470 QMessageBox messageBox(
this);
471 messageBox.setIcon(QMessageBox::Warning);
472 messageBox.setWindowTitle(
"Save Warning");
474 std::string msgText =
"A problem was found when saving changes to ";
475 msgText.append(
"the database.<br/><br/>");
476 msgText.append(
"Intermediate changes will be obscured by ");
477 msgText.append(
"this change. (Attempting to copy global ");
478 msgText.append(
"configuration with ID ");
479 msgText.append(boost::lexical_cast<std::string>
481 msgText.append(
".)");
482 msgText.append(
"<ul><li>Detailed message: \"");
483 msgText.append(statusObj.
message);
484 msgText.append(
"\"</li></ul>");
485 messageBox.setText(msgText.c_str());
487 msgText =
"Do you want to save anyway? (<b>Please Note</b> that ";
488 msgText.append(
"if you say Yes, the dataset that you are ");
489 msgText.append(
"currently saving will take precedence over the ");
490 msgText.append(
"existing one with the same name and DCM operating ");
491 msgText.append(
"mode <b>and</b> differences will <b>not</b> be ");
492 msgText.append(
"automatically brought forward.)");
493 messageBox.setInformativeText(msgText.c_str());
495 messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
496 messageBox.setDefaultButton(QMessageBox::No);
497 int retCode = messageBox.exec();
499 return (retCode == QMessageBox::Yes);
501 else if (statusObj.
code != NamedConfigUtils::COPY_SUCCEEDED) {
502 std::cerr <<
"Unable to create a copy of the named " 503 <<
"global configuration with ID = " 516 QMenu* helpMenu = menuBar()->addMenu(
tr(
"&Help"));
517 QAction* helpAction =
518 helpMenu->addAction(
tr(
"&Help"));
virtual bool _doReloadCurrentDataset(const dbutils::daqconfig::IDSpec &idSpec)=0
bool _getUserResponseToGlobalCopyFailure(const novadaq::Status &status)
virtual void closeEvent(QCloseEvent *event)
int64_t _currentGlobalConfigId
static EnvVarCache & getInstance()
void put(const std::string &key, const std::string &value)
SettingsDisplay * _settingsDisplay
void updateNamedConfiguration(const dbutils::daqconfig::GlobalNameSpec &nameSpec)
std::map< GlobalNameSpec, std::vector< GlobalNameSpec > > GlobalNameSpecMap
void _addHelpMenu(std::string customText="")
def connect(endpoint="tcp://127.0.0.1:5555")
virtual bool _doSaveChanges(const dbutils::daqconfig::IDSpec &oldIdSpec, const dbutils::daqconfig::IDSpec &newIdSpec, const dbutils::daqconfig::GlobalNameSpec &newNameSpec)=0
boost::shared_ptr< dbutils::daqconfig::GlobalNameSpec > _globalNameSpecPtr
virtual void reactToDataChange()
std::string _customHelpText
virtual void reactToDataSave()
void reloadCurrentDataset()
void saveChangesWithNewName()
virtual bool _doLoadNewDataset(const dbutils::daqconfig::IDSpec &idSpec)=0
virtual bool hasChanges() const =0
std::string getEnvVar(std::string name)