BRL-CAD
item.c
Go to the documentation of this file.
1 /* I T E M . 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/item.c
21  *
22  * The item command.
23  *
24  */
25 
26 #include "common.h"
27 #include <stdlib.h>
28 #include "ged.h"
29 
30 int
31 ged_item(struct ged *gedp, int argc, const char *argv[])
32 {
33  int status = GED_OK;
34  struct directory *dp;
35  int ident, air, GIFTmater=0, los=0;
36  int GIFTmater_set, los_set;
37  struct rt_db_internal intern;
38  struct rt_comb_internal *comb;
39  static const char *usage = "region ident [air [material [los]]]";
40 
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 < 3 || 6 < argc) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_ERROR;
57  }
58 
59  GED_DB_LOOKUP(gedp, dp, argv[1], LOOKUP_NOISY, GED_ERROR);
60  GED_CHECK_COMB(gedp, dp, GED_ERROR);
61  GED_CHECK_REGION(gedp, dp, GED_ERROR);
62 
63  air = ident = 0;
64  GIFTmater_set = los_set = 0;
65  ident = atoi(argv[2]);
66 
67  /*
68  * If <air> is not included, it is assumed to be zero.
69  * If, on the other hand, either of <GIFTmater> and <los>
70  * is not included, it is left unchanged.
71  */
72  if (argc > 3) {
73  air = atoi(argv[3]);
74  }
75 
76  if (argc > 4) {
77  GIFTmater = atoi(argv[4]);
78  GIFTmater_set = 1;
79  }
80 
81  if (argc > 5) {
82  los = atoi(argv[5]);
83  los_set = 1;
84  }
85 
86  GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, GED_ERROR);
87 
88  comb = (struct rt_comb_internal *)intern.idb_ptr;
89  RT_CK_COMB(comb);
90  comb->region_id = ident;
91  comb->aircode = air;
92 
93  if (GIFTmater_set) {
94  comb->GIFTmater = GIFTmater;
95  }
96 
97  if (los_set) {
98  comb->los = los;
99  }
100 
101  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
102 
103  return status;
104 }
105 
106 
107 /*
108  * Local Variables:
109  * tab-width: 8
110  * mode: C
111  * indent-tabs-mode: t
112  * c-file-style: "stroustrup"
113  * End:
114  * ex: shiftwidth=4 tabstop=8
115  */
#define GED_CHECK_COMB(_gedp, _dp, _flags)
Definition: ged.h:104
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
#define GED_DB_LOOKUP(_gedp, _dp, _name, _noisy, _flags)
Definition: ged.h:223
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
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
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 ged_item(struct ged *gedp, int argc, const char *argv[])
Definition: item.c:31
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
struct bu_vls * ged_result_str
Definition: ged.h:357
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 LOOKUP_NOISY
Definition: raytrace.h:892
#define GED_HELP
Definition: ged.h:62
#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
double fastf_t
Definition: defines.h:300
#define GED_CHECK_REGION(_gedp, _dp, _flags)
Definition: ged.h:192