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() {return v_;}
96  virtual void save(std::ostream&);
97  void viewmenu(Glyph*);
98 private:
101 };
102 
103 // view into a scene; independent scales in x and y direction.
104 // ie. as window resized, view remains same (directions magnified separately)
105 class XYView : public TransformSetter , public Observable{
106 public:
107  XYView(Scene*, Coord xsize=200, Coord ysize=200);
108  XYView(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene*,
109  Coord xsize=200, Coord ysize=200);
110  virtual ~XYView();
111 
112  virtual Scene* scene() const;
113  virtual Coord left() const, right() const, top() const, bottom() const;
114  virtual Coord width() const, height() const;
115 
116  virtual void damage(Glyph*, const Allocation&,
117  bool fixed = false, bool viewfixed = false);
118  virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
119  virtual void damage_all();
120 
121  /* damage area in model coords, call from draw */
122  virtual void damage_area(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
123  virtual void set_damage_area(Canvas*);
124 
125  virtual void request(Requisition&)const;
126  virtual void allocate(Canvas*, const Allocation&, Extension&);
127  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
128  virtual void undraw();
129 
130  Canvas* canvas();
131  //transforms canvas from scene to parent glyph coordinates.
132  const Transformer& s2o()const {return scene2viewparent_;}
133  void canvas(Canvas*);
134 
135  void size(Coord x1, Coord y1, Coord x2, Coord y2);
136  void origin(Coord x1, Coord y1);
137  void x_span(Coord);
138  void y_span(Coord);
139  virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
140 
141  static XYView* current_pick_view();
142  static void current_pick_view(XYView*);
143  static XYView* current_draw_view();
144  Coord x_pick_epsilon() {return x_pick_epsilon_;}
145  Coord y_pick_epsilon() {return y_pick_epsilon_;}
146  virtual void move_view(Coord dx, Coord dy); // in screen coords.
147  virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen coords.
148  virtual XYView* new_view(Coord x1, Coord y1, Coord x2, Coord y2);
149  void rebind(); // stop the flicker on scale_view and move_view
150  virtual void save(std::ostream&);
151  OcViewGlyph* parent() { return parent_;}
152  virtual void printfile(const char*);
153  virtual void zout(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
154  virtual void zin(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
155  Coord view_margin() const {return view_margin_;}
156  virtual void view_ratio(float xratio, float yratio, Coord& x, Coord& y) const;
157  virtual void ratio_view(Coord x, Coord y, float& xratio, float& yratio) const;
158  virtual void stroke(Canvas*, const Color*, const Brush*);
159 protected:
160  virtual void transform(
161  Transformer&, const Allocation&, const Allocation& natural
162  ) const;
163  void scene2view(const Allocation& parent) const;
164  void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const; // not really const
165 private:
166  void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene*,
167  Coord xsize, Coord ysize);
168  void append_view(Scene*);
169 protected:
170  Coord x_pick_epsilon_, y_pick_epsilon_;
171 private:
172  Coord x1_, y1_, x_span_, y_span_;
175  Coord xsize_, ysize_, xsize_orig_, ysize_orig_, xc0_, yc0_;
176  friend class OcViewGlyph;
178  Coord xd1_, xd2_, yd1_, yd2_;
180 };
181 
182 // view into a scene; scale in x & y direction is the same and determined
183 // by span in smallest window dimension. Coords are scene coordinates.
184 
185 class View : public XYView {
186 public:
187  View(Scene*); // view of entire scene
188  View(Coord x, Coord y, Coord span, Scene*,
189  Coord xsize = 200, Coord ysize = 200); //x,y is center of view
190  View(Coord left, Coord bottom, Coord x_span, Coord y_span, Scene*,
191  Coord xsize=200, Coord ysize=200);
192  virtual ~View();
193 
194  virtual Coord x() const, y() const;
195  virtual Coord view_width() const, view_height() const;
196 
197  void origin(Coord x, Coord y); // center
198  virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2);
199  virtual void move_view(Coord dx, Coord dy); // in screen coords.
200  virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale); // in screen coords.
201  virtual XYView* new_view(Coord x1, Coord y1, Coord x2, Coord y2);
202 protected:
203  virtual void transform(
204  Transformer&, const Allocation&, const Allocation& natural
205  ) const;
206 private:
207  Coord x_span_, y_span_;
208 };
209 
210 class Scene : public Glyph , public Observable{
211 public:
212  Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* background=NULL);
213  virtual ~Scene();
214  virtual void background(Glyph* bg=NULL);
215  virtual Coord x1() const, y1() const, x2() const, y2() const;
216  virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2);
217  virtual void wholeplot(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const;
218  virtual int view_count() const;
219  virtual XYView* sceneview(int) const;
220  virtual void dismiss(); // dismiss windows that contain only this scene
221  virtual void printfile(const char*);
222 
223  virtual void modified(GlyphIndex);
224  void move(GlyphIndex, Coord x, Coord y);
225  void location(GlyphIndex, Coord& x, Coord& y)const;
226  void show(GlyphIndex, bool);
227  bool showing(GlyphIndex) const;
228 
229  virtual void damage(GlyphIndex);
230  virtual void damage(Coord x1, Coord y1, Coord x2, Coord y2);
231  virtual void damage_all();
232 
233  enum {NOTOOL=0, MOVE, DELETE, CHANGECOLOR, EXTRATOOL};
234  virtual void tool(int);
235  virtual int tool();
236  virtual void help();
237  virtual void delete_label(GLabel*);
238  virtual void change_label_color(GLabel*);
239  virtual void change_line_color(GPolyLine*);
240  virtual void request(Requisition&) const;
241  virtual void allocate(Canvas*, const Allocation&, Extension&);
242  virtual void draw(Canvas*, const Allocation&) const;
243  virtual void print(Printer*, const Allocation&) const;
244  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
245 
246  virtual void append(Glyph*);
247  virtual void append_fixed(Glyph*);
248  virtual void append_viewfixed(Glyph*);
249  virtual void prepend(Glyph*);
250  virtual void insert(GlyphIndex, Glyph*);
251  virtual void remove(GlyphIndex);
252  virtual void replace(GlyphIndex, Glyph*);
253  virtual void change(GlyphIndex);
254  virtual void change_to_fixed(GlyphIndex, XYView*);
255  virtual void change_to_vfixed(GlyphIndex, XYView*);
256 
257  virtual GlyphIndex count() const;
258  virtual Glyph* component(GlyphIndex) const;
259  virtual void allotment(GlyphIndex, DimensionName, Allotment&) const;
260  virtual GlyphIndex glyph_index(const Glyph*);
261  bool drawing_fixed_item()const { return drawing_fixed_item_;}
262 
263  static void save_all(std::ostream&);
264  static long scene_list_index(Scene*);
265  bool mark() {return mark_;}
266  void mark(bool m) {mark_ = m;}
267  virtual void save_phase1(std::ostream&);
268  virtual void save_phase2(std::ostream&);
269  virtual Coord mbs() const;
270 
271  static const Color* default_background();
272  static const Color* default_foreground();
273 
274  ScenePicker* picker();
275  Object* hoc_obj_ptr() { return hoc_obj_ptr_;}
276  void hoc_obj_ptr(Object* o) { hoc_obj_ptr_ = o;}
277  bool menu_picked() { return menu_picked_;}
278 protected:
279  virtual void save_class(std::ostream&, const char*);
280 private:
281 #if 1
282  friend class XYView;
283 #else
284  // I prefer this but the SGI compiler doesn't like it
285  friend void XYView::append_view(Scene*);
286  friend XYView::~XYView();
287 #endif
288  virtual void damage(GlyphIndex, const Allocation&);
289  void append_view(XYView*);
290  void remove_view(XYView*);
291  void check_allocation(GlyphIndex);
292 private:
293  Coord x1_, y1_, x2_, y2_;
294  SceneInfo_List* info_;
295  XYView_PtrList* views_;
298  int tool_;
299  bool mark_;
301  static Coord mbs_; // menu_box_size (pixels) in left top
305 
306  Coord x1_orig_, x2_orig_, y1_orig_, y2_orig_;
307 };
308 
309 class ViewWindow : public PrintableWindow , public Observer {
310 public:
311  ViewWindow(XYView*, const char* name);
312  virtual ~ViewWindow();
313  virtual void update(Observable*);
314  virtual void reconfigured();
315 };
316 
317 inline Coord Scene::x1() const { return x1_; }
318 inline Coord Scene::x2() const { return x2_; }
319 inline Coord Scene::y1() const { return y1_; }
320 inline Coord Scene::y2() const { return y2_; }
321 
322 
323 #endif
o
Definition: seclist.cpp:180
Coord y2_orig_
Definition: scenevie.h:306
Transformer scene2viewparent_
Definition: scenevie.h:174
ScenePicker * picker_
Definition: scenevie.h:297
virtual ~OcViewGlyph()
Glyph * g_
Definition: scenevie.h:100
XYView_PtrList * views_
Definition: scenevie.h:295
Coord yd2_
Definition: scenevie.h:178
bool drawing_fixed_item() const
Definition: scenevie.h:261
const Transformer & s2o() const
Definition: scenevie.h:132
Coord y_span_
Definition: scenevie.h:207
XYView * v_
Definition: scenevie.h:99
#define TransformSetter
Definition: _defines.h:315
#define Glyph
Definition: _defines.h:132
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
#define Color
Definition: _defines.h:74
virtual Coord x2() const
Definition: scenevie.h:318
#define Scene
Definition: _defines.h:251
static void update(NrnThread *)
Definition: fadvance.cpp:570
static double location(void *v)
Definition: impedanc.cpp:82
#define print
Definition: redef.h:109
Coord y_span_
Definition: scenevie.h:172
SceneInfo_List * info_
Definition: scenevie.h:294
XYView * view()
Definition: scenevie.h:95
void init()
Definition: init.cpp:169
Coord x1_
Definition: scenevie.h:172
Coord y1_
Definition: scenevie.h:172
void append(Item *ql, Item *q)
Definition: list.cpp:348
bool mark()
Definition: scenevie.h:265
#define Printer
Definition: _defines.h:211
virtual Coord x1() const
Definition: scenevie.h:317
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
int tool_
Definition: scenevie.h:298
#define xorg
Definition: axis.cpp:156
static Coord view_margin_
Definition: scenevie.h:179
static double insert(void *v)
Definition: tqueue.cpp:22
#define GlyphIndex
Definition: _defines.h:23
static void help(const char *)
Definition: hel2mos.cpp:104
void viewmenu(Glyph *)
#define Canvas
Definition: _defines.h:65
Coord view_margin() const
Definition: scenevie.h:155
Coord ysize_orig_
Definition: scenevie.h:175
bool menu_picked_
Definition: scenevie.h:304
OcViewGlyph(XYView *)
char * name
Definition: init.cpp:16
bool mark_
Definition: scenevie.h:299
void hoc_obj_ptr(Object *o)
Definition: scenevie.h:276
unsigned int DimensionName
Definition: geometry.h:40
virtual ~XYView()
OcViewGlyph * parent_
Definition: scenevie.h:177
Canvas * canvas_
Definition: scenevie.h:173
Glyph * background_
Definition: scenevie.h:296
#define parent
Definition: rbtqueue.cpp:47
#define left
Definition: rbtqueue.cpp:45
virtual void move(const Event &e)
Definition: ocinput.h:19
bool menu_picked()
Definition: scenevie.h:277
OcViewGlyph * parent()
Definition: scenevie.h:151
virtual void save(std::ostream &)
#define right
Definition: rbtqueue.cpp:46
virtual Coord y2() const
Definition: scenevie.h:320
Coord y_pick_epsilon_
Definition: scenevie.h:170
#define Transformer
Definition: _defines.h:316
static int component(PyHocObject *po)
Definition: nrnpy_hoc.cpp:448
Definition: hocdec.h:226
Definition: scenevie.h:185
#define yorg
Definition: axis.cpp:157
Coord x_pick_epsilon()
Definition: scenevie.h:144
Item * prepend(Item *ql, Item *q)
Definition: list.cpp:355
Object * hoc_obj_ptr()
Definition: scenevie.h:275
Definition: graph.h:329
void mark(bool m)
Definition: scenevie.h:266
Coord y_pick_epsilon()
Definition: scenevie.h:145
bool drawing_fixed_item_
Definition: scenevie.h:302
virtual Coord y1() const
Definition: scenevie.h:319
void append_view(Scene *)
Object * hoc_obj_ptr_
Definition: scenevie.h:303
static Scene * current_scene_
Definition: scenevie.h:300
return NULL
Definition: cabcode.cpp:461
Coord y2_
Definition: scenevie.h:293
static Coord mbs_
Definition: scenevie.h:301
#define Hit
Definition: _defines.h:147