BRL-CAD
overlay.c
Go to the documentation of this file.
1 /* O V E R L A Y . 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/overlay.c
21  *
22  * The overlay command.
23  *
24  */
25 
26 #include "common.h"
27 
28 
29 #include "./ged_private.h"
30 
31 
32 int
33 ged_overlay(struct ged *gedp, int argc, const char *argv[])
34 {
35  int ret;
36  struct bn_vlblock*vbp;
37  FILE *fp;
38  double char_size;
39  char *name;
40  static const char *usage = "file.plot3 char_size [name]";
41 
44  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
45 
46  /* initialize result */
47  bu_vls_trunc(gedp->ged_result_str, 0);
48 
49  /* must be wanting help */
50  if (argc == 1) {
51  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
52  return GED_HELP;
53  }
54 
55  if (argc < 3 || 4 < argc) {
56  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
57  return GED_ERROR;
58  }
59 
60  if (sscanf(argv[2], "%lf", &char_size) != 1) {
61  bu_vls_printf(gedp->ged_result_str, "ged_overlay: bad character size - %s\n", argv[2]);
62  return GED_ERROR;
63  }
64 
65  if (argc == 3)
66  name = "_PLOT_OVERLAY_";
67  else
68  name = (char *)argv[3];
69 
70  if ((fp = fopen(argv[1], "rb")) == NULL) {
71  bu_vls_printf(gedp->ged_result_str, "ged_overlay: failed to open file - %s\n", argv[1]);
72  return GED_ERROR;
73  }
74 
75  vbp = rt_vlblock_init();
76  ret = rt_uplot_to_vlist(vbp, fp, char_size, gedp->ged_gdp->gd_uplotOutputMode);
77  fclose(fp);
78 
79  if (ret < 0) {
80  rt_vlblock_free(vbp);
81  return GED_ERROR;
82  }
83 
84  _ged_cvt_vlblock_to_solids(gedp, vbp, name, 0);
85  rt_vlblock_free(vbp);
86 
87  return GED_OK;
88 }
89 
90 
91 /*
92  * Local Variables:
93  * tab-width: 8
94  * mode: C
95  * indent-tabs-mode: t
96  * c-file-style: "stroustrup"
97  * End:
98  * ex: shiftwidth=4 tabstop=8
99  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void rt_vlblock_free(struct bn_vlblock *vbp)
Definition: vlist.c:78
Definition: ged.h:338
Definition: clone.c:90
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 bn_vlblock * rt_vlblock_init(void)
Definition: vlist.c:71
#define GED_ERROR
Definition: ged.h:61
int rt_uplot_to_vlist(struct bn_vlblock *vbp, FILE *fp, double char_size, int mode)
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int ged_overlay(struct ged *gedp, int argc, const char *argv[])
Definition: overlay.c:33
#define GED_CHECK_DRAWABLE(_gedp, _flags)
Definition: ged.h:129
struct bu_vls * ged_result_str
Definition: ged.h:357
struct ged_drawable * ged_gdp
Definition: ged.h:360
int gd_uplotOutputMode
output mode for unix plots
Definition: ged.h:318
void _ged_cvt_vlblock_to_solids(struct ged *gedp, struct bn_vlblock *vbp, const char *name, int copy)
Definition: draw.c:554
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