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-2026 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 * Design notes:
28 *
29 * Aside from the X/Y/Z-only scale operations, the "generic" operations for
30 * both sed and oed seem to differ primarily in that the former update the
31 * wireframe and primitive parameters immediately, and the latter manipulate
32 * only the matrix until the final step. In the oed case, the altered
33 * primitive wireframes are handled by using the working matrix to distort the
34 * existing draw solids.
35 *
36 * It feels like there should be some sort of consolidation possible here - in
37 * the case where an operation (sed or oed) doesn't need a new wireframe,
38 * reusing an existing one is a sensible approach. For operations on large
39 * combs, which may involve thousands of large wireframes, reuse is key.
40 * Rather than have two "modes", what we should do instead is have the edit
41 * operations themselves determine if a new wireframe is needed. If not, then
42 * no matter what the op is we should try to reuse an existing wireframe (if
43 * one is available from the app) and only generate one if the app does not
44 * have the one we need available. That may allow us to completely eliminate
45 * the distinction between sed and oed, and treat comb edits like any other
46 * primitive edits by using functab methods (semi-related is the attempt to
47 * make a comb tess method in d1dc6a4fae8).
48 *
49 * Such changes would involve a significant update to the MGED drawing logic,
50 * which uses a very simple UP/DOWN flag trick to turn existing solid
51 * wireframes into the edit wireframes (and comes with some significant
52 * limitations as well). What we really need is a way for a scene obj to
53 * reference another scene obj and override specific values, so we can point to
54 * an existing scene obj and use it for edit drawing without having to do
55 * anything to the original obj except flagging it as involved (so the main
56 * update pass knows to skip drawing it.) Commit de2c0da2d4a has a bit of what
57 * would be needed for that to work, but there's a lot more to think about both
58 * in the original and new draw cycles. To properly have the edit drawing
59 * independent of other uses of geometry in a scene while still enabling vlist
60 * reuse (which the new drawing path isn't really doing properly) we may need
61 * to have all comb instances define themselves in a scene as an object that
62 * references another scene object which isn't drawn but holds the data
63 * defining the vlist. Then the instance obj would just hold the matrix and
64 * any override info for color, etc. Need to check how MGED is handling comb
65 * instances now, the new drawing layer I think is just creating a new
66 * bv_scene_obj for each instance with its own vlist...
67 */
68
69#ifndef RT_EDIT_H
70#define RT_EDIT_H
71
72#include "common.h"
73#include <float.h>
74#include "vmath.h"
75#include "bn/mat.h"
76#include "bu/parse.h"
77#include "bu/avs.h"
78#include "bv/defines.h"
79#include "rt/defines.h"
80#include "rt/db_internal.h"
81
83
84struct db_full_path;
85
86// Settings used for both solid and matrix edits
87#define RT_EDIT_DEFAULT -1
88#define RT_EDIT_IDLE 0
89
90/**
91 * Maximum number of parameters that can be supplied via e_para in a single
92 * rt_edit operation. This must be large enough to hold all parameters for
93 * the most complex single command (currently ECMD_SKETCH_APPEND_BEZIER, which
94 * needs one slot per control-point index; degree 15 → 16 indices).
95 */
96/* Maximum number of keyboard-input parameters for a single edit command.
97 * SET_MATRIX requires 1 index + 16 matrix elements = 17 values; use 20
98 * to give headroom for future operations. */
99#define RT_EDIT_MAXPARA 20
100
101/* Maximum number of simultaneous string parameters (companion to e_para for
102 * RT_EDIT_PARAM_STRING commands) and the maximum byte length of each. */
103#define RT_EDIT_MAXSTR 5
104#define RT_EDIT_MAXSTR_LEN 512
105
106
107// Solid editing (done via sed in MGED) alters primitive parameters to produce
108// new shapes. Parameters are updated immediately, allowing for new wireframe
109// generation from primitive plot commands. Not supported for combs.
110//
111// Translate, rotate and scale can typically be applied to any geometry object,
112// without needing awareness of the details of the object's definition. The
113// primitives themselves define more specific per-data editing flags.
114#define RT_PARAMS_EDIT_TRANS 1
115#define RT_PARAMS_EDIT_SCALE 2 // Scale whole solid by scalar
116#define RT_PARAMS_EDIT_ROT 3
117
118// This isn't an edit operation as such in that it doesn't (and won't) change
119// the geometry itself - rather it is used in edit_mode to indicate a
120// particular selection state.
121//
122// Eventually it might very well end up being used for an edit flag - it is
123// quite reasonable to think that ft_edit_xy might take this flag and a mouse
124// argument to select the geometrically closest editing feature from the solid
125// and set the appropriate edit flag and/or per-prim data structure info - but
126// right now we don't have anything like that.
127#define RT_PARAMS_EDIT_PICK 5
128
129// Matrix editing (done via oed in MGED) alters a matrix rather than solid
130// parameters in its intermediate stages (at the end when changes are written
131// to disk, and if a solid is being edited rather than a comb the matrix
132// changes are translated by the per-primitive routines to new solid parameters
133// at that time.)
134//
135// Matrix rotation: absolute Euler angles (X,Y,Z in degrees) supplied via
136// e_para[0..2]. The existing rotation stored in model_changes is replaced
137// by the new absolute rotation while the keypoint's world position and the
138// accumulated scale factor are preserved. This mirrors MGED's "orot X Y Z"
139// (f_rot_obj / mged_rot_obj) behaviour. Incremental rotation via knob or
140// mouse input uses rt_knob_edit_rot() with matrix_edit=1 instead.
141#define RT_MATRIX_EDIT_ROT 6
142
143// Matrix translate operations specified relative to VIEW XY are view-dependent.
144// They project the object keypoint into view space, replace the requested
145// XY component(s) with the supplied mouse/parameter value, and project back
146// to model space. This matches MGED's oed mouse-drag (RARROW/UARROW) behaviour
147// and is the correct mapping for interactive viewport dragging.
148//
149// For non-interactive (command-line) absolute placement in model coordinates,
150// use RT_MATRIX_EDIT_TRANS_MODEL_XYZ which places the keypoint at the given
151// model-space X,Y,Z position directly. This mirrors MGED's "translate X Y Z"
152// (f_tr_obj) behaviour when in object-edit mode.
153#define RT_MATRIX_EDIT_TRANS_VIEW_XY 7
154#define RT_MATRIX_EDIT_TRANS_VIEW_X 8
155#define RT_MATRIX_EDIT_TRANS_VIEW_Y 9
156
157// Absolute model-space translation: move object so that e_keypoint lands at
158// the specified model-space position. e_para[0..2] supply the target X,Y,Z
159// coordinates in local (display) units; the edit function converts to base
160// units internally. Equivalent to MGED's "translate X Y Z" command when in
161// object-edit (oed) mode. Unlike the VIEW variants above this operation is
162// view-independent and maps directly to model coordinates.
163#define RT_MATRIX_EDIT_TRANS_MODEL_XYZ 14
164
165// Non-uniform scale operations scale relative to the MODEL coordinate system,
166// NOT the view plane.
167//
168// Note that the underlying solids do not always support directly expressing
169// the shapes that can be created with these opts using comb instances (for
170// example, a TOR scaled in the X direction) and the edit will be rejected in
171// those cases. Just because a comb instance of a solid can be stretched, that
172// does not mean the solid itself can support that shape. Consequently, it is
173// recommended that the _X, _Y and _Z versions of the scale operations be used
174// sparingly if at all. Even if a comb instance's tree is able to support
175// rendering such an operation at the time the original edit is made, a
176// subsequent editing of that tree could add new geometry and ultimately result
177// in an inability to apply the matrix successfully to all leaf solids.
178#define RT_MATRIX_EDIT_SCALE 10
179#define RT_MATRIX_EDIT_SCALE_X 11
180#define RT_MATRIX_EDIT_SCALE_Y 12
181#define RT_MATRIX_EDIT_SCALE_Z 13
182
183
184struct rt_edit_map;
185
186struct rt_edit {
187
188 struct rt_edit_map *m;
189
190 // Optional logging of messages from editing code
192
193 // Container to hold the intermediate state
194 // of the object being edited
196
197 // When we're editing a comb instance, we need to record which specific
198 // instance(s) we're working with. db_find_named_leaf is what finds the
199 // named instance that the editing matrix will ultimately be applied to.
200 //
201 // Although normally we're either transforming the whole comb (i.e. the
202 // matrix gets applied to ALL instances in the comb tree) or operating on a
203 // single instance, there is nothing conceptually that would prevent the
204 // editing of multiple instances.
205 //
206 // In the interest of making the API flexible, we use a bu_ptbl to hold
207 // pointers to tr_l.tl_name strings in the es_int comb tree to identify all
208 // active instances in the comb that are actually being edited. (An empty
209 // bu_ptbl means edit all of them.) For any object type other than combs
210 // this tbl is ignored.
211 //
212 // An edit operation on a comb will populate this with the active instance(s).
213 // which in turn means the edit structure will have enough information for
214 // application level drawing code to figure out which solids in the comb need
215 // to be visualized as part of the active editing geometry.
217
218 // Dynamic configuration options (key-value pairs)
219 // used to pass settings from calling code down into primitive edit logic
220 // (e.g., "raw_mode" to bypass simplification).
222
223 // Tolerance for calculations
224 const struct bn_tol *tol;
225 struct db_i *dbip; /**< @brief database instance (for checkpoint/revert) */
226
227 // Main view associated with the edit. This may not be the only view in
228 // which the edit is *visible*, but this should hold the pointer to the
229 // view which will be used to drive any view dependent edit ops.
230 struct bview *vp;
231 // Knob based editing data
233
234 // Current editing operation. This holds the exact operation being
235 // performed (for example, ECMD_TGC_SCALE_A to scale a tgc primitive's
236 // A vector). The RT_PARAM_* and RT_MATRIX_* values may also be set
237 // here, if the operations being performed are the more generic/general
238 // cases.
240
241 // MGED uses es_edclass (in mged_edit_state) to track whether the active
242 // edit is a rotate, translate, or scale. That tracking is driven by the
243 // primitive-specific EDIT_ROTATE / EDIT_TRAN / EDIT_SCALE macros in
244 // sedit.h. edit_mode serves the same purpose in the librt editing layer:
245 // it tells mouse-input handlers and knob drivers which interaction mode
246 // is active, without having to enumerate every primitive-specific ECMD.
247 //
248 // Options:
249 // RT_PARAMS_EDIT_TRANS – free translate
250 // RT_PARAMS_EDIT_SCALE – uniform or axis scale
251 // RT_PARAMS_EDIT_ROT – rotation
252 // RT_PARAMS_EDIT_PICK – geometric pick (e.g. click to select a vertex)
253 //
254 // For matrix editing (RT_MATRIX_EDIT_*) and primitive-scale (pscale),
255 // edit_mode is also set so that edit_generic_xy() and the knob rate loop
256 // can decide how to apply the incremental delta.
257 //
258 // NOTE - this is only active in the librt editing code; MGED uses its
259 // own primitive-aware defines (SEDIT_ROTATE, etc.) for the same purpose.
261
262 fastf_t es_scale; /* scale factor */
263 mat_t incr_change; /* change(s) from last cycle */
264
265 /* Matrix-based editing visualizations are a different beast from edits
266 * that change primitive parameters. In the latter case, we must
267 * regenerate vlists based on new object parameters. Applications
268 * supporting solid editing need to be able to support visualizing an
269 * entity whose source geometry visualization data is constantly changing.
270 *
271 * Combs, on the other hand, have a wireframe representation that consists
272 * of one or more individual primitive wireframes from OTHER solids -
273 * potentially *thousands* of them for large models. Nor to matrix edits
274 * typically call for a wireframe regeneration - tra and rot operations
275 * definitely don't, and while scaled primitives might be more smoothly
276 * represented by refreshed wireframes not all matrix edits can be
277 * successfully translated to primitive param updates in all cases. As
278 * a result, for matrix-based editing wireframes are treated as static
279 * data to be manipulated.
280 *
281 * Consequently, rather than generating copies of all those wireframes and
282 * modifying them all every time an incremental edit is made, a more
283 * efficient option is to re-use any existing wireframes the app already
284 * has loaded for the comb tree in question and distort the *view space* to
285 * reflect the editing operation while doing the draw. Because the source
286 * wireframe data isn't changing, view distortion drawing is feasible.
287 *
288 * Combs are *only* editable via matrix manipulations, so rather than
289 * trying to manage the comb's editing visualization data in this struct
290 * the problem is "punted" to the application, which can decide for itself
291 * whether and how to reuse any existing wireframe information when drawing
292 * editing objects.
293 *
294 * To use model_changes to generate appropriate matrices for this purpose,
295 * the pattern looks like the following:
296 *
297 * mat_t model2objview;
298 * struct bview *vp = <current view pointer>;
299 * bn_mat_mul(model2objview, vp->gv_model2view, s->model_changes);
300 * ## A second bn_mat_mul might be needed if a perspective matrix is in use
301 * dm_loadmatrix(DMP, model2objview, which_eye);
302 * ## Do the drawing
303 */
304 mat_t model_changes; /* full changes this edit */
305
306 mat_t model2objview; /* Matrix for applying model_changes to view objects (used for matrix xy translation) */
307
308 fastf_t acc_sc[3]; /* accumulate local object scale factors */
309 fastf_t acc_sc_obj; /* accumulate global object scale factor */
310 fastf_t acc_sc_sol; /* accumulate solid scale factor */
311 mat_t acc_rot_sol; /* accumulate solid rotations */
312
313 int e_keyfixed; /* keypoint specified by user? */
314 point_t e_keypoint; /* center of editing xforms */
315 const char *e_keytag; /* string identifying the keypoint */
316
317 int e_mvalid; /* e_mparam valid. e_inpara must = 0 */
318 vect_t e_mparam; /* mouse input param. Only when es_mvalid set */
319
320 int e_inpara; /* number of valid entries in e_para (set by caller before rt_edit_process) */
321 fastf_t e_para[RT_EDIT_MAXPARA]; /* keyboard input parameters; e_para[0..e_inpara-1] are valid */
322
323 /* Parallel string-parameter array for RT_EDIT_PARAM_STRING commands.
324 * Use rt_edit_set_str() to write; primitive edit handlers retrieve the
325 * value via the ECMD_GET_FILENAME callback mechanism. */
326 int e_nstr; /* number of valid entries in e_str */
327 char e_str[RT_EDIT_MAXSTR][RT_EDIT_MAXSTR_LEN]; /* string params; e_str[0..e_nstr-1] are valid */
328
329 mat_t e_invmat; /* inverse of e_mat KAA */
330 mat_t e_mat; /* accumulated matrix of path */
331
332 point_t curr_e_axes_pos; /* center of editing xforms */
334
335 // Conversion factors
338
339 // Trigger for view updating
341
342 // vlfree list
344
345 /* Flag to trigger some primitive edit opts to use keypoint (and maybe other behaviors?) */
347
348 /* Internal primitive editing information specific to primitive types. */
349 void *ipe_ptr;
350
351 /* Snap-to-grid: when snap.enabled is non-zero, ft_edit_xy implementations
352 * should call rt_edit_snap_point() on the computed UV/model position before
353 * applying it. spacing is in model (base) units. */
354 struct {
355 int enabled; /**< non-zero → snap active */
356 fastf_t spacing; /**< grid spacing in mm (base units) */
358
359 /* Single-level checkpoint/revert. rt_edit_checkpoint() serialises
360 * es_int here; rt_edit_revert() restores it. bu_external.ext_buf is
361 * NULL when no snapshot has been saved. */
363
364 /* User pointer */
365 void *u_ptr;
366};
367
368/** Create and initialize an rt_edit struct */
369RT_EXPORT extern struct rt_edit *
370rt_edit_create(struct db_full_path *dfp, struct db_i *dbip, struct bn_tol *, struct bview *v);
371
372/** Free a rt_edit struct */
373RT_EXPORT extern void
375
376/**
377 * Reset an rt_edit back to an idle/empty state without freeing the struct
378 * itself. This frees any loaded primitive data (es_int, ipe_ptr, es_ckpt,
379 * comb_insts) and resets all edit-state fields to their initial values, but
380 * leaves the rt_edit struct, its edit_map, and its log_str allocated and
381 * usable. The pointer returned by rt_edit_create() remains valid after this
382 * call and can be reloaded with a new solid by calling rt_edit_reinit().
383 *
384 * Use this instead of rt_edit_destroy()+rt_edit_create() when a single
385 * persistent rt_edit should be kept alive across multiple editing sessions
386 * (e.g. in MGED where MEDIT(s) must never be NULL).
387 */
388RT_EXPORT extern void
390
391/**
392 * Reload an existing (reset or newly created) rt_edit with solid data from
393 * @a dfp inside database @a dbip. Equivalent to rt_edit_create() but reuses
394 * the already-allocated struct rather than allocating a new one.
395 *
396 * Calls rt_edit_reset() first to discard any previous solid data, then
397 * imports the solid, sets up the primitive-specific private state, and
398 * computes the path matrix and initial keypoint.
399 *
400 * @return BRLCAD_OK on success, BRLCAD_ERROR if the solid import fails.
401 */
402RT_EXPORT extern int
403rt_edit_reinit(struct rt_edit *s, struct db_full_path *dfp, struct db_i *dbip,
404 struct bn_tol *tol, struct bview *v);
405
406/**
407 * Set a dynamic option for this editing session.
408 * These options are available to primitive-specific editing logic.
409 */
410RT_EXPORT extern int
411rt_edit_set_opt(struct rt_edit *s, const char *key, const char *val);
412
413/**
414 * Retrieve a dynamic option for this editing session.
415 * Returns NULL if the option is not set.
416 */
417RT_EXPORT extern const char *
418rt_edit_get_opt(struct rt_edit *s, const char *key);
419
420/**
421 * Set a string parameter in the edit struct's e_str[] array.
422 *
423 * @param s The edit struct to update.
424 * @param index Slot index (0 .. RT_EDIT_MAXSTR-1); must equal
425 * rt_edit_param_desc::index for the STRING parameter.
426 * @param str NUL-terminated string to copy (truncated to
427 * RT_EDIT_MAXSTR_LEN-1 bytes).
428 */
429RT_EXPORT extern void
430rt_edit_set_str(struct rt_edit *s, int index, const char *str);
431
432/* Logic for working with editing callback maps.
433 *
434 * Editing callback maps allow applications to register logic to be executed for particular
435 * commands or the pre-defined standard registration points which are general to all commands,
436 * per the defines below. */
437#define ECMD_CLEAR_CLBKS 0
438#define ECMD_PRINT_STR 10
439#define ECMD_PRINT_RESULTS 20
440#define ECMD_EAXES_POS 30
441#define ECMD_REPLOT_EDITING_SOLID 40
442#define ECMD_VIEW_UPDATE 50
443#define ECMD_VIEW_SET_FLAG 60
444#define ECMD_MENU_SET 70
445#define ECMD_MENU_REFRESH 71
446#define ECMD_GET_FILENAME 80
447
448RT_EXPORT extern struct rt_edit_map *
450RT_EXPORT extern void
452RT_EXPORT extern int
453rt_edit_map_clbk_set(struct rt_edit_map *em, int ed_cmd, int mode, bu_clbk_t f, void *d);
454RT_EXPORT extern int
455rt_edit_map_clbk_get(bu_clbk_t *f, void **d, struct rt_edit_map *em, int ed_cmd, int mode);
456RT_EXPORT extern int
458RT_EXPORT extern int
460
461/* Functions for manipulating rt_edit data */
462RT_EXPORT extern void
463rt_get_solid_keypoint(struct rt_edit *s, point_t *pt, const char **strp, fastf_t *mat);
464
465RT_EXPORT extern void
467
468RT_EXPORT extern int
470 struct rt_edit *s,
471 vect_t *rvec, int *do_rot, vect_t *tvec, int *do_tran, int *do_sca,
472 struct bview *v, const char *cmd, fastf_t f,
473 char origin, int incr_flag, void *u_data
474 );
475
476RT_EXPORT extern void
478 char coords,
479 char rotate_about,
480 int matrix_edit,
482 );
483
484RT_EXPORT extern void
486 char coords,
487 int matrix_edit,
488 const vect_t tvec);
489
490RT_EXPORT extern void
492 struct rt_edit *s,
493 int matrix_edit);
494
495/* Equivalent to sedit - run editing logic after input data is set in
496 * rt_edit container */
497RT_EXPORT extern void
499
500/**
501 * Snap a 2-D UV point to the grid defined in s->snap.
502 *
503 * If s->snap.enabled is zero the point is returned unchanged.
504 * Otherwise each component is rounded to the nearest multiple of
505 * s->snap.spacing.
506 *
507 * @param[in,out] pt 2-D UV coordinate to snap (in model/base units).
508 * @param[in] s rt_edit struct carrying snap configuration.
509 */
510RT_EXPORT extern void
512
513/**
514 * Save a snapshot of the current primitive parameters so they can be
515 * restored later with rt_edit_revert().
516 *
517 * The snapshot is stored inside the rt_edit struct. Calling this
518 * function again overwrites any previous snapshot (single-level undo).
519 *
520 * @return BRLCAD_OK on success, BRLCAD_ERROR if the export failed.
521 */
522RT_EXPORT extern int
524
525/**
526 * Restore primitive parameters from the snapshot saved by
527 * rt_edit_checkpoint().
528 *
529 * If no snapshot has been saved (or the last snapshot was already
530 * consumed) this function logs a message and returns BRLCAD_ERROR.
531 *
532 * @return BRLCAD_OK on success, BRLCAD_ERROR otherwise.
533 */
534RT_EXPORT extern int
536
537
538/* Edit menu items encode information about specific edit operations, as well
539 * as info documenting them. Edit functab methods use this data type. */
541 const char *menu_string;
542 void (*menu_func)(struct rt_edit *, int, int, int, void *);
544};
545
546
547/*
548 * ============================================================
549 * ft_edit_desc() parameter-descriptor API
550 *
551 * These types allow a primitive's ft_edit_desc() slot to return
552 * machine-readable metadata describing every edit operation it
553 * supports. A GUI (e.g. qged) can use this metadata to
554 * auto-generate appropriate edit widgets without needing any
555 * primitive-specific code.
556 * ============================================================
557 */
558
559/** Parameter type codes for struct rt_edit_param_desc */
560#define RT_EDIT_PARAM_SCALAR 1 /**< single fastf_t; QDoubleSpinBox / QSlider */
561#define RT_EDIT_PARAM_INTEGER 2 /**< truncated fastf_t; QSpinBox */
562#define RT_EDIT_PARAM_BOOLEAN 3 /**< !NEAR_ZERO(val); QCheckBox */
563#define RT_EDIT_PARAM_POINT 4 /**< point_t (3 fastf_t); 3x QDoubleSpinBox */
564#define RT_EDIT_PARAM_VECTOR 5 /**< vect_t (3 fastf_t); 3x QDoubleSpinBox */
565#define RT_EDIT_PARAM_STRING 6 /**< NUL-terminated; QLineEdit */
566#define RT_EDIT_PARAM_ENUM 7 /**< integer choice; QComboBox */
567#define RT_EDIT_PARAM_COLOR 8 /**< RGB triple as three fastf_t (0-255) in
568 * e_para[index..index+2]; QColorDialog button */
569#define RT_EDIT_PARAM_MATRIX 9 /**< 4x4 row-major in e_para[0..15]; matrix widget*/
570
571/** Sentinel for "no range constraint" on a parameter. */
572#define RT_EDIT_PARAM_NO_LIMIT (-DBL_MAX)
573
574/**
575 * Describes a single input parameter for one edit command.
576 *
577 * For scalar/integer/boolean/enum parameters the value is stored in
578 * s->e_para[index]. For POINT/VECTOR, three consecutive slots starting
579 * at e_para[index] are used. For MATRIX, e_para[0..15] are used.
580 * For STRING the value is in the primitive-specific edit struct; prim_field
581 * documents which field that is.
582 * For COLOR three fastf_t integer values (0-255) are stored in
583 * e_para[index], e_para[index+1], e_para[index+2].
584 */
586 const char *name; /**< machine-readable id, e.g. "r1" */
587 const char *label; /**< human-readable widget label, e.g. "Major Radius" */
588 int type; /**< RT_EDIT_PARAM_* type code */
589 int index; /**< offset into s->e_para[] (unused for STRING) */
590 fastf_t range_min; /**< RT_EDIT_PARAM_NO_LIMIT = no lower bound */
591 fastf_t range_max; /**< RT_EDIT_PARAM_NO_LIMIT = no upper bound */
592 const char *units; /**< "length", "angle_deg", "angle_rad",
593 * "fraction", "count", "none", or NULL */
594 /* RT_EDIT_PARAM_ENUM only */
595 int nenum; /**< number of choices */
596 const char * const *enum_labels; /**< human-readable option strings */
597 const int *enum_ids; /**< integer value stored in e_para[index] */
598 /* RT_EDIT_PARAM_STRING only */
599 const char *prim_field; /**< name of the primitive struct field, e.g.
600 * "es_shader" or "dsp_name" */
601};
602
603/**
604 * Describes a single edit command (one ECMD_* constant) together with
605 * the parameters it requires.
606 */
608 int cmd_id; /**< ECMD_* constant */
609 const char *label; /**< human-readable operation label */
610 const char *category; /**< grouping hint: "radius", "geometry",
611 * "rotation", "material", "tree", "misc" */
612 int nparam; /**< number of entries in params[] */
613 const struct rt_edit_param_desc *params; /**< NULL when nparam == 0 */
614 /** Non-zero: GUI should re-call rt_edit_process() on every widget change
615 * (live wireframe update). Zero: only apply on explicit Apply button. */
617 /** Suggested display order within the category group. Lower values
618 * appear first. Ties are broken by array order. */
620 /** Comma-separated list of types this cmd is valid for (e.g. "sph" or "arb4"). NULL means all. */
621 const char *req_types;
622};
623
624/**
625 * Describes a dynamically toggleable option for a primitive.
626 */
628 const char *name; /**< machine-readable id, e.g. "raw_mode" */
629 const char *label; /**< human-readable widget label */
630 const char *desc; /**< description of option behavior */
631 int type; /**< RT_EDIT_PARAM_* type code */
632};
633
634/**
635 * Top-level descriptor for a single primitive type.
636 * Returned by ft_edit_desc().
637 */
639 const char *prim_type; /**< "tor", "ell", "tgc", ... */
640 const char *prim_label; /**< "Torus", "Ellipsoid", ... */
641 int ncmd;
642 const struct rt_edit_cmd_desc *cmds; /**< array of ncmd entries */
643 int nopt; /**< number of entries in opts[] */
644 const struct rt_edit_opt_desc *opts; /**< array of nopt entries */
645};
646
647/**
648 * Serialise a primitive edit descriptor to a JSON string appended to @p out.
649 * The caller is responsible for bu_vls_init / bu_vls_free.
650 * Returns BRLCAD_OK on success, BRLCAD_ERROR on error.
651 */
652RT_EXPORT extern int
654 const struct rt_edit_prim_desc *desc);
655
656/**
657 * Convenience wrapper: look up the EDOBJ entry for @p prim_type_id and
658 * call rt_edit_prim_desc_to_json() on its ft_edit_desc() result.
659 * Returns BRLCAD_OK on success, BRLCAD_ERROR if the primitive has no
660 * descriptor or the type id is out of range.
661 */
662RT_EXPORT extern int
664
665
666
667/***************************************************
668 * Experiments with expressing editing constraints
669 ***************************************************/
670
677
683
696
698 const char *name;
701};
702
712
719
727
734
745
752
754 struct bu_ptbl *violations,
755 const struct rt_db_internal *ip,
756 const struct rt_constraint_edit_ctx *ctx);
757
759 struct rt_constraint_edit_result *out,
760 struct rt_db_internal *ip,
761 const struct rt_constraint_edit_op *op,
762 const struct rt_constraint_edit_ctx *ctx);
763
765 const struct rt_db_internal *before_ip,
766 const struct rt_db_internal *after_ip,
767 const struct rt_constraint_edit_metric *metric);
768
771
775
776
777
778
779
781
782#endif /* RT_EDIT_H */
783
784/*
785 * Local Variables:
786 * tab-width: 8
787 * mode: C
788 * indent-tabs-mode: t
789 * c-file-style: "stroustrup"
790 * End:
791 * ex: shiftwidth=4 tabstop=8
792 */
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
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:348
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:333
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
fastf_t point2d_t[ELEMENTS_PER_POINT2D]
2-tuple point
Definition vmath.h:342
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:354
struct rt_edit_map * rt_edit_map_create(void)
void rt_constraint_edit_violation_init(struct rt_constraint_edit_violation *v)
void rt_edit_destroy(struct rt_edit *s)
void rt_constraint_edit_violation_free(struct rt_constraint_edit_violation *v)
int rt_edit_map_clear(struct rt_edit_map *m)
void rt_edit_set_edflag(struct rt_edit *s, int edflag)
#define RT_EDIT_MAXPARA
Definition edit.h:99
int rt_edit_type_to_json(struct bu_vls *out, int prim_type_id)
int(* rt_constraint_edit_validate_t)(struct bu_ptbl *violations, const struct rt_db_internal *ip, const struct rt_constraint_edit_ctx *ctx)
Definition edit.h:753
struct rt_edit * rt_edit_create(struct db_full_path *dfp, struct db_i *dbip, struct bn_tol *, struct bview *v)
void rt_edit_snap_point(point2d_t pt, const struct rt_edit *s)
rt_constraint_edit_policy
Definition edit.h:671
@ RT_CONSTRAINT_EDIT_SNAP_IF_WITHIN_TOL
Definition edit.h:675
@ RT_CONSTRAINT_EDIT_REJECT
Definition edit.h:672
@ RT_CONSTRAINT_EDIT_WARN_ONLY
Definition edit.h:673
@ RT_CONSTRAINT_EDIT_SNAP
Definition edit.h:674
void rt_constraint_edit_result_free(struct rt_constraint_edit_result *r)
void rt_edit_reset(struct rt_edit *s)
void rt_knob_edit_tran(struct rt_edit *s, char coords, int matrix_edit, const vect_t tvec)
void rt_edit_process(struct rt_edit *s)
int rt_edit_revert(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_reinit(struct rt_edit *s, struct db_full_path *dfp, struct db_i *dbip, struct bn_tol *tol, struct bview *v)
#define RT_EDIT_MAXSTR
Definition edit.h:103
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)
int(* rt_constraint_edit_project_apply_t)(struct rt_constraint_edit_result *out, struct rt_db_internal *ip, const struct rt_constraint_edit_op *op, const struct rt_constraint_edit_ctx *ctx)
Definition edit.h:758
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_constraint_edit_result_clear(struct rt_constraint_edit_result *r)
void rt_knob_edit_rot(struct rt_edit *s, char coords, char rotate_about, int matrix_edit, mat_t newrot)
int rt_edit_checkpoint(struct rt_edit *s)
void rt_edit_map_destroy(struct rt_edit_map *)
void rt_constraint_edit_result_init(struct rt_constraint_edit_result *r)
void rt_get_solid_keypoint(struct rt_edit *s, point_t *pt, const char **strp, fastf_t *mat)
int rt_edit_set_opt(struct rt_edit *s, const char *key, const char *val)
void rt_edit_set_str(struct rt_edit *s, int index, const char *str)
const char * rt_edit_get_opt(struct rt_edit *s, const char *key)
rt_constraint_edit_op_kind
Definition edit.h:684
@ RT_CONSTRAINT_EDIT_OP_DELETE_POINT
Definition edit.h:688
@ RT_CONSTRAINT_EDIT_OP_INSERT_POINT
Definition edit.h:687
@ RT_CONSTRAINT_EDIT_OP_ADD_POINT
Definition edit.h:686
@ RT_CONSTRAINT_EDIT_OP_SCALE_BEND
Definition edit.h:694
@ RT_CONSTRAINT_EDIT_OP_SET_BEND
Definition edit.h:691
@ RT_CONSTRAINT_EDIT_OP_SCALE_ID
Definition edit.h:693
@ RT_CONSTRAINT_EDIT_OP_SET_OD
Definition edit.h:689
@ RT_CONSTRAINT_EDIT_OP_SCALE_OD
Definition edit.h:692
@ RT_CONSTRAINT_EDIT_OP_MOVE_POINT
Definition edit.h:685
@ RT_CONSTRAINT_EDIT_OP_SET_ID
Definition edit.h:690
int rt_edit_prim_desc_to_json(struct bu_vls *out, const struct rt_edit_prim_desc *desc)
#define RT_EDIT_MAXSTR_LEN
Definition edit.h:104
fastf_t(* rt_constraint_edit_score_delta_t)(const struct rt_db_internal *before_ip, const struct rt_db_internal *after_ip, const struct rt_constraint_edit_metric *metric)
Definition edit.h:764
rt_constraint_edit_severity
Definition edit.h:678
@ RT_CONSTRAINT_EDIT_WARN
Definition edit.h:680
@ RT_CONSTRAINT_EDIT_ERROR
Definition edit.h:681
@ RT_CONSTRAINT_EDIT_INFO
Definition edit.h:679
Definition tol.h:72
Definition ptbl.h:53
Definition vls.h:53
struct rt_constraint_edit_metric metric
Definition edit.h:748
enum rt_constraint_edit_policy policy
Definition edit.h:747
struct rt_constraint_edit_tolerances tol
Definition edit.h:749
vect_t proposed_coord
Definition edit.h:731
enum rt_constraint_edit_op_kind kind
Definition edit.h:729
fastf_t proposed_scalar
Definition edit.h:732
struct bu_ptbl violations
Definition edit.h:742
struct bu_vls summary
Definition edit.h:743
struct bu_ptbl changed_params
Definition edit.h:741
enum rt_constraint_edit_severity severity
Definition edit.h:705
struct rt_constraint_edit_param_ref a
Definition edit.h:706
struct rt_constraint_edit_param_ref b
Definition edit.h:707
int display_order
Definition edit.h:619
const char * category
Definition edit.h:610
const char * req_types
Definition edit.h:621
const struct rt_edit_param_desc * params
Definition edit.h:613
const char * label
Definition edit.h:609
int interactive
Definition edit.h:616
void(* menu_func)(struct rt_edit *, int, int, int, void *)
Definition edit.h:542
const char * menu_string
Definition edit.h:541
const char * desc
Definition edit.h:630
const char * name
Definition edit.h:628
const char * label
Definition edit.h:629
const char * units
Definition edit.h:592
const char * prim_field
Definition edit.h:599
fastf_t range_min
Definition edit.h:590
const char *const * enum_labels
Definition edit.h:596
fastf_t range_max
Definition edit.h:591
const char * name
Definition edit.h:586
const char * label
Definition edit.h:587
const int * enum_ids
Definition edit.h:597
const char * prim_label
Definition edit.h:640
const struct rt_edit_opt_desc * opts
Definition edit.h:644
const struct rt_edit_cmd_desc * cmds
Definition edit.h:642
const char * prim_type
Definition edit.h:639
int enabled
Definition edit.h:355
fastf_t es_scale
Definition edit.h:262
double local2base
Definition edit.h:337
int e_nstr
Definition edit.h:326
int e_mvalid
Definition edit.h:317
struct rt_edit::@11 snap
point_t e_axes_pos
Definition edit.h:333
struct bu_external es_ckpt
Definition edit.h:362
void * ipe_ptr
Definition edit.h:349
int edit_flag
Definition edit.h:239
fastf_t acc_sc_obj
Definition edit.h:309
fastf_t spacing
Definition edit.h:356
vect_t e_mparam
Definition edit.h:318
mat_t model2objview
Definition edit.h:306
mat_t acc_rot_sol
Definition edit.h:311
double base2local
Definition edit.h:336
int e_inpara
Definition edit.h:320
int edit_mode
Definition edit.h:260
struct bu_vls * log_str
Definition edit.h:191
mat_t model_changes
Definition edit.h:304
fastf_t acc_sc_sol
Definition edit.h:310
struct rt_edit_map * m
Definition edit.h:188
struct bview_knobs k
Definition edit.h:232
const struct bn_tol * tol
Definition edit.h:224
mat_t e_mat
Definition edit.h:330
fastf_t acc_sc[3]
Definition edit.h:308
point_t curr_e_axes_pos
Definition edit.h:332
fastf_t e_para[RT_EDIT_MAXPARA]
Definition edit.h:321
struct bview * vp
Definition edit.h:230
struct db_i * dbip
database instance (for checkpoint/revert)
Definition edit.h:225
int update_views
Definition edit.h:340
struct rt_db_internal es_int
Definition edit.h:195
mat_t e_invmat
Definition edit.h:329
int mv_context
Definition edit.h:346
char e_str[RT_EDIT_MAXSTR][RT_EDIT_MAXSTR_LEN]
Definition edit.h:327
mat_t incr_change
Definition edit.h:263
int e_keyfixed
Definition edit.h:313
void * u_ptr
Definition edit.h:365
struct bu_ptbl comb_insts
Definition edit.h:216
struct bu_list * vlfree
Definition edit.h:343
point_t e_keypoint
Definition edit.h:314
struct bu_attribute_value_set options
Definition edit.h:221
const char * e_keytag
Definition edit.h:315
fundamental vector, matrix, quaternion math macros