BALL  1.4.1
mainControl.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
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       // copy ctor needed for Python support only!
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       void setStatusbarText(const QString& text, bool important = false, bool beep = false);
00617 
00619       String getStatusbarText() const;
00620   
00622       const FragmentDB& getFragmentDB() const
00623         { return fragment_db_;}
00624 
00626       const ModelInformation& getModelInformation() const;
00627 
00629       void setModelInformation(ModelInformation* mi);
00630 
00635       String getWorkingDir() const
00636         { return working_dir_;}
00637 
00639       void setWorkingDir(const String& dir);
00640 
00643       void enableLoggingToFile();
00644       
00647       void disableLoggingToFile();
00648 
00652       void setLoggingFilename(const String& string);
00653 
00655       const String& getLoggingFilename() const;
00656 
00658       bool isAboutToQuit() { return about_to_quit_;}
00659     
00660 
00662 
00665 
00672       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00673           
00681       virtual void openFile(const String& file) ;
00682 
00683 
00685 
00688       
00689       public slots:
00690 
00706       virtual void show();
00707 
00718       virtual void checkMenus();
00719 
00721       void stopSimulation();
00722   
00724       void complementSelection();
00725 
00729       void clearSelection();
00730 
00743       virtual void aboutToExit();
00744 
00750       void menuItemHighlighted(QAction* action);
00751       
00753       virtual bool event(QEvent* e);
00754 
00756       virtual void quit(int return_value = 0);
00757     
00759       virtual void resize(int w, int h );
00760 
00762       void setContentSize(int w, int h);
00763 
00765       void toggleFullScreen();
00766 
00768       void quickSave();
00769 
00771       void quickLoad();
00772       
00774       void saveBALLViewProjectFile(); 
00775 
00777       void loadBALLViewProjectFile();
00778 
00780       void quickLoadConfirm();
00781 
00783       
00784       protected slots:
00785 
00786       /*_ This slot is called internally whenever the apply button
00787           of the Preferences dialog is pressed.
00788           It calls among other things the method applyPreferences().
00789       */
00790       virtual void applyPreferencesClicked_();
00791       
00792       /*_ This slot is called internally whenever the ok button
00793           of the Preferences dialog is pressed.
00794           It calls among other things the method applyPreferences().
00795       */
00796       virtual void okPreferencesClicked_();
00797 
00798       //_ Called by timer to clear the text in the statusbar
00799       void clearStatusBarText_();
00800 
00801       // Connected to the delete entry
00802       virtual void deleteClicked();
00803 
00804       void updateRepLabel_();
00805 
00806       protected:
00807 
00808       virtual void initializePreferencesTab_();
00809 
00810       //_  Called after receiving an SimulationThreadFinished event
00811       void stopedSimulation_();
00812 
00814       void lockComposites_();
00815 
00816       /*_ Remove a composite.
00817           Every Representation, which was created for the Composite is deleted, by sending a 
00818           RepresentationMessage with type RepresentationMessage::REMOVE.\par
00819           Redraws representations of the parent of the Composite, if wished.
00820           \return bool <tt>true</tt> if the CompositeManager has the Composite
00821       */
00822       bool remove_(Composite& composite, bool update_representations_of_parent = true, 
00823                                          bool to_delete = true);
00824 
00825       /*_ Select the composite parents of the geometric objects.
00826           The GeometricObjectSelectionMessage is sent by the Scene.
00827        */
00828       void selectComposites_(GeometricObjectSelectionMessage& message);
00829 
00830       void reduceSelection_(Composite* const composite);
00831 
00832       //_ Called by constructors
00833       void setup_();
00834 
00835       void complementSelectionHelper_(Composite& c);
00836 
00839       void setBusyMode_(bool state);
00840 
00841       //_
00842       void setPreferencesEnabled_(bool state);
00843 
00844       void init_();
00845 
00846       bool                about_to_quit_;
00847       bool                multi_threading_mode_;  
00848 
00849       //_
00850       FragmentDB                  fragment_db_;
00851 
00852       ModelInformation*           model_information_;
00853 
00854       /*_ List with the selected composites
00855       */
00856       HashSet<Composite*>         selection_;
00857 
00858       /*_ List with the selected composites of the control.
00859           (Not the one with the checkboxes!)
00860       */
00861       std::list<Composite*>           control_selection_;
00862 
00863       /*_ Message label in the statusbar
00864           \see setStatusbarText
00865       */
00866       QLabel*                     message_label_;
00867 
00868       RepresentationManager       primitive_manager_;
00869       CompositeManager            composite_manager_; 
00870       ShortcutRegistry            shortcut_registry_;
00871 
00872       MainControlPreferences*     main_control_preferences_;
00873       OpenSavePreferences*        open_save_preferences_;
00874       NetworkPreferences*         network_preferences_;
00875       Preferences*                preferences_dialog_;
00876       INIFile                     preferences_file_;
00877       
00878       bool                        composites_locked_;
00879       ModularWidget*              locking_widget_;
00880       bool                        stop_simulation_;
00881 
00882       SimulationThread*           simulation_thread_;
00883 
00884       /*_ A list containing all modular widgets.
00885           This list is modified by addModularWidget and
00886           removeModularWidget.
00887       */
00888       std::list<ModularWidget*>       modular_widgets_;
00889     
00890       QLabel*             simulation_icon_;
00891       QLabel*             rep_label_;
00892       static const char  *simulation_running_xpm_[];
00893       static const char  *simulation_stoped_xpm_[];
00894       Position            rep_label_nr_;
00895 
00896       String              working_dir_;
00897 
00898       String              logging_file_name_;
00899       bool                logging_to_file_;
00900       File                logging_file_;
00901 
00902       bool                important_text_in_statusbar_;
00903       bool                was_not_busy_;
00904       Index               rep_label_delta_;
00905       QTimer              timer_;
00906       QTimer              render_timer_;
00907       Mutex               composites_locked_mutex_;
00908 
00909       QAction* stop_simulation_action_;
00910       QAction* fullscreen_action_;
00911       QAction* complement_selection_action_;
00912       QAction* clear_selection_action_;
00913       QAction* open_action_;
00914       QAction* save_project_action_;
00915       QAction* preferences_action_;
00916       QAction* delete_action_;
00917       QAction* qload_action_, *qsave_action_;
00918 
00919       QAction* last_highlighted_menu_entry_;
00920       HashMap<Position, QMenu*> id_to_menu_;
00921       QPoint        last_point_;
00922       QSize         last_size_;
00923       QByteArray    last_state_;
00924 };
00925 
00926 #   ifndef BALL_NO_INLINE_FUNCTIONS
00927 #     include <BALL/VIEW/KERNEL/mainControl.iC>
00928 #   endif 
00929     
00930     } // namespace VIEW
00931   } // namespace BALL
00932 
00933 #endif // BALL_VIEW_KERNEL_MAINCONTROL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines