1 #include <../../nrnconf.h>
9 #include <InterViews/handler.h>
10 #include <InterViews/action.h>
11 #include <InterViews/style.h>
12 #include <InterViews/color.h>
13 #include <InterViews/polyglyph.h>
14 #include <IV-look/kit.h>
15 #include <InterViews/layout.h>
16 #include <InterViews/background.h>
35 #define SelectVariable_ "PlotWhat PlotShape"
36 #define VariableScale_ "VariableScale PlotShape"
37 #define TimePlot_ "TimePlot PlotShape"
38 #define SpacePlot_ "SpacePlot PlotShape"
39 #define ShapePlot_ "ShapePlot PlotShape"
40 #define MoveText_ "MoveText PlotShape"
45 void* (*nrnpy_get_pyobj)(
Object* obj) = 0;
53 ((ShapePlot*)
v)->flush();
63 ((ShapePlot*)
v)->fast_flush();
78 ((ShapePlot*)
v)->scale(
float(*
getarg(1)),
float(*
getarg(2)));
89 void ShapePlot::has_iv_view(
bool value) {
98 ShapePlot* sh = (ShapePlot*)
v;
99 sh->has_iv_view(
true);
106 for (
i = 0;
i < 8; ++
i) {
121 ShapePlot* sh = (ShapePlot*)
v;
131 if (sh->has_iv_view()) {
223 s->shape_type(
int(
chkarg(1, 0., 2.)));
225 return s->shape_type();
250 ShapePlot*
s = (ShapePlot*)
v;
252 s->color_value()->colormap(
int(
chkarg(1, 0, 255)),
259 b = (bool)
chkarg(2, 0, 1);
261 s->color_value()->colormap(
int(
chkarg(1, 0, 1000)), b);
274 double xsize =
chkarg(4, 1e-9, 1e9);
275 double ysize = xsize;
277 ysize =
chkarg(5, 1e-9, 1e9);
279 Hinton* h =
new Hinton(pd, xsize, ysize, ss);
380 ShapePlot* sh =
NULL;
381 sh =
new ShapePlot(
NULL, sl);
382 sh->has_iv_view(
i ?
true :
false);
406 ShapePlot* sp = (ShapePlot*)
v;
441 class ShapePlotImpl:
public Observer {
443 ShapePlotImpl(ShapePlot*,
Symbol*);
446 virtual void space();
447 virtual void shape();
448 virtual void show_shape_val(
bool);
449 virtual void select_variable();
450 virtual void scale();
451 virtual void colorbar();
468 MakeTimePlot(ShapePlotImpl*);
469 virtual ~MakeTimePlot();
478 MakeSpacePlot(ShapePlotImpl*);
479 virtual ~MakeSpacePlot();
486 declareActionCallback(ShapePlotImpl);
487 implementActionCallback(ShapePlotImpl);
499 spi_ =
new ShapePlotImpl(
this, sym);
501 picker()->add_menu(
"Plot What?",
502 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::select_variable));
503 picker()->add_menu(
"Variable scale",
504 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::scale));
505 picker()->add_radio_menu(
"Time Plot",
506 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::time));
507 picker()->add_radio_menu(
"Space Plot",
508 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::space));
509 picker()->add_radio_menu(
"Shape Plot",
510 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::shape));
511 color_value()->attach(spi_);
514 ShapePlot::~ShapePlot() {
517 color_value()->detach(spi_);
522 float ShapePlot::low() {
523 return color_value()->low();
525 float ShapePlot::high() {
526 return color_value()->high();
529 Object* ShapePlot::neuron_section_list() {
541 if (spi_->showing_) {
544 for (
i = 0;
i <
cnt; ++
i) {
552 void ShapePlot::erase_all() {
554 spi_->colorbar_ =
NULL;
562 void ShapePlot::variable(
Symbol* sym) {
565 i = glyph_index(spi_->variable_);
577 if (spi_->showing_) {
578 spi_->showing_ =
false;
579 spi_->show_shape_val(
true);
583 const char* ShapePlot::varname()
const {
584 return spi_->sym_->name;
587 void* ShapePlot::varobj()
const {
591 void ShapePlot::varobj(
void* obj) {
596 void ShapePlot::scale(
float min,
float max) {
597 color_value()->set_scale(min, max);
601 void ShapePlot::save_phase1(std::ostream& o) {
602 o <<
"{" << std::endl;
603 save_class(o,
"PlotShape");
604 o <<
"save_window_.variable(\"" << spi_->sym_->name <<
"\")" << std::endl;
607 void ShapePlot::shape_plot() {}
608 void ShapePlot::make_time_plot(
Section*,
float) {}
609 void ShapePlot::make_space_plot(
Section*,
float,
Section*,
float) {}
610 void ShapePlot::flush() {
612 if (tool() == SHAPE) {
617 if (tool() == SHAPE) {
618 int i,
cnt = view_count();
621 for (
i = 0;
i <
cnt; ++
i) {
623 Coord x =
v->left(), y =
v->bottom();
632 if (w->bottom() < 0) {
637 v->damage(x, y, x, y);
642 extern void* mswin_setclip(
Canvas*,
int,
int,
int,
int);
643 extern void mswin_delete_object(
void*);
665 c->push_clipping(
true);
691 void* new_clip = mswin_setclip(
c, 0, 0,
c->pwidth(),
c->pheight());
695 for (
i = 0;
i <
cnt; ++
i) {
700 ((
FastShape*) (gi->body()))->fast_draw(
c, x, y,
false);
705 mswin_delete_object(new_clip);
714 ShapePlotImpl::ShapePlotImpl(ShapePlot* sp,
Symbol* sym) {
727 time_sh_ =
new MakeTimePlot(
this);
731 ShapePlotImpl::~ShapePlotImpl() {
737 void ShapePlotImpl::colorbar() {
740 int i = sp_->glyph_index(colorbar_);
742 showing = sp_->showing(
i);
747 colorbar_ = sp_->color_value()->make_glyph();
749 sp_->append_fixed(
new GraphItem(colorbar_, 0));
750 sp_->show(sp_->count() - 1, showing);
753 sp_->move(sp_->count() - 1,
v->left(),
v->top());
757 void ShapePlotImpl::select_variable() {
763 Style* style =
new Style(Session::instance()->style());
764 style->attribute(
"caption",
"Variable in the shape domain");
778 void ShapePlotImpl::scale() {
783 x = sp_->color_value()->low();
784 y = sp_->color_value()->high();
791 void ShapePlotImpl::time() {
796 sp_->tool(ShapePlot::TIME);
800 sp_->section_handler(time_sh_);
801 show_shape_val(
false);
805 void ShapePlotImpl::space() {
810 sp_->tool(ShapePlot::SPACE);
815 show_shape_val(
false);
816 sp_->picker()->bind_select(
new RubberLine(
new MakeSpacePlot(
this)));
819 void ShapePlotImpl::shape() {
824 sp_->tool(ShapePlot::SHAPE);
828 show_shape_val(
true);
831 void ShapePlotImpl::show_shape_val(
bool show) {
832 if (
show != showing_) {
833 PolyGlyph* pg = sp_->shape_section_list();
836 for (
i = 0;
i <
cnt; ++
i) {
841 for (
i = 0;
i <
cnt; ++
i) {
847 int i = sp_->glyph_index(colorbar_);
851 sp_->move(
i,
v->left(),
v->top());
859 MakeTimePlot::MakeTimePlot(ShapePlotImpl* spi) {
862 MakeTimePlot::~MakeTimePlot() {}
864 bool MakeTimePlot::event(
Event&) {
868 if (spi_->sp_->tool() != ShapePlot::TIME) {
871 if (spi_->graphid_ == 0) {
872 oc.
run(
"newPlotV()\n");
873 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
876 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
878 float x = spi_->sp_->arc_selected();
881 if (spi_->graphid_ ==
hoc_ac_) {
883 Sprintf(
buf,
"{graphItem.color(%d)}\n", spi_->colorid_);
886 "{graphItem.addvar(\"%s.%s(%g)\")}\n",
888 spi_->sp_->varname(),
899 MakeSpacePlot::MakeSpacePlot(ShapePlotImpl* spi) {
902 MakeSpacePlot::~MakeSpacePlot() {}
905 ShapePlot* sp = spi_->sp_;
907 Coord x1, y1, x2, y2;
913 oc.
run(
"objectvar rvp_\n");
916 sec1 = sp->selected()->section();
917 a1 = sp->arc_selected();
918 a1 = (a1 < .5) ? 0. : 1.;
920 sec2 = sp->selected()->section();
921 a2 = sp->arc_selected();
922 a2 = (a2 < .5) ? 0. : 1.;
923 if (sec1 == sec2 && a1 == a2) {
924 printf(
"Null path for space plot: ignored\n");
927 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
929 if (spi_->graphid_ == 0. || spi_->graphid_ !=
hoc_ac_) {
930 oc.
run(
"graphItem = new Graph()\n");
931 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
933 oc.
run(
"{graphItem.save_name(\"flush_list.\")}\n");
934 oc.
run(
"{flush_list.append(graphItem)}\n");
938 ColorValue* cv = sp->color_value();
939 Sprintf(
buf,
"rvp_ = new RangeVarPlot(\"%s\")\n", sp->varname());
945 oc.
run(
"{rvp_.origin(rvp_.d2root)}\n");
946 Sprintf(
buf,
"{graphItem.size(rvp_.left(), rvp_.right(), %g, %g)}\n", cv->low(), cv->high());
948 Sprintf(
buf,
"{graphItem.addobject(rvp_, %d, 1) graphItem.yaxis()}\n", spi_->colorid_);
950 sp->color(sec1, sec2,
colors->
color(spi_->colorid_));
954 static const Color* gray;
956 static const Color** crange;
958 static int spec[] = {95, 0, 95, 111, 0, 111, 127, 0, 143, 143, 0, 127, 159, 0, 111,
959 175, 0, 95, 191, 0, 79, 207, 0, 63, 207, 31, 47, 223, 47, 47,
960 239, 63, 31, 255, 79, 15, 255, 95, 7, 255, 111, 0, 255, 127, 0,
961 255, 143, 0, 255, 159, 0, 255, 175, 0, 255, 191, 0, 255, 207, 0,
962 255, 223, 0, 255, 239, 0, 255, 247, 0, 255, 255, 0, -1};
965 ColorValue::ColorValue() {
967 Style*
s = Session::instance()->style();
970 if (
s->find_attribute(
"shape_scale_file",
name)) {
974 if ((f = fopen(
name.string(),
"r")) == 0) {
977 printf(
"Cannot open %s: Using built-in colormap for shapeplot\n",
name.string());
981 while (fscanf(f,
"%d %d %d", &r, &g, &b) == 3) {
985 crange =
new const Color*[csize];
988 while (fscanf(f,
"%d %d %d", &r, &g, &b) == 3) {
1000 for (csize = 0; spec[csize * 3] != -1; csize++) {
1002 crange =
new const Color*[csize];
1003 for (csize = 0; spec[csize * 3] != -1; csize++) {
1010 gray =
Color::lookup(Session::instance()->default_display(),
"gray");
1018 ColorValue::~ColorValue() {
1021 for (
i = 0;
i < csize_; ++
i) {
1022 crange_[
i]->unref();
1028 void ColorValue::set_scale(
float low,
float high) {
1036 const Color* ColorValue::get_color(
float val)
const {
1037 float x = (val - low_) / (high_ - low_);
1040 return crange_[csize_ - 1];
1044 return crange_[int(csize_ * x)];
1047 return crange[csize - 1];
1051 return crange[int(csize * x)];
1055 const Color* ColorValue::no_value()
const {
1059 class ColorValueGlyphItem:
public MonoGlyph {
1061 ColorValueGlyphItem(
const char*,
const Color*);
1062 virtual ~ColorValueGlyphItem();
1067 const Color* color_;
1070 ColorValueGlyphItem::ColorValueGlyphItem(
const char*
buf,
const Color*
c) {
1076 ColorValueGlyphItem::~ColorValueGlyphItem() {}
1090 Glyph* ColorValue::make_glyph() {
1094 int c = csize_ ? csize_ : csize;
1095 for (
int i =
c - 1;
i >= 0; --
i) {
1097 float x = low_ +
i * (high_ - low_) / (
c - 1);
1099 box->append(
new ColorValueGlyphItem(
buf, get_color(x)));
1105 void ColorValue::colormap(
int size,
bool global) {
1108 for (
i = 0;
i < csize_; ++
i) {
1109 crange_[
i]->unref();
1117 for (
i = 0;
i < csize; ++
i) {
1122 csize = (size > 1) ? size : 2;
1123 crange =
new const Color*[csize];
1124 for (
i = 0;
i < csize; ++
i) {
1129 csize_ = (size > 1) ? size : 2;
1130 crange_ =
new const Color*[csize_];
1131 for (
i = 0;
i < csize_; ++
i) {
1137 void ColorValue::colormap(
int i,
int r,
int g,
int b) {
1139 if (
i >= 0 &&
i < csize_ && r < 256 && g < 256 && b < 256) {
1140 crange_[
i]->unref();
1147 if (
i >= 0 &&
i < csize && r < 256 && g < 256 && b < 256) {
1180 ss_->remove(ss_->glyph_index(
this));
1198 const Color* color = ss_->color_value()->get_color(*pd_);
1199 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_, color);
1200 ((Hinton*)
this)->old_ = color;
1201 IfIdraw(rect(
c, x - xsize_, y - ysize_, x + xsize_, y + ysize_, color,
NULL,
true));
1206 const Color* color = ss_->color_value()->get_color(*pd_);
1207 if (color != old_) {
1208 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_, color);
1209 ((Hinton*)
this)->old_ = color;
1214 bool ShapePlot::has_iv_view() {
1215 return has_iv_view_;
double nrn_section_orientation(Section *sec)
double nrn_arc_position(Section *sec, Node *node)
char * hoc_section_pathname(Section *sec)
Node * node_exact(Section *sec, double x)
like node_index but give proper node when x is 0 or 1 as well as in between
const Color * color(int) const
void set(Canvas *, const Allocation &)
FastGraphItem(FastShape *g, bool save=true, bool pick=true)
virtual void draw(Canvas *, const Allocation &) const
virtual void update(Observable *)
static void help(const char *)
int run(int argc, const char **argv)
void notify_pointer_disconnect(Observer *)
static void text(Canvas *, const char *, const Transformer &, const Font *f=NULL, const Color *c=NULL)
static std::ostream * idraw_stream
static void rect(Canvas *, Coord x1, Coord y1, Coord x2, Coord y2, const Color *c=NULL, const Brush *b=NULL, bool fill=false)
void require_x(const Requirement &)
void require_y(const Requirement &)
virtual void unref() const
virtual void execute(Rubberband *)
virtual void get_line(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
void move(GlyphIndex, Coord x, Coord y)
virtual void append(Glyph *)
virtual GlyphIndex count() const
virtual bool event(Event &)
virtual const char * varname() const
ShapePlotData(Symbol *=NULL, Object *=NULL)
virtual Object * neuron_section_list()
virtual bool has_iv_view()
virtual void scale(float min, float max)
virtual void variable(Symbol *)
virtual void * varobj() const
virtual void observe(SectionList *=NULL)
static ShapeScene * current_pick_scene()
virtual void clear_variable()
Section * section() const
virtual void setColor(const Color *, ShapeScene *)
virtual void set_range_variable(Symbol *)
virtual const std::string & selected() const
static XYView * current_draw_view()
static XYView * current_pick_view()
void class2oc(const char *, ctor_f *cons, dtor_f *destruct, Member_func *, Member_ret_obj_func *, Member_ret_str_func *)
Symbol * hoc_table_lookup(const char *, Symlist *)
HocReturnType hoc_return_type_code
double chkarg(int, double low, double high)
int hoc_is_object_arg(int narg)
const char * expand_env_var(const char *s)
void check_obj_type(Object *obj, const char *type_name)
void hoc_dec_refcount(Object **pobj)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
#define TRY_GUI_REDIRECT_OBJ(name, obj)
Object ** hoc_objgetarg(int)
static double location(void *v)
Symbol * lookup(const char *)
void update(NrnThread *_nt)
void hoc_execerror(const char *s1, const char *s2)
void notify_when_handle_dies(data_handle< double > dh, Observer *obs)
Register that obs should be notified when dh dies.
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
int const size_t const size_t n
static HocReturnType component(PyHocObject *po)
static double sh_begin(void *v)
double ivoc_gr_menu_action(void *v)
void *(* nrnpy_get_pyobj)(Object *obj)=0
static void sh_destruct(void *v)
static double sh_flush(void *v)
double nrniv_len_scale(void *)
static double sh_view_count(void *v)
static double sh_hinton(void *v)
Object ** nrniv_sh_selected_seg(void *)
static double s_colormap(void *v)
static double sh_save_name(void *v)
static double sh_scale(void *v)
static double exec_menu(void *v)
double ivoc_gr_gif(void *)
static double fast_flush(void *v)
void(* nrnpy_decref)(void *pyobj)=0
double nrniv_sh_observe(void *)
double ivoc_gr_mark(void *)
double ivoc_gr_menu_tool(void *)
double ivoc_gr_label(void *)
Object ** nrniv_sh_nearest_seg(void *)
double nrniv_sh_color_all(void *)
static double sh_printfile(void *v)
static double sh_view(void *v)
double ivoc_erase_all(void *)
double ivoc_gr_line(void *)
double ivoc_gr_erase(void *)
static double sh_unmap(void *v)
double ivoc_gr_size(void *)
double nrniv_sh_color(void *)
static Member_ret_obj_func retobj_members[]
static void * sh_cons(Object *ho)
double nrniv_sh_rotate(void *)
double nrniv_sh_nearest(void *)
static Member_func sh_members[]
static double sh_variable(void *v)
double nrniv_sh_push(void *)
double nrniv_sh_color_list(void *)
static double sh_show(void *v)
double ivoc_gr_begin_line(void *)
Symlist * hoc_built_in_symlist
bool var_pair_chooser(const char *, float &x, float &y, Window *w=NULL, Coord x1=400., Coord y1=400.)