BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
demoTutorialDialog.C
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #include "demoTutorialDialog.h"
6 #include "mainframe.h"
7 
11 
16 
18 
27 
29 #include <BALL/SYSTEM/path.h>
30 
31 #include <QtGui/QPushButton>
32 #include <QtGui/QMessageBox>
33 #include <QtGui/QTextBrowser>
34 
35 namespace BALL
36 {
37  namespace VIEW
38  {
39 
41 {
51 };
52 
53 
55  : QDialog(parent),
56  Ui_DemoTutorialDialogData(),
57  ModularWidget(name),
58  surface_(0),
59  demo_action_(0),
60  tutorial_action_(0)
61 {
62 #ifdef BALL_VIEW_DEBUG
63  Log.error() << "new DemoTutorialDialog " << this << std::endl;
64 #endif
65 
66  setupUi(this);
67  setObjectName(name);
68 
69  // register the widget with the MainControl
71  hide();
72  connect(next_button, SIGNAL(clicked()), this, SLOT(nextStepClicked()));
73  connect(cancel_button, SIGNAL(clicked()), this, SLOT(hide()));
74 }
75 
77 {
78 #ifdef BALL_VIEW_DEBUG
79  Log.error() << "deleting DemoTutorialDialog " << this << std::endl;
80 #endif
81 
82  delete surface_;
83 }
84 
86 {
87  setWindowTitle(tr("BALLView Demo"));
88 
89  prefix_ = getBaseDir_() + "demo";
90 
91  next_button->setEnabled(true);
92  QDialog::show();
93  raise();
94  move(20,20);
95 
96  // hide some dockwidgets
97  if (LogView::getInstance(0) != 0) LogView::getInstance(0)->hide();
98  if (DatasetControl::getInstance(0) != 0) DatasetControl::getInstance(0)->hide();
99 #ifdef BALL_PYTHON_SUPPORT
100  if (PyWidget::getInstance(0) != 0) PyWidget::getInstance(0)->hide();
101 #endif
102 }
103 
105 {
106  Path p;
107  String dir = p.find( String("..")
109  + "doc"
111  + "internal"
113 
114  return dir;
115 }
116 
118 {
119  setWindowTitle(tr("BALLView Tutorial"));
120 
121  prefix_ = getBaseDir_() + "tutorial";
122 
123  next_button->setEnabled(false);
124 
125  ((Mainframe*)getMainControl())->reset();
126 
127  Scene::getInstance(0)->show();
128  MolecularControl::getInstance(0)->show();
129  MolecularControl::getInstance(0)->setFloating(false);
130  MolecularControl::getInstance(0)->applyPreferences();
131  DatasetControl::getInstance(0)->show();
132  DatasetControl::getInstance(0)->applyPreferences();
133  DatasetControl::getInstance(0)->setFloating(false);
134  GeometricControl::getInstance(0)->show();
135  GeometricControl::getInstance(0)->applyPreferences();
136  GeometricControl::getInstance(0)->setFloating(false);
137 
138  LogView::getInstance(0)->hide();
139 }
140 
142 {
143  current_step_ = 1;
144 
145  if (demo_mode_)
146  {
147  initDemo_();
148  }
149  else
150  {
151  int result = QMessageBox::question(this, tr("Warning"),
152  tr("To start the tutorial, all loaded structures and molecules will be deleted."),
153  QMessageBox::Ok| QMessageBox::Cancel, QMessageBox::Ok);
154  if (result != QMessageBox::Ok) return;
155 
156  initTutorial_();
157  }
158 
159  QUrl qurl = QUrl::fromLocalFile((prefix_ + "01.html").c_str());
160  text_browser->setSource(qurl);
161 
162  QDialog::show();
163  resize(350, 650);
164  raise();
165 }
166 
168 {
169  if (!isVisible()) return;
170 
171  if (demo_mode_)
172  {
173  onNotifyDemo_(message);
174  }
175  else
176  {
177  onNotifyTutorial_(message);
178  }
179 }
180 
182 {
183  RepresentationMessage* rmsg = RTTI::castTo<RepresentationMessage>(*message);
184 
185  if (current_step_ == 13 ||
186  current_step_ == 14)
187  {
188  if (!RTTI::isKindOf<FinishedSimulationMessage>(*message)) return;
189  }
190  else if (current_step_ == 15)
191  {
192  DatasetMessage* msg = RTTI::castTo<DatasetMessage>(*message);
193  if (msg == 0) return;
194 
195  if (msg->getDataset() == 0)
196  {
198  return;
199  }
200 
201  RegularData3DDataset* set = dynamic_cast<RegularData3DDataset*>(msg->getDataset());
202  if (set->getType() != RegularData3DController::type) return;
203 
204  grid_ = (RegularData3D*) set->getData();
205  }
206  else if (current_step_ == 16)
207  {
208  SceneMessage* msg = RTTI::castTo<SceneMessage>(*message);
209  if (msg == 0 || msg->getType() != SceneMessage::REBUILD_DISPLAY_LISTS)
210  {
211  return;
212  }
213  }
214  else if (rmsg == 0 ||
216  {
217  return;
218  }
219 
220  enableNextStep_();
221 }
222 
223 
225 {
226  next_button->setEnabled(true);
227 }
228 
229 
231 {
232  String id = String(current_step_ + 1);
233  if (id.size() == 1) id = "0" + id;
234 
235  id = prefix_ + id + ".html";
236 
237  QUrl qurl = QUrl::fromLocalFile(id.c_str());
238  text_browser->setSource(qurl);
239  next_button->setEnabled(false);
240 
241  current_step_ ++;
242 
243  if (demo_mode_)
244  {
245  if (current_step_ == 18)
246  {
247  showTutorial();
248  return;
249  }
250 
251  nextStepDemo_();
252  }
253  else
254  {
255  if (current_step_ == 9)
256  {
257  next_button->setEnabled(true);
258  }
259  if (current_step_ == 10)
260  {
261  hide();
262  HelpViewer* hv = HelpViewer::getInstance(1);
263  if (hv == 0) return;
264  hv->showHelp();
265  hv->setFloating(true);
266  hv->showMaximized();
267  }
268  }
269 }
270 
271 
273 {
274  // initialisation for first real step
275  if (current_step_ == 2)
276  {
277  DisplayProperties* dp = DisplayProperties::getInstance(0);
279 
280  ((Mainframe*)getMainControl())->reset();
281 
282  // open bpti
283  try
284  {
285  Path path;
286  String file_name = path.find("structures/bpti.pdb");
287 
288  MolecularFileDialog* dialog = MolecularFileDialog::getInstance(0);
289  if (dialog == 0) return;
290 
292  system_ = dialog->openMolecularFile(file_name);
294 
295  if (system_ == 0)
296  {
297  String msg((String)tr("Could not open bpti.pdb. Maybe the file was deleted?")+"\n");
298  msg += (String)tr("It should be found in") + " " + file_name;
299 
300  QMessageBox::critical(0, tr("Error while starting BALLView Demo"), msg.c_str(),
301  QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
302  return;
303  }
304 
305  system_->apply(getFragmentDB().add_hydrogens);
306  system_->apply(getFragmentDB().build_bonds);
307  getMainControl()->update(*system_, true);
308  }
309  catch(Exception::FileNotFound e)
310  {
311  Log.error() << (String)tr("Could not open") << " " << e.getFilename() << std::endl;
312  return;
313  }
314 
315  composites_.clear();
316  composites_.push_back(system_);
317  }
318 
319  if (current_step_ == 18) // last page
320  {
321  hide();
322  return;
323  }
324 
325  MolecularStructure* ms = MolecularStructure::getInstance(0);
326 
327  next_button->setEnabled(current_step_ >= 15);
328 
329  // remove representations
332  std::list<Representation*> reps = pm.getRepresentations();
333 
334  if (surface_ == 0 && nr == 1 && current_step_ == 7)
335  {
336  GeometricObject* go = *(**reps.begin()).getGeometricObjects().begin();
337  Mesh* mesh = dynamic_cast<Mesh*>(go);
338  if (mesh != 0)
339  {
340  surface_ = new Mesh(*mesh);
341  }
342  else
343  {
344  // should not happen
346  surface_ = new Mesh();
347  }
348  }
349 
350  for (Position p = 0; p < nr; p++)
351  {
352  getMainControl()->remove(**reps.begin());
353  reps.pop_front();
354  }
355 
356  if (current_step_ < 9)
357  {
358  ModelType type = (ModelType) (current_step_ - 2);
359  if (type >= MODEL_SA_SURFACE)
360  {
361  type = (ModelType)((Index)type + 1);
362  }
364  }
365  else if (current_step_ == 9)
366  {
369  ms->calculateHBonds();
372 
373  }
374  else if (current_step_ == 10)
375  {
377  }
378  else if (current_step_ == 11)
379  {
381  }
382  else if (current_step_ == 12)
383  {
385  }
386  else if (current_step_ == 13 ||
387  current_step_ == 14)
388  {
392 
393  list<Composite*> composites;
394  composites.push_back(*getMainControl()->getCompositeManager().getComposites().begin());
395  MolecularControl::getInstance(0)->highlight(composites);
396 
397  if (current_step_ == 13)
398  {
400  ms->chooseAmberFF();
404  ms->runMinimization(false);
405  }
406  else
407  {
408  ms->getMDSimulationDialog().setTimeStep(0.002);
410  ms->MDSimulation(false);
411  }
412  }
413  else if (current_step_ == 15) //FDPB
414  {
416  if (!ms->calculateFDPB(false))
417  {
419  }
421  }
422  else if (current_step_ == 16) // SES colored
423  {
424  // Create a new representation containing the contour surface.
427  rep->insert(*new Mesh(*surface_));
428  getMainControl()->insert(*rep);
429 
430  ModifyRepresentationDialog* cdialog = ModifyRepresentationDialog::getInstance(0);
431  cdialog->setMode(0);
432  cdialog->setRepresentation(rep);
433  cdialog->setGrid(grid_);
434  cdialog->setMinValue(-0.7);
435  cdialog->setMaxValue(0.7);
436  cdialog->accept();
437 
438  getMainControl()->update(*rep);
439  }
440  else if (current_step_ == 17)
441  {
445 
447 
448  DatasetController* dc = DatasetControl::getInstance(0)->getController(RegularData3DController::type);
450  vector<Dataset*> grids = rcon.getDatasets();
451  if (grids.empty()) return;
452  rcon.computeIsoContourSurface(*grids[0], ColorRGBA(255,0,0), -0.1);
453  rcon.computeIsoContourSurface(*grids[0], ColorRGBA(0,0,255), 0.1);
454 
455  // last entry: we are done
456  }
457 }
458 
460 {
461  demo_mode_ = false;
462  show();
463 }
464 
466 {
467  demo_mode_ = true;
468  show();
469 }
470 
472 {
473  CompositeMessage* cmsg = RTTI::castTo<CompositeMessage>(*message);
474  RepresentationMessage* rmsg = RTTI::castTo<RepresentationMessage>(*message);
475 
476  if (rmsg != 0 && rmsg->getRepresentation() == 0) return;
477 
478  switch (current_step_)
479  {
480  case TUTORIAL_PEPTIDE: // "Building a peptide from a given sequence"
481  {
482  if (cmsg == 0 || cmsg->getType() != CompositeMessage::NEW_MOLECULE) return;
483  break;
484  }
485 
486  case TUTORIAL_ROTATE: // "Rotating"
487  {
488  if (!RTTI::isKindOf<SceneMessage>(*message)) return;
489  break;
490  }
491 
492  case TUTORIAL_HIERARCHY: // "Hierarchy of molecules"
493  {
494  break;
495  }
496 
497  case TUTORIAL_MDS: // "Molecular Dynamics Simulation")
498  {
499  if (!RTTI::isKindOf<DatasetMessage>(*message)) return;
500  DatasetMessage* msg = dynamic_cast<DatasetMessage*>(message);
501  if (msg->getDataset() == 0)
502  {
504  return;
505  }
506 
507  if (msg->getDataset()->getType() != TrajectoryController::type ||
508  msg->getType() != DatasetMessage::ADD)
509  {
510  return;
511  }
512 
513  break;
514  }
515 
516  case TUTORIAL_TRAJECTORY: // "Visualisation of trajectories")
517  {
518  if (cmsg != 0 && cmsg->getType() == CompositeMessage::CHANGED_COMPOSITE)
519  {
520  enableNextStep_();
521  }
522  break;
523  }
524 
525  case TUTORIAL_ES: // "Calculation of electrostatics"
526  {
527  if (!RTTI::isKindOf<DatasetMessage>(*message)) return;
528  DatasetMessage* msg = dynamic_cast<DatasetMessage*>(message);
529  if (msg->getDataset() == 0)
530  {
532  return;
533  }
534 
536  msg->getType() != DatasetMessage::ADD)
537  {
538  return;
539  }
540 
541  break;
542  }
543 
544  case TUTORIAL_SES: // "Creating a Solvent Excluded Surface"
545  {
546  if (rmsg == 0 ||
549  {
550  return;
551  }
552  break;
553  }
554 
555  case TUTORIAL_SES_COLORING: // "Coloring a SES by electrostatics"
556  {
557  if (rmsg == 0 ||
560  {
561  return;
562  }
563  break;
564  }
565 
566  case TUTORIAL_CS: // "Creating a isocontour surface"
567  {
568  if (rmsg == 0 ||
570  {
571  return;
572  }
573  break;
574  }
575 
576  default:
578  Log.error() << (String)tr("Current step") << ": " << current_step_ << std::endl;
579  return;
580  }
581 
582  enableNextStep_();
583 }
584 
586 {
588 
589  String description = "Shortcut|Help|Demo";
590  demo_action_ = insertMenuEntry(MainControl::HELP, (String)tr("Demo"), this, SLOT(showDemo()), description);
591  setMenuHint((String)tr("Show a demonstration of BALLView's features"));
592 
593  description = "Shortcut|Help|Tutorial";
594  tutorial_action_ = insertMenuEntry(MainControl::HELP, (String)tr("Tutorial"), this, SLOT(showTutorial()), description);
595  setMenuHint((String)tr("Perform a step-by-step tutorial"));
597 }
598 
600 {
601  bool busy = main_control.isBusy();
602  demo_action_->setEnabled(!busy);
603  tutorial_action_->setEnabled(!busy);
604 }
605 
606 } } // namespaces