2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-2002 Grace Development Team
9 * Maintained by Evgeny Stambulchik
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * track/edit points etc.
41 #include "core_utils.h"
46 static int track_setno
= -1;
47 static int track_add_at
; /* where to begin inserting points in the set */
48 static int track_move_dir
; /* direction on point movement */
50 static Widget points_frame
;
51 static ListStructure
*track_set_sel
;
52 static TextStructure
*locate_point_item
;
53 static Widget locate_point_message
;
54 static Widget goto_index_item
;
59 static void do_track_proc(void *data
)
61 set_action(DO_NOTHING
);
62 SetLabel(locate_point_message
, "Track points");
67 * activate the add point item in the canvas event proc
69 static void do_add_proc(void *data
)
73 set_action(DO_NOTHING
);
75 track_add_at
= (int) data
;
77 switch (track_add_at
) {
78 case ADD_POINT_BEGINNING
:
79 s
= "Add points at the beginning of set";
82 s
= "Add points to the end of set";
84 case ADD_POINT_NEAREST
:
85 s
= "Add points to the nearest position";
91 SetLabel(locate_point_message
, s
);
93 set_action(ADD_POINT
);
97 * activate the delete point item in the canvas event proc
99 static void do_del_proc(void *data
)
101 set_action(DO_NOTHING
);
102 SetLabel(locate_point_message
, "Delete points");
103 set_action(DEL_POINT
);
109 static void do_ptsmove_proc(void *data
)
113 set_action(DO_NOTHING
);
115 track_move_dir
= (int) data
;
117 switch (track_move_dir
) {
122 s
= "Move points along x";
125 s
= "Move points along y";
130 SetLabel(locate_point_message
, s
);
132 set_action(MOVE_POINT1ST
);
135 static void do_gotopt_proc(void *data
)
142 if (is_set_dataless(cg
, track_setno
)) {
143 errmsg("No or inactive set selected");
147 xv_evalexpri(goto_index_item
, &ind
);
148 if (get_point(cg
, track_setno
, ind
, &wp
) == RETURN_SUCCESS
) {
149 vp
= Wpoint2Vpoint(wp
);
152 errmsg("Point index out of range");
157 static void points_done_proc(void *data
)
159 set_action(DO_NOTHING
);
160 UnmanageChild(GetParent((Widget
) data
));
163 static void track_set_cbproc(int n
, int *values
, void *data
)
166 track_setno
= values
[0];
172 void create_points_frame(void *data
)
176 if (points_frame
== NULL
) {
177 Widget dialog
, wbut
, rc
, fr
;
179 points_frame
= CreateDialogForm(app_shell
, "Point explorer");
181 fr
= CreateFrame(points_frame
, NULL
);
182 AddDialogFormChild(points_frame
, fr
);
183 locate_point_message
= CreateLabel(fr
, "Point explorer");
185 dialog
= CreateVContainer(points_frame
);
186 AddDialogFormChild(points_frame
, dialog
);
188 track_set_sel
= CreateSetChoice(dialog
,
189 "Restrict to set:", LIST_TYPE_SINGLE
, TRUE
);
190 AddListChoiceCB(track_set_sel
, track_set_cbproc
, NULL
);
192 rc
= CreateHContainer(dialog
);
193 goto_index_item
= CreateTextItem2(rc
, 6, "Point location:");
194 wbut
= CreateButton(rc
, "Goto point");
195 AddButtonCB(wbut
, do_gotopt_proc
, NULL
);
197 locate_point_item
= CreateTextInput(dialog
, "Point data:");
199 CreateSeparator(dialog
);
201 rc
= CreateHContainer(dialog
);
203 wbut
= CreateButton(rc
, "Track");
204 AddButtonCB(wbut
, do_track_proc
, NULL
);
206 wbut
= CreateButton(rc
, "Move");
207 AddButtonCB(wbut
, do_ptsmove_proc
, (void *) MOVE_POINT_XY
);
208 wbut
= CreateButton(rc
, "Move X");
209 AddButtonCB(wbut
, do_ptsmove_proc
, (void *) MOVE_POINT_X
);
210 wbut
= CreateButton(rc
, "Move Y");
211 AddButtonCB(wbut
, do_ptsmove_proc
, (void *) MOVE_POINT_Y
);
213 wbut
= CreateButton(rc
, "Prepend");
214 AddButtonCB(wbut
, do_add_proc
, (void *) ADD_POINT_BEGINNING
);
215 wbut
= CreateButton(rc
, "Append");
216 AddButtonCB(wbut
, do_add_proc
, (void *) ADD_POINT_END
);
217 wbut
= CreateButton(rc
, "Insert");
218 AddButtonCB(wbut
, do_add_proc
, (void *) ADD_POINT_NEAREST
);
220 wbut
= CreateButton(rc
, "Delete");
221 AddButtonCB(wbut
, do_del_proc
, NULL
);
223 wbut
= CreateButton(rc
, "Close");
224 AddButtonCB(wbut
, points_done_proc
, (void *) points_frame
);
226 ManageChild(points_frame
);
229 RaiseWindow(GetParent(points_frame
));
233 void update_point_locator(int gno
, int setno
, int loc
)
239 if (points_frame
== NULL
) {
243 if (get_datapoint(gno
, setno
, loc
, &ncols
, &dpoint
) == RETURN_SUCCESS
) {
244 SelectListChoice(track_set_sel
, setno
);
246 s
= copy_string(NULL
, "(");
247 for (col
= 0; col
< ncols
; col
++) {
248 sprintf(buf
, "%g", dpoint
.ex
[col
]);
249 s
= concat_strings(s
, buf
);
250 if (col
!= ncols
- 1) {
251 s
= concat_strings(s
, ", ");
254 if (dpoint
.s
!= NULL
) {
255 s
= concat_strings(s
, ", \"");
256 s
= concat_strings(s
, dpoint
.s
);
257 s
= concat_strings(s
, "\"");
259 s
= concat_strings(s
, ")");
260 SetTextString(locate_point_item
, s
);
263 sprintf(buf
, "%d", loc
);
264 xv_setstr(goto_index_item
, buf
);
267 SelectListChoices(track_set_sel
, 0, NULL
);
268 SetTextString(locate_point_item
, "");
269 xv_setstr(goto_index_item
, "");
273 void get_tracking_props(int *setno
, int *move_dir
, int *add_at
)
275 *setno
= track_setno
;
276 *move_dir
= track_move_dir
;
277 *add_at
= track_add_at
;