BRL-CAD
edcomb.c
Go to the documentation of this file.
1 /* E D C O M B . 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/edcomb.c
21  *
22  * The edcomb command.
23  *
24  */
25 
26 #include "ged.h"
27 
28 
29 int
30 ged_edcomb(struct ged *gedp, int argc, const char *argv[])
31 {
32  struct directory *dp;
33  int regionid, air, mat, los;
34  struct rt_db_internal intern;
35  struct rt_comb_internal *comb;
36  static const char *usage = "combname region_flag region_id air los material_id";
37 
40  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
41 
42  /* initialize result */
43  bu_vls_trunc(gedp->ged_result_str, 0);
44 
45  /* must be wanting help */
46  if (argc == 1) {
47  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
48  return GED_HELP;
49  }
50 
51  if (argc != 7) {
52  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
53  return GED_ERROR;
54  }
55 
56  GED_DB_LOOKUP(gedp, dp, argv[1], LOOKUP_NOISY, GED_ERROR);
57  GED_CHECK_COMB(gedp, dp, GED_ERROR);
58 
59  if (sscanf(argv[3], "%d", &regionid) != 1) {
60  bu_vls_printf(gedp->ged_result_str, "Bad region identifier");
61  return GED_ERROR;
62  }
63  if (sscanf(argv[4], "%d", &air) != 1) {
64  bu_vls_printf(gedp->ged_result_str, "Bad air code");
65  return GED_ERROR;
66  }
67  if (sscanf(argv[5], "%d", &los) != 1) {
68  bu_vls_printf(gedp->ged_result_str, "Bad los line-of-sight equivalence factor");
69  return GED_ERROR;
70  }
71  if (sscanf(argv[6], "%d", &mat) != 1) {
72  bu_vls_printf(gedp->ged_result_str, "Bad material identifier");
73  return GED_ERROR;
74  }
75 
76  GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, GED_ERROR);
77  comb = (struct rt_comb_internal *)intern.idb_ptr;
78  RT_CK_COMB(comb);
79 
80  if (argv[2][0] == 'R' || atoi(argv[2]))
81  comb->region_flag = 1;
82  else
83  comb->region_flag = 0;
84 
85  comb->region_id = regionid;
86  comb->aircode = air;
87  comb->los = los;
88  comb->GIFTmater = mat;
89  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
90 
91  return GED_OK;
92 }
93 
94 
95 /*
96  * Local Variables:
97  * tab-width: 8
98  * mode: C
99  * indent-tabs-mode: t
100  * c-file-style: "stroustrup"
101  * End:
102  * ex: shiftwidth=4 tabstop=8
103  */
#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
char region_flag
!0 ==> this COMB is a REGION
Definition: raytrace.h:939
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
#define GED_ERROR
Definition: ged.h:61
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
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
int ged_edcomb(struct ged *gedp, int argc, const char *argv[])
Definition: edcomb.c:30
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
double fastf_t
Definition: defines.h:300