NEURON
scenevie.h
Go to the documentation of this file.
1 #ifndef sceneview_h
2 #define sceneview_h
3 
4 /*
5  A universe where data is placed is a scene. There can be 0 or many
6  views into a scene. Each view has one canvas.
7  canvas canvas canvas
8  . . .
9  view view view view view
10  scene
11  glyph glyph glyph glyph glyph glyph glyph
12 
13  A scene is very similar to a page in that we have
14  arbitrary placement of glyphs. However, the protocol differs in that
15  the user should call Scene::modified(GlyphIndex) whenever a glyph's allocation
16  needs to be recomputed or its request will change. If you wish merely to
17  redraw the glyph with Scene's stored allocation
18  one can call Scene::damage(GlyphIndex). Notice that all communication
19  with Scene is in terms of Scene coordinates. (If the scene coordinates
20  are changed after construction, there are two coordinate systems.
21  see below)
22 
23  Scene maintains a list of views whose canvas will be damaged whenever
24  the scene changes. This list is maintained during construction and
25  destruction of views.
26 
27  Scene maintains a list of glyphs along with their allocations and placement.
28  Note that when Scene::modified is called, damage is called on both the
29  old (stored by Scene) and new allocation of the glyph.
30 
31 It is sometimes the case that scene coordinates have inappropriate scales
32 for some glyphs such as labels on a plot (even though
33 their placement is still in scene coords).
34 Here we want the labels to have a fixed appearance on the screen regardless
35 of the scene scaling. This is done with append_fixed(). Such glyphs are
36 relative to the scaling of the xyview's parent glyph.
37 (Therefore the PrintWindowManager
38 will scale these, relative to the resizing of the window on the
39 paper icon. See the implementation for how to go further using
40 view_transform())
41 
42 It is also sometimes the case that we want items positioned relative to
43 the view window. This is done with append_viewfixed(). Such glyphs have a
44 location that is relative to view coordinates. (0,0) is left,bottom and (1,1)
45 is right,top
46 
47 Items added to the list are not displayed until they are moved away
48 from (0,0) or modified() to avoid damageing large portions of the canvas
49 with the common append/move.
50 */
51 
52 /*
53  The static function XYView* XYView::current_pick_view holds the view of
54  latest pick. From that a glyph in the scene can obtain current scene.
55 */
56 
57 /*
58  The creator of a scene may use a standard method of input handling by
59  accessing the method picker() which provides a way of associating actions
60  with mouse events.
61 
62  By default the right mouse button pops up a menu with zoom, new view,
63  and whole scene items. The middle button translates the view. The
64  left button defaults to new view. These actions have names which label
65  the print window manager when one enters a view. See ocpicker.h for details.
66 */
67 
68 /*
69  To put a view into a window with a banner that shows the size in scene
70  coordinates, use ViewWindow(XYView*)
71 */
72 
73 #include <InterViews/tformsetter.h>
74 #include <InterViews/observe.h>
75 #include "apwindow.h"
76 #include "ocglyph.h"
77 #include <ivstream.h>
78 
79 #undef Scene
80 
81 class Scene;
82 class SceneInfo_List;
83 class SceneInfo;
84 class XYView;
85 class XYView_PtrList;
86 class ScenePicker;
87 class GLabel;
88 class GPolyLine;
89 struct Object;
90 
91 class OcViewGlyph: public OcGlyph {
92  public:
94  virtual ~OcViewGlyph();
95  XYView* view() {
96  return v_;
97  }
98  virtual void save(std::ostream&);
99  void viewmenu(Glyph*);
100 
101  private:
104 };
105 
106 // view into a scene; independent scales in x and y direction.
107 // ie. as window resized, view remains same (directions magnified separately)
108 class XYView: public TransformSetter, public Observable {
109  public:
110  XYView(Scene*, Coord xsize = 200, Coord ysize = 200);
112  Coord y1,
113  Coord x_span,
114  Coord y_span,
115  Scene*,
116  Coord xsize = 200,
117  Coord ysize = 200);
118  virtual ~XYView();
119 
120  virtual Scene* scene() const;
121  virtual Coord left() const, right() const, top() const, bottom() const;
122  virtual Coord width() const, height() const;
123 
124  virtual void damage(Glyph*, const Allocation&, bool fixed = false, bool viewfixed = false);
125  virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
126  virtual void damage_all();
127 
128  /* damage area in model coords, call from draw */
129  virtual void damage_area(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
130  virtual void set_damage_area(Canvas*);
131 
132  virtual void request(Requisition&) const;
133  virtual void allocate(Canvas*, const Allocation&, Extension&);
134  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
135  virtual void undraw();
136 
138  // transforms canvas from scene to parent glyph coordinates.
139  const Transformer& s2o() const {
140  return scene2viewparent_;
141  }
142  void canvas(Canvas*);
143 
144  void size(Coord x1, Coord y1, Coord x2, Coord y2);
145  void origin(Coord x1, Coord y1);
146  void x_span(Coord);
147  void y_span(Coord);
148  virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
149 
151  static void current_pick_view(XYView*);
154  return x_pick_epsilon_;
155  }
157  return y_pick_epsilon_;
158  }
159  virtual void move_view(Coord dx, Coord dy); // in screen coords.
160  virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen
161  // coords.
162  virtual XYView* new_view(Coord x1, Coord y1, Coord x2, Coord y2);
163  void rebind(); // stop the flicker on scale_view and move_view
164  virtual void save(std::ostream&);
166  return parent_;
167  }
168  virtual void printfile(const char*);
169  virtual void zout(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
170  virtual void zin(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
171  Coord view_margin() const {
172  return view_margin_;
173  }
174  virtual void view_ratio(float xratio, float yratio, Coord& x, Coord& y) const;
175  virtual void ratio_view(Coord x, Coord y, float& xratio, float& yratio) const;
176  virtual void stroke(Canvas*, const Color*, const Brush*);
177 
178  protected:
179  virtual void transform(Transformer&, const Allocation&, const Allocation& natural) const;
180  void scene2view(const Allocation& parent) const;
181  void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const; // not really const
182  private:
183  void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene*, Coord xsize, Coord ysize);
185 
186  protected:
188 
189  private:
194  friend class OcViewGlyph;
198 };
199 
200 // view into a scene; scale in x & y direction is the same and determined
201 // by span in smallest window dimension. Coords are scene coordinates.
202 
203 class View: public XYView {
204  public:
205  View(Scene*); // view of entire scene
206  View(Coord x, Coord y, Coord span, Scene*, Coord xsize = 200, Coord ysize = 200); // x,y is
207  // center of
208  // view
210  Coord bottom,
211  Coord x_span,
212  Coord y_span,
213  Scene*,
214  Coord xsize = 200,
215  Coord ysize = 200);
216  virtual ~View();
217 
218  virtual Coord x() const, y() const;
219  virtual Coord view_width() const, view_height() const;
220 
221  void origin(Coord x, Coord y); // center
222  virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
223  virtual void move_view(Coord dx, Coord dy); // in screen coords.
224  virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen
225  // coords.
226  virtual XYView* new_view(Coord x1, Coord y1, Coord x2, Coord y2);
227 
228  protected:
229  virtual void transform(Transformer&, const Allocation&, const Allocation& natural) const;
230 
231  private:
233 };
234 
235 class Scene: public Glyph, public Observable {
236  public:
237  Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* background = NULL);
238  virtual ~Scene();
239  virtual void background(Glyph* bg = NULL);
240  virtual Coord x1() const, y1() const, x2() const, y2() const;
241  virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2);
242  virtual void wholeplot(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
243  virtual int view_count() const;
244  virtual XYView* sceneview(int) const;
245  virtual void dismiss(); // dismiss windows that contain only this scene
246  virtual void printfile(const char*);
247 
248  virtual void modified(GlyphIndex);
250  void location(GlyphIndex, Coord& x, Coord& y) const;
251  void show(GlyphIndex, bool);
252  bool showing(GlyphIndex) const;
253 
254  virtual void damage(GlyphIndex);
255  virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
256  virtual void damage_all();
257 
258  enum { NOTOOL = 0, MOVE, DELETE, CHANGECOLOR, EXTRATOOL };
259  virtual void tool(int);
260  virtual int tool();
261  virtual void help();
262  virtual void delete_label(GLabel*);
263  virtual void change_label_color(GLabel*);
264  virtual void change_line_color(GPolyLine*);
265  virtual void request(Requisition&) const;
266  virtual void allocate(Canvas*, const Allocation&, Extension&);
267  virtual void draw(Canvas*, const Allocation&) const;
268  virtual void print(Printer*, const Allocation&) const;
269  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
270 
271  virtual void append(Glyph*);
272  virtual void append_fixed(Glyph*);
273  virtual void append_viewfixed(Glyph*);
274  virtual void prepend(Glyph*);
275  virtual void insert(GlyphIndex, Glyph*);
276  virtual void remove(GlyphIndex);
277  virtual void replace(GlyphIndex, Glyph*);
278  virtual void change(GlyphIndex);
281 
282  virtual GlyphIndex count() const;
283  virtual Glyph* component(GlyphIndex) const;
284  virtual void allotment(GlyphIndex, DimensionName, Allotment&) const;
285  virtual GlyphIndex glyph_index(const Glyph*);
286  bool drawing_fixed_item() const {
287  return drawing_fixed_item_;
288  }
289 
290  static void save_all(std::ostream&);
291  static long scene_list_index(Scene*);
292  bool mark() {
293  return mark_;
294  }
295  void mark(bool m) {
296  mark_ = m;
297  }
298  virtual void save_phase1(std::ostream&);
299  virtual void save_phase2(std::ostream&);
300  virtual Coord mbs() const;
301 
302  static const Color* default_background();
303  static const Color* default_foreground();
304 
307  return hoc_obj_ptr_;
308  }
310  hoc_obj_ptr_ = o;
311  }
312  bool menu_picked() {
313  return menu_picked_;
314  }
315 
316  protected:
317  virtual void save_class(std::ostream&, const char*);
318 
319  private:
320 #if 1
321  friend class XYView;
322 #else
323  // I prefer this but the SGI compiler doesn't like it
324  friend void XYView::append_view(Scene*);
325  friend XYView::~XYView();
326 #endif
327  virtual void damage(GlyphIndex, const Allocation&);
331 
332  private:
333  Coord x1_, y1_, x2_, y2_;
334  SceneInfo_List* info_;
335  XYView_PtrList* views_;
338  int tool_;
339  bool mark_;
341  static Coord mbs_; // menu_box_size (pixels) in left top
345 
346  Coord x1_orig_, x2_orig_, y1_orig_, y2_orig_;
347 };
348 
349 class ViewWindow: public PrintableWindow, public Observer {
350  public:
351  ViewWindow(XYView*, const char* name);
352  virtual ~ViewWindow();
353  virtual void update(Observable*);
354  virtual void reconfigured();
355 };
356 
357 inline Coord Scene::x1() const {
358  return x1_;
359 }
360 inline Coord Scene::x2() const {
361  return x2_;
362 }
363 inline Coord Scene::y1() const {
364  return y1_;
365 }
366 inline Coord Scene::y2() const {
367  return y2_;
368 }
369 
370 
371 #endif
#define Color
Definition: _defines.h:74
#define Transformer
Definition: _defines.h:316
#define Canvas
Definition: _defines.h:65
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
#define Hit
Definition: _defines.h:147
#define Printer
Definition: _defines.h:211
#define GlyphIndex
Definition: _defines.h:23
#define TransformSetter
Definition: _defines.h:315
#define Glyph
Definition: _defines.h:132
Definition: graph.h:424
XYView * v_
Definition: scenevie.h:102
XYView * view()
Definition: scenevie.h:95
Glyph * g_
Definition: scenevie.h:103
OcViewGlyph(XYView *)
void viewmenu(Glyph *)
virtual ~OcViewGlyph()
virtual void save(std::ostream &)
bool menu_picked()
Definition: scenevie.h:312
virtual GlyphIndex glyph_index(const Glyph *)
bool mark_
Definition: scenevie.h:339
void mark(bool m)
Definition: scenevie.h:295
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
Object * hoc_obj_ptr_
Definition: scenevie.h:343
static long scene_list_index(Scene *)
bool drawing_fixed_item() const
Definition: scenevie.h:286
SceneInfo_List * info_
Definition: scenevie.h:334
Object * hoc_obj_ptr()
Definition: scenevie.h:306
virtual void change_label_color(GLabel *)
bool drawing_fixed_item_
Definition: scenevie.h:342
virtual Coord y2() const
Definition: scenevie.h:366
virtual void save_phase1(std::ostream &)
virtual void damage(GlyphIndex, const Allocation &)
virtual void change_to_fixed(GlyphIndex, XYView *)
virtual void save_phase2(std::ostream &)
virtual Coord y1() const
Definition: scenevie.h:363
virtual void replace(GlyphIndex, Glyph *)
virtual void allocate(Canvas *, const Allocation &, Extension &)
virtual void background(Glyph *bg=NULL)
virtual void delete_label(GLabel *)
virtual void append_viewfixed(Glyph *)
virtual void tool(int)
ScenePicker * picker()
static const Color * default_background()
Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph *background=NULL)
static Scene * current_scene_
Definition: scenevie.h:340
void check_allocation(GlyphIndex)
Glyph * background_
Definition: scenevie.h:336
virtual void append(Glyph *)
static Coord mbs_
Definition: scenevie.h:341
virtual void change_to_vfixed(GlyphIndex, XYView *)
virtual void prepend(Glyph *)
void remove_view(XYView *)
virtual int tool()
static const Color * default_foreground()
virtual void change(GlyphIndex)
bool menu_picked_
Definition: scenevie.h:344
virtual void save_class(std::ostream &, const char *)
bool mark()
Definition: scenevie.h:292
virtual void request(Requisition &) const
ScenePicker * picker_
Definition: scenevie.h:337
virtual ~Scene()
Coord x1_
Definition: scenevie.h:333
virtual Coord x2() const
Definition: scenevie.h:360
virtual void change_line_color(GPolyLine *)
virtual GlyphIndex count() const
virtual Glyph * component(GlyphIndex) const
virtual void remove(GlyphIndex)
@ CHANGECOLOR
Definition: scenevie.h:258
int tool_
Definition: scenevie.h:338
virtual Coord x1() const
Definition: scenevie.h:357
virtual void insert(GlyphIndex, Glyph *)
Coord x1_orig_
Definition: scenevie.h:346
static void save_all(std::ostream &)
virtual void allotment(GlyphIndex, DimensionName, Allotment &) const
void append_view(XYView *)
virtual void print(Printer *, const Allocation &) const
virtual void append_fixed(Glyph *)
virtual void help()
void hoc_obj_ptr(Object *o)
Definition: scenevie.h:309
virtual void draw(Canvas *, const Allocation &) const
virtual Coord mbs() const
XYView_PtrList * views_
Definition: scenevie.h:335
Definition: scenevie.h:203
virtual void move_view(Coord dx, Coord dy)
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
Coord x_span_
Definition: scenevie.h:232
View(Scene *)
void origin(Coord x, Coord y)
virtual Coord y() const
virtual Coord view_height() const
virtual ~View()
virtual Coord x() const
virtual Coord view_width() const
Coord y_span_
Definition: scenevie.h:232
View(Coord x, Coord y, Coord span, Scene *, Coord xsize=200, Coord ysize=200)
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
View(Coord left, Coord bottom, Coord x_span, Coord y_span, Scene *, Coord xsize=200, Coord ysize=200)
virtual void reconfigured()
virtual ~ViewWindow()
ViewWindow(XYView *, const char *name)
virtual void update(Observable *)
virtual void damage_area(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
Coord x_span_
Definition: scenevie.h:190
Canvas * canvas()
Coord yd2_
Definition: scenevie.h:196
Coord x_pick_epsilon()
Definition: scenevie.h:153
virtual Coord bottom() const
virtual Coord height() const
XYView(Scene *, Coord xsize=200, Coord ysize=200)
virtual void move_view(Coord dx, Coord dy)
virtual Coord top() const
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene *, Coord xsize, Coord ysize)
void rebind()
virtual void printfile(const char *)
virtual void zout(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
Coord yd1_
Definition: scenevie.h:196
virtual void allocate(Canvas *, const Allocation &, Extension &)
void size(Coord x1, Coord y1, Coord x2, Coord y2)
virtual Scene * scene() const
virtual void set_damage_area(Canvas *)
virtual void undraw()
virtual Coord width() const
void origin(Coord x1, Coord y1)
Coord ysize_orig_
Definition: scenevie.h:193
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
static Coord view_margin_
Definition: scenevie.h:197
Coord xc0_
Definition: scenevie.h:193
virtual ~XYView()
virtual Coord left() const
OcViewGlyph * parent()
Definition: scenevie.h:165
void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
void x_span(Coord)
Coord yc0_
Definition: scenevie.h:193
Transformer scene2viewparent_
Definition: scenevie.h:192
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
Coord x1_
Definition: scenevie.h:190
virtual void save(std::ostream &)
virtual void request(Requisition &) const
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
virtual void ratio_view(Coord x, Coord y, float &xratio, float &yratio) const
virtual void damage_all()
virtual Coord right() const
Canvas * canvas_
Definition: scenevie.h:191
XYView(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene *, Coord xsize=200, Coord ysize=200)
Coord xsize_orig_
Definition: scenevie.h:193
void y_span(Coord)
Coord xsize_
Definition: scenevie.h:193
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
Coord xd2_
Definition: scenevie.h:196
Coord ysize_
Definition: scenevie.h:193
void scene2view(const Allocation &parent) const
virtual void zin(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static XYView * current_draw_view()
static XYView * current_pick_view()
Coord x_pick_epsilon_
Definition: scenevie.h:187
virtual void stroke(Canvas *, const Color *, const Brush *)
const Transformer & s2o() const
Definition: scenevie.h:139
Coord y1_
Definition: scenevie.h:190
void canvas(Canvas *)
Coord view_margin() const
Definition: scenevie.h:171
OcViewGlyph * parent_
Definition: scenevie.h:195
Coord y_pick_epsilon()
Definition: scenevie.h:156
Coord y_pick_epsilon_
Definition: scenevie.h:187
Coord xd1_
Definition: scenevie.h:196
Coord y_span_
Definition: scenevie.h:190
static void current_pick_view(XYView *)
void append_view(Scene *)
unsigned int DimensionName
Definition: geometry.h:40
static double location(void *v)
Definition: impedanc.cpp:85
char * name
Definition: init.cpp:16
#define xorg
Definition: axis.cpp:156
#define yorg
Definition: axis.cpp:157
virtual void move(const Event &e)
Definition: ocinput.h:26
o
Definition: seclist.cpp:175
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227