1 #include <../../nrnconf.h>
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>
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>
33 virtual ~XYView_helper();
48 static XYView* current_pick_view_;
49 static XYView* current_draw_view_;
53 XYView_helper::current_pick_view_ =
v;
57 float a00, a01, a10, a11, a20, a21;
58 t.matrix(a00, a01, a10, a11, a20, a21);
59 printf(
"%s transform %g %g %g %g %g %g\n", s, a00, a01, a10, a11, a20, a21);
65 void XYView_helper::request(
Requisition& req)
const {
66 Requirement rx(v_->width(), 0, 0, -v_->left() / v_->width());
67 Requirement ry(v_->height(), 0, 0, -v_->bottom() / v_->height());
73 t_ =
c->transformer();
75 body()->allocate(
c, a, ext);
79 current_draw_view_ = v_;
80 ((XYView_helper*)
this)->t_ =
c->transformer();
82 v_->set_damage_area(
c);
88 tr.translate(3 * 72, 4 * 72);
93 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
100 current_draw_view_ = v_;
102 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
106 v_->s2o().matrix(x, b, b, b, b, b);
115 Allotment ax(v_->left(), v_->width(), 0);
116 Allotment ay(v_->bottom(), v_->height(), 0);
120 body()->print(
c, a1);
125 if (
MyMath::inside(h.left(), h.bottom(), v_->left(), v_->bottom(), v_->right(), v_->top())) {
126 if (h.event()->grabber()) {
133 h.target(depth,
this, 0, h.event()->grabber());
138 current_pick_view_ = v_;
139 MonoGlyph::pick(
c, a, depth, h);
140 if (h.event()->type() == Event::down) {
142 printf(
"XYView_helper hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
143 h.event()->pointer_x(), h.event()->pointer_y());
150 static Coord pick_epsilon;
151 static void set_pick_epsilon() {
158 init(s->
x1(), s->
y1(), s->
x2() - s->
x1(), s->
y2() - s->
y1(), s, xsize, ysize);
163 init(x1, y1, xs, ys, s, xsize, ysize);
170 csize(0., xsize, 0., ysize);
179 Style* style = Session::instance()->style();
180 if (!style->find_attribute(
"view_margin",
view_margin_)) {
190 XYView_helper::~XYView_helper() {
191 if (v_ == current_pick_view_) {
192 current_pick_view_ =
NULL;
194 if (v_ == current_draw_view_) {
195 current_draw_view_ =
NULL;
207 return XYView_helper::current_pick_view_;
210 XYView* XYView_helper::current_pick_view_;
216 return XYView_helper::current_draw_view_;
219 XYView* XYView_helper::current_draw_view_;
230 if (
scene()->drawing_fixed_item()) {
246 TransformSetter::undraw();
253 canvas_->transformer(((XYView_helper*) body())->t_);
260 s2o().inverse_transform(a.
x(), a.
y(), x, y);
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);
293 canvas_->damage(tx1, ty1, tx2, ty2);
299 c->restrict_damage(0., 0.,
c->width(),
c->height());
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_);
314 TransformSetter::request(req);
332 TransformSetter::allocate(
c, a, ext);
339 if (h.event()->type() == Event::down) {
341 printf(
"XYView hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
342 h.event()->pointer_x(), h.event()->pointer_y());
345 TransformSetter::pick(
c, a, depth, h);
350 return (
Scene*) (((XYView_helper*) body())->body());
405 size(x1, y1, x2, y2);
437 dx = .1 / 1.2 * (x2 - x1);
438 dy = .1 / 1.2 * (y2 - y1);
456 Coord x1, y1, x2, y2;
459 "{save_window_.view(%g, %g, %g, %g, %g, %g, %g, %g)}",
521 printf(
"XYView::transform ax origin=%g span=%g alignment=%g begin=%g\n",
523 printf(
"XYView::transform ay origin=%g span=%g alignment=%g begin=%g %g\n",
525 printf(
"XYView::transform natx origin=%g span=%g alignment=%g begin=%g\n",
527 printf(
"XYView::transform naty origin=%g span=%g alignment=%g begin=%g %g\n",
534 :
XYView(s, s->x2() - s->x1(), s->y2() - s->y1()) {
539 :
XYView(x - span / 2., y - (ysize / xsize) * span / 2., span, span, s, xsize, ysize) {
544 :
XYView(x1, y1, xs, ys, s, xsize, ysize) {
568 origin((x1 + x2) / 2, (y1 + y2) / 2);
592 t.translate(-
x(), -
y());
595 v->x_pick_epsilon_ = pick_epsilon / sx;
596 v->y_pick_epsilon_ = pick_epsilon / sx;
604 t.inverse_transform(ax.
begin(), ay.
begin(), x1, y1);
605 v->x_span_ = 2 * (
x() - x1);
606 v->y_span_ = 2 * (
y() - y1);
607 v->size(x1, y1, x1 +
v->x_span_, y1 +
v->y_span_);
613 Coord x0, x1, y0, y1;
619 }
else if (dy < .9 * dx) {
626 s2o().transform(0, 0, x0, y0);
627 s2o().transform(dx, dy, x1, y1);
628 x0 = x0 - x1 +
left();
662 }
else if (dy < .9 * dx) {
674 t = -(
top() - y0) * dy +
top();
697 s2o().inverse_transform(x1, y1, l, b);
698 s2o().inverse_transform(x2, y2, r,
t);
699 return new XYView(x1, y1, x2 - x1, y2 - y1,
scene(), r - l,
t - b);
704 s2o().inverse_transform(x1, y1, l, b);
705 s2o().inverse_transform(x2, y2, r,
t);
706 return new View((x1 + x2) / 2, (y1 + y2) / 2, x2 - x1,
scene(), r - l,
t - b);
711 NPInsetFrame(
Glyph*);
712 virtual ~NPInsetFrame();
716 NPInsetFrame::NPInsetFrame(
Glyph*
g)
718 NPInsetFrame::~NPInsetFrame() {}
720 Style* s = WidgetKit::instance()->style();
722 s->find_attribute(
"scene_print_border",
i);
734 new NPInsetFrame(
LayoutKit::instance()->variable_span(
v)),
755 sprintf(
buf,
"scene_vector_[%ld] = save_window_",
i);
757 sprintf(
buf,
"save_window_ = scene_vector_[%ld]",
i);
778 g->view()->detach(
this);
785 "%s %s x %g : %g y %g : %g",
787 v->scene()->picker()->select_name(),
void allot_y(const Allotment &)
Allotment & x_allotment()
Allotment & y_allotment()
void allot_x(const Allotment &)
virtual Glyph * glyph() const
virtual const char * name() const
static bool equal(float x, float y, float e)
static bool inside(Coord x, Coord min, Coord max)
static double round(float &x1, float &x2, int direction, int digits)
virtual PrintableWindow * window()
static ostream * idraw_stream
virtual void save(std::ostream &)
virtual Coord save_left() const
virtual Coord save_bottom() const
const char * type() const
void require_x(const Requirement &)
void require_y(const Requirement &)
virtual void unref() const
static long scene_list_index(Scene *)
virtual void save_phase1(std::ostream &)
virtual void save_phase2(std::ostream &)
void remove_view(XYView *)
void append_view(XYView *)
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)
void origin(Coord x, Coord y)
virtual Coord view_height() const
virtual Coord view_width() const
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
ViewWindow(XYView *, const char *name)
virtual void update(Observable *)
virtual void damage_area(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
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)
virtual void zout(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
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 Coord width() const
void origin(Coord x1, Coord y1)
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
static Coord view_margin_
virtual Coord left() const
void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
Transformer scene2viewparent_
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
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
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
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()
virtual void stroke(Canvas *, const Color *, const Brush *)
const Transformer & s2o() const
Coord view_margin() const
void append_view(Scene *)
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
static void update(NrnThread *)
int const size_t const size_t n