BRL-CAD
slew.c
Go to the documentation of this file.
1 /* S L E W . 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/slew.c
21  *
22  * The slew 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_slew(struct ged *gedp, int argc, const char *argv[])
37 {
38  vect_t svec;
39  static const char *usage = "x y [z]";
40 
43  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
44 
45  /* initialize result */
46  bu_vls_trunc(gedp->ged_result_str, 0);
47 
48  /* must be wanting help */
49  if (argc == 1) {
50  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
51  return GED_HELP;
52  }
53 
54  if (argc == 2) {
55  int n;
56 
57  if ((n = bn_decode_vect(svec, argv[1])) != 3) {
58  if (n != 2) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
60  return GED_ERROR;
61  }
62 
63  svec[Z] = 0.0;
64  }
65 
66  return _ged_do_slew(gedp, svec);
67  }
68 
69  if (argc == 3 || argc == 4) {
70  double scan[3];
71 
72  if (sscanf(argv[1], "%lf", &scan[X]) != 1) {
73  bu_vls_printf(gedp->ged_result_str, "slew: bad X value %s\n", argv[1]);
74  return GED_ERROR;
75  }
76 
77  if (sscanf(argv[2], "%lf", &scan[Y]) != 1) {
78  bu_vls_printf(gedp->ged_result_str, "slew: bad Y value %s\n", argv[2]);
79  return GED_ERROR;
80  }
81 
82  if (argc == 4) {
83  if (sscanf(argv[3], "%lf", &scan[Z]) != 1) {
84  bu_vls_printf(gedp->ged_result_str, "slew: bad Z value %s\n", argv[3]);
85  return GED_ERROR;
86  }
87  } else
88  scan[Z] = 0.0;
89 
90  /* convert from double to fastf_t */
91  VMOVE(svec, scan);
92 
93  return _ged_do_slew(gedp, svec);
94  }
95 
96  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
97  return GED_ERROR;
98 }
99 
100 
101 /*
102  * Local Variables:
103  * tab-width: 8
104  * mode: C
105  * indent-tabs-mode: t
106  * c-file-style: "stroustrup"
107  * End:
108  * ex: shiftwidth=4 tabstop=8
109  */
void usage(struct ged *gedp)
Definition: coil.c:315
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.
#define GED_ERROR
Definition: ged.h:61
Definition: color.c:49
int _ged_do_slew(struct ged *gedp, vect_t svec)
Definition: vutil.c:168
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int ged_slew(struct ged *gedp, int argc, const char *argv[])
Definition: slew.c:36
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
#define GED_HELP
Definition: ged.h:62
Definition: color.c:51
Definition: color.c:50