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
178  DISPLAY_CONTINUOUSLOOP,
180 #endif
181  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 
350  const HashSet<Composite*>& getSelection() const;
351 
353  HashSet<Composite*>& getSelection() ;
354 
356  std::list<Composite*>& getMolecularControlSelection();
357 
359  System* getSelectedSystem();
360 
362  void selectCompositeRecursive(Composite* composite, bool first_call=false);
363 
365  void deselectCompositeRecursive(Composite* composite, bool first_call=false);
366 
375  void printSelectionInfos();
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 
414  INIFile& getINIFile();
415 
418  const INIFile& getINIFile() const;
419 
423  Preferences* getPreferences();
424 
433  virtual void applyPreferences();
434 
435 
437 
440 
453  static MainControl* getMainControl(const QObject* object);
454 
460  void addModularWidget(ModularWidget* widget);
461 
467  void removeModularWidget(ModularWidget* widget);
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 
540  virtual QMenu* initPopupMenu(int ID, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
541 
547  void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
548 
550  void setMenuHint(QAction* id, const String& hint);
551 
553  String getMenuHint(QAction* id) const;
554 
558  void setDeleteEntryEnabled(bool state);
559 
563  void insertDeleteEntry();
564 
566  QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
567 
569 
572 
576  bool compositesAreLocked() const;
577 
583  bool lockCompositesFor(ModularWidget* widget);
584 
586  bool unlockCompositesFor(ModularWidget* widget);
587 
589  ModularWidget* getLockingWidget();
590 
592  bool updateOfRepresentationRunning();
593 
595  bool stopedSimulation() { return stop_simulation_;}
596 
602  bool setSimulationThread(SimulationThread* thread);
603 
607  SimulationThread* getSimulationThread();
608 
621  bool useMultithreading();
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 
655  String getStatusbarText() const;
656 
658  const FragmentDB& getFragmentDB() const
659  { return fragment_db_;}
660 
662  const ModelInformation& getModelInformation() const;
663 
665  void setModelInformation(ModelInformation* mi);
666 
672  { return working_dir_;}
673 
675  void setWorkingDir(const String& dir);
676 
679  void enableLoggingToFile();
680 
683  void disableLoggingToFile();
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 
761  void stopSimulation();
762 
764  void complementSelection();
765 
769  void clearSelection();
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 
805  void toggleFullScreen();
806 
808  void quickSave();
809 
811  void quickLoad();
812 
814  void saveBALLViewProjectFile();
815 
817  void loadBALLViewProjectFile();
818 
820  void quickLoadConfirm();
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
839  void clearStatusBarText_();
840 
841  // Connected to the delete entry
842  virtual void deleteClicked();
843 
844  void updateRepLabel_();
845 
846  protected:
847 
848  virtual void initializePreferencesTab_();
849 
850  //_ Called after receiving an SimulationThreadFinished event
851  void stopedSimulation_();
852 
854  void lockComposites_();
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  */
868  void selectComposites_(GeometricObjectSelectionMessage& message);
869 
870  void reduceSelection_(Composite* const composite);
871 
872  //_ Called by constructors
873  void setup_();
874 
875  void complementSelectionHelper_(Composite& c);
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
QAction * complement_selection_action_
Definition: mainControl.h:953
SimulationThread * simulation_thread_
Definition: mainControl.h:924
RepresentationManager primitive_manager_
Definition: mainControl.h:910
std::list< ModularWidget * > modular_widgets_
Definition: mainControl.h:930
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition: embeddable.h:31
BALL_VIEW_EXPORT MainControl * getMainControl()
const FragmentDB & getFragmentDB() const
Get a const reference for the fragment database.
Definition: mainControl.h:658
QAction * fullscreen_action_
Definition: mainControl.h:952
ModelInformation * model_information_
Definition: mainControl.h:894
QAction * last_highlighted_menu_entry_
Definition: mainControl.h:959
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:73
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
CompositeManager composite_manager_
Definition: mainControl.h:911
QAction * clear_selection_action_
Definition: mainControl.h:954
File menu sub menu export.
Definition: mainControl.h:151
Grid submenu in Tools.
Definition: mainControl.h:191
Python submenu in Tools.
Definition: mainControl.h:194
Molmec submenu for force field selection.
Definition: mainControl.h:185
CompositeManager & getCompositeManager()
Definition: mainControl.h:320
ShortcutRegistry shortcut_registry_
Definition: mainControl.h:912
MainControlPreferences * main_control_preferences_
Definition: mainControl.h:914
OpenSavePreferences * open_save_preferences_
Definition: mainControl.h:915
QAction * stop_simulation_action_
Definition: mainControl.h:951
QAction * preferences_action_
Definition: mainControl.h:956
Definition: constants.h:12
File menu sub menu import [currently unused].
Definition: mainControl.h:148
void setMultithreading(bool state)
See above.
Definition: mainControl.h:624
RepresentationManager & getRepresentationManager()
Definition: mainControl.h:256
Preferences * preferences_dialog_
Definition: mainControl.h:917
NetworkPreferences * network_preferences_
Definition: mainControl.h:916
String getWorkingDir() const
Definition: mainControl.h:671
File menu sub menu open grid.
Definition: mainControl.h:145
HashSet< Composite * > selection_
Definition: mainControl.h:898
QAction * getLastHighLightedMenuEntry()
Get the ID of the last highlighted menu entry.
Definition: mainControl.h:566
std::list< Composite * > control_selection_
Definition: mainControl.h:903
File menu sub menu open.
Definition: mainControl.h:142
bool stopedSimulation()
Returns true, if the simulation was told to stop, but hasnt done this so far.
Definition: mainControl.h:595
HashMap< Position, QMenu * > id_to_menu_
Definition: mainControl.h:960
BALL_EXTERN_VARIABLE const double h
Definition: constants.h:102
ShortcutRegistry & getShortcutRegistry()
Definition: mainControl.h:308
ModularWidget * locking_widget_
Definition: mainControl.h:921