BRL-CAD
Loading...
Searching...
No Matches
edit.h
Go to the documentation of this file.
1/* E D I T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2025 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 edit.h
21 *
22 * NOTE!!! This API is a work in progress as we migrate and consolidate
23 * editing code from MGED, libged and other codes to a unified common
24 * implementation in LIBRT. Until this notice is removed, there are NO
25 * guarantees of API stability with this code!
26 */
27
28#ifndef RT_EDIT_H
29#define RT_EDIT_H
30
31#include "common.h"
32#include "vmath.h"
33#include "bn/mat.h"
34#include "bv/defines.h"
35#include "rt/defines.h"
36#include "rt/db_internal.h"
37#include "rt/resource.h"
38
40
41// Settings used for both solid and matrix edits
42#define RT_EDIT_DEFAULT -1
43#define RT_EDIT_IDLE 0
44
45
46// Solid editing (done via sed in MGED) alters primitive parameters to produce
47// new shapes. Parameters are updated immediately, allowing for new wireframe
48// generation from primitive plot commands. Not supported for combs.
49//
50// Translate, rotate and scale can typically be applied to any geometry object,
51// without needing awareness of the details of the object's definition. The
52// primitives themselves define more specific per-data editing flags.
53#define RT_PARAMS_EDIT_TRANS 1
54#define RT_PARAMS_EDIT_SCALE 2 // Scale whole solid by scalar
55#define RT_PARAMS_EDIT_ROT 3
56
57// This isn't an edit operation as such in that it doesn't (and won't) change
58// the geometry itself - rather it is used in edit_mode to indicate a
59// particular selection state.
60//
61// Eventually it might very well end up being used for an edit flag - it is
62// quite reasonable to think that ft_edit_xy might take this flag and a mouse
63// argument to select the geometrically closest editing feature from the solid
64// and set the appropriate edit flag and/or per-prim data structure info - but
65// right now we don't have anything like that.
66#define RT_PARAMS_EDIT_PICK 5
67
68// Matrix editing (done via oed in MGED) alters a matrix rather than solid
69// parameters in its intermediate stages (at the end when changes are written
70// to disk, and if a solid is being edited rather than a comb the matrix
71// changes are translated by the per-primitive routines to new solid parameters
72// at that time.)
73#define RT_MATRIX_EDIT_ROT 6
74
75// Matrix translate operations are specified relative to the VIEW XY, NOT the
76// model space coordinate system. I.e. the resulting translations are view
77// dependent.
78//
79// Not sure what the history is here - I suppose the thinking might be that
80// the view can be set to axis align to get constrained movement in model
81// coordinate space, and this allows for other constraints as well when the
82// view is adjusted, but it has a definite drawback if the user wants to
83// watch the movement of the solid along a model space X,Y or Z axis from
84// another view while editing. Also has the drawback that it is inconsistent
85// with the matrix scale edit ops, which appear to be scaling relative to the
86// model coordinate system.
87//
88// TODO - Should additional edit operations be defined for constrained
89// translating on the model axis directions?
90#define RT_MATRIX_EDIT_TRANS_VIEW_XY 7
91#define RT_MATRIX_EDIT_TRANS_VIEW_X 8
92#define RT_MATRIX_EDIT_TRANS_VIEW_Y 9
94// Non-uniform scale operations scale relative to the MODEL coordinate system,
95// NOT the view plane.
96//
97// Note that the underlying solids do not always support directly expressing
98// the shapes that can be created with these opts using comb instances (for
99// example, a TOR scaled in the X direction) and the edit will be rejected in
100// those cases. Just because a comb instance of a solid can be stretched, that
101// does not mean the solid itself can support that shape. Consequently, it is
102// recommended that the _X, _Y and _Z versions of the scale operations be used
103// sparingly if at all. Even if a comb instance's tree is able to support
104// rendering such an operation at the time the original edit is made, a
105// subsequent editing of that tree could add new geometry and ultimately result
106// in an inability to apply the matrix successfully to all leaf solids.
107#define RT_MATRIX_EDIT_SCALE 10
108#define RT_MATRIX_EDIT_SCALE_X 11
109#define RT_MATRIX_EDIT_SCALE_Y 12
110#define RT_MATRIX_EDIT_SCALE_Z 13
112
113struct rt_edit_map;
114
115struct rt_edit {
117 struct rt_edit_map *m;
119 // Optional logging of messages from editing code
120 struct bu_vls *log_str;
122 // Container to hold the intermediate state
123 // of the object being edited
124 struct rt_db_internal es_int;
126 // When we're editing a comb instance, we need to record which specific
127 // instance(s) we're working with. db_find_named_leaf is what finds the
128 // named instance that the editing matrix will ultimately be applied to.
129 //
130 // Although normally we're either transforming the whole comb (i.e. the
131 // matrix gets applied to ALL instances in the comb tree) or operating on a
132 // single instance, there is nothing conceptually that would prevent the
133 // editing of multiple instances.
134 //
135 // In the interest of making the API flexible, we use a bu_ptbl to hold
136 // pointers to tr_l.tl_name strings in the es_int comb tree to identify all
137 // active instances in the comb that are actually being edited. (An empty
138 // bu_ptbl means edit all of them.) For any object type other than combs
139 // this tbl is ignored.
140 //
141 // An edit operation on a comb will populate this with the active instance(s).
142 // which in turn means the edit structure will have enough information for
143 // application level drawing code to figure out which solids in the comb need
144 // to be visualized as part of the active editing geometry.
145 struct bu_ptbl comb_insts;
147 // Tolerance for calculations
148 const struct bn_tol *tol;
150 // Main view associated with the edit. This may not be the only view in
151 // which the edit is *visible*, but this should hold the pointer to the
152 // view which will be used to drive any view dependent edit ops.
153 struct bview *vp;
154 // Knob based editing data
155 struct bview_knobs k;
157 // Current editing operation. This holds the exact operation being
158 // performed (for example, ECMD_TGC_SCALE_A to scale a tgc primitive's
159 // A vector). The RT_PARAM_* and RT_MATRIX_* values may also be set
160 // here, if the operations being performed are the more generic/general
161 // cases.
162 int edit_flag;
164 // MGED wants to know if we're in solid rotate, translate or scale mode,
165 // even if edit_flag is set to a more specific mode. (TODO - why?)
166 // Rather than keying off of primitive specific edit op types, have the ops
167 // set a flag. Options are:
168 //
169 // RT_PARAMS_EDIT_TRANS
170 // RT_PARAMS_EDIT_SCALE
171 // RT_PARAMS_EDIT_ROT
172 // RT_PARAMS_EDIT_PICK
173 //
174 // (TODO - should we be setting this for matrix and pscale values as well?
175 // The above were originally driven by MGED code, which IIRC was using it
176 // for awareness of cases when primitive specific edits need specific
177 // interaction modes...)
178 //
179 // NOTE - this is only active in the new librt editing code - MGED uses
180 // primitive aware defines to do this instead (ew) so in the main branch
181 // it is not used except in the state save/restore functions.
182 int edit_mode;
183
184 fastf_t es_scale; /* scale factor */
185 mat_t incr_change; /* change(s) from last cycle */
186
187 /* Matrix-based editing visualizations are a different beast from edits
188 * that change primitive parameters. In the latter case, we must
189 * regenerate vlists based on new object parameters. Applications
190 * supporting solid editing need to be able to support visualizing an
191 * entity whose source geometry visualization data is constantly changing.
192 *
193 * Combs, on the other hand, have a wireframe representation that consists
194 * of one or more individual primitive wireframes from OTHER solids -
195 * potentially *thousands* of them for large models. Nor to matrix edits
196 * typically call for a wireframe regeneration - tra and rot operations
197 * definitely don't, and while scaled primitives might be more smoothly
198 * represented by refreshed wireframes not all matrix edits can be
199 * successfully translated to primitive param updates in all cases. As
200 * a result, for matrix-based editing wireframes are treated as static
201 * data to be manipulated.
202 *
203 * Consequently, rather than generating copies of all those wireframes and
204 * modifying them all every time an incremental edit is made, a more
205 * efficient option is to re-use any existing wireframes the app already
206 * has loaded for the comb tree in question and distort the *view space* to
207 * reflect the editing operation while doing the draw. Because the source
208 * wireframe data isn't changing, view distortion drawing is feasible.
209 *
210 * Combs are *only* editable via matrix manipulations, so rather than
211 * trying to manage the comb's editing visualization data in this struct
212 * the problem is "punted" to the application, which can decide for itself
213 * whether and how to reuse any existing wireframe information when drawing
214 * editing objects.
215 *
216 * To use model_changes to generate appropriate matrices for this purpose,
217 * the pattern looks like the following:
218 *
219 * mat_t model2objview;
220 * struct bview *vp = <current view pointer>;
221 * bn_mat_mul(model2objview, vp->gv_model2view, s->model_changes);
222 * ## A second bn_mat_mul might be needed if a perspective matrix is in use
223 * dm_loadmatrix(DMP, model2objview, which_eye);
224 * ## Do the drawing
225 */
226 mat_t model_changes; /* full changes this edit */
227
228 mat_t model2objview; /* Matrix for applying model_changes to view objects (used for matrix xy translation) */
230 fastf_t acc_sc[3]; /* accumulate local object scale factors */
231 fastf_t acc_sc_obj; /* accumulate global object scale factor */
232 fastf_t acc_sc_sol; /* accumulate solid scale factor */
233 mat_t acc_rot_sol; /* accumulate solid rotations */
235 int e_keyfixed; /* keypoint specified by user? */
236 point_t e_keypoint; /* center of editing xforms */
237 const char *e_keytag; /* string identifying the keypoint */
239 int e_mvalid; /* e_mparam valid. e_inpara must = 0 */
240 vect_t e_mparam; /* mouse input param. Only when es_mvalid set */
241
242 int e_inpara; /* parameter input from keyboard flag. 1 == e_para valid. e_mvalid must = 0 */
243 vect_t e_para; /* keyboard input parameter changes */
244
245 mat_t e_invmat; /* inverse of e_mat KAA */
246 mat_t e_mat; /* accumulated matrix of path */
247
248 point_t curr_e_axes_pos; /* center of editing xforms */
250
251 // Conversion factors
253 double local2base;
254
255 // Trigger for view updating
257
258 // vlfree list
260
261 /* Flag to trigger some primitive edit opts to use keypoint (and maybe other behaviors?) */
263
264 /* Internal primitive editing information specific to primitive types. */
265 void *ipe_ptr;
266
267 /* User pointer */
268 void *u_ptr;
269};
270
271/** Create and initialize an rt_edit struct */
272RT_EXPORT extern struct rt_edit *
273rt_edit_create(struct db_full_path *dfp, struct db_i *dbip, struct bn_tol *, struct bview *v);
274
275/** Free a rt_edit struct */
276RT_EXPORT extern void
277rt_edit_destroy(struct rt_edit *s);
278
279/* Logic for working with editing callback maps.
281 * Editing callback maps allow applications to register logic to be executed for particular
282 * commands or the pre-defined standard registration points which are general to all commands,
283 * per the defines below. */
284#define ECMD_CLEAR_CLBKS 0
285#define ECMD_PRINT_STR 10
286#define ECMD_PRINT_RESULTS 20
287#define ECMD_EAXES_POS 30
288#define ECMD_REPLOT_EDITING_SOLID 40
289#define ECMD_VIEW_UPDATE 50
290#define ECMD_VIEW_SET_FLAG 60
291#define ECMD_MENU_SET 70
292#define ECMD_GET_FILENAME 80
294RT_EXPORT extern struct rt_edit_map *
296RT_EXPORT extern void
298RT_EXPORT extern int
299rt_edit_map_clbk_set(struct rt_edit_map *em, int ed_cmd, int mode, bu_clbk_t f, void *d);
300RT_EXPORT extern int
301rt_edit_map_clbk_get(bu_clbk_t *f, void **d, struct rt_edit_map *em, int ed_cmd, int mode);
302RT_EXPORT extern int
304RT_EXPORT extern int
305rt_edit_map_copy(struct rt_edit_map *om, struct rt_edit_map *im);
307/* Functions for manipulating rt_edit data */
308RT_EXPORT extern void
309rt_get_solid_keypoint(struct rt_edit *s, point_t *pt, const char **strp, fastf_t *mat);
310
311RT_EXPORT extern void
313
314RT_EXPORT extern int
316 struct rt_edit *s,
317 vect_t *rvec, int *do_rot, vect_t *tvec, int *do_tran, int *do_sca,
318 struct bview *v, const char *cmd, fastf_t f,
319 char origin, int incr_flag, void *u_data
320 );
321
322RT_EXPORT extern void
323rt_knob_edit_rot(struct rt_edit *s,
324 char coords,
325 char rotate_about,
328 );
329
330RT_EXPORT extern void
331rt_knob_edit_tran(struct rt_edit *s,
332 char coords,
333 int matrix_edit,
335
336RT_EXPORT extern void
338 struct rt_edit *s,
339 int matrix_edit);
341/* Equivalent to sedit - run editing logic after input data is set in
342 * rt_edit container */
343RT_EXPORT extern void
344rt_edit_process(struct rt_edit *s);
345
346
347/* Edit menu items encode information about specific edit operations, as well
348 * as info documenting them. Edit functab methods use this data type. */
349struct rt_edit_menu_item {
350 char *menu_string;
351 void (*menu_func)(struct rt_edit *, int, int, int, void *);
357
358#endif /* RT_EDIT_H */
359
360/*
361 * Local Variables:
362 * tab-width: 8
363 * mode: C
364 * indent-tabs-mode: t
365 * c-file-style: "stroustrup"
366 * End:
367 * ex: shiftwidth=4 tabstop=8
368 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int(* bu_clbk_t)(int, const char **, void *, void *)
Definition defines.h:204
void int char * mode
Definition tig.h:179
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:334
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:370
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
void rt_knob_edit_tran(struct rt_edit *s, char coords, int matrix_edit, vect_t tvec)
struct rt_edit_map * rt_edit_map_create(void)
void rt_edit_destroy(struct rt_edit *s)
int rt_edit_map_clear(struct rt_edit_map *m)
void rt_edit_set_edflag(struct rt_edit *s, int edflag)
struct rt_edit * rt_edit_create(struct db_full_path *dfp, struct db_i *dbip, struct bn_tol *, struct bview *v)
void rt_edit_process(struct rt_edit *s)
int rt_edit_map_clbk_set(struct rt_edit_map *em, int ed_cmd, int mode, bu_clbk_t f, void *d)
int rt_edit_map_copy(struct rt_edit_map *om, struct rt_edit_map *im)
int rt_edit_knob_cmd_process(struct rt_edit *s, vect_t *rvec, int *do_rot, vect_t *tvec, int *do_tran, int *do_sca, struct bview *v, const char *cmd, fastf_t f, char origin, int incr_flag, void *u_data)
void rt_knob_edit_sca(struct rt_edit *s, int matrix_edit)
int rt_edit_map_clbk_get(bu_clbk_t *f, void **d, struct rt_edit_map *em, int ed_cmd, int mode)
void rt_knob_edit_rot(struct rt_edit *s, char coords, char rotate_about, int matrix_edit, mat_t newrot)
void rt_edit_map_destroy(struct rt_edit_map *)
void rt_get_solid_keypoint(struct rt_edit *s, point_t *pt, const char **strp, fastf_t *mat)
Definition tol.h:72
Definition ptbl.h:53
Definition vls.h:53
char * menu_string
Definition edit.h:353
void(* menu_func)(struct rt_edit *, int, int, int, void *)
Definition edit.h:354
fastf_t es_scale
Definition edit.h:187
double local2base
Definition edit.h:256
int e_mvalid
Definition edit.h:242
point_t e_axes_pos
Definition edit.h:252
void * ipe_ptr
Definition edit.h:268
int edit_flag
Definition edit.h:163
fastf_t acc_sc_obj
Definition edit.h:234
vect_t e_mparam
Definition edit.h:243
mat_t model2objview
Definition edit.h:231
mat_t acc_rot_sol
Definition edit.h:236
double base2local
Definition edit.h:255
int e_inpara
Definition edit.h:245
struct bu_vls * log_str
Definition edit.h:121
mat_t model_changes
Definition edit.h:229
fastf_t acc_sc_sol
Definition edit.h:235
struct rt_edit_map * m
Definition edit.h:118
struct bview_knobs k
Definition edit.h:156
const struct bn_tol * tol
Definition edit.h:149
mat_t e_mat
Definition edit.h:249
fastf_t acc_sc[3]
Definition edit.h:233
point_t curr_e_axes_pos
Definition edit.h:251
struct bview * vp
Definition edit.h:154
int update_views
Definition edit.h:259
struct rt_db_internal es_int
Definition edit.h:125
mat_t e_invmat
Definition edit.h:248
int mv_context
Definition edit.h:265
todo why todo should we be setting this for matrix and pscale values as well int edit_mode
Definition edit.h:185
vect_t e_para
Definition edit.h:246
mat_t incr_change
Definition edit.h:188
int e_keyfixed
Definition edit.h:238
void * u_ptr
Definition edit.h:271
struct bu_ptbl comb_insts
Definition edit.h:146
struct bu_list * vlfree
Definition edit.h:262
point_t e_keypoint
Definition edit.h:239
const char * e_keytag
Definition edit.h:240
fundamental vector, matrix, quaternion math macros