BRL-CAD
shader.c
Go to the documentation of this file.
1 /* S H A D E R . 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/shader.c
21  *
22  * The shader command.
23  *
24  */
25 
26 #include "ged.h"
27 
28 
29 int
30 ged_shader(struct ged *gedp, int argc, const char *argv[])
31 {
32  struct directory *dp;
33  struct rt_db_internal intern;
34  struct rt_comb_internal *comb;
35  static const char *usage = "combination shader_material [shader_argument(s)]";
36 
38  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
39 
40  /* initialize result */
41  bu_vls_trunc(gedp->ged_result_str, 0);
42 
43  /* must be wanting help */
44  if (argc == 1) {
45  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
46  return GED_HELP;
47  }
48 
49  GED_DB_LOOKUP(gedp, dp, argv[1], LOOKUP_NOISY, GED_ERROR);
50  GED_CHECK_COMB(gedp, dp, GED_ERROR);
51  GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, GED_ERROR);
52 
53  comb = (struct rt_comb_internal *)intern.idb_ptr;
54  RT_CK_COMB(comb);
55 
56  if (argc == 2) {
57  /* Return the current shader string */
58  bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&comb->shader));
59  rt_db_free_internal(&intern);
60  } else {
61  if (gedp->ged_wdbp->dbip->dbi_read_only) {
62  bu_vls_printf(gedp->ged_result_str, "Sorry, this database is READ-ONLY");
63  rt_db_free_internal(&intern);
64 
65  return GED_ERROR;
66  }
67 
68  /* Replace with new shader string from command line */
69  bu_vls_free(&comb->shader);
70 
71  /* Bunch up the rest of the args, space separated */
72  bu_vls_from_argv(&comb->shader, argc-2, (const char **)argv+2);
73 
74  GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
75  /* Internal representation has been freed by rt_db_put_internal */
76  }
77 
78  return GED_OK;
79 }
80 
81 
82 /*
83  * Local Variables:
84  * tab-width: 8
85  * mode: C
86  * indent-tabs-mode: t
87  * c-file-style: "stroustrup"
88  * End:
89  * ex: shiftwidth=4 tabstop=8
90  */
#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
struct db_i * dbip
Definition: raytrace.h:1266
#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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
#define GED_ERROR
Definition: ged.h:61
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
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
void bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
Definition: vls.c:532
struct bu_vls shader
Definition: raytrace.h:950
int ged_shader(struct ged *gedp, int argc, const char *argv[])
Definition: shader.c:30
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
int dbi_read_only
!0 => read only file
Definition: raytrace.h:806
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
double fastf_t
Definition: defines.h:300
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216