1 #include <../../nrnconf.h>
8 #include <InterViews/display.h>
9 #include <InterViews/session.h>
10 #include <InterViews/background.h>
11 #include <InterViews/style.h>
12 #include <InterViews/window.h>
13 #include <InterViews/tformsetter.h>
14 #include <InterViews/brush.h>
15 #include <InterViews/action.h>
16 #include <InterViews/color.h>
17 #include <InterViews/hit.h>
18 #include <InterViews/handler.h>
19 #include <InterViews/event.h>
20 #include <InterViews/telltale.h>
21 #include <InterViews/layout.h>
22 #include <IV-look/kit.h>
42 #define Shape_Section_ "Section PlotShape"
43 #define Shape_Rotate_ "Rotate3D PlotShape"
44 #define Shape_Style_ "ShapeStyle PlotShape"
57 static long beveljoin_ = 0;
62 class ShapeChangeObserver:
public Observer {
65 virtual ~ShapeChangeObserver();
78 static const Color* sec_sel_color() {
82 Display* dis = Session::instance()->default_display();
83 if (!dis->style()->find_attribute(
"section_select_color",
c) ||
92 static const Color* sec_adjacent_color() {
96 Display* dis = Session::instance()->default_display();
97 if (!dis->style()->find_attribute(
"section_adjacent_color",
c) ||
106 inline float norm(
float x,
float y) {
107 return (x * x + y * y);
114 PointMark(OcShape*,
Object*,
const Color*,
const char style =
'O',
float size = 8.);
115 virtual ~PointMark();
122 virtual void set_loc(
Section*,
float x);
123 bool everything_ok();
134 class OcShapeHandler;
139 virtual void select_section(
Section*);
140 virtual void handle_picked();
147 virtual void set_select_action(
const char*);
148 virtual void set_select_action(
Object*);
150 virtual PointMark* point_mark(
Object*,
152 const char style =
'O',
153 const float size = 8.);
154 virtual PointMark* point_mark(
Section*,
float x,
const Color*);
155 virtual void point_mark_remove(
Object* pp =
NULL);
163 OcShapeHandler* osh_;
165 bool show_adjacent_selection_;
170 OcShapeHandler(OcShape*);
171 virtual ~OcShapeHandler();
177 OcShapeHandler::OcShapeHandler(OcShape* s) {
180 OcShapeHandler::~OcShapeHandler() {}
181 bool OcShapeHandler::event(
Event&) {
195 OcShape* sh = (OcShape*)
v;
199 for (
i = 0;
i < 8; ++
i) {
237 ((OcShape*)
v)->select_section(
sec);
249 ((OcShape*)
v)->set_select_action(
gargstr(1));
285 if (s && s->
good()) {
287 d = ss->arc_selected();
302 ssec = ss->selected();
304 d = ss->arc_selected();
305 obj = (*nrnpy_seg_from_sec_x)(ssec->
section(), d);
320 ssec = ss->selected();
322 double d = ss->arc_selected();
323 obj = (*nrnpy_seg_from_sec_x)(ssec->
section(), d);
392 s->colorseg(
sec, x,
c);
431 OcShape* s = (OcShape*)
v;
439 style = char(
chkarg(3, 0, 127));
443 size = float(
chkarg(4, 1
e-9, 1e9));
459 OcShape* s = (OcShape*)
v;
463 s->point_mark_remove(
o);
485 s->shape_type(
int(
chkarg(1, 0., 2.)));
621 sh =
new OcShape(
sl);
651 point_mark_list_ =
NULL;
652 osh_ =
new OcShapeHandler(
this);
654 section_handler(osh_);
656 Display* dis = Session::instance()->default_display();
657 show_adjacent_selection_ = dis->style()->value_is_on(
"show_adjacent_selection");
659 OcShape::~OcShape() {
667 void OcShape::erase_all() {
669 point_mark_list_ =
NULL;
673 PointMark* OcShape::point_mark(
Object* ob,
const Color*
c,
const char style,
const float size) {
674 if (!point_mark_list_) {
677 PointMark*
g =
new PointMark(
this, ob,
c, style, size);
678 point_mark_list_->append(
g);
680 if (!
g->everything_ok()) {
681 point_mark_list_->remove(point_mark_list_->count() - 1);
689 if (!point_mark_list_) {
692 PointMark*
g =
new PointMark(
this,
NULL,
c);
694 point_mark_list_->append(
g);
696 if (!
g->everything_ok()) {
697 point_mark_list_->remove(point_mark_list_->count() - 1);
703 void OcShape::point_mark_remove(
Object*
o) {
704 if (point_mark_list_) {
707 for (
i =
cnt - 1;
i >= 0; --
i) {
708 PointMark*
g = (PointMark*) point_mark_list_->component(
i);
709 if (
g->object() ==
o) {
711 point_mark_list_->remove(
i);
716 while (point_mark_list_->count()) {
717 remove(glyph_index(point_mark_list_->component(0)));
718 point_mark_list_->remove(0);
724 void OcShape::set_select_action(
const char* s) {
731 void OcShape::set_select_action(
Object* pobj) {
746 if (show_adjacent_selection_) {
752 ss = shape_section(s);
762 c = sec_adjacent_color();
764 if (show_adjacent_selection_) {
770 ss = shape_section(s);
783 ss = shape_section(
sec);
792 void OcShape::handle_picked() {
794 if (!s1 || !s1->
good()) {
797 sel_color(sold_, s1);
812 void OcShape::save_phase1(ostream&
o) {
814 save_class(
o,
"Shape");
821 :
View((s->x1() + s->x2()) / 2,
822 (s->y1() + s->y2()) / 2,
823 Math::
max(s->x2() - s->x1(), s->y2() - s->y1()) * 1.1,
830 :
View(x[0], x[1], x[2], x[3], s, x[6], x[7]) {
831 Coord x1, y1, x2, y2;
832 zout(x1, y1, x2, y2);
833 size(x1, y1, x2, y2);
840 class ShapeType:
public Action {
843 virtual ~ShapeType();
849 ShapeType::ShapeType(
int st) {
852 ShapeType::~ShapeType() {}
871 while (
sg_->count()) {
875 sg_->remove(
sg_->count() - 1);
896 volatile_ptr_ref =
NULL;
911 new_size(-100, -100, 100, 100);
916 shape_changed_ =
NULL;
921 wk.style()->find_attribute(
"shape_beveljoin", beveljoin_);
927 section_handler_ =
NULL;
931 picker()->remove_item(
"Crosshair");
932 picker()->remove_item(
"Plot what?");
933 picker()->remove_item(
"Pick Vector");
934 picker()->remove_item(
"Color/Brush");
935 picker()->remove_item(
"Keep Lines");
936 picker()->remove_item(
"Family Label?");
937 picker()->remove_item(
"Erase");
938 picker()->remove_item(
"Remove");
942 m2->state()->set(TelltaleState::is_chosen,
true);
943 picker()->add_radio_menu(
"3D Rotate", r3b_, 0, ROTATE);
947 mi = wk.menu_item(
"Show Diam");
949 picker()->add_menu(
"Show Diam", mi, m);
950 mi = wk.menu_item(
"Centroid");
952 picker()->add_menu(
"Centroid", mi, m);
953 mi = wk.menu_item(
"Schematic");
955 picker()->add_menu(
"Schematic", mi, m);
956 mi = wk.menu_item(
"Shape Style");
958 picker()->add_menu(mi);
961 Coord x1, y1, x2, y2;
962 Coord xt1 = 0, yt1 = 0, xt2 = 0, yt2 = 0;
964 for (
i = 0;
i <
cnt; ++
i) {
973 color_value_ =
new ColorValue();
975 shape_changed_ =
new ShapeChangeObserver(
this);
997 volatile_ptr_ref =
NULL;
1012 volatile_ptr_ref =
NULL;
1044 for (
i = 0;
i <
n; ++
i) {
1058 long i,
j,
n =
sg_->count();
1062 for (
i = 0;
i <
n; ++
i) {
1110 double d1, d2;
int ntic;
1127 w->place(l +
e.pointer_root_x() -
e.pointer_x(), b +
e.pointer_root_y() -
e.pointer_y());
1155 for (
i = 0;
i <
cnt; ++
i) {
1171 if (
this != volatile_ptr_ref) {
1172 volatile_ptr_ref =
this;
1176 for (
i = 0;
i <
cnt; ++
i) {
1194 for (csec =
sec->child; csec; csec = csec->
sibling) {
1220 for (
i = 0;
i <
cnt; ++
i) {
1228 if (par_helper(ss->
section())) {
1239 if (ss && ss->
color() !=
c) {
1246 if (ss && ss->
color() !=
c) {
1253 for (
i = 0;
i <
cnt; ++
i) {
1268 for (
i = 0;
i <
cnt; ++
i) {
1286 w->
xplace(
int(x[4]),
int(x[5]));
1354 Coord x0, y0, xp, yp;
1382 logic_con =
sec->logical_connection;
1389 r[0] = logic_con->
x;
1390 r[1] = logic_con->
y;
1391 r[2] = logic_con->
z;
1399 for (
i = 0;
i <
n_; ++
i) {
1416 for (
i = 1;
i <
n_;
i++) {
1434 }
else if (a >= .999) {
1447 if (a <= sec_->pt3d[
i].arc) {
1451 float t1 = (a - a1) / (a2 - a1);
1452 x =
x_[
i] * t1 +
x_[
i - 1] * (1. - t1);
1453 y =
y_[
i] * t1 +
y_[
i - 1] * (1. - t1);
1471 if (
t->test(TelltaleState::is_enabled_active)) {
1474 }
else if (
t->test(TelltaleState::is_enabled)) {
1475 if (
color_ == sec_sel_color()) {
1543 for (
i = 0;
i <
n; ++
i) {
1558 for (
i = 0;
i <
n; ++
i) {
1567 for (
i = 0;
i <
n; ++
i) {
1605 printf(
"xmin_=%g a.left=%g ymin_=%g a.bottom=%g xmax_=%g a.right=%g\n",
1622 if (
sec->nnode == 2) {
1629 color = cv->no_value();
1641 }
else if (
sec->npt3d > 2) {
1667 for (iseg = 0; iseg <
sec->nnode - 1; ++iseg) {
1674 color = cv->no_value();
1681 xend = double(iseg + 1) * dseg;
1682 for (; i3d <
sec->npt3d; ++i3d) {
1685 if (a3dnew > xend) {
1686 frac = (a3dnew - xend) / dseg;
1711 for (
int iseg = 0; iseg <
sec->nnode - 1; ++iseg) {
1718 color = cv->no_value();
1743 float len, f1, f2, d, x1, x2, y1, y2, a, aa;
1750 if ((aa - a) < 1
e-5) {
1753 f1 = (a1 - a) / (aa - a);
1754 f2 = (a2 - a) / (aa - a);
1756 x1 = f1 * d +
x_[
i];
1757 x2 = f2 * d +
x_[
i];
1759 y1 = f1 * d +
y_[
i];
1760 y2 = f2 * d +
y_[
i];
1763 float d1, d2, t1, t2;
1766 d1 = f1 * (t2 - t1) + t1;
1767 d2 = f2 * (t2 - t1) + t1;
1793 float perp1[2], perp2[2], x, y;
1799 if (b && (perp1[0] != perp2[0] || perp1[1] != perp2[1])) {
1801 xt[0] = x + d * perp1[0];
1802 yt[0] = y + d * perp1[1];
1803 xt[1] = x - d * perp2[0];
1804 yt[1] = y - d * perp2[1];
1805 xt[2] = x - d * perp1[0];
1806 yt[2] = y - d * perp1[1];
1807 xt[3] = x + d * perp2[0];
1808 yt[3] = y + d * perp2[1];
1811 c->move_to(xt[0], yt[0]);
1812 for (
i = 1;
i < 4; ++
i) {
1813 c->line_to(xt[
i], yt[
i]);
1827 float darc = 1. / float(
sec_->
nnode - 1);
1829 float x = ds * iseg;
1836 float x1, x2, y1, y2;
1837 x1 = darc * iseg * (
x_[1] -
x_[0]) +
x_[0];
1838 x2 = darc * (iseg + 1) * (
x_[1] -
x_[0]) +
x_[0];
1839 y1 = darc * iseg * (
y_[1] -
y_[0]) +
y_[0];
1840 y2 = darc * (iseg + 1) * (
y_[1] -
y_[0]) +
y_[0];
1843 float d1, d2, t1, t2;
1846 d1 = darc * iseg * (t2 - t1) + t1;
1847 d2 = darc * (iseg + 1) * (t2 - t1) + t1;
1924 float x, y, rx, ry, d, norm;
1927 norm =
sqrt(x * x + y * y);
1938 c->move_to(x1 + rx * d, y1 + ry * d);
1939 c->line_to(x1 - rx * d, y1 - ry * d);
1941 c->line_to(x2 - rx * d, y2 - ry * d);
1942 c->line_to(x2 + rx * d, y2 + ry * d);
1948 xt[0] = x1 + rx * d;
1949 yt[0] = y1 + ry * d;
1950 xt[1] = x1 - rx * d;
1951 yt[1] = y1 - ry * d;
1953 xt[2] = x2 - rx * d;
1954 yt[2] = y2 - ry * d;
1955 xt[3] = x2 + rx * d;
1956 yt[3] = y2 + ry * d;
1962 if (x <= 0.0 || x >= 1.0) {
1992 if (!
good() || !h.event() || h.event()->type() != Event::down)
1995 Coord y = h.bottom();
2029 for (
int i = 1;
i <
n; ++
i) {
2047 for (
int i = 1;
i <
n; ++
i) {
2059 float darc, len, dlen1;
2060 for (
int i = 1;
i <
n; ++
i) {
2071 if (dlen1 <= d + 1
e-2) {
2073 }
else if (len <= d + 1
e-2) {
2076 darc =
sqrt(dlen1 - d);
2081 d = (d < 0.) ? 0. : d;
2082 d = (d > 1.) ? 1. : d;
2088 }
else if (d > 1. - dx / 4.) {
2091 d = (int(d * (
sec_->
nnode - 1)) + .5) * dx;
2100 for (
i = 0;
i <
n; ++
i) {
2101 if (arc < sec_->pt3d[
i].arc) {
2111 x =
x_[
i - 1] * (1 - frac) +
x_[
i] * frac;
2112 y =
y_[
i - 1] * (1 - frac) +
y_[
i] * frac;
2113 i = (
i > 0 && frac < .5) ?
i - 1 :
i;
2141 PointMark::PointMark(OcShape* sh,
Object* ob,
const Color*
c,
const char style,
const float size)
2153 PointMark::~PointMark() {
2168 sh_->point_mark_remove(ob);
2179 tv.inverse_transform(
x_,
y_, x, y);
2180 a.x_allotment().origin(x);
2181 a.y_allotment().origin(y);
2182 MonoGlyph::draw(
c, a);
2185 void PointMark::set_loc(
Section*
sec,
float x) {
2190 bool PointMark::everything_ok() {
2194 if (pnt && pnt->
sec) {
2199 if (!sec_ || !sec_->prop) {
2207 if (i_ >= sh_->count() || sh_->component(i_) != (
Glyph*)
this) {
2208 i_ = sh_->glyph_index(
this);
2212 sh_->move(i_,
x_,
y_);
2219 if (point_mark_list_) {
2221 for (
i = 0;
i <
cnt; ++
i) {
2222 ((PointMark*) point_mark_list_->component(
i))->
update(
NULL);
2227 ShapeChangeObserver::ShapeChangeObserver(
ShapeScene* s) {
2234 ShapeChangeObserver::~ShapeChangeObserver() {
2244 volatile_ptr_ref =
NULL;
2248 if (s_->view_all()) {
double nrn_section_orientation(Section *sec)
const char * secname(Section *sec)
void nrn_pushsec(Section *sec)
double nrn_arc_position(Section *sec, Node *node)
Section * nrn_trueparent(Section *sec)
double section_length(Section *sec)
double nrn_connection_position(Section *sec)
int nrn_exists(Symbol *s, Node *node)
int arc0at0(Section *sec)
double * nrn_rangepointer(Section *sec, Symbol *s, double d)
Section * chk_access(void)
const Brush * brush(int) const
const Color * color(int) const
void set(Canvas *, const Allocation &)
const Color * color() const
virtual GlyphIndex glyph_index(const Glyph *)
virtual void save_phase2(std::ostream &)
virtual void save_phase1(std::ostream &)
static HocMark * instance(char style, float size, const Color *, const Brush *)
static bool equal(float x, float y, float e)
static bool near_line_segment(Coord x, Coord y, Coord x1, Coord y1, Coord x2, Coord y2, float epsilon)
static float distance_to_line_segment(Coord x, Coord y, Coord x1, Coord y1, Coord x2, Coord y2)
static bool unit_normal(Coord x, Coord y, Coord *perp)
static void round_range(Coord x1, Coord x2, double &y1, double &y2, int &ntic)
static void box(Requisition &, Coord &x1, Coord &y1, Coord &x2, Coord &y2)
static float norm2(Coord x, Coord y)
static void Detach(Object *, Observer *)
static void Attach(Object *, Observer *)
virtual void disconnect(Observable *)
virtual void update(Observable *)
static void help(const char *)
void notify_detach(Observer *)
void notify_attach(Observer *)
static ostream * idraw_stream
static void polygon(Canvas *, int count, const Coord *x, const Coord *y, const Color *c=NULL, const Brush *b=NULL, bool fill=false)
void xplace(int left, int top)
void require(DimensionName, const Requirement &)
virtual void unref() const
void origin(float x, float y, float z)
void rotate(float x, float y, float z, float *tr) const
void rotate_x(float radians)
void rotate_z(float radians)
void rotate_y(float radians)
virtual bool event(Event &)
virtual void damage(GlyphIndex)
virtual void damage_all()
virtual void append(Glyph *)
virtual void new_size(Coord x1, Coord y1, Coord x2, Coord y2)
static const Color * default_foreground()
virtual void wholeplot(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual GlyphIndex count() const
virtual void remove(GlyphIndex)
virtual void modified(GlyphIndex)
virtual ~SectionHandler()
ShapeSection * shape_section()
virtual bool event(Event &)
void shape_section(ShapeSection *)
virtual void observe(SectionList *=NULL)
void colorseg(Section *, double, const Color *)
virtual float arc_selected()
ColorValue * color_value_
virtual SectionHandler * section_handler()
virtual float nearest(Coord, Coord)
SectionHandler * section_handler_
virtual ShapeSection * selected()
virtual void name(const char *)
virtual ShapeSection * shape_section(Section *)
virtual void wholeplot(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static ShapeScene * current_pick_scene()
virtual void save_phase2(std::ostream &)
virtual void transform3d(Rubberband *rb=NULL)
ShapeChangeObserver * shape_changed_
static ShapeScene * current_draw_scene()
virtual void section_handler(SectionHandler *)
ShapeScene(SectionList *=NULL)
ColorValue * color_value()
PolyGlyph * shape_section_list()
virtual void draw(Canvas *, const Allocation &) const
virtual void draw_seg(Canvas *, const Color *, int iseg) const
virtual void transform3d(Rotation3d *)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
int get_coord(double arc, Coord &, Coord &) const
virtual void size(Coord &l, Coord &b, Coord &r, Coord &t) const
void bevel_join(Canvas *, const Color *, int, float) const
float arc_position(Coord, Coord) const
virtual void request(Requisition &) const
void fastidious_draw(Canvas *, const Color *, int, float, float) const
float how_near(Coord, Coord) const
virtual void selectMenu()
virtual void clear_variable()
virtual void damage(ShapeScene *)
virtual bool near_section(Coord, Coord, Coord mineps) const
Section * section() const
virtual void allocate(Canvas *, const Allocation &, Extension &)
virtual void fast_draw(Canvas *, Coord x, Coord y, bool) const
virtual void setColorseg(const Color *, double, ShapeScene *)
virtual void draw_points(Canvas *, const Color *, int, int) const
void loc(double, Coord &, Coord &)
virtual void setColor(const Color *, ShapeScene *)
virtual void set_range_variable(Symbol *)
void trapezoid(Canvas *, const Color *, int i) const
const char * string() const
virtual Scene * scene() const
static XYView * current_draw_view()
static XYView * current_pick_view()
const Transformer & s2o() const
Point_process * ob2pntproc(Object *)
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 *)
int hoc_is_object_arg(int narg)
int hoc_is_str_arg(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)
#define TRY_GUI_REDIRECT_ACTUAL_OBJ(name, obj)
Object ** hoc_objgetarg(int)
static char line[MAXLINE]
Object ** hoc_temp_objptr(Object *)
#define ITERATE(itm, lst)
double * nrn_recalc_ptr(double *)
Point_process * ob2pntproc_0(Object *)
Object *(* nrnpy_seg_from_sec_x)(Section *, double)
void nrn_clear_mark(void)
short nrn_value_mark(Section *)
void section_ref(Section *)
void section_unref(Section *)
void nrn_seg_or_x_arg(int iarg, Section **psec, double *px)
short nrn_increment_mark(Section *)
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)
void hoc_ivbutton(CChar *name, CChar *action, Object *pyact=0)
void hoc_ivmenu(CChar *, bool add2menubar=false)
void hoc_ivpanel(CChar *, bool h=false)
static double remove(void *v)
static void pnode(Prop *)
#define implementRubberCallback(T)
#define RubberCallback(T)
#define declareRubberCallback(T)
check_obj_type(o, "SectionList")
static double sh_begin(void *v)
double nrniv_sh_color_list(void *v)
static double sh_select(void *v)
double nrniv_sh_color(void *v)
double ivoc_gr_menu_action(void *v)
double nrniv_sh_color_all(void *v)
static void sh_destruct(void *v)
static double sh_flush(void *v)
static double sh_view_count(void *v)
static double sh_select_action(void *v)
static double sh_save_name(void *v)
double(* nrnpy_object_to_double_)(Object *)
static double exec_menu(void *v)
double ivoc_gr_gif(void *)
static double sh_point_mark(void *v)
double ivoc_gr_mark(void *)
double ivoc_gr_menu_tool(void *)
double ivoc_gr_label(void *)
Object ** nrniv_sh_nearest_seg(void *v)
static double sh_printfile(void *v)
double nrniv_sh_nearest(void *v)
double nrniv_sh_rotate(void *v)
Object ** nrniv_sh_selected_seg(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_observe(void *v)
static Member_ret_obj_func retobj_members[]
static void * sh_cons(Object *ho)
static Member_func sh_members[]
static double sh_point_mark_remove(void *v)
double nrniv_sh_push(void *v)
double nrniv_len_scale(void *v)
static double sh_show(void *v)
double ivoc_gr_begin_line(void *)
struct Section * parentsec