26 #include <QtWidgets/QPushButton>
27 #include <QtWidgets/QMessageBox>
28 #include <QtWidgets/QTextBrowser>
51 DemoTutorialDialog::DemoTutorialDialog(
QWidget* parent,
const char* name)
53 Ui_DemoTutorialDialogData(),
62 demo_action_(nullptr),
63 tutorial_action_(nullptr),
64 raytracing_tutorial_action_(nullptr)
66 #ifdef BALL_VIEW_DEBUG
67 Log.
error() <<
"new DemoTutorialDialog " <<
this << std::endl;
77 connect(cancel_button, SIGNAL(clicked()),
this, SLOT(hide()));
82 #ifdef BALL_VIEW_DEBUG
83 Log.
error() <<
"deleting DemoTutorialDialog " <<
this << std::endl;
91 setWindowTitle(tr(
"BALLView Demo"));
95 next_button->setEnabled(
true);
101 if (LogView::getInstance(0) != 0) LogView::getInstance(0)->hide();
102 if (DatasetControl::getInstance(0) != 0) DatasetControl::getInstance(0)->hide();
104 #ifdef BALL_HAS_RTFACT
107 Stage* stage = Scene::getInstance(0)->getStage();
110 StageSettings* stage_settings = Scene::getInstance(0)->getStageSettings();
126 LightSettings::getInstance(0)->updateFromStage();
128 Scene::getInstance(0)->applyPreferences();
140 if (tutorial_type_ == TUTORIAL)
142 setWindowTitle(tr(
"BALLView Tutorial"));
145 else if (tutorial_type_ == RAYTRACING_TUTORIAL)
147 setWindowTitle(tr(
"Ray tracing Tutorial"));
151 next_button->setEnabled(
false);
153 #ifdef BALL_HAS_RTFACT
157 Scene::getInstance(0)->show();
158 MolecularControl::getInstance(0)->show();
159 MolecularControl::getInstance(0)->setFloating(
false);
160 MolecularControl::getInstance(0)->applyPreferences();
161 GeometricControl::getInstance(0)->show();
162 GeometricControl::getInstance(0)->applyPreferences();
163 GeometricControl::getInstance(0)->setFloating(
false);
167 Stage* stage = Scene::getInstance(0)->getStage();
171 StageSettings* stage_settings = Scene::getInstance(0)->getStageSettings();
186 LightSettings::getInstance(0)->updateFromStage();
188 if (tutorial_type_ == TUTORIAL)
190 DatasetControl::getInstance(0)->show();
191 DatasetControl::getInstance(0)->applyPreferences();
192 DatasetControl::getInstance(0)->setFloating(
false);
194 else if (tutorial_type_ == RAYTRACING_TUTORIAL)
196 #ifdef BALL_HAS_RTFACT
211 Scene::getInstance(0)->getMaterialSettings()->updateDefaultMaterialsFromStage();
217 Scene::getInstance(0)->applyPreferences();
219 next_button->setEnabled(
true);
221 Log.
info() <<
"DemoTutorialDialog: no RTFact available! Close the dialog!" << __FILE__ <<
" " << __LINE__ << endl;
225 LogView::getInstance(0)->hide();
232 if (tutorial_type_ == DEMO)
238 int result = QMessageBox::question(
this, tr(
"Warning"),
239 tr(
"To start the tutorial, all loaded structures and molecules will be deleted."),
240 QMessageBox::Ok| QMessageBox::Cancel, QMessageBox::Ok);
241 if (result != QMessageBox::Ok)
return;
246 QUrl qurl = QUrl::fromLocalFile((prefix_ +
"01.html").c_str());
247 text_browser->setSource(qurl);
256 if (!isVisible())
return;
258 switch (tutorial_type_)
266 case RAYTRACING_TUTORIAL:
276 if (current_step_ == 13 || current_step_ == 14)
278 if (!RTTI::isKindOf<FinishedSimulationMessage>(message))
return;
280 else if (current_step_ == 15)
291 RegularData3DDataset* set =
dynamic_cast<RegularData3DDataset*
>(msg->
getDataset());
296 else if (current_step_ == 16)
298 SceneMessage* msg = RTTI::castTo<SceneMessage>(*message);
315 next_button->setEnabled(
true);
322 if (
id.size() == 1)
id =
"0" + id;
324 id = prefix_ +
id +
".html";
326 QUrl qurl = QUrl::fromLocalFile(
id.c_str());
327 text_browser->setSource(qurl);
328 next_button->setEnabled(
false);
330 if (tutorial_type_ == DEMO)
332 if (current_step_ == 17)
340 #ifdef BALL_HAS_RTFACT
342 if (current_step_ == 11)
345 next_button->setEnabled(
true);
350 else if (tutorial_type_ == TUTORIAL)
352 if (current_step_ == 8)
354 next_button->setEnabled(
true);
357 else if (tutorial_type_ == RAYTRACING_TUTORIAL)
359 switch (current_step_)
365 Scene::getInstance(0)->getStage()->setBackgroundColor(color);
366 StageSettings* stage_settings = Scene::getInstance(0)->getStageSettings();
368 Scene::getInstance(0)->applyPreferences();
376 LightSource& ls = Scene::getInstance(0)->getStage()->getLightSource(0);
382 LightSettings::getInstance(0)->updateFromStage();
385 Camera& camera = Scene::getInstance(0)->getStage()->getCamera();
389 Scene::getInstance(0)->applyPreferences();
395 if (
getMainControl()->getCompositeManager().getComposites().size() == 0)
397 Log.
info() <<
"DemoTutorialDialog: no system available! " << __FILE__ <<
" " << __LINE__ << endl;
415 HashSet<Composite*> composites = MainControl::getInstance(0)->getCompositeManager().getComposites();
431 Log.
info() <<
"DemoTutorialDialog.addPlane(): No system given! "<< __FILE__ <<
" " << __LINE__ << endl;
438 system =
dynamic_cast<System*
>(*sit);
446 if (v_low.
x > low.
x) v_low.
x = low.
x;
447 if (v_low.
y > low.
y) v_low.
y = low.
y;
448 if (v_low.
z > low.
z) v_low.
z = low.
z;
450 if (v_upp.
x < upp.
x) v_upp.
x = upp.
x;
451 if (v_upp.
y < upp.
y) v_upp.
y = upp.
y;
452 if (v_upp.
z < upp.
z) v_upp.
z = upp.
z;
462 height = height*(-1);
463 boundary = boundary*(-1);
474 if (plane_specifier ==
'x')
476 v_low = v_low -
Vector3(height, boundary, boundary);
477 v_upp = v_upp +
Vector3(height, boundary, boundary);
478 v_low_left =
Vector3(v_low.
x, v_low.
y, v_low.
z);
479 v_low_right =
Vector3(v_low.
x, v_upp.
y, v_low.
z);
480 v_upp_right =
Vector3(v_low.
x, v_upp.
y, v_upp.
z);
481 v_upp_left =
Vector3(v_low.
x, v_low.
y, v_upp.
z);
484 else if (plane_specifier ==
'y')
486 v_low = v_low -
Vector3(boundary, height, boundary);
487 v_upp = v_upp +
Vector3(boundary, height, boundary);
488 v_low_left =
Vector3(v_low.
x, v_low.
y, v_low.
z);
489 v_low_right =
Vector3(v_low.
x, v_low.
y, v_upp.
z);
490 v_upp_right =
Vector3(v_upp.
x, v_low.
y, v_upp.
z);
491 v_upp_left =
Vector3(v_upp.
x, v_low.
y, v_low.
z);
494 else if (plane_specifier ==
'z')
496 v_low = v_low -
Vector3(boundary, boundary, height);
497 v_upp = v_upp +
Vector3(boundary, boundary, height);
498 v_low_left =
Vector3(v_low.
x, v_low.
y, v_low.
z);
499 v_low_right =
Vector3(v_low.
x, v_upp.
y, v_low.
z);
500 v_upp_right =
Vector3(v_upp.
x, v_upp.
y, v_low.
z);
501 v_upp_left =
Vector3(v_upp.
x, v_low.
y, v_low.
z);
506 Log.
info() <<
"DemoTutorialDialog.addPlane(): unknown plane_specifier! "<< __FILE__ <<
" " << __LINE__ << endl;
514 plane->
vertex.push_back(v_low_left);
515 plane->
vertex.push_back(v_low_right);
516 plane->
vertex.push_back(v_upp_right);
517 plane->
vertex.push_back(v_upp_left);
536 for (
int i=0; i<4; i++)
537 plane->
normal.push_back(normal);
561 if (current_step_ == 1)
572 String file_name = path.
find(
"structures/bpti.pdb");
583 String msg((
String)tr(
"Could not open bpti.pdb. Maybe the file was deleted?")+
"\n");
584 msg += (
String)tr(
"It should be found in") +
" " + file_name;
586 QMessageBox::critical(0, tr(
"Error while starting BALLView Demo"), msg.
c_str(),
587 QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
602 composites_.push_back(system_);
605 if (current_step_ == 17)
612 next_button->setEnabled(current_step_ >= 14);
619 if (!surface_ && nr == 1 && current_step_ == 6)
622 Mesh* mesh =
dynamic_cast<Mesh*
>(go);
625 surface_ =
new Mesh(*mesh);
631 surface_ =
new Mesh();
641 if (current_step_ < 6)
650 else if (current_step_ < 8)
659 else if (current_step_ == 8)
665 #ifndef BALL_HAS_RTFACT
669 else if (current_step_ == 9)
673 else if (current_step_ == 10)
677 else if (current_step_ == 11)
681 else if (current_step_ == 12 || current_step_ == 13)
687 list<Composite*> composites;
688 composites.push_back(*
getMainControl()->getCompositeManager().getComposites().begin());
689 MolecularControl::getInstance(0)->highlight(composites);
691 if (current_step_ == 12)
697 #ifdef BALL_HAS_RTFACT
711 else if (current_step_ == 14)
720 else if (current_step_ == 15)
738 else if (current_step_ == 16)
749 if (grids.empty())
return;
759 tutorial_type_ = RAYTRACING_TUTORIAL;
766 tutorial_type_ = TUTORIAL;
772 tutorial_type_ = DEMO;
783 switch (current_step_)
793 if (!RTTI::isKindOf<SceneMessage>(message))
return;
804 if (!RTTI::isKindOf<DatasetMessage>(message))
return;
831 if (!RTTI::isKindOf<DatasetMessage>(message))
return;
881 Log.
error() << (
String)tr(
"Current step") <<
": " << current_step_ << std::endl;
895 switch (current_step_)
909 if (Scene::getInstance(0)->getStage()->getBackgroundColor() !=
ColorRGBA(0, 0, 0, 255))
return;
914 if (!RTTI::isKindOf<SceneMessage>(message))
return;
920 if (Scene::getInstance(0)->getStage()->getLightSources().size() != 2)
return;
938 cout <<
"*7*" << cmsg->
getType() << endl;
943 Log.
error() <<
"Current step: " << current_step_ << std::endl;
954 String description =
"Shortcut|Help|Demo";
956 description, QKeySequence(),
957 tr(
"Show a demonstration of BALLView's features"),
960 description =
"Shortcut|Help|Tutorial";
962 description, QKeySequence(), tr(
"Perform a step-by-step tutorial"),
965 #ifdef BALL_HAS_RTFACT
966 description =
"Shortcut|Help|RaytracingTutorial";
978 bool busy = main_control.
isBusy();
980 demo_action_->setEnabled(!busy);
981 if (tutorial_action_)
982 tutorial_action_->setEnabled(!busy);
983 if (raytracing_tutorial_action_)
984 raytracing_tutorial_action_->setEnabled(!busy);