Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

base_jotapp.H

Go to the documentation of this file.
00001 #ifndef BASEJOTAPP_H
00002 #define BASEJOTAPP_H
00003 
00004 #include "std/config.H"
00005 #include "disp/view.H"
00006 #include "geom/winsys.H"
00007 #include "geom/world.H"
00008 #include "gest/easel_manager.H"
00009 #include "gest/pen_manager.H"
00010 #include "manip/manip.H"
00011 #include "manip/key_menu.H"
00012 #include "net/data_item.H"
00013 #include "geom/icon2d.H" 
00014 
00015 class MoveMenu;
00016 class Cam_int;
00017 class Cam_int_fp;
00018 class Cam_int_edit;
00019 class BMESH;
00020 class GEOM;
00021 
00022 /**********************************************************************
00023  * Simple_Keyboard
00024  **********************************************************************/
00025 
00026 class Simple_Keyboard : public Key_int {
00027  public :
00028    Simple_Keyboard(State *start) {
00029       add_event("abcdefghijklmnopqrstuvwxyz", start);
00030       add_event("ABCDEFGHIJKLMNOPQRSTUVWXYZ", start);
00031       add_event("1234567890_=!@#$%^&*()", start);
00032       add_event(" _+-[]{}|;:'\",<.>/?~`", start);
00033       add_event("\n\x8\x7f\x1b", start);
00034       *start += _entry;
00035    }
00036    virtual ~Simple_Keyboard() {}
00037 
00038 
00039    virtual int down(const Event &e, State *&) {
00040       switch (e._c) {
00041       case 'Q':
00042          WORLD::Quit();
00043          break;
00044       default:
00045          cerr << "Simple_Keyboard::down() - Unhandled key: '" << e._c << "'\n";
00046          break;
00047       }
00048       return 0;
00049    }
00050 };
00051 
00052 /*!
00053  *  \brief The base class for a Jot application.
00054  *
00055  */
00056 class BaseJOTapp : public MAPPED_CB, public FD_TIMEOUT {
00057  public:
00058 
00059    
00060    class WINDOW {
00061 
00062     public:
00063 
00064       MoveMenu*      _menu;
00065       Cam_int*       _cam1;
00066      Cam_int_fp*    _cam2;
00067      Cam_int_edit*  _cam3;
00068       WINSYS*        _win;
00069       ButtonMapper   _mouse_map;
00070       VIEWptr        _view;
00071       State          _start;
00072 
00073 
00074       WINDOW() :
00075          _menu(0),_cam1(0), _cam2(0), _win(0),  _mouse_map(0,0) {}
00076       WINDOW(WINSYS *win) :
00077          _menu(0),_cam1(0),_cam2(0), _win(win),_mouse_map(0,0) {}
00078 
00079       virtual ~WINDOW() {}
00080    };
00081 
00082    static BaseJOTapp *instance()        { return _instance;     }
00083    static WINDOW *window(int i=0)       { return _windows[i];   }
00084    static void Clean_On_Exit () {
00085       if (_instance)
00086          _instance->clean_on_exit();
00087    }
00088 
00089    BaseJOTapp(int argc, char **argv);
00090    BaseJOTapp(Cstr_ptr &name);
00091 
00092    virtual ~BaseJOTapp() {
00093       if (FD_MANAGER::mgr())
00094          FD_MANAGER::mgr()->rem_timeout(this);
00095    }
00096 
00097    virtual void init();
00098    virtual void Run();
00099 
00100    //! \name EaselManager Related Functions
00101    //@{
00102 
00103    EaselManager &easels() { return _easel_manager; }
00104 
00105    //@}
00106 
00107    //! \name PenManager Related Functions
00108    //@{
00109 
00110    Pen *cur_pen() { return _pen_manager ? _pen_manager->cur_pen() : 0; }
00111    void next_pen() { if(_pen_manager)
00112          _pen_manager->next_pen(); }
00113    void prev_pen() { if(_pen_manager)
00114          _pen_manager->prev_pen(); }
00115 
00116    //@}
00117 
00118    //! \name Render Mode Menu Related Functions
00119    //@{
00120 
00121    bool menu_is_shown();
00122    void show_menu();
00123    void hide_menu();
00124    void toggle_menu();
00125 
00126    //(de)activate on screen camera button
00127    static void activate_button(Cstr_ptr &file);
00128    static void update_button(Cstr_ptr &file);
00129    static void toggle_button(Cstr_ptr &file);
00130    static void deactivate_button();
00131 
00132 
00133    //@}
00134 
00135    //! \name KeyMenu Callback Functions
00136    //@{
00137    //! \brief Callback to switch cam mode
00138    static int cam_switch(const Event&, State *&);
00139    //! \brief Callback to toggle camera buttons
00140    static int button_toggle(const Event&, State *&);
00141    //! \brief Callback to display KeyMenu help menu.
00142    static int keymenu_help_cb(const Event&, State *&);
00143 
00144    //! \brief Callback to quit application.
00145    static int keymenu_quit_cb(const Event&, State *&);
00146 
00147    //! \brief Callback to toggle showing render style menu.
00148    static int show_menu_cb(const Event&, State *&);
00149 
00150    //! \brief Callback to reset camera to fit whole scene in view:
00151    static int viewall(const Event&, State *&);
00152 
00153 
00154 
00155    //@}
00156 
00157  protected:
00158 
00159    //! \name Utility Functions for Subclasses
00160    //@{
00161 
00162 
00163    void pop_arg();
00164 
00165    //@}
00166 
00167    //! \name Creation functions to be overriden by subclasses
00168    //@{
00169 
00170    virtual WINDOW *new_window(WINSYS *win) { return new WINDOW(win);}
00171    virtual VIEWptr new_view(WINSYS *win);
00172 
00173    //@}
00174 
00175    //! \name Hooks to be overriden/extended by subclasses
00176    //@{
00177 
00178    virtual void clean_on_exit();
00179 
00180 
00181 
00182    virtual void print_usage() const;
00183 
00184    // Create top level widget
00185    virtual void init_top();
00186    // Create world
00187    virtual void init_world();
00188    // Create view and add mapped handler
00189    virtual void init_view(WINDOW &window);
00190    virtual void init_camera(CVIEWptr &v);
00191    // Create on-screen controls
00192    virtual void init_buttons(CVIEWptr &v);
00193    
00194    // Create basic scene
00195    virtual void init_scene();
00196    // Load world or set up for networking
00197    virtual void load_scene();
00198 
00199    // load different file types: .jot, .sm, .obj:
00200    virtual bool load_jot_file(Cstr_ptr &file);
00201    virtual bool load_sm_file (Cstr_ptr &file);
00202    virtual bool load_obj_file(Cstr_ptr &file);
00203    
00204 
00205    // Default method for creating a new BMESH or derived type:
00206    virtual BMESH* new_mesh() const;
00207 
00208    // Default method for creating GEOM or derived type to hold a mesh:
00209    virtual GEOM* new_geom(BMESH* mesh, Cstr_ptr& name) const;
00210 
00211    // Put the mesh in GEOM and add it to the scene:
00212    bool create_mesh(BMESH* mesh, Cstr_ptr &file) const;
00213 
00214    // Add Interaction stuff
00215    virtual void init_win_cb(WINDOW &win);
00216    virtual void init_dev_cb(WINDOW &win);
00217    virtual void init_interact_cb(WINDOW &win);
00218 
00219    virtual void init_menu(WINDOW &win);
00220    virtual void init_kbd(WINDOW &win);
00221    virtual void init_kbd_nav(WINDOW &win);
00222    virtual void init_pens(WINDOW &win);
00223    virtual void init_cam_manip(WINDOW &win);
00224    virtual void init_obj_manip(WINDOW &) {}
00225    virtual void init_fsa();
00226 
00227    //@}
00228 
00229    //! \name FD_TIMEOUT Methods
00230    //@{
00231 
00232    virtual void         timeout();
00233 
00234    //@}
00235 
00236    //! \name MAPPED_CB Methods
00237    //@{
00238 
00239    virtual void         mapped();
00240    virtual void         icon();
00241 
00242    //@}
00243 
00244    static BaseJOTapp*      _instance;
00245    static ARRAY<WINDOW*>   _windows;
00246 
00247    str_ptr                 _prog_name;  // from original argv[0]
00248    char**                  _argv;
00249    int                     _argc;
00250    int                     _wins_to_map;
00251    
00252 
00253 
00254    EaselManager            _easel_manager;
00255    PenManager*             _pen_manager;
00256    KeyMenu*                _key_menu;
00257    WORLDptr                _world;
00258    ARRAY<FD_EVENT *>       _events; // Events to be destructed
00259    ARRAY<ICON2D *>         _buttons; // Array of camera buttons
00260    private:
00261 
00262    int cam_num; //determines which camera is being used
00263          
00264 };
00265 
00266 #endif // BASEJOTAPP_H
00267 
00268 // end of file base_jotapp.H

Generated on Mon Sep 18 11:39:28 2006 for jot by  doxygen 1.4.4