BRL-CAD
plot.c
Go to the documentation of this file.
1 /* P L O T . 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/plot.c
21  *
22  * The plot command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "bn.h"
33 #include "plot3.h"
34 
35 
36 #include "./ged_private.h"
37 
38 
39 /*
40  * plot file [opts]
41  * potential options might include:
42  * grid, 3d w/color, |filter, infinite Z
43  */
44 int
45 ged_plot(struct ged *gedp, int argc, const char *argv[])
46 {
47  FILE *fp;
48  int Three_D; /* 0=2-D -vs- 1=3-D */
49  int Z_clip; /* Z clipping */
50  int floating; /* 3-D floating point plot */
51  int is_pipe = 0;
52  static const char *usage = "file [2|3] [f] [g] [z]";
53 
57  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
58 
59  /* initialize result */
60  bu_vls_trunc(gedp->ged_result_str, 0);
61 
62  /* must be wanting help */
63  if (argc == 1) {
64  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
65  return GED_HELP;
66  }
67 
68  /* Process any options */
69  Three_D = 1; /* 3-D w/color, by default */
70  Z_clip = 0; /* NO Z clipping, by default*/
71  floating = 0;
72  while (argv[1] != (char *)0 && argv[1][0] == '-') {
73  switch (argv[1][1]) {
74  case 'f':
75  floating = 1;
76  break;
77  case '3':
78  Three_D = 1;
79  break;
80  case '2':
81  Three_D = 0; /* 2-D, for portability */
82  break;
83  case 'g':
84  /* do grid */
85  bu_vls_printf(gedp->ged_result_str, "%s: grid unimplemented\n", argv[0]);
86  break;
87  case 'z':
88  case 'Z':
89  /* Enable Z clipping */
90  bu_vls_printf(gedp->ged_result_str, "%s: Clipped in Z to viewing cube\n", argv[0]);
91  Z_clip = 1;
92  break;
93  default:
94  bu_vls_printf(gedp->ged_result_str, "%s: bad PLOT option %s\n", argv[0], argv[1]);
95  break;
96  }
97  argv++;
98  }
99  if (argv[1] == (char *)0) {
100  bu_vls_printf(gedp->ged_result_str, "%s: no filename or filter specified\n", argv[0]);
101  return GED_ERROR;
102  }
103  if (argv[1][0] == '|') {
104  struct bu_vls str = BU_VLS_INIT_ZERO;
105  bu_vls_strcpy(&str, &argv[1][1]);
106  while ((++argv)[1] != (char *)0) {
107  bu_vls_strcat(&str, " ");
108  bu_vls_strcat(&str, argv[1]);
109  }
110  if ((fp = popen(bu_vls_addr(&str), "w")) == NULL) {
111  perror(bu_vls_addr(&str));
112  return GED_ERROR;
113  }
114 
115  bu_vls_printf(gedp->ged_result_str, "piped to %s\n", bu_vls_addr(&str));
116  bu_vls_free(&str);
117  is_pipe = 1;
118  } else {
119  if ((fp = fopen(argv[1], "w")) == NULL) {
120  perror(argv[1]);
121  return GED_ERROR;
122  }
123 
124  bu_vls_printf(gedp->ged_result_str, "plot stored in %s\n", argv[1]);
125  is_pipe = 0;
126  }
127 
128  dl_plot(gedp->ged_gdp->gd_headDisplay, fp, gedp->ged_gvp->gv_model2view, floating, gedp->ged_gvp->gv_center, gedp->ged_gvp->gv_scale, Three_D, Z_clip);
129 
130  if (is_pipe)
131  (void)pclose(fp);
132  else
133  (void)fclose(fp);
134 
135  return GED_ERROR;
136 }
137 
138 
139 /*
140  * Local Variables:
141  * tab-width: 8
142  * mode: C
143  * indent-tabs-mode: t
144  * c-file-style: "stroustrup"
145  * End:
146  * ex: shiftwidth=4 tabstop=8
147  */
void usage(struct ged *gedp)
Definition: coil.c:315
mat_t gv_center
Definition: bview.h:221
int ged_plot(struct ged *gedp, int argc, const char *argv[])
Definition: plot.c:45
Definition: ged.h:338
void dl_plot(struct bu_list *hdlp, FILE *fp, mat_t model2view, int floating, mat_t center, fastf_t scale, int Three_D, int Z_clip)
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
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.
struct bu_list * gd_headDisplay
head of display list
Definition: ged.h:307
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
fastf_t gv_scale
Definition: bview.h:211
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
struct ged_drawable * ged_gdp
Definition: ged.h:360
mat_t gv_model2view
Definition: bview.h:222
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
void bu_vls_strcpy(struct bu_vls *vp, const char *s)
Definition: vls.c:310
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
Definition: vls.h:56