BALL  1.5.0
mainControl.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_VIEW_KERNEL_MAINCONTROL_H
6 #define BALL_VIEW_KERNEL_MAINCONTROL_H
7 
8 #ifndef BALL_CONCEPT_EMBEDDABLE_H
10 #endif
11 
12 #ifndef BALL_DATATYPE_HASHMAP_H
13 # include <BALL/DATATYPE/hashMap.h>
14 #endif
15 
16 #ifndef BALL_VIEW_KERNEL_CONNECTIONOBJECT_H
18 #endif
19 
20 #ifndef BALL_VIEW_KERNEL_REPRESENTATIONMANAGER_H
22 #endif
23 
24 #ifndef BALL_VIEW_KERNEL_COMPOSITEMANAGER_H
26 #endif
27 
28 #ifndef BALL_VIEW_KERNEL_SHORTCUTREGISTRY_H
30 #endif
31 
32 #ifndef BALL_VIEW_KERNEL_UIOPERATIONMODE_H
34 #endif
35 
36 #ifndef BALL_VIEW_KERNEL_UIOPERATIONMODE_H
38 #endif
39 
40 #ifndef BALL_FORMAT_INIFILE_H
41 # include <BALL/FORMAT/INIFile.h>
42 #endif
43 
44 #ifndef BALL_SYSTEM_FILE_H
45 # include <BALL/SYSTEM/file.h>
46 #endif
47 
48 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
50 #endif
51 
52 #include <QtGui/QKeySequence>
53 #include <QtWidgets/QMainWindow>
54 #include <QtWidgets/QApplication>
55 #include <QtWidgets/QMenuBar>
56 #include <QtWidgets/QLabel>
57 #include <QtCore/QTimer>
58 
59 class QCloseEvent;
60 
61 namespace BALL
62 {
63  namespace VIEW
64  {
65  class ModelInformation;
66  class ModularWidget;
67  class Preferences;
68  class MainControlPreferences;
69  class OpenSavePreferences;
70  class NetworkPreferences;
71  class GeometricObjectSelectionMessage;
72  class SimulationThread;
73 
115  : public QMainWindow,
116  public ConnectionObject,
117  public Embeddable
118  {
119  friend class RepresentationManager;
120  friend class SimulationThread;
121 
122  Q_OBJECT
123 
124  public:
125 
127 
128 
136  enum PopUpID
137  {
139  FILE = 10001,
140 
143 
146 
149 
152 
155 
157  EDIT = 10100,
158 
160  BUILD = 10200,
161 
163  DISPLAY = 10300,
164 
167 
170 
173 
176 
177 #ifdef BALL_HAS_RTFACT
179  DISPLAY_CONTINUOUSLOOP,
180 #endif
182  MOLECULARMECHANICS = 10400,
183 
186 
188  TOOLS = 10500,
189 
192 
195 
197  WINDOWS = 10600,
198 
200  USER = 10700,
201 
203  MACRO = 10750,
204 
207  HELP = 10800
208  };
209 
211 
214 
230  MainControl(QWidget* parent = 0, const char* name = 0 , String inifile = ".BALL.preferences");
231 
235  virtual ~MainControl();
236 
237  // copy ctor needed for Python support only!
238  MainControl(const MainControl& main_control);
239 
242  virtual void clear();
243 
246  void clearData();
247 
249 
252 
257  { return primitive_manager_;}
258 
264  bool insert(Representation& rep);
265 
270  bool remove(Representation& rep);
271 
276  bool update(Representation& rep);
277 
293  bool updateRepresentationsOf(const Composite& composite, bool rebuild = true, bool force = false);
294 
299  void redrawAllRepresentations(bool rebuild_display_lists = false);
300 
302 
308  ShortcutRegistry& getShortcutRegistry() { return shortcut_registry_;}
309 
310 
312  //
316 
321  { return composite_manager_;}
322 
329  bool insert(Composite& composite, String name = "", bool normalize = true);
330 
337  bool remove(Composite& composite, bool to_delete = true, bool update = true);
338 
347  void update(Composite& composite, bool changed_hierarchy = true);
348 
351 
354 
356  std::list<Composite*>& getMolecularControlSelection();
357 
360 
362  void selectCompositeRecursive(Composite* composite, bool first_call=false);
363 
365  void deselectCompositeRecursive(Composite* composite, bool first_call=false);
366 
376 
377 
379 
382 
384  void saveBALLViewProjectFile(const String& filename, bool binary = true);
385 
387  void loadBALLViewProjectFile(const String& filename);
388 
395  virtual void fetchPreferences(INIFile &inifile);
396 
404  virtual void writePreferences(INIFile &inifile);
405 
407  virtual void restoreWindows();
408 
410  virtual void restoreWindows(const INIFile& inifile);
411 
415 
418  const INIFile& getINIFile() const;
419 
424 
433  virtual void applyPreferences();
434 
435 
437 
440 
453  static MainControl* getMainControl(const QObject* object);
454 
461 
468 
480  virtual void onNotify(Message *message);
481 
487  void sendMessage(Message& message);
488 
489 
491 
494 
507  QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
508  const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence(),
510 
523  QAction* insertMenuEntry(Position parent_id, const QString& name, const QObject* receiver = 0,
524  const char* slot = 0, const QString& description = "", QKeySequence accel = QKeySequence(),
526 
528  virtual QMenu* addMenu(const QString& title, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
529 
531  void removeMenuEntry (Index parent_id, QAction* action);
532 
541 
548 
550  void setMenuHint(QAction* id, const String& hint);
551 
553  String getMenuHint(QAction* id) const;
554 
558  void setDeleteEntryEnabled(bool state);
559 
564 
566  QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
567 
569 
572 
576  bool compositesAreLocked() const;
577 
584 
587 
590 
593 
595  bool stopedSimulation() { return stop_simulation_;}
596 
603 
608 
622 
624  void setMultithreading(bool state)
625  {multi_threading_mode_ = state;}
626 
628  bool isBusy() const;
629 
631  void wait();
632 
634  void processEvents(Size ms);
635 
636 
638 
641 
649  void setStatusbarText(const String& text, bool important = false, bool beep = false);
650 
652  void setStatusbarText(const QString& text, bool important = false, bool beep = false);
653 
656 
658  const FragmentDB& getFragmentDB() const
659  { return fragment_db_;}
660 
663 
666 
672  { return working_dir_;}
673 
675  void setWorkingDir(const String& dir);
676 
680 
684 
688  void setLoggingFilename(const String& string);
689 
691  const String& getLoggingFilename() const;
692 
694  bool isAboutToQuit() { return about_to_quit_;}
695 
696 
698 
701 
708  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
709 
717  virtual void openFile(const String& file) ;
718 
719 
722  virtual QMenu* createPopupMenu();
723 
725 
728 
729  public Q_SLOTS:
730 
746  virtual void show();
747 
758  virtual void checkMenus();
759 
762 
765 
770 
783  virtual void aboutToExit();
784 
790  void menuItemHighlighted(QAction* action);
791 
793  virtual bool event(QEvent* e);
794 
796  virtual void quit(int return_value = 0);
797 
799  virtual void resize(int w, int h );
800 
802  void setContentSize(int w, int h);
803 
806 
808  void quickSave();
809 
811  void quickLoad();
812 
815 
818 
821 
823 
824  protected Q_SLOTS:
825 
826  /*_ This slot is called internally whenever the apply button
827  of the Preferences dialog is pressed.
828  It calls among other things the method applyPreferences().
829  */
830  virtual void applyPreferencesClicked_();
831 
832  /*_ This slot is called internally whenever the ok button
833  of the Preferences dialog is pressed.
834  It calls among other things the method applyPreferences().
835  */
836  virtual void okPreferencesClicked_();
837 
838  //_ Called by timer to clear the text in the statusbar
840 
841  // Connected to the delete entry
842  virtual void deleteClicked();
843 
845 
846  protected:
847 
849 
850  //_ Called after receiving an SimulationThreadFinished event
852 
855 
856  /*_ Remove a composite.
857  Every Representation, which was created for the Composite is deleted, by sending a
858  RepresentationMessage with type RepresentationMessage::REMOVE.\par
859  Redraws representations of the parent of the Composite, if wished.
860  \return bool <tt>true</tt> if the CompositeManager has the Composite
861  */
862  bool remove_(Composite& composite, bool update_representations_of_parent = true,
863  bool to_delete = true);
864 
865  /*_ Select the composite parents of the geometric objects.
866  The GeometricObjectSelectionMessage is sent by the Scene.
867  */
869 
870  void reduceSelection_(Composite* const composite);
871 
872  //_ Called by constructors
873  void setup_();
874 
876 
879  void setBusyMode_(bool state);
880 
881  //_
882  void setPreferencesEnabled_(bool state);
883 
884  void init_();
885 
886  virtual void closeEvent(QCloseEvent* evt);
887 
890 
891  //_
893 
895 
896  /*_ List with the selected composites
897  */
899 
900  /*_ List with the selected composites of the control.
901  (Not the one with the checkboxes!)
902  */
903  std::list<Composite*> control_selection_;
904 
905  /*_ Message label in the statusbar
906  \see setStatusbarText
907  */
908  QLabel* message_label_;
909 
913 
919 
923 
925 
926  /*_ A list containing all modular widgets.
927  This list is modified by addModularWidget and
928  removeModularWidget.
929  */
930  std::list<ModularWidget*> modular_widgets_;
931 
933  QLabel* rep_label_;
934  static const char *simulation_running_xpm_[];
935  static const char *simulation_stoped_xpm_[];
937 
939 
943 
947  QTimer timer_;
950 
955  QAction* open_action_;
957  QAction* delete_action_;
958 
961  QPoint last_point_;
962  QSize last_size_;
963  QByteArray last_state_;
964 };
965 
966 # ifndef BALL_NO_INLINE_FUNCTIONS
967 # include <BALL/VIEW/KERNEL/mainControl.iC>
968 # endif
969 
970  } // namespace VIEW
971  } // namespace BALL
972 
973 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition: embeddable.h:31
Definition: constants.h:13
BALL_INDEX_TYPE Index
BALL_EXTERN_VARIABLE const double h
Definition: constants.h:102
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:74
virtual QMenu * createPopupMenu()
QAction * stop_simulation_action_
Definition: mainControl.h:951
virtual void restoreWindows(const INIFile &inifile)
Restore the positions the main window and of all DockWindow's from a given inifile.
System * getSelectedSystem()
If exactly one System is selected in the Control, return a pointer to this system,...
virtual void openFile(const String &file)
virtual void dump(std::ostream &s=std::cout, Size depth=0) const
String getStatusbarText() const
void update(Composite &composite, bool changed_hierarchy=true)
ShortcutRegistry & getShortcutRegistry()
Definition: mainControl.h:308
bool remove(Composite &composite, bool to_delete=true, bool update=true)
bool insert(Representation &rep)
RepresentationManager primitive_manager_
Definition: mainControl.h:910
bool update(Representation &rep)
QAction * last_highlighted_menu_entry_
Definition: mainControl.h:959
ModularWidget * getLockingWidget()
Get the ModularWidget with excluse access to the Composites.
void loadBALLViewProjectFile(const String &filename)
Load a BALLView project file.
void setContentSize(int w, int h)
OpenSavePreferences * open_save_preferences_
Definition: mainControl.h:915
void selectComposites_(GeometricObjectSelectionMessage &message)
virtual void fetchPreferences(INIFile &inifile)
virtual void resize(int w, int h)
overloaded from QT for Python Interface
void stopSimulation()
Stop a currently running calculation.
void setStatusbarText(const String &text, bool important=false, bool beep=false)
void wait()
Wait until the MainControl is not busy anymore.
void sendMessage(Message &message)
virtual void applyPreferences()
NetworkPreferences * network_preferences_
Definition: mainControl.h:916
void quickSave()
Create a BALLView project file with the name quick.bvp in the users home dir.
QAction * clear_selection_action_
Definition: mainControl.h:954
bool stopedSimulation()
Returns true, if the simulation was told to stop, but hasnt done this so far.
Definition: mainControl.h:595
QAction * getLastHighLightedMenuEntry()
Get the ID of the last highlighted menu entry.
Definition: mainControl.h:566
Preferences * preferences_dialog_
Definition: mainControl.h:917
virtual void clear()
virtual QMenu * initPopupMenu(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
QAction * fullscreen_action_
Definition: mainControl.h:952
void redrawAllRepresentations(bool rebuild_display_lists=false)
QAction * complement_selection_action_
Definition: mainControl.h:953
RepresentationManager & getRepresentationManager()
Definition: mainControl.h:256
Preferences * getPreferences()
bool compositesAreLocked() const
bool lockCompositesFor(ModularWidget *widget)
virtual void restoreWindows()
Restore the positions the main window and of all DockWindow's from the INIFile assigned to this insta...
SimulationThread * simulation_thread_
Definition: mainControl.h:924
void complementSelectionHelper_(Composite &c)
HashMap< Position, QMenu * > id_to_menu_
Definition: mainControl.h:960
bool remove(Representation &rep)
void saveBALLViewProjectFile(const String &filename, bool binary=true)
Save the current configuration, structures and representations to a BALLView project file (*....
QAction * insertMenuEntry(Position parent_id, const QString &name, const QObject *receiver=0, const char *slot=0, const QString &description="", QKeySequence accel=QKeySequence(), UIOperationMode::OperationMode minimal_mode=UIOperationMode::MODE_ALL)
QAction * insertMenuEntry(Position parent_id, const String &name, const QObject *receiver=0, const char *slot=0, const String &description="", QKeySequence accel=QKeySequence(), UIOperationMode::OperationMode minimal_mode=UIOperationMode::MODE_ALL)
virtual void okPreferencesClicked_()
void removeModularWidget(ModularWidget *widget)
bool insert(Composite &composite, String name="", bool normalize=true)
void addModularWidget(ModularWidget *widget)
void setBusyMode_(bool state)
virtual bool event(QEvent *e)
Interface to QT events, e.g. to communicate with other threads.
void menuItemHighlighted(QAction *action)
bool remove_(Composite &composite, bool update_representations_of_parent=true, bool to_delete=true)
void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
void setMenuHint(QAction *id, const String &hint)
Set a hint for a menu entry.
virtual void closeEvent(QCloseEvent *evt)
virtual void aboutToExit()
HashSet< Composite * > selection_
Definition: mainControl.h:898
virtual void quit(int return_value=0)
Make the program exit.
HashSet< Composite * > & getSelection()
Get the HashSet with the selected (e.g. picked) Composite objects.
const INIFile & getINIFile() const
void processEvents(Size ms)
Added overloaded method from QApplication for access in Python.
SimulationThread * getSimulationThread()
const FragmentDB & getFragmentDB() const
Get a const reference for the fragment database.
Definition: mainControl.h:658
QAction * preferences_action_
Definition: mainControl.h:956
bool unlockCompositesFor(ModularWidget *widget)
Lock the Composites for a given Modular Widget.
ShortcutRegistry shortcut_registry_
Definition: mainControl.h:912
ModelInformation * model_information_
Definition: mainControl.h:894
virtual QMenu * addMenu(const QString &title, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
std::list< Composite * > control_selection_
Definition: mainControl.h:903
virtual void writePreferences(INIFile &inifile)
void setDeleteEntryEnabled(bool state)
MainControl(const MainControl &main_control)
virtual void deleteClicked()
virtual void onNotify(Message *message)
void reduceSelection_(Composite *const composite)
CompositeManager & getCompositeManager()
Definition: mainControl.h:320
MainControlPreferences * main_control_preferences_
Definition: mainControl.h:914
void setModelInformation(ModelInformation *mi)
virtual void initializePreferencesTab_()
const ModelInformation & getModelInformation() const
std::list< Composite * > & getMolecularControlSelection()
Get the selection (highlighted items) of the MolecularControl (not the selection with checkboxes)
const HashSet< Composite * > & getSelection() const
Get the HashSet with the selected (e.g. picked) Composite objects (const)
String getMenuHint(QAction *id) const
Get the hint for a menu entry.
virtual void applyPreferencesClicked_()
void deselectCompositeRecursive(Composite *composite, bool first_call=false)
Select a Composite recursive and add all Atom and AtomContainer objects to the selection.
bool updateRepresentationsOf(const Composite &composite, bool rebuild=true, bool force=false)
void setWorkingDir(const String &dir)
Set the working directory for the next file dialog and file operation to the given directory.
ModularWidget * locking_widget_
Definition: mainControl.h:921
bool setSimulationThread(SimulationThread *thread)
String getWorkingDir() const
Definition: mainControl.h:671
void selectCompositeRecursive(Composite *composite, bool first_call=false)
Select a Composite recursive and add all Atom and AtomContainer objects to the selection.
const String & getLoggingFilename() const
See above.
@ CHOOSE_FF
Molmec submenu for force field selection.
Definition: mainControl.h:185
@ DISPLAY_STEREO
Display Stereo submenu.
Definition: mainControl.h:172
@ FILE_OPEN
File menu sub menu open.
Definition: mainControl.h:142
@ FILE_IMPORT
File menu sub menu import [currently unused].
Definition: mainControl.h:148
@ DISPLAY_ANIMATION
Display Animation submenu.
Definition: mainControl.h:175
@ FILE_OPEN_GRID
File menu sub menu open grid.
Definition: mainControl.h:145
@ TOOLS_PYTHON
Python submenu in Tools.
Definition: mainControl.h:194
@ FILE_EXPORT
File menu sub menu export.
Definition: mainControl.h:151
@ DISPLAY_CREATE
Display Create submenu.
Definition: mainControl.h:166
@ TOOLS_GRID
Grid submenu in Tools.
Definition: mainControl.h:191
@ DISPLAY_VIEWPOINT
Display Viewpoint submenu.
Definition: mainControl.h:169
void setMultithreading(bool state)
See above.
Definition: mainControl.h:624
void removeMenuEntry(Index parent_id, QAction *action)
virtual void checkMenus()
MainControl(QWidget *parent=0, const char *name=0, String inifile=".BALL.preferences")
void setLoggingFilename(const String &string)
void setStatusbarText(const QString &text, bool important=false, bool beep=false)
CompositeManager composite_manager_
Definition: mainControl.h:911
bool updateOfRepresentationRunning()
Return true if Representations are (re)calculated.
static MainControl * getMainControl(const QObject *object)
void setPreferencesEnabled_(bool state)
void quickLoad()
Quickload quick.bvp in the users home die (see above)
std::list< ModularWidget * > modular_widgets_
Definition: mainControl.h:930
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52