Skip to content

Commit

Permalink
Get ready to re-try the merge of scene_obj_manage
Browse files Browse the repository at this point in the history
First step is to revert the reversion of the original merge.
  • Loading branch information
starseeker committed Apr 11, 2022
1 parent 288e893 commit e4b642a
Show file tree
Hide file tree
Showing 68 changed files with 1,110 additions and 754 deletions.
2 changes: 1 addition & 1 deletion include/bg/polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ struct bv_polygon {
//
// v->gv_width = dm_get_width((struct dm *)v->dmp);
// v->gv_height = dm_get_height((struct dm *)v->dmp);
BG_EXPORT extern struct bv_scene_obj *bv_create_polygon(struct bview *v, int type, int x, int y, struct bv_scene_obj *free_scene_obj);
BG_EXPORT extern struct bv_scene_obj *bv_create_polygon(struct bview *v, int type, int x, int y);

// Various update modes have similar logic - we pass in the flags to the update
// routine to enable/disable specific portions of the overall flow.
Expand Down
1 change: 1 addition & 0 deletions include/bv.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "./bv/adc.h"
#include "./bv/util.h"
#include "./bv/vlist.h"
#include "./bv/view_sets.h"

#endif /* BV_H */

Expand Down
1 change: 1 addition & 0 deletions include/bv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(bv_headers
util.h
vectfont.h
vlist.h
view_sets.h
)
BRLCAD_MANAGE_FILES(bv_headers ${INCLUDE_DIR}/brlcad/bv)

Expand Down
36 changes: 22 additions & 14 deletions include/bv/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ struct bv_obj_settings {

struct bview;

#define BV_SCENE_OBJ_DB 0
#define BV_SCENE_OBJ_VIEW 1
#define BV_SCENE_OBJ_DB_LOCAL 2
#define BV_SCENE_OBJ_VIEW_LOCAL 3

#define BV_DB_OBJS 0x01
#define BV_VIEW_OBJS 0x02
#define BV_SHARED_OBJS 0x04

struct bv_scene_obj {
struct bu_list l;

Expand Down Expand Up @@ -278,9 +287,19 @@ struct bv_scene_obj {
/* Child objects of this object */
struct bu_ptbl children;

/* Object level pointers to parent containers. These are stored so
* that the object itself knows everything needed for data manipulation
* and it is unnecessary to explicitly pass other parameters. */

/* Reusable vlists */
struct bu_list *vlfree;

/* Container for reusing bv_scene_obj allocations */
struct bv_scene_obj *free_scene_obj;

/* View container containing this object */
struct bu_ptbl *otbl;

/* For more specialized routines not using vlists, we may need
* additional drawing data associated with a scene object */
void *draw_data;
Expand Down Expand Up @@ -413,7 +432,7 @@ struct bview_objs {
// Container for db object groups unique to this view (typical use case is
// adaptive plotting, where geometry wireframes may differ from view to
// view and thus need unique vlists.)
struct bu_ptbl *view_grps;
struct bu_ptbl *db_objs;
// Container for storing bv_scene_obj elements unique to this view.
struct bu_ptbl *view_objs;

Expand Down Expand Up @@ -526,22 +545,11 @@ struct bview {
// Because bview instances frequently share objects in applications, they are
// not always fully independent - we define a container and some basic
// operations to manage this.
struct bview_set_internal;
struct bview_set {
struct bu_ptbl views;
struct bu_ptbl shared_db_objs;
struct bu_ptbl shared_view_objs;
struct bview_set_internal *i;
struct bview_settings settings;

struct bv_scene_obj *free_scene_obj;
struct bu_list vlfree;
};
BV_EXPORT void
bv_set_init(struct bview_set *s);
BV_EXPORT void
bv_set_free(struct bview_set *s);

BV_EXPORT void
bv_set_add(struct bview_set *s, struct bview *v);

#endif /* BV_DEFINES_H */

Expand Down
51 changes: 45 additions & 6 deletions include/bv/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ BV_EXPORT extern unsigned long long bv_hash(struct bview *v);
/* Return a hash of the contents of a display list. Returns 0 on failure. */
BV_EXPORT extern unsigned long long bv_dl_hash(struct display_list *dl);

/* Return number of objects defined in any object container
* known to this view (0 if completely cleared). */
BV_EXPORT size_t
bv_clear(struct bview *v, int flags);

/* Note that some of these are mutually exclusive as far as producing any
* changes - a simultaneous constraint in X and Y, for example, results in a
Expand Down Expand Up @@ -97,12 +101,6 @@ BV_EXPORT extern int bv_adjust(struct bview *v, int dx, int dy, point_t keypoint
* calculation is impossible), else 0. */
BV_EXPORT extern int bv_screen_to_view(struct bview *v, fastf_t *fx, fastf_t *fy, fastf_t x, fastf_t y);

/* Initialize a scene object to standard default settings */
BV_EXPORT extern void bv_scene_obj_init(struct bv_scene_obj *s, struct bv_scene_obj *free_scene_obj);

/* Free the object contents, including all child objects */
BV_EXPORT extern void bv_scene_obj_free(struct bv_scene_obj *s, struct bv_scene_obj *free_scene_obj);

/* Compute the min, max, and center points of the scene object.
* Return 1 if a bound was computed, else 0 */
BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s);
Expand All @@ -111,6 +109,47 @@ BV_EXPORT extern int bv_scene_obj_bound(struct bv_scene_obj *s);
* the vlist points in s in the context of view v */
BV_EXPORT extern fastf_t bv_vZ_calc(struct bv_scene_obj *s, struct bview *v, int mode);


/* Given a view, create an object of the specified type. Issues such as memory
* management as a function of view settings are handled internally, so client
* codes don't need to manage it. */
BV_EXPORT struct bv_scene_obj *
bv_obj_get(struct bview *v, int type);

/* Given an object, create an object that is a child of that object. Issues
* such as memory management as a function of view settings are handled
* internally, so client codes don't need to manage it. */
BV_EXPORT struct bv_scene_obj *
bv_obj_get_child(struct bv_scene_obj *s);

/* Clear the contents of an object (including releasing its children), but keep
* it active in the view. Generally used when redrawing an object */
BV_EXPORT void
bv_obj_reset(struct bv_scene_obj *s);

/* Release an object to the internal pools. */
BV_EXPORT void
bv_obj_put(struct bv_scene_obj *o);

/* Given a scene object and a name vname, glob match child names and uuids to
* attempt to locate a child of s that matches vname */
BV_EXPORT struct bv_scene_obj *
bv_find_child(struct bv_scene_obj *s, const char *vname);

/* Given a view and a name vname, glob match names and uuids to attempt to
* locate a scene object in v that matches vname.
*
* NOTE - currently this is searching the top level objects, but does not walk
* down into their children. May want to support that in the future... */
BV_EXPORT struct bv_scene_obj *
bv_find_obj(struct bview *v, const char *vname);

/* For the given view, return a pointer to the bu_ptbl holding active scene
* objects with the specified type */
BV_EXPORT struct bu_ptbl *
bv_view_objs(struct bview *v, int type);


__END_DECLS

/** @} */
Expand Down
93 changes: 93 additions & 0 deletions include/bv/view_sets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* V I E W _ S E T S . H
* BRL-CAD
*
* Copyright (c) 1993-2022 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
/** @addtogroup bv_util
*
* In applications with multiple views, those views typically share common
* scene objects and memory. To manage this sharing, we define view sets.
*/
/** @{ */
/** @file bv/view_sets.h */

#ifndef BV_VIEW_SETS_H
#define BV_VIEW_SETS_H

#include "common.h"
#include "bv/defines.h"

__BEGIN_DECLS

/**
* Initialize an empty view set
*/
BV_EXPORT void
bv_set_init(struct bview_set *s);

/**
* Free view set
*/
BV_EXPORT void
bv_set_free(struct bview_set *s);

/**
* Add view v to set s, handling shared memory assignments.
*/
BV_EXPORT void
bv_set_add_view(struct bview_set *s, struct bview *v);

/**
* Remove view v from set s
*/
BV_EXPORT void
bv_set_rm_view(struct bview_set *s, struct bview *v);

/**
* Return a bu_ptbl holding pointers to all views in set s
*/
BV_EXPORT struct bu_ptbl *
bv_set_views(struct bview_set *s);

/**
* Return a pointer to the view with name vname, if it is present in s. If not
* found, returns NULL
*/
BV_EXPORT struct bview *
bv_set_find_view(struct bview_set *s, const char *vname);


// Expose free_scene_obj for older codes - do not use in new coding
BV_EXPORT struct bv_scene_obj *
bv_set_fsos(struct bview_set *s);


__END_DECLS

/** @} */

#endif /* BV_VIEW_SETS_H */

/*
* Local Variables:
* mode: C
* tab-width: 8
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
4 changes: 4 additions & 0 deletions include/bv/vlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ BV_EXPORT extern void bv_vlblock_to_objs(struct bu_ptbl *out,
struct bv_scene_obj *f,
struct bu_list *vlfree);


BV_EXPORT extern struct bv_scene_obj *
bv_vlblock_obj(struct bv_vlblock *vbp, struct bview *v, const char *name);

/**
* Output a vlist as an extended 3-D floating point UNIX-Plot file.
* You provide the file. Uses libplot3 routines to create the
Expand Down
2 changes: 0 additions & 2 deletions include/ged/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ GED_EXPORT extern struct bg_polygon *ged_import_polygon(struct ged *gedp, const
GED_EXPORT extern int ged_polygons_overlap(struct ged *gedp, struct bg_polygon *polyA, struct bg_polygon *polyB);
GED_EXPORT extern void ged_polygon_fill_segments(struct ged *gedp, struct bg_polygon *poly, vect2d_t vfilldir, fastf_t vfilldelta);

GED_EXPORT extern struct bview * ged_find_view(struct ged *gedp, const char *key);

__END_DECLS

#endif /* GED_VIEW_H */
Expand Down
2 changes: 1 addition & 1 deletion include/rt/primitives/sketch.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RT_EXPORT extern int curve_to_tcl_list(struct bu_vls *vls,
struct rt_curve *crv);

RT_EXPORT extern struct bv_scene_obj *
db_sketch_to_scene_obj(const char *sname, struct db_i *dbip, struct directory *dp, struct bview *sv, struct bv_scene_obj *free_scene_obj);
db_sketch_to_scene_obj(const char *sname, struct db_i *dbip, struct directory *dp, struct bview *sv);

RT_EXPORT extern struct directory *
db_scene_obj_to_sketch(struct db_i *dbip, const char *sname, struct bv_scene_obj *s);
Expand Down
Loading

0 comments on commit e4b642a

Please sign in to comment.