BRL-CAD
protate.c
Go to the documentation of this file.
1 /* P R O T A T E . 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/protate.c
21  *
22  * The protate command.
23  */
24 
25 #include "common.h"
26 
27 #include <string.h>
28 
29 #include "bu/cmd.h"
30 #include "rtgeom.h"
31 #include "raytrace.h"
32 
33 #include "./ged_private.h"
34 
35 
36 int
37 ged_protate(struct ged *gedp, int argc, const char *argv[])
38 {
39  int ret;
40  mat_t rmat;
41  char *last;
42  struct rt_db_internal intern;
43  struct directory *dp;
44 
45  /* intentionally double for scan */
46  double rx, ry, rz;
47 
48  static const char *usage = "obj attribute rvec";
49 
52  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
53 
54  /* initialize result */
55  bu_vls_trunc(gedp->ged_result_str, 0);
56 
57  /* must be wanting help */
58  if (argc == 1) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
60  return GED_HELP;
61  }
62 
63  if (argc != 4) {
64  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
65  return GED_ERROR;
66  }
67 
68  if (sscanf(argv[3], "%lf %lf %lf", &rx, &ry, &rz) != 3) {
69  bu_vls_printf(gedp->ged_result_str, "%s: bad rotation vector - %s", argv[0], argv[3]);
70  return GED_ERROR;
71  }
72 
73  if ((last = strrchr(argv[1], '/')) == NULL)
74  last = (char *)argv[1];
75  else
76  ++last;
77 
78  if (last[0] == '\0') {
79  bu_vls_printf(gedp->ged_result_str, "%s: illegal input - %s", argv[0], argv[1]);
80  return GED_ERROR;
81  }
82 
83  if ((dp = db_lookup(gedp->ged_wdbp->dbip, last, LOOKUP_QUIET)) == RT_DIR_NULL) {
84  bu_vls_printf(gedp->ged_result_str, "%s: %s not found", argv[0], argv[1]);
85  return GED_ERROR;
86  }
87 
88  GED_DB_GET_INTERNAL(gedp, &intern, dp, (matp_t)NULL, &rt_uniresource, GED_ERROR);
89  RT_CK_DB_INTERNAL(&intern);
90 
91  if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD) {
92  bu_vls_printf(gedp->ged_result_str, "%s: Object not eligible for rotating.", argv[0]);
93  rt_db_free_internal(&intern);
94 
95  return GED_ERROR;
96  }
97 
98  bn_mat_angles(rmat, rx, ry, rz);
99 
100  switch (intern.idb_minor_type) {
101  case DB5_MINORTYPE_BRLCAD_ETO:
102  ret = _ged_rotate_eto(gedp, (struct rt_eto_internal *)intern.idb_ptr, argv[2], rmat);
103  break;
104  case DB5_MINORTYPE_BRLCAD_EXTRUDE:
105  ret = _ged_rotate_extrude(gedp, (struct rt_extrude_internal *)intern.idb_ptr, argv[2], rmat);
106  break;
107  case DB5_MINORTYPE_BRLCAD_HYP:
108  ret = _ged_rotate_hyp(gedp, (struct rt_hyp_internal *)intern.idb_ptr, argv[2], rmat);
109  break;
110  case DB5_MINORTYPE_BRLCAD_TGC:
111  ret = _ged_rotate_tgc(gedp, (struct rt_tgc_internal *)intern.idb_ptr, argv[2], rmat);
112  break;
113  default:
114  bu_vls_printf(gedp->ged_result_str, "%s: Object not yet supported.", argv[0]);
115  rt_db_free_internal(&intern);
116 
117  return GED_ERROR;
118  }
119 
120  if (ret == GED_OK) {
121  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
122  } else if (ret == GED_ERROR) {
123  rt_db_free_internal(&intern);
124  }
125 
126  return ret;
127 }
128 
129 
130 /*
131  * Local Variables:
132  * tab-width: 8
133  * mode: C
134  * indent-tabs-mode: t
135  * c-file-style: "stroustrup"
136  * End:
137  * ex: shiftwidth=4 tabstop=8
138  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
int _ged_rotate_tgc(struct ged *gedp, struct rt_tgc_internal *tgc, const char *attribute, matp_t rmat)
Definition: rotate_tgc.c:38
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
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
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
struct rt_wdb * ged_wdbp
Definition: ged.h:340
int _ged_rotate_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, matp_t rmat)
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
int idb_major_type
Definition: raytrace.h:192
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int ged_protate(struct ged *gedp, int argc, const char *argv[])
Definition: protate.c:37
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define LOOKUP_QUIET
Definition: raytrace.h:893
struct bu_vls * ged_result_str
Definition: ged.h:357
int _ged_rotate_hyp(struct ged *gedp, struct rt_hyp_internal *hyp, const char *attribute, matp_t rmat)
Definition: rotate_hyp.c:38
void bn_mat_angles(mat_t mat, double alpha, double beta, double ggamma)
void * idb_ptr
Definition: raytrace.h:195
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define RT_DIR_NULL
Definition: raytrace.h:875
#define GED_HELP
Definition: ged.h:62
int idb_minor_type
ID_xxx.
Definition: raytrace.h:193
#define GED_DB_GET_INTERNAL(_gedp, _intern, _dp, _mat, _resource, _flags)
Definition: ged.h:233
int _ged_rotate_eto(struct ged *gedp, struct rt_eto_internal *eto, const char *attribute, matp_t rmat)
Definition: rotate_eto.c:38
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216