BRL-CAD
get_type.c
Go to the documentation of this file.
1 /* G E T _ T Y P 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/get_type.c
21  *
22  * The get_type command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_get_type(struct ged *gedp, int argc, const char *argv[])
37 {
38  struct rt_db_internal intern;
39  int type;
40  static const char *usage = "object";
41 
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  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_ERROR;
57  }
58 
59  if (wdb_import_from_path(gedp->ged_result_str, &intern, argv[1], gedp->ged_wdbp) == GED_ERROR)
60  return GED_ERROR;
61 
62  if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD) {
63  bu_vls_printf(gedp->ged_result_str, "unknown");
64  rt_db_free_internal(&intern);
65 
66  return GED_OK;
67  }
68 
69  switch (intern.idb_minor_type) {
70  case DB5_MINORTYPE_BRLCAD_TOR:
71  bu_vls_printf(gedp->ged_result_str, "tor");
72  break;
73  case DB5_MINORTYPE_BRLCAD_TGC:
74  bu_vls_printf(gedp->ged_result_str, "tgc");
75  break;
76  case DB5_MINORTYPE_BRLCAD_ELL:
77  bu_vls_printf(gedp->ged_result_str, "ell");
78  break;
79  case DB5_MINORTYPE_BRLCAD_SUPERELL:
80  bu_vls_printf(gedp->ged_result_str, "superell");
81  break;
82  case DB5_MINORTYPE_BRLCAD_ARB8:
83  type = rt_arb_std_type(&intern, &gedp->ged_wdbp->wdb_tol);
84 
85  switch (type) {
86  case 4:
87  bu_vls_printf(gedp->ged_result_str, "arb4");
88  break;
89  case 5:
90  bu_vls_printf(gedp->ged_result_str, "arb5");
91  break;
92  case 6:
93  bu_vls_printf(gedp->ged_result_str, "arb6");
94  break;
95  case 7:
96  bu_vls_printf(gedp->ged_result_str, "arb7");
97  break;
98  case 8:
99  bu_vls_printf(gedp->ged_result_str, "arb8");
100  break;
101  default:
102  bu_vls_printf(gedp->ged_result_str, "invalid");
103  break;
104  }
105 
106  break;
107  case DB5_MINORTYPE_BRLCAD_ARS:
108  bu_vls_printf(gedp->ged_result_str, "ars");
109  break;
110  case DB5_MINORTYPE_BRLCAD_HALF:
111  bu_vls_printf(gedp->ged_result_str, "half");
112  break;
113  case DB5_MINORTYPE_BRLCAD_HYP:
114  bu_vls_printf(gedp->ged_result_str, "hyp");
115  break;
116  case DB5_MINORTYPE_BRLCAD_REC:
117  bu_vls_printf(gedp->ged_result_str, "rec");
118  break;
119  case DB5_MINORTYPE_BRLCAD_POLY:
120  bu_vls_printf(gedp->ged_result_str, "poly");
121  break;
122  case DB5_MINORTYPE_BRLCAD_BSPLINE:
123  bu_vls_printf(gedp->ged_result_str, "spline");
124  break;
125  case DB5_MINORTYPE_BRLCAD_SPH:
126  bu_vls_printf(gedp->ged_result_str, "sph");
127  break;
128  case DB5_MINORTYPE_BRLCAD_NMG:
129  bu_vls_printf(gedp->ged_result_str, "nmg");
130  break;
131  case DB5_MINORTYPE_BRLCAD_EBM:
132  bu_vls_printf(gedp->ged_result_str, "ebm");
133  break;
134  case DB5_MINORTYPE_BRLCAD_VOL:
135  bu_vls_printf(gedp->ged_result_str, "vol");
136  break;
137  case DB5_MINORTYPE_BRLCAD_ARBN:
138  bu_vls_printf(gedp->ged_result_str, "arbn");
139  break;
140  case DB5_MINORTYPE_BRLCAD_PIPE:
141  bu_vls_printf(gedp->ged_result_str, "pipe");
142  break;
143  case DB5_MINORTYPE_BRLCAD_PARTICLE:
144  bu_vls_printf(gedp->ged_result_str, "part");
145  break;
146  case DB5_MINORTYPE_BRLCAD_RPC:
147  bu_vls_printf(gedp->ged_result_str, "rpc");
148  break;
149  case DB5_MINORTYPE_BRLCAD_RHC:
150  bu_vls_printf(gedp->ged_result_str, "rhc");
151  break;
152  case DB5_MINORTYPE_BRLCAD_EPA:
153  bu_vls_printf(gedp->ged_result_str, "epa");
154  break;
155  case DB5_MINORTYPE_BRLCAD_EHY:
156  bu_vls_printf(gedp->ged_result_str, "ehy");
157  break;
158  case DB5_MINORTYPE_BRLCAD_ETO:
159  bu_vls_printf(gedp->ged_result_str, "eto");
160  break;
161  case DB5_MINORTYPE_BRLCAD_GRIP:
162  bu_vls_printf(gedp->ged_result_str, "grip");
163  break;
164  case DB5_MINORTYPE_BRLCAD_JOINT:
165  bu_vls_printf(gedp->ged_result_str, "joint");
166  break;
167  case DB5_MINORTYPE_BRLCAD_HF:
168  bu_vls_printf(gedp->ged_result_str, "hf");
169  break;
170  case DB5_MINORTYPE_BRLCAD_DSP:
171  bu_vls_printf(gedp->ged_result_str, "dsp");
172  break;
173  case DB5_MINORTYPE_BRLCAD_SKETCH:
174  bu_vls_printf(gedp->ged_result_str, "sketch");
175  break;
176  case DB5_MINORTYPE_BRLCAD_EXTRUDE:
177  bu_vls_printf(gedp->ged_result_str, "extrude");
178  break;
179  case DB5_MINORTYPE_BRLCAD_SUBMODEL:
180  bu_vls_printf(gedp->ged_result_str, "submodel");
181  break;
182  case DB5_MINORTYPE_BRLCAD_CLINE:
183  bu_vls_printf(gedp->ged_result_str, "cline");
184  break;
185  case DB5_MINORTYPE_BRLCAD_BOT:
186  bu_vls_printf(gedp->ged_result_str, "bot");
187  break;
188  case DB5_MINORTYPE_BRLCAD_COMBINATION:
189  bu_vls_printf(gedp->ged_result_str, "comb");
190  break;
191  case DB5_MINORTYPE_BRLCAD_BREP:
192  bu_vls_printf(gedp->ged_result_str, "brep");
193  break;
194  case DB5_MINORTYPE_BRLCAD_METABALL:
195  bu_vls_printf(gedp->ged_result_str, "metaball");
196  break;
197  default:
198  bu_vls_printf(gedp->ged_result_str, "other");
199  break;
200  }
201 
202  rt_db_free_internal(&intern);
203  return GED_OK;
204 }
205 
206 
207 /*
208  * Local Variables:
209  * tab-width: 8
210  * mode: C
211  * indent-tabs-mode: t
212  * c-file-style: "stroustrup"
213  * End:
214  * ex: shiftwidth=4 tabstop=8
215  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
int wdb_import_from_path(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb)
Definition: wdb.c:431
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 rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
int idb_major_type
Definition: raytrace.h:192
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
struct bu_vls * ged_result_str
Definition: ged.h:357
int ged_get_type(struct ged *gedp, int argc, const char *argv[])
Definition: get_type.c:36
struct bn_tol wdb_tol
Definition: raytrace.h:1269
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
int idb_minor_type
ID_xxx.
Definition: raytrace.h:193
int rt_arb_std_type(const struct rt_db_internal *ip, const struct bn_tol *tol)
Definition: arb8.c:317
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216