1 #include <../../nrnconf.h>
7 #include <InterViews/handler.h>
8 #include <InterViews/action.h>
9 #include <InterViews/style.h>
10 #include <InterViews/color.h>
11 #include <InterViews/polyglyph.h>
12 #include <IV-look/kit.h>
13 #include <InterViews/layout.h>
14 #include <InterViews/background.h>
34 #define SelectVariable_ "PlotWhat PlotShape"
35 #define VariableScale_ "VariableScale PlotShape"
36 #define TimePlot_ "TimePlot PlotShape"
37 #define SpacePlot_ "SpacePlot PlotShape"
38 #define ShapePlot_ "ShapePlot PlotShape"
39 #define MoveText_ "MoveText PlotShape"
46 void* (*nrnpy_get_pyobj)(
Object* obj) = 0;
53 IFGUI((ShapePlot*)
v)->flush();
62 IFGUI((ShapePlot*)
v)->fast_flush();
88 void ShapePlot::has_iv_view(
bool value) {
97 ShapePlot* sh = (ShapePlot*)
v;
98 sh->has_iv_view(
true);
105 for (
i = 0;
i < 8; ++
i) {
120 ShapePlot* sh = (ShapePlot*)
v;
130 if (sh->has_iv_view()) {
219 s->shape_type(
int(
chkarg(1, 0., 2.)));
231 ShapePlot* s = (ShapePlot*)
v;
233 s->color_value()->colormap(
int(
chkarg(1, 0, 255)),
240 b = (bool)
chkarg(2, 0, 1);
242 s->color_value()->colormap(
int(
chkarg(1, 0, 1000)), b);
255 double xsize =
chkarg(4, 1
e-9, 1e9);
256 double ysize = xsize;
260 Hinton* h =
new Hinton(pd, xsize, ysize, ss);
392 ShapePlot* sh =
NULL;
393 sh =
new ShapePlot(
NULL,
sl);
394 sh->has_iv_view(
i ?
true :
false);
419 ShapePlot* sp = (ShapePlot*)
v;
455 class ShapePlotImpl:
public Observer {
457 ShapePlotImpl(ShapePlot*,
Symbol*);
460 virtual void space();
461 virtual void shape();
462 virtual void show_shape_val(
bool);
463 virtual void select_variable();
464 virtual void scale();
465 virtual void colorbar();
482 MakeTimePlot(ShapePlotImpl*);
483 virtual ~MakeTimePlot();
492 MakeSpacePlot(ShapePlotImpl*);
493 virtual ~MakeSpacePlot();
500 declareActionCallback(ShapePlotImpl);
501 implementActionCallback(ShapePlotImpl);
507 sl_ =
sl->nrn_object();
513 spi_ =
new ShapePlotImpl(
this, sym);
515 picker()->add_menu(
"Plot What?",
516 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::select_variable));
517 picker()->add_menu(
"Variable scale",
518 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::scale));
519 picker()->add_radio_menu(
"Time Plot",
520 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::time));
521 picker()->add_radio_menu(
"Space Plot",
522 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::space));
523 picker()->add_radio_menu(
"Shape Plot",
524 new ActionCallback(ShapePlotImpl)(spi_, &ShapePlotImpl::shape));
525 color_value()->attach(spi_);
528 ShapePlot::~ShapePlot() {
531 color_value()->detach(spi_);
536 float ShapePlot::low() {
537 return color_value()->low();
539 float ShapePlot::high() {
540 return color_value()->high();
543 Object* ShapePlot::neuron_section_list() {
555 if (spi_->showing_) {
558 for (
i = 0;
i <
cnt; ++
i) {
566 void ShapePlot::update_ptrs() {
569 for (
i = 0;
i <
cnt; ++
i) {
575 void ShapePlot::erase_all() {
577 spi_->colorbar_ =
NULL;
585 void ShapePlot::variable(
Symbol* sym) {
588 i = glyph_index(spi_->variable_);
600 if (spi_->showing_) {
601 spi_->showing_ =
false;
602 spi_->show_shape_val(
true);
606 const char* ShapePlot::varname()
const {
607 return spi_->sym_->name;
610 void* ShapePlot::varobj()
const {
614 void ShapePlot::varobj(
void* obj) {
619 void ShapePlot::scale(
float min,
float max) {
620 color_value()->set_scale(
min,
max);
624 void ShapePlot::save_phase1(ostream&
o) {
626 save_class(
o,
"PlotShape");
628 sprintf(
buf,
"save_window_.variable(\"%s\")", spi_->sym_->name);
632 void ShapePlot::shape_plot() {}
633 void ShapePlot::make_time_plot(
Section*,
float) {}
634 void ShapePlot::make_space_plot(
Section*,
float,
Section*,
float) {}
635 void ShapePlot::flush() {
637 if (tool() == SHAPE) {
642 if (tool() == SHAPE) {
643 int i,
cnt = view_count();
646 for (
i = 0;
i <
cnt; ++
i) {
648 Coord x =
v->left(), y =
v->bottom();
657 if (w->bottom() < 0) {
662 v->damage(x, y, x, y);
667 extern void* mswin_setclip(
Canvas*,
int,
int,
int,
int);
668 extern void mswin_delete_object(
void*);
673 #if defined(WIN32) || MAC
690 c->push_clipping(
true);
692 c->clip_rect(
v->left(),
v->bottom(),
v->right(),
v->top());
719 void* new_clip = mswin_setclip(
c, 0, 0,
c->pwidth(),
c->pheight());
723 for (
i = 0;
i <
cnt; ++
i) {
728 ((
FastShape*) (gi->body()))->fast_draw(
c, x, y,
false);
731 #if defined(WIN32) || MAC
734 mswin_delete_object(new_clip);
745 ShapePlotImpl::ShapePlotImpl(ShapePlot* sp,
Symbol* sym) {
758 time_sh_ =
new MakeTimePlot(
this);
762 ShapePlotImpl::~ShapePlotImpl() {
768 void ShapePlotImpl::colorbar() {
771 int i = sp_->glyph_index(colorbar_);
773 showing = sp_->showing(
i);
778 colorbar_ = sp_->color_value()->make_glyph();
780 sp_->append_fixed(
new GraphItem(colorbar_, 0));
781 sp_->show(sp_->count() - 1, showing);
784 sp_->move(sp_->count() - 1,
v->left(),
v->top());
788 void ShapePlotImpl::select_variable() {
794 Style* style =
new Style(Session::instance()->style());
795 style->attribute(
"caption",
"Variable in the shape domain");
809 void ShapePlotImpl::scale() {
814 x = sp_->color_value()->low();
815 y = sp_->color_value()->high();
822 void ShapePlotImpl::time() {
827 sp_->tool(ShapePlot::TIME);
831 sp_->section_handler(time_sh_);
832 show_shape_val(
false);
836 void ShapePlotImpl::space() {
846 show_shape_val(
false);
847 sp_->picker()->bind_select(
new RubberLine(
new MakeSpacePlot(
this)));
850 void ShapePlotImpl::shape() {
855 sp_->tool(ShapePlot::SHAPE);
859 show_shape_val(
true);
862 void ShapePlotImpl::show_shape_val(
bool show) {
863 if (show != showing_) {
864 PolyGlyph* pg = sp_->shape_section_list();
867 for (
i = 0;
i <
cnt; ++
i) {
872 for (
i = 0;
i <
cnt; ++
i) {
878 int i = sp_->glyph_index(colorbar_);
882 sp_->move(
i,
v->left(),
v->top());
890 MakeTimePlot::MakeTimePlot(ShapePlotImpl* spi) {
893 MakeTimePlot::~MakeTimePlot() {}
895 bool MakeTimePlot::event(
Event&) {
899 if (spi_->sp_->tool() != ShapePlot::TIME) {
902 if (spi_->graphid_ == 0) {
903 oc.
run(
"newPlotV()\n");
904 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
907 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
909 float x = spi_->sp_->arc_selected();
912 if (spi_->graphid_ ==
hoc_ac_) {
914 sprintf(
buf,
"{graphItem.color(%d)}\n", spi_->colorid_);
917 "{graphItem.addvar(\"%s.%s(%g)\")}\n",
919 spi_->sp_->varname(),
930 MakeSpacePlot::MakeSpacePlot(ShapePlotImpl* spi) {
933 MakeSpacePlot::~MakeSpacePlot() {}
936 ShapePlot* sp = spi_->sp_;
938 Coord x1, y1, x2, y2;
944 oc.
run(
"objectvar rvp_\n");
947 sec1 = sp->selected()->section();
948 a1 = sp->arc_selected();
949 a1 = (a1 < .5) ? 0. : 1.;
951 sec2 = sp->selected()->section();
952 a2 = sp->arc_selected();
953 a2 = (a2 < .5) ? 0. : 1.;
954 if (sec1 == sec2 && a1 == a2) {
955 printf(
"Null path for space plot: ignored\n");
958 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
960 if (spi_->graphid_ == 0. || spi_->graphid_ !=
hoc_ac_) {
961 oc.
run(
"graphItem = new Graph()\n");
962 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
964 oc.
run(
"{graphItem.save_name(\"flush_list.\")}\n");
965 oc.
run(
"{flush_list.append(graphItem)}\n");
969 ColorValue* cv = sp->color_value();
970 sprintf(
buf,
"rvp_ = new RangeVarPlot(\"%s\")\n", sp->varname());
976 oc.
run(
"{rvp_.origin(rvp_.d2root)}\n");
977 sprintf(
buf,
"{graphItem.size(rvp_.left(), rvp_.right(), %g, %g)}\n", cv->low(), cv->high());
979 sprintf(
buf,
"{graphItem.addobject(rvp_, %d, 1) graphItem.yaxis()}\n", spi_->colorid_);
981 sp->color(sec1, sec2,
colors->
color(spi_->colorid_));
985 static const Color* gray;
987 static const Color** crange;
989 static int spec[] = {95, 0, 95, 111, 0, 111, 127, 0, 143, 143, 0, 127, 159, 0, 111,
990 175, 0, 95, 191, 0, 79, 207, 0, 63, 207, 31, 47, 223, 47, 47,
991 239, 63, 31, 255, 79, 15, 255, 95, 7, 255, 111, 0, 255, 127, 0,
992 255, 143, 0, 255, 159, 0, 255, 175, 0, 255, 191, 0, 255, 207, 0,
993 255, 223, 0, 255, 239, 0, 255, 247, 0, 255, 255, 0, -1};
996 ColorValue::ColorValue() {
998 Style* s = Session::instance()->style();
1001 if (s->find_attribute(
"shape_scale_file",
name)) {
1005 if ((f =
fopen(
name.string(),
"r")) == 0) {
1008 printf(
"Cannot open %s: Using built-in colormap for shapeplot\n",
name.string());
1012 while (fscanf(f,
"%d %d %d", &r, &
g, &b) == 3) {
1016 crange =
new const Color*[csize];
1019 while (fscanf(f,
"%d %d %d", &r, &
g, &b) == 3) {
1031 for (csize = 0; spec[csize * 3] != -1; csize++) {
1033 crange =
new const Color*[csize];
1034 for (csize = 0; spec[csize * 3] != -1; csize++) {
1041 gray =
Color::lookup(Session::instance()->default_display(),
"gray");
1049 ColorValue::~ColorValue() {
1052 for (
i = 0;
i < csize_; ++
i) {
1053 crange_[
i]->unref();
1059 void ColorValue::set_scale(
float low,
float high) {
1067 const Color* ColorValue::get_color(
float val)
const {
1068 float x = (val - low_) / (high_ - low_);
1071 return crange_[csize_ - 1];
1075 return crange_[int(csize_ * x)];
1078 return crange[csize - 1];
1082 return crange[int(csize * x)];
1086 const Color* ColorValue::no_value()
const {
1090 class ColorValueGlyphItem:
public MonoGlyph {
1092 ColorValueGlyphItem(
const char*,
const Color*);
1093 virtual ~ColorValueGlyphItem();
1098 const Color* color_;
1101 ColorValueGlyphItem::ColorValueGlyphItem(
const char*
buf,
const Color*
c) {
1107 ColorValueGlyphItem::~ColorValueGlyphItem() {}
1121 Glyph* ColorValue::make_glyph() {
1125 int c = csize_ ? csize_ : csize;
1126 for (
int i =
c - 1;
i >= 0; --
i) {
1128 float x = low_ +
i * (high_ - low_) / (
c - 1);
1130 box->append(
new ColorValueGlyphItem(
buf, get_color(x)));
1136 void ColorValue::colormap(
int size,
bool global) {
1139 for (
i = 0;
i < csize_; ++
i) {
1140 crange_[
i]->unref();
1148 for (
i = 0;
i < csize; ++
i) {
1153 csize = (size > 1) ? size : 2;
1154 crange =
new const Color*[csize];
1155 for (
i = 0;
i < csize; ++
i) {
1160 csize_ = (size > 1) ? size : 2;
1161 crange_ =
new const Color*[csize_];
1162 for (
i = 0;
i < csize_; ++
i) {
1168 void ColorValue::colormap(
int i,
int r,
int g,
int b) {
1170 if (
i >= 0 &&
i < csize_ && r < 256 &&
g < 256 && b < 256) {
1171 crange_[
i]->unref();
1178 if (
i >= 0 &&
i < csize && r < 256 &&
g < 256 && b < 256) {
1209 ss_->remove(ss_->glyph_index(
this));
1227 const Color*
color = ss_->color_value()->get_color(*pd_);
1228 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_,
color);
1229 ((Hinton*)
this)->old_ =
color;
1230 IfIdraw(rect(
c, x - xsize_, y - ysize_, x + xsize_, y + ysize_,
color,
NULL,
true));
1235 const Color*
color = ss_->color_value()->get_color(*pd_);
1236 if (
color != old_) {
1237 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_,
color);
1238 ((Hinton*)
this)->old_ =
color;
1243 bool ShapePlot::has_iv_view() {
1244 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)
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_when_freed(void *p, Observer *)
void notify_pointer_disconnect(Observer *)
static ostream * idraw_stream
static void text(Canvas *, const char *, const Transformer &, const Font *f=NULL, const Color *c=NULL)
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
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 *)
const char * string() const
virtual const String * selected() const
static XYView * current_draw_view()
static XYView * current_pick_view()
Symbol * hoc_table_lookup(const char *, Symlist *)
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)
double chkarg(int, double low, double high)
static void update(NrnThread *)
void hoc_execerror(const char *, const char *)
int hoc_is_object_arg(int narg)
const char * expand_env_var(const char *s)
void hoc_dec_refcount(Object **pobj)
double * hoc_pgetarg(int narg)
#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)
Symlist * hoc_built_in_symlist
int const size_t const size_t n
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
static int component(PyHocObject *po)
check_obj_type(o, "SectionList")
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)
double(* nrnpy_object_to_double_)(Object *)
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 *)
bool var_pair_chooser(const char *, float &x, float &y, Window *w=NULL, Coord x1=400., Coord y1=400.)