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