BRL-CAD
annotate.c
Go to the documentation of this file.
1 /* A N N O T A T E . 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/annotate.c
21  *
22  * The annotate command.
23  *
24  * Examples:
25  *
26  * annotate
27  * [text {string}]
28  * [as label|leader|angular|radial|dimension|table|note|box|axes|plane [named {name}]]
29  * [on|for {object1} [and {object2}] [and {...}]]
30  * [to|thru|at {point|plane} [offset {distance|vector}]]
31  * [align auto|model|view]
32  * [position auto|fixed|absolute|relative]
33  * [visible always|never|rendering|wireframe]
34  *
35  * [help]
36  * [list {name}]
37  * [get {key} from {name}]
38  * [set {key=value} on {name}]
39  *
40  * annotate help
41  * annotate text "Hello, World!"
42  * annotate for all.g
43  * annotate as label named my.note for all.g text "This is a tank."
44  * annotate as box text "This geometry is unclassified."
45  *
46  * DESIGN OPTIONS TO CONSIDER:
47  *
48  * Types: text (see Text), leader, angular, radial, aligned, ordinate, linear
49  *
50  * Extended types: note, label, table, dimension, tolerance, box (see Box), axes, plane
51  *
52  * Orientation: auto, horizontal, vertical, above, below, inline
53  *
54  * Align: auto, model, view
55  *
56  * Text: fontname, fontsize, fontstyle (regular, italic, bold), linespacing, justification
57  * Justification:
58  * undefined
59  * left
60  * center
61  * right
62  * bottom
63  * middle
64  * top
65  * bottomleft
66  * bottomcenter
67  * bottomright
68  * middleleft
69  * middlecenter
70  * middleright
71  * topleft
72  * topcenter
73  * topright
74  *
75  * Decoration: color, leader line, box (see Box) around target, box around annotation
76  *
77  * Box: empty, hatch, gradient, solid
78  *
79  * Placement: position (auto/fixed/relative/absolute), scale, orientation/rotation/twist, head/tail
80  * auto is automatic static placement
81  * fixed is 2d coordinate relative to view
82  * absolute is 2d coordinate relative to world center or global 3d position
83  * relative is 2d coordinate relative to view center or 3d offset distance from target center
84  *
85  * Leader: linelength, linewidth, type (no head, arrow head, round head, square head)
86  *
87  * Visibility: auto, wireframe, render, both
88  *
89  * linearformat: "%.2f"
90  * linearunits: mm, m, in, ft, etc.
91  *
92  * angularformat: "%.2f"
93  * angularunits: degrees, radians
94  *
95  * struct parameters:
96  * type
97  * plane
98  * point list
99  * text?
100  * color?
101  * visibility?
102  *
103  */
104 
105 #include "common.h"
106 
107 #include <string.h>
108 
109 #include "ged.h"
110 
111 
112 void
113 annotate_help(struct bu_vls *result, const char *cmd)
114 {
115  static const char *usage = "[object(s)] [-n name] [-p x y z]";
116 
117  bu_vls_printf(result, "Usage: %s %s", cmd, usage);
118 }
119 
120 
121 int
122 ged_annotate(struct ged *gedp, int argc, const char *argv[])
123 {
124  char **object_argv;
125  const char *argv0 = argv[0];
126  struct bu_vls objects = BU_VLS_INIT_ZERO;
127  int object_count = 0;
128  int i;
129 
131  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
132 
133  /* initialize result */
134  bu_vls_trunc(gedp->ged_result_str, 0);
135 
136  /* must be wanting help */
137  if (argc == 1) {
138  annotate_help(gedp->ged_result_str, argv0);
139  return GED_HELP;
140  }
141 
143 
144  /* stash objects, quoting them if they include spaces */
145  for (i = 1; i < argc; i++) {
146  bu_log("DEBUG: argv[%d] == %s\n", i, argv[i]);
147 
148  if (argv[i][0] != '-') {
149  object_count++;
150  if (i != 1)
151  bu_vls_putc(&objects, ' ');
152  bu_vls_from_argv(&objects, 1, &(argv[i]));
153  } else {
154  break;
155  }
156  }
157  bu_log("DEBUG: objects: [%s]\n", bu_vls_addr(&objects));
158 
159  object_argv = (char **)bu_calloc(object_count+1, sizeof(char *), "alloc object argv");
160  bu_argv_from_string(object_argv, object_count, bu_vls_addr(&objects));
161  for (i = 0; i < object_count; i++) {
162  bu_log("DEBUG: stashed [%s]\n", object_argv[i]);
163  }
164 
165  bu_vls_free(&objects);
166  bu_free((void *)object_argv, "ged_annotate");
167 
168  return GED_OK;
169 }
170 
171 
172 /*
173  * Local Variables:
174  * tab-width: 8
175  * mode: C
176  * indent-tabs-mode: t
177  * c-file-style: "stroustrup"
178  * End:
179  * ex: shiftwidth=4 tabstop=8
180  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
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.
#define GED_ERROR
Definition: ged.h:61
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
void bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
Definition: vls.c:532
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
int ged_annotate(struct ged *gedp, int argc, const char *argv[])
Definition: annotate.c:122
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
void annotate_help(struct bu_vls *result, const char *cmd)
Definition: annotate.c:113
#define GED_HELP
Definition: ged.h:62
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
size_t bu_argv_from_string(char *argv[], size_t lim, char *lp)
Definition: argv.c:32
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
Definition: vls.h:56
void bu_vls_putc(struct bu_vls *vp, int c)
Definition: vls.c:666