00001
00002
00003
00004
00005 #ifndef BALL_VIEW_KERNEL_MAINCONTROL_H
00006 #define BALL_VIEW_KERNEL_MAINCONTROL_H
00007
00008 #ifndef BALL_CONCEPT_EMBEDDABLE_H
00009 # include <BALL/CONCEPT/embeddable.h>
00010 #endif
00011
00012 #ifndef BALL_DATATYPE_HASHMAP_H
00013 # include <BALL/DATATYPE/hashMap.h>
00014 #endif
00015
00016 #ifndef BALL_VIEW_KERNEL_CONNECTIONOBJECT_H
00017 # include <BALL/VIEW/KERNEL/connectionObject.h>
00018 #endif
00019
00020 #ifndef BALL_VIEW_KERNEL_REPRESENTATIONMANAGER_H
00021 # include <BALL/VIEW/KERNEL/representationManager.h>
00022 #endif
00023
00024 #ifndef BALL_VIEW_KERNEL_COMPOSITEMANAGER_H
00025 # include <BALL/VIEW/KERNEL/compositeManager.h>
00026 #endif
00027
00028 #ifndef BALL_VIEW_KERNEL_SHORTCUTREGISTRY_H
00029 #include <BALL/VIEW/KERNEL/shortcutRegistry.h>
00030 #endif
00031
00032 #ifndef BALL_FORMAT_INIFILE_H
00033 # include <BALL/FORMAT/INIFile.h>
00034 #endif
00035
00036 #ifndef BALL_SYSTEM_FILE_H
00037 # include <BALL/SYSTEM/file.h>
00038 #endif
00039
00040 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
00041 # include <BALL/STRUCTURE/fragmentDB.h>
00042 #endif
00043
00044 #include <QtGui/QKeySequence>
00045 #include <QtGui/QMainWindow>
00046 #include <QtGui/QApplication>
00047 #include <QtGui/QMenuBar>
00048 #include <QtGui/QLabel>
00049 #include <QtCore/QTimer>
00050
00051 namespace BALL
00052 {
00053 namespace VIEW
00054 {
00055 class ModelInformation;
00056 class ModularWidget;
00057 class Preferences;
00058 class MainControlPreferences;
00059 class OpenSavePreferences;
00060 class NetworkPreferences;
00061 class GeometricObjectSelectionMessage;
00062 class SimulationThread;
00063
00104 class BALL_VIEW_EXPORT MainControl
00105 : public QMainWindow,
00106 public ConnectionObject,
00107 public Embeddable
00108 {
00109 friend class RepresentationManager;
00110 friend class SimulationThread;
00111
00112 Q_OBJECT
00113
00114 public:
00115
00116 BALL_EMBEDDABLE(MainControl,Embeddable)
00117
00118
00126 enum PopUpID
00127 {
00129 FILE = 10001,
00130
00132 FILE_OPEN,
00133
00135 FILE_OPEN_GRID,
00136
00138 FILE_IMPORT,
00139
00141 FILE_EXPORT,
00142
00144 FILE_MONITOR,
00145
00147 EDIT = 10100,
00148
00150 BUILD = 10200,
00151
00153 DISPLAY = 10300,
00154
00156 DISPLAY_CREATE,
00157
00159 DISPLAY_VIEWPOINT,
00160
00162 DISPLAY_STEREO,
00163
00165 DISPLAY_ANIMATION,
00166
00168 MOLECULARMECHANICS = 10400,
00169
00171 CHOOSE_FF,
00172
00174 TOOLS = 10500,
00175
00177 TOOLS_GRID,
00178
00180 TOOLS_PYTHON,
00181
00183 WINDOWS = 10600,
00184
00186 USER = 10700,
00187
00189 MACRO = 10750,
00190
00192 HELP = 10800
00193 };
00194
00196
00199
00215 MainControl(QWidget* parent = 0, const char* name = 0 , String inifile = ".BALL.preferences");
00216
00220 virtual ~MainControl();
00221
00222
00223 MainControl(const MainControl& main_control);
00224
00227 virtual void clear();
00228
00231 void clearData();
00232
00234
00237
00241 RepresentationManager& getRepresentationManager()
00242 { return primitive_manager_;}
00243
00249 bool insert(Representation& rep);
00250
00255 bool remove(Representation& rep);
00256
00261 bool update(Representation& rep);
00262
00278 bool updateRepresentationsOf(const Composite& composite, bool rebuild = true, bool force = false);
00279
00284 void redrawAllRepresentations(bool rebuild_display_lists = false);
00285
00287
00293 ShortcutRegistry& getShortcutRegistry() { return shortcut_registry_;}
00294
00295
00297
00301
00305 CompositeManager& getCompositeManager()
00306 { return composite_manager_;}
00307
00314 bool insert(Composite& composite, String name = "");
00315
00322 bool remove(Composite& composite, bool to_delete = true, bool update = true);
00323
00332 void update(Composite& composite, bool changed_hierarchy = true);
00333
00335 const HashSet<Composite*>& getSelection() const;
00336
00338 HashSet<Composite*>& getSelection() ;
00339
00341 std::list<Composite*>& getMolecularControlSelection();
00342
00344 System* getSelectedSystem();
00345
00347 void selectCompositeRecursive(Composite* composite, bool first_call=false);
00348
00350 void deselectCompositeRecursive(Composite* composite, bool first_call=false);
00351
00360 void printSelectionInfos();
00361
00362
00364
00367
00369 void saveBALLViewProjectFile(const String& filename, bool binary = true);
00370
00372 void loadBALLViewProjectFile(const String& filename);
00373
00380 virtual void fetchPreferences(INIFile &inifile);
00381
00389 virtual void writePreferences(INIFile &inifile);
00390
00392 virtual void restoreWindows();
00393
00395 virtual void restoreWindows(const INIFile& inifile);
00396
00399 INIFile& getINIFile();
00400
00403 const INIFile& getINIFile() const;
00404
00408 Preferences* getPreferences();
00409
00418 virtual void applyPreferences();
00419
00420
00422
00425
00438 static MainControl* getMainControl(const QObject* object);
00439
00445 void addModularWidget(ModularWidget* widget);
00446
00452 void removeModularWidget(ModularWidget* widget);
00453
00465 virtual void onNotify(Message *message);
00466
00472 void sendMessage(Message& message);
00473
00474
00476
00479
00491 QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
00492 const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence());
00493
00495 void removeMenuEntry (Index parent_id, QAction* action);
00496
00504 virtual QMenu* initPopupMenu(int ID);
00505
00511 void insertPopupMenuSeparator(int ID);
00512
00514 void setMenuHint(QAction* id, const String& hint);
00515
00517 String getMenuHint(QAction* id) const;
00518
00522 void setDeleteEntryEnabled(bool state);
00523
00527 void insertDeleteEntry();
00528
00530 QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
00531
00533
00536
00540 bool compositesAreLocked() const;
00541
00547 bool lockCompositesFor(ModularWidget* widget);
00548
00550 bool unlockCompositesFor(ModularWidget* widget);
00551
00553 ModularWidget* getLockingWidget();
00554
00556 bool updateOfRepresentationRunning();
00557
00559 bool stopedSimulation() { return stop_simulation_;}
00560
00566 bool setSimulationThread(SimulationThread* thread);
00567
00571 SimulationThread* getSimulationThread();
00572
00585 bool useMultithreading();
00586
00588 void setMultithreading(bool state)
00589 {multi_threading_mode_ = state;}
00590
00592 bool isBusy() const;
00593
00595 void wait();
00596
00598 void processEvents(Size ms);
00599
00600
00602
00605
00613 void setStatusbarText(const String& text, bool important = false, bool beep = false);
00614
00616 String getStatusbarText() const;
00617
00619 const FragmentDB& getFragmentDB() const
00620 { return fragment_db_;}
00621
00623 const ModelInformation& getModelInformation() const;
00624
00626 void setModelInformation(ModelInformation* mi);
00627
00632 String getWorkingDir() const
00633 { return working_dir_;}
00634
00636 void setWorkingDir(const String& dir);
00637
00640 void enableLoggingToFile();
00641
00644 void disableLoggingToFile();
00645
00649 void setLoggingFilename(const String& string);
00650
00652 const String& getLoggingFilename() const;
00653
00655 bool isAboutToQuit() { return about_to_quit_;}
00656
00657
00659
00662
00669 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00670
00678 virtual void openFile(const String& file) ;
00679
00680
00682
00685
00686 public slots:
00687
00703 virtual void show();
00704
00715 virtual void checkMenus();
00716
00718 void stopSimulation();
00719
00721 void complementSelection();
00722
00726 void clearSelection();
00727
00740 virtual void aboutToExit();
00741
00747 void menuItemHighlighted(QAction* action);
00748
00750 virtual bool event(QEvent* e);
00751
00753 virtual void quit(int return_value = 0);
00754
00756 virtual void resize(int w, int h );
00757
00759 void setContentSize(int w, int h);
00760
00762 void toggleFullScreen();
00763
00765 void quickSave();
00766
00768 void quickLoad();
00769
00771 void saveBALLViewProjectFile();
00772
00774 void loadBALLViewProjectFile();
00775
00777 void quickLoadConfirm();
00778
00780
00781 protected slots:
00782
00783
00784
00785
00786
00787 virtual void applyPreferencesClicked_();
00788
00789
00790
00791
00792
00793 virtual void okPreferencesClicked_();
00794
00795
00796 void clearStatusBarText_();
00797
00798
00799 virtual void deleteClicked();
00800
00801 void updateRepLabel_();
00802
00803 protected:
00804
00805 virtual void initializePreferencesTab_();
00806
00807
00808 void stopedSimulation_();
00809
00811 void lockComposites_();
00812
00813
00814
00815
00816
00817
00818
00819 bool remove_(Composite& composite, bool update_representations_of_parent = true,
00820 bool to_delete = true);
00821
00822
00823
00824
00825 void selectComposites_(GeometricObjectSelectionMessage& message);
00826
00827 void reduceSelection_(Composite* const composite);
00828
00829
00830 void setup_();
00831
00832 void complementSelectionHelper_(Composite& c);
00833
00836 void setBusyMode_(bool state);
00837
00838
00839 void setPreferencesEnabled_(bool state);
00840
00841 void init_();
00842
00843 bool about_to_quit_;
00844 bool multi_threading_mode_;
00845
00846
00847 FragmentDB fragment_db_;
00848
00849 ModelInformation* model_information_;
00850
00851
00852
00853 HashSet<Composite*> selection_;
00854
00855
00856
00857
00858 std::list<Composite*> control_selection_;
00859
00860
00861
00862
00863 QLabel* message_label_;
00864
00865 RepresentationManager primitive_manager_;
00866 CompositeManager composite_manager_;
00867 ShortcutRegistry shortcut_registry_;
00868
00869 MainControlPreferences* main_control_preferences_;
00870 OpenSavePreferences* open_save_preferences_;
00871 NetworkPreferences* network_preferences_;
00872 Preferences* preferences_dialog_;
00873 INIFile preferences_file_;
00874
00875 bool composites_locked_;
00876 ModularWidget* locking_widget_;
00877 bool stop_simulation_;
00878
00879 SimulationThread* simulation_thread_;
00880
00881
00882
00883
00884
00885 std::list<ModularWidget*> modular_widgets_;
00886
00887 QLabel* simulation_icon_;
00888 QLabel* rep_label_;
00889 static const char *simulation_running_xpm_[];
00890 static const char *simulation_stoped_xpm_[];
00891 Position rep_label_nr_;
00892
00893 String working_dir_;
00894
00895 String logging_file_name_;
00896 bool logging_to_file_;
00897 File logging_file_;
00898
00899 bool important_text_in_statusbar_;
00900 bool was_not_busy_;
00901 Index rep_label_delta_;
00902 QTimer timer_;
00903 QTimer render_timer_;
00904 Mutex composites_locked_mutex_;
00905
00906 QAction* stop_simulation_action_;
00907 QAction* fullscreen_action_;
00908 QAction* complement_selection_action_;
00909 QAction* clear_selection_action_;
00910 QAction* open_action_;
00911 QAction* save_project_action_;
00912 QAction* preferences_action_;
00913 QAction* delete_action_;
00914 QAction* qload_action_, *qsave_action_;
00915
00916 QAction* last_highlighted_menu_entry_;
00917 HashMap<Position, QMenu*> id_to_menu_;
00918 QPoint last_point_;
00919 QSize last_size_;
00920 QByteArray last_state_;
00921 };
00922
00923 # ifndef BALL_NO_INLINE_FUNCTIONS
00924 # include <BALL/VIEW/KERNEL/mainControl.iC>
00925 # endif
00926
00927 }
00928 }
00929
00930 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H