BRL-CAD
defines.h
Go to the documentation of this file.
1/* D E F I N E S . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-2023 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/** @addtogroup ged_defines
21 *
22 * Geometry EDiting Library specific definitions.
23 *
24 */
25/** @{ */
26/** @file ged/defines.h */
27
28#ifndef GED_DEFINES_H
29#define GED_DEFINES_H
30
31#include "common.h"
32#include "bu/hash.h"
33#include "bu/list.h"
34#include "bu/process.h"
35#include "bu/vls.h"
36#include "bv/defines.h"
37#include "rt/search.h"
38#include "bv/defines.h"
39#include "dm/fbserv.h" // for fbserv_obj
40#include "rt/wdb.h" // for struct rt_wdb
41
42__BEGIN_DECLS
43
44#ifndef GED_EXPORT
45# if defined(GED_DLL_EXPORTS) && defined(GED_DLL_IMPORTS)
46# error "Only GED_DLL_EXPORTS or GED_DLL_IMPORTS can be defined, not both."
47# elif defined(GED_DLL_EXPORTS)
48# define GED_EXPORT COMPILER_DLLEXPORT
49# elif defined(GED_DLL_IMPORTS)
50# define GED_EXPORT COMPILER_DLLIMPORT
51# else
52# define GED_EXPORT
53# endif
54#endif
55
56#define GED_VMIN -2048.0
57#define GED_VMAX 2047.0
58#define GED_VRANGE 4095.0
59#define INV_GED_V 0.00048828125
60#define INV_4096_V 0.000244140625
61
62#define GED_NULL ((struct ged *)0)
63#define GED_DISPLAY_LIST_NULL ((struct display_list *)0)
64#define GED_DRAWABLE_NULL ((struct ged_drawable *)0)
65#define GED_VIEW_NULL ((struct bview *)0)
66
67#define GED_RESULT_NULL ((void *)0)
68
69/* Sequence starts after BRLCAD_ERROR, to be compatible with
70 * BU return codes */
71#define GED_HELP 0x0002 /**< invalid specification, result contains usage */
72#define GED_MORE 0x0004 /**< incomplete specification, can specify again interactively */
73#define GED_QUIET 0x0008 /**< don't set or modify the result string */
74#define GED_UNKNOWN 0x0010 /**< argv[0] was not a known command */
75#define GED_EXIT 0x0020 /**< command is requesting a clean application shutdown */
76
77/* Forward declaration */
78struct ged;
80
81typedef int (*ged_func_ptr)(struct ged *, int, const char *[]);
82#define GED_FUNC_PTR_NULL ((ged_func_ptr)0)
83
84/* Callback related definitions */
85typedef void (*ged_io_func_t)(void *, int);
86typedef void (*ged_refresh_func_t)(void *);
89typedef void (*ged_destroy_vlist_func_t)(unsigned int, int);
90struct ged_callback_state;
91
92/**
93 * Definition of global parallel-processing semaphores.
94 *
95 */
96#define GED_SEM_WORKER ANALYZE_SEM_LAST
97#define GED_SEM_STATS GED_SEM_WORKER+1
98#define GED_SEM_LIST GED_SEM_STATS+1
99#define GED_SEM_LAST GED_SEM_LIST+1
100
101#define GED_INIT(_gedp, _wdbp) { \
102 ged_init((_gedp)); \
103 (_gedp)->dbip = NULL; \
104 if ((struct rt_wdb *)(_wdbp) != NULL) {\
105 (_gedp)->dbip = ((struct rt_wdb *)(_wdbp))->dbip; \
106 } \
107}
108
109#define GED_INITIALIZED(_gedp) ((_gedp)->dbip != NULL)
110#define GED_LOCAL2BASE(_gedp) ((_gedp)->dbip->dbi_local2base)
111#define GED_BASE2LOCAL(_gedp) ((_gedp)->dbip->dbi_base2local)
112
113/* From include/dm.h */
114#define GED_MAX 2047.0
115#define GED_MIN -2048.0
116#define GED_RANGE 4095.0
117#define INV_GED 0.00048828125
118#define INV_4096 0.000244140625
119
120/* FIXME: leftovers from dg.h */
121#define RT_VDRW_PREFIX "_VDRW"
122#define RT_VDRW_PREFIX_LEN 6
123#define RT_VDRW_MAXNAME 31
124#define RT_VDRW_DEF_COLOR 0xffff00
125
126
128 uint32_t magic; /**< @brief magic number */
129 struct bu_process *p;
130 void *chan;
132 struct ged *gedp;
133 void (*end_clbk)(int, void *); /**< @brief function called when process completes */
138};
139
140/* FIXME: should be private */
142 unsigned char r;
143 unsigned char g;
144 unsigned char b;
145};
146
147/* FIXME: should be private */
149 char type;
150 struct bu_vls fmt;
151};
152
153struct vd_curve {
154 struct bu_list l;
155 char vdc_name[RT_VDRW_MAXNAME+1]; /**< @brief name array */
156 long vdc_rgb; /**< @brief color */
157 struct bu_list vdc_vhd; /**< @brief head of list of vertices */
158};
159#define VD_CURVE_NULL ((struct vd_curve *)NULL)
160
161/* FIXME: should be private */
163 struct bu_list *gd_headDisplay; /**< @brief head of display list */
164 struct bu_list *gd_headVDraw; /**< @brief head of vdraw list */
165 struct vd_curve *gd_currVHead; /**< @brief current vdraw head */
166
167 char **gd_rt_cmd; /* DEPRECATED - will be removed, do not use */
168 int gd_rt_cmd_len; /* DEPRECATED - will be removed, do not use */
169
170 void (*gd_rtCmdNotify)(int aborted); /**< @brief function called when rt command completes */
171
172 int gd_uplotOutputMode; /**< @brief output mode for unix plots */
173
174 /* qray state */
175 struct bu_vls gd_qray_basename; /**< @brief basename of query ray vlist */
176 struct bu_vls gd_qray_script; /**< @brief query ray script */
177 char gd_qray_effects; /**< @brief t for text, g for graphics or b for both */
178 int gd_qray_cmd_echo; /**< @brief 0 - don't echo command, 1 - echo command */
184 int gd_shaded_mode; /**< @brief 1 - draw bots shaded by default */
185};
186
187
188
189
190struct ged_cmd;
191
192/* struct details are private - use accessor functions to manipulate */
193struct ged_results;
194
195struct ged {
197 struct db_i *dbip;
198
199 /*************************************************************/
200 /* Information pertaining to views and view objects . */
201 /*************************************************************/
202 /* The current view */
203 struct bview *ged_gvp;
204 /* The full set of views associated with this ged object */
206 /* Drawing data associated with this .g file */
208
209
210 void *u_data; /**< @brief User data associated with this ged instance */
211
212 /** for catching log messages */
214
215
216 /* @todo: add support for returning an array of objects, not just a
217 * simple string.
218 *
219 * the calling application needs to be able to distinguish the
220 * individual object names from the "ls" command without resorting
221 * to quirky string encoding or format-specific quote wrapping.
222 *
223 * want to consider whether we need a json-style dictionary, but
224 * probably a literal null-terminated array will suffice here.
225 */
228
231
232 char *ged_output_script; /**< @brief script for use by the outputHandler */
233
234 /* Selection data */
237
238
239 /* FIXME -- this ugly hack needs to die. the result string should
240 * be stored before the call.
241 */
243
244
245 /* TODO: hide all callback related symbols, callback typedefs
246 * (above), and eventually most if not all of the remaining fields
247 * into an _impl structure so callers are not tightly coupled to
248 * the ged structure. access via public functions that have been
249 * given design consideration.
250 */
251
252 /* FOR LIBGED INTERNAL USE */
253 struct ged_cmd *cmds;
254 int (*add)(struct ged *gedp, const struct ged_cmd *cmd);
255 int (*del)(struct ged *gedp, const char *name);
256 int (*run)(struct ged *gedp, int ac, char *av[]);
257
258 struct bu_ptbl ged_subp; /**< @brief forked sub-processes */
259
260 /* Callbacks */
261
262 struct ged_callback_state *ged_cbs;
263 void (*ged_refresh_handler)(void *); /**< @brief function for handling refresh requests */
264 void *ged_refresh_clientdata; /**< @brief client data passed to refresh handler */
265 void (*ged_output_handler)(struct ged *, char *); /**< @brief function for handling output */
266 void (*ged_create_vlist_scene_obj_callback)(struct bv_scene_obj *); /**< @brief function to call after creating a vlist to create display list for solid */
267 void (*ged_create_vlist_display_list_callback)(struct display_list *); /**< @brief function to call after all vlist created that loops through creating display list for each solid */
268 void (*ged_destroy_vlist_callback)(unsigned int, int); /**< @brief function to call after freeing a vlist */
269
270
271 /* Functions assigned to ged_subprocess init_clbk and end_clbk
272 * slots when the ged_subprocess is created. TODO - eventually
273 * this should be command-specific callback registrations, but
274 * first we'll get the basic mechanism working, then introduce
275 * that extra complication... */
276 void (*ged_subprocess_init_callback)(int, void *); /**< @brief function called when process starts */
277 void (*ged_subprocess_end_callback)(int, void *); /**< @brief function called when process completes */
279
280 /* Handler functions for I/O communication with asynchronous subprocess commands. There
281 * are two opaque data structures at play here, with different scopes. One is the "data"
282 * pointer passed to ged_create_io_handler, which is used to store command-specific
283 * information internal to the library (the simplest thing to do is pass ged_subprocess
284 * in as the data pointer, but if that's not enough - see for example rtcheck - this
285 * mechanism allows for more elaborate measures.
286 *
287 * The second is ged_io_data, which is set in gedp by the calling application. This is where
288 * information specific to the parent's I/O environment (which by definition the library
289 * can't know about as it is application specific) lives. It should be assigned in the
290 * applications gedp before any calls to ged_create_io_handler are made.
291 * */
292 void (*ged_create_io_handler)(struct ged_subprocess *gp, bu_process_io_t d, ged_io_func_t callback, void *data);
294 void *ged_io_data; /**< brief caller supplied data */
295
296 /* fbserv server and I/O callbacks. These must hook into the application's event
297 * loop, and so cannot be effectively supplied by low-level libraries - the
298 * application must tell us how to tie in with the toplevel event
299 * processing system it is using (typically toolkit specific). */
301 int (*fbs_is_listening)(struct fbserv_obj *); /**< @brief return 1 if listening, else 0 */
302 int (*fbs_listen_on_port)(struct fbserv_obj *, int); /**< @brief return 1 on success, 0 on failure */
303 void (*fbs_open_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to open listener handler */
304 void (*fbs_close_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to close handler listener */
305 void (*fbs_open_client_handler)(struct fbserv_obj *, int, void *); /**< @brief platform/toolkit specific client handler setup (called by fbs_new_client) */
306 void (*fbs_close_client_handler)(struct fbserv_obj *, int); /**< @brief platform/toolkit method to close handler for client at index client_id */
307
308 // Other callbacks...
309 // Tcl command strings - these are libtclcad level callbacks that execute user supplied Tcl commands if set:
310 // gdv_callback, gdv_edit_motion_delta_callback, go_more_args_callback, go_rt_end_callback
311 //
312 // fbserv_obj: fbs_callback
313 // bv.h gv_callback (only used by MGED?)
314 // db_search_callback_t
315
316 // TODO - this probably should be handled with a registration function of some kind
317 // that assigns contexts based on dm type - right now the dms more or less have to
318 // assume that whatever is in here is intended for their initialization, and if a
319 // program wants to attach multiple types of DMs a single pointer is not a great way
320 // to manage things. A map would be better, but that's a C++ construct so we can't
321 // expose it directly here - need some sort of means to manage the setting and getting,
322 // maybe with functions like:
323 // ged_ctx_set(const char *dm_type, void *ctx)
324 // ged_ctx_get(const char *dm_type)
325 void *ged_ctx; /* Temporary - do not rely on when designing new functionality */
326
327 void *ged_interp; /* Temporary - do not rely on when designing new functionality */
328 db_search_callback_t ged_interp_eval; /* FIXME: broke the rule written on the previous line */
329
330};
331
332/* accessor functions for ged_results - calling
333 * applications should not work directly with the
334 * internals of ged_results, which are not guaranteed
335 * to stay the same.
336 * defined in ged_util.c */
337GED_EXPORT extern size_t ged_results_count(struct ged_results *results);
338GED_EXPORT extern const char *ged_results_get(struct ged_results *results, size_t index);
339GED_EXPORT extern void ged_results_clear(struct ged_results *results);
340GED_EXPORT extern void ged_results_free(struct ged_results *results);
341
342
343
344GED_EXPORT extern void ged_close(struct ged *gedp);
345GED_EXPORT extern void ged_free(struct ged *gedp);
346GED_EXPORT extern void ged_init(struct ged *gedp);
347/* Call BU_PUT to release returned ged structure */
348GED_EXPORT extern struct ged *ged_open(const char *dbtype,
349 const char *filename,
350 int existing_only);
351
352
353/**
354 * make sure there is a command name given
355 *
356 * @todo - where should this go?
357 */
358#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags) \
359 if ((_argc) < 1) { \
360 int ged_check_argc_gt_0_quiet = (_flags) & GED_QUIET; \
361 if (!ged_check_argc_gt_0_quiet) { \
362 bu_vls_trunc((_gedp)->ged_result_str, 0); \
363 bu_vls_printf((_gedp)->ged_result_str, "Command name not provided on (%s:%d).", __FILE__, __LINE__); \
364 } \
365 return (_flags); \
366 }
367
368
369struct ged_cmd_impl;
370struct ged_cmd {
371 struct ged_cmd_impl *i;
372};
373
375 uint32_t api_version; /* must be first in struct */
376 const struct ged_cmd ** const cmds;
378};
379
380/* Report any messages from libged when plugins were initially loaded.
381 * Can be important when diagnosing command errors. */
382GED_EXPORT const char * ged_init_msgs(void);
383
384
385__END_DECLS
386
387#endif /* GED_DEFINES_H */
388
389/** @} */
390
391/*
392 * Local Variables:
393 * tab-width: 8
394 * mode: C
395 * indent-tabs-mode: t
396 * c-file-style: "stroustrup"
397 * End:
398 * ex: shiftwidth=4 tabstop=8
399 */
Header file for the BRL-CAD common definitions.
This header holds generic routines and data structures used for TCP based communication between a fra...
bu_process_io_t
Definition: process.h:55
int(* db_search_callback_t)(int, const char *[], void *)
Definition: search.h:40
void ged_close(struct ged *gedp)
struct ged * ged_open(const char *dbtype, const char *filename, int existing_only)
void(* ged_refresh_func_t)(void *)
Definition: defines.h:86
const char * ged_results_get(struct ged_results *results, size_t index)
#define RT_VDRW_MAXNAME
Definition: defines.h:123
int(* ged_func_ptr)(struct ged *, int, const char *[])
Definition: defines.h:81
size_t ged_results_count(struct ged_results *results)
void ged_results_clear(struct ged_results *results)
void ged_free(struct ged *gedp)
void(* ged_destroy_vlist_func_t)(unsigned int, int)
Definition: defines.h:89
const char * ged_init_msgs(void)
void(* ged_create_vlist_display_list_func_t)(struct display_list *)
Definition: defines.h:88
void ged_results_free(struct ged_results *results)
void(* ged_create_vlist_solid_func_t)(struct bv_scene_obj *)
Definition: defines.h:87
void(* ged_io_func_t)(void *, int)
Definition: defines.h:85
void ged_init(struct ged *gedp)
Definition: list.h:131
Definition: ptbl.h:53
Definition: vls.h:53
Definition: defines.h:476
struct ged_cmd_impl * i
Definition: defines.h:371
int gd_rt_cmd_len
Definition: defines.h:168
struct bu_vls gd_qray_basename
basename of query ray vlist
Definition: defines.h:175
int gd_qray_cmd_echo
0 - don't echo command, 1 - echo command
Definition: defines.h:178
struct bu_list * gd_headVDraw
head of vdraw list
Definition: defines.h:164
struct ged_qray_color gd_qray_odd_color
Definition: defines.h:180
struct ged_qray_color gd_qray_overlap_color
Definition: defines.h:183
struct bu_vls gd_qray_script
query ray script
Definition: defines.h:176
void(* gd_rtCmdNotify)(int aborted)
function called when rt command completes
Definition: defines.h:170
int gd_shaded_mode
1 - draw bots shaded by default
Definition: defines.h:184
struct ged_qray_color gd_qray_void_color
Definition: defines.h:182
char ** gd_rt_cmd
Definition: defines.h:167
struct ged_qray_color gd_qray_even_color
Definition: defines.h:181
struct ged_qray_fmt * gd_qray_fmts
Definition: defines.h:179
char gd_qray_effects
t for text, g for graphics or b for both
Definition: defines.h:177
struct bu_list * gd_headDisplay
head of display list
Definition: defines.h:163
int gd_uplotOutputMode
output mode for unix plots
Definition: defines.h:172
struct vd_curve * gd_currVHead
current vdraw head
Definition: defines.h:165
const struct ged_cmd **const cmds
Definition: defines.h:376
uint32_t api_version
Definition: defines.h:375
int cmd_cnt
Definition: defines.h:377
unsigned char b
Definition: defines.h:144
unsigned char g
Definition: defines.h:143
unsigned char r
Definition: defines.h:142
struct bu_vls fmt
Definition: defines.h:150
char type
Definition: defines.h:149
int stdin_active
Definition: defines.h:135
struct bu_process * p
Definition: defines.h:129
int stderr_active
Definition: defines.h:137
uint32_t magic
magic number
Definition: defines.h:128
int stdout_active
Definition: defines.h:136
void(* end_clbk)(int, void *)
function called when process completes
Definition: defines.h:133
struct ged * gedp
Definition: defines.h:132
void * chan
Definition: defines.h:130
void * end_clbk_data
Definition: defines.h:134
Definition: defines.h:195
struct fbserv_obj * ged_fbs
Definition: defines.h:300
void(* ged_output_handler)(struct ged *, char *)
function for handling output
Definition: defines.h:265
void(* fbs_open_server_handler)(struct fbserv_obj *)
platform/toolkit method to open listener handler
Definition: defines.h:303
struct bu_vls * ged_result_str
Definition: defines.h:226
void(* ged_create_vlist_scene_obj_callback)(struct bv_scene_obj *)
function to call after creating a vlist to create display list for solid
Definition: defines.h:266
void * ged_subprocess_clbk_context
Definition: defines.h:278
int(* run)(struct ged *gedp, int ac, char *av[])
Definition: defines.h:256
struct ged_cmd * cmds
Definition: defines.h:253
int(* del)(struct ged *gedp, const char *name)
Definition: defines.h:255
int(* fbs_listen_on_port)(struct fbserv_obj *, int)
return 1 on success, 0 on failure
Definition: defines.h:302
struct ged_selection_sets * ged_selection_sets
Definition: defines.h:235
struct ged_results * ged_results
Definition: defines.h:227
int ged_internal_call
Definition: defines.h:242
void(* ged_subprocess_end_callback)(int, void *)
function called when process completes
Definition: defines.h:277
void(* fbs_close_server_handler)(struct fbserv_obj *)
platform/toolkit method to close handler listener
Definition: defines.h:304
db_search_callback_t ged_interp_eval
Definition: defines.h:328
struct bu_vls * ged_log
Definition: defines.h:213
struct ged_callback_state * ged_cbs
Definition: defines.h:262
struct bview * ged_gvp
Definition: defines.h:203
void(* ged_create_io_handler)(struct ged_subprocess *gp, bu_process_io_t d, ged_io_func_t callback, void *data)
Definition: defines.h:292
struct bu_vls go_name
Definition: defines.h:196
struct bu_ptbl free_solids
Definition: defines.h:230
void * ged_interp
Definition: defines.h:327
void * ged_ctx
Definition: defines.h:325
void(* ged_delete_io_handler)(struct ged_subprocess *gp, bu_process_io_t fd)
Definition: defines.h:293
void * ged_refresh_clientdata
client data passed to refresh handler
Definition: defines.h:264
int(* add)(struct ged *gedp, const struct ged_cmd *cmd)
Definition: defines.h:254
struct ged_drawable * ged_gdp
Definition: defines.h:229
void(* ged_subprocess_init_callback)(int, void *)
function called when process starts
Definition: defines.h:276
void(* ged_refresh_handler)(void *)
function for handling refresh requests
Definition: defines.h:263
void(* fbs_close_client_handler)(struct fbserv_obj *, int)
platform/toolkit method to close handler for client at index client_id
Definition: defines.h:306
struct bu_ptbl ged_subp
forked sub-processes
Definition: defines.h:258
char * ged_output_script
script for use by the outputHandler
Definition: defines.h:232
struct bview_set ged_views
Definition: defines.h:205
struct ged_selection_set * ged_cset
Definition: defines.h:236
struct db_i * dbip
Definition: defines.h:197
void * ged_io_data
Definition: defines.h:294
void(* ged_create_vlist_display_list_callback)(struct display_list *)
function to call after all vlist created that loops through creating display list for each solid
Definition: defines.h:267
void * u_data
User data associated with this ged instance.
Definition: defines.h:210
struct bg_mesh_lod_context * ged_lod
Definition: defines.h:207
void(* fbs_open_client_handler)(struct fbserv_obj *, int, void *)
platform/toolkit specific client handler setup (called by fbs_new_client)
Definition: defines.h:305
void(* ged_destroy_vlist_callback)(unsigned int, int)
function to call after freeing a vlist
Definition: defines.h:268
int(* fbs_is_listening)(struct fbserv_obj *)
return 1 if listening, else 0
Definition: defines.h:301
char vdc_name[RT_VDRW_MAXNAME+1]
name array
Definition: defines.h:155
long vdc_rgb
color
Definition: defines.h:156
struct bu_list vdc_vhd
head of list of vertices
Definition: defines.h:157
struct bu_list l
Definition: defines.h:154