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;
54 ((ShapePlot*)v)->flush();
64 ((ShapePlot*)v)->fast_flush();
79 ((ShapePlot*)v)->scale(
float(*
getarg(1)),
float(*
getarg(2)));
90 void ShapePlot::has_iv_view(
bool value) {
99 ShapePlot* sh = (ShapePlot*)v;
100 sh->has_iv_view(
true);
106 for (i=0; i < 8; ++
i) {
121 ShapePlot* sh = (ShapePlot*) v;
131 if (sh->has_iv_view()) {
221 s->shape_type(
int(
chkarg(1, 0., 2.)));
233 ShapePlot*
s = (ShapePlot*)v;
235 s->color_value()->colormap(
int(
chkarg(1, 0, 255)),
243 b = (bool)
chkarg(2, 0, 1);
245 s->color_value()->colormap(
int(
chkarg(1, 0, 1000)), b);
258 double xsize =
chkarg(4, 1
e-9, 1e9);
259 double ysize = xsize;
263 Hinton* h =
new Hinton(pd, xsize, ysize, ss);
368 ShapePlot* sh =
NULL;
369 sh =
new ShapePlot(
NULL, sl);
370 sh->has_iv_view(i ?
true :
false);
394 ShapePlot* sp = (ShapePlot*) v;
429 class ShapePlotImpl :
public Observer {
431 ShapePlotImpl(ShapePlot*,
Symbol*);
434 virtual void space();
435 virtual void shape();
436 virtual void show_shape_val(
bool);
437 virtual void select_variable();
438 virtual void scale();
439 virtual void colorbar();
455 MakeTimePlot(ShapePlotImpl*);
456 virtual ~MakeTimePlot();
457 virtual bool event(
Event&);
464 MakeSpacePlot(ShapePlotImpl*);
465 virtual ~MakeSpacePlot();
471 declareActionCallback(ShapePlotImpl);
472 implementActionCallback(ShapePlotImpl);
482 spi_ =
new ShapePlotImpl(
this, sym);
484 picker()->add_menu(
"Plot What?",
new ActionCallback(ShapePlotImpl)(
485 spi_, &ShapePlotImpl::select_variable));
486 picker()->add_menu(
"Variable scale",
new ActionCallback(ShapePlotImpl)(
487 spi_, &ShapePlotImpl::scale));
488 picker()->add_radio_menu(
"Time Plot",
new ActionCallback(ShapePlotImpl)(
489 spi_, &ShapePlotImpl::time));
490 picker()->add_radio_menu(
"Space Plot",
new ActionCallback(ShapePlotImpl)(
491 spi_, &ShapePlotImpl::space));
492 picker()->add_radio_menu(
"Shape Plot",
new ActionCallback(ShapePlotImpl)(
493 spi_, &ShapePlotImpl::shape));
494 color_value()->attach(spi_);
497 ShapePlot::~ShapePlot() {
499 color_value()->detach(spi_);
504 float ShapePlot::low() {
505 return color_value()->low();
507 float ShapePlot::high() {
508 return color_value()->high();
511 Object* ShapePlot::neuron_section_list() {
518 sl_ = sl ? sl -> nrn_object() :
NULL;
521 if (spi_->showing_) {
524 for (i=0; i <
cnt; ++
i) {
532 void ShapePlot::update_ptrs() {
535 for (i=0; i <
cnt; ++
i) {
541 void ShapePlot::erase_all() {
543 spi_->colorbar_ =
NULL;
551 void ShapePlot::variable(
Symbol* sym) {
554 i = glyph_index(spi_->variable_);
566 if (spi_->showing_) {
567 spi_->showing_ =
false;
568 spi_->show_shape_val(
true);
572 const char* ShapePlot::varname()
const {
573 return spi_->sym_->name;
576 void* ShapePlot::varobj()
const {
580 void ShapePlot::varobj(
void* obj) {
585 void ShapePlot::scale(
float min,
float max) {
586 color_value()->set_scale(
min, max);
590 void ShapePlot::save_phase1(ostream&
o) {
592 save_class(o,
"PlotShape");
594 sprintf(buf,
"save_window_.variable(\"%s\")", spi_->sym_->name);
598 void ShapePlot::shape_plot() {}
599 void ShapePlot::make_time_plot(
Section*,
float) {
601 void ShapePlot::make_space_plot(
Section*,
float,
Section*,
float) {
603 void ShapePlot::flush() {
605 if (tool() == SHAPE) {
610 if (tool() == SHAPE) {
611 int i,
cnt = view_count();
614 for (i=0; i <
cnt; ++
i) {
625 if (w->bottom() < 0) {
635 extern void* mswin_setclip(
Canvas*,
int,
int,
int,
int);
636 extern void mswin_delete_object(
void*);
641 #if defined(WIN32) || MAC 658 c->push_clipping(
true);
687 void* new_clip = mswin_setclip(
c, 0, 0,
c->pwidth(),
c->pheight());
691 for (i=0; i <
cnt; ++
i) {
696 ((
FastShape*)(gi->body()))->fast_draw(
c, x, y,
false);
699 #if defined(WIN32) || MAC 702 mswin_delete_object(new_clip);
712 ShapePlotImpl::ShapePlotImpl(ShapePlot* sp,
Symbol* sym) {
725 time_sh_ =
new MakeTimePlot(
this);
729 ShapePlotImpl::~ShapePlotImpl() {
735 void ShapePlotImpl::colorbar() {
738 int i = sp_->glyph_index(colorbar_);
740 showing = sp_->showing(i);
745 colorbar_ = sp_->color_value()->make_glyph();
747 sp_->append_fixed(
new GraphItem(colorbar_, 0));
748 sp_->show(sp_->count() - 1, showing);
751 sp_->move(sp_->count() - 1, v->
left(), v->
top());
755 void ShapePlotImpl::select_variable() {
761 Style* style =
new Style(Session::instance()->style());
762 style->attribute(
"caption",
"Variable in the shape domain");
776 void ShapePlotImpl::scale() {
781 x = sp_->color_value()->low();
782 y = sp_->color_value()->high();
789 void ShapePlotImpl::time() {
794 sp_->tool(ShapePlot::TIME);
798 sp_->section_handler(time_sh_);
799 show_shape_val(
false);
803 void ShapePlotImpl::space() {
813 show_shape_val(
false);
814 sp_->picker()->bind_select(
new RubberLine(
new MakeSpacePlot(
this)));
817 void ShapePlotImpl::shape() {
822 sp_->tool(ShapePlot::SHAPE);
825 sp_->picker()->bind_select((
OcHandler*)NULL);
826 show_shape_val(
true);
829 void ShapePlotImpl::show_shape_val(
bool show) {
830 if (show != showing_) {
831 PolyGlyph* pg = sp_->shape_section_list();
834 for (i=0; i <
cnt; ++
i) {
839 for (i=0; i <
cnt; ++
i) {
845 int i = sp_->glyph_index(colorbar_);
849 sp_->move(i, v->
left(), v->
top());
857 MakeTimePlot::MakeTimePlot(ShapePlotImpl* spi){
860 MakeTimePlot::~MakeTimePlot(){
863 bool MakeTimePlot::event(
Event&) {
867 if (spi_->sp_->tool() != ShapePlot::TIME) {
870 if (spi_->graphid_ == 0) {
871 oc.
run(
"newPlotV()\n");
872 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
875 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
877 float x = spi_->sp_->arc_selected();
880 if (spi_->graphid_ ==
hoc_ac_) {
882 sprintf(buf,
"{graphItem.color(%d)}\n", spi_->colorid_);
884 sprintf(buf,
"{graphItem.addvar(\"%s.%s(%g)\")}\n",
886 spi_->sp_->varname(),
899 MakeSpacePlot::MakeSpacePlot(ShapePlotImpl* spi){
902 MakeSpacePlot::~MakeSpacePlot(){
906 ShapePlot* sp = spi_->sp_;
908 Coord x1, y1, x2, y2;
914 oc.
run(
"objectvar rvp_\n");
917 sec1 = sp->selected()->section();
918 a1 = sp->arc_selected();
919 a1 = (a1 < .5) ? 0. : 1.;
921 sec2 = sp->selected()->section();
922 a2 = sp->arc_selected();
923 a2 = (a2 < .5) ? 0. : 1.;
924 if (sec1 == sec2 && a1 == a2) {
925 printf(
"Null path for space plot: ignored\n");
928 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
930 if (spi_->graphid_ == 0. || spi_->graphid_ !=
hoc_ac_) {
931 oc.
run(
"graphItem = new Graph()\n");
932 oc.
run(
"hoc_ac_ = object_id(graphItem)\n");
934 oc.
run(
"{graphItem.save_name(\"flush_list.\")}\n");
935 oc.
run(
"{flush_list.append(graphItem)}\n");
939 ColorValue* cv = sp->color_value();
940 sprintf(buf,
"rvp_ = new RangeVarPlot(\"%s\")\n", sp->varname());oc.
run(buf);
943 oc.
run(
"{rvp_.origin(rvp_.d2root)}\n");
944 sprintf(buf,
"{graphItem.size(rvp_.left(), rvp_.right(), %g, %g)}\n", cv->low(), cv->high()); oc.
run(buf);
945 sprintf(buf,
"{graphItem.addobject(rvp_, %d, 1) graphItem.yaxis()}\n", spi_->colorid_); oc.
run(buf);
946 sp->color(sec1, sec2,
colors->
color(spi_->colorid_));
950 static const Color* gray;
952 static const Color** crange;
954 static int spec[] = { 95, 0, 95,
981 ColorValue::ColorValue(){
983 Style*
s = Session::instance()->style();
986 if (s->find_attribute(
"shape_scale_file", name)) {
993 printf(
"Cannot open %s: Using built-in colormap for shapeplot\n", name.
string());
997 while(fscanf(f,
"%d %d %d", &r, &g, &b) == 3) {
1001 crange =
new const Color*[csize];
1004 while(fscanf(f,
"%d %d %d", &r, &g, &b) == 3) {
1005 crange[csize] =
new Color(
1018 for ( csize=0; spec[csize*3] != -1; csize++) { }
1019 crange =
new const Color*[csize];
1020 for ( csize=0; spec[csize*3] != -1; csize++) {
1021 crange[csize] =
new Color(
1029 gray =
Color::lookup(Session::instance()->default_display(),
"gray");
1037 ColorValue::~ColorValue(){
1040 for (i=0; i < csize_; ++
i) {
1041 crange_[
i]->unref();
1047 void ColorValue::set_scale(
float low,
float high) {
1055 const Color* ColorValue::get_color(
float val)
const {
1056 float x = (val - low_)/(high_ - low_);
1058 if (x > .99)
return crange_[csize_-1];
1059 else if (x < 0)
return crange_[0];
1060 else return crange_[
int(csize_ * x)];
1062 if (x > .99)
return crange[csize-1];
1063 else if (x < 0)
return crange[0];
1064 else return crange[
int(csize * x)];
1068 const Color* ColorValue::no_value()
const {
1072 class ColorValueGlyphItem :
public MonoGlyph {
1074 ColorValueGlyphItem(
const char*,
const Color*);
1075 virtual ~ColorValueGlyphItem();
1079 const Color* color_;
1082 ColorValueGlyphItem::ColorValueGlyphItem(
const char*
buf,
const Color*
c) {
1088 ColorValueGlyphItem::~ColorValueGlyphItem() {}
1102 Glyph* ColorValue::make_glyph() {
1106 int c = csize_ ? csize_ : csize;
1107 for (
int i = c-1;
i >= 0; --
i) {
1109 float x = low_ +
i*(high_ - low_)/(c-1);
1111 box->append(
new ColorValueGlyphItem(buf, get_color(x)));
1117 void ColorValue::colormap(
int size,
bool global) {
1120 for (i=0; i < csize_; ++
i) {
1121 crange_[
i]->unref();
1129 for (i=0; i < csize; ++
i) {
1134 csize = (size > 1) ? size : 2;
1135 crange =
new const Color*[csize];
1136 for (i=0; i < csize; ++
i) {
1141 csize_ = (size > 1) ? size : 2;
1142 crange_ =
new const Color*[csize_];
1143 for (i=0; i < csize_; ++
i) {
1149 void ColorValue::colormap(
int i,
int r,
int g,
int b) {
1151 if (
i >= 0 &&
i < csize_ && r < 256 &&
g < 256 && b < 256) {
1152 crange_[
i]->unref();
1161 if (
i >= 0 &&
i < csize && r < 256 &&
g < 256 && b < 256) {
1195 ss_->remove(ss_->glyph_index(
this));
1213 const Color*
color = ss_->color_value()->get_color(*pd_);
1214 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_, color);
1215 ((Hinton*)
this)->old_ =
color;
1216 IfIdraw(rect(
c, x - xsize_, y - ysize_, x + xsize_, y + ysize_, color,
NULL,
true));
1221 const Color*
color = ss_->color_value()->get_color(*pd_);
1222 if (color != old_) {
1223 c->fill_rect(x - xsize_, y - ysize_, x + xsize_, y + ysize_, color);
1224 ((Hinton*)
this)->old_ =
color;
1229 bool ShapePlot::has_iv_view() {
1230 return has_iv_view_;
virtual void * varobj() const
FastGraphItem(FastShape *g, bool save=true, bool pick=true)
virtual void damage_all()
char * hoc_section_pathname(Section *sec)
static ostream * idraw_stream
Object ** nrniv_sh_nearest_seg(void *)
static double fast_flush(void *v)
double ivoc_gr_begin_line(void *)
double max(double a, double b)
virtual Coord bottom() const
double ivoc_erase_all(void *)
void set(Canvas *, const Allocation &)
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
static double sh_view_count(void *v)
static double sh_variable(void *v)
double nrn_arc_position(Section *sec, Node *node)
static Member_ret_obj_func retobj_members[]
static double sh_show(void *v)
const char * expand_env_var(const char *s)
virtual Coord top() const
static void help(const char *)
double ivoc_gr_menu_action(void *v)
static void update(NrnThread *)
static double sh_save_name(void *v)
check_obj_type(o, "SectionList")
static double location(void *v)
double ivoc_gr_line(void *)
double nrniv_sh_color_all(void *)
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
Section * section() const
virtual void draw(Canvas *, const Allocation &) const
double * hoc_pgetarg(int narg)
const char * string() const
bool var_pair_chooser(const char *, float &x, float &y, Window *w=NULL, Coord x1=400., Coord y1=400.)
virtual void get_line(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static void * sh_cons(Object *ho)
double ivoc_gr_label(void *)
double nrniv_sh_nearest(void *)
void(* nrnpy_decref)(void *pyobj)=0
int const size_t const size_t n
static double sh_hinton(void *v)
void notify_pointer_disconnect(Observer *)
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
double ivoc_gr_gif(void *)
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
double ivoc_gr_mark(void *)
virtual Coord left() const
static double sh_unmap(void *v)
Object ** nrniv_sh_selected_seg(void *)
double nrniv_len_scale(void *)
static double sh_printfile(void *v)
static XYView * current_draw_view()
virtual bool has_iv_view()
void hoc_execerror(const char *, const char *)
void require_y(const Requirement &)
double nrniv_sh_color(void *)
void hoc_dec_refcount(Object **pobj)
static double sh_scale(void *v)
double ivoc_gr_menu_tool(void *)
double nrniv_sh_rotate(void *)
double nrniv_sh_observe(void *)
virtual void scale(float min, float max)
double nrn_section_orientation(Section *sec)
virtual void unref() const
ShapePlotData(Symbol *=NULL, Object *=NULL)
virtual void variable(Symbol *)
static void rect(Canvas *, Coord x1, Coord y1, Coord x2, Coord y2, const Color *c=NULL, const Brush *b=NULL, bool fill=false)
static double s_colormap(void *v)
Symlist * hoc_built_in_symlist
double(* nrnpy_object_to_double_)(Object *)
virtual const char * varname() const
static double sh_begin(void *v)
static void sh_destruct(void *v)
double ivoc_gr_erase(void *)
void require_x(const Requirement &)
#define TRY_GUI_REDIRECT_OBJ(name, obj)
virtual Object * neuron_section_list()
static ShapeScene * current_pick_scene()
void notify_when_freed(void *p, Observer *)
virtual void setColor(const Color *, ShapeScene *)
static int component(PyHocObject *po)
virtual void clear_variable()
Symbol * hoc_table_lookup(const char *, Symlist *)
static double sh_view(void *v)
virtual const String * selected() const
static double exec_menu(void *v)
static void text(Canvas *, const char *, const Transformer &, const Font *f=NULL, const Color *c=NULL)
double ivoc_gr_size(void *)
int hoc_is_object_arg(int narg)
double nrniv_sh_color_list(void *)
static XYView * current_pick_view()
int run(int argc, const char **argv)
double nrniv_sh_push(void *)
Object ** hoc_objgetarg(int)
virtual Coord right() const
static double sh_flush(void *v)
const Color * color(int) const
Node * node_exact(Section *sec, double x)
double chkarg(int, double low, double high)
static Member_func sh_members[]
virtual void set_range_variable(Symbol *)
virtual void observe(SectionList *=NULL)
void *(* nrnpy_get_pyobj)(Object *obj)=0