1 #include <../../nrnconf.h>
39 #include <InterViews/canvas.h>
40 #include <InterViews/hit.h>
41 #include <InterViews/session.h>
42 #include <InterViews/style.h>
43 #include <InterViews/color.h>
44 #include <InterViews/brush.h>
45 #include <InterViews/background.h>
56 #define Scene_Move_Text_ "MoveText Graph"
57 #define Scene_ChangeColor_ "ChangeColor Graph"
58 #define Scene_Delete_ "Delete Graph"
60 static const int SceneInfoShowing = 0x01;
61 static const int SceneInfoFixed = 0x02;
62 static const int SceneInfoViewFixed = 0x04;
63 static const int SceneInfoAllocated = 0x08;
77 void SceneInfo::pinfo() {
82 SceneInfo::SceneInfo() {
93 status_ = SceneInfoShowing;
96 static const float epsilon = 0.001;
97 static std::vector<Scene*>* scene_list;
103 static const Brush* mb_brush_;
104 static const Color* mb_color_;
111 info.glyph_->request(
s);
122 if (
info.status_ & SceneInfoAllocated) {
123 if (!a_old.
equals(a, epsilon)) {
130 info.status_ |= SceneInfoAllocated;
138 info.glyph_->request(
s);
151 if ((
info.status_ & SceneInfoAllocated) && !a_old.
equals(a, epsilon)) {
156 info.status_ |= SceneInfoAllocated;
159 static const Color* scene_background_;
160 static const Color* scene_foreground_;
163 if (!scene_background_) {
164 Style*
s = Session::instance()->style();
166 if (!
s->find_attribute(
"Scene_background",
c) ||
167 (scene_background_ =
Color::lookup(Session::instance()->default_display(),
c)) ==
169 scene_background_ =
Color::lookup(Session::instance()->default_display(),
"#ffffff");
173 return scene_background_;
177 if (!scene_foreground_) {
178 Style*
s = Session::instance()->style();
180 if (!
s->find_attribute(
"Scene_foreground",
c) ||
181 (scene_foreground_ =
Color::lookup(Session::instance()->default_display(),
c)) ==
183 scene_foreground_ =
Color::lookup(Session::instance()->default_display(),
"#000000");
187 return scene_foreground_;
192 drawing_fixed_item_ =
false;
196 info_ =
new std::vector<SceneInfo>();
197 views_ =
new std::vector<XYView*>();
207 scene_list =
new std::vector<Scene*>();
210 Session::instance()->style()->find_attribute(
"scene_menu_box_size", mbs_);
213 mb_brush_ =
new Brush(1);
221 scene_list->push_back(
this);
257 printf(
"No help for this tool\n");
301 for (
auto& item: *
info_) {
327 return int(
views_->size());
352 for (
auto& item: *
views_) {
354 item->damage(
info.glyph_,
356 (
info.status_ & SceneInfoFixed) != 0,
357 (
info.status_ & SceneInfoViewFixed) != 0);
363 for (
auto& item: *
views_) {
364 item->damage(
info.glyph_,
366 (
info.status_ & SceneInfoFixed) != 0,
367 (
info.status_ & SceneInfoViewFixed) != 0);
372 for (
auto& item: *
views_) {
373 if (item->canvas()) {
380 for (
auto& item: *
views_) {
387 if (((
info.status_ & SceneInfoShowing) == SceneInfoShowing) !=
showing) {
391 info.status_ |= SceneInfoShowing;
393 info.status_ &= ~SceneInfoShowing;
400 return (
info_->at(
index).status_ & SceneInfoShowing) != 0;
409 if (!(
info.status_ & SceneInfoAllocated) ||
x1 != x ||
y1 != y) {
421 return info_->size();
429 a =
info_->at(
index).allocation_.allotment(res);
438 if (
info.status_ & SceneInfoViewFixed) {
439 info.status_ &= ~SceneInfoViewFixed;
440 printf(
"changed to fixed\n");
444 info.status_ |= SceneInfoFixed;
450 if (!(
info.status_ & SceneInfoViewFixed)) {
451 info.status_ |= SceneInfoViewFixed;
452 info.status_ |= SceneInfoFixed;
453 printf(
"changed to vfixed\n");
454 v->s2o().inverse_transform(
info.x_,
info.y_);
461 SceneInfo
info(glyph);
467 SceneInfo
info(glyph);
468 info.status_ |= SceneInfoFixed;
475 SceneInfo
info(glyph);
476 info.status_ |= SceneInfoFixed | SceneInfoViewFixed;
482 SceneInfo
info(glyph);
489 SceneInfo
info(glyph);
513 if (
info.glyph_ == g) {
542 #include <IV-X11/xcanvas.h>
543 #include <InterViews/transformer.h>
546 printf(
"damage %g %g %g %g\n", cd.left, cd.bottom, cd.right, cd.top);
548 Coord x1, y1, x2, y2;
549 t.inverse_transform(cd.left, cd.bottom, x1, y1);
550 t.inverse_transform(cd.right, cd.top, x2, y2);
551 printf(
" model %g %g %g %g\n", x1, y1, x2, y2);
564 canvas->transformer().transform(a.
left(), a.
top(), l,
t);
565 if (canvas->damaged(l,
t -
mbs_, l +
mbs_,
t)) {
567 canvas->push_transform();
569 canvas->transformer(tr);
570 canvas->rect(l,
t -
mbs_, l +
mbs_,
t, mb_color_, mb_brush_);
571 canvas->pop_transform();
574 bool are_fixed =
false;
576 if (
info.status_ & SceneInfoFixed) {
578 }
else if (
info.glyph_ !=
NULL && (
info.status_ & SceneInfoShowing)) {
582 if (canvas->damaged(b)) {
583 info.glyph_->draw(canvas, a);
589 ((
Scene*)
this)->drawing_fixed_item_ =
true;
590 canvas->push_transform();
594 canvas->transform(tv);
597 if ((
info.status_ & SceneInfoFixed) &&
info.glyph_ !=
NULL &&
598 (
info.status_ & SceneInfoShowing)) {
601 if (!(
info.status_ & SceneInfoViewFixed)) {
602 tv.inverse_transform(a.
x(), a.
y(), x, y);
610 if (canvas->damaged(b)) {
611 info.glyph_->draw(canvas, a);
618 ((
Scene*)
this)->drawing_fixed_item_ =
false;
619 canvas->pop_transform();
628 bool are_fixed =
false;
630 if (
info.status_ & SceneInfoFixed) {
632 }
else if (
info.glyph_ !=
NULL && (
info.status_ & SceneInfoShowing)) {
636 if (canvas->damaged(b)) {
637 info.glyph_->print(canvas, a);
643 ((
Scene*)
this)->drawing_fixed_item_ =
true;
644 canvas->push_transform();
648 canvas->transform(tv);
650 if ((
info.status_ & SceneInfoFixed) &&
info.glyph_ !=
NULL &&
651 (
info.status_ & SceneInfoShowing)) {
654 if (!(
info.status_ & SceneInfoViewFixed)) {
655 tv.inverse_transform(a.
x(), a.
y(), x, y);
663 if (canvas->damaged(b)) {
664 info.glyph_->print(canvas, a);
668 ((
Scene*)
this)->drawing_fixed_item_ =
false;
669 canvas->pop_transform();
675 if (
mbs() > 0. &&
picker_ && h.
event() && h.event()->type() == Event::down) {
676 Coord ax, ay, ex, ey;
677 c->transformer().transform(h.left(), h.top(), ex, ey);
678 c->transformer().transform(a.
left(), a.
top(), ax, ay);
696 bool are_fixed =
false;
698 if (
info.status_ & SceneInfoFixed) {
700 }
else if (
info.glyph_ !=
NULL && (
info.status_ & SceneInfoShowing)) {
702 if (h.right() >= a.
left() - epsx && h.left() < a.
right() + epsx &&
703 h.top() >= a.
bottom() - epsy && h.bottom() < a.
top() + epsy) {
704 h.begin(depth,
this,
index);
705 info.glyph_->pick(
c, a, depth + 1, h);
716 tv.matrix(scx, tmp, tmp, scy, tmp, tmp);
718 if ((
info.status_ & SceneInfoFixed) &&
info.glyph_ !=
NULL &&
719 (
info.status_ & SceneInfoShowing)) {
722 if (
info.status_ & SceneInfoViewFixed) {
730 l = (a.
left() - a.
x()) * scx + a.
x();
731 r = (a.
right() - a.
x()) * scx + a.
x();
732 t = (a.
top() - a.
y()) * scy + a.
y();
733 b = (a.
bottom() - a.
y()) * scy + a.
y();
737 if (h.right() >= l && h.left() < r && h.top() >= b && h.bottom() <
t) {
738 h.begin(depth,
this,
index);
739 info.glyph_->pick(
c, a, depth + 1, h);
748 auto it =
std::find(scene_list->begin(), scene_list->end(),
s);
749 if (it == scene_list->end()) {
756 o <<
"objectvar save_window_, rvp_" << std::endl;
760 if (!scene_list->empty()) {
761 o <<
"objectvar scene_vector_[" << scene_list->size() <<
"]" << std::endl;
763 for (
auto& scene: *scene_list) {
770 o <<
"save_window_ = new " <<
s <<
"(0)" << std::endl;
782 Sprintf(
buf,
"save_window_.size(%g,%g,%g,%g)", left, right, bottom, top);
783 o <<
buf << std::endl;
791 views_->front()->printfile(fname);
797 if (!obuf.open(fname, std::ios::out)) {
800 std::ostream o(&obuf);
void allot_y(const Allotment &)
bool equals(const Allocation &, float epsilon) const
void allot(DimensionName, const Allotment &)
Allotment & x_allotment()
Allotment & y_allotment()
void allot_x(const Allotment &)
void set(Canvas *, const Allocation &)
static bool inside(Coord x, Coord min, Coord max)
virtual PrintableWindow * window()
virtual bool has_window()
static void help(const char *)
static PrintableWindowManager * current()
void psfilter(const char *filename)
void require_x(const Requirement &)
void require_y(const Requirement &)
virtual void unref() const
virtual GlyphIndex glyph_index(const Glyph *)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
static long scene_list_index(Scene *)
virtual XYView * sceneview(int) const
void show(GlyphIndex, bool)
std::vector< XYView * > * views_
virtual void printfile(const char *)
void move(GlyphIndex, Coord x, Coord y)
virtual void save_phase1(std::ostream &)
virtual void change_to_fixed(GlyphIndex, XYView *)
virtual void save_phase2(std::ostream &)
virtual void replace(GlyphIndex, Glyph *)
virtual void damage(GlyphIndex)
std::vector< SceneInfo > * info_
virtual void allocate(Canvas *, const Allocation &, Extension &)
bool showing(GlyphIndex) const
virtual void background(Glyph *bg=NULL)
virtual void append_viewfixed(Glyph *)
static const Color * default_background()
void location(GlyphIndex, Coord &x, Coord &y) const
Scene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph *background=NULL)
void check_allocation(GlyphIndex)
virtual void damage_all()
virtual void append(Glyph *)
virtual void change_to_vfixed(GlyphIndex, XYView *)
virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void prepend(Glyph *)
void remove_view(XYView *)
static const Color * default_foreground()
virtual void change(GlyphIndex)
virtual void save_class(std::ostream &, const char *)
virtual int view_count() const
virtual void request(Requisition &) const
virtual void wholeplot(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual GlyphIndex count() const
virtual Glyph * component(GlyphIndex) const
virtual void remove(GlyphIndex)
virtual void insert(GlyphIndex, Glyph *)
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 modified(GlyphIndex)
virtual void draw(Canvas *, const Allocation &) const
virtual Coord mbs() const
virtual void pick_menu(Glyph *, int, Hit &)
void event(const Event &)
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
virtual void printfile(const char *)
virtual void zin(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static XYView * current_draw_view()
static XYView * current_pick_view()
const Transformer & s2o() const
#define y_(arg)
Crout matrix decomposition : Forward/Backward substitution.
void erase_first(T &&iterable, value_type &&value)
constexpr auto reverse(T &&iterable)
constexpr auto range(T &&iterable)
constexpr auto enumerate(T &&iterable)
unsigned int DimensionName
Symbol * lookup(const char *)
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
static void pr(N_Vector x)
int find(const int, const int, const int, const int, const int)