BRL-CAD
tra.c
Go to the documentation of this file.
1 /* T R A . 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/tra.c
21  *
22  * The tra 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_tra_args(struct ged *gedp, int argc, const char *argv[], char *coord, vect_t tvec)
37 {
38  static const char *usage = "[-m|-v] x y z";
39 
42  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
43 
44  /* initialize result */
45  bu_vls_trunc(gedp->ged_result_str, 0);
46 
47  /* must be wanting help */
48  if (argc == 1) {
49  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
50  return GED_HELP;
51  }
52 
53  /* process possible coord flag */
54  if (argv[1][0] == '-' && (argv[1][1] == 'v' || argv[1][1] == 'm') && argv[1][2] == '\0') {
55  *coord = argv[1][1];
56  --argc;
57  ++argv;
58  } else
59  *coord = gedp->ged_gvp->gv_coord;
60 
61  if (argc != 2 && argc != 4) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_ERROR;
64  }
65 
66  if (argc == 2) {
67  if (bn_decode_vect(tvec, argv[1]) != 3) {
68  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
69  return GED_ERROR;
70  }
71  } else {
72  double scan[3];
73 
74  if (sscanf(argv[1], "%lf", &scan[X]) != 1) {
75  bu_vls_printf(gedp->ged_result_str, "%s: bad X value %s\n", argv[0], argv[1]);
76  return GED_ERROR;
77  }
78 
79  if (sscanf(argv[2], "%lf", &scan[Y]) != 1) {
80  bu_vls_printf(gedp->ged_result_str, "%s: bad Y value %s\n", argv[0], argv[2]);
81  return GED_ERROR;
82  }
83 
84  if (sscanf(argv[3], "%lf", &scan[Z]) != 1) {
85  bu_vls_printf(gedp->ged_result_str, "%s: bad Z value %s\n", argv[0], argv[3]);
86  return GED_ERROR;
87  }
88 
89  /* convert from double to fastf_t */
90  VMOVE(tvec, scan);
91  }
92 
93  return GED_OK;
94 }
95 
96 
97 int
98 ged_tra(struct ged *gedp, int argc, const char *argv[])
99 {
100  int ret;
101  char coord;
102  vect_t tvec;
103 
104  if ((ret = ged_tra_args(gedp, argc, argv, &coord, tvec)) != GED_OK)
105  return ret;
106 
107  return _ged_do_tra(gedp, coord, tvec, (int (*)())0);
108 }
109 
110 
111 /*
112  * Local Variables:
113  * tab-width: 8
114  * mode: C
115  * indent-tabs-mode: t
116  * c-file-style: "stroustrup"
117  * End:
118  * ex: shiftwidth=4 tabstop=8
119  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
int ged_tra_args(struct ged *gedp, int argc, const char *argv[], char *coord, vect_t tvec)
Definition: tra.c:36
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
int _ged_do_tra(struct ged *gedp, char coord, vect_t tvec, int(*func)())
Definition: vutil.c:181
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
int ged_tra(struct ged *gedp, int argc, const char *argv[])
Definition: tra.c:98
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
char gv_coord
coordinate system
Definition: bview.h:218
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