NEURON
xyview.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <ivstream.h>
5 #include <stdio.h>
6 #include <assert.h>
7 
8 #include <InterViews/event.h>
9 #include <InterViews/hit.h>
10 #include <InterViews/canvas.h>
11 #include <InterViews/printer.h>
12 #include <InterViews/session.h>
13 
14 #include <InterViews/monoglyph.h>
15 #include <InterViews/tformsetter.h>
16 #include <InterViews/layout.h>
17 #include <InterViews/style.h>
18 #include <IV-look/kit.h>
19 #include <InterViews/background.h>
20 
21 #include "mymath.h"
22 #include "apwindow.h"
23 #include "ocglyph.h"
24 #include "scenevie.h"
25 #include "scenepic.h"
26 #include "rubband.h"
27 #include "idraw.h"
28 
29 // XYView
30 /*static*/ class XYView_helper : public MonoGlyph {
31 public:
32  XYView_helper(Scene*, XYView*);
33  virtual ~XYView_helper();
34  virtual void request(Requisition&) const;
35  virtual void allocate(Canvas*, const Allocation&, Extension&);
36  virtual void draw(Canvas*, const Allocation&) const;
37  virtual void print(Printer*, const Allocation&) const;
38  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
39 public:
40  Transformer t_;
41 private:
42  XYView* v_;
45  friend void XYView::current_pick_view(XYView*);
46  static XYView* current_pick_view_;
47  static XYView* current_draw_view_;
48 };
49 
51  XYView_helper::current_pick_view_ = v;
52 }
53 
54 void print_t(const char* s, const Transformer& t){
55 float a00, a01, a10, a11, a20, a21;
56 t.matrix(a00, a01, a10, a11, a20, a21);
57 printf("%s transform %g %g %g %g %g %g\n", s, a00, a01, a10, a11, a20, a21);
58 }
59 XYView_helper::XYView_helper(Scene* s, XYView* v) : MonoGlyph(s) {
60  v_ = v;
61 }
62 void XYView_helper::request(Requisition& req) const {
63  Requirement rx(v_->width(), 0, 0, -v_->left()/v_->width());
64  Requirement ry(v_->height(), 0, 0, -v_->bottom()/v_->height());
65  req.require_x(rx);
66  req.require_y(ry);
67 }
68 
69 void XYView_helper::allocate(Canvas* c, const Allocation& a, Extension& ext) {
70  t_ = c->transformer();
71 //print_t("XYView_helper::allocate", t_);
72  body()->allocate(c, a, ext);
73 }
74 
75 void XYView_helper::draw(Canvas* c, const Allocation& a) const {
76  current_draw_view_ = v_;
77  ((XYView_helper*)this)->t_ = c->transformer();
78 //print_t("XYView_helper::draw", c->transformer());
79  v_->set_damage_area(c);
80 #if 0
81  IfIdraw(pict(t_));
82 #else
84  Transformer tr(t_);
85  tr.translate(3*72, 4*72);
86  OcIdraw::pict(tr);
87  }
88 #endif
89  c->push_clipping();
90  c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
91  body()->draw(c, a);
92  c->pop_clipping();
93  IfIdraw(end());
94 }
95 
96 void XYView_helper::print(Printer* c, const Allocation&) const {
97  current_draw_view_ = v_;
98  c->push_clipping();
99  c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
100 
101  char buf[100];
102  float x, b;
103  v_->s2o().matrix(x, b, b, b, b, b);
104  sprintf(buf, "\n%g setlinewidth", x);
105  c->comment(buf);
106 
107  // when printfile started printing at the level of the xyview
108  // the allocation was incorrect and was used by the background
109  // that was ok when the background was white...
110  // set the allocation the same as the clipping
111  Allocation a1;
112  Allotment ax(v_->left(), v_->width(), 0);
113  Allotment ay(v_->bottom(), v_->height(), 0);
114  a1.allot_x(ax);
115  a1.allot_y(ay);
116 
117  body()->print(c, a1);
118  c->pop_clipping();
119 }
120 
121 void XYView_helper::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
122  if (MyMath::inside(h.left(), h.bottom(), v_->left(), v_->bottom(),
123  v_->right(), v_->top())) {
124  if (h.event()->grabber()) { // fixes a bug but I dont know why
125 #if 1
126 //The above fix broke the handling of keystrokes for crosshairs and Rotate3D
127 //It was needed so that buttons would appear normal when moving quickly from
128 // a button through a box to a scene. Now we put in the right handler in
129 //case event was a keystroke.
130  if (h.event()->type() == Event::key) {
131  h.target(depth, this, 0, h.event()->grabber());
132  }
133 #endif
134  return;
135  }
136  current_pick_view_ = v_;
137  MonoGlyph::pick(c, a, depth, h);
138  if (h.event()->type() == Event::down) {
139 #if 0
140 printf("XYView_helper hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
141 h.event()->pointer_x(), h.event()->pointer_y());
142 printf(" allocation lb=(%g, %g), rt=(%g,%g)\n", a.left(), a.bottom(), a.right(), a.top());
143 #endif
144  }
145  }
146 }
147 
148 static Coord pick_epsilon;
149 static void set_pick_epsilon() {
150  pick_epsilon = 2;
151 }
152 
153 
154 XYView::XYView(Scene* s, Coord xsize, Coord ysize)
155  : TransformSetter(new XYView_helper(s, this)) {
156  init(s->x1(), s->y1(), s->x2() - s->x1(), s->y2() - s->y1(), s,
157  xsize, ysize);
158 }
159 
160 XYView::XYView(Coord x1, Coord y1, Coord xs, Coord ys, Scene* s, Coord xsize, Coord ysize)
161  : TransformSetter(new XYView_helper(s, this))
162 {
163  init(x1, y1, xs, ys, s, xsize, ysize);
164 }
165 
166 void XYView::init(Coord x1, Coord y1, Coord xs, Coord ys, Scene* s, Coord xsize, Coord ysize) {
167  set_pick_epsilon();
168  xsize_orig_ = xsize;
169  ysize_orig_ = ysize;
170  csize(0., xsize, 0., ysize);
171  origin(x1, y1);
172  x_span(xs);
173  y_span(ys);
174  canvas(NULL);
175  parent_ = NULL; //not reffed
176  append_view(s);
177 #if 0
178  if (view_margin_ == fil) {
179  Style* style = Session::instance()->style();
180  if (!style->find_attribute("view_margin", view_margin_)) {
181  view_margin_ = 0;
182  }
183  view_margin_ *= 72;
184  }
185 #endif
186 }
187 
189 
190 XYView_helper::~XYView_helper() {
191  if (v_ == current_pick_view_) {
192  current_pick_view_ = NULL;
193  }
194  if (v_ == current_draw_view_) {
195  current_draw_view_ = NULL;
196  }
197 }
198 
199 XYView::~XYView() {
200 // printf("~XYView\n");
201  scene()->remove_view(this);
202 }
203 
204 // should only be accessed by a method that traces its call from the pick
206 // printf("current pick view %p\n", XYView_helper::current_pick_view_);
207  return XYView_helper::current_pick_view_;
208 }
209 
210 XYView* XYView_helper::current_pick_view_;
211 
212 // should only be accessed by a method that traces its call from the draw
213 // or print
215 // printf("current draw view %p\n", XYView_helper::current_draw_view_);
216  return XYView_helper::current_draw_view_;
217 }
218 
219 XYView* XYView_helper::current_draw_view_;
220 
221 void XYView::append_view(Scene* s) {
222  s->append_view(this);
223 }
224 
225 void XYView::canvas(Canvas* c) {
226  canvas_ = c;
227 }
228 
229 void XYView::stroke(Canvas* c, const Color* color, const Brush* brush) {
230  if (scene()->drawing_fixed_item()) {
231  c->stroke(color, brush);
232  }else{
233  c->push_transform();
234  c->transform(s2o());
235  c->stroke(color, brush);
236  c->pop_transform();
237  }
238 }
239 
241  return canvas_;
242 }
243 
244 void XYView::undraw() {
245  canvas_ = NULL;
246  TransformSetter::undraw();
247 }
248 
249 void XYView::damage(Glyph* g, const Allocation& a, bool fixed, bool vf) {
250  if (canvas_) {
251  Extension e;
252  canvas_->push_transform();
253  canvas_->transformer(((XYView_helper*)body())->t_);
254  if (fixed) {
255  Coord x, y;
256  canvas_->transform(s2o());
257  if (vf) {
258  view_ratio(a.x(), a.y(), x, y);
259  }else{
260  s2o().inverse_transform(a.x(), a.y(), x, y);
261  }
262  Allocation a_fix = a;
263  a_fix.x_allotment().origin(x);
264  a_fix.y_allotment().origin(y);
265  g->allocate(canvas_, a_fix, e);
266  }else{
267  g->allocate(canvas_, a, e);
268  }
269 //printf("damage extension %g %g %g %g\n", e.left(), e.bottom(), e.right(), e.top());
270 //print_t("XYView::damage", canvas_->transformer());
271  canvas_->pop_transform();
272  canvas_->damage(e);
273  }
274 }
275 
276 void XYView::damage_all() {
277  if (canvas_) {
278  canvas_->damage(xc0_, yc0_, xc0_ + xsize_, yc0_ + ysize_);
279  }
280 }
281 
282 void XYView::damage(Coord x1, Coord y1, Coord x2, Coord y2) {
283  if (canvas_) {
284  Transformer& t = ((XYView_helper*)body())->t_;
285  Coord tx1, ty1, tx2, ty2;
286  t.transform(x1, y1, tx1, ty1);
287  t.transform(x2, y2, tx2, ty2);
288  const float off = canvas_->to_coord(1);
289  tx1 = Math::max(tx1-off, Coord(0));
290  ty1 = Math::max(ty1-off, Coord(0));
291  tx2 = Math::min(tx2+off, canvas_->width());
292  ty2 = Math::min(ty2+off, canvas_->height());
293  canvas_->damage(tx1, ty1, tx2, ty2);
294  }
295 }
296 
298  Extension e;
299  c->restrict_damage(0.,0., c->width(), c->height());
300  c->damage_area(e);
301  const float off = c->to_coord(1);
302  c->transformer().inverse_transform(e.left()-off, e.bottom()-off, xd1_, yd1_);
303  c->transformer().inverse_transform(e.right()+off, e.top()+off, xd2_, yd2_);
304 }
305 
306 void XYView::damage_area(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
307  x1 = xd1_;
308  y1 = yd1_;
309  x2 = xd2_;
310  y2 = yd2_;
311 }
312 
313 void XYView::request(Requisition& req) const {
314  TransformSetter::request(req);
315  Requirement rx(xsize_orig_);
316  Requirement ry(ysize_orig_);
317  req.require_x(rx);
318  req.require_y(ry);
319 }
320 
321 void XYView::allocate(Canvas* c, const Allocation& a, Extension& ext) {
322 #if defined(WIN32) || defined(CYGWIN)
323  if (a.y_allotment().span() <= 0. || a.x_allotment().span() <= 0.) {
324  // a bug in mswindows iconify
325  return;
326  }
327 #endif
328  if (canvas_ == NULL) {
329  canvas_ = c;
330  }
331  c->push_transform();
332  TransformSetter::allocate(c, a, ext);
333  c->pop_transform();
334 }
335 
336 void XYView::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
337  canvas_ = c;
338  c->push_transform();
339  if (h.event()->type() == Event::down) {
340 #if 0
341 printf("XYView hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
342 h.event()->pointer_x(), h.event()->pointer_y());
343 #endif
344  }
345  TransformSetter::pick(c, a, depth, h);
346  c->pop_transform();
347 }
348 
349 Scene* XYView::scene() const { return (Scene*)(((XYView_helper*)body())->body()); }
350 
351 Coord XYView::left() const { return x1_; }
352 Coord XYView::right() const { return x1_ + x_span_; }
353 Coord XYView::bottom() const { return y1_; }
354 Coord XYView::top() const { return y1_ + y_span_; }
355 Coord XYView::width() const { return x_span_; }
356 Coord XYView::height() const { return y_span_; }
357 
358 void XYView::view_ratio(float xrat, float yrat, Coord& x, Coord& y) const {
359  x = xrat*xsize_ + xc0_;
360  y = yrat*ysize_ + yc0_;
361 }
362 
363 void XYView::ratio_view(Coord x, Coord y, float& xrat, float& yrat) const {
364  xrat = (x - xc0_)/xsize_;
365  yrat = (y - yc0_)/ysize_;
366 }
367 
368 void XYView::size(Coord x1, Coord y1, Coord x2, Coord y2) {
369  x1_ = Math::min(x1, x2);
370  y1_ = Math::min(y1, y2);
371  x_span_ = Math::abs(x2 - x1);
372  y_span_ = Math::abs(y2 - y1);
373  notify();
374 }
375 
376 void XYView::origin(Coord x1, Coord y1) {
377  x1_ = x1;
378  y1_ = y1;
379  notify();
380 }
381 
382 void XYView::csize(Coord x0, Coord x, Coord y0, Coord y) const {
383  XYView* v = (XYView*)this;
384  v->xsize_ = x;
385  v->ysize_ = y;
386  v->xc0_ = x0;
387  v->yc0_ = y0;
388 }
389 
390 void XYView::box_size(Coord x1, Coord y1, Coord x2, Coord y2) {
391  size(x1, y1, x2, y2);
392 }
393 
394 void XYView::x_span(Coord x) { x_span_ = (x > 0) ? x : 1.; notify();}
395 void XYView::y_span(Coord x) { y_span_ = (x > 0) ? x : 1.; notify();}
396 
397 
398 void XYView::zout(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
399  Coord dx, dy;
400  x1 = left(); x2 = right();
401  y1 = bottom(); y2 = top();
402  dx = .1*(x2 - x1);
403  dy = .1*(y2 - y1);
404  x1 -= dx; x2 += dx; y1 -= dy; y2 += dy;
405 }
406 void XYView::zin(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
407  Coord dx, dy;
408  x1 = left(); x2 = right();
409  y1 = bottom(); y2 = top();
410  dx = .1/1.2*(x2 - x1);
411  dy = .1/1.2*(y2 - y1);
412  x1 += dx; x2 -= dx; y1 += dy; y2 -= dy;
413 }
414 
415 void XYView::save(ostream& o) {
416  PrintableWindow* w;
417  if (!canvas_) {
418  if (!parent() || !parent()->has_window()) {
419  return;
420  }
421  w = parent()->window();
422  }else{
423  w = (PrintableWindow*)canvas()->window();
424  }
425  char buf[256];
426  Coord x1, y1, x2, y2;
427  zin(x1, y1, x2, y2);
428  sprintf(buf, "{save_window_.view(%g, %g, %g, %g, %g, %g, %g, %g)}",
429  x1, y1, x2 - x1, y2 - y1,
430  w->save_left(), w->save_bottom(), xsize_, ysize_
431  );
432  o << buf << endl;
433 }
434 
435 void XYView::scene2view(const Allocation& a) const{
436  float m00 = width()/a.x_allotment().span();
437  float m11 = height()/a.y_allotment().span();
438 
439  //takes a canvas transformation from scene to parent glyph coordinates
440  // transforms vectors from original to xyview
441  XYView* xyv = (XYView*)this;
443  m00, 0,
444  0, m11,
445  left() - a.left()*m00,
446  bottom() - a.bottom()*m11
447  );
448 //print_t("scene2view", scene2viewparent_);
449 }
450 
451 void XYView::transform(
452  Transformer& t, const Allocation& a, const Allocation& n
453 ) const {
454 #if 0
455  Allotment ax, ay;
456  if (view_margin()) {
457  const Allotment& alx = a.x_allotment();
458  ax.span(alx.span() - 2*view_margin());
459  ax.origin(alx.begin() + view_margin());
460  ax.alignment(0);
461  const Allotment& aly = a.y_allotment();
462  ay.span(aly.span() - 2*view_margin());
463  ay.origin(aly.begin() + view_margin());
464  ay.alignment(0);
465  }else{
466  ax = a.x_allotment();
467  ay = a.y_allotment();
468  }
469  Allocation al;
470  al.allot_x(ax);
471  al.allot_y(ay);
472  scene2view(al);
473 #else
474  scene2view(a);
475  const Allotment& ax = a.x_allotment();
476  const Allotment& ay = a.y_allotment();
477 #endif
478  const Allotment& nx = n.x_allotment();
479  const Allotment& ny = n.y_allotment();
480  XYView* v = (XYView*)this;
481  csize(ax.begin(), ax.span(), ay.begin(), ay.span());
482  float sx = xsize_/width();
483  float sy = ysize_/height();
484  XYView* xv = (XYView*)this;
485  xv->x_pick_epsilon_ = pick_epsilon/sx;
486  xv->y_pick_epsilon_ = pick_epsilon/sy;
487  t.translate( -left(), -bottom());
488  t.scale(sx, sy);
489  t.translate(ax.begin(), ay.begin());
490 #if 0
491 printf("XYView::transform ax origin=%g span=%g alignment=%g begin=%g\n",
492 ax.origin(), ax.span(), ax.alignment(), ax.begin());
493 printf("XYView::transform ay origin=%g span=%g alignment=%g begin=%g %g\n",
494 ay.origin(), ay.span(), ay.alignment(), ay.begin(), ay.end());
495 printf("XYView::transform natx origin=%g span=%g alignment=%g begin=%g\n",
496 nx.origin(), nx.span(), nx.alignment(), nx.begin());
497 printf("XYView::transform naty origin=%g span=%g alignment=%g begin=%g %g\n",
498 ny.origin(), ny.span(), ny.alignment(), ny.begin(), ny.end());
499 #endif
500 }
501 
502 //View
503 View::View(Scene* s) : XYView(s, s->x2() - s->x1(), s->y2() - s->y1()) {
504  x_span_ = XYView::width();
505  y_span_ = XYView::height();
506 }
507 View::View(Coord x, Coord y, Coord span, Scene* s, Coord xsize, Coord ysize)
508  : XYView(x - span/2., y - (ysize/xsize)*span/2., span, span, s, xsize, ysize)
509 {
510  x_span_ = XYView::width();
511  y_span_ = XYView::height();
512 }
513 View::View(Coord x1, Coord y1, Coord xs, Coord ys, Scene* s, Coord xsize, Coord ysize)
514  : XYView(x1, y1, xs, ys, s, xsize, ysize) {
515  x_span_ = XYView::width();
516  y_span_ = XYView::height();
517 }
518 View::~View(){}
519 
520 void View::origin(Coord x, Coord y) {
521  XYView::origin(x - XYView::width()/2., y - XYView::height()/2.);
522 }
523 
524 void View::box_size(Coord x1, Coord y1, Coord x2, Coord y2) {
525  Coord w = x2 - x1;
526  Coord h = y2 - y1;
527  Coord magx = w/x_span_;
528  Coord magy = h/y_span_;
529  if (magx > magy) {
530  x_span_ *= magx;
531  y_span_ *= magx;
532  }else{
533  x_span_ *= magy;
534  y_span_ *= magy;
535  }
536  x_span(x_span_);
537  y_span(y_span_);
538  origin((x1+x2)/2, (y1+y2)/2);
539 }
540 
541 Coord View::x() const {return left() + XYView::width()/2.;}
542 Coord View::y() const {return bottom() + XYView::height()/2.;}
543 Coord View::view_width()const {return x_span_;}
544 Coord View::view_height()const {return y_span_;}
545 
546 void View::transform(
547  Transformer& t, const Allocation& a, const Allocation&
548 ) const {
549  scene2view(a);
550  const Allotment& ax = a.x_allotment();
551  const Allotment& ay = a.y_allotment();
552  csize(ax.begin(), ax.span(), ay.begin(), ay.span());
553  float sx = ax.span()/XYView::width();
554  float sy = ay.span()/XYView::height();
555 // if (sx > sy) sx = sy;
556  t.translate( -x(), -y());
557  t.scale(sx, sx);
558  View* v = (View*)this;
559  v->x_pick_epsilon_ = pick_epsilon/sx;
560  v->y_pick_epsilon_ = pick_epsilon/sx;
561  t.translate((ax.begin() + ax.end())/2,(ay.begin() + ay.end())/2);
562 //printf("\nx origin=%g span=%g alignment=%g begin=%g end=%g\n", ax.origin(), ax.span(), ax.alignment(), ax.begin(), ax.end());
563 //printf("\ny origin=%g span=%g alignment=%g begin=%g end=%g\n", ay.origin(), ay.span(), ay.alignment(), ay.begin(), ay.end());
564  Coord x1,y1;
565  t.transform(x() - x_span_/2, y() - y_span_/2, x1, y1);
566  if (!Math::equal(ax.begin(), x1, 1) || !Math::equal(ay.begin(), y1, 1)) {
567  t.inverse_transform(ax.begin(), ay.begin(), x1, y1);
568  v->x_span_ = 2*(x() - x1);
569  v->y_span_ = 2*(y() - y1);
570  v->size(x1,y1,x1+v->x_span_, y1+v->y_span_);
571  }
572 
573 }
574 
575 void XYView::move_view(Coord dx1, Coord dy1) {
576 // printf("move by %g %g \n", dx1, dy1);
577  Coord x0, x1, y0, y1;
578  Coord dx = Math::abs(dx1);
579  Coord dy = Math::abs(dy1);
580  if (dx < .9*dy) {
581  dx = 0.;
582  dy = dy1;
583  }else if (dy < .9*dx) {
584  dx = dx1;
585  dy = 0.;
586  }else{
587  dx = dx1;
588  dy = dy1;
589  }
590  s2o().transform(0, 0, x0, y0);
591  s2o().transform(dx, dy, x1, y1);
592  x0 = x0 - x1 + left();
593  y0 = y0 - y1 + bottom();
594  x1 = x0 + width();
595  y1 = y0 + height();
596 
597 #if 1
598  if (dx > 0) {
599  MyMath::round(x0, x1, MyMath::Higher, 4);
600  }else{
601  MyMath::round(x0, x1, MyMath::Lower, 4);
602  }
603  if (dy > 0) {
604  MyMath::round(y0, y1, MyMath::Higher, 4);
605  }else{
606  MyMath::round(y0, y1, MyMath::Lower, 4);
607  }
608 #endif
609 
610  XYView::origin(x0, y0);
611  damage_all();
612 }
613 
614 void View::move_view(Coord dx, Coord dy) {
615  XYView::move_view(dx, dy);
616 }
617 
618 
619 void XYView::scale_view(Coord xorg, Coord yorg, float dxscl, float dyscl) {
620  Coord x0, y0, l, b, r, t;
621  Coord dx = Math::abs(dxscl);
622  Coord dy = Math::abs(dyscl);
623  if (dx < .9*dy) {
624  dx = 0.;
625  dy = dyscl;
626  }else if (dy < .9*dx) {
627  dx = dxscl;
628  dy = 0.;
629  }else{
630  dx = dxscl;
631  dy = dyscl;
632  }
633  s2o().transform(xorg, yorg, x0, y0);
634 //printf("org %g %g %g %g\n", xorg, yorg, x0, y0);
635  l = -(left()-x0)*dx + left();
636  b = -(bottom()-y0)*dy + bottom();
637  r = -(right()-x0)*dx + right();
638  t = -(top()-y0)*dy + top();
639 #if 1
640  if (dxscl > 1) {
641  MyMath::round(l, r, MyMath::Expand, 4);
642  }else{
644  }
645  if (dyscl > 1) {
646  MyMath::round(b, t, MyMath::Expand, 4);
647  }else{
649  }
650 #endif
651  size(l, b, r, t);
652  damage_all();
653 }
654 
655 void View::scale_view(Coord xorg, Coord yorg, float dxscl, float) {
656  XYView::scale_view(xorg, yorg, dxscl, dxscl);
657 }
658 
659 XYView* XYView::new_view(Coord x1, Coord y1, Coord x2, Coord y2) {
660  Coord l,b,r,t;
661  s2o().inverse_transform(x1,y1,l,b);
662  s2o().inverse_transform(x2,y2,r,t);
663  return new XYView( x1, y1, x2-x1, y2-y1, scene(), r-l, t-b);
664 }
665 
666 XYView* View::new_view(Coord x1, Coord y1, Coord x2, Coord y2) {
667  Coord l,b,r,t;
668  s2o().inverse_transform(x1,y1,l,b);
669  s2o().inverse_transform(x2,y2,r,t);
670  return new View( (x1+x2)/2, (y1+y2)/2, x2-x1, scene(), r-l, t-b);
671 }
672 
673 /*static*/ class NPInsetFrame : public MonoGlyph {
674 public:
675  NPInsetFrame(Glyph*);
676  virtual ~NPInsetFrame();
677  virtual void print(Printer*, const Allocation&) const;
678 };
679 
680 NPInsetFrame::NPInsetFrame(Glyph* g)
681  : MonoGlyph(WidgetKit::instance()->inset_frame(g)) {}
682 NPInsetFrame::~NPInsetFrame(){}
683 void NPInsetFrame::print(Printer* p, const Allocation& a) const {
684  Style* s = WidgetKit::instance()->style();
685  long i=1;
686  s->find_attribute("scene_print_border", i);
687 //printf("NPInsetFrame %ld\n", i);
688  if (i) {
689  body()->print(p, a);
690  }else{
691  ((MonoGlyph*)body())->body()->print(p, a);
692  }
693 }
694 
696 new Background (
697 // WidgetKit::instance()->inset_frame(
698  new NPInsetFrame(
699  LayoutKit::instance()->variable_span(
700  v
701  )
702  ),
703  WidgetKit::instance()->background()
704 )
705 )
706 {
707  v_ = v;
708  g_ = NULL;
709  v_->ref();
710  assert(v_->parent() == NULL);
711  v_->parent_ = this;
712 };
713 
715  v_->parent_ = NULL;
716  v_->unref();
717  Resource::unref(g_);
718 }
719 
720 void OcViewGlyph::save(ostream& o) {
721  Scene* s = v_->scene();
722  char buf[256];
723  long i = Scene::scene_list_index(s);
724  if (!s->mark()) {
725  s->save_phase1(o);
726  sprintf(buf, "scene_vector_[%ld] = save_window_", i);
727  }else{
728  sprintf(buf, "save_window_ = scene_vector_[%ld]", i);
729  }
730  o << buf << endl;
731  v_->save(o);
732  if (!s->mark()) {
733  s->save_phase2(o);
734  s->mark(true);
735  }
736 }
737 
738 ViewWindow::ViewWindow(XYView* v, const char* name)
739  : PrintableWindow(new OcViewGlyph(v)) {
740  if (name) {
741  type(name);
742  }
743  v->attach(this);
744  update(v);
745 }
746 
748  OcViewGlyph* g = (OcViewGlyph*)glyph();
749  g->view()->detach(this);
750 }
751 
753  char s[200];
754  XYView* v = (XYView*)o;
755  sprintf(s, "%s %s x %g : %g y %g : %g", type(),
756  v->scene()->picker()->select_name(),
757  v->left(), v->right(),
758  v->bottom(), v->top());
759  name(s);
760 }
761 #endif
o
Definition: seclist.cpp:180
Transformer scene2viewparent_
Definition: scenevie.h:174
void allot_x(const Allotment &)
Definition: geometry.h:282
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual void damage_all()
virtual ~OcViewGlyph()
static ostream * idraw_stream
Definition: idraw.h:47
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
void scene2view(const Allocation &parent) const
double max(double a, double b)
Definition: geometry3d.cpp:22
#define assert(ex)
Definition: hocassrt.h:26
virtual Coord bottom() const
short type
Definition: cabvars.h:10
Coord x() const
Definition: geometry.h:290
virtual void save_phase2(std::ostream &)
#define WidgetKit
Definition: _defines.h:331
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual void move_view(Coord dx, Coord dy)
Coord y_span_
Definition: scenevie.h:207
#define min(a, b)
Definition: matrix.h:157
#define g
Definition: passive0.cpp:23
Coord xsize_
Definition: scenevie.h:175
#define TransformSetter
Definition: _defines.h:315
#define Glyph
Definition: _defines.h:132
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
static bool equal(float x, float y, float e)
Definition: math.h:108
size_t p
#define Color
Definition: _defines.h:74
virtual const char * select_name()
virtual Coord x2() const
Definition: scenevie.h:318
Coord x_pick_epsilon_
Definition: scenevie.h:170
virtual ~View()
virtual Coord top() const
virtual void stroke(Canvas *, const Color *, const Brush *)
#define IfIdraw(arg)
Definition: idraw.h:61
#define print
Definition: redef.h:109
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
#define v
Definition: md1redef.h:4
virtual void request(Requisition &) const
Coord y() const
Definition: geometry.h:291
static int abs(int)
Definition: math.cpp:43
Coord begin() const
Definition: geometry.h:274
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static bool inside(Coord x, Coord min, Coord max)
Definition: mymath.h:97
void size(Coord x1, Coord y1, Coord x2, Coord y2)
static double round(float &x1, float &x2, int direction, int digits)
Definition: mymath.cpp:335
#define e
Definition: passive0.cpp:24
void origin(Coord)
Definition: geometry.h:266
XYView * view()
Definition: scenevie.h:95
void init()
Definition: init.cpp:169
Coord xc0_
Definition: scenevie.h:175
Coord bottom() const
Definition: geometry.h:298
bool mark()
Definition: scenevie.h:265
void allot_y(const Allotment &)
Definition: geometry.h:283
int const size_t const size_t n
Definition: nrngsl.h:12
#define color
Definition: rbtqueue.cpp:50
#define Printer
Definition: _defines.h:211
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
_CONST char * s
Definition: system.cpp:74
virtual Coord x1() const
Definition: scenevie.h:317
Coord top() const
Definition: geometry.h:295
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
virtual void undraw()
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
virtual Coord left() const
#define xorg
Definition: axis.cpp:156
static Coord view_margin_
Definition: scenevie.h:179
#define printf
Definition: mwprefix.h:26
XYView(Scene *, Coord xsize=200, Coord ysize=200)
Coord left() const
Definition: geometry.h:297
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
void x_span(Coord)
Coord left() const
Definition: geometry.h:292
#define LayoutKit
Definition: _defines.h:161
virtual void attach(Observer *)
Definition: observe.cpp:54
static XYView * current_draw_view()
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
#define Canvas
Definition: _defines.h:65
void require_y(const Requirement &)
Definition: geometry.h:248
#define key
Definition: spt2queue.cpp:20
View(Scene *)
virtual void save_phase1(std::ostream &)
virtual Coord view_width() const
virtual void unref() const
Definition: resource.cpp:52
virtual void zout(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
OcViewGlyph(XYView *)
char * name
Definition: init.cpp:16
inode< _nt-> end
Definition: multicore.cpp:985
virtual void move_view(Coord dx, Coord dy)
virtual ~XYView()
#define parent
Definition: rbtqueue.cpp:47
void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene *, Coord xsize, Coord ysize)
void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const
Coord ysize_
Definition: scenevie.h:175
ViewWindow(XYView *, const char *name)
Coord bottom() const
Definition: geometry.h:294
#define left
Definition: rbtqueue.cpp:45
Coord right() const
Definition: geometry.h:299
virtual void save(std::ostream &)
virtual Coord save_bottom() const
#define fil
Definition: coord.h:42
void y_span(Coord)
#define right
Definition: rbtqueue.cpp:46
virtual void update(Observable *)
virtual Coord y2() const
Definition: scenevie.h:320
void append_view(XYView *)
void require_x(const Requirement &)
Definition: geometry.h:247
Coord end() const
Definition: geometry.h:278
Coord x_span_
Definition: scenevie.h:207
Canvas * canvas()
virtual Scene * scene() const
Coord y_pick_epsilon_
Definition: scenevie.h:170
virtual void set_damage_area(Canvas *)
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
#define Transformer
Definition: _defines.h:316
static void pict()
void span(Coord)
Definition: geometry.h:269
Coord right() const
Definition: geometry.h:293
Coord top() const
Definition: geometry.h:300
virtual Coord width() const
Definition: scenevie.h:185
void origin(Coord x, Coord y)
#define i
Definition: md1redef.h:12
#define yorg
Definition: axis.cpp:157
virtual void print(Printer *, const Allocation &) const
virtual ~ViewWindow()
void origin(Coord x1, Coord y1)
#define c
virtual Coord y() const
virtual void detach(Observer *)
Definition: observe.cpp:63
Allotment & x_allotment()
Definition: geometry.h:285
virtual void ratio_view(Coord x, Coord y, float &xratio, float &yratio) const
char buf[512]
Definition: init.cpp:13
#define Style
Definition: _defines.h:281
virtual void damage_area(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void allocate(Canvas *, const Allocation &, Extension &)
void alignment(float)
Definition: geometry.h:271
virtual Coord view_height() const
virtual Coord save_left() const
virtual Coord y1() const
Definition: scenevie.h:319
Allotment & y_allotment()
Definition: geometry.h:286
#define MonoGlyph
Definition: _defines.h:181
#define Background
Definition: _defines.h:43
double t
Definition: init.cpp:123
static XYView * current_pick_view()
void append_view(Scene *)
virtual Coord height() const
ScenePicker * picker()
Coord yc0_
Definition: scenevie.h:175
virtual void save(std::ostream &)
virtual Coord right() const
virtual void zin(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static long scene_list_index(Scene *)
return NULL
Definition: cabcode.cpp:461
virtual Coord x() const
#define Hit
Definition: _defines.h:147
virtual void update(Observable *)
Definition: observe.cpp:86