Revision: 41212
http://brlcad.svn.sourceforge.net/brlcad/?rev=41212&view=rev
Author: brlcad
Date: 2010-11-02 10:31:29 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
convert to try/catch block exception style, cleanup ws
Modified Paths:
--------------
brlcad/trunk/src/conv/nmg/nmg-bot.c
Modified: brlcad/trunk/src/conv/nmg/nmg-bot.c
===================================================================
--- brlcad/trunk/src/conv/nmg/nmg-bot.c 2010-11-02 10:23:07 UTC (rev 41211)
+++ brlcad/trunk/src/conv/nmg/nmg-bot.c 2010-11-02 10:31:29 UTC (rev 41212)
@@ -45,7 +45,7 @@
static struct rt_wdb *fdout=NULL;
static void
-nmg_conv(struct rt_db_internal *intern, const char *name )
+nmg_conv(struct rt_db_internal *intern, const char *name)
{
struct model *m;
struct nmgregion *r;
@@ -53,100 +53,101 @@
RT_CK_DB_INTERNAL(intern);
m = (struct model *)intern->idb_ptr;
- NMG_CK_MODEL( m );
- r = BU_LIST_FIRST( nmgregion, &m->r_hd );
- if (r && BU_LIST_NEXT( nmgregion, &r->l ) != (struct nmgregion *)&m->r_hd
)
- bu_exit(1, "ERROR: this code works only for NMG models with one
region!\n" );
+ NMG_CK_MODEL(m);
+ r = BU_LIST_FIRST(nmgregion, &m->r_hd);
+ if (r && BU_LIST_NEXT(nmgregion, &r->l) != (struct nmgregion *)&m->r_hd)
+ bu_exit(1, "ERROR: this code works only for NMG models with one
region!\n");
- s = BU_LIST_FIRST( shell, &r->s_hd );
- if (s && BU_LIST_NEXT( shell, &s->l) != (struct shell *)&r->s_hd )
- bu_exit(1, "ERROR: this code works only for NMG models with one
shell!\n" );
+ s = BU_LIST_FIRST(shell, &r->s_hd);
+ if (s && BU_LIST_NEXT(shell, &s->l) != (struct shell *)&r->s_hd)
+ bu_exit(1, "ERROR: this code works only for NMG models with one
shell!\n");
- if (BU_SETJUMP) {
+ if (!s) {
+ bu_log("WARNING: NMG has no shells\n");
+ return;
+ }
+
+ if (!BU_SETJUMP) {
+ /* try */
+ mk_bot_from_nmg(fdout, name, s);
+ } else {
+ /* catch */
BU_UNSETJUMP;
- bu_log( "Failed to convert %s\n", name );
- rt_db_free_internal(intern);
+ bu_log("Failed to convert %s\n", name);
return;
- }
- if (s) {
- mk_bot_from_nmg( fdout, name, s);
- }
- BU_UNSETJUMP;
+ } BU_UNSETJUMP;
+
if (verbose) bu_log("Converted %s to a Bot solid\n", name);
- rt_db_free_internal(intern);
}
+
int
main(int argc, char **argv)
{
struct directory *dp;
- if ( argc != 3 && argc != 4 )
- {
- bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0] );
+ if (argc != 3 && argc != 4) {
+ bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0]);
}
- if ( argc == 4 )
- {
- if ( !strcmp( argv[1], "-v" ) )
+ if (argc == 4) {
+ if (!strcmp(argv[1], "-v"))
verbose = 1;
- else
- {
- bu_log( "Illegal option: %s\n", argv[1] );
- bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0] );
+ else {
+ bu_log("Illegal option: %s\n", argv[1]);
+ bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0]);
}
}
- rt_init_resource( &rt_uniresource, 0, NULL );
+ rt_init_resource(&rt_uniresource, 0, NULL);
- dbip = db_open( argv[argc-2], "r" );
- if ( dbip == DBI_NULL )
- {
- perror( argv[0] );
- bu_exit(1, "Cannot open file (%s)\n", argv[argc-2] );
+ dbip = db_open(argv[argc-2], "r");
+ if (dbip == DBI_NULL) {
+ perror(argv[0]);
+ bu_exit(1, "Cannot open file (%s)\n", argv[argc-2]);
}
- if ( (fdout=wdb_fopen( argv[argc-1] )) == NULL )
- {
- perror( argv[0] );
- bu_exit(1, "Cannot open file (%s)\n", argv[argc-1] );
+ if ((fdout=wdb_fopen(argv[argc-1])) == NULL) {
+ perror(argv[0]);
+ bu_exit(1, "Cannot open file (%s)\n", argv[argc-1]);
}
- if ( db_dirbuild( dbip ) ) {
- bu_exit(1, "db_dirbuild failed\n" );
+ if (db_dirbuild(dbip)) {
+ bu_exit(1, "db_dirbuild failed\n");
}
/* Visit all records in input database, and spew them out,
* modifying NMG objects into BoTs.
*/
- FOR_ALL_DIRECTORY_START(dp, dbip) {
- struct rt_db_internal intern;
+ FOR_ALL_DIRECTORY_START(dp, dbip) {
+ struct rt_db_internal intern;
int id;
int ret;
- id = rt_db_get_internal( &intern, dp, dbip, NULL, &rt_uniresource );
- if ( id < 0 ) {
+ id = rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource);
+ if (id < 0) {
fprintf(stderr,
"%s: rt_db_get_internal(%s) failure, skipping\n",
argv[0], dp->d_namep);
continue;
}
- if ( id == ID_NMG ) {
- nmg_conv( &intern, dp->d_namep );
+ if (id == ID_NMG) {
+ nmg_conv(&intern, dp->d_namep);
} else {
- ret = wdb_put_internal( fdout, dp->d_namep, &intern, 1.0 );
- if ( ret < 0 ) {
+ ret = wdb_put_internal(fdout, dp->d_namep, &intern, 1.0);
+ if (ret < 0) {
fprintf(stderr,
"%s: wdb_put_internal(%s) failure, skipping\n",
argv[0], dp->d_namep);
rt_db_free_internal(&intern);
continue;
}
- rt_db_free_internal(&intern);
}
+ rt_db_free_internal(intern);
} FOR_ALL_DIRECTORY_END
wdb_close(fdout);
return 0;
}
+
/*
* Local Variables:
* mode: C
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits