BRL-CAD
arot.c
Go to the documentation of this file.
1 /* A R O 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/arot.c
21  *
22  * The arot 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 int
35 ged_arot_args(struct ged *gedp, int argc, const char *argv[], mat_t rmat)
36 {
37  point_t pt;
38  vect_t axisv;
39  double axis[3]; /* not fastf_t due to sscanf */
40  double angle; /* not fastf_t due to sscanf */
41  static const char *usage = "x y z angle";
42 
45  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
46 
47  /* initialize result */
48  bu_vls_trunc(gedp->ged_result_str, 0);
49 
50  /* must be wanting help */
51  if (argc == 1) {
52  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
53  return GED_HELP;
54  }
55 
56  if (argc != 5) {
57  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
58  return GED_ERROR;
59  }
60 
61  if (sscanf(argv[1], "%lf", &axis[X]) != 1) {
62  bu_vls_printf(gedp->ged_result_str, "%s: bad X value - %s\n", argv[0], argv[1]);
63  return GED_ERROR;
64  }
65 
66  if (sscanf(argv[2], "%lf", &axis[Y]) != 1) {
67  bu_vls_printf(gedp->ged_result_str, "%s: bad Y value - %s\n", argv[0], argv[2]);
68  return GED_ERROR;
69  }
70 
71  if (sscanf(argv[3], "%lf", &axis[Z]) != 1) {
72  bu_vls_printf(gedp->ged_result_str, "%s: bad Z value - %s\n", argv[0], argv[3]);
73  return GED_ERROR;
74  }
75 
76  if (sscanf(argv[4], "%lf", &angle) != 1) {
77  bu_vls_printf(gedp->ged_result_str, "%s: bad angle - %s\n", argv[0], argv[4]);
78  return GED_ERROR;
79  }
80 
81  VSETALL(pt, 0.0);
82  VUNITIZE(axis);
83  VMOVE(axisv, axis);
84  bn_mat_arb_rot(rmat, pt, axisv, angle*DEG2RAD);
85 
86  return GED_OK;
87 }
88 
89 
90 int
91 ged_arot(struct ged *gedp, int argc, const char *argv[])
92 {
93  int ret;
94  mat_t rmat;
95 
96  if ((ret = ged_arot_args(gedp, argc, argv, rmat)) != GED_OK)
97  return ret;
98 
99  return _ged_do_rot(gedp, gedp->ged_gvp->gv_coord, rmat, (int (*)())0);
100 }
101 
102 
103 /*
104  * Local Variables:
105  * tab-width: 8
106  * mode: C
107  * indent-tabs-mode: t
108  * c-file-style: "stroustrup"
109  * End:
110  * ex: shiftwidth=4 tabstop=8
111  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
int ged_arot(struct ged *gedp, int argc, const char *argv[])
Definition: arot.c:91
Definition: ged.h:338
#define VSETALL(a, s)
Definition: color.c:54
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
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 ged_arot_args(struct ged *gedp, int argc, const char *argv[], mat_t rmat)
Definition: arot.c:35
struct bu_vls * ged_result_str
Definition: ged.h:357
int _ged_do_rot(struct ged *gedp, char coord, mat_t rmat, int(*func)())
Definition: vutil.c:103
axis
Definition: color.c:48
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
void bn_mat_arb_rot(mat_t m, const point_t pt, const vect_t dir, const fastf_t ang)
Definition: mat.c:987
Definition: color.c:50