BRL-CAD
polybinout.c
Go to the documentation of this file.
1 /* P O L Y B I N O U T . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1990-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program 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 program 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 
21 #include "common.h"
22 
23 #include <string.h>
24 #include <math.h>
25 #include <signal.h>
26 
27 #include "vmath.h"
28 #include "mater.h"
29 
30 
31 #include "ged.h"
32 #include "./ged_private.h"
33 
34 /*
35  * Interface for writing binary polygons that represent
36  * the current (evaluated) view.
37  *
38  * Usage: polybinout file
39  */
40 int
41 ged_polybinout(struct ged *gedp, int argc, const char *argv[])
42 {
43  FILE *fp;
44  struct polygon_header ph;
45  static const char *usage = "Usage: polybinout file";
46 
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 == 1) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_HELP;
57  }
58 
59  if (argc != 2) {
60  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
61  return GED_ERROR;
62  }
63 
64  ph.npts = 0;
65 
66  if ((fp = fopen(argv[1], "w")) == NULL) {
67  perror(argv[1]);
68  bu_vls_printf(gedp->ged_result_str, "%s: Unable to open %s for writing\n", argv[0], argv[1]);
69  return GED_ERROR;
70  }
71 
72  dl_polybinout(gedp->ged_gdp->gd_headDisplay, &ph, fp);
73 
74  fclose(fp);
75  return GED_OK;
76 }
77 
78 
79 /*
80  * Local Variables:
81  * mode: C
82  * tab-width: 8
83  * indent-tabs-mode: t
84  * c-file-style: "stroustrup"
85  * End:
86  * ex: shiftwidth=4 tabstop=8
87  */
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.
int ged_polybinout(struct ged *gedp, int argc, const char *argv[])
Definition: polybinout.c:41
struct bu_list * gd_headDisplay
head of display list
Definition: ged.h:307
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
struct bu_vls * ged_result_str
Definition: ged.h:357
struct ged_drawable * ged_gdp
Definition: ged.h:360
int npts
Definition: ged.h:462
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 dl_polybinout(struct bu_list *hdlp, struct polygon_header *ph, FILE *fp)