BRL-CAD
lod.c
Go to the documentation of this file.
1 /* L O D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2013-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 lod.c
21  *
22  * Level of Detail drawing configuration command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "rtgeom.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 ged_lod(struct ged *gedp, int argc, const char *argv[])
39 {
40  struct bview *gvp;
41  int printUsage = 0;
42  static const char *usage = "lod (on|off|enabled)\n"
43  "lod scale (points|curves) <factor>\n"
44  "lod redraw (off|onzoom)\n";
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  /* must be wanting help */
54  if (argc < 2) {
55  bu_vls_printf(gedp->ged_result_str, "Usage:\n%s", usage);
56  return GED_HELP;
57  }
58 
59  gvp = gedp->ged_gvp;
60  if (gvp == NULL) {
61  return GED_OK;
62  }
63 
64  /* determine subcommand */
65  --argc;
66  ++argv;
67  printUsage = 0;
68  if (argc == 1 && BU_STR_EQUAL(argv[0], "on")) {
69  /* lod on */
70  gvp->gv_adaptive_plot = 1;
71  } else if (argc == 1 && BU_STR_EQUAL(argv[0], "off")) {
72  /* lod off */
73  gvp->gv_adaptive_plot = 0;
74  } else if (argc == 1 && BU_STR_EQUAL(argv[0], "enabled")) {
75  /* lod enabled - return on state */
77  } else if (BU_STR_EQUAL(argv[0], "scale")) {
78  if (argc == 2 || argc == 3) {
79  if (BU_STR_EQUAL(argv[1], "points")) {
80  if (argc == 2) {
81  /* lod scale points - return current value */
82  bu_vls_printf(gedp->ged_result_str, "%f", gvp->gv_point_scale);
83  } else {
84  /* lod scale points f - set value */
85  gvp->gv_point_scale = atof(argv[2]);
86  }
87  } else if (BU_STR_EQUAL(argv[1], "curves")) {
88  if (argc == 2) {
89  /* lod scale curves - return current value */
90  bu_vls_printf(gedp->ged_result_str, "%f", gvp->gv_curve_scale);
91  } else {
92  /* lod scale curves f - set value */
93  gvp->gv_curve_scale = atof(argv[2]);
94  }
95  } else {
96  printUsage = 1;
97  }
98  } else {
99  printUsage = 1;
100  }
101  } else if (BU_STR_EQUAL(argv[0], "redraw")) {
102  printUsage = 1;
103  if (argc == 1) {
104  /* lod redraw - return current value */
105  if (gvp->gv_redraw_on_zoom) {
106  bu_vls_printf(gedp->ged_result_str, "onzoom");
107  } else {
108  bu_vls_printf(gedp->ged_result_str, "off");
109  }
110  printUsage = 0;
111  } else if (argc == 2) {
112  if (BU_STR_EQUAL(argv[1], "off")) {
113  /* lod redraw off */
114  gvp->gv_redraw_on_zoom = 0;
115  printUsage = 0;
116  } else if (BU_STR_EQUAL(argv[1], "onzoom")) {
117  /* lod redraw onzoom */
118  gvp->gv_redraw_on_zoom = 1;
119  printUsage = 0;
120  }
121  }
122  } else {
123  printUsage = 1;
124  }
125 
126  if (printUsage) {
127  bu_vls_printf(gedp->ged_result_str, "Usage:\n%s", usage);
128  return GED_ERROR;
129  }
130 
131  return GED_OK;
132 }
133 
134 
135 /*
136  * Local Variables:
137  * tab-width: 8
138  * mode: C
139  * indent-tabs-mode: t
140  * c-file-style: "stroustrup"
141  * End:
142  * ex: shiftwidth=4 tabstop=8
143  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
fastf_t gv_curve_scale
Definition: bview.h:260
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
Definition: bview.h:209
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int gv_adaptive_plot
Definition: bview.h:255
struct bu_vls * ged_result_str
Definition: ged.h:357
int gv_redraw_on_zoom
Definition: bview.h:256
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int ged_lod(struct ged *gedp, int argc, const char *argv[])
Definition: lod.c:38
#define GED_HELP
Definition: ged.h:62
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
fastf_t gv_point_scale
Definition: bview.h:259
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126