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-2022 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/* Forward declaration */
70struct ged;
71
72typedef int (*ged_func_ptr)(struct ged *, int, const char *[]);
73#define GED_FUNC_PTR_NULL ((ged_func_ptr)0)
74
75/* Callback related definitions */
76typedef void (*ged_io_func_t)(void *, int);
77typedef void (*ged_refresh_func_t)(void *);
80typedef void (*ged_destroy_vlist_func_t)(unsigned int, int);
81struct ged_callback_state;
82
83/**
84 * Definition of global parallel-processing semaphores.
85 *
86 */
87#define GED_SEM_WORKER ANALYZE_SEM_LAST
88#define GED_SEM_STATS GED_SEM_WORKER+1
89#define GED_SEM_LIST GED_SEM_STATS+1
90#define GED_SEM_LAST GED_SEM_LIST+1
91
92#define GED_INIT(_gedp, _wdbp) { \
93 ged_init((_gedp)); \
94 (_gedp)->ged_wdbp = (_wdbp); \
95 if ((_gedp)->ged_wdbp) { \
96 (_gedp)->dbip = (_gedp)->ged_wdbp->dbip; \
97 } \
98 }
99
100#define GED_INITIALIZED(_gedp) ((_gedp)->ged_wdbp != RT_WDB_NULL)
101#define GED_LOCAL2BASE(_gedp) ((_gedp)->ged_wdbp->dbip->dbi_local2base)
102#define GED_BASE2LOCAL(_gedp) ((_gedp)->ged_wdbp->dbip->dbi_base2local)
103
104/* From include/dm.h */
105#define GED_MAX 2047.0
106#define GED_MIN -2048.0
107#define GED_RANGE 4095.0
108#define INV_GED 0.00048828125
109#define INV_4096 0.000244140625
110
111/* FIXME: leftovers from dg.h */
112#define RT_VDRW_PREFIX "_VDRW"
113#define RT_VDRW_PREFIX_LEN 6
114#define RT_VDRW_MAXNAME 31
115#define RT_VDRW_DEF_COLOR 0xffff00
116
117
119 uint32_t magic; /**< @brief magic number */
120 struct bu_process *p;
121 void *chan;
123 struct ged *gedp;
127};
128
129/* FIXME: should be private */
131 unsigned char r;
132 unsigned char g;
133 unsigned char b;
134};
135
136/* FIXME: should be private */
138 char type;
139 struct bu_vls fmt;
140};
141
142struct vd_curve {
143 struct bu_list l;
144 char vdc_name[RT_VDRW_MAXNAME+1]; /**< @brief name array */
145 long vdc_rgb; /**< @brief color */
146 struct bu_list vdc_vhd; /**< @brief head of list of vertices */
147};
148#define VD_CURVE_NULL ((struct vd_curve *)NULL)
149
150/* FIXME: should be private */
152 struct bu_list *gd_headDisplay; /**< @brief head of display list */
153 struct bu_list *gd_headVDraw; /**< @brief head of vdraw list */
154 struct vd_curve *gd_currVHead; /**< @brief current vdraw head */
155
156 char **gd_rt_cmd; /* DEPRECATED - will be removed, do not use */
157 int gd_rt_cmd_len; /* DEPRECATED - will be removed, do not use */
158
159 void (*gd_rtCmdNotify)(int aborted); /**< @brief function called when rt command completes */
160
161 int gd_uplotOutputMode; /**< @brief output mode for unix plots */
162
163 /* qray state */
164 struct bu_vls gd_qray_basename; /**< @brief basename of query ray vlist */
165 struct bu_vls gd_qray_script; /**< @brief query ray script */
166 char gd_qray_effects; /**< @brief t for text, g for graphics or b for both */
167 int gd_qray_cmd_echo; /**< @brief 0 - don't echo command, 1 - echo command */
173 int gd_shaded_mode; /**< @brief 1 - draw bots shaded by default */
174};
175
176
177
178
179struct ged_cmd;
180
181/* struct details are private - use accessor functions to manipulate */
182struct ged_results;
183
184struct ged {
187 struct db_i *dbip;
188
189 /*************************************************************/
190 /* Information pertaining to views and view objects . */
191 /*************************************************************/
192 // The full set of views associated with this ged object
194 /* The current view */
195 struct bview *ged_gvp;
196
197 /* bv group objects corresponding to drawn .g solids and combs. Shared
198 * across multiple views */
200
201 /* View objects intended to be shared across multiple views (rtcheck
202 * overlap visualizations, for example.) */
204
205
206 /* Containers holding reusable view related structures. These
207 * are important for performance, since drawing routines regularly
208 * create and discard lots of these. */
212
213
214 void *u_data; /**< @brief User data associated with this ged instance */
215
216 /** for catching log messages */
218
219
220 /* @todo: add support for returning an array of objects, not just a
221 * simple string.
222 *
223 * the calling application needs to be able to distinguish the
224 * individual object names from the "ls" command without resorting
225 * to quirky string encoding or format-specific quote wrapping.
226 *
227 * want to consider whether we need a json-style dictionary, but
228 * probably a literal null-terminated array will suffice here.
229 */
232
234 struct bu_hash_tbl *ged_selections; /**< @brief object name -> struct rt_object_selections */
235
236 char *ged_output_script; /**< @brief script for use by the outputHandler */
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 /* Handler functions for I/O communication with asynchronous subprocess commands. There
271 * are two opaque data structures at play here, with different scopes. One is the "data"
272 * pointer passed to ged_create_io_handler, which is used to store command-specific
273 * information internal to the library (the simplest thing to do is pass ged_subprocess
274 * in as the data pointer, but if that's not enough - see for example rtcheck - this
275 * mechanism allows for more elaborate measures.
276 *
277 * The second is ged_io_data, which is set in gedp by the calling application. This is where
278 * information specific to the parent's I/O environment (which by definition the library
279 * can't know about as it is application specific) lives. It should be assigned in the
280 * applications gedp before any calls to ged_create_io_handler are made.
281 * */
282 void (*ged_create_io_handler)(struct ged_subprocess *gp, bu_process_io_t d, ged_io_func_t callback, void *data);
284 void *ged_io_data; /**< brief caller supplied data */
285
286 /* fbserv server and I/O callbacks. These must hook into the application's event
287 * loop, and so cannot be effectively supplied by low-level libraries - the
288 * application must tell us how to tie in with the toplevel event
289 * processing system it is using (typically toolkit specific). */
291 int (*fbs_is_listening)(struct fbserv_obj *); /**< @brief return 1 if listening, else 0 */
292 int (*fbs_listen_on_port)(struct fbserv_obj *, int); /**< @brief return 1 on success, 0 on failure */
293 void (*fbs_open_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to open listener handler */
294 void (*fbs_close_server_handler)(struct fbserv_obj *); /**< @brief platform/toolkit method to close handler listener */
295 void (*fbs_open_client_handler)(struct fbserv_obj *, int, void *); /**< @brief platform/toolkit specific client handler setup (called by fbs_new_client) */
296 void (*fbs_close_client_handler)(struct fbserv_obj *, int); /**< @brief platform/toolkit method to close handler for client at index client_id */
297
298 // Other callbacks...
299 // Tcl command strings - these are libtclcad level callbacks that execute user supplied Tcl commands if set:
300 // gdv_callback, gdv_edit_motion_delta_callback, go_more_args_callback, go_rt_end_callback
301 //
302 // fbserv_obj: fbs_callback
303 // bv.h gv_callback (only used by MGED?)
304 // db_search_callback_t
305
306 // TODO - this probably should be handled with a registration function of some kind
307 // that assigns contexts based on dm type - right now the dms more or less have to
308 // assume that whatever is in here is intended for their initialization, and if a
309 // program wants to attach multiple types of DMs a single pointer is not a great way
310 // to manage things. A map would be better, but that's a C++ construct so we can't
311 // expose it directly here - need some sort of means to manage the setting and getting,
312 // maybe with functions like:
313 // ged_ctx_set(const char *dm_type, void *ctx)
314 // ged_ctx_get(const char *dm_type)
315 void *ged_ctx; /* Temporary - do not rely on when designing new functionality */
316
317 void *ged_interp; /* Temporary - do not rely on when designing new functionality */
318 db_search_callback_t ged_interp_eval; /* FIXME: broke the rule written on the previous line */
319
320};
321
322/* accessor functions for ged_results - calling
323 * applications should not work directly with the
324 * internals of ged_results, which are not guaranteed
325 * to stay the same.
326 * defined in ged_util.c */
327GED_EXPORT extern size_t ged_results_count(struct ged_results *results);
328GED_EXPORT extern const char *ged_results_get(struct ged_results *results, size_t index);
329GED_EXPORT extern void ged_results_clear(struct ged_results *results);
330GED_EXPORT extern void ged_results_free(struct ged_results *results);
331
332
333
334GED_EXPORT extern void ged_close(struct ged *gedp);
335GED_EXPORT extern void ged_free(struct ged *gedp);
336GED_EXPORT extern void ged_init(struct ged *gedp);
337/* Call BU_PUT to release returned ged structure */
338GED_EXPORT extern struct ged *ged_open(const char *dbtype,
339 const char *filename,
340 int existing_only);
341
342
343/**
344 * make sure there is a command name given
345 *
346 * @todo - where should this go?
347 */
348#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags) \
349 if ((_argc) < 1) { \
350 int ged_check_argc_gt_0_quiet = (_flags) & BRLCAD_QUIET; \
351 if (!ged_check_argc_gt_0_quiet) { \
352 bu_vls_trunc((_gedp)->ged_result_str, 0); \
353 bu_vls_printf((_gedp)->ged_result_str, "Command name not provided on (%s:%d).", __FILE__, __LINE__); \
354 } \
355 return (_flags); \
356 }
357
358
359struct ged_cmd_impl;
360struct ged_cmd {
361 struct ged_cmd_impl *i;
362};
363
365 uint32_t api_version; /* must be first in struct */
366 const struct ged_cmd ** const cmds;
368};
369
370/* Report any messages from libged when plugins were initially loaded.
371 * Can be important when diagnosing command errors. */
372GED_EXPORT const char * ged_init_msgs();
373
374
375__END_DECLS
376
377#endif /* GED_DEFINES_H */
378
379/** @} */
380
381/*
382 * Local Variables:
383 * tab-width: 8
384 * mode: C
385 * indent-tabs-mode: t
386 * c-file-style: "stroustrup"
387 * End:
388 * ex: shiftwidth=4 tabstop=8
389 */
Header file for the BRL-CAD common definitions.
This header holds generic routines and data structures used for TCP based communication between a fra...
struct bu_hash_tbl bu_hash_tbl
Definition: hash.h:47
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:77
const char * ged_results_get(struct ged_results *results, size_t index)
#define RT_VDRW_MAXNAME
Definition: defines.h:114
int(* ged_func_ptr)(struct ged *, int, const char *[])
Definition: defines.h:72
size_t ged_results_count(struct ged_results *results)
void ged_results_clear(struct ged_results *results)
void ged_free(struct ged *gedp)
const char * ged_init_msgs()
void(* ged_destroy_vlist_func_t)(unsigned int, int)
Definition: defines.h:80
void(* ged_create_vlist_display_list_func_t)(struct display_list *)
Definition: defines.h:79
void ged_results_free(struct ged_results *results)
void(* ged_create_vlist_solid_func_t)(struct bv_scene_obj *)
Definition: defines.h:78
void(* ged_io_func_t)(void *, int)
Definition: defines.h:76
void ged_init(struct ged *gedp)
Definition: list.h:131
Definition: ptbl.h:53
Definition: vls.h:53
Definition: defines.h:364
struct ged_cmd_impl * i
Definition: defines.h:361
int gd_rt_cmd_len
Definition: defines.h:157
struct bu_vls gd_qray_basename
basename of query ray vlist
Definition: defines.h:164
int gd_qray_cmd_echo
0 - don't echo command, 1 - echo command
Definition: defines.h:167
struct bu_list * gd_headVDraw
head of vdraw list
Definition: defines.h:153
struct ged_qray_color gd_qray_odd_color
Definition: defines.h:169
struct ged_qray_color gd_qray_overlap_color
Definition: defines.h:172
struct bu_vls gd_qray_script
query ray script
Definition: defines.h:165
void(* gd_rtCmdNotify)(int aborted)
function called when rt command completes
Definition: defines.h:159
int gd_shaded_mode
1 - draw bots shaded by default
Definition: defines.h:173
struct ged_qray_color gd_qray_void_color
Definition: defines.h:171
char ** gd_rt_cmd
Definition: defines.h:156
struct ged_qray_color gd_qray_even_color
Definition: defines.h:170
struct ged_qray_fmt * gd_qray_fmts
Definition: defines.h:168
char gd_qray_effects
t for text, g for graphics or b for both
Definition: defines.h:166
struct bu_list * gd_headDisplay
head of display list
Definition: defines.h:152
int gd_uplotOutputMode
output mode for unix plots
Definition: defines.h:161
struct vd_curve * gd_currVHead
current vdraw head
Definition: defines.h:154
const struct ged_cmd **const cmds
Definition: defines.h:366
uint32_t api_version
Definition: defines.h:365
int cmd_cnt
Definition: defines.h:367
unsigned char b
Definition: defines.h:133
unsigned char g
Definition: defines.h:132
unsigned char r
Definition: defines.h:131
struct bu_vls fmt
Definition: defines.h:139
char type
Definition: defines.h:138
int stdin_active
Definition: defines.h:124
struct bu_process * p
Definition: defines.h:120
int stderr_active
Definition: defines.h:126
uint32_t magic
magic number
Definition: defines.h:119
int stdout_active
Definition: defines.h:125
struct ged * gedp
Definition: defines.h:123
void * chan
Definition: defines.h:121
Definition: defines.h:184
struct bv_scene_obj * free_scene_obj
Definition: defines.h:209
struct fbserv_obj * ged_fbs
Definition: defines.h:290
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:293
struct bu_vls * ged_result_str
Definition: defines.h:230
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
struct bu_ptbl ged_views
Definition: defines.h:193
int(* run)(struct ged *gedp, int ac, char *av[])
Definition: defines.h:256
struct ged_cmd * cmds
Definition: defines.h:253
struct rt_wdb * ged_wdbp
Definition: defines.h:186
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:292
struct ged_results * ged_results
Definition: defines.h:231
int ged_internal_call
Definition: defines.h:242
void(* fbs_close_server_handler)(struct fbserv_obj *)
platform/toolkit method to close handler listener
Definition: defines.h:294
db_search_callback_t ged_interp_eval
Definition: defines.h:318
struct bu_vls * ged_log
Definition: defines.h:217
struct ged_callback_state * ged_cbs
Definition: defines.h:262
struct bview * ged_gvp
Definition: defines.h:195
void(* ged_create_io_handler)(struct ged_subprocess *gp, bu_process_io_t d, ged_io_func_t callback, void *data)
Definition: defines.h:282
struct bu_vls go_name
Definition: defines.h:185
struct bu_ptbl free_solids
Definition: defines.h:210
void * ged_interp
Definition: defines.h:317
void * ged_ctx
Definition: defines.h:315
void(* ged_delete_io_handler)(struct ged_subprocess *gp, bu_process_io_t fd)
Definition: defines.h:283
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 bu_hash_tbl * ged_selections
object name -> struct rt_object_selections
Definition: defines.h:234
struct ged_drawable * ged_gdp
Definition: defines.h:233
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:296
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:236
struct db_i * dbip
Definition: defines.h:187
void * ged_io_data
Definition: defines.h:284
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:214
struct bu_ptbl ged_view_shared_objs
Definition: defines.h:203
void(* fbs_open_client_handler)(struct fbserv_obj *, int, void *)
platform/toolkit specific client handler setup (called by fbs_new_client)
Definition: defines.h:295
struct bu_ptbl ged_db_grps
Definition: defines.h:199
struct bu_list vlfree
Definition: defines.h:211
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:291
Definition: wdb.h:56
char vdc_name[RT_VDRW_MAXNAME+1]
name array
Definition: defines.h:144
long vdc_rgb
color
Definition: defines.h:145
struct bu_list vdc_vhd
head of list of vertices
Definition: defines.h:146
struct bu_list l
Definition: defines.h:143