BRL-CAD
pscale.c
Go to the documentation of this file.
1 /* P S C A L 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/pscale.c
21  *
22  * The pscale 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_pscale(struct ged *gedp, int argc, const char *argv[])
38 {
39  int ret;
40  int rflag;
41  struct rt_db_internal intern;
42 
43  /* intentionally double for scan */
44  double sf;
45 
46  char *last;
47  struct directory *dp;
48  static const char *usage = "[-r] obj attribute sf";
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 || argc > 5) {
64  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
65  return GED_ERROR;
66  }
67 
68  if (argc == 5) {
69  if (argv[1][0] == '-' && argv[1][1] == 'r' && argv[1][2] == '\0') {
70  rflag = 1;
71  --argc;
72  ++argv;
73  } else {
74  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
75  return BRLCAD_ERROR;
76  }
77  } else
78  rflag = 0;
79 
80  if (sscanf(argv[3], "%lf", &sf) != 1 ||
81  sf <= SQRT_SMALL_FASTF) {
82  bu_vls_printf(gedp->ged_result_str, "%s: bad scale factor - %s", argv[0], argv[3]);
83  return GED_ERROR;
84  }
85 
86  if ((last = strrchr(argv[1], '/')) == NULL)
87  last = (char *)argv[1];
88  else
89  ++last;
90 
91  if (last[0] == '\0') {
92  bu_vls_printf(gedp->ged_result_str, "%s: illegal input - %s", argv[0], argv[1]);
93  return GED_ERROR;
94  }
95 
96  if ((dp = db_lookup(gedp->ged_wdbp->dbip, last, LOOKUP_QUIET)) == RT_DIR_NULL) {
97  bu_vls_printf(gedp->ged_result_str, "%s: %s not found", argv[0], argv[1]);
98  return GED_ERROR;
99  }
100 
101  GED_DB_GET_INTERNAL(gedp, &intern, dp, (matp_t)NULL, &rt_uniresource, GED_ERROR);
102  RT_CK_DB_INTERNAL(&intern);
103 
104  if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD) {
105  bu_vls_printf(gedp->ged_result_str, "%s: Object not eligible for scaling.", argv[0]);
106  rt_db_free_internal(&intern);
107 
108  return GED_ERROR;
109  }
110 
111  switch (intern.idb_minor_type) {
112  case DB5_MINORTYPE_BRLCAD_EHY:
113  ret = _ged_scale_ehy(gedp, (struct rt_ehy_internal *)intern.idb_ptr, argv[2], sf, rflag);
114  break;
115  case DB5_MINORTYPE_BRLCAD_ELL:
116  case DB5_MINORTYPE_BRLCAD_SPH:
117  ret = _ged_scale_ell(gedp, (struct rt_ell_internal *)intern.idb_ptr, argv[2], sf, rflag);
118  break;
119  case DB5_MINORTYPE_BRLCAD_EPA:
120  ret = _ged_scale_epa(gedp, (struct rt_epa_internal *)intern.idb_ptr, argv[2], sf, rflag);
121  break;
122  case DB5_MINORTYPE_BRLCAD_ETO:
123  ret = _ged_scale_eto(gedp, (struct rt_eto_internal *)intern.idb_ptr, argv[2], sf, rflag);
124  break;
125  case DB5_MINORTYPE_BRLCAD_EXTRUDE:
126  ret = _ged_scale_extrude(gedp, (struct rt_extrude_internal *)intern.idb_ptr, argv[2], sf, rflag);
127  break;
128  case DB5_MINORTYPE_BRLCAD_HYP:
129  ret = _ged_scale_hyp(gedp, (struct rt_hyp_internal *)intern.idb_ptr, argv[2], sf, rflag);
130  break;
131  case DB5_MINORTYPE_BRLCAD_PARTICLE:
132  ret = _ged_scale_part(gedp, (struct rt_part_internal *)intern.idb_ptr, argv[2], sf, rflag);
133  break;
134  case DB5_MINORTYPE_BRLCAD_RHC:
135  ret = _ged_scale_rhc(gedp, (struct rt_rhc_internal *)intern.idb_ptr, argv[2], sf, rflag);
136  break;
137  case DB5_MINORTYPE_BRLCAD_RPC:
138  ret = _ged_scale_rpc(gedp, (struct rt_rpc_internal *)intern.idb_ptr, argv[2], sf, rflag);
139  break;
140  case DB5_MINORTYPE_BRLCAD_SUPERELL:
141  ret = _ged_scale_superell(gedp, (struct rt_superell_internal *)intern.idb_ptr, argv[2], sf, rflag);
142  break;
143  case DB5_MINORTYPE_BRLCAD_TGC:
144  ret = _ged_scale_tgc(gedp, (struct rt_tgc_internal *)intern.idb_ptr, argv[2], sf, rflag);
145  break;
146  case DB5_MINORTYPE_BRLCAD_TOR:
147  ret = _ged_scale_tor(gedp, (struct rt_tor_internal *)intern.idb_ptr, argv[2], sf, rflag);
148  break;
149  case DB5_MINORTYPE_BRLCAD_PIPE:
150  ret = _ged_scale_pipe(gedp, (struct rt_pipe_internal *)intern.idb_ptr, argv[2], sf, rflag);
151  break;
152  case DB5_MINORTYPE_BRLCAD_METABALL:
153  ret = _ged_scale_metaball(gedp, (struct rt_metaball_internal *)intern.idb_ptr, argv[2], sf, rflag);
154  break;
155  default:
156  bu_vls_printf(gedp->ged_result_str, "%s: Object not yet supported.", argv[0]);
157  rt_db_free_internal(&intern);
158 
159  return GED_ERROR;
160  }
161 
162  if (ret == GED_OK) {
163  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
164  } else if (ret == GED_ERROR) {
165  rt_db_free_internal(&intern);
166  }
167 
168  return ret;
169 }
170 
171 
172 /*
173  * Local Variables:
174  * tab-width: 8
175  * mode: C
176  * indent-tabs-mode: t
177  * c-file-style: "stroustrup"
178  * End:
179  * ex: shiftwidth=4 tabstop=8
180  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
int _ged_scale_rhc(struct ged *gedp, struct rt_rhc_internal *rhc, const char *attribute, fastf_t sf, int rflag)
Definition: scale_rhc.c:36
int _ged_scale_superell(struct ged *gedp, struct rt_superell_internal *superell, const char *attribute, fastf_t sf, int rflag)
Definition: ged.h:338
int _ged_scale_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, fastf_t sf, int rflag)
Definition: scale_extrude.c:38
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
int _ged_scale_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf, int rflag)
int ged_pscale(struct ged *gedp, int argc, const char *argv[])
Definition: pscale.c:37
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 _ged_scale_eto(struct ged *gedp, struct rt_eto_internal *eto, const char *attribute, fastf_t sf, int rflag)
Definition: scale_eto.c:38
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
int _ged_scale_ehy(struct ged *gedp, struct rt_ehy_internal *ehy, const char *attribute, fastf_t sf, int rflag)
Definition: scale_ehy.c:36
int idb_major_type
Definition: raytrace.h:192
int _ged_scale_pipe(struct ged *gedp, struct rt_pipe_internal *pipeip, const char *attribute, fastf_t sf, int rflag)
Definition: edpipe.c:516
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
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define LOOKUP_QUIET
Definition: raytrace.h:893
#define SQRT_SMALL_FASTF
Definition: defines.h:346
struct bu_vls * ged_result_str
Definition: ged.h:357
int _ged_scale_part(struct ged *gedp, struct rt_part_internal *part, const char *attribute, fastf_t sf, int rflag)
Definition: scale_part.c:36
void * idb_ptr
Definition: raytrace.h:195
int _ged_scale_rpc(struct ged *gedp, struct rt_rpc_internal *rpc, const char *attribute, fastf_t sf, int rflag)
Definition: scale_rpc.c:36
int _ged_scale_hyp(struct ged *gedp, struct rt_hyp_internal *hyp, const char *attribute, fastf_t sf, int rflag)
Definition: scale_hyp.c:38
int _ged_scale_ell(struct ged *gedp, struct rt_ell_internal *ell, const char *attribute, fastf_t sf, int rflag)
Definition: scale_ell.c:36
int _ged_scale_tor(struct ged *gedp, struct rt_tor_internal *tor, const char *attribute, fastf_t sf, int rflag)
Definition: scale_tor.c:38
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
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
#define BRLCAD_ERROR
Definition: defines.h:72
int _ged_scale_tgc(struct ged *gedp, struct rt_tgc_internal *tgc, const char *attribute, fastf_t sf, int rflag)
Definition: scale_tgc.c:38
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216
int _ged_scale_epa(struct ged *gedp, struct rt_epa_internal *epa, const char *attribute, fastf_t sf, int rflag)
Definition: scale_epa.c:36