BRL-CAD
pset.c
Go to the documentation of this file.
1 /* P S E 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/pset.c
21  *
22  * The pset 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_pset(struct ged *gedp, int argc, const char *argv[])
38 {
39  int ret;
40  struct rt_db_internal intern;
41 
42  /* intentionally double for scan */
43  double val;
44 
45  char *last;
46  struct directory *dp;
47  static const char *usage = "obj attribute val";
48 
51  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
52 
53  /* initialize result */
54  bu_vls_trunc(gedp->ged_result_str, 0);
55 
56  /* must be wanting help */
57  if (argc == 1) {
58  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
59  return GED_HELP;
60  }
61 
62  if (argc != 4) {
63  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
64  return GED_ERROR;
65  }
66 
67  if (sscanf(argv[3], "%lf", &val) != 1) {
68  bu_vls_printf(gedp->ged_result_str, "%s: bad value - %s", argv[0], argv[3]);
69  return GED_ERROR;
70  }
71 
72  if ((last = strrchr(argv[1], '/')) == NULL)
73  last = (char *)argv[1];
74  else
75  ++last;
76 
77  if (last[0] == '\0') {
78  bu_vls_printf(gedp->ged_result_str, "%s: illegal input - %s", argv[0], argv[1]);
79  return GED_ERROR;
80  }
81 
82  if ((dp = db_lookup(gedp->ged_wdbp->dbip, last, LOOKUP_QUIET)) == RT_DIR_NULL) {
83  bu_vls_printf(gedp->ged_result_str, "%s: %s not found", argv[0], argv[1]);
84  return GED_ERROR;
85  }
86 
87  GED_DB_GET_INTERNAL(gedp, &intern, dp, (matp_t)NULL, &rt_uniresource, GED_ERROR);
88  RT_CK_DB_INTERNAL(&intern);
89 
90  if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD) {
91  bu_vls_printf(gedp->ged_result_str, "%s: Object not eligible for scaling.", argv[0]);
92  rt_db_free_internal(&intern);
93 
94  return GED_ERROR;
95  }
96 
97  switch (intern.idb_minor_type) {
98  case DB5_MINORTYPE_BRLCAD_METABALL:
99  ret = _ged_set_metaball(gedp, (struct rt_metaball_internal *)intern.idb_ptr, argv[2], val);
100  break;
101  default:
102  bu_vls_printf(gedp->ged_result_str, "%s: Object not yet supported.", argv[0]);
103  rt_db_free_internal(&intern);
104 
105  return GED_ERROR;
106  }
107 
108  if (ret == GED_OK) {
109  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
110  } else if (ret == GED_ERROR) {
111  rt_db_free_internal(&intern);
112  }
113 
114  return ret;
115 }
116 
117 
118 /*
119  * Local Variables:
120  * tab-width: 8
121  * mode: C
122  * indent-tabs-mode: t
123  * c-file-style: "stroustrup"
124  * End:
125  * ex: shiftwidth=4 tabstop=8
126  */
Definition: db_flip.c:35
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
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
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
#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
void * idb_ptr
Definition: raytrace.h:195
int ged_pset(struct ged *gedp, int argc, const char *argv[])
Definition: pset.c:37
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_set_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf)
Definition: edit_metaball.c:87
#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