BRL-CAD
shaded_mode.c
Go to the documentation of this file.
1 /* S H A D E D _ M O D 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/shaded_mode.c
21  *
22  * The shaded_mode command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 /*
35  * Set/get the shaded mode.
36  *
37  * Usage:
38  * shaded_mode [0|1|2]
39  *
40  */
41 int
42 ged_shaded_mode(struct ged *gedp, int argc, const char *argv[])
43 {
44  static const char *usage = "[0|1|2]";
45 
48  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
49 
50  /* initialize result */
51  bu_vls_trunc(gedp->ged_result_str, 0);
52 
53  if (argc > 2) {
54  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
55  return GED_ERROR;
56  }
57 
58  /* get shaded mode */
59  if (argc == 1) {
61  return GED_OK;
62  }
63 
64  /* set shaded mode */
65  if (argc == 2) {
66  int shaded_mode;
67 
68  if (sscanf(argv[1], "%d", &shaded_mode) != 1)
69  goto bad;
70 
71  if (shaded_mode < 0 || 2 < shaded_mode)
72  goto bad;
73 
74  gedp->ged_gdp->gd_shaded_mode = shaded_mode;
75  return GED_OK;
76  }
77 
78 bad:
79  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
80  return GED_ERROR;
81 }
82 
83 
84 /*
85  * Local Variables:
86  * tab-width: 8
87  * mode: C
88  * indent-tabs-mode: t
89  * c-file-style: "stroustrup"
90  * End:
91  * ex: shiftwidth=4 tabstop=8
92  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
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
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
int ged_shaded_mode(struct ged *gedp, int argc, const char *argv[])
Definition: shaded_mode.c:42
struct bu_vls * ged_result_str
Definition: ged.h:357
struct ged_drawable * ged_gdp
Definition: ged.h:360
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int gd_shaded_mode
1 - draw bots shaded by default
Definition: ged.h:330