BRL-CAD
hide.c
Go to the documentation of this file.
1 /* H I D E . 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/hide.c
21  *
22  * The hide command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_hide(struct ged *gedp, int argc, const char *argv[])
37 {
38  struct directory *dp;
39  struct db_i *dbip;
40  struct bu_external ext;
41  struct bu_external tmp;
42  struct db5_raw_internal raw;
43  int i;
44  static const char *usage = "<objects>";
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  dbip = gedp->ged_wdbp->dbip;
60 
61  if (db_version(dbip) < 5) {
62  bu_vls_printf(gedp->ged_result_str, "Database was created with a previous release of BRL-CAD.\nSelect \"Tools->Upgrade Database...\" to enable support for this feature.");
63  return GED_ERROR;
64  }
65 
66  for (i = 1; i < argc; i++) {
67  if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) {
68  continue;
69  }
70 
71  RT_CK_DIR(dp);
72 
73  BU_EXTERNAL_INIT(&ext);
74 
75  if (db_get_external(&ext, dp, dbip) < 0) {
76  bu_vls_printf(gedp->ged_result_str, "db_get_external failed for %s\n", dp->d_namep);
77  continue;
78  }
79 
80  if (db5_get_raw_internal_ptr(&raw, ext.ext_buf) == NULL) {
81  bu_vls_printf(gedp->ged_result_str, "db5_get_raw_internal_ptr() failed for %s\n", dp->d_namep);
82  bu_free_external(&ext);
83  continue;
84  }
85 
86  raw.h_name_hidden = (unsigned char)(0x1);
87 
88  BU_EXTERNAL_INIT(&tmp);
89  db5_export_object3(&tmp, DB5HDR_HFLAGS_DLI_APPLICATION_DATA_OBJECT,
90  dp->d_namep,
91  raw.h_name_hidden,
92  &raw.attributes,
93  &raw.body,
94  raw.major_type, raw.minor_type,
95  raw.a_zzz, raw.b_zzz);
96  bu_free_external(&ext);
97 
98  if (db_put_external(&tmp, dp, dbip)) {
99  bu_vls_printf(gedp->ged_result_str, "db_put_external() failed for %s\n", dp->d_namep);
100  bu_free_external(&tmp);
101  continue;
102  }
103  bu_free_external(&tmp);
104  dp->d_flags |= RT_DIR_HIDDEN;
105  }
106 
107  return GED_OK;
108 }
109 
110 
111 /*
112  * Local Variables:
113  * tab-width: 8
114  * mode: C
115  * indent-tabs-mode: t
116  * c-file-style: "stroustrup"
117  * End:
118  * ex: shiftwidth=4 tabstop=8
119  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
char * d_namep
pointer to name string
Definition: raytrace.h:859
Definition: raytrace.h:800
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
const unsigned char * db5_get_raw_internal_ptr(struct db5_raw_internal *rip, const unsigned char *ip)
Definition: db5_io.c:245
#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
int db_version(struct db_i *dbip)
Definition: db5_scan.c:414
void bu_free_external(struct bu_external *ep)
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_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int db_get_external(struct bu_external *ep, const struct directory *dp, const struct db_i *dbip)
#define RT_CK_DIR(_dp)
Definition: raytrace.h:876
uint8_t * ext_buf
Definition: parse.h:216
#define RT_DIR_HIDDEN
object name is hidden
Definition: raytrace.h:886
int ged_hide(struct ged *gedp, int argc, const char *argv[])
Definition: hide.c:36
struct bu_vls * ged_result_str
Definition: ged.h:357
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 LOOKUP_NOISY
Definition: raytrace.h:892
#define BU_EXTERNAL_INIT(_p)
Definition: parse.h:229
#define GED_HELP
Definition: ged.h:62
int db_put_external(struct bu_external *ep, struct directory *dp, struct db_i *dbip)
Definition: db_io.c:281
void db5_export_object3(struct bu_external *out, int dli, const char *name, const unsigned char hidden, const struct bu_external *attrib, const struct bu_external *body, int major, int minor, int a_zzz, int b_zzz)
Definition: db5_io.c:420
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
int d_flags
flags
Definition: raytrace.h:869