BRL-CAD
bot_flip.c
Go to the documentation of this file.
1 /* B O T _ F L I P . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 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 /** @file libged/bot_flip.c
21  *
22  * The bot_flip command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "rtgeom.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 ged_bot_flip(struct ged *gedp, int argc, const char *argv[])
39 {
40  int i;
41  struct directory *dp;
42  struct rt_db_internal intern;
43  struct rt_bot_internal *bot;
44  static const char *usage = "bot [bot2 bot3 ...]";
45 
48  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
49 
50  /* initialize result */
51  bu_vls_trunc(gedp->ged_result_str, 0);
52 
53  /* must be wanting help */
54  if (argc == 1) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
56  return GED_HELP;
57  }
58 
59  for (i = 1; i < argc; ++i) {
60  /* Skip past any path elements */
61  char *obj = (char *)bu_calloc(strlen(argv[i]), sizeof(char), "ged_bot_flip obj");
62  bu_basename(obj, argv[i]);
63 
64  if (BU_STR_EQUAL(obj, ".")) {
65  /* malformed path, lookup using exactly what was provided */
66  bu_free(obj, "free bu_basename");
67  obj = bu_strdup(argv[i]);
68  }
69 
70  if ((dp = db_lookup(gedp->ged_wdbp->dbip, obj, LOOKUP_QUIET)) == RT_DIR_NULL) {
71  bu_vls_printf(gedp->ged_result_str, "%s: db_lookup(%s) error\n", argv[0], obj);
72  } else {
74 
75  if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) {
76  bu_vls_printf(gedp->ged_result_str, "%s: %s is not a BOT solid!\n", argv[0], obj);
77  } else {
78  bot = (struct rt_bot_internal *)intern.idb_ptr;
79  rt_bot_flip(bot);
80 
81  GED_DB_PUT_INTERNAL(gedp, dp, &intern, gedp->ged_wdbp->wdb_resp, GED_ERROR);
82  }
83  }
84  bu_free(obj, "free obj");
85  }
86 
87  return GED_OK;
88 }
89 
90 
91 /*
92  * Local Variables:
93  * tab-width: 8
94  * mode: C
95  * indent-tabs-mode: t
96  * c-file-style: "stroustrup"
97  * End:
98  * ex: shiftwidth=4 tabstop=8
99  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
const mat_t bn_mat_identity
Matrix and vector functionality.
Definition: mat.c:46
struct db_i * dbip
Definition: raytrace.h:1266
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags)
Definition: ged.h:243
int rt_bot_flip(struct rt_bot_internal *bot)
Definition: bot.c:4632
int idb_major_type
Definition: raytrace.h:192
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
#define LOOKUP_QUIET
Definition: raytrace.h:893
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_basename(char *basename, const char *path)
Definition: basename.c:30
void * idb_ptr
Definition: raytrace.h:195
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define RT_DIR_NULL
Definition: raytrace.h:875
#define GED_HELP
Definition: ged.h:62
int idb_minor_type
ID_xxx.
Definition: raytrace.h:193
#define GED_DB_GET_INTERNAL(_gedp, _intern, _dp, _mat, _resource, _flags)
Definition: ged.h:233
int ged_bot_flip(struct ged *gedp, int argc, const char *argv[])
Definition: bot_flip.c:38
struct resource * wdb_resp
Definition: raytrace.h:1270
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
#define bu_strdup(s)
Definition: str.h:71
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126