Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mainwindow.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "mainwindow.h"
4 #include "aprocdelegate.h"
5 #include "iprocdelegate.h"
6 #include "gparamdelegate.h"
7 #include "dialog.h"
8 #include "addprocdialog.h"
9 #include "addcondition.h"
10 #include "editcondition.h"
11 #include "guihelp.h"
12 
13 #include "marlin/CMProcessor.h"
14 
15 #include <string>
16 #include <sstream>
17 #include <stdlib.h>
18 
19 MainWindow::MainWindow() : _modified(false), _saved(false), _file(""), msc(NULL)
20 {
21  //key shortcut for help
22  QShortcut *helpF1 = new QShortcut(Qt::Key_F1, this);
23  connect(helpF1, SIGNAL(activated()), this, SLOT(help()));
24 
25  //signal if modifications were made
26  connect(this, SIGNAL(modifiedContent()), this, SLOT(madeChanges()));
27 
28  //init views
29  setupViews();
30 
31  //Left
32  QVBoxLayout *leftLayout = new QVBoxLayout;
33  leftLayout->addWidget(lcioColsGBox);
34  leftLayout->addWidget(globalSectionGBox);
35  leftLayout->addWidget(viewButtonsGBox);
36 
37  QWidget *left = new QWidget;
38  left->setLayout(leftLayout);
39 
40  //Vertical Splitter
41  vSplitter = new QSplitter;
42  vSplitter->setOrientation( Qt::Vertical );
43  vSplitter->addWidget(aProcGBox);
44  vSplitter->addWidget(condGBox);
45  vSplitter->addWidget(aProcErrorsGBox);
46  vSplitter->addWidget(iProcGBox);
47 
48  QList<int> vSizes;
49  vSizes << 650 << 500 << 450 << 400;
50  vSplitter->setSizes( vSizes );
51 
52  //Horizontal Splitter
53  hSplitter = new QSplitter;
54  hSplitter->addWidget(left);
55  hSplitter->addWidget(vSplitter);
56 
57  hSizes << 600 << 800;
58  hSplitter->setSizes( hSizes );
59 
60  //about Marlin GUI message
61  aboutGUIMsg = QString(tr(
62  "<font size=5><b>Marlin - Graphical User Interface</b></font><br><br>"
63  "<font size=4>This application lets you \"repair\" or create "
64  "new Steering Files for Marlin.</font><br><br><br>"
65  "<b>WARNING:</b><br>"
66  "<font color=#FB0000>Please be aware that comments made in the original steering files will get lost in the saving process.<br>"
67  "Processors that are not installed in your Marlin binary are not editable in this application and loose "
68  "their parameter's descriptions and types.<br>"
69  "Extra parameters that aren't categorized as default in a processor also loose their description and type.</font><br><br><br>"
70 
71  "In order for this application to work correctly you should first check if all processors found in the "
72  "steering file are installed in your Marlin binary.<br>This can easily be check by running \"Marlin -c SteeringFile.xml\"<br><br><br>"
73  "If you have comments or suggestions please take a look at the ILC Forum<br>under the Marlin section at "
74  "<a href=\"http://forum.linearcollider.org\">http://forum.linearcollider.org</a>. Thanks <br><br>"
75  "Author: Jan Engels @ DESY -IT-"
76  ));
77 
78  //save changes message
79  saveChangesMsg = QString(tr(
80  "You made changes that will get lost.\nDo you want to save your changes?\n\n"
81  "WARNING:\n"
82  "Please be aware that comments made in the original steering files will get lost in the saving process.\n"
83  "Processors that are not installed in your Marlin binary will loose their parameter's descriptions and types as well.\n"
84  "Extra parameters that aren't categorized as default in a processor also loose their description and type.\n\n"
85  ));
86 
87  //set central widget
88  QLabel *defLab = new QLabel(aboutGUIMsg);
89 
90  defLab->setAlignment(Qt::AlignCenter);
91  setCentralWidget(defLab);
92 
93  //Menu & Status Bars
94  createMenus();
95  statusBar();
96 
97  //Window Title
98  setWindowTitle(tr("Marlin GUI"));
99 
101 
102  //Window Size
103  showMaximized();
104 }
105 
106 void MainWindow::closeEvent(QCloseEvent *e)
107 {
108  // bug fix: when editing global parameters the values only get saved
109  // after the edit box has lost focus
110  this->setFocus();
111 
112  if( !_modified ){
113  e->accept();
114  return;
115  }
116 
117  int ret = QMessageBox::warning(this, tr("Exit Marlin GUI"), saveChangesMsg,
118  QMessageBox::Yes,
119  QMessageBox::No | QMessageBox::Default,
120  QMessageBox::Cancel | QMessageBox::Escape);
121 
122  if( ret == QMessageBox::Yes ){
123  saveXMLFile();
124  e->accept();
125  }
126  else if( ret == QMessageBox::No ){
127  e->accept();
128  }
129  else{
130  e->ignore();
131  }
132 }
133 
135 //INIT METHODS
137 
139 {
140  QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
141  QAction *newAction = fileMenu->addAction(tr("&New..."));
142  newAction->setShortcut(QKeySequence(tr("Ctrl+N")));
143  QAction *openAction = fileMenu->addAction(tr("&Open..."));
144  openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
145  QAction *saveAction = fileMenu->addAction(tr("&Save..."));
146  saveAction->setShortcut(QKeySequence(tr("Ctrl+S")));
147  QAction *saveasAction = fileMenu->addAction(tr("Save &As..."));
148  saveasAction->setShortcut(QKeySequence(tr("Ctrl+A")));
149  fileMenu->addSeparator();
150  QAction *quitAction = fileMenu->addAction(tr("E&xit"));
151  quitAction->setShortcut(QKeySequence(tr("Ctrl+X")));
152 
153  connect(newAction, SIGNAL(triggered()), this, SLOT(newXMLFile()));
154  connect(openAction, SIGNAL(triggered()), this, SLOT(openXMLFile()));
155  connect(saveAction, SIGNAL(triggered()), this, SLOT(saveXMLFile()));
156  connect(saveasAction, SIGNAL(triggered()), this, SLOT(saveAsXMLFile()));
157  connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
158 
159  styleActionGroup = new QActionGroup(this);
160  foreach (QString styleName, QStyleFactory::keys()) {
161  QAction *action = new QAction(styleActionGroup);
162  action->setText(tr("%1 Style").arg(styleName));
163  action->setData(styleName);
164  action->setCheckable(true);
165  connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStyle(bool)));
166  }
167 
168  QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
169  foreach( QAction *action, styleActionGroup->actions() )
170  viewMenu->addAction(action);
171 
172  QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
173  QAction *aboutGUIAction = aboutMenu->addAction(tr("About &Marlin GUI..."));
174  QAction *aboutQTAction = aboutMenu->addAction(tr("About &QT..."));
175  QAction *helpAction = aboutMenu->addAction(tr("&Help..."));
176 
177  connect(aboutGUIAction, SIGNAL(triggered()), this, SLOT(aboutGUI()));
178  connect(aboutQTAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
179  connect(helpAction, SIGNAL(triggered()), this, SLOT(help()));
180 }
181 
183  QMessageBox::about(this, tr("About Marlin GUI"), aboutGUIMsg);
184 }
185 
187  QWidget *help = NULL;
188  if( !showCond->isChecked() ){
189  help= new GUIHelp;
190  }
191  else{
192  help= new GUIHelp("/gui/help/html/conditions.html",this, Qt::Dialog );
193  }
194  help->show();
195 }
196 
198 {
199 
201  //CONDITIONS TABLE
203 
204  condTable = new QTableWidget;
205 
206  QStringList labels;
207  labels << tr("Condition");
208  condTable->setColumnCount(1);
209  condTable->setHorizontalHeaderLabels(labels);
210  condTable->horizontalHeader()->resizeSection(0, 500);
211  condTable->setSelectionBehavior(QAbstractItemView::SelectRows);
212  condTable->setSelectionMode(QAbstractItemView::SingleSelection);
213  condTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
214 
215  connect(condTable, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(editCondition()));
216 
217  //Buttons
218  QPushButton *addCond = new QPushButton(tr("&Insert"));
219  QPushButton *editCond = new QPushButton(tr("Edit"));
220  QPushButton *remCond = new QPushButton(tr("Remove"));
221 
222  addCond->setToolTip(tr("Insert New Condition"));
223  editCond->setToolTip(tr("Edit selected Condition"));
224  remCond->setToolTip(tr("Remove Selected Condition"));
225 
226  connect(addCond, SIGNAL(clicked()), this, SLOT(addCondition()));
227  connect(editCond, SIGNAL(clicked()), this, SLOT(editCondition()));
228  connect(remCond, SIGNAL(clicked()), this, SLOT(remCondition()));
229 
230  //Buttons Layout
231  QVBoxLayout *condButtonsLayout = new QVBoxLayout;
232  condButtonsLayout->addWidget(addCond);
233  condButtonsLayout->addWidget(editCond);
234  condButtonsLayout->addWidget(remCond);
235 
236  QGroupBox *condButtons = new QGroupBox(tr("Operations"));
237  condButtons->setLayout( condButtonsLayout );
238  condButtons->setFixedWidth( 120 );
239 
240  //Layout
241  QGridLayout *condLayout = new QGridLayout;
242  condLayout->addWidget(condTable,0,0);
243  condLayout->addWidget(condButtons,0,1,Qt::AlignTop);
244 
245  //GroupBox
246  condGBox = new QGroupBox(tr("Edit Conditions List"));
247  condGBox->setLayout(condLayout);
248 
249  //hide conditions by default when starting the GUI
250  condGBox->hide();
251 
253  //ACTIVE PROCESSORS
255  aProcTable = new QTableWidget;
256 
257  labels.clear();
258  labels << tr("Name") << tr("Type");
259  aProcTable->setColumnCount(2);
260  aProcTable->setHorizontalHeaderLabels(labels);
261  aProcTable->horizontalHeader()->setClickable(true);
262  aProcTable->horizontalHeader()->resizeSection(0, 220);
263  aProcTable->horizontalHeader()->resizeSection(1, 220);
264  aProcTable->verticalHeader()->hide();
265  aProcTable->setSelectionBehavior(QAbstractItemView::SelectRows);
266  aProcTable->setSelectionMode(QAbstractItemView::SingleSelection);
267  //aProcTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
268  aProcTable->setItemDelegate(new AProcDelegate(this));
269 
270  connect(aProcTable->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(selectColumn(int)));
271  connect(aProcTable, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(procTypeDC(int, int)));
272  connect(aProcTable, SIGNAL(cellPressed(int, int)), this, SLOT(selectionChanged(int)));
273  connect(aProcTable, SIGNAL(cellClicked(int, int)), this, SLOT(conditionChanged(int, int)));
274 
275  //Buttons
276  QPushButton *addAProc = new QPushButton(tr("&Add"));
277  QPushButton *editAProc = new QPushButton(tr("&Edit"));
278  QPushButton *remAProc = new QPushButton(tr("Delete"));
279  QPushButton *deactProc = new QPushButton(tr("Dea&ctivate"));
280  QPushButton *mvAProcUp = new QPushButton(tr("Move &Up"));
281  QPushButton *mvAProcDn = new QPushButton(tr("Move &Down"));
282  showCond = new QPushButton(tr("&Show Cond."));
283 
284  showCond->setCheckable( true );
285 
286  addAProc->setToolTip(tr("Add New Processor"));
287  editAProc->setToolTip(tr("Edit Selected Processor"));
288  remAProc->setToolTip(tr("Delete Selected Processor"));
289  deactProc->setToolTip(tr("Deactivate Selected Processor"));
290  mvAProcUp->setToolTip(tr("Move Selected Processor Up"));
291  mvAProcDn->setToolTip(tr("Move Selected Processor Down"));
292  showCond->setToolTip(tr("Show/Hide Conditions"));
293 
294  connect(addAProc, SIGNAL(clicked()), this, SLOT(addAProcessor()));
295  connect(editAProc, SIGNAL(clicked()), this, SLOT(editAProcessor()));
296  connect(remAProc, SIGNAL(clicked()), this, SLOT(remAProcessor()));
297  connect(deactProc, SIGNAL(clicked()), this, SLOT(deactivateProcessor()));
298  connect(mvAProcUp, SIGNAL(clicked()), this, SLOT(moveProcessorUp()));
299  connect(mvAProcDn, SIGNAL(clicked()), this, SLOT(moveProcessorDown()));
300  connect(showCond, SIGNAL(toggled(bool)), this, SLOT(showConditions(bool)));
301 
302  //Buttons Layout
303  QVBoxLayout *aProcButtonsLayout = new QVBoxLayout;
304  aProcButtonsLayout->addWidget(addAProc);
305  aProcButtonsLayout->addWidget(editAProc);
306  aProcButtonsLayout->addWidget(remAProc);
307  aProcButtonsLayout->addWidget(deactProc);
308  aProcButtonsLayout->addWidget(mvAProcUp);
309  aProcButtonsLayout->addWidget(mvAProcDn);
310  aProcButtonsLayout->addWidget(showCond);
311 
312  //Buttons GroupBox
313  aProcButtonsGBox = new QGroupBox(tr("Operations"));
314  aProcButtonsGBox->setLayout(aProcButtonsLayout);
315  aProcButtonsGBox->setFixedWidth(120);
316 
317 
318  //Layout
319  QGridLayout *aProcLayout = new QGridLayout;
320  aProcLayout->addWidget(aProcTable,0,0);
321  aProcLayout->addWidget(aProcButtonsGBox,0,1,Qt::AlignTop);
322 
323  //GroupBox
324  aProcGBox = new QGroupBox(tr("Active Processors"));
325  aProcGBox->setLayout(aProcLayout);
326 
328  //INACTIVE PROCESSORS
330  iProcTable = new QTableWidget;
331 
332  labels.clear();
333  labels << tr("Name") << tr("Type");
334  iProcTable->setColumnCount(2);
335  iProcTable->setHorizontalHeaderLabels(labels);
336  iProcTable->horizontalHeader()->resizeSection(0, 220);
337  iProcTable->horizontalHeader()->resizeSection(1, 220);
338  iProcTable->verticalHeader()->hide();
339  iProcTable->setSelectionBehavior(QAbstractItemView::SelectRows);
340  iProcTable->setSelectionMode(QAbstractItemView::SingleSelection);
341  //iProcTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
342  iProcTable->setItemDelegate(new IProcDelegate(this));
343 
344  //Buttons
345  QPushButton *editIProc = new QPushButton(tr("Edit"));
346  QPushButton *remIProc = new QPushButton(tr("Delete"));
347  QPushButton *actProc = new QPushButton(tr("Activate"));
348 
349  editIProc->setToolTip(tr("Edit Selected Processor"));
350  remIProc->setToolTip(tr("Delete Selected Processor"));
351  actProc->setToolTip(tr("Activate Selected Processor"));
352 
353  connect(editIProc, SIGNAL(clicked()), this, SLOT(editIProcessor()));
354  connect(remIProc, SIGNAL(clicked()), this, SLOT(remIProcessor()));
355  connect(actProc, SIGNAL(clicked()), this, SLOT(activateProcessor()));
356 
357  //Buttons Layout
358  QVBoxLayout *iProcButtonsLayout = new QVBoxLayout;
359  iProcButtonsLayout->addWidget(actProc);
360  iProcButtonsLayout->addWidget(editIProc);
361  iProcButtonsLayout->addWidget(remIProc);
362 
363  //Buttons GroupBox
364  iProcButtonsGBox = new QGroupBox(tr("Operations"));
365  iProcButtonsGBox->setLayout(iProcButtonsLayout);
366  iProcButtonsGBox->setFixedWidth(120);
367 
368  //Layout
369  QGridLayout *iProcLayout = new QGridLayout;
370  iProcLayout->addWidget(iProcTable,0,0);
371  iProcLayout->addWidget(iProcButtonsGBox,0,1,Qt::AlignTop);
372 
373  //GroupBox
374  iProcGBox = new QGroupBox(tr("Inactive Processors"));
375  iProcGBox->setLayout(iProcLayout);
376 
378  //LCIO COLLECTIONS LIST
380  lcioColsTable = new QTableWidget;
381 
382  labels.clear();
383  labels << tr("Name") << tr("Type") << tr("LCIO File");
384  lcioColsTable->setColumnCount(3);
385  lcioColsTable->setHorizontalHeaderLabels(labels);
386  lcioColsTable->setSelectionMode(QAbstractItemView::NoSelection);
387  lcioColsTable->horizontalHeader()->resizeSection(0, 160);
388  lcioColsTable->horizontalHeader()->resizeSection(1, 160);
389  lcioColsTable->horizontalHeader()->resizeSection(2, 160);
390  lcioColsTable->verticalHeader()->hide();
391  //lcioColsTable->setSortingEnabled( true );
392  //lcioColsTable->sortItems( 1 );
393  lcioColsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
394 
395  //Layout
396  QVBoxLayout *lcioColsLayout = new QVBoxLayout;
397  lcioColsLayout->addWidget(lcioColsTable);
398 
399  //GroupBox
400  lcioColsGBox = new QGroupBox(tr("List of all Collections Found in LCIO Files"));
401  lcioColsGBox->setLayout(lcioColsLayout);
402 
404  //LCIO FILES LIST
406 
407  lcioFilesList = new QListWidget;
408 
409  //Buttons
410  QPushButton *mvFileUp = new QPushButton(tr("Move Up"));
411  QPushButton *mvFileDn = new QPushButton(tr("Move Down"));
412  QPushButton *addFile = new QPushButton(tr("Add"));
413  QPushButton *remFile = new QPushButton(tr("Remove"));
414 
415  addFile->setToolTip(tr("Add New LCIO File"));
416  remFile->setToolTip(tr("Remove Selected LCIO File"));
417  mvFileUp->setToolTip(tr("Move Selected File Up"));
418  mvFileDn->setToolTip(tr("Move Selected File Down"));
419 
420  connect(addFile, SIGNAL(clicked()), this, SLOT(addLCIOFile()));
421  connect(remFile, SIGNAL(clicked()), this, SLOT(remLCIOFile()));
422  connect(mvFileUp, SIGNAL(clicked()), this, SLOT(moveLCIOFileUp()));
423  connect(mvFileDn, SIGNAL(clicked()), this, SLOT(moveLCIOFileDown()));
424 
425  //Layout
426  QVBoxLayout *lcioButtonsLayout = new QVBoxLayout;
427  lcioButtonsLayout->addWidget(addFile);
428  lcioButtonsLayout->addWidget(remFile);
429  lcioButtonsLayout->addWidget(mvFileUp);
430  lcioButtonsLayout->addWidget(mvFileDn);
431 
432  QWidget *lcioButtons = new QWidget;
433  lcioButtons->setLayout( lcioButtonsLayout );
434 
435  //Label
436  QLabel *cwdl = new QLabel( "CWD: " );
437  QLineEdit *cwdle = new QLineEdit(QDir::currentPath());
438  cwdle->setReadOnly( true );
439  QWidget *cwdWdg = new QWidget;
440 
441  QHBoxLayout *cwdLayout = new QHBoxLayout;
442  cwdLayout->addWidget(cwdl);
443  cwdLayout->addWidget(cwdle);
444 
445  cwdWdg->setLayout( cwdLayout );
446 
447  cwdWdg->setToolTip(tr("Current Working Directory: LCIO Files in the same directory branch of this path are added with relative paths"));
448 
449  //Layout
450  QGridLayout *lcioFilesLayout = new QGridLayout;
451  lcioFilesLayout->addWidget(cwdWdg,0,0);
452  lcioFilesLayout->addWidget(lcioFilesList,1,0);
453  lcioFilesLayout->addWidget(lcioButtons,1,1,Qt::AlignTop);
454 
455  //GroupBox
456  lcioFilesGBox = new QGroupBox(tr("Global Section LCIO Files"));
457  lcioFilesGBox->setLayout(lcioFilesLayout);
458  lcioFilesGBox->setMaximumHeight(180);
459 
461  //GLOBAL SECTION TABLE
463 
464  globalSectionTable = new QTableWidget;
465 
466  labels.clear();
467  labels << tr("Parameter Name") << tr("Parameter Value");
468  globalSectionTable->setColumnCount(2);
469  globalSectionTable->setHorizontalHeaderLabels(labels);
470  globalSectionTable->horizontalHeader()->resizeSection(0, 240);
471  globalSectionTable->horizontalHeader()->resizeSection(1, 240);
472  globalSectionTable->verticalHeader()->hide();
473  globalSectionTable->setSelectionMode(QAbstractItemView::NoSelection);
474  globalSectionTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
475 
476  //GEAR Button
477  QPushButton *gearButton = new QPushButton(tr("Browse for GEAR File"));
478  connect(gearButton, SIGNAL(clicked()), this, SLOT(changeGearFile()));
479 
480  //Layout
481  QVBoxLayout *globalParametersLayout = new QVBoxLayout;
482  globalParametersLayout->addWidget(globalSectionTable);
483  globalParametersLayout->addWidget(gearButton);
484 
485  //GroupBox
486  QGroupBox *globalParametersGBox = new QGroupBox(tr("Global Section Parameters"));
487  globalParametersGBox->setLayout(globalParametersLayout);
488 
489  //Layout
490  QVBoxLayout *globalSectionLayout = new QVBoxLayout;
491  globalSectionLayout->addWidget(lcioFilesGBox);
492  globalSectionLayout->addWidget(globalParametersGBox);
493 
494  //GroupBox
495  globalSectionGBox = new QGroupBox(tr("Global Section"));
496  globalSectionGBox->setLayout(globalSectionLayout);
497 
498 
500  //VIEW OPTION BUTTONS
502  hideProcs = new QPushButton(tr("Hide Inactive Processors"));
503  hideErrors = new QPushButton(tr("Hide Active Processor Errors"));
504  hideProcs->setCheckable(true);
505  hideErrors->setCheckable(true);
506 
507  hideProcs->setToolTip(tr("Hide/Show Inactive Processors"));
508  hideErrors->setToolTip(tr("Hide/Show Active Processor Errors"));
509 
510  connect(hideProcs, SIGNAL(toggled(bool)), this, SLOT(hideIProcessors(bool)));
511  connect(hideErrors, SIGNAL(toggled(bool)), this, SLOT(hideAProcErrors(bool)));
512 
513  //Layout
514  QHBoxLayout *viewButtonsLayout = new QHBoxLayout;
515  viewButtonsLayout->addWidget(hideProcs);
516  viewButtonsLayout->addWidget(hideErrors);
517 
518  //GroupBox
519  viewButtonsGBox = new QGroupBox(tr("View Options"));
520  viewButtonsGBox->setLayout(viewButtonsLayout);
521 
523  //ERRORS
525  aProcErrors = new QTextEdit;
526  aProcErrors->setReadOnly(true);
527 
528  //Layout
529  QVBoxLayout *aProcErrorsLayout = new QVBoxLayout;
530  aProcErrorsLayout->addWidget(aProcErrors);
531 
532  //GroupBox
533  aProcErrorsGBox = new QGroupBox(tr("Error Description for selected Active Processor"));
534  aProcErrorsGBox->setLayout(aProcErrorsLayout);
535 
536 }
537 
538 void MainWindow::setMarlinSteerCheck( const char* filename )
539 {
540 
541  if( msc != NULL ){
542  delete msc;
543  }
544 
545  msc = new MarlinSteerCheck(filename);
546 
547  if( msc->getErrors().size()!=0 ){
548  QString errors;
549  for( sSet::const_iterator p=msc->getErrors().begin(); p!=msc->getErrors().end(); p++){
550  errors+=(*p).c_str();
551  errors+="\n";
552  }
553  QMessageBox::warning(this,
554  tr("Errors Occured loading Steering File"),
555  errors
556  );
557  if( msc->getErrors().find("XML File parsing error") != msc->getErrors().end() ){
558  return;
559  }
560  }
561 
562  std::string filen(filename);
563 
564  //if it is an old steering file append .xml at the end
565  if( filen.find(".xml",0) == std::string::npos ){
566  filen+=".xml";
567  }
568 
569  _file=filen;
570  _modified=false;
571  _saved=false;
572  std::cout << "Marlin steering file [" << filen << "] loaded successfully into the GUI\n";
573  //set the window title
574  QString title= "Marlin GUI - ";
575  QFileInfo xmlFile(filen.c_str());
576  title+=xmlFile.absoluteFilePath();
577  setWindowTitle(title);
578 
579  setCentralWidget(hSplitter);
580 
581  //create backup file
582  std::string cmd= "ls ";
583  cmd+=filename;
584  cmd+="~";
585  cmd+= " >/dev/null 2>/dev/null";
586  //if backup file doesn't exist create backup
587  if( system( cmd.c_str() ) ){
588  cmd= "cp -f ";
589  cmd+=filename;
590  cmd+=" ";
591  cmd+=filename;
592  cmd+="~";
593  if( system( cmd.c_str() ) ){
594  std::cerr << "Marlin GUI::setMarlinSteerCheck: Error creating backup file!!\n";
595  }
596  }
597 
599  updateFiles();
602  updateConds();
603 
604  //Delegate
606  globalSectionTable->setItemDelegate( gpDelegate );
607 }
608 
609 
611 //UPDATE VIEWS METHODS
613 
615 {
616  //initialize global parameters
617  StringVec paramKeys;
618  msc->getGlobalParameters()->getStringKeys(paramKeys);
619 
620  globalSectionTable->setRowCount(0);
621  for( unsigned int i=0; i<paramKeys.size(); i++ ){
622 
623  int row = globalSectionTable->rowCount();
624  globalSectionTable->setRowCount(row + 1);
625 
626  StringVec paramValues;
627  msc->getGlobalParameters()->getStringVals(paramKeys[i], paramValues);
628 
629  QString str;
630 
631  for( unsigned int j=0; j<paramValues.size(); j++ ){
632  str+=paramValues[j].c_str();
633  str+=" ";
634  }
635 
636  QTableWidgetItem *item0 = new QTableWidgetItem( paramKeys[i].c_str() );
637  QTableWidgetItem *item1 = new QTableWidgetItem( str );
638 
639  if(paramKeys[i]=="GearXMLFile"){
640  QFileInfo gearInfo(paramValues[0].c_str());
641  item1->setBackgroundColor( ( !gearInfo.exists() ? QColor(184,16,0,180) : QColor(32,140,64,180)) );
642  item1->setFlags(item0->flags() & ~Qt::ItemIsEditable);
643  }
644 
645  item0->setFlags(item0->flags() & ~Qt::ItemIsEditable);
646 
647  globalSectionTable->setItem(row, 0, item0);
648  globalSectionTable->setItem(row, 1, item1);
649 
650  //globalSectionTable->openPersistentEditor(item1);
651  }
652 }
653 
654 void MainWindow::updateConds( int pos ){
655  condTable->setRowCount(0);
656  for( sSet::const_iterator p=msc->getPConditions().begin(); p!=msc->getPConditions().end(); p++ ){
657  int row = condTable->rowCount();
658  condTable->setRowCount(row + 1);
659 
660  QTableWidgetItem *item = new QTableWidgetItem((*p).c_str());
661  condTable->setItem(row, 0, item);
662  }
663  if( pos == -1 ){
664  selectRow(condTable, condTable->rowCount());
665  }
666  else{
667  selectRow(condTable, pos);
668  }
669 }
670 
672 {
673  //initialize LCIO collections table
674  lcioColsTable->setRowCount(0);
675  for( unsigned int i=0; i<msc->getLCIOCols().size(); i++ ){
676 
677  int row = lcioColsTable->rowCount();
678  lcioColsTable->setRowCount(row + 1);
679 
680  QTableWidgetItem *item0 = new QTableWidgetItem(msc->getLCIOCols()[i]->getValue().c_str());
681  QTableWidgetItem *item1 = new QTableWidgetItem(msc->getLCIOCols()[i]->getType().c_str());
682  QTableWidgetItem *item2 = new QTableWidgetItem(msc->getLCIOCols()[i]->getName().c_str());
683 
684  lcioColsTable->setItem(row, 0, item0);
685  lcioColsTable->setItem(row, 1, item1);
686  lcioColsTable->setItem(row, 2, item2);
687  }
688 
689  //initialize LCIO files list
690  lcioFilesList->clear();
691  for( unsigned int i=0; i<msc->getLCIOFiles().size(); i++ ){
692  new QListWidgetItem(msc->getLCIOFiles()[i].c_str(), lcioFilesList);
693  }
694 
695  if( pos == -1 ){
697  }
698  else{
700  }
701 }
702 
703 void MainWindow::selectLCIORow(QListWidget* t, int row ){
704  if( row>=0 && row<=t->count() ){
705  if( row==t->count() ){ row--; }
706  t->setCurrentRow( row );
707  t->setItemSelected( t->item(row), true );
708  }
709 }
710 
712 {
713  //clear errors
714  aProcErrors->clear();
715 
716  //initialize active processors table
717  int numCond = msc->getPConditions().size();
718  aProcTable->setColumnCount( 0 );
719  aProcTable->setColumnCount( numCond+2 );
720 
721  QStringList labels;
722  for( int i=0; i<numCond; i++ ){
723  QString num;
724 
725  if( (i+1) >= 10){
726  num=((i+1)/10)+48;
727  num+=((i+1)%10)+48;
728  }
729  else{
730  num=(i+1)+48;
731  }
732  //append condition to the header
733  sSet::const_iterator p=msc->getPConditions().begin();
734  advance(p,i);
735  num+=" ";
736  num+=(*p).c_str();
737 
738  labels << num;
739  aProcTable->horizontalHeader()->resizeSection(i, 25);
740  aProcTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
741  aProcTable->setColumnHidden(i, !showCond->isChecked() );
742  }
743 
744  labels << tr("Name") << tr("Type");
745  aProcTable->setHorizontalHeaderLabels(labels);
746  aProcTable->horizontalHeader()->resizeSection( numCond, 220);
747  aProcTable->horizontalHeader()->resizeSection( numCond+1, 220);
748 
749  aProcTable->setRowCount(0);
750  for( unsigned int i=0; i<msc->getAProcs().size(); i++ ){
751  int row = aProcTable->rowCount();
752  aProcTable->setRowCount(row + 1);
753 
754  QTableWidgetItem *item0 = new QTableWidgetItem(msc->getAProcs()[i]->getName().c_str());
755  QTableWidgetItem *item1 = new QTableWidgetItem(msc->getAProcs()[i]->getType().c_str());
756 
757  item0->setToolTip( QString(msc->getAProcs()[i]->getDescription().c_str() ));
758  item1->setToolTip( QString(msc->getAProcs()[i]->getDescription().c_str() ));
759 
760  item1->setFlags(item1->flags() & ~Qt::ItemIsEditable);
761 
762  aProcTable->setItem(row, numCond, item0);
763  aProcTable->setItem(row, numCond+1, item1);
764 
765  item0->setBackgroundColor( (msc->getAProcs()[i]->hasErrors() ? QColor(184,16,0,180) : QColor(32,140,64,180)) );
766  item1->setBackgroundColor( (msc->getAProcs()[i]->hasErrors() ? QColor(184,16,0,180) : QColor(32,140,64,180)) );
767 
768  for( int j=0; j<numCond; j++ ){
769  QTableWidgetItem *item = new QTableWidgetItem;
770  item->setFlags(item->flags() & ~Qt::ItemIsEditable);
771 
772  item->setCheckState( msc->getAProcs()[i]->hasCondition( msc->getCondition(j) ) ? Qt::Checked : Qt::Unchecked );
773  item->setToolTip( msc->getCondition(j).c_str() );
774  aProcTable->setItem(row, j, item);
775  }
776  }
777  if( pos == -1 ){
778  selectRow(aProcTable, aProcTable->rowCount(), true);
779  }
780  else{
781  selectRow(aProcTable, pos, true);
782  }
783 }
784 
786 {
787  //initialize inactive processors table
788  iProcTable->setRowCount(0);
789  for( unsigned int i=0; i<msc->getIProcs().size(); i++ ){
790  int row = iProcTable->rowCount();
791  iProcTable->setRowCount(row + 1);
792 
793  QTableWidgetItem *item0 = new QTableWidgetItem(msc->getIProcs()[i]->getName().c_str());
794  QTableWidgetItem *item1 = new QTableWidgetItem(msc->getIProcs()[i]->getType().c_str());
795 
796  item0->setToolTip( QString(msc->getIProcs()[i]->getDescription().c_str() ));
797  item1->setToolTip( QString(msc->getIProcs()[i]->getDescription().c_str() ));
798 
799  item1->setFlags(item1->flags() & ~Qt::ItemIsEditable);
800 
801  iProcTable->setItem(row, 0, item0);
802  iProcTable->setItem(row, 1, item1);
803 
804  item0->setBackgroundColor( (msc->getIProcs()[i]->isInstalled() ? QColor(255,255,255) : QColor(128,128,128)) );
805  item1->setBackgroundColor( (msc->getIProcs()[i]->isInstalled() ? QColor(255,255,255) : QColor(128,128,128)) );
806  item0->setTextColor( (msc->getIProcs()[i]->isInstalled() ? QColor(0,0,0) : QColor(200,200,200)) );
807  item1->setTextColor( (msc->getIProcs()[i]->isInstalled() ? QColor(0,0,0) : QColor(200,200,200)) );
808  }
809  if( pos == -1 ){
810  selectRow(iProcTable, iProcTable->rowCount());
811  }
812  else{
813  selectRow(iProcTable, pos);
814  }
815 }
816 
817 void MainWindow::conditionChanged( int row, int col ){
818  if( col < aProcTable->columnCount()-2){
819  QTableWidgetItem *item = aProcTable->item(row, col);
820  if(item->checkState() == Qt::Checked){
821  msc->getAProcs()[row]->getConditions().insert( msc->getCondition( col ));
822  }
823  else{
824  msc->getAProcs()[row]->getConditions().erase( msc->getCondition( col ));
825  }
826  emit modifiedContent();
827  }
828 }
829 
830 void MainWindow::selectColumn( int col ){
831  if( col < aProcTable->columnCount()-2 && msc->getAProcs().size() > 0 ){
832  //selection based on the select state from the first item in the table
833  bool select=msc->getAProcs()[0]->hasCondition( msc->getCondition( col ));
834 
835  for( unsigned int i=0; i<msc->getAProcs().size(); i++ ){
836  if( !select ){
837  msc->getAProcs()[i]->getConditions().insert( msc->getCondition( col ));
838  }
839  else{
840  msc->getAProcs()[i]->getConditions().erase( msc->getCondition( col ));
841  }
842  }
843  updateAProcessors( aProcTable->currentRow() );
844  emit modifiedContent();
845  }
846 }
847 
848 
849 void MainWindow::selectRow(QTableWidget* t, int row, bool colors ){
850  if( row>=0 && row<=t->rowCount() ){
851  if( row==t->rowCount() ){ row--; }
852  t->setCurrentCell( row, 0 );
853  t->setItemSelected( t->currentItem(), true );
854  if( colors ){ emit selectionChanged( row ); }
855  }
856 }
857 
858 void MainWindow::procTypeDC( int row, int col ){
859  if( row>=0 && col == aProcTable->columnCount() - 1 ){
860  editAProcessor();
861  }
862 }
863 
865 //PUBLIC SLOTS
867 
869  //update the name of the processor in the vector
870  msc->getAProcs()[aProcTable->currentRow()]->setName(aProcTable->currentItem()->text().toStdString());
871  emit modifiedContent();
872 }
873 
875  //update the name of the processor in the vector
876  msc->getIProcs()[iProcTable->currentRow()]->setName(iProcTable->currentItem()->text().toStdString());
877  emit modifiedContent();
878 }
879 
880 
882 //PRIVATE SLOTS
884 
885 void MainWindow::showConditions(bool checked)
886 {
887  int numCond = msc->getPConditions().size();
888 
889  //show conditions
890  if(checked){
891  for( int i=0; i<numCond; i++ ){
892  aProcTable->setColumnHidden(i, false);
893  }
894 
895  showCond->setText(tr("&Hide Cond."));
896 
897  hSizes = hSplitter->sizes();
898  hSplitterSize = hSizes[0];
899  hSizes[0] = 0;
900 
901  vSplitter->widget(1)->show();
902  vSplitter->widget(2)->hide();
903  vSplitter->widget(3)->hide();
904  }
905  //hide conditions
906  else{
907  for( int i=0; i<numCond; i++ ){
908  aProcTable->setColumnHidden(i, true);
909  }
910 
911  showCond->setText(tr("&Show Cond."));
912 
913  hSizes[0] = hSplitterSize;
914 
915  vSplitter->widget(1)->hide();
916  if( !hideErrors->isChecked() ){
917  vSplitter->widget(2)->show();
918  }
919  if( !hideProcs->isChecked() ){
920  vSplitter->widget(3)->show();
921  }
922  }
923  hSplitter->setSizes( hSizes );
924 }
925 
926 void MainWindow::hideIProcessors(bool checked)
927 {
928  //hide inactive processors
929  if(checked){
930  hideProcs->setText(tr("Show Inactive Processors"));
931  vSplitter->widget(3)->hide();
932  }
933  //show inactive processors
934  else{
935  hideProcs->setText(tr("Hide Inactive Processors"));
936  vSplitter->widget(3)->show();
937  }
938 }
939 
940 void MainWindow::hideAProcErrors(bool checked)
941 {
942  //hide active processors
943  if(checked){
944  hideErrors->setText(tr("Show Active Processor Errors"));
945  vSplitter->widget(2)->hide();
946  }
947  //show active processors
948  else{
949  hideErrors->setText(tr("Hide Active Processor Errors"));
950  vSplitter->widget(2)->show();
951  }
952 }
953 
955 {
956  if( row >= 0 && ((unsigned)row) < msc->getAProcs().size() ){
957 
958  //set the selection color to red or green acoording to the active processor's errors
959  QPalette pal = aProcTable->palette();
960  pal.setColor(QPalette::Highlight, msc->getAProcs()[row]->hasErrors() ? QColor(184,16,0,180) : QColor(32,140,64,220) );
961  aProcTable->setPalette(pal);
962 
963  //display the error description of active processors
964  if( msc->getAProcs()[row]->hasErrors() ){
966  ss << msc->getAProcs()[row]->getError();
967 
968  if( msc->getAProcs()[row]->hasErrorCols() ){
969  ss << std::endl;
970  msc->dumpColErrors(row, ss, true);
971  }
972  aProcErrors->setPlainText( ss.str().c_str() );
973  }
974  else{
975  aProcErrors->clear();
976  }
977  }
978 }
979 
981  ACDialog dg( msc, this, Qt::Dialog );
982  dg.resize(400,150);
983  if( dg.exec() ){
984  updateConds();
985  updateAProcessors(aProcTable->currentRow());
986  emit modifiedContent();
987  }
988 }
989 
991  int row=condTable->currentRow();
992  if( row >= 0 && row < condTable->rowCount() ){
993  ECDialog ec( msc, condTable->currentItem()->text().toStdString(), this, Qt::Dialog );
994  ec.resize(400,150);
995  if( ec.exec() ){
996  updateConds();
997  updateAProcessors(aProcTable->currentRow());
998  emit modifiedContent();
999  }
1000  }
1001 }
1002 
1004  if( msc->getPConditions().size() > 0 ){
1005  int ret = QMessageBox::warning(this, tr("Delete Condition"),
1006  tr( "Delete selected condition?\nThe condition will also be removed from every processor afected by it!!\n"),
1007  QMessageBox::Yes | QMessageBox::Default,
1008  QMessageBox::No | QMessageBox::Escape);
1009 
1010  if( ret == QMessageBox::Yes ){
1011  msc->remCondition( condTable->currentItem()->text().toStdString() );
1012  updateConds( condTable->currentRow() );
1013  updateAProcessors(aProcTable->currentRow());
1014  emit modifiedContent();
1015  }
1016  }
1017 }
1018 
1020 {
1021  APDialog dg( msc, this, Qt::Dialog );
1022  dg.resize(700,300);
1023  dg.exec();
1024  emit modifiedContent();
1025 }
1026 
1028 {
1029  int pos = aProcTable->currentRow();
1030  if( pos >= 0 && pos < aProcTable->rowCount() ){
1031 
1032  int ret = QMessageBox::warning(this, tr("Delete Processor"),
1033  tr( "Delete selected processor?\nAll parameter values for this processor will also be deleted!!\n"
1034  "If you don't want this processor to be executed, but still keep it's parameter values saved, "
1035  "try the \"Deactivate\" button instead."),
1036  QMessageBox::Yes | QMessageBox::Default,
1037  QMessageBox::No | QMessageBox::Escape);
1038 
1039  if( ret == QMessageBox::No ){
1040  return;
1041  }
1042 
1043  msc->remProcessor( pos, ACTIVE );
1044  updateAProcessors(pos);
1045  emit modifiedContent();
1046  }
1047 }
1048 
1050 {
1051  int pos = iProcTable->currentRow();
1052  if( pos >= 0 && pos < iProcTable->rowCount() ){
1053 
1054  int ret = QMessageBox::warning(this, tr("Delete Processor"),
1055  tr("Delete selected processor?\nAll parameter values for this processor will also be deleted!!"),
1056  QMessageBox::Yes | QMessageBox::Default,
1057  QMessageBox::No | QMessageBox::Escape);
1058 
1059  if( ret == QMessageBox::No ){
1060  return;
1061  }
1062 
1063  msc->remProcessor( pos, INACTIVE );
1064  updateIProcessors(pos);
1065  emit modifiedContent();
1066  }
1067 }
1068 
1070 {
1071  int pos;
1072 
1073  //if new processor
1074  if(row != -1 ){
1075  updateAProcessors(row);
1076  pos=row;
1077  }
1078  //existing processor
1079  else{
1080  pos = aProcTable->currentRow();
1081  }
1082 
1083  if( pos >= 0 && msc->getAProcs()[pos]->isInstalled() ){
1084 
1085  //save the current processor before editing it
1086  CCProcessor *p = new CCProcessor( *msc->getAProcs()[pos] );
1087 
1088  Dialog dg( msc->getAProcs()[pos], msc, this, Qt::Window );
1089  //dg.resize(1100,900);
1090  dg.setWindowState( Qt::WindowMaximized);
1091 
1092  if(dg.exec()){
1093  delete p;
1094  }
1095  else{
1096  delete msc->getAProcs()[pos];
1097  msc->getAProcs()[pos]=p;
1098  }
1099  msc->consistencyCheck();
1100  updateAProcessors(pos);
1101  }
1102 }
1103 
1105 {
1106  int pos = iProcTable->currentRow();
1107  if( pos >= 0 ){
1108  if( msc->getIProcs()[pos]->isInstalled() ){
1109  //save the current processor before editing it
1110  CCProcessor *p = new CCProcessor( *msc->getIProcs()[pos] );
1111 
1112  Dialog dg( msc->getIProcs()[pos], msc, this, Qt::Window );
1113  //dg.resize(1100,900);
1114  dg.setWindowState( Qt::WindowMaximized);
1115 
1116  if(dg.exec()){
1117  delete p;
1118  }
1119  else{
1120  delete msc->getIProcs()[pos];
1121  msc->getIProcs()[pos]=p;
1122  }
1123  }
1124  else{
1125  QMessageBox::warning(this, tr("Activate Processor"),
1126  tr( "Sorry, you cannot edit this processor because it is not installed in your Marlin binary.\n"
1127  "Install it first and then try again")
1128  );
1129  }
1130  }
1131 }
1132 
1134 {
1135  int pos = iProcTable->currentRow();
1136  if( pos >= 0 ){
1137  if(msc->getIProcs()[pos]->isInstalled()){
1138  msc->activateProcessor( pos );
1139  updateIProcessors(pos);
1141  emit modifiedContent();
1142  }
1143  else{
1144  QMessageBox::warning(this, tr("Activate Processor"),
1145  tr( "Sorry, you cannot activate this processor because it is not installed in your Marlin binary.\n"
1146  "Install it first and then try again")
1147  );
1148  }
1149  }
1150 }
1151 
1153 {
1154  int pos = aProcTable->currentRow();
1155  if( pos >= 0 ){
1156  msc->deactivateProcessor( pos );
1157  updateAProcessors(pos);
1159  emit modifiedContent();
1160  }
1161 }
1162 
1164 {
1165  int pos = aProcTable->currentRow();
1166  if( pos > 0 ){
1167  msc->changeProcessorPos( pos, pos - 1 );
1168  updateAProcessors(pos - 1);
1169  emit modifiedContent();
1170  }
1171 }
1172 
1174 {
1175  int pos = aProcTable->currentRow();
1176  if( pos < aProcTable->rowCount() - 1 ){
1177  msc->changeProcessorPos( pos, pos + 1 );
1178  updateAProcessors(pos + 1);
1179  emit modifiedContent();
1180  }
1181 }
1182 
1184 {
1185  int pos = lcioFilesList->currentRow();
1186  if( pos > 0 ){
1187  msc->changeLCIOFilePos( pos, pos - 1 );
1188  updateFiles(pos -1);
1189  emit modifiedContent();
1190  }
1191 }
1192 
1194 {
1195  int pos = lcioFilesList->currentRow();
1196  if( pos < lcioFilesList->count() - 1 ){
1197  msc->changeLCIOFilePos( pos, pos + 1 );
1198  updateFiles(pos + 1);
1199  emit modifiedContent();
1200  }
1201 }
1202 
1204 {
1205  QString absFileName = QFileDialog::getOpenFileName(this, tr("Choose a Gear file"), "", "*.xml", 0, QFileDialog::DontResolveSymlinks);
1206 
1207  if( !absFileName.isEmpty() ){
1208  //get the current Path
1209  QDir dir;
1210 
1211  //test if the file is on the same directory-branch from the working directory
1212  StringVec currentPath, filePath;
1213  msc->getMProcs()->tokenize(dir.absolutePath().toStdString(),currentPath,"/");
1214  msc->getMProcs()->tokenize(absFileName.toStdString(),filePath,"/");
1215 
1216  QString fileName;
1217  //if file is on the same directory-branch from the working directory take relative path
1218  if(currentPath[0]==filePath[0]){
1219  fileName = dir.relativeFilePath(absFileName);
1220  }
1221  //else take absolute path
1222  else{
1223  fileName = absFileName;
1224  }
1225 
1226  //if( !absFileName.isEmpty() ){
1227  //QFileInfo xmlFile(msc->getXMLFile().c_str());
1229  //QDir dir(xmlFile.absolutePath());
1231  //QString fileName = dir.relativeFilePath(absFileName);
1232 
1233  statusBar()->showMessage(tr("Changed GEAR File to %1").arg(fileName), 2000);
1234  msc->getGlobalParameters()->erase( "GearXMLFile" );
1235  StringVec file;
1236  file.push_back( fileName.toStdString() );
1237  msc->getGlobalParameters()->add( "GearXMLFile", file );
1239  emit modifiedContent();
1240  }
1241 }
1242 
1244 {
1245  QString absFileName = QFileDialog::getOpenFileName(this, tr("Choose an LCIO file"), "", "*.slcio", 0, QFileDialog::DontResolveSymlinks);
1246 /*
1247  QString fileName;
1248 
1249  if( _file != "Untitled.xml" ){
1250  QFileInfo xmlFile(msc->getXMLFile().c_str());
1251  //extract the absolute path from the xml file
1252  QDir dir(xmlFile.absolutePath());
1253  //get the relative path for the LCIO file
1254  fileName = dir.relativeFilePath(absFileName);
1255  }
1256  else{
1257  //get the current Path
1258  QDir dir;
1259  //get the relative path for the LCIO file
1260  fileName = dir.relativeFilePath(absFileName);
1261  }
1262 */
1263  if( !absFileName.isEmpty() ){
1264  //get the current Path
1265  QDir dir;
1266 
1267  //test if the file is on the same directory-branch from the working directory
1268  StringVec currentPath, filePath;
1269  msc->getMProcs()->tokenize(dir.absolutePath().toStdString(),currentPath,"/");
1270  msc->getMProcs()->tokenize(absFileName.toStdString(),filePath,"/");
1271 
1272  QString fileName;
1273  //if file is on the same directory-branch from the working directory take relative path
1274  if(currentPath[0]==filePath[0]){
1275  fileName = dir.relativeFilePath(absFileName);
1276  }
1277  //else take absolute path
1278  else{
1279  fileName = absFileName;
1280  }
1281 
1282  QDir newFile(absFileName);
1283  QFileInfo newFileI(absFileName);
1284  for( unsigned int i=0; i<msc->getLCIOFiles().size(); i++){
1285  QDir existingFile(msc->getLCIOFiles()[i].c_str());
1286  QFileInfo existingFileI(msc->getLCIOFiles()[i].c_str());
1287  if((newFile.canonicalPath() == existingFile.canonicalPath()) ||
1288  (newFileI.fileName() == existingFileI.fileName()) ){
1289  QString error="Error opening LCIO file [";
1290  error+=absFileName;
1291  error+="]. This file has already been opened!!";
1292  QMessageBox::critical(this, tr("Error Opening LCIO File"), error );
1293  return;
1294  }
1295  }
1296  msc->addLCIOFile( fileName.toStdString().c_str() );
1297  statusBar()->showMessage(tr("Added LCIO File %1").arg(fileName), 2000);
1298  updateFiles();
1301  emit modifiedContent();
1302  }
1303 }
1304 
1306 {
1307  if( lcioFilesList->currentRow() != -1 ){
1308  msc->remLCIOFile(lcioFilesList->currentItem()->text().toStdString() );
1309  statusBar()->showMessage(tr("Removed LCIO File %1").arg(lcioFilesList->currentItem()->text()), 2000);
1310  updateFiles();
1313  emit modifiedContent();
1314  }
1315 }
1316 
1318 {
1319  if( _modified ){
1320  int ret = QMessageBox::warning(this, tr("Exit Marlin GUI"), saveChangesMsg,
1321  QMessageBox::Yes,
1322  QMessageBox::No | QMessageBox::Default,
1323  QMessageBox::Cancel | QMessageBox::Escape);
1324 
1325  if( ret == QMessageBox::Yes ){
1326  saveXMLFile();
1327  }
1328  else if( ret == QMessageBox::Cancel ){
1329  return;
1330  }
1331  }
1332 
1333  QString fileName = QFileDialog::getOpenFileName(this,
1334  tr("Choose a Marlin Steering File to open..."),
1335  QDir::currentPath(),
1336  "*.xml\n*.steer"
1337  );
1338 
1339  if( !fileName.isEmpty() ){
1340  QFileInfo xmlFile(fileName);
1341  //get the current path
1342  QDir dir(QDir::currentPath());
1343  //get the relative path for the LCIO file
1344  fileName = dir.relativeFilePath(xmlFile.absoluteFilePath());
1345 
1346  setMarlinSteerCheck(fileName.toStdString().c_str());
1347  statusBar()->showMessage(tr("Loaded %1").arg(fileName), 2000);
1348  }
1349 }
1350 
1352 
1353  // bug fix: when editing global parameters the values only get saved
1354  // after the edit box has lost focus
1355  this->setFocus();
1356 
1357  if( _modified ){
1358  int ret = QMessageBox::warning(this, tr("Exit Marlin GUI"), saveChangesMsg,
1359  QMessageBox::Yes,
1360  QMessageBox::No | QMessageBox::Default,
1361  QMessageBox::Cancel | QMessageBox::Escape);
1362 
1363  if( ret == QMessageBox::Yes ){
1364  saveXMLFile();
1365  }
1366  else if( ret == QMessageBox::Cancel ){
1367  return;
1368  }
1369  }
1370 
1371 
1372  _file="Untitled.xml";
1373  _modified=false;
1374  _saved=false;
1375  setWindowTitle(tr("Marlin GUI - Untitled.xml"));
1376 
1377  setCentralWidget(hSplitter);
1378 
1379  if( msc != NULL ){
1380  delete msc;
1381  }
1382 
1383  msc = new MarlinSteerCheck();
1384 
1386  updateFiles();
1389 }
1390 
1392 
1393  // bug fix: when editing global parameters the values only get saved
1394  // after the edit box has lost focus
1395  this->setFocus();
1396 
1397  //create backup file
1398  std::string cmd= "ls ";
1399  cmd+=_file;
1400  cmd+= " >/dev/null 2>/dev/null";
1401  //if file already exists show overwrite warning
1402  if( !_saved && !system( cmd.c_str()) ){
1403  QString msg=_file.c_str();
1404  msg+=" already exists. Do you want to replace it?";
1405  int ret = QMessageBox::warning(this, tr("Save"), msg,
1406  QMessageBox::Yes,
1407  QMessageBox::No | QMessageBox::Default);
1408  if( ret == QMessageBox::No ){
1409  saveAsXMLFile();
1410  return;
1411  }
1412  }
1413 
1414  if( !_saved && _file == "Untitled.xml" ){
1415  saveAsXMLFile();
1416  }
1417  else{
1418  if(!msc->saveAsXMLFile(_file)){
1419  QMessageBox::critical(this,
1420  tr("Error Saving File"),
1421  tr("Sorry, there was an error saving the file. Please choose another file.")
1422  );
1423  saveAsXMLFile();
1424  return;
1425  }
1426  _modified=false;
1427  _saved=true;
1428  statusBar()->showMessage(tr("Saved %1").arg(QString(_file.c_str())), 2000);
1429  }
1430 }
1431 
1433 
1434  // bug fix: when editing global parameters the values only get saved
1435  // after the edit box has lost focus
1436  this->setFocus();
1437 
1438  QFileDialog *fd = new QFileDialog(this, tr("Save file as"), QDir::currentPath(), "*.xml");
1439 
1440  fd->setDefaultSuffix( "xml" );
1441  fd->setAcceptMode( QFileDialog::AcceptSave );
1442  fd->setFileMode( QFileDialog::AnyFile );
1443  fd->setResolveSymlinks( false );
1444  fd->setFilter( "*.xml" );
1445 
1446  QString fileName;
1447 
1448  if( fd->exec() ){
1449  fileName=fd->selectedFiles().at(0);
1450  }
1451 
1452  if( !fileName.isEmpty() ){
1453 
1454  //if it is an old steering file append .xml at the end
1455  if( !fileName.contains(".xml", Qt::CaseInsensitive ) ){
1456  QString error;
1457  error="Sorry, you have tried to save the file with an extension different than \".xml\"\n"
1458  "Marlin GUI does not support other extensions than the xml one.. \nThe filename you've chosen (";
1459  error+=fileName;
1460  error+=") was therefore renamed to (";
1461  error+=fileName;
1462  error+=".xml)";
1463 
1464  QMessageBox::critical(this,
1465  tr( "Error Saving File"),
1466  error
1467  );
1468  fileName+=".xml";
1469  _saved=false;
1470  }
1471  else{
1472  _saved=true;
1473  }
1474 
1475  //update the window title bar
1476  QString title= "Marlin GUI - ";
1477  title+=fileName;
1478  setWindowTitle(title);
1479 
1480  _file=fileName.toStdString();
1481  saveXMLFile();
1482  }
1483 }
1484 
1486  _modified=true;
1487 }
1488 
1490 {
1491  foreach (QAction *action, styleActionGroup->actions()){
1492  QString styleName = action->data().toString();
1493  QStyle *candidate = QStyleFactory::create(styleName);
1494  Q_ASSERT(candidate);
1495  if(candidate->metaObject()->className() == QApplication::style()->metaObject()->className()){
1496  action->trigger();
1497  return;
1498  }
1499  delete candidate;
1500  }
1501 }
1502 
1503 void MainWindow::changeStyle(bool checked)
1504 {
1505  if (!checked){ return; }
1506  QAction *action = qobject_cast<QAction *>(sender());
1507  QStyle *style = QStyleFactory::create(action->data().toString());
1508  Q_ASSERT(style);
1509  QApplication::setStyle(style);
1510 }
1511 
QTextEdit * aProcErrors
Definition: mainwindow.h:149
QGroupBox * iProcButtonsGBox
Definition: mainwindow.h:121
Definition: dialog.h:21
QGroupBox * aProcButtonsGBox
Definition: mainwindow.h:120
QListWidget * lcioFilesList
Definition: mainwindow.h:135
QTableWidget * globalSectionTable
Definition: mainwindow.h:132
void showConditions(bool checked)
Definition: mainwindow.cpp:885
void addLCIOFile()
void saveAsXMLFile()
void selectRow(QTableWidget *t, int row, bool colors=false)
Definition: mainwindow.cpp:849
void selectionChanged(int row)
Definition: mainwindow.cpp:954
void changeGearFile()
void activateProcessor()
void remProcessor(unsigned int index, bool status)
Remove processor with the given status at the given index.
void aProcNameChanged()
Definition: mainwindow.cpp:868
void setMarlinSteerCheck(const char *filename=NULL)
Definition: mainwindow.cpp:538
QPushButton * showCond
Definition: mainwindow.h:140
sSet & getPConditions()
Returns a set with all the processor&#39;s conditions.
void remCondition()
void moveProcessorDown()
void moveLCIOFileDown()
this class is a Marlin Steering File consistency check Tool.
QTableWidget * condTable
Definition: mainwindow.h:134
QString aboutGUIMsg
Definition: mainwindow.h:151
T endl(T...args)
ColVec & getLCIOCols() const
Returns the collections read from LCIO files.
void updateIProcessors(int pos=-1)
Definition: mainwindow.cpp:785
@ class Small delegate class for changing active processor&#39;s names
Definition: aprocdelegate.h:13
void remCondition(const std::string &condition)
Removes the given condition.
void aboutGUI()
Definition: mainwindow.cpp:182
T end(T...args)
std::shared_ptr< StringParameters > getGlobalParameters()
Returns the Global Parameters.
QTableWidget * aProcTable
Definition: mainwindow.h:130
bool _modified
Definition: mainwindow.h:112
void addAProcessor()
void hideIProcessors(bool checked)
Definition: mainwindow.cpp:926
void addCondition()
Definition: mainwindow.cpp:980
QPushButton * hideErrors
Definition: mainwindow.h:139
#define INACTIVE
Definition: CCProcessor.h:11
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
Definition: CCProcessor.h:39
const std::string getCondition(unsigned int index)
Returns the condition for a given index.
QActionGroup * styleActionGroup
Definition: mainwindow.h:152
void deactivateProcessor()
void activateProcessor(unsigned int index)
Activate processor at the given index.
STL class.
QGroupBox * condGBox
Definition: mainwindow.h:124
QSplitter * vSplitter
Definition: mainwindow.h:143
void hideAProcErrors(bool checked)
Definition: mainwindow.cpp:940
T push_back(T...args)
void editAProcessor(int row=-1)
void remLCIOFile()
void createMenus()
Definition: mainwindow.cpp:138
void changeStyle(bool checked)
void saveXMLFile()
void moveProcessorUp()
void selectColumn(int col)
Definition: mainwindow.cpp:830
virtual void closeEvent(QCloseEvent *e)
Definition: mainwindow.cpp:106
QGroupBox * globalSectionGBox
Definition: mainwindow.h:127
@ class Small delegate class for changing inactive processor&#39;s names
Definition: iprocdelegate.h:13
T erase(T...args)
void updateGlobalSection()
Definition: mainwindow.cpp:614
sSet & getErrors()
Returns a set with all the errors found after performing a consistency check.
ProcVec & getIProcs()
Returns the Inactive Processors.
bool saveAsXMLFile(const std::string &file)
Saves the data to an XML file with the given name Returns false if error occured. ...
void editIProcessor()
MarlinSteerCheck * msc
Definition: mainwindow.h:115
QGroupBox * aProcErrorsGBox
Definition: mainwindow.h:118
QGroupBox * lcioFilesGBox
Definition: mainwindow.h:125
QString saveChangesMsg
Definition: mainwindow.h:150
void consistencyCheck()
Performs a check at all active processors to search for unavailable collections.
QTableWidget * iProcTable
Definition: mainwindow.h:131
T get(T...args)
void help()
Definition: mainwindow.cpp:186
T insert(T...args)
CMProcessor * getMProcs()
Returns the Marlin Processors.
void tokenize(const std::string str, StringVec &tokens, const std::string &delimiters=" ")
Definition: CMProcessor.cc:212
T find(T...args)
T size(T...args)
void changeProcessorPos(unsigned int pos, unsigned int newPos)
Change the active processor at the given index to the new given position.
QSplitter * hSplitter
Definition: mainwindow.h:144
void iProcNameChanged()
Definition: mainwindow.cpp:874
void updateAProcessors(int pos=-1)
Definition: mainwindow.cpp:711
void remAProcessor()
void dumpColErrors(unsigned int i, std::ostream &stream, bool separators=false)
Writes the collection errors for the active processor with given index to the given stream...
T begin(T...args)
void deactivateProcessor(unsigned int index)
Deactivate processor at the given index.
T c_str(T...args)
QGroupBox * lcioColsGBox
Definition: mainwindow.h:126
int hSplitterSize
Definition: mainwindow.h:146
void selectLCIORow(QListWidget *t, int row)
Definition: mainwindow.cpp:703
void modifiedContent()
QList< int > hSizes
Definition: mainwindow.h:145
void setupViews()
Definition: mainwindow.cpp:197
void moveLCIOFileUp()
void checkCurrentStyle()
bool _saved
Definition: mainwindow.h:113
QTableWidget * lcioColsTable
Definition: mainwindow.h:133
ProcVec & getAProcs()
Returns the Active Processors.
StringVec & getLCIOFiles()
Returns the names of the LCIO files found in the global section.
#define ACTIVE
Definition: CCProcessor.h:10
void updateFiles(int pos=-1)
Definition: mainwindow.cpp:671
void procTypeDC(int row, int col)
Definition: mainwindow.cpp:858
void remIProcessor()
QPushButton * hideProcs
Definition: mainwindow.h:138
void changeLCIOFilePos(unsigned int pos, unsigned int newPos)
Change the LCIO File at the given index to the new given position.
void openXMLFile()
void madeChanges()
int addLCIOFile(const std::string &file)
Add LCIO file and read all collections inside it.
void remLCIOFile(const std::string &file)
Remove LCIO file and all collections associated to it.
std::string _file
Definition: mainwindow.h:114
QGroupBox * aProcGBox
Definition: mainwindow.h:122
void newXMLFile()
void editCondition()
Definition: mainwindow.cpp:990
void conditionChanged(int row, int col)
Definition: mainwindow.cpp:817
QGroupBox * viewButtonsGBox
Definition: mainwindow.h:119
void updateConds(int pos=-1)
Definition: mainwindow.cpp:654
QGroupBox * iProcGBox
Definition: mainwindow.h:123