scenevie.h

Go to the documentation of this file.
00001 #ifndef sceneview_h
00002 #define sceneview_h
00003 
00004 /*
00005  A universe where data is placed is a scene. There can be 0 or many
00006   views into a scene. Each view has one canvas.
00007       canvas   canvas  canvas
00008          . . . 
00009    view  view  view  view  view
00010          scene
00011   glyph  glyph  glyph  glyph  glyph  glyph  glyph
00012 
00013  A scene is very similar to a page in that we have
00014   arbitrary placement of glyphs. However, the protocol differs in that
00015   the user should call Scene::modified(GlyphIndex) whenever a glyph's allocation
00016   needs to be recomputed or its request will change. If you wish merely to
00017   redraw the glyph with Scene's stored allocation
00018   one can call Scene::damage(GlyphIndex). Notice that all communication
00019   with Scene is in terms of Scene coordinates. (If the scene coordinates
00020   are changed after construction, there are two coordinate systems.
00021   see below)
00022 
00023  Scene maintains a list of views whose canvas will be damaged whenever
00024   the scene changes. This list is maintained during construction and
00025   destruction of views.
00026 
00027  Scene maintains a list of glyphs along with their allocations and placement.
00028  Note that when Scene::modified is called, damage is called on both the
00029  old (stored by Scene) and new allocation of the glyph.
00030 
00031 It is sometimes the case that scene coordinates have inappropriate scales
00032 for some glyphs such as labels on a plot (even though
00033 their placement is still in scene coords).
00034 Here we want the labels to have a fixed appearance on the screen regardless
00035 of the scene scaling. This is done with append_fixed(). Such glyphs are
00036 relative to the scaling of the xyview's parent glyph.
00037 (Therefore the PrintWindowManager
00038 will scale these, relative to the resizing of the window on the
00039 paper icon. See the implementation for how to go further using
00040 view_transform())
00041 
00042 It is also sometimes the case that we want items positioned relative to
00043 the view window. This is done with append_viewfixed(). Such glyphs have a
00044 location that is relative to view coordinates. (0,0) is left,bottom and (1,1)
00045 is right,top
00046 
00047 Items added to the list are not displayed until they are moved away
00048 from (0,0) or modified() to avoid damageing large portions of the canvas
00049 with the common append/move.
00050 */
00051 
00052 /*
00053  The static function XYView* XYView::current_pick_view holds the view of
00054  latest pick. From that a glyph in the scene can obtain current scene.
00055 */
00056 
00057 /*
00058  The creator of a scene may use a standard method of input handling by
00059  accessing the method picker() which provides a way of associating actions
00060  with mouse events.
00061 
00062  By default the right mouse button pops up a menu with zoom, new view,
00063  and whole scene items. The middle button translates the view. The
00064  left button defaults to new view. These actions have names which label
00065  the print window manager when one enters a view. See ocpicker.h for details.
00066 */
00067 
00068 /*
00069  To put a view into a window with a banner that shows the size in scene
00070  coordinates, use ViewWindow(XYView*)
00071 */
00072 
00073 #include <InterViews/tformsetter.h>
00074 #include <InterViews/observe.h>
00075 #include "apwindow.h"
00076 #include "ocglyph.h"
00077 #include <ivstream.h>
00078 
00079 #undef Scene
00080 
00081 class Scene;
00082 class SceneInfo_List;
00083 class SceneInfo;
00084 class XYView;
00085 class XYView_PtrList;
00086 class ScenePicker;
00087 class GLabel;
00088 class GPolyLine;
00089 struct Object;
00090 
00091 class OcViewGlyph : public OcGlyph {
00092 public:
00093    OcViewGlyph(XYView*);
00094    virtual ~OcViewGlyph();
00095    XYView* view() {return v_;}
00096    virtual void save(ostream&);
00097    void viewmenu(Glyph*);
00098 private:
00099    XYView* v_;
00100    Glyph* g_;
00101 };
00102 
00103 // view into a scene; independent scales in x and y direction.
00104 // ie. as window resized, view remains same (directions magnified separately)
00105 class XYView : public TransformSetter , public Observable{
00106 public:
00107    XYView(Scene*, Coord xsize=200, Coord ysize=200);
00108    XYView(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene*,
00109      Coord xsize=200, Coord ysize=200);
00110    virtual ~XYView();
00111 
00112    virtual Scene* scene() const;
00113    virtual Coord left() const, right() const, top() const, bottom() const;
00114    virtual Coord width() const, height() const;
00115    
00116    virtual void damage(Glyph*, const Allocation&,
00117       boolean fixed = false, boolean viewfixed = false);
00118    virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
00119    virtual void damage_all();
00120 
00121    /* damage area in model coords, call from draw */  
00122    virtual void damage_area(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
00123    virtual void set_damage_area(Canvas*);
00124 
00125    virtual void request(Requisition&)const;
00126    virtual void allocate(Canvas*, const Allocation&, Extension&);
00127    virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
00128    virtual void undraw();
00129 
00130    Canvas* canvas();
00131    //transforms canvas from scene to parent glyph coordinates.
00132    const Transformer& s2o()const {return scene2viewparent_;}
00133    void canvas(Canvas*);
00134 
00135    void size(Coord x1, Coord y1, Coord x2, Coord y2);
00136    void origin(Coord x1, Coord y1);
00137    void x_span(Coord);
00138    void y_span(Coord);
00139    virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
00140 
00141    static XYView* current_pick_view();
00142    static void current_pick_view(XYView*);
00143    static XYView* current_draw_view();
00144    Coord x_pick_epsilon() {return x_pick_epsilon_;}
00145    Coord y_pick_epsilon() {return y_pick_epsilon_;}
00146    virtual void move_view(Coord dx, Coord dy); // in screen coords.
00147    virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen coords.
00148    virtual XYView*  new_view(Coord x1, Coord y1, Coord x2, Coord y2);
00149    void rebind(); // stop the flicker on scale_view and move_view
00150    virtual void save(ostream&);
00151    OcViewGlyph* parent() { return parent_;}
00152    virtual void printfile(const char*);
00153    virtual void zout(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
00154    virtual void zin(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
00155    Coord view_margin() const {return view_margin_;}
00156    virtual void view_ratio(float xratio, float yratio, Coord& x, Coord& y) const;
00157    virtual void ratio_view(Coord x, Coord y, float& xratio, float& yratio) const;
00158    virtual void stroke(Canvas*, const Color*, const Brush*);
00159 protected:
00160    virtual void transform(
00161       Transformer&, const Allocation&, const Allocation& natural
00162    ) const;
00163    void scene2view(const Allocation& parent) const;
00164    void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const;   // not really const
00165 private:
00166    void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene*,
00167      Coord xsize, Coord ysize);
00168    void append_view(Scene*);
00169 protected:
00170    Coord x_pick_epsilon_, y_pick_epsilon_;
00171 private:
00172    Coord x1_, y1_, x_span_, y_span_;
00173    Canvas* canvas_;
00174    Transformer scene2viewparent_;
00175    Coord xsize_, ysize_, xsize_orig_, ysize_orig_, xc0_, yc0_;
00176    friend class OcViewGlyph;
00177    OcViewGlyph* parent_;
00178    Coord xd1_, xd2_, yd1_, yd2_;
00179    static Coord view_margin_;
00180 };
00181 
00182 // view into a scene; scale in x & y direction is the same and determined
00183 //  by span in smallest window dimension. Coords are scene coordinates.
00184 
00185 class View : public XYView {
00186 public:
00187    View(Scene*);  // view of entire scene
00188    View(Coord x, Coord y, Coord span, Scene*,
00189       Coord xsize = 200, Coord ysize = 200); //x,y is center of view
00190    View(Coord left, Coord bottom, Coord x_span, Coord y_span, Scene*,
00191      Coord xsize=200, Coord ysize=200);
00192    virtual ~View();
00193    
00194    virtual Coord x() const, y() const;
00195    virtual Coord view_width() const, view_height() const;
00196 
00197    void origin(Coord x, Coord y); // center
00198    virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
00199    virtual void move_view(Coord dx, Coord dy); // in screen coords.
00200    virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen coords.
00201    virtual XYView*  new_view(Coord x1, Coord y1, Coord x2, Coord y2);
00202 protected:
00203    virtual void transform(
00204       Transformer&, const Allocation&, const Allocation& natural
00205    ) const;
00206 private:
00207    Coord x_span_, y_span_;
00208 };
00209    
00210 class Scene : public Glyph , public Observable{
00211 public:
00212    Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* background=nil);
00213    virtual ~Scene();
00214    virtual void background(Glyph* bg=nil);
00215    virtual Coord x1() const, y1() const, x2() const, y2() const;
00216    virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2);
00217    virtual void wholeplot(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
00218    virtual int view_count() const;
00219    virtual XYView* sceneview(int) const;
00220    virtual void dismiss(); // dismiss windows that contain only this scene
00221    virtual void printfile(const char*);
00222 
00223    virtual void modified(GlyphIndex);
00224    void move(GlyphIndex, Coord x, Coord y);
00225    void location(GlyphIndex, Coord& x, Coord& y)const;
00226    void show(GlyphIndex, boolean);
00227    boolean showing(GlyphIndex) const;
00228 
00229    virtual void damage(GlyphIndex);
00230    virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
00231    virtual void damage_all();
00232 
00233    enum {NOTOOL=0, MOVE, DELETE, CHANGECOLOR, EXTRATOOL};
00234    virtual void tool(int);
00235    virtual int tool();
00236    virtual void help();
00237    virtual void delete_label(GLabel*);
00238    virtual void change_label_color(GLabel*);
00239    virtual void change_line_color(GPolyLine*);
00240    virtual void request(Requisition&) const;
00241    virtual void allocate(Canvas*, const Allocation&, Extension&);
00242    virtual void draw(Canvas*, const Allocation&) const;
00243    virtual void print(Printer*, const Allocation&) const;
00244    virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
00245 
00246    virtual void append(Glyph*);
00247    virtual void append_fixed(Glyph*);
00248    virtual void append_viewfixed(Glyph*);
00249    virtual void prepend(Glyph*);
00250    virtual void insert(GlyphIndex, Glyph*);
00251    virtual void remove(GlyphIndex);
00252    virtual void replace(GlyphIndex, Glyph*);
00253    virtual void change(GlyphIndex);
00254    virtual void change_to_fixed(GlyphIndex, XYView*);
00255    virtual void change_to_vfixed(GlyphIndex, XYView*);
00256 
00257    virtual GlyphIndex count() const;
00258    virtual Glyph* component(GlyphIndex) const;
00259    virtual void allotment(GlyphIndex, DimensionName, Allotment&) const;
00260    virtual GlyphIndex glyph_index(const Glyph*);
00261    boolean drawing_fixed_item()const { return drawing_fixed_item_;}
00262 
00263    static void save_all(ostream&);
00264    static long scene_list_index(Scene*);
00265    boolean mark() {return mark_;}
00266    void mark(boolean m) {mark_ = m;}
00267    virtual void save_phase1(ostream&);
00268    virtual void save_phase2(ostream&);
00269    virtual Coord mbs() const;
00270    
00271    static const Color* default_background();
00272    static const Color* default_foreground();
00273    
00274    ScenePicker* picker();
00275    Object* hoc_obj_ptr() { return hoc_obj_ptr_;}
00276    void hoc_obj_ptr(Object* o) { hoc_obj_ptr_ = o;}
00277    boolean menu_picked() { return menu_picked_;}
00278 protected:
00279    virtual void save_class(ostream&, const char*);
00280 private:
00281 #if 1
00282    friend class XYView;
00283 #else
00284    // I prefer this but the SGI compiler doesn't like it
00285    friend void XYView::append_view(Scene*);
00286    friend XYView::~XYView();
00287 #endif
00288    virtual void damage(GlyphIndex, const Allocation&);
00289    void append_view(XYView*);
00290    void remove_view(XYView*);
00291    void check_allocation(GlyphIndex);
00292 private:
00293    Coord x1_, y1_, x2_, y2_;
00294    SceneInfo_List* info_;
00295    XYView_PtrList* views_;
00296    Glyph* background_;
00297    ScenePicker* picker_;
00298    int tool_;
00299    boolean mark_;
00300    static Scene* current_scene_;
00301    static Coord mbs_;   // menu_box_size (pixels) in left top
00302    boolean drawing_fixed_item_;
00303    Object* hoc_obj_ptr_;
00304    boolean menu_picked_;
00305 
00306    Coord x1_orig_, x2_orig_, y1_orig_, y2_orig_;
00307 };
00308 
00309 class ViewWindow : public PrintableWindow , public Observer {
00310 public:
00311    ViewWindow(XYView*, const char* name);
00312    virtual ~ViewWindow();
00313    virtual void update(Observable*);
00314    virtual void reconfigured();
00315 };
00316    
00317 inline Coord Scene::x1() const { return x1_; }
00318 inline Coord Scene::x2() const { return x2_; }
00319 inline Coord Scene::y1() const { return y1_; }
00320 inline Coord Scene::y2() const { return y2_; }
00321 
00322 
00323 #endif
Generated on Mon Jun 13 08:10:24 2011 for NEURON by  doxygen 1.6.3