BALL  1.4.1
 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_FORMAT_INIFILE_H
33 # include <BALL/FORMAT/INIFile.h>
34 #endif
35 
36 #ifndef BALL_SYSTEM_FILE_H
37 # include <BALL/SYSTEM/file.h>
38 #endif
39 
40 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
42 #endif
43 
44 #include <QtGui/QKeySequence>
45 #include <QtGui/QMainWindow>
46 #include <QtGui/QApplication>
47 #include <QtGui/QMenuBar>
48 #include <QtGui/QLabel>
49 #include <QtCore/QTimer>
50 
51 namespace BALL
52 {
53  namespace VIEW
54  {
55  class ModelInformation;
56  class ModularWidget;
57  class Preferences;
58  class MainControlPreferences;
59  class OpenSavePreferences;
60  class NetworkPreferences;
61  class GeometricObjectSelectionMessage;
62  class SimulationThread;
63 
105  : public QMainWindow,
106  public ConnectionObject,
107  public Embeddable
108  {
109  friend class RepresentationManager;
110  friend class SimulationThread;
111 
112  Q_OBJECT
113 
114  public:
115 
117 
118 
126  enum PopUpID
127  {
129  FILE = 10001,
130 
133 
136 
139 
142 
145 
147  EDIT = 10100,
148 
150  BUILD = 10200,
151 
153  DISPLAY = 10300,
154 
157 
160 
163 
166 
168  MOLECULARMECHANICS = 10400,
169 
172 
174  TOOLS = 10500,
175 
178 
181 
183  WINDOWS = 10600,
184 
186  USER = 10700,
187 
189  MACRO = 10750,
190 
192  HELP = 10800
193  };
194 
196 
199 
215  MainControl(QWidget* parent = 0, const char* name = 0 , String inifile = ".BALL.preferences");
216 
220  virtual ~MainControl();
221 
222  // copy ctor needed for Python support only!
223  MainControl(const MainControl& main_control);
224 
227  virtual void clear();
228 
231  void clearData();
232 
234 
237 
241  RepresentationManager& getRepresentationManager()
242  { return primitive_manager_;}
243 
249  bool insert(Representation& rep);
250 
255  bool remove(Representation& rep);
256 
261  bool update(Representation& rep);
262 
278  bool updateRepresentationsOf(const Composite& composite, bool rebuild = true, bool force = false);
279 
284  void redrawAllRepresentations(bool rebuild_display_lists = false);
285 
287 
293  ShortcutRegistry& getShortcutRegistry() { return shortcut_registry_;}
294 
295 
297  //
301 
305  CompositeManager& getCompositeManager()
306  { return composite_manager_;}
307 
314  bool insert(Composite& composite, String name = "");
315 
322  bool remove(Composite& composite, bool to_delete = true, bool update = true);
323 
332  void update(Composite& composite, bool changed_hierarchy = true);
333 
335  const HashSet<Composite*>& getSelection() const;
336 
338  HashSet<Composite*>& getSelection() ;
339 
341  std::list<Composite*>& getMolecularControlSelection();
342 
344  System* getSelectedSystem();
345 
347  void selectCompositeRecursive(Composite* composite, bool first_call=false);
348 
350  void deselectCompositeRecursive(Composite* composite, bool first_call=false);
351 
360  void printSelectionInfos();
361 
362 
364 
367 
369  void saveBALLViewProjectFile(const String& filename, bool binary = true);
370 
372  void loadBALLViewProjectFile(const String& filename);
373 
380  virtual void fetchPreferences(INIFile &inifile);
381 
389  virtual void writePreferences(INIFile &inifile);
390 
392  virtual void restoreWindows();
393 
395  virtual void restoreWindows(const INIFile& inifile);
396 
399  INIFile& getINIFile();
400 
403  const INIFile& getINIFile() const;
404 
408  Preferences* getPreferences();
409 
418  virtual void applyPreferences();
419 
420 
422 
425 
438  static MainControl* getMainControl(const QObject* object);
439 
445  void addModularWidget(ModularWidget* widget);
446 
452  void removeModularWidget(ModularWidget* widget);
453 
465  virtual void onNotify(Message *message);
466 
472  void sendMessage(Message& message);
473 
474 
476 
479 
491  QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
492  const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence());
493 
495  void removeMenuEntry (Index parent_id, QAction* action);
496 
504  virtual QMenu* initPopupMenu(int ID);
505 
511  void insertPopupMenuSeparator(int ID);
512 
514  void setMenuHint(QAction* id, const String& hint);
515 
517  String getMenuHint(QAction* id) const;
518 
522  void setDeleteEntryEnabled(bool state);
523 
527  void insertDeleteEntry();
528 
530  QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
531 
533 
536 
540  bool compositesAreLocked() const;
541 
547  bool lockCompositesFor(ModularWidget* widget);
548 
550  bool unlockCompositesFor(ModularWidget* widget);
551 
553  ModularWidget* getLockingWidget();
554 
556  bool updateOfRepresentationRunning();
557 
559  bool stopedSimulation() { return stop_simulation_;}
560 
566  bool setSimulationThread(SimulationThread* thread);
567 
571  SimulationThread* getSimulationThread();
572 
585  bool useMultithreading();
586 
588  void setMultithreading(bool state)
589  {multi_threading_mode_ = state;}
590 
592  bool isBusy() const;
593 
595  void wait();
596 
598  void processEvents(Size ms);
599 
600 
602 
605 
613  void setStatusbarText(const String& text, bool important = false, bool beep = false);
614 
616  void setStatusbarText(const QString& text, bool important = false, bool beep = false);
617 
619  String getStatusbarText() const;
620 
622  const FragmentDB& getFragmentDB() const
623  { return fragment_db_;}
624 
626  const ModelInformation& getModelInformation() const;
627 
629  void setModelInformation(ModelInformation* mi);
630 
635  String getWorkingDir() const
636  { return working_dir_;}
637 
639  void setWorkingDir(const String& dir);
640 
643  void enableLoggingToFile();
644 
647  void disableLoggingToFile();
648 
652  void setLoggingFilename(const String& string);
653 
655  const String& getLoggingFilename() const;
656 
658  bool isAboutToQuit() { return about_to_quit_;}
659 
660 
662 
665 
672  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
673 
681  virtual void openFile(const String& file) ;
682 
683 
685 
688 
689  public slots:
690 
706  virtual void show();
707 
718  virtual void checkMenus();
719 
721  void stopSimulation();
722 
724  void complementSelection();
725 
729  void clearSelection();
730 
743  virtual void aboutToExit();
744 
750  void menuItemHighlighted(QAction* action);
751 
753  virtual bool event(QEvent* e);
754 
756  virtual void quit(int return_value = 0);
757 
759  virtual void resize(int w, int h );
760 
762  void setContentSize(int w, int h);
763 
765  void toggleFullScreen();
766 
768  void quickSave();
769 
771  void quickLoad();
772 
774  void saveBALLViewProjectFile();
775 
777  void loadBALLViewProjectFile();
778 
780  void quickLoadConfirm();
781 
783 
784  protected slots:
785 
786  /*_ This slot is called internally whenever the apply button
787  of the Preferences dialog is pressed.
788  It calls among other things the method applyPreferences().
789  */
790  virtual void applyPreferencesClicked_();
791 
792  /*_ This slot is called internally whenever the ok button
793  of the Preferences dialog is pressed.
794  It calls among other things the method applyPreferences().
795  */
796  virtual void okPreferencesClicked_();
797 
798  //_ Called by timer to clear the text in the statusbar
799  void clearStatusBarText_();
800 
801  // Connected to the delete entry
802  virtual void deleteClicked();
803 
804  void updateRepLabel_();
805 
806  protected:
807 
808  virtual void initializePreferencesTab_();
809 
810  //_ Called after receiving an SimulationThreadFinished event
811  void stopedSimulation_();
812 
814  void lockComposites_();
815 
816  /*_ Remove a composite.
817  Every Representation, which was created for the Composite is deleted, by sending a
818  RepresentationMessage with type RepresentationMessage::REMOVE.\par
819  Redraws representations of the parent of the Composite, if wished.
820  \return bool <tt>true</tt> if the CompositeManager has the Composite
821  */
822  bool remove_(Composite& composite, bool update_representations_of_parent = true,
823  bool to_delete = true);
824 
825  /*_ Select the composite parents of the geometric objects.
826  The GeometricObjectSelectionMessage is sent by the Scene.
827  */
828  void selectComposites_(GeometricObjectSelectionMessage& message);
829 
830  void reduceSelection_(Composite* const composite);
831 
832  //_ Called by constructors
833  void setup_();
834 
835  void complementSelectionHelper_(Composite& c);
836 
839  void setBusyMode_(bool state);
840 
841  //_
842  void setPreferencesEnabled_(bool state);
843 
844  void init_();
845 
848 
849  //_
851 
853 
854  /*_ List with the selected composites
855  */
857 
858  /*_ List with the selected composites of the control.
859  (Not the one with the checkboxes!)
860  */
861  std::list<Composite*> control_selection_;
862 
863  /*_ Message label in the statusbar
864  \see setStatusbarText
865  */
866  QLabel* message_label_;
867 
871 
877 
881 
883 
884  /*_ A list containing all modular widgets.
885  This list is modified by addModularWidget and
886  removeModularWidget.
887  */
888  std::list<ModularWidget*> modular_widgets_;
889 
891  QLabel* rep_label_;
892  static const char *simulation_running_xpm_[];
893  static const char *simulation_stoped_xpm_[];
895 
897 
901 
905  QTimer timer_;
908 
913  QAction* open_action_;
916  QAction* delete_action_;
917  QAction* qload_action_, *qsave_action_;
918 
921  QPoint last_point_;
922  QSize last_size_;
923  QByteArray last_state_;
924 };
925 
926 # ifndef BALL_NO_INLINE_FUNCTIONS
927 # include <BALL/VIEW/KERNEL/mainControl.iC>
928 # endif
929 
930  } // namespace VIEW
931  } // namespace BALL
932 
933 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H