/
overlay.c
273 lines (221 loc) · 6.8 KB
/
overlay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* O V E R L A Y . C
* BRL-CAD
*
* Copyright (c) 1988-2014 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
/** @file mged/overlay.c
*
*/
#include "common.h"
#include <math.h>
#include <signal.h>
#include "vmath.h"
#include "raytrace.h"
#include "./mged.h"
#include "./sedit.h"
#include "./mged_dm.h"
/* Usage: overlay file.plot3 [name] */
int
cmd_overlay(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[])
{
int ret;
Tcl_DString ds;
int ac;
const char *av[5];
struct bu_vls char_size = BU_VLS_INIT_ZERO;
if (gedp == GED_NULL)
return TCL_OK;
Tcl_DStringInit(&ds);
if (argc == 1) {
Tcl_DStringAppend(&ds, "file.plot3 [name]", -1);
Tcl_DStringResult(interp, &ds);
return TCL_OK;
}
ac = argc + 1;
bu_vls_printf(&char_size, "%lf", view_state->vs_gvp->gv_scale * 0.01);
av[0] = argv[0]; /* command name */
av[1] = argv[1]; /* plotfile name */
av[2] = bu_vls_addr(&char_size);
if (argc == 3) {
av[3] = argv[2]; /* name */
av[4] = (char *)0;
} else
av[3] = (char *)0;
ret = ged_overlay(gedp, ac, (const char **)av);
Tcl_DStringAppend(&ds, bu_vls_addr(gedp->ged_result_str), -1);
Tcl_DStringResult(interp, &ds);
if (ret != GED_OK)
return TCL_ERROR;
update_views = 1;
bu_vls_free(&char_size);
return ret;
}
/* Usage: labelvert solid(s) */
int
f_labelvert(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[])
{
struct display_list *gdlp;
struct display_list *next_gdlp;
int i;
struct bn_vlblock*vbp;
struct directory *dp;
mat_t mat;
fastf_t scale;
CHECK_DBI_NULL;
if (argc < 2) {
struct bu_vls vls = BU_VLS_INIT_ZERO;
bu_vls_printf(&vls, "help labelvert");
Tcl_Eval(interp, bu_vls_addr(&vls));
bu_vls_free(&vls);
return TCL_ERROR;
}
vbp = rt_vlblock_init();
MAT_IDN(mat);
bn_mat_inv(mat, view_state->vs_gvp->gv_rotation);
scale = view_state->vs_gvp->gv_size / 100; /* divide by # chars/screen */
for (i=1; i<argc; i++) {
struct solid *s;
if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL)
continue;
/* Find uses of this solid in the solid table */
gdlp = BU_LIST_NEXT(display_list, gedp->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, gedp->ged_gdp->gd_headDisplay)) {
next_gdlp = BU_LIST_PNEXT(display_list, gdlp);
FOR_ALL_SOLIDS(s, &gdlp->dl_headSolid) {
if (db_full_path_search(&s->s_fullpath, dp)) {
rt_label_vlist_verts(vbp, &s->s_vlist, mat, scale, base2local);
}
}
gdlp = next_gdlp;
}
}
cvt_vlblock_to_solids(vbp, "_LABELVERT_", 0);
bn_vlblock_free(vbp);
update_views = 1;
return TCL_OK;
}
void get_face_list(const struct model* m, struct face** f_list )
{
struct nmgregion *r;
struct shell *s;
struct faceuse *fu;
struct face *f;
int idx = 0;
NMG_CK_MODEL(m);
for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) {
NMG_CK_REGION(r);
if (r->ra_p) {
NMG_CK_REGION_A(r->ra_p);
}
for (BU_LIST_FOR(s, shell, &r->s_hd)) {
NMG_CK_SHELL(s);
if (s->sa_p) {
NMG_CK_SHELL_A(s->sa_p);
}
/* Faces in shell */
for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
NMG_CK_FACEUSE(fu);
f = fu->f_p;
NMG_CK_FACE(f);
f_list[idx++] = f;
if (f->g.magic_p) switch (*f->g.magic_p) {
case NMG_FACE_G_PLANE_MAGIC:
break;
case NMG_FACE_G_SNURB_MAGIC:
break;
}
}
}
}
}
/* Usage: labelface solid(s) */
int
f_labelface(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[])
{
struct rt_db_internal internal;
struct directory *dp;
struct display_list *gdlp;
struct display_list *next_gdlp;
int i;
struct bn_vlblock *vbp;
mat_t mat;
fastf_t scale;
struct model* m;
const char* name;
struct face* f_list[50] = {0};
/* attempt to resolve and verify */
name = argv[1];
if ( (dp=db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET))
== RT_DIR_NULL ) {
bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", name);
return GED_ERROR;
}
if (rt_db_get_internal(&internal, dp, gedp->ged_wdbp->dbip,
bn_mat_identity, &rt_uniresource) < 0) {
bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n");
return GED_ERROR;
}
if (internal.idb_type != ID_NMG) {
bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name);
rt_db_free_internal(&internal);
return GED_ERROR;
}
m = (struct model *)internal.idb_ptr;
NMG_CK_MODEL(m);
CHECK_DBI_NULL;
if (argc < 2) {
struct bu_vls vls = BU_VLS_INIT_ZERO;
bu_vls_printf(&vls, "help labelface");
Tcl_Eval(interp, bu_vls_addr(&vls));
bu_vls_free(&vls);
return TCL_ERROR;
}
vbp = rt_vlblock_init();
MAT_IDN(mat);
bn_mat_inv(mat, view_state->vs_gvp->gv_rotation);
scale = view_state->vs_gvp->gv_size / 100; /* divide by # chars/screen */
for (i=1; i<argc; i++) {
struct solid *s;
if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL)
continue;
/* Find uses of this solid in the solid table */
gdlp = BU_LIST_NEXT(display_list, gedp->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, gedp->ged_gdp->gd_headDisplay)) {
next_gdlp = BU_LIST_PNEXT(display_list, gdlp);
FOR_ALL_SOLIDS(s, &gdlp->dl_headSolid) {
if (db_full_path_search(&s->s_fullpath, dp)) {
get_face_list(m, &f_list[0]);
rt_label_vlist_faces(vbp, &f_list[0], mat, scale, base2local);
}
}
gdlp = next_gdlp;
}
}
cvt_vlblock_to_solids(vbp, "_LABELFACE_", 0);
bn_vlblock_free(vbp);
update_views = 1;
return TCL_OK;
}
/*
* Local Variables:
* mode: C
* tab-width: 8
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/