BRL-CAD
aet.c
Go to the documentation of this file.
1 /* A E T . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library 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 library 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/aet.c
21  *
22  * The ae command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_aet(struct ged *gedp, int argc, const char *argv[])
37 {
38  vect_t aet;
39  int iflag = 0;
40  static const char *usage = "[[-i] az el [tw]]";
41 
44  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
45 
46  /* initialize result */
47  bu_vls_trunc(gedp->ged_result_str, 0);
48 
49  /* get aet */
50  if (argc == 1) {
52  return GED_OK;
53  }
54 
55  /* Check for -i option */
56  if (argv[1][0] == '-' && argv[1][1] == 'i') {
57  iflag = 1; /* treat arguments as incremental values */
58  ++argv;
59  --argc;
60  }
61 
62  if (argc == 2) {
63  /* set aet */
64  int n;
65 
66  if ((n = bn_decode_vect(aet, argv[1])) == 2)
67  aet[2] = 0;
68  else if (n != 3) {
69  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
70  return GED_ERROR;
71  }
72 
73  if (iflag) {
74  VADD2(gedp->ged_gvp->gv_aet, gedp->ged_gvp->gv_aet, aet);
75  } else {
76  VMOVE(gedp->ged_gvp->gv_aet, aet);
77  }
78  _ged_mat_aet(gedp->ged_gvp);
79  ged_view_update(gedp->ged_gvp);
80 
81  return GED_OK;
82  }
83 
84  if (argc == 3 || argc == 4) {
85  double scan[3];
86 
87  if (sscanf(argv[1], "%lf", &scan[X]) != 1) {
88  bu_vls_printf(gedp->ged_result_str, "%s: bad azimuth - %s\n", argv[0], argv[1]);
89  return GED_ERROR;
90  }
91 
92  if (sscanf(argv[2], "%lf", &scan[Y]) != 1) {
93  bu_vls_printf(gedp->ged_result_str, "%s: bad elevation - %s\n", argv[0], argv[2]);
94  return GED_ERROR;
95  }
96 
97  if (argc == 4) {
98  if (sscanf(argv[3], "%lf", &scan[Z]) != 1) {
99  bu_vls_printf(gedp->ged_result_str, "%s: bad twist - %s\n", argv[0], argv[3]);
100  return GED_ERROR;
101  }
102  } else
103  scan[Z] = 0.0;
104 
105  /* convert from double to fastf_t */
106  VMOVE(aet, scan);
107 
108  if (iflag) {
109  VADD2(gedp->ged_gvp->gv_aet, gedp->ged_gvp->gv_aet, aet);
110  } else {
111  VMOVE(gedp->ged_gvp->gv_aet, aet);
112  }
113  _ged_mat_aet(gedp->ged_gvp);
114  ged_view_update(gedp->ged_gvp);
115 
116  return GED_OK;
117  }
118 
119  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
120  return GED_ERROR;
121 }
122 
123 
124 /*
125  * Local Variables:
126  * tab-width: 8
127  * mode: C
128  * indent-tabs-mode: t
129  * c-file-style: "stroustrup"
130  * End:
131  * ex: shiftwidth=4 tabstop=8
132  */
void usage(struct ged *gedp)
Definition: coil.c:315
int ged_aet(struct ged *gedp, int argc, const char *argv[])
Definition: aet.c:36
#define GED_OK
Definition: ged.h:55
void bn_encode_vect(struct bu_vls *vp, const vect_t v)
Definition: ged.h:338
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
Header file for the BRL-CAD common definitions.
void ged_view_update(struct bview *gvp)
Definition: vutil.c:33
void _ged_mat_aet(struct bview *gvp)
Definition: vutil.c:82
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
Definition: color.c:49
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int bn_decode_vect(vect_t v, const char *str)
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
Definition: color.c:51
vect_t gv_aet
Definition: bview.h:215
Definition: color.c:50