BRL-CAD
savekey.c
Go to the documentation of this file.
1 /* S A V E K E 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/savekey.c
21  *
22  * The savekey command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 
35 /**
36  * Write out the information that RT's -M option needs to show current view.
37  * Note that the model-space location of the eye is a parameter,
38  * as it can be computed in different ways.
39  * The is the OLD format, needed only when sending to RT on a pipe,
40  * due to some oddball hackery in RT to determine old -vs- new format.
41  */
42 static void
43 savekey_rt_oldwrite(struct ged *gedp, FILE *fp, fastf_t *eye_model)
44 {
45  int i;
46 
47  fprintf(fp, "%.9e\n", gedp->ged_gvp->gv_size);
48  fprintf(fp, "%.9e %.9e %.9e\n",
49  eye_model[X], eye_model[Y], eye_model[Z]);
50  for (i = 0; i < 16; i++) {
51  fprintf(fp, "%.9e ", gedp->ged_gvp->gv_rotation[i]);
52  if ((i%4) == 3)
53  fprintf(fp, "\n");
54  }
55  fprintf(fp, "\n");
56 }
57 
58 
59 int
60 ged_savekey(struct ged *gedp, int argc, const char *argv[])
61 {
62  FILE *fp;
63  fastf_t timearg;
64  vect_t eye_model;
65  vect_t temp;
66  static const char *usage = "file [time]";
67 
70  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
71 
72  /* initialize result */
73  bu_vls_trunc(gedp->ged_result_str, 0);
74 
75  /* must be wanting help */
76  if (argc == 1) {
77  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
78  return GED_HELP;
79  }
80 
81  if (argc < 2 || 3 < argc) {
82  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
83  return GED_ERROR;
84  }
85 
86  if ((fp = fopen(argv[1], "a")) == NULL) {
87  perror(argv[1]);
88  return TCL_ERROR;
89  }
90  if (argc > 2) {
91  timearg = atof(argv[2]);
92  fprintf(fp, "%f\n", timearg);
93  }
94  /*
95  * Eye is in conventional place.
96  */
97  VSET(temp, 0.0, 0.0, 1.0);
98  MAT4X3PNT(eye_model, gedp->ged_gvp->gv_view2model, temp);
99  savekey_rt_oldwrite(gedp, fp, eye_model);
100  (void)fclose(fp);
101 
102  return GED_OK;
103 }
104 
105 
106 /*
107  * Local Variables:
108  * tab-width: 8
109  * mode: C
110  * indent-tabs-mode: t
111  * c-file-style: "stroustrup"
112  * End:
113  * ex: shiftwidth=4 tabstop=8
114  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
#define VSET(a, b, c, d)
Definition: color.c:53
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.
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
mat_t gv_view2model
Definition: bview.h:224
Definition: color.c:49
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
fastf_t gv_size
2.0 * scale
Definition: bview.h:212
struct bu_vls * ged_result_str
Definition: ged.h:357
mat_t gv_rotation
Definition: bview.h:220
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
Definition: color.c:51
double fastf_t
Definition: defines.h:300
int ged_savekey(struct ged *gedp, int argc, const char *argv[])
Definition: savekey.c:60
Definition: color.c:50