NEURON
graph.h
Go to the documentation of this file.
1 #ifndef graph_h
2 #define graph_h
3 
4 #include <ivstream.h>
5 #include <OS/list.h>
6 #include <OS/string.h>
7 #include <InterViews/observe.h>
8 #include "scenevie.h"
9 
10 class DataVec;
11 class Color;
12 class Brush;
13 struct Symbol;
14 class Symlist;
15 class GraphLine;
16 class GLabel;
17 class GPolyLine;
18 class SymChooser;
19 class Event;
20 class GraphVector;
21 class HocCommand;
22 class LineExtension;
23 class TelltaleState;
24 struct Object;
25 
26 declarePtrList(LineList, GraphLine);
27 
28 //all Glyphs added to Graph must be enclosed in a GraphItem
29 class GraphItem : public MonoGlyph {
30 public:
31  enum { ERASE_LINE=1, ERASE_AXIS };
32  GraphItem(Glyph* g, bool = true, bool pick = true);
33  virtual ~GraphItem();
34  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
35  virtual void save(std::ostream&, Coord, Coord);
36  virtual void erase(Scene*, GlyphIndex, int erase_type);
37  bool save() { return save_; }
38  void save(bool s) {save_ = s;}
39  virtual bool is_polyline();
40  virtual bool is_mark();
41  virtual bool is_fast() { return false;}
42  virtual bool is_graphVector() { return false;}
43 private:
44  bool save_;
45  bool pick_;
46 };
47 
48 class Graph : public Scene { // Scene of GraphLines labels and polylines
49 public:
50  enum {CROSSHAIR = Scene::EXTRATOOL, CHANGELABEL, PICK, EXTRAGRAPHTOOL};
51  Graph(bool = true); //true means map a new default view
52  virtual ~Graph();
53  void axis(DimensionName, float min, float max, float pos = 0.,
54  int ntics = -1, int nminor=0,
55  int invert = 0, bool number = true);
56  GraphLine* add_var(const char*, const Color*, const Brush*,
57  bool usepointer, int fixtype = 1, double* p = NULL,
58  const char* lab = NULL, Object* obj = NULL);
59  void x_expr(const char*, bool usepointer);
60  void add_polyline(GPolyLine*);
61  void add_graphVector(GraphVector*);
62  void begin();
63  void plot(float);
64  void flush();
65  void fast_flush();
66  void begin_line(const char* s = NULL);
67  void begin_line(const Color*, const Brush*, const char* s = NULL);
68  void line(Coord x, Coord y);
69  void mark(Coord x, Coord y, char style='+', float size=12,
70  const Color* =NULL, const Brush* =NULL);
71  void erase();
72  virtual void erase_all();
73  void erase_lines(); // all GPolylines
74  virtual void delete_label(GLabel*);
75  virtual bool change_label(GLabel*, const char*, GLabel* gl=NULL);
76  virtual void help();
77  void keep_lines();
78  void keep_lines_toggle();
79  void family(bool);
80  void family(const char*);
81  void family_label_chooser();
82  void new_axis();
83  void erase_axis();
84  void view_axis();
85  void view_box();
86  void change_prop();
87  void color(int);
88  void brush(int);
89  const Color* color() const {return color_;}
90  const Brush* brush() const {return brush_;}
91  void set_cross_action(const char*, Object*, bool vectorcopy=false);
92  void cross_action(char, GPolyLine*, int);
93  void cross_action(char, Coord, Coord);
94  void simgraph();// faintly analogous to Vector.record for localstep plotting
95 
96  virtual void draw(Canvas*, const Allocation&) const;
97  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
98  virtual GlyphIndex glyph_index(const Glyph*);
99  virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2);
100  virtual void wholeplot(Coord &x1, Coord& y1, Coord& x2, Coord& y2)const;
101 
102  //label info
103  GLabel* label(float x, float y, const char* s, int fixtype,
104  float scale, float x_align, float y_align, const Color*);
105  GLabel* label(float x, float y, const char* s, float n=0, int fixtype = -1);
106  GLabel* label(const char* s, int fixtype = -1);
107  GLabel* new_proto_label() const;
108  void fixed(float scale);
109  void vfixed(float scale);
110  void relative(float scale);
111  void align(float x, float y);
112  void choose_sym();
113  void name(char*);
114  void change_label_color(GLabel*);
115  void change_line_color(GPolyLine*);
116  void update_ptrs();
117 
118  virtual void save_phase1(std::ostream&);
119  virtual void save_phase2(std::ostream&);
120  int labeltype() const { return label_fixtype_; }
121  static bool label_chooser(const char*, char*, GLabel*, Coord x = 400., Coord y = 400.);
122 
123  virtual void see_range_plot(GraphVector*);
124  static void ascii(std::ostream*);
125  static std::ostream* ascii();
126 private:
127  void extension_start();
128  void extension_continue();
129  void ascii_save(std::ostream& o) const;
130  void family_value();
131 private:
133  LineList line_list_;
134  int loc_;
138  static SymChooser* fsc_;
141 
142  const Color* color_;
143  const Brush* brush_;
146  float label_x_align_, label_y_align_;
147  float label_x_, label_y_, label_n_;
151  double family_val_;
155 
157  double* x_pval_;
158 
160  static std::ostream* ascii_;
161 };
162 
163 class DataVec :public Resource { // info for single dimension
164 public:
165  DataVec(int size);
166  DataVec(const DataVec*);
167  virtual ~DataVec();
168  void add(float);
169  float max() const, min() const;
170  float max(int low, int high), min(int, int);
171  int loc_max() const, loc_min() const;
172  void erase();
173  int count() const { return count_;}
174  void write();
175  float get_val(int i) const {return y_[i];} //y[(i<count_)?i:count_-1)];
176  int size() const { return size_; }
177  const Coord* vec() { return y_;}
178  void running_start();
179  float running_max();
180  float running_min();
181  Object** new_vect(GLabel* g = NULL)const;
182 private:
183  int count_, size_, iMinLoc_, iMaxLoc_;
184  int running_min_loc_, running_max_loc_;
185  float* y_;
186 };
187 
188 class DataPointers : public Resource { // vector of pointers
189 public:
190  DataPointers(int size = 50);
191  virtual ~DataPointers();
192  void add(double*);
193  void erase() { count_ = 0; }
194  int size() { return size_;}
195  int count() {return count_;}
196  double* p(int i) { return px_[i]; }
197  void update_ptrs();
198 private:
199  int count_, size_;
200  double** px_;
201 };
202 
203 class GPolyLine : public Glyph {
204 public:
205  GPolyLine(DataVec* x, const Color* = NULL, const Brush* = NULL);
206  GPolyLine(DataVec* x, DataVec* y, const Color* = NULL, const Brush* = NULL);
208  virtual ~GPolyLine();
209 
210  virtual void request(Requisition&) const;
211  virtual void allocate(Canvas*, const Allocation&, Extension&);
212  virtual void draw(Canvas*, const Allocation&) const;
213  virtual void draw_specific(Canvas*, const Allocation&, int, int) const;
214  virtual void print(Printer*, const Allocation&) const;
215  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
216  virtual void save(std::ostream&);
217  virtual void pick_vector();
218 
219  void plot(Coord x, Coord y);
220  void erase() { y_->erase();}
221  virtual void erase_line(Scene*, GlyphIndex); // Erase by menu command
222 
223  void color(const Color*);
224  void brush(const Brush*);
225  const Color* color() const {return color_;}
226  const Brush* brush() const {return brush_;}
227 
228  Coord x(int index) const { return x_->get_val(index); }
229  Coord y(int index) const { return y_->get_val(index); }
230  const DataVec* x_data() const {return x_;}
231  const DataVec* y_data() const {return y_;}
232 
233  GLabel* label() const { return glabel_; }
234  void label(GLabel*);
235  void label_loc(Coord& x, Coord& y)const;
236 
237  // screen coords
238  bool near(Coord, Coord, float, const Transformer&) const;
239  // model coords input but checking relative to screen coords
240  int nearest(Coord, Coord, const Transformer&, int index = -1) const;
241  bool keepable() { return keepable_;}
242 private:
243  void init(DataVec*, DataVec*, const Color*, const Brush*);
244 protected:
247  const Color* color_;
248  const Brush* brush_;
250  bool keepable_;
251 };
252 
253 class GraphLine : public GPolyLine , public Observer { // An oc variable to plot
254 public:
255  GraphLine(const char*, DataVec* x, Symlist**, const Color* = NULL, const Brush* = NULL,
256  bool usepointer=0, double* pd = NULL, Object* obj = NULL);
257  virtual ~GraphLine();
258 
259  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
260  virtual void save(std::ostream&);
261 
262  void plot();
263 
264  const char* name() const;
265  LineExtension* extension() { return extension_; }
266  void extension_start();
267  void extension_continue();
268  const Color* save_color() const { return save_color_;}
269  const Brush* save_brush() const { return save_brush_;}
270  void save_color(const Color*);
271  void save_brush(const Brush*);
272  bool change_expr(const char*, Symlist**);
273  virtual void update(Observable*);
274  bool valid(bool check = false);
275  virtual void erase_line(Scene*, GlyphIndex) {erase();} // Erase by menu command
276  void simgraph_activate(bool);
277  void simgraph_init();
278  void simgraph_continuous(double);
279  void update_ptrs();
280 
282  double* pval_;
284 private:
285  LineExtension* extension_;
288  bool valid_;
290 };
291 
292 class GraphVector : public GPolyLine , public Observer{ // fixed x and vector of pointers
293 public:
294  GraphVector(const char*, const Color* = NULL, const Brush* = NULL);
295  virtual ~GraphVector();
296  virtual void request(Requisition&) const;
297  void begin();
298  void add(float, double*);
299  virtual void save(std::ostream&);
300  const char* name() const;
301  bool trivial() const;
302 
303  virtual bool choose_sym(Graph*);
304  virtual void update(Observable*);
305  DataPointers* py_data() { return dp_; }
306  void update_ptrs();
307  void record_install();
308  void record_uninstall();
309 private:
313 };
314 
315 class GPolyLineItem : public GraphItem {
316 public:
318  virtual ~GPolyLineItem(){};
319  virtual bool is_polyline();
320  virtual void save(std::ostream& o, Coord, Coord){
321  ((GPolyLine*)body())->save(o);}
322  virtual void erase(Scene* s, GlyphIndex i, int type) {
323  if (type & GraphItem::ERASE_LINE) {
324  s->remove(i);
325  }
326  }
327 };
328 
329 class GLabel : public Glyph {
330 public:
331  GLabel(const char* s, const Color*, int fixtype = 1, float size = 12,
332  float x_align = 0., float y_align = 0.);
333  virtual ~GLabel();
334  virtual Glyph* clone() const;
335 
336  virtual void request(Requisition&) const;
337  virtual void allocate(Canvas*, const Allocation&, Extension&);
338  virtual void draw(Canvas*, const Allocation&) const;
339  virtual void save(std::ostream&, Coord, Coord);
340  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
341 
342  void text(const char*);
343  void fixed(float scale);
344  void vfixed(float scale);
345  void relative(float scale);
346  void align(float x, float y);
347  void color(const Color*);
348 
349  bool fixed() const {return fixtype_ == 1;}
350  float scale() const { return scale_;}
351  const char* text() const { return text_.string();}
352  int fixtype() const {return fixtype_;}
353  float x_align() const {return x_align_;}
354  float y_align() const {return y_align_;}
355  const Color* color() const { return color_;}
356  bool erase_flag() { return erase_flag_; }
357  void erase_flag(bool b) { erase_flag_ = b; }
358 
359  GPolyLine* labeled_line() const { return gpl_; }
360 private:
361  void need(Canvas*, const Allocation&, Extension&)const;
362  friend void GPolyLine::label(GLabel*);
363 private:
364  int fixtype_;
365  float scale_;
366  float x_align_, y_align_;
369  const Color* color_;
372 };
373 
375 public:
376  ColorPalette();
377  virtual ~ColorPalette();
378  const Color* color(int)const;
379  const Color* color(int, const char*);
380  const Color* color(int, const Color*);
381  int color(const Color*)const;
382 // enum {COLOR_SIZE = 20};
383 // ZFM: changed to allow more colors
384  enum {COLOR_SIZE = 100};
385 private:
386  const Color* color_palette[COLOR_SIZE];
387 };
389 public:
390  BrushPalette();
391  virtual ~BrushPalette();
392  const Brush* brush(int)const;
393  const Brush* brush(int index, int pattern, Coord width);
394  int brush(const Brush*)const;
395  enum {BRUSH_SIZE = 25};
396 private:
397  const Brush* brush_palette[BRUSH_SIZE];
398 };
399 extern ColorPalette* colors;
400 extern BrushPalette* brushes;
401 
402 #endif
o
Definition: seclist.cpp:180
Symbol * x_expr_
Definition: graph.h:156
Definition: hocdec.h:84
static double fast_flush(void *v)
Definition: shapeplt.cpp:60
double max(double a, double b)
Definition: geometry3d.cpp:22
Coord x(int index) const
Definition: graph.h:228
short type
Definition: cabvars.h:10
Symlist * symlist_
Definition: graph.h:132
const Color * save_color_
Definition: graph.h:286
static char * pattern
Definition: regexp.cpp:82
#define text
Definition: plot.cpp:81
GPolyLine * gpl_
Definition: graph.h:370
void erase()
Definition: graph.h:193
bool family_on_
Definition: graph.h:149
bool keepable_
Definition: graph.h:250
GraphVector * rvp_
Definition: graph.h:159
bool vector_copy_
Definition: graph.h:154
int family_cnt_
Definition: graph.h:152
#define min(a, b)
Definition: matrix.h:157
virtual bool is_mark()
#define g
Definition: passive0.cpp:23
#define Glyph
Definition: _defines.h:132
#define Coord
Definition: _defines.h:19
virtual void save(std::ostream &o, Coord, Coord)
Definition: graph.h:320
static double valid(void *v)
Definition: linmod1.cpp:52
#define Brush
Definition: _defines.h:59
size_t p
#define Color
Definition: _defines.h:74
CopyString name_
Definition: graph.h:311
bool extension_flushed_
Definition: graph.h:136
float get_val(int i) const
Definition: graph.h:175
static void update(NrnThread *)
Definition: fadvance.cpp:570
GPolyLine * current_polyline_
Definition: graph.h:140
LineExtension * extension_
Definition: graph.h:285
Definition: graph.h:163
bool keepable()
Definition: graph.h:241
#define print
Definition: redef.h:109
const Brush * save_brush() const
Definition: graph.h:269
float x_align() const
Definition: graph.h:353
const char * text() const
Definition: graph.h:351
int count() const
Definition: graph.h:173
DataVec * y_
Definition: graph.h:245
float y_align_
Definition: graph.h:366
const Color * color() const
Definition: graph.h:225
void save(bool s)
Definition: graph.h:38
bool valid_
Definition: graph.h:288
ColorPalette * colors
float scale() const
Definition: graph.h:350
const DataVec * x_data() const
Definition: graph.h:230
double * p(int i)
Definition: graph.h:196
Definition: graph.h:48
virtual bool is_graphVector()
Definition: graph.h:42
void init()
Definition: init.cpp:169
virtual bool is_fast()
Definition: graph.h:41
GPolyLineItem(Glyph *g)
Definition: graph.h:317
GLabel * family_label_
Definition: graph.h:150
Glyph * label_
Definition: graph.h:368
HocCommand * cross_action_
Definition: graph.h:153
int const size_t const size_t n
Definition: nrngsl.h:12
#define color
Definition: rbtqueue.cpp:50
static double check(double t, Daspk *ida)
Definition: nrndaspk.cpp:214
GLabel * glabel_
Definition: graph.h:249
virtual void erase(Scene *s, GlyphIndex i, int type)
Definition: graph.h:322
#define Printer
Definition: _defines.h:211
_CONST char * s
Definition: system.cpp:74
DataVec * x_
Definition: graph.h:246
int fixtype() const
Definition: graph.h:352
#define near
Definition: mwprefix.h:34
static N_Vector x_
Coord y(int index) const
Definition: graph.h:229
static std::ostream * ascii_
Definition: graph.h:160
bool erase_flag()
Definition: graph.h:356
#define GlyphIndex
Definition: _defines.h:23
static void help(const char *)
Definition: hel2mos.cpp:104
const Color * color_
Definition: graph.h:247
#define Canvas
Definition: _defines.h:65
const Coord * vec()
Definition: graph.h:177
const Brush * save_brush_
Definition: graph.h:287
float y_align() const
Definition: graph.h:354
float label_y_
Definition: graph.h:147
int labeltype() const
Definition: graph.h:120
Definition: model.h:57
GraphItem(Glyph *g, bool=true, bool pick=true)
bool erase_flag_
Definition: graph.h:371
const Color * color() const
Definition: graph.h:355
char * name
Definition: init.cpp:16
Symbol * expr_
Definition: graph.h:281
void erase()
Definition: graph.h:220
bool save()
Definition: graph.h:37
double * pval_
Definition: graph.h:282
static N_Vector y_
bool pick_
Definition: graph.h:45
LineExtension * extension()
Definition: graph.h:265
Object * obj_
Definition: graph.h:283
bool fixed() const
Definition: graph.h:349
BrushPalette * brushes
unsigned int DimensionName
Definition: geometry.h:40
const Brush * brush() const
Definition: graph.h:90
#define Event
Definition: _defines.h:107
int loc_
Definition: graph.h:134
DataPointers * py_data()
Definition: graph.h:305
int count()
Definition: graph.h:195
const Color * color_
Definition: graph.h:142
bool save_
Definition: graph.h:44
DataVec * x_
Definition: graph.h:135
int size() const
Definition: graph.h:176
const Brush * brush() const
Definition: graph.h:226
float label_scale_
Definition: graph.h:145
double * x_pval_
Definition: graph.h:157
virtual ~GraphItem()
GPolyLine * labeled_line() const
Definition: graph.h:359
LineList line_list_
Definition: graph.h:133
float label_y_align_
Definition: graph.h:146
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
int size_
Definition: graph.h:199
int label_fixtype_
Definition: graph.h:144
#define Transformer
Definition: _defines.h:316
int size()
Definition: graph.h:194
virtual void erase_line(Scene *, GlyphIndex)
Definition: graph.h:275
CopyString * var_name_
Definition: graph.h:139
static SymChooser * fsc_
Definition: graph.h:138
Definition: hocdec.h:226
declarePtrList(LineList, GraphLine)
virtual void remove(GlyphIndex)
const Brush * brush_
Definition: graph.h:143
#define i
Definition: md1redef.h:12
const Brush * brush_
Definition: graph.h:248
virtual ~GPolyLineItem()
Definition: graph.h:318
CopyString text_
Definition: graph.h:367
SymChooser * sc_
Definition: graph.h:137
static char line[MAXLINE]
Definition: ivecop.c:35
int size_
Definition: graph.h:183
const Color * color_
Definition: graph.h:369
Definition: graph.h:329
double family_val_
Definition: graph.h:151
GLabel * label() const
Definition: graph.h:233
#define relative(pc)
Definition: cabcode.cpp:2149
DataPointers * dp_
Definition: graph.h:310
#define add
Definition: redef.h:24
int fixtype_
Definition: graph.h:364
TelltaleState * keep_lines_toggle_
Definition: graph.h:148
DataVec * simgraph_x_sav_
Definition: graph.h:289
void erase_flag(bool b)
Definition: graph.h:357
#define TelltaleState
Definition: _defines.h:296
float * y_
Definition: graph.h:185
#define MonoGlyph
Definition: _defines.h:181
virtual void erase(Scene *, GlyphIndex, int erase_type)
const DataVec * y_data() const
Definition: graph.h:231
int running_min_loc_
Definition: graph.h:184
const Color * save_color() const
Definition: graph.h:268
const Color * color() const
Definition: graph.h:89
#define begin
Definition: redef.h:32
virtual bool is_polyline()
invert
Definition: extdef.h:3
return NULL
Definition: cabcode.cpp:461
bool disconnect_defer_
Definition: graph.h:312
double ** px_
Definition: graph.h:200
short index
Definition: cabvars.h:11
float scale_
Definition: graph.h:365
#define Hit
Definition: _defines.h:147