BRL-CAD
adc.c
Go to the documentation of this file.
1 /* A D C . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1985-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/adc.c
21  *
22  */
23 
24 #include "common.h"
25 
26 #include <stdlib.h>
27 #include <math.h>
28 #include <string.h>
29 
30 
31 #include "vmath.h"
32 #include "ged.h"
33 
34 static void
35 adc_vls_print(struct bview *gvp, fastf_t base2local, struct bu_vls *out_vp)
36 {
37  bu_vls_printf(out_vp, "draw = %d\n", gvp->gv_adc.draw);
38  bu_vls_printf(out_vp, "a1 = %.15e\n", gvp->gv_adc.a1);
39  bu_vls_printf(out_vp, "a2 = %.15e\n", gvp->gv_adc.a2);
40  bu_vls_printf(out_vp, "dst = %.15e\n", gvp->gv_adc.dst * gvp->gv_scale * base2local);
41  bu_vls_printf(out_vp, "odst = %d\n", gvp->gv_adc.dv_dist);
42  bu_vls_printf(out_vp, "hv = %.15e %.15e\n",
43  gvp->gv_adc.pos_grid[X] * gvp->gv_scale * base2local,
44  gvp->gv_adc.pos_grid[Y] * gvp->gv_scale * base2local);
45  bu_vls_printf(out_vp, "xyz = %.15e %.15e %.15e\n",
46  gvp->gv_adc.pos_model[X] * base2local,
47  gvp->gv_adc.pos_model[Y] * base2local,
48  gvp->gv_adc.pos_model[Z] * base2local);
49  bu_vls_printf(out_vp, "x = %d\n", gvp->gv_adc.dv_x);
50  bu_vls_printf(out_vp, "y = %d\n", gvp->gv_adc.dv_y);
51  bu_vls_printf(out_vp, "anchor_pos = %d\n", gvp->gv_adc.anchor_pos);
52  bu_vls_printf(out_vp, "anchor_a1 = %d\n", gvp->gv_adc.anchor_a1);
53  bu_vls_printf(out_vp, "anchor_a2 = %d\n", gvp->gv_adc.anchor_a2);
54  bu_vls_printf(out_vp, "anchor_dst = %d\n", gvp->gv_adc.anchor_dst);
55  bu_vls_printf(out_vp, "anchorpoint_a1 = %.15e %.15e %.15e\n",
56  gvp->gv_adc.anchor_pt_a1[X] * base2local,
57  gvp->gv_adc.anchor_pt_a1[Y] * base2local,
58  gvp->gv_adc.anchor_pt_a1[Z] * base2local);
59  bu_vls_printf(out_vp, "anchorpoint_a2 = %.15e %.15e %.15e\n",
60  gvp->gv_adc.anchor_pt_a2[X] * base2local,
61  gvp->gv_adc.anchor_pt_a2[Y] * base2local,
62  gvp->gv_adc.anchor_pt_a2[Z] * base2local);
63  bu_vls_printf(out_vp, "anchorpoint_dst = %.15e %.15e %.15e\n",
64  gvp->gv_adc.anchor_pt_dst[X] * base2local,
65  gvp->gv_adc.anchor_pt_dst[Y] * base2local,
66  gvp->gv_adc.anchor_pt_dst[Z] * base2local);
67 }
68 
69 
70 HIDDEN void
71 adc_usage(struct bu_vls *vp, const char *name)
72 {
73  bu_vls_printf(vp, "Usage: %s \n", name);
74  bu_vls_printf(vp, "%s", " adc vname toggle display of angle/distance cursor\n");
75  bu_vls_printf(vp, "%s", " adc vname vars print a list of all variables (i.e. var = val)\n");
76  bu_vls_printf(vp, "%s", " adc vname draw [0|1] set or get the draw parameter\n");
77  bu_vls_printf(vp, "%s", " adc vname a1 [#] set or get angle1\n");
78  bu_vls_printf(vp, "%s", " adc vname a2 [#] set or get angle2\n");
79  bu_vls_printf(vp, "%s", " adc vname dst [#] set or get radius (distance) of tick\n");
80  bu_vls_printf(vp, "%s", " adc vname odst [#] set or get radius (distance) of tick (+-2047)\n");
81  bu_vls_printf(vp, "%s", " adc vname hv [# #] set or get position (grid coordinates)\n");
82  bu_vls_printf(vp, "%s", " adc vname xyz [# # #] set or get position (model coordinates)\n");
83  bu_vls_printf(vp, "%s", " adc vname x [#] set or get horizontal position (+-2047)\n");
84  bu_vls_printf(vp, "%s", " adc vname y [#] set or get vertical position (+-2047)\n");
85  bu_vls_printf(vp, "%s", " adc vname dh # add to horizontal position (grid coordinates)\n");
86  bu_vls_printf(vp, "%s", " adc vname dv # add to vertical position (grid coordinates)\n");
87  bu_vls_printf(vp, "%s", " adc vname dx # add to X position (model coordinates)\n");
88  bu_vls_printf(vp, "%s", " adc vname dy # add to Y position (model coordinates)\n");
89  bu_vls_printf(vp, "%s", " adc vname dz # add to Z position (model coordinates)\n");
90  bu_vls_printf(vp, "%s", " adc vname anchor_pos [0|1] anchor ADC to current position in model coordinates\n");
91  bu_vls_printf(vp, "%s", " adc vname anchor_a1 [0|1] anchor angle1 to go through anchorpoint_a1\n");
92  bu_vls_printf(vp, "%s", " adc vname anchor_a2 [0|1] anchor angle2 to go through anchorpoint_a2\n");
93  bu_vls_printf(vp, "%s", " adc vname anchor_dst [0|1] anchor tick distance to go through anchorpoint_dst\n");
94  bu_vls_printf(vp, "%s", " adc vname anchorpoint_a1 [# # #] set or get anchor point for angle1\n");
95  bu_vls_printf(vp, "%s", " adc vname anchorpoint_a2 [# # #] set or get anchor point for angle2\n");
96  bu_vls_printf(vp, "%s", " adc vname anchorpoint_dst [# # #] set or get anchor point for tick distance\n");
97  bu_vls_printf(vp, "%s", " adc vname -i any of the above appropriate commands will interpret parameters as increments\n");
98  bu_vls_printf(vp, "%s", " adc vname reset reset angles, location, and tick distance\n");
99  bu_vls_printf(vp, "%s", " adc vname help prints this help message\n");
100 }
101 
102 
103 /*
104  * Note - this needs to be rewritten to accept keyword/value pairs so
105  * that multiple attributes can be set with a single command call.
106  */
107 int
108 ged_adc(struct ged *gedp,
109  int argc,
110  const char *argv[])
111 {
112  char *command;
113  char *parameter;
114  char **argp = (char **)argv;
115  double scanval;
116  point_t user_pt; /* Value(s) provided by user */
117  point_t scaled_pos;
118  int incr_flag;
119  int i;
120 
122  GED_CHECK_VIEW(gedp, GED_ERROR);
123  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
124 
125  /* initialize result */
126  bu_vls_trunc(gedp->ged_result_str, 0);
127 
128  if (argc < 2 || 6 < argc) {
129  adc_usage(gedp->ged_result_str, argv[0]);
130  return GED_ERROR;
131  }
132 
133  command = (char *)argv[0];
134 
135  if (BU_STR_EQUAL(argv[1], "-i")) {
136  if (argc < 5) {
137  bu_vls_printf(gedp->ged_result_str, "%s: -i option specified without an op-val pair", command);
138  return GED_ERROR;
139  }
140 
141  incr_flag = 1;
142  parameter = (char *)argv[2];
143  argc -= 3;
144  argp += 3;
145  } else {
146  incr_flag = 0;
147  parameter = (char *)argv[1];
148  argc -= 2;
149  argp += 2;
150  }
151 
152  for (i = 0; i < argc; ++i) {
153  if (sscanf(argp[i], "%lf", &scanval) != 1) {
154  adc_usage(gedp->ged_result_str, command);
155  return GED_ERROR;
156  }
157  user_pt[i] = scanval;
158  }
159 
160  if (BU_STR_EQUAL(parameter, "draw")) {
161  if (argc == 0) {
162  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.draw);
163  return GED_OK;
164  } else if (argc == 1) {
165  i = (int)user_pt[X];
166 
167  if (i)
168  gedp->ged_gvp->gv_adc.draw = 1;
169  else
170  gedp->ged_gvp->gv_adc.draw = 0;
171 
172  return GED_OK;
173  }
174 
175  bu_vls_printf(gedp->ged_result_str, "The '%s draw' command accepts 0 or 1 argument\n", command);
176  return GED_ERROR;
177  }
178 
179  if (BU_STR_EQUAL(parameter, "a1")) {
180  if (argc == 0) {
181  bu_vls_printf(gedp->ged_result_str, "%g", gedp->ged_gvp->gv_adc.a1);
182  return GED_OK;
183  } else if (argc == 1) {
184  if (!gedp->ged_gvp->gv_adc.anchor_a1) {
185  if (incr_flag)
186  gedp->ged_gvp->gv_adc.a1 += user_pt[0];
187  else
188  gedp->ged_gvp->gv_adc.a1 = user_pt[0];
189 
190  gedp->ged_gvp->gv_adc.dv_a1 = (1.0 - (gedp->ged_gvp->gv_adc.a1 / 45.0)) * GED_MAX;
191  }
192 
193  return GED_OK;
194  }
195 
196  bu_vls_printf(gedp->ged_result_str, "The '%s a1' command accepts only 1 argument\n", command);
197  return GED_ERROR;
198  }
199 
200  if (BU_STR_EQUAL(parameter, "a2")) {
201  if (argc == 0) {
202  bu_vls_printf(gedp->ged_result_str, "%g", gedp->ged_gvp->gv_adc.a2);
203  return GED_OK;
204  } else if (argc == 1) {
205  if (!gedp->ged_gvp->gv_adc.anchor_a2) {
206  if (incr_flag)
207  gedp->ged_gvp->gv_adc.a2 += user_pt[0];
208  else
209  gedp->ged_gvp->gv_adc.a2 = user_pt[0];
210 
211  gedp->ged_gvp->gv_adc.dv_a2 = (1.0 - (gedp->ged_gvp->gv_adc.a2 / 45.0)) * GED_MAX;
212  }
213 
214  return GED_OK;
215  }
216 
217  bu_vls_printf(gedp->ged_result_str, "The '%s a2' command accepts only 1 argument\n", command);
218  return GED_ERROR;
219  }
220 
221  if (BU_STR_EQUAL(parameter, "dst")) {
222  if (argc == 0) {
223  bu_vls_printf(gedp->ged_result_str, "%g", gedp->ged_gvp->gv_adc.dst * gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
224  return GED_OK;
225  } else if (argc == 1) {
226  if (!gedp->ged_gvp->gv_adc.anchor_dst) {
227  if (incr_flag)
228  gedp->ged_gvp->gv_adc.dst += user_pt[0] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
229  else
230  gedp->ged_gvp->gv_adc.dst = user_pt[0] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
231 
232  gedp->ged_gvp->gv_adc.dv_dist = (gedp->ged_gvp->gv_adc.dst / M_SQRT1_2 - 1.0) * GED_MAX;
233  }
234 
235  return GED_OK;
236  }
237 
238  bu_vls_printf(gedp->ged_result_str, "The '%s dst' command accepts 0 or 1 argument\n", command);
239  return GED_ERROR;
240  }
241 
242  if (BU_STR_EQUAL(parameter, "odst")) {
243  if (argc == 0) {
244  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.dv_dist);
245  return GED_OK;
246  } else if (argc == 1) {
247  if (!gedp->ged_gvp->gv_adc.anchor_dst) {
248  if (incr_flag)
249  gedp->ged_gvp->gv_adc.dv_dist += user_pt[0];
250  else
251  gedp->ged_gvp->gv_adc.dv_dist = user_pt[0];
252 
253  gedp->ged_gvp->gv_adc.dst = (gedp->ged_gvp->gv_adc.dv_dist * INV_GED + 1.0) * M_SQRT1_2;
254  }
255 
256  return GED_OK;
257  }
258 
259  bu_vls_printf(gedp->ged_result_str, "The '%s odst' command accepts 0 or 1 argument\n", command);
260  return GED_ERROR;
261  }
262 
263  if (BU_STR_EQUAL(parameter, "dh")) {
264  if (argc == 1) {
265  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
266  gedp->ged_gvp->gv_adc.pos_grid[X] += user_pt[0] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
268  MAT4X3PNT(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_view2model, gedp->ged_gvp->gv_adc.pos_view);
269  }
270 
271  return GED_OK;
272  }
273 
274  bu_vls_printf(gedp->ged_result_str, "The '%s dh' command requires 1 argument\n", command);
275  return GED_ERROR;
276  }
277 
278  if (BU_STR_EQUAL(parameter, "dv")) {
279  if (argc == 1) {
280  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
281  gedp->ged_gvp->gv_adc.pos_grid[Y] += user_pt[0] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
283  MAT4X3PNT(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_view2model, gedp->ged_gvp->gv_adc.pos_view);
284  }
285 
286  return GED_OK;
287  }
288 
289  bu_vls_printf(gedp->ged_result_str, "The '%s dv' command requires 1 argument\n", command);
290  return GED_ERROR;
291  }
292 
293  if (BU_STR_EQUAL(parameter, "hv")) {
294  if (argc == 0) {
295  bu_vls_printf(gedp->ged_result_str, "%g %g",
296  gedp->ged_gvp->gv_adc.pos_grid[X] * gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local,
297  gedp->ged_gvp->gv_adc.pos_grid[Y] * gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
298  return GED_OK;
299  } else if (argc == 2) {
300  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
301  if (incr_flag) {
302  gedp->ged_gvp->gv_adc.pos_grid[X] += user_pt[X] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
303  gedp->ged_gvp->gv_adc.pos_grid[Y] += user_pt[Y] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
304  } else {
305  gedp->ged_gvp->gv_adc.pos_grid[X] = user_pt[X] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
306  gedp->ged_gvp->gv_adc.pos_grid[Y] = user_pt[Y] / (gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local);
307  }
308 
309  gedp->ged_gvp->gv_adc.pos_grid[Z] = 0.0;
311  MAT4X3PNT(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_view2model, gedp->ged_gvp->gv_adc.pos_model);
312  }
313 
314  return GED_OK;
315  }
316 
317  bu_vls_printf(gedp->ged_result_str, "The '%s hv' command requires 0 or 2 arguments\n", command);
318  return GED_ERROR;
319  }
320 
321  if (BU_STR_EQUAL(parameter, "dx")) {
322  if (argc == 1) {
323  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
324  gedp->ged_gvp->gv_adc.pos_model[X] += user_pt[0] * gedp->ged_wdbp->dbip->dbi_local2base;
327  }
328 
329  return GED_OK;
330  }
331 
332  bu_vls_printf(gedp->ged_result_str, "The '%s dx' command requires 1 argument\n", command);
333  return GED_ERROR;
334  }
335 
336  if (BU_STR_EQUAL(parameter, "dy")) {
337  if (argc == 1) {
338  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
339  gedp->ged_gvp->gv_adc.pos_model[Y] += user_pt[0] * gedp->ged_wdbp->dbip->dbi_local2base;
342  }
343 
344  return GED_OK;
345  }
346 
347  bu_vls_printf(gedp->ged_result_str, "The '%s dy' command requires 1 argument\n", command);
348  return GED_ERROR;
349  }
350 
351  if (BU_STR_EQUAL(parameter, "dz")) {
352  if (argc == 1) {
353  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
354  gedp->ged_gvp->gv_adc.pos_model[Z] += user_pt[0] * gedp->ged_wdbp->dbip->dbi_local2base;
357  }
358 
359  return GED_OK;
360  }
361 
362  bu_vls_printf(gedp->ged_result_str, "The '%s dz' command requires 1 argument\n", command);
363  return GED_ERROR;
364  }
365 
366  if (BU_STR_EQUAL(parameter, "xyz")) {
367  if (argc == 0) {
368  VSCALE(scaled_pos, gedp->ged_gvp->gv_adc.pos_model, gedp->ged_wdbp->dbip->dbi_base2local);
369  bu_vls_printf(gedp->ged_result_str, "%g %g %g", V3ARGS(scaled_pos));
370  return GED_OK;
371  } else if (argc == 3) {
372  VSCALE(user_pt, user_pt, gedp->ged_wdbp->dbip->dbi_local2base);
373 
374  if (incr_flag) {
375  VADD2(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_adc.pos_model, user_pt);
376  } else {
377  VMOVE(gedp->ged_gvp->gv_adc.pos_model, user_pt);
378  }
379 
382 
383  return GED_OK;
384  }
385 
386  bu_vls_printf(gedp->ged_result_str, "The '%s xyz' command requires 0 or 3 arguments\n", command);
387  return GED_ERROR;
388  }
389 
390  if (BU_STR_EQUAL(parameter, "x")) {
391  if (argc == 0) {
392  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.dv_x);
393  return GED_OK;
394  } else if (argc == 1) {
395  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
396  if (incr_flag) {
397  gedp->ged_gvp->gv_adc.dv_x += user_pt[0];
398  } else {
399  gedp->ged_gvp->gv_adc.dv_x = user_pt[0];
400  }
401 
402  gedp->ged_gvp->gv_adc.pos_view[X] = gedp->ged_gvp->gv_adc.dv_x * INV_GED;
403  gedp->ged_gvp->gv_adc.pos_view[Y] = gedp->ged_gvp->gv_adc.dv_y * INV_GED;
405  MAT4X3PNT(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_view2model, gedp->ged_gvp->gv_adc.pos_view);
406  }
407 
408  return GED_OK;
409  }
410 
411  bu_vls_printf(gedp->ged_result_str, "The '%s x' command requires 0 or 1 argument\n", command);
412  return GED_ERROR;
413  }
414 
415  if (BU_STR_EQUAL(parameter, "y")) {
416  if (argc == 0) {
417  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.dv_y);
418  return GED_OK;
419  } else if (argc == 1) {
420  if (!gedp->ged_gvp->gv_adc.anchor_pos) {
421  if (incr_flag) {
422  gedp->ged_gvp->gv_adc.dv_y += user_pt[0];
423  } else {
424  gedp->ged_gvp->gv_adc.dv_y = user_pt[0];
425  }
426 
427  gedp->ged_gvp->gv_adc.pos_view[X] = gedp->ged_gvp->gv_adc.dv_x * INV_GED;
428  gedp->ged_gvp->gv_adc.pos_view[Y] = gedp->ged_gvp->gv_adc.dv_y * INV_GED;
430  MAT4X3PNT(gedp->ged_gvp->gv_adc.pos_model, gedp->ged_gvp->gv_view2model, gedp->ged_gvp->gv_adc.pos_view);
431  }
432 
433  return GED_OK;
434  }
435 
436  bu_vls_printf(gedp->ged_result_str, "The '%s y' command requires 0 or 1 argument\n", command);
437  return GED_ERROR;
438  }
439 
440  if (BU_STR_EQUAL(parameter, "anchor_pos")) {
441  if (argc == 0) {
443  return GED_OK;
444  } else if (argc == 1) {
445  i = (int)user_pt[X];
446 
447  if (i < 0 || 2 < i) {
448  bu_vls_printf(gedp->ged_result_str, "The '%d anchor_pos' parameter accepts values of 0, 1, or 2.", i);
449  return GED_ERROR;
450  }
451 
452  gedp->ged_gvp->gv_adc.anchor_pos = i;
453  ged_calc_adc_pos(gedp->ged_gvp);
454 
455  return GED_OK;
456  }
457 
458  bu_vls_printf(gedp->ged_result_str, "The '%s anchor_pos' command accepts 0 or 1 argument\n", command);
459  return GED_ERROR;
460  }
461 
462  if (BU_STR_EQUAL(parameter, "anchor_a1")) {
463  if (argc == 0) {
464  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.anchor_a1);
465  return GED_OK;
466  } else if (argc == 1) {
467  i = (int)user_pt[X];
468 
469  if (i)
470  gedp->ged_gvp->gv_adc.anchor_a1 = 1;
471  else
472  gedp->ged_gvp->gv_adc.anchor_a1 = 0;
473 
474  ged_calc_adc_a1(gedp->ged_gvp);
475 
476  return GED_OK;
477  }
478 
479  bu_vls_printf(gedp->ged_result_str, "The '%s anchor_a1' command accepts 0 or 1 argument\n", command);
480  return GED_ERROR;
481  }
482 
483  if (BU_STR_EQUAL(parameter, "anchorpoint_a1")) {
484  if (argc == 0) {
485  VSCALE(scaled_pos, gedp->ged_gvp->gv_adc.anchor_pt_a1, gedp->ged_wdbp->dbip->dbi_base2local);
486  bu_vls_printf(gedp->ged_result_str, "%g %g %g", V3ARGS(scaled_pos));
487 
488  return GED_OK;
489  } else if (argc == 3) {
490  VSCALE(user_pt, user_pt, gedp->ged_wdbp->dbip->dbi_local2base);
491 
492  if (incr_flag) {
493  VADD2(gedp->ged_gvp->gv_adc.anchor_pt_a1, gedp->ged_gvp->gv_adc.anchor_pt_a1, user_pt);
494  } else {
495  VMOVE(gedp->ged_gvp->gv_adc.anchor_pt_a1, user_pt);
496  }
497 
498  ged_calc_adc_a1(gedp->ged_gvp);
499 
500  return GED_OK;
501  }
502 
503  bu_vls_printf(gedp->ged_result_str, "The '%s anchorpoint_a1' command accepts 0 or 3 arguments\n", command);
504  return GED_ERROR;
505  }
506 
507  if (BU_STR_EQUAL(parameter, "anchor_a2")) {
508  if (argc == 0) {
509  bu_vls_printf(gedp->ged_result_str, "%d", gedp->ged_gvp->gv_adc.anchor_a2);
510 
511  return GED_OK;
512  } else if (argc == 1) {
513  i = (int)user_pt[X];
514 
515  if (i)
516  gedp->ged_gvp->gv_adc.anchor_a2 = 1;
517  else
518  gedp->ged_gvp->gv_adc.anchor_a2 = 0;
519 
520  ged_calc_adc_a2(gedp->ged_gvp);
521 
522  return GED_OK;
523  }
524 
525  bu_vls_printf(gedp->ged_result_str, "The '%s anchor_a2' command accepts 0 or 1 argument\n", command);
526  return GED_ERROR;
527  }
528 
529  if (BU_STR_EQUAL(parameter, "anchorpoint_a2")) {
530  if (argc == 0) {
531  VSCALE(scaled_pos, gedp->ged_gvp->gv_adc.anchor_pt_a2, gedp->ged_wdbp->dbip->dbi_base2local);
532 
533  bu_vls_printf(gedp->ged_result_str, "%g %g %g", V3ARGS(scaled_pos));
534 
535  return GED_OK;
536  } else if (argc == 3) {
537  VSCALE(user_pt, user_pt, gedp->ged_wdbp->dbip->dbi_local2base);
538 
539  if (incr_flag) {
540  VADD2(gedp->ged_gvp->gv_adc.anchor_pt_a2, gedp->ged_gvp->gv_adc.anchor_pt_a2, user_pt);
541  } else {
542  VMOVE(gedp->ged_gvp->gv_adc.anchor_pt_a2, user_pt);
543  }
544 
545  ged_calc_adc_a2(gedp->ged_gvp);
546 
547  return GED_OK;
548  }
549 
550  bu_vls_printf(gedp->ged_result_str, "The '%s anchorpoint_a2' command accepts 0 or 3 arguments\n", command);
551  return GED_ERROR;
552  }
553 
554  if (BU_STR_EQUAL(parameter, "anchor_dst")) {
555  if (argc == 0) {
557 
558  return GED_OK;
559  } else if (argc == 1) {
560  i = (int)user_pt[X];
561 
562  if (i) {
563  gedp->ged_gvp->gv_adc.anchor_dst = 1;
564  } else
565  gedp->ged_gvp->gv_adc.anchor_dst = 0;
566 
567  ged_calc_adc_dst(gedp->ged_gvp);
568 
569  return GED_OK;
570  }
571 
572  bu_vls_printf(gedp->ged_result_str, "The '%s anchor_dst' command accepts 0 or 1 argument\n", command);
573  return GED_ERROR;
574  }
575 
576  if (BU_STR_EQUAL(parameter, "anchorpoint_dst")) {
577  if (argc == 0) {
578  VSCALE(scaled_pos, gedp->ged_gvp->gv_adc.anchor_pt_dst, gedp->ged_wdbp->dbip->dbi_base2local);
579  bu_vls_printf(gedp->ged_result_str, "%g %g %g", V3ARGS(scaled_pos));
580 
581  return GED_OK;
582  } else if (argc == 3) {
583  VSCALE(user_pt, user_pt, gedp->ged_wdbp->dbip->dbi_local2base);
584 
585  if (incr_flag) {
586  VADD2(gedp->ged_gvp->gv_adc.anchor_pt_dst, gedp->ged_gvp->gv_adc.anchor_pt_dst, user_pt);
587  } else {
588  VMOVE(gedp->ged_gvp->gv_adc.anchor_pt_dst, user_pt);
589  }
590 
591  ged_calc_adc_dst(gedp->ged_gvp);
592 
593  return GED_OK;
594  }
595 
596  bu_vls_printf(gedp->ged_result_str, "The '%s anchorpoint_dst' command accepts 0 or 3 arguments\n", command);
597  return GED_ERROR;
598  }
599 
600  if (BU_STR_EQUAL(parameter, "reset")) {
601  if (argc == 0) {
603 
604  return GED_OK;
605  }
606 
607  bu_vls_printf(gedp->ged_result_str, "The '%s reset' command accepts no arguments\n", command);
608  return GED_ERROR;
609  }
610 
611  if (BU_STR_EQUAL(parameter, "vars")) {
612  adc_vls_print(gedp->ged_gvp, gedp->ged_wdbp->dbip->dbi_base2local, gedp->ged_result_str);
613  return GED_OK;
614  }
615 
616  if (BU_STR_EQUAL(parameter, "help")) {
617  adc_usage(gedp->ged_result_str, command);
618  return GED_HELP;
619  }
620 
621  bu_vls_printf(gedp->ged_result_str, "%s: unrecognized command '%s'\n", command, parameter);
622  adc_usage(gedp->ged_result_str, command);
623 
624  return GED_ERROR;
625 }
626 
627 
628 void
630 {
631  if (gvp->gv_adc.anchor_pos == 1) {
634  } else if (gvp->gv_adc.anchor_pos == 2) {
636  MAT4X3PNT(gvp->gv_adc.pos_model, gvp->gv_view2model, gvp->gv_adc.pos_view);
637  } else {
639  MAT4X3PNT(gvp->gv_adc.pos_model, gvp->gv_view2model, gvp->gv_adc.pos_view);
640  }
641 }
642 
643 
644 void
645 ged_calc_adc_a1(struct bview *gvp)
646 {
647  if (gvp->gv_adc.anchor_a1) {
648  fastf_t dx, dy;
649  point_t view_pt;
650 
651  MAT4X3PNT(view_pt, gvp->gv_model2view, gvp->gv_adc.anchor_pt_a1);
652  dx = view_pt[X] * GED_MAX - gvp->gv_adc.dv_x;
653  dy = view_pt[Y] * GED_MAX - gvp->gv_adc.dv_y;
654 
655  if (!ZERO(dx) || !ZERO(dy)) {
656  gvp->gv_adc.a1 = RAD2DEG*atan2(dy, dx);
657  gvp->gv_adc.dv_a1 = (1.0 - (gvp->gv_adc.a1 / 45.0)) * GED_MAX;
658  }
659  }
660 }
661 
662 
663 void
664 ged_calc_adc_a2(struct bview *gvp)
665 {
666  if (gvp->gv_adc.anchor_a2) {
667  fastf_t dx, dy;
668  point_t view_pt;
669 
670  MAT4X3PNT(view_pt, gvp->gv_model2view, gvp->gv_adc.anchor_pt_a2);
671  dx = view_pt[X] * GED_MAX - gvp->gv_adc.dv_x;
672  dy = view_pt[Y] * GED_MAX - gvp->gv_adc.dv_y;
673 
674  if (!ZERO(dx) || !ZERO(dy)) {
675  gvp->gv_adc.a2 = RAD2DEG*atan2(dy, dx);
676  gvp->gv_adc.dv_a2 = (1.0 - (gvp->gv_adc.a2 / 45.0)) * GED_MAX;
677  }
678  }
679 }
680 
681 
682 void
684 {
685  if (gvp->gv_adc.anchor_dst) {
686  fastf_t dist;
687  fastf_t dx, dy;
688  point_t view_pt;
689 
690  MAT4X3PNT(view_pt, gvp->gv_model2view, gvp->gv_adc.anchor_pt_dst);
691 
692  dx = view_pt[X] * GED_MAX - gvp->gv_adc.dv_x;
693  dy = view_pt[Y] * GED_MAX - gvp->gv_adc.dv_y;
694  dist = sqrt(dx * dx + dy * dy);
695  gvp->gv_adc.dst = dist * INV_GED;
696  gvp->gv_adc.dv_dist = (dist / M_SQRT1_2) - GED_MAX;
697  } else
698  gvp->gv_adc.dst = (gvp->gv_adc.dv_dist * INV_GED + 1.0) * M_SQRT1_2;
699 }
700 
701 
702 /*
703  * Local Variables:
704  * mode: C
705  * tab-width: 8
706  * indent-tabs-mode: t
707  * c-file-style: "stroustrup"
708  * End:
709  * ex: shiftwidth=4 tabstop=8
710  */
#define GED_OK
Definition: ged.h:55
#define GED_MAX
Definition: ged.h:253
int anchor_a1
Definition: bview.h:67
void adc_model_to_adc_view(struct bview_adc_state *adcs, mat_t model2view, fastf_t amax)
Definition: clip.c:192
void ged_calc_adc_a1(struct bview *gvp)
Definition: adc.c:645
Definition: ged.h:338
fastf_t a2
Definition: bview.h:64
struct db_i * dbip
Definition: raytrace.h:1266
Definition: clone.c:90
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
void ged_calc_adc_dst(struct bview *gvp)
Definition: adc.c:683
void adc_grid_to_adc_view(struct bview_adc_state *adcs, mat_t model2view, fastf_t amax)
Definition: clip.c:201
Definition: bview.h:209
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
void ged_calc_adc_pos(struct bview *gvp)
Definition: adc.c:629
int dv_dist
Definition: bview.h:59
int anchor_pos
Definition: bview.h:66
#define GED_ERROR
Definition: ged.h:61
#define HIDDEN
Definition: common.h:86
fastf_t pos_grid[3]
Definition: bview.h:62
struct bview * ged_gvp
Definition: ged.h:361
fastf_t a1
Definition: bview.h:63
mat_t gv_view2model
Definition: bview.h:224
Definition: color.c:49
fastf_t anchor_pt_a1[3]
Definition: bview.h:70
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
fastf_t gv_scale
Definition: bview.h:211
#define V3ARGS(a)
Definition: color.c:56
fastf_t anchor_pt_dst[3]
Definition: bview.h:72
fastf_t dst
Definition: bview.h:65
struct bview_adc_state gv_adc
Definition: bview.h:236
HIDDEN void adc_usage(struct bu_vls *vp, const char *name)
Definition: adc.c:71
struct bu_vls * ged_result_str
Definition: ged.h:357
double dbi_base2local
unit conversion factors
Definition: raytrace.h:808
fastf_t anchor_pt_a2[3]
Definition: bview.h:71
#define ZERO(val)
Definition: units.c:38
fastf_t pos_view[3]
Definition: bview.h:61
mat_t gv_model2view
Definition: bview.h:222
void ged_calc_adc_a2(struct bview *gvp)
Definition: adc.c:664
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
Definition: color.c:51
#define INV_GED
Definition: clip.c:226
double dbi_local2base
local2mm
Definition: raytrace.h:807
fastf_t pos_model[3]
Definition: bview.h:60
Definition: vls.h:56
int anchor_dst
Definition: bview.h:69
#define M_SQRT1_2
Definition: fft.h:38
double fastf_t
Definition: defines.h:300
void adc_reset(struct bview_adc_state *adcs, mat_t view2model, mat_t model2view)
Definition: clip.c:229
void adc_view_to_adc_grid(struct bview_adc_state *adcs, mat_t model2view)
Definition: clip.c:215
int anchor_a2
Definition: bview.h:68
int ged_adc(struct ged *gedp, int argc, const char *argv[])
Definition: adc.c:108
Definition: color.c:50
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126