BRL-CAD
zoom.c
Go to the documentation of this file.
1 /* Z O O M . 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 
21 #include "common.h"
22 
23 #include "ged.h"
24 
25 HIDDEN int
26 zoom(struct ged *gedp, double sf)
27 {
28  gedp->ged_gvp->gv_scale /= sf;
29  if (gedp->ged_gvp->gv_scale < RT_MINVIEWSCALE)
31  gedp->ged_gvp->gv_size = 2.0 * gedp->ged_gvp->gv_scale;
32  gedp->ged_gvp->gv_isize = 1.0 / gedp->ged_gvp->gv_size;
33  ged_view_update(gedp->ged_gvp);
34 
35  return GED_OK;
36 }
37 
38 
39 int
40 ged_zoom(struct ged *gedp, int argc, const char *argv[])
41 {
42  int ret;
43  double sf = 1.0;
44 
46  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
47 
48  /* initialize result */
49  bu_vls_trunc(gedp->ged_result_str, 0);
50 
51  /* must be wanting help */
52  if (argc != 2) {
53  bu_vls_printf(gedp->ged_result_str, "Usage: %s scale_factor", argv[0]);
54  return (argc == 1) ? GED_HELP : GED_ERROR;
55  }
56 
57  /* get the scale factor */
58  ret = sscanf(argv[1], "%lf", &sf);
59  if (ret != 1 || sf < SMALL_FASTF || sf > INFINITY) {
60  bu_vls_printf(gedp->ged_result_str, "ERROR: bad scale factor [%s]", argv[1]);
61  return GED_ERROR;
62  }
63 
64  return zoom(gedp, sf);
65 }
66 
67 
68 HIDDEN int
69 zoom_load(struct ged *gedp)
70 {
71  extern const struct ged_cmd *zoom_cmd(void);
72 
73  const struct ged_cmd *cmd = zoom_cmd();
74  return gedp->add(cmd);
75 }
76 
77 
78 HIDDEN void
79 zoom_unload(struct ged *gedp)
80 {
81  gedp->del("zoom");
82 }
83 
84 
85 const struct ged_cmd *
86 zoom_cmd(void)
87 {
88  static struct ged_cmd cmd = {
90  "zoom",
91  "zoom view by specified scale factor",
92  "zoom",
93  &zoom_load,
94  &zoom_unload,
95  &ged_zoom
96  };
98  return &cmd;
99 }
100 
101 /*
102  * Local Variables:
103  * tab-width: 8
104  * mode: C
105  * indent-tabs-mode: t
106  * c-file-style: "stroustrup"
107  * End:
108  * ex: shiftwidth=4 tabstop=8
109  */
#define GED_OK
Definition: ged.h:55
int ged_zoom(struct ged *gedp, int argc, const char *argv[])
Definition: zoom.c:40
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
#define BU_LIST_INIT_ZERO
Definition: list.h:167
#define BU_LIST_MAGIC_SET(_l, _magic)
Definition: list.h:129
#define GED_CMD_MAGIC
Definition: magic.h:176
Header file for the BRL-CAD common definitions.
void ged_view_update(struct bview *gvp)
Definition: vutil.c:33
#define GED_ERROR
Definition: ged.h:61
HIDDEN int zoom_load(struct ged *gedp)
Definition: zoom.c:69
#define HIDDEN
Definition: common.h:86
struct bview * ged_gvp
Definition: ged.h:361
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
int(* del)(const char *name)
Definition: ged.h:379
fastf_t gv_isize
1.0 / size
Definition: bview.h:213
fastf_t gv_scale
Definition: bview.h:211
fastf_t gv_size
2.0 * scale
Definition: bview.h:212
int(* add)(const struct ged_cmd *cmd)
Definition: ged.h:378
struct bu_vls * ged_result_str
Definition: ged.h:357
HIDDEN int zoom(struct ged *gedp, double sf)
Definition: zoom.c:26
HIDDEN void zoom_unload(struct ged *gedp)
Definition: zoom.c:79
Definition: ged.h:399
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
struct bu_list l
Definition: ged.h:400
#define GED_HELP
Definition: ged.h:62
const struct ged_cmd * zoom_cmd(void)
Definition: zoom.c:86
#define RT_MINVIEWSCALE
Definition: raytrace.h:1302