Skip to content

Commit

Permalink
Move the metaball code to more specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Dec 2, 2024
1 parent 7ac44ff commit c3ff6fe
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 99 deletions.
1 change: 1 addition & 0 deletions src/libged/edit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(edit_srcs
scale_eto.c
scale_extrude.c
scale_hyp.c
scale_metaball.c
scale_part.c
scale_pipe.c
scale_rhc.c
Expand Down
7 changes: 7 additions & 0 deletions src/libged/edit/ged_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ extern int _ged_scale_hyp(struct ged *gedp,
fastf_t sf,
int rflag);

/* defined in edit_metaball.c */
GED_EXPORT extern int _ged_scale_metaball(struct ged *gedp,
struct rt_metaball_internal *mbip,
const char *attribute,
fastf_t sf,
int rflag);

/* defined in scale_part.c */
GED_EXPORT extern int _ged_scale_part(struct ged *gedp,
struct rt_part_internal *part,
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_ehy.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_ehy(struct ged *gedp, struct rt_ehy_internal *ehy, const char *attribute, fastf_t sf, int rflag)
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_ell.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_ell(struct ged *gedp, struct rt_ell_internal *ell, const char *attribute, fastf_t sf, int rflag)
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_epa.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_epa(struct ged *gedp, struct rt_epa_internal *epa, const char *attribute, fastf_t sf, int rflag)
Expand Down
2 changes: 1 addition & 1 deletion src/libged/edit/scale_eto.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "raytrace.h"

#include "../ged_private.h"

#include "./ged_edit.h"

int
_ged_scale_eto(struct ged *gedp, struct rt_eto_internal *eto, const char *attribute, fastf_t sf, int rflag)
Expand Down
2 changes: 1 addition & 1 deletion src/libged/edit/scale_extrude.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "raytrace.h"

#include "../ged_private.h"

#include "./ged_edit.h"

int
_ged_scale_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, fastf_t sf, int rflag)
Expand Down
2 changes: 1 addition & 1 deletion src/libged/edit/scale_hyp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "raytrace.h"

#include "../ged_private.h"

#include "./ged_edit.h"

int
_ged_scale_hyp(struct ged *gedp, struct rt_hyp_internal *hyp, const char *attribute, fastf_t sf, int rflag)
Expand Down
98 changes: 98 additions & 0 deletions src/libged/edit/scale_metaball.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* S C A L E _ M E T A B A L L . C
* BRL-CAD
*
* Copyright (c) 2008-2024 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.
*/
/** @file libged/scale_metaball.c
*
* The scale_metaball command.
*
*/

#include "common.h"

#include <string.h>

#include "bu/cmd.h"
#include "rt/geom.h"
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

#define GED_METABALL_SCALE(_d, _scale) \
if ((_scale) < 0.0) \
(_d) = -(_scale); \
else \
(_d) *= (_scale);

int
_ged_scale_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf, int rflag)
{
int mbp_i;
struct wdb_metaball_pnt *mbpp;

RT_METABALL_CK_MAGIC(mbip);

if (!rflag && sf > 0)
sf = -sf;

switch (attribute[0]) {
case 'f':
case 'F':
if (sscanf(attribute+1, "%d", &mbp_i) != 1)
mbp_i = 0;

if ((mbpp = rt_metaball_get_pt_i(mbip, mbp_i)) == (struct wdb_metaball_pnt *)NULL)
return BRLCAD_ERROR;

BU_CKMAG(mbpp, WDB_METABALLPT_MAGIC, "wdb_metaball_pnt");
GED_METABALL_SCALE(mbpp->fldstr, sf);

break;
case 's':
case 'S':
if (sscanf(attribute+1, "%d", &mbp_i) != 1)
mbp_i = 0;

if ((mbpp = rt_metaball_get_pt_i(mbip, mbp_i)) == (struct wdb_metaball_pnt *)NULL)
return BRLCAD_ERROR;

BU_CKMAG(mbpp, WDB_METABALLPT_MAGIC, "wdb_metaball_pnt");
GED_METABALL_SCALE(mbpp->sweat, sf);

break;
default:
bu_vls_printf(gedp->ged_result_str, "bad metaball attribute - %s", attribute);
return BRLCAD_ERROR;
}

return BRLCAD_OK;
}




/*
* Local Variables:
* tab-width: 8
* mode: C
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
1 change: 1 addition & 0 deletions src/libged/edit/scale_part.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_part(struct ged *gedp, struct rt_part_internal *part, const char *attribute, fastf_t sf, int rflag)
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_rhc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_rhc(struct ged *gedp, struct rt_rhc_internal *rhc, const char *attribute, fastf_t sf, int rflag)
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_rpc(struct ged *gedp, struct rt_rpc_internal *rpc, const char *attribute, fastf_t sf, int rflag)
Expand Down
1 change: 1 addition & 0 deletions src/libged/edit/scale_superell.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raytrace.h"

#include "../ged_private.h"
#include "./ged_edit.h"

int
_ged_scale_superell(struct ged *gedp, struct rt_superell_internal *superell, const char *attribute, fastf_t sf, int rflag)
Expand Down
2 changes: 1 addition & 1 deletion src/libged/edit/scale_tgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "raytrace.h"

#include "../ged_private.h"

#include "./ged_edit.h"

int
_ged_scale_tgc(struct ged *gedp, struct rt_tgc_internal *tgc, const char *attribute, fastf_t sf, int rflag)
Expand Down
2 changes: 1 addition & 1 deletion src/libged/edit/scale_tor.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "raytrace.h"

#include "../ged_private.h"

#include "./ged_edit.h"

int
_ged_scale_tor(struct ged *gedp, struct rt_tor_internal *tor, const char *attribute, fastf_t sf, int rflag)
Expand Down
17 changes: 5 additions & 12 deletions src/libged/ged_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ GED_EXPORT extern void _ged_do_list(struct ged *gedp,
struct directory *dp,
int verbose);

/* defined in loadview.c */
/* defined in loadview.c
*
* TODO - I'm thinking these shouldn't exist... need to figure out how they're
* being used and make them go away.
**/
GED_EXPORT extern vect_t _ged_eye_model;
GED_EXPORT extern mat_t _ged_viewrot;
GED_EXPORT extern struct ged *_ged_current_gedp;
Expand Down Expand Up @@ -359,17 +363,6 @@ GED_EXPORT extern void _ged_rt_write(struct ged *gedp,
GED_EXPORT extern void _ged_wait_status(struct bu_vls *logstr,
int status);

/* defined in edit_metaball.c */
GED_EXPORT extern int _ged_scale_metaball(struct ged *gedp,
struct rt_metaball_internal *mbip,
const char *attribute,
fastf_t sf,
int rflag);
GED_EXPORT extern int _ged_set_metaball(struct ged *gedp,
struct rt_metaball_internal *mbip,
const char *attribute,
fastf_t sf);

/* defined in ged_util.cpp */
GED_EXPORT struct directory **
_ged_dir_getspace(struct db_i *dbip,
Expand Down
82 changes: 0 additions & 82 deletions src/libged/ged_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,88 +2241,6 @@ _ged_dir_getspace(struct db_i *dbip,
return dir_basep;
}

int
_ged_set_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf)
{
RT_METABALL_CK_MAGIC(mbip);

switch (attribute[0]) {
case 'm':
case 'M':
if (sf <= METABALL_METABALL)
mbip->method = METABALL_METABALL;
else if (sf >= METABALL_BLOB)
mbip->method = METABALL_BLOB;
else
mbip->method = (int)sf;

break;
case 't':
case 'T':
if (sf < 0)
mbip->threshold = -sf;
else
mbip->threshold = sf;

break;
default:
bu_vls_printf(gedp->ged_result_str, "bad metaball attribute - %s", attribute);
return BRLCAD_ERROR;
}

return BRLCAD_OK;
}

#define GED_METABALL_SCALE(_d, _scale) \
if ((_scale) < 0.0) \
(_d) = -(_scale); \
else \
(_d) *= (_scale);

int
_ged_scale_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf, int rflag)
{
int mbp_i;
struct wdb_metaball_pnt *mbpp;

RT_METABALL_CK_MAGIC(mbip);

if (!rflag && sf > 0)
sf = -sf;

switch (attribute[0]) {
case 'f':
case 'F':
if (sscanf(attribute+1, "%d", &mbp_i) != 1)
mbp_i = 0;

if ((mbpp = rt_metaball_get_pt_i(mbip, mbp_i)) == (struct wdb_metaball_pnt *)NULL)
return BRLCAD_ERROR;

BU_CKMAG(mbpp, WDB_METABALLPT_MAGIC, "wdb_metaball_pnt");
GED_METABALL_SCALE(mbpp->fldstr, sf);

break;
case 's':
case 'S':
if (sscanf(attribute+1, "%d", &mbp_i) != 1)
mbp_i = 0;

if ((mbpp = rt_metaball_get_pt_i(mbip, mbp_i)) == (struct wdb_metaball_pnt *)NULL)
return BRLCAD_ERROR;

BU_CKMAG(mbpp, WDB_METABALLPT_MAGIC, "wdb_metaball_pnt");
GED_METABALL_SCALE(mbpp->sweat, sf);

break;
default:
bu_vls_printf(gedp->ged_result_str, "bad metaball attribute - %s", attribute);
return BRLCAD_ERROR;
}

return BRLCAD_OK;
}

#if 0

// TODO - need to generalize the path specifier parsing per notes in TODO. This is a first
Expand Down
31 changes: 31 additions & 0 deletions src/libged/pset/pset.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@

#include "../ged_private.h"

static int
_ged_set_metaball(struct ged *gedp, struct rt_metaball_internal *mbip, const char *attribute, fastf_t sf)
{
RT_METABALL_CK_MAGIC(mbip);

switch (attribute[0]) {
case 'm':
case 'M':
if (sf <= METABALL_METABALL)
mbip->method = METABALL_METABALL;
else if (sf >= METABALL_BLOB)
mbip->method = METABALL_BLOB;
else
mbip->method = (int)sf;

break;
case 't':
case 'T':
if (sf < 0)
mbip->threshold = -sf;
else
mbip->threshold = sf;

break;
default:
bu_vls_printf(gedp->ged_result_str, "bad metaball attribute - %s", attribute);
return BRLCAD_ERROR;
}

return BRLCAD_OK;
}

int
ged_pset_core(struct ged *gedp, int argc, const char *argv[])
Expand Down

0 comments on commit c3ff6fe

Please sign in to comment.