00001
00002
00003
00004
00005 #include "mainframe.h"
00006 #include "icons.h"
00007 #include "demoTutorialDialog.h"
00008
00009 #include <BALL/VIEW/KERNEL/iconLoader.h>
00010 #include <BALL/VIEW/RENDERING/POVRenderer.h>
00011 #include <BALL/VIEW/RENDERING/VRMLRenderer.h>
00012 #include <BALL/VIEW/WIDGETS/molecularStructure.h>
00013 #include <BALL/VIEW/WIDGETS/molecularControl.h>
00014 #include <BALL/VIEW/WIDGETS/geometricControl.h>
00015 #include <BALL/VIEW/WIDGETS/logView.h>
00016 #include <BALL/VIEW/WIDGETS/helpViewer.h>
00017 #include <BALL/VIEW/WIDGETS/datasetControl.h>
00018 #include <BALL/VIEW/WIDGETS/editableScene.h>
00019 #include <BALL/VIEW/WIDGETS/fileObserver.h>
00020 #include <BALL/VIEW/DIALOGS/pubchemDialog.h>
00021 #include <BALL/VIEW/DIALOGS/undoManagerDialog.h>
00022 #include <BALL/VIEW/DIALOGS/downloadPDBFile.h>
00023 #include <BALL/VIEW/DIALOGS/downloadElectronDensity.h>
00024 #include <BALL/VIEW/DIALOGS/labelDialog.h>
00025 #include <BALL/VIEW/DIALOGS/displayProperties.h>
00026 #include <BALL/VIEW/DIALOGS/molecularFileDialog.h>
00027 #include <BALL/VIEW/DATATYPE/standardDatasets.h>
00028 #ifdef BALL_PYTHON_SUPPORT
00029 # include <BALL/VIEW/WIDGETS/pyWidget.h>
00030 # include <BALL/VIEW/WIDGETS/testFramework.h>
00031 #endif
00032
00033 #include <BALL/SYSTEM/path.h>
00034 #include <BALL/KERNEL/forEach.h>
00035 #include <BALL/COMMON/version.h>
00036
00037 #include <QtGui/QKeyEvent>
00038 #include <QtGui/QTreeWidget>
00039
00040 #include <BALL/CONCEPT/moleculeObjectCreator.h>
00041 #ifdef BALL_HAS_ASIO
00042 #include <BALL/VIEW/KERNEL/serverWidget.h>
00043 #endif
00044
00045 #include "ui_aboutDialog.h"
00046
00047 #include <BALL/VIEW/DIALOGS/pluginDialog.h>
00048
00049 using namespace std;
00050
00051
00052 namespace BALL
00053 {
00054 using namespace std;
00055 using namespace BALL::VIEW;
00056
00057 Mainframe::Mainframe(QWidget* parent, const char* name)
00058 : MainControl(parent, name, ".BALLView"),
00059 scene_(0)
00060 {
00061 #ifdef BALL_VIEW_DEBUG
00062 Log.error() << "new Mainframe " << this << std::endl;
00063 #endif
00064
00065
00066
00067
00068 setWindowTitle(tr("BALLView"));
00069 setWindowIcon(QPixmap(bucky_64x64_xpm));
00070
00071 initPopupMenu(FILE_OPEN);
00072 initPopupMenu(EDIT);
00073 initPopupMenu(BUILD);
00074 initPopupMenu(DISPLAY);
00075 initPopupMenu(MOLECULARMECHANICS);
00076 initPopupMenu(TOOLS);
00077 #ifdef BALL_PYTHON_SUPPORT
00078 initPopupMenu(TOOLS_PYTHON);
00079 initPopupMenu(MainControl::USER);
00080 #endif
00081 initPopupMenu(WINDOWS);
00082 initPopupMenu(MACRO);
00083
00084
00085
00086
00087
00088
00089 setLoggingFilename("BALLView.log");
00090
00091
00092 String description = "Shortcut|Display|Toggle_Fullscreen";
00093 fullscreen_action_ = insertMenuEntry(MainControl::DISPLAY, (String)tr("Toggle Fullscreen"), this,
00094 SLOT(toggleFullScreen()), description,
00095 QKeySequence("Alt+X"));
00096
00097 fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
00098
00099 insertPopupMenuSeparator(DISPLAY);
00100 initPopupMenu(DISPLAY_VIEWPOINT);
00101
00102 new MolecularFileDialog(this, ((String)tr("MolecularFileDialog")).c_str());
00103 new DownloadPDBFile( this, ((String)tr("DownloadPDBFile")).c_str(), false);
00104 new DownloadElectronDensity(this, ((String)tr("DownloadElectronDensity")).c_str(), false);
00105 new PubChemDialog( this, ((String)tr("PubChemDialog")).c_str());
00106 new PluginDialog( this, ((String)tr("PluginDialog")).c_str());
00107 new UndoManagerDialog( this, ((String)tr("UndoManagerDialog")).c_str());
00108
00109 addDockWidget(Qt::LeftDockWidgetArea, new MolecularControl(this, ((String)tr("Structures")).c_str()));
00110 addDockWidget(Qt::LeftDockWidgetArea, new GeometricControl(this, ((String)tr("Representations")).c_str()));
00111 addDockWidget(Qt::TopDockWidgetArea, new DatasetControl(this, ((String)tr("Datasets")).c_str()));
00112 DatasetControl* dc = DatasetControl::getInstance(0);
00113 dc->registerController(new RegularData3DController());
00114 dc->registerController(new TrajectoryController());
00115 dc->registerController(new VectorGridController());
00116 dc->registerController(new DockResultController());
00117
00118
00119
00120
00121 DatasetControl::getInstance(0)->hide();
00122
00123 new DemoTutorialDialog(this, ((String)tr("BALLViewDemo")).c_str());
00124
00125 Path path;
00126
00127
00128
00129 String dirp = path.find("../doc/BALL/");
00130
00131 if (dirp != "")
00132 {
00133 HelpViewer* BALL_docu = new HelpViewer(this, ((String)tr("BALL Docu")).c_str());
00134 addDockWidget(Qt::BottomDockWidgetArea, BALL_docu);
00135
00136
00137 BALL_docu->setBaseDirectory(dirp);
00138 BALL_docu->setWhatsThisEnabled(false);
00139 BALL_docu->setProject("BALL");
00140 BALL_docu->setDefaultPage("index.html");
00141
00142 }
00143
00144 addDockWidget(Qt::BottomDockWidgetArea, new HelpViewer(this, "BALLView Docu"));
00145 new LabelDialog( this, ((String)tr("LabelDialog")).c_str());
00146 new MolecularStructure( this, ((String)tr("MolecularStructure")).c_str());
00147 addDockWidget(Qt::BottomDockWidgetArea, new LogView( this, ((String)tr("Logs")).c_str()));
00148 addDockWidget(Qt::BottomDockWidgetArea, new FileObserver( this, ((String)tr("FileObserver")).c_str()));
00149
00150 Scene::stereoBufferSupportTest();
00151 scene_ = new EditableScene(this, ((String)tr("3D View")).c_str());
00152 setCentralWidget(scene_);
00153 setAcceptDrops(true);
00154
00155 new DisplayProperties(this, ((String)tr("DisplayProperties")).c_str());
00156
00157
00158 #ifdef BALL_HAS_ASIO
00159 ServerWidget* server = new ServerWidget(this);
00160
00161 MoleculeObjectCreator* object_creator = new MoleculeObjectCreator;
00162 server->registerObjectCreator(*object_creator);
00163 #endif
00164
00165 #ifdef BALL_PYTHON_SUPPORT
00166 new TestFramework(this, ((String)"Test Framework").c_str());
00167 addDockWidget(Qt::BottomDockWidgetArea, new PyWidget(this, ((String)tr("Python Interpreter")).c_str()));
00168 #endif
00169
00170
00171
00172
00173
00174 description = "Shortcut|File|Open|Project";
00175 insertMenuEntry(MainControl::FILE_OPEN, ((String)tr("Project")).c_str(), this,
00176 SLOT(loadBALLViewProjectFile()), description);
00177
00178 description = "Shortcut|File|Save_Project";
00179 save_project_action_ = insertMenuEntry(MainControl::FILE, ((String)tr("Save Project")).c_str(), this,
00180 SLOT(saveBALLViewProjectFile()), description);
00181
00182
00183 QAction* action = 0;
00184
00185 description = "Shortcut|Help|About";
00186 action = insertMenuEntry(MainControl::HELP, (String)tr("About"), this, SLOT(about()), description);
00187 setMenuHint(action, (String)tr("Show informations on this version of BALLView"));
00188
00189 description = "Shortcut|Help|How_to_cite";
00190 action = insertMenuEntry(MainControl::HELP, (String)tr("How to cite"), this, SLOT(howToCite()), description);
00191 setMenuHint(action, (String)tr("Show infos on how to cite BALL and BALLView"));
00192
00193
00194 description = "Shortcut|MolecularMechanics|Abort_Calculation";
00195 stop_simulation_action_ = insertMenuEntry(MainControl::MOLECULARMECHANICS, (String)tr("Abort Calculation"), this,
00196 SLOT(stopSimulation()), description,
00197 QKeySequence("Alt+C"));
00198 stop_simulation_action_->setEnabled(false);
00199 insertPopupMenuSeparator(MainControl::MOLECULARMECHANICS);
00200 setMenuHint(stop_simulation_action_, (String)tr("Abort a running simulation"));
00201
00202 stop_simulation_action_->setIcon(IconLoader::instance().getIcon("actions/process-stop"));
00203
00204 description = "Shortcut|Edit|Invert_Selection";
00205 complement_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Invert Selection"), this,
00206 SLOT(complementSelection()), description);
00207
00208 description = "Shortcut|Edit|Clear_Selection";
00209 clear_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Clear Selection"), this,
00210 SLOT(clearSelection()), description);
00211
00212
00213 qApp->installEventFilter(this);
00214
00215 setStatusbarText((String)tr("Ready."));
00216 }
00217
00218 Mainframe::~Mainframe()
00219 {
00220 }
00221
00222
00223 bool Mainframe::eventFilter(QObject* sender, QEvent* event)
00224 {
00225 if (event->type() != QEvent::KeyPress) return false;
00226
00227 QKeyEvent* e = dynamic_cast<QKeyEvent*>(event);
00228
00229 if (e->key() == Qt::Key_Escape &&
00230 HelpViewer::getInstance("BALLView Docu")->isWhatsThisEnabled())
00231 {
00232 HelpViewer::getInstance("BALLView Docu")->exitWhatsThisMode();
00233 }
00234
00235 QPoint point = QCursor::pos();
00236 QWidget* widget = qApp->widgetAt(point);
00237 if (widget == scene_ &&
00238 qApp->focusWidget() != scene_)
00239 {
00240 scene_->keyPressEvent(e);
00241 return true;
00242 }
00243
00244 if (e->key() == Qt::Key_Delete &&
00245 RTTI::isKindOf<QTreeWidget>(*sender))
00246 {
00247 deleteClicked();
00248 return true;
00249 }
00250
00251 if (e->key() == Qt::Key_Enter)
00252 {
00253 if (composite_manager_.getNumberOfComposites() == 0) return false;
00254
00255 if (getMolecularControlSelection().size() == 0)
00256 {
00257 control_selection_.push_back(*composite_manager_.begin());
00258 }
00259
00260 MolecularStructure::getInstance(0)->centerCamera();
00261 return true;
00262 }
00263
00264
00265 if (e->key() == Qt::Key_Alt ||
00266 e->key() == Qt::Key_Control)
00267 {
00268 checkMenus();
00269 return false;
00270 }
00271
00272 #ifdef BALL_PYTHON_SUPPORT
00273 PyWidget::getInstance(0)->reactTo(*e);
00274 e->accept();
00275 #endif
00276
00277 return false;
00278 }
00279
00280
00281 void Mainframe::reset()
00282 {
00283 if (composites_locked_ || getRepresentationManager().updateRunning()) return;
00284
00285 clearData();
00286
00287 DisplayProperties* dp = DisplayProperties::getInstance(0);
00288 dp->setDrawingPrecision(DRAWING_PRECISION_HIGH);
00289 dp->selectModel(MODEL_STICK);
00290 dp->selectColoringMethod(COLORING_ELEMENT);
00291 dp->selectMode(DRAWING_MODE_SOLID);
00292 dp->setTransparency(0);
00293 dp->setSurfaceDrawingPrecision(6.5);
00294 }
00295
00296
00297 void Mainframe::howToCite()
00298 {
00299 HelpViewer::getInstance("BALLView Docu")->showHelp("tips.html", (String)tr("cite"));
00300 }
00301
00302 void Mainframe::show()
00303 {
00304
00305 if (preferences_action_ != 0)
00306 {
00307 MainControl::show();
00308 return;
00309 }
00310
00311
00312 QToolBar* tb = new QToolBar("Main Toolbar", this);
00313 tb->setObjectName(tr("Main Toolbar"));
00314 tb->setIconSize(QSize(22,22));
00315 addToolBar(Qt::TopToolBarArea, tb);
00316
00317 MainControl::show();
00318
00319 initPopupMenu(MainControl::WINDOWS)->addSeparator();
00320 initPopupMenu(MainControl::WINDOWS)->addAction(tb->toggleViewAction());
00321 MolecularFileDialog::getInstance(0)->addToolBarEntries(tb);
00322 DownloadPDBFile::getInstance(0)->addToolBarEntries(tb);
00323 DownloadElectronDensity::getInstance(0)->addToolBarEntries(tb);
00324 PubChemDialog::getInstance(0)->addToolBarEntries(tb);
00325 UndoManagerDialog::getInstance(0)->addToolBarEntries(tb);
00326 tb->addAction(fullscreen_action_);
00327 Path path;
00328
00329 IconLoader& loader = IconLoader::instance();
00330 qload_action_ = new QAction(loader.getIcon("actions/quickopen-file"), tr("quickload"), this);
00331 qload_action_->setObjectName(tr("quickload"));
00332 connect(qload_action_, SIGNAL(triggered()), this, SLOT(quickLoadConfirm()));
00333 HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qload_action_, "tips.html#quickload");
00334 tb->addAction(qload_action_);
00335
00336 qsave_action_ = new QAction(loader.getIcon("actions/quicksave"), tr("quicksave"), this);
00337 qsave_action_->setObjectName(tr("quicksave"));
00338 connect(qsave_action_, SIGNAL(triggered()), this, SLOT(quickSave()));
00339 HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qsave_action_, "tips.html#quickload");
00340 tb->addAction(qsave_action_);
00341
00342 tb->addSeparator();
00343 DisplayProperties::getInstance(0)->addToolBarEntries(tb);
00344 MolecularStructure::getInstance(0)->addToolBarEntries(tb);
00345 scene_->addToolBarEntries(tb);
00346 tb->addAction(stop_simulation_action_);
00347 tb->addAction(preferences_action_);
00348 HelpViewer::getInstance("BALLView Docu")->addToolBarEntries(tb);
00349
00350
00351
00352 restoreWindows();
00353
00354
00355 applyPreferences();
00356 }
00357
00358 void Mainframe::about()
00359 {
00360
00361 QDialog w;
00362 Ui_AboutDialog about;
00363 about.setupUi(&w);
00364 QString version = QString(tr("QT ")) + qVersion();
00365 #ifdef BALL_QT_HAS_THREADS
00366 version += "(mt)";
00367 #endif
00368 about.qt_version_label->setText(version);
00369 QFont font = about.BALLView_version_label->font();
00370 about.BALLView_version_label->setText(QString("BALLView ") + BALL_RELEASE_STRING);
00371 font.setPixelSize(18);
00372 about.BALLView_version_label->setFont(font);
00373 about.BALL_version_label->setText(__DATE__);
00374
00375
00376 Path p;
00377 String logo_path = p.find("graphics/logo.png");
00378
00379 if (logo_path != "")
00380 about.BALLView_logo_label->setPixmap(QPixmap(logo_path.c_str()));
00381
00382 w.exec();
00383 }
00384
00385 void Mainframe::changeEvent(QEvent* evt)
00386 {
00387 if(evt->type() == QEvent::WindowStateChange) {
00388 if (isFullScreen())
00389 {
00390 fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-restore"));
00391 } else {
00392 fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
00393 }
00394 }
00395 }
00396
00397 }