BALL  1.4.2
 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 class QCloseEvent;
52 
53 namespace BALL
54 {
55  namespace VIEW
56  {
57  class ModelInformation;
58  class ModularWidget;
59  class Preferences;
60  class MainControlPreferences;
61  class OpenSavePreferences;
62  class NetworkPreferences;
63  class GeometricObjectSelectionMessage;
64  class SimulationThread;
65 
107  : public QMainWindow,
108  public ConnectionObject,
109  public Embeddable
110  {
111  friend class RepresentationManager;
112  friend class SimulationThread;
113 
114  Q_OBJECT
115 
116  public:
117 
119 
120 
128  enum PopUpID
129  {
131  FILE = 10001,
132 
135 
138 
141 
144 
147 
149  EDIT = 10100,
150 
152  BUILD = 10200,
153 
155  DISPLAY = 10300,
156 
159 
162 
165 
168 
170  MOLECULARMECHANICS = 10400,
171 
174 
176  TOOLS = 10500,
177 
180 
183 
185  WINDOWS = 10600,
186 
188  USER = 10700,
189 
191  MACRO = 10750,
192 
194  HELP = 10800
195  };
196 
198 
201 
217  MainControl(QWidget* parent = 0, const char* name = 0 , String inifile = ".BALL.preferences");
218 
222  virtual ~MainControl();
223 
224  // copy ctor needed for Python support only!
225  MainControl(const MainControl& main_control);
226 
229  virtual void clear();
230 
233  void clearData();
234 
236 
239 
243  RepresentationManager& getRepresentationManager()
244  { return primitive_manager_;}
245 
251  bool insert(Representation& rep);
252 
257  bool remove(Representation& rep);
258 
263  bool update(Representation& rep);
264 
280  bool updateRepresentationsOf(const Composite& composite, bool rebuild = true, bool force = false);
281 
286  void redrawAllRepresentations(bool rebuild_display_lists = false);
287 
289 
295  ShortcutRegistry& getShortcutRegistry() { return shortcut_registry_;}
296 
297 
299  //
303 
307  CompositeManager& getCompositeManager()
308  { return composite_manager_;}
309 
316  bool insert(Composite& composite, String name = "");
317 
324  bool remove(Composite& composite, bool to_delete = true, bool update = true);
325 
334  void update(Composite& composite, bool changed_hierarchy = true);
335 
337  const HashSet<Composite*>& getSelection() const;
338 
340  HashSet<Composite*>& getSelection() ;
341 
343  std::list<Composite*>& getMolecularControlSelection();
344 
346  System* getSelectedSystem();
347 
349  void selectCompositeRecursive(Composite* composite, bool first_call=false);
350 
352  void deselectCompositeRecursive(Composite* composite, bool first_call=false);
353 
362  void printSelectionInfos();
363 
364 
366 
369 
371  void saveBALLViewProjectFile(const String& filename, bool binary = true);
372 
374  void loadBALLViewProjectFile(const String& filename);
375 
382  virtual void fetchPreferences(INIFile &inifile);
383 
391  virtual void writePreferences(INIFile &inifile);
392 
394  virtual void restoreWindows();
395 
397  virtual void restoreWindows(const INIFile& inifile);
398 
401  INIFile& getINIFile();
402 
405  const INIFile& getINIFile() const;
406 
410  Preferences* getPreferences();
411 
420  virtual void applyPreferences();
421 
422 
424 
427 
440  static MainControl* getMainControl(const QObject* object);
441 
447  void addModularWidget(ModularWidget* widget);
448 
454  void removeModularWidget(ModularWidget* widget);
455 
467  virtual void onNotify(Message *message);
468 
474  void sendMessage(Message& message);
475 
476 
478 
481 
493  QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
494  const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence());
495 
497  void removeMenuEntry (Index parent_id, QAction* action);
498 
506  virtual QMenu* initPopupMenu(int ID);
507 
513  void insertPopupMenuSeparator(int ID);
514 
516  void setMenuHint(QAction* id, const String& hint);
517 
519  String getMenuHint(QAction* id) const;
520 
524  void setDeleteEntryEnabled(bool state);
525 
529  void insertDeleteEntry();
530 
532  QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
533 
535 
538 
542  bool compositesAreLocked() const;
543 
549  bool lockCompositesFor(ModularWidget* widget);
550 
552  bool unlockCompositesFor(ModularWidget* widget);
553 
555  ModularWidget* getLockingWidget();
556 
558  bool updateOfRepresentationRunning();
559 
561  bool stopedSimulation() { return stop_simulation_;}
562 
568  bool setSimulationThread(SimulationThread* thread);
569 
573  SimulationThread* getSimulationThread();
574 
587  bool useMultithreading();
588 
590  void setMultithreading(bool state)
591  {multi_threading_mode_ = state;}
592 
594  bool isBusy() const;
595 
597  void wait();
598 
600  void processEvents(Size ms);
601 
602 
604 
607 
615  void setStatusbarText(const String& text, bool important = false, bool beep = false);
616 
618  void setStatusbarText(const QString& text, bool important = false, bool beep = false);
619 
621  String getStatusbarText() const;
622 
624  const FragmentDB& getFragmentDB() const
625  { return fragment_db_;}
626 
628  const ModelInformation& getModelInformation() const;
629 
631  void setModelInformation(ModelInformation* mi);
632 
637  String getWorkingDir() const
638  { return working_dir_;}
639 
641  void setWorkingDir(const String& dir);
642 
645  void enableLoggingToFile();
646 
649  void disableLoggingToFile();
650 
654  void setLoggingFilename(const String& string);
655 
657  const String& getLoggingFilename() const;
658 
660  bool isAboutToQuit() { return about_to_quit_;}
661 
662 
664 
667 
674  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
675 
683  virtual void openFile(const String& file) ;
684 
685 
687 
690 
691  public slots:
692 
708  virtual void show();
709 
720  virtual void checkMenus();
721 
723  void stopSimulation();
724 
726  void complementSelection();
727 
731  void clearSelection();
732 
745  virtual void aboutToExit();
746 
752  void menuItemHighlighted(QAction* action);
753 
755  virtual bool event(QEvent* e);
756 
758  virtual void quit(int return_value = 0);
759 
761  virtual void resize(int w, int h );
762 
764  void setContentSize(int w, int h);
765 
767  void toggleFullScreen();
768 
770  void quickSave();
771 
773  void quickLoad();
774 
776  void saveBALLViewProjectFile();
777 
779  void loadBALLViewProjectFile();
780 
782  void quickLoadConfirm();
783 
785 
786  protected slots:
787 
788  /*_ This slot is called internally whenever the apply button
789  of the Preferences dialog is pressed.
790  It calls among other things the method applyPreferences().
791  */
792  virtual void applyPreferencesClicked_();
793 
794  /*_ This slot is called internally whenever the ok button
795  of the Preferences dialog is pressed.
796  It calls among other things the method applyPreferences().
797  */
798  virtual void okPreferencesClicked_();
799 
800  //_ Called by timer to clear the text in the statusbar
801  void clearStatusBarText_();
802 
803  // Connected to the delete entry
804  virtual void deleteClicked();
805 
806  void updateRepLabel_();
807 
808  protected:
809 
810  virtual void initializePreferencesTab_();
811 
812  //_ Called after receiving an SimulationThreadFinished event
813  void stopedSimulation_();
814 
816  void lockComposites_();
817 
818  /*_ Remove a composite.
819  Every Representation, which was created for the Composite is deleted, by sending a
820  RepresentationMessage with type RepresentationMessage::REMOVE.\par
821  Redraws representations of the parent of the Composite, if wished.
822  \return bool <tt>true</tt> if the CompositeManager has the Composite
823  */
824  bool remove_(Composite& composite, bool update_representations_of_parent = true,
825  bool to_delete = true);
826 
827  /*_ Select the composite parents of the geometric objects.
828  The GeometricObjectSelectionMessage is sent by the Scene.
829  */
830  void selectComposites_(GeometricObjectSelectionMessage& message);
831 
832  void reduceSelection_(Composite* const composite);
833 
834  //_ Called by constructors
835  void setup_();
836 
837  void complementSelectionHelper_(Composite& c);
838 
841  void setBusyMode_(bool state);
842 
843  //_
844  void setPreferencesEnabled_(bool state);
845 
846  void init_();
847 
848  virtual void closeEvent(QCloseEvent* evt);
849 
852 
853  //_
855 
857 
858  /*_ List with the selected composites
859  */
861 
862  /*_ List with the selected composites of the control.
863  (Not the one with the checkboxes!)
864  */
865  std::list<Composite*> control_selection_;
866 
867  /*_ Message label in the statusbar
868  \see setStatusbarText
869  */
870  QLabel* message_label_;
871 
875 
881 
885 
887 
888  /*_ A list containing all modular widgets.
889  This list is modified by addModularWidget and
890  removeModularWidget.
891  */
892  std::list<ModularWidget*> modular_widgets_;
893 
895  QLabel* rep_label_;
896  static const char *simulation_running_xpm_[];
897  static const char *simulation_stoped_xpm_[];
899 
901 
905 
909  QTimer timer_;
912 
917  QAction* open_action_;
920  QAction* delete_action_;
921  QAction* qload_action_, *qsave_action_;
922 
925  QPoint last_point_;
926  QSize last_size_;
927  QByteArray last_state_;
928 };
929 
930 # ifndef BALL_NO_INLINE_FUNCTIONS
931 # include <BALL/VIEW/KERNEL/mainControl.iC>
932 # endif
933 
934  } // namespace VIEW
935  } // namespace BALL
936 
937 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H