BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <QtGui/QMainWindow>
54 #include <QtGui/QApplication>
55 #include <QtGui/QMenuBar>
56 #include <QtGui/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 
206  HELP = 10800
207  };
208 
210 
213 
229  MainControl(QWidget* parent = 0, const char* name = 0 , String inifile = ".BALL.preferences");
230 
234  virtual ~MainControl();
235 
236  // copy ctor needed for Python support only!
237  MainControl(const MainControl& main_control);
238 
241  virtual void clear();
242 
245  void clearData();
246 
248 
251 
256  { return primitive_manager_;}
257 
263  bool insert(Representation& rep);
264 
269  bool remove(Representation& rep);
270 
275  bool update(Representation& rep);
276 
292  bool updateRepresentationsOf(const Composite& composite, bool rebuild = true, bool force = false);
293 
298  void redrawAllRepresentations(bool rebuild_display_lists = false);
299 
301 
307  ShortcutRegistry& getShortcutRegistry() { return shortcut_registry_;}
308 
309 
311  //
315 
320  { return composite_manager_;}
321 
328  bool insert(Composite& composite, String name = "", bool normalize = true);
329 
336  bool remove(Composite& composite, bool to_delete = true, bool update = true);
337 
346  void update(Composite& composite, bool changed_hierarchy = true);
347 
349  const HashSet<Composite*>& getSelection() const;
350 
352  HashSet<Composite*>& getSelection() ;
353 
355  std::list<Composite*>& getMolecularControlSelection();
356 
358  System* getSelectedSystem();
359 
361  void selectCompositeRecursive(Composite* composite, bool first_call=false);
362 
364  void deselectCompositeRecursive(Composite* composite, bool first_call=false);
365 
374  void printSelectionInfos();
375 
376 
378 
381 
383  void saveBALLViewProjectFile(const String& filename, bool binary = true);
384 
386  void loadBALLViewProjectFile(const String& filename);
387 
394  virtual void fetchPreferences(INIFile &inifile);
395 
403  virtual void writePreferences(INIFile &inifile);
404 
406  virtual void restoreWindows();
407 
409  virtual void restoreWindows(const INIFile& inifile);
410 
413  INIFile& getINIFile();
414 
417  const INIFile& getINIFile() const;
418 
422  Preferences* getPreferences();
423 
432  virtual void applyPreferences();
433 
434 
436 
439 
452  static MainControl* getMainControl(const QObject* object);
453 
459  void addModularWidget(ModularWidget* widget);
460 
466  void removeModularWidget(ModularWidget* widget);
467 
479  virtual void onNotify(Message *message);
480 
486  void sendMessage(Message& message);
487 
488 
490 
493 
506  QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
507  const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence(),
509 
522  QAction* insertMenuEntry(Position parent_id, const QString& name, const QObject* receiver = 0,
523  const char* slot = 0, const QString& description = "", QKeySequence accel = QKeySequence(),
525 
527  virtual QMenu* addMenu(const QString& title, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
528 
530  void removeMenuEntry (Index parent_id, QAction* action);
531 
539  virtual QMenu* initPopupMenu(int ID, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
540 
546  void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode = UIOperationMode::MODE_ALL);
547 
549  void setMenuHint(QAction* id, const String& hint);
550 
552  String getMenuHint(QAction* id) const;
553 
557  void setDeleteEntryEnabled(bool state);
558 
562  void insertDeleteEntry();
563 
565  QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
566 
568 
571 
575  bool compositesAreLocked() const;
576 
582  bool lockCompositesFor(ModularWidget* widget);
583 
585  bool unlockCompositesFor(ModularWidget* widget);
586 
588  ModularWidget* getLockingWidget();
589 
591  bool updateOfRepresentationRunning();
592 
594  bool stopedSimulation() { return stop_simulation_;}
595 
601  bool setSimulationThread(SimulationThread* thread);
602 
606  SimulationThread* getSimulationThread();
607 
620  bool useMultithreading();
621 
623  void setMultithreading(bool state)
624  {multi_threading_mode_ = state;}
625 
627  bool isBusy() const;
628 
630  void wait();
631 
633  void processEvents(Size ms);
634 
635 
637 
640 
648  void setStatusbarText(const String& text, bool important = false, bool beep = false);
649 
651  void setStatusbarText(const QString& text, bool important = false, bool beep = false);
652 
654  String getStatusbarText() const;
655 
657  const FragmentDB& getFragmentDB() const
658  { return fragment_db_;}
659 
661  const ModelInformation& getModelInformation() const;
662 
664  void setModelInformation(ModelInformation* mi);
665 
671  { return working_dir_;}
672 
674  void setWorkingDir(const String& dir);
675 
678  void enableLoggingToFile();
679 
682  void disableLoggingToFile();
683 
687  void setLoggingFilename(const String& string);
688 
690  const String& getLoggingFilename() const;
691 
693  bool isAboutToQuit() { return about_to_quit_;}
694 
695 
697 
700 
707  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
708 
716  virtual void openFile(const String& file) ;
717 
718 
721  virtual QMenu* createPopupMenu();
722 
724 
727 
728  public slots:
729 
745  virtual void show();
746 
757  virtual void checkMenus();
758 
760  void stopSimulation();
761 
763  void complementSelection();
764 
768  void clearSelection();
769 
782  virtual void aboutToExit();
783 
789  void menuItemHighlighted(QAction* action);
790 
792  virtual bool event(QEvent* e);
793 
795  virtual void quit(int return_value = 0);
796 
798  virtual void resize(int w, int h );
799 
801  void setContentSize(int w, int h);
802 
804  void toggleFullScreen();
805 
807  void quickSave();
808 
810  void quickLoad();
811 
813  void saveBALLViewProjectFile();
814 
816  void loadBALLViewProjectFile();
817 
819  void quickLoadConfirm();
820 
822 
823  protected slots:
824 
825  /*_ This slot is called internally whenever the apply button
826  of the Preferences dialog is pressed.
827  It calls among other things the method applyPreferences().
828  */
829  virtual void applyPreferencesClicked_();
830 
831  /*_ This slot is called internally whenever the ok button
832  of the Preferences dialog is pressed.
833  It calls among other things the method applyPreferences().
834  */
835  virtual void okPreferencesClicked_();
836 
837  //_ Called by timer to clear the text in the statusbar
838  void clearStatusBarText_();
839 
840  // Connected to the delete entry
841  virtual void deleteClicked();
842 
843  void updateRepLabel_();
844 
845  protected:
846 
847  virtual void initializePreferencesTab_();
848 
849  //_ Called after receiving an SimulationThreadFinished event
850  void stopedSimulation_();
851 
853  void lockComposites_();
854 
855  /*_ Remove a composite.
856  Every Representation, which was created for the Composite is deleted, by sending a
857  RepresentationMessage with type RepresentationMessage::REMOVE.\par
858  Redraws representations of the parent of the Composite, if wished.
859  \return bool <tt>true</tt> if the CompositeManager has the Composite
860  */
861  bool remove_(Composite& composite, bool update_representations_of_parent = true,
862  bool to_delete = true);
863 
864  /*_ Select the composite parents of the geometric objects.
865  The GeometricObjectSelectionMessage is sent by the Scene.
866  */
867  void selectComposites_(GeometricObjectSelectionMessage& message);
868 
869  void reduceSelection_(Composite* const composite);
870 
871  //_ Called by constructors
872  void setup_();
873 
874  void complementSelectionHelper_(Composite& c);
875 
878  void setBusyMode_(bool state);
879 
880  //_
881  void setPreferencesEnabled_(bool state);
882 
883  void init_();
884 
885  virtual void closeEvent(QCloseEvent* evt);
886 
889 
890  //_
892 
894 
895  /*_ List with the selected composites
896  */
898 
899  /*_ List with the selected composites of the control.
900  (Not the one with the checkboxes!)
901  */
902  std::list<Composite*> control_selection_;
903 
904  /*_ Message label in the statusbar
905  \see setStatusbarText
906  */
907  QLabel* message_label_;
908 
912 
918 
922 
924 
925  /*_ A list containing all modular widgets.
926  This list is modified by addModularWidget and
927  removeModularWidget.
928  */
929  std::list<ModularWidget*> modular_widgets_;
930 
932  QLabel* rep_label_;
933  static const char *simulation_running_xpm_[];
934  static const char *simulation_stoped_xpm_[];
936 
938 
942 
946  QTimer timer_;
949 
954  QAction* open_action_;
957  QAction* delete_action_;
958  QAction* qload_action_, *qsave_action_;
959 
962  QPoint last_point_;
963  QSize last_size_;
964  QByteArray last_state_;
965 };
966 
967 # ifndef BALL_NO_INLINE_FUNCTIONS
968 # include <BALL/VIEW/KERNEL/mainControl.iC>
969 # endif
970 
971  } // namespace VIEW
972  } // namespace BALL
973 
974 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H
CompositeManager composite_manager_
Definition: mainControl.h:910
Molmec submenu for force field selection.
Definition: mainControl.h:185
RepresentationManager & getRepresentationManager()
Definition: mainControl.h:255
QAction * preferences_action_
Definition: mainControl.h:956
OpenSavePreferences * open_save_preferences_
Definition: mainControl.h:914
std::list< ModularWidget * > modular_widgets_
Definition: mainControl.h:929
QAction * last_highlighted_menu_entry_
Definition: mainControl.h:960
ModelInformation * model_information_
Definition: mainControl.h:893
QAction * fullscreen_action_
Definition: mainControl.h:951
QAction * clear_selection_action_
Definition: mainControl.h:953
String getWorkingDir() const
Definition: mainControl.h:670
QAction * stop_simulation_action_
Definition: mainControl.h:950
const FragmentDB & getFragmentDB() const
Get a const reference for the fragment database.
Definition: mainControl.h:657
ModularWidget * locking_widget_
Definition: mainControl.h:920
bool stopedSimulation()
Returns true, if the simulation was told to stop, but hasnt done this so far.
Definition: mainControl.h:594
BALL_EXTERN_VARIABLE const double h
Definition: constants.h:102
BALL_VIEW_EXPORT MainControl * getMainControl()
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
QAction * complement_selection_action_
Definition: mainControl.h:952
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
NetworkPreferences * network_preferences_
Definition: mainControl.h:915
File menu sub menu export.
Definition: mainControl.h:151
Preferences * preferences_dialog_
Definition: mainControl.h:916
SimulationThread * simulation_thread_
Definition: mainControl.h:923
File menu sub menu import [currently unused].
Definition: mainControl.h:148
File menu sub menu open grid.
Definition: mainControl.h:145
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition: embeddable.h:31
ShortcutRegistry & getShortcutRegistry()
Definition: mainControl.h:307
HashSet< Composite * > selection_
Definition: mainControl.h:897
RepresentationManager primitive_manager_
Definition: mainControl.h:909
void setMultithreading(bool state)
See above.
Definition: mainControl.h:623
MainControlPreferences * main_control_preferences_
Definition: mainControl.h:913
File menu sub menu open.
Definition: mainControl.h:142
QAction * getLastHighLightedMenuEntry()
Get the ID of the last highlighted menu entry (used for the HelpViewer)
Definition: mainControl.h:565
ShortcutRegistry shortcut_registry_
Definition: mainControl.h:911
std::list< Composite * > control_selection_
Definition: mainControl.h:902
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:73
QAction * save_project_action_
Definition: mainControl.h:955
HashMap< Position, QMenu * > id_to_menu_
Definition: mainControl.h:961
CompositeManager & getCompositeManager()
Definition: mainControl.h:319
Grid submenu in Tools.
Definition: mainControl.h:191
Python submenu in Tools.
Definition: mainControl.h:194