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.h>
00047 #include <QtGui/qmenubar.h>
00048 #include <QtGui/qlabel.h>
00049 #include <QtCore/qtimer.h>
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 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
00355 void clearSelection();
00356
00365 void printSelectionInfos();
00366
00367
00369
00372
00374 void saveBALLViewProjectFile(const String& filename, bool binary = true);
00375
00377 void loadBALLViewProjectFile(const String& filename);
00378
00385 virtual void fetchPreferences(INIFile &inifile);
00386
00394 virtual void writePreferences(INIFile &inifile);
00395
00397 virtual void restoreWindows();
00398
00400 virtual void restoreWindows(const INIFile& inifile);
00401
00404 INIFile& getINIFile();
00405
00408 const INIFile& getINIFile() const;
00409
00413 Preferences* getPreferences();
00414
00423 virtual void applyPreferences();
00424
00425
00427
00430
00443 static MainControl* getMainControl(const QObject* object);
00444
00450 void addModularWidget(ModularWidget* widget);
00451
00457 void removeModularWidget(ModularWidget* widget);
00458
00470 virtual void onNotify(Message *message);
00471
00477 void sendMessage(Message& message);
00478
00479
00481
00484
00496 QAction* insertMenuEntry(Position parent_id, const String& name, const QObject* receiver = 0,
00497 const char* slot = 0, const String& description = "", QKeySequence accel = QKeySequence());
00498
00500 void removeMenuEntry (Index parent_id, QAction* action);
00501
00509 virtual QMenu* initPopupMenu(int ID);
00510
00516 void insertPopupMenuSeparator(int ID);
00517
00519 void setMenuHint(QAction* id, const String& hint);
00520
00522 String getMenuHint(QAction* id) const;
00523
00527 void setDeleteEntryEnabled(bool state);
00528
00532 void insertDeleteEntry();
00533
00535 QAction* getLastHighLightedMenuEntry() { return last_highlighted_menu_entry_;}
00536
00538
00541
00545 bool compositesAreLocked() const;
00546
00552 bool lockCompositesFor(ModularWidget* widget);
00553
00555 bool unlockCompositesFor(ModularWidget* widget);
00556
00558 ModularWidget* getLockingWidget();
00559
00561 bool updateOfRepresentationRunning();
00562
00564 bool stopedSimulation() { return stop_simulation_;}
00565
00571 bool setSimulationThread(SimulationThread* thread);
00572
00576 SimulationThread* getSimulationThread();
00577
00590 bool useMultithreading();
00591
00593 void setMultithreading(bool state)
00594 {multi_threading_mode_ = state;}
00595
00597 bool isBusy() const;
00598
00600 void wait();
00601
00603 void processEvents(Size ms);
00604
00605
00607
00610
00618 void setStatusbarText(const String& text, bool important = false, bool beep = false);
00619
00621 String getStatusbarText() const;
00622
00624 const FragmentDB& getFragmentDB() const
00625 { return fragment_db_;}
00626
00628 const ModelInformation& getModelInformation() const;
00629
00631 void setModelInformation(ModelInformation* mi);
00632
00637 String getWorkingDir() const
00638 { return working_dir_;}
00639
00641 void setWorkingDir(const String& dir);
00642
00645 void enableLoggingToFile();
00646
00649 void disableLoggingToFile();
00650
00654 void setLoggingFilename(const String& string);
00655
00657 const String& getLoggingFilename() const;
00658
00660 void setProxy(const String& host, Position port);
00661
00663 String getProxy() const { return proxy_;}
00664
00666 Position getProxyPort() const { return proxy_port_;}
00667
00669 bool isAboutToQuit() { return about_to_quit_;}
00670
00671
00673
00676
00683 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00684
00692 virtual void openFile(const String& file) ;
00693
00694
00696
00699
00700 public slots:
00701
00717 virtual void show();
00718
00729 virtual void checkMenus();
00730
00732 void stopSimulation();
00733
00735 void complementSelection();
00736
00749 virtual void aboutToExit();
00750
00756 void menuItemHighlighted(QAction* action);
00757
00759 virtual bool event(QEvent* e);
00760
00762 virtual void quit(int return_value = 0);
00763
00765 virtual void resize(int w, int h );
00766
00768 void setContentSize(int w, int h);
00769
00771 void toggleFullScreen();
00772
00774 void quickSave();
00775
00777 void quickLoad();
00778
00780 void saveBALLViewProjectFile();
00781
00783 void loadBALLViewProjectFile();
00784
00786 void quickLoadConfirm();
00787
00789
00790 protected slots:
00791
00792
00793
00794
00795
00796 virtual void applyPreferencesClicked_();
00797
00798
00799
00800
00801
00802 virtual void okPreferencesClicked_();
00803
00804
00805 void clearStatusBarText_();
00806
00807
00808 virtual void deleteClicked();
00809
00810 void updateRepLabel_();
00811
00812 protected:
00813
00814 virtual void initializePreferencesTab_();
00815
00816
00817 void stopedSimulation_();
00818
00820 void lockComposites_();
00821
00822
00823
00824
00825
00826
00827
00828 bool remove_(Composite& composite, bool update_representations_of_parent = true,
00829 bool to_delete = true);
00830
00831
00832
00833
00834 void selectComposites_(GeometricObjectSelectionMessage& message);
00835
00836 void reduceSelection_(Composite* const composite);
00837
00838
00839 void setup_();
00840
00841 void complementSelectionHelper_(Composite& c);
00842
00845 void setBusyMode_(bool state);
00846
00847
00848 void setPreferencesEnabled_(bool state);
00849
00850 void init_();
00851
00852 bool about_to_quit_;
00853 bool multi_threading_mode_;
00854
00855
00856 FragmentDB fragment_db_;
00857
00858 ModelInformation* model_information_;
00859
00860
00861
00862 HashSet<Composite*> selection_;
00863
00864
00865
00866
00867 List<Composite*> control_selection_;
00868
00869
00870
00871
00872 QLabel* message_label_;
00873
00874 RepresentationManager primitive_manager_;
00875 CompositeManager composite_manager_;
00876 ShortcutRegistry shortcut_registry_;
00877
00878 MainControlPreferences* main_control_preferences_;
00879 OpenSavePreferences* open_save_preferences_;
00880 NetworkPreferences* network_preferences_;
00881 Preferences* preferences_dialog_;
00882 INIFile preferences_file_;
00883
00884 bool composites_locked_;
00885 ModularWidget* locking_widget_;
00886 bool stop_simulation_;
00887
00888 SimulationThread* simulation_thread_;
00889
00890
00891
00892
00893
00894 List<ModularWidget*> modular_widgets_;
00895
00896 QLabel* simulation_icon_;
00897 QLabel* rep_label_;
00898 static const char *simulation_running_xpm_[];
00899 static const char *simulation_stoped_xpm_[];
00900 Position rep_label_nr_;
00901
00902 String working_dir_;
00903
00904 String logging_file_name_;
00905 bool logging_to_file_;
00906 File logging_file_;
00907
00908 bool important_text_in_statusbar_;
00909 bool was_not_busy_;
00910 Index rep_label_delta_;
00911 QTimer timer_;
00912 QTimer render_timer_;
00913 Mutex composites_locked_mutex_;
00914
00915 String proxy_;
00916 Position proxy_port_;
00917
00918 QAction* stop_simulation_action_;
00919 QAction* complement_selection_action_;
00920 QAction* open_action_;
00921 QAction* save_project_action_;
00922 QAction* preferences_action_;
00923 QAction* delete_action_;
00924 QAction* qload_action_, *qsave_action_;
00925
00926 QAction* last_highlighted_menu_entry_;
00927 HashMap<Position, QMenu*> id_to_menu_;
00928 bool fullscreen_;
00929 QPoint last_point_;
00930 QSize last_size_;
00931 QByteArray last_state_;
00932 };
00933
00934 # ifndef BALL_NO_INLINE_FUNCTIONS
00935 # include <BALL/VIEW/KERNEL/mainControl.iC>
00936 # endif
00937
00938 }
00939 }
00940
00941 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H