BRL-CAD
cc.c
Go to the documentation of this file.
1 /* C C . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2009-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/cc.c
21  *
22  * The cc (create constraint) command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "raytrace.h"
31 #include "wdb.h"
32 #include "bu/cmd.h"
33 
34 #include "./ged_private.h"
35 
36 
37 #define RT_TERMINAL_WIDTH 80
38 #define RT_COLUMNS ((RT_TERMINAL_WIDTH + V4_MAXNAME - 1) / V4_MAXNAME)
39 
40 
41 /*
42  * List constraint objects in this database
43  */
44 int
45 ged_cc(struct ged *gedp, int argc, const char *argv[])
46 {
47  static const char *usage = "name constraint_expression";
48 
49  struct rt_db_internal internal;
50  struct rt_constraint_internal *con_ip;
51  struct directory *dp;
52 
55  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
56 
57  /* initialize result */
58  bu_vls_trunc(gedp->ged_result_str, 0);
59  if (argc != 3) {
60  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
61  return GED_HELP;
62  }
63 
64  GED_CHECK_EXISTS(gedp, argv[1], LOOKUP_QUIET, GED_ERROR);
65  GED_CHECK_EXISTS(gedp, argv[2], LOOKUP_QUIET, GED_ERROR);
66 
67  RT_DB_INTERNAL_INIT(&internal);
68  internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
69  internal.idb_type = ID_CONSTRAINT;
70  internal.idb_meth=&OBJ[ID_CONSTRAINT];
71 
72  BU_ALLOC(internal.idb_ptr, struct rt_constraint_internal);
73  con_ip = (struct rt_constraint_internal *)internal.idb_ptr;
74  con_ip->magic = RT_CONSTRAINT_MAGIC;
75  con_ip->id = 324;
76  con_ip->type = 4;
77  bu_vls_init(&(con_ip->expression));
78  bu_vls_strcat(&(con_ip->expression), argv[2]);
79 
80  GED_DB_DIRADD(gedp, dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_NON_GEOM , (void *)&internal.idb_type, GED_ERROR);
81  GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR);
82 
83  bu_vls_printf(gedp->ged_result_str, "Constraint saved");
84  return GED_OK;
85 }
86 
87 
88 /*
89  * Local Variables:
90  * tab-width: 8
91  * mode: C
92  * indent-tabs-mode: t
93  * c-file-style: "stroustrup"
94  * End:
95  * ex: shiftwidth=4 tabstop=8
96  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_DB_DIRADD(_gedp, _dp, _name, _laddr, _len, _dirflags, _ptr, _flags)
Definition: ged.h:213
void bu_vls_init(struct bu_vls *vp)
Definition: vls.c:56
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
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
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
struct bu_vls expression
Definition: raytrace.h:1026
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
#define ID_CONSTRAINT
Constraint object.
Definition: raytrace.h:503
#define RT_DIR_NON_GEOM
object is not geometry (e.g. binary object)
Definition: raytrace.h:887
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
#define RT_DB_INTERNAL_INIT(_p)
Definition: raytrace.h:199
#define LOOKUP_QUIET
Definition: raytrace.h:893
#define RT_DIR_PHONY_ADDR
Special marker for d_addr field.
Definition: raytrace.h:879
int ged_cc(struct ged *gedp, int argc, const char *argv[])
Definition: cc.c:45
#define GED_CHECK_EXISTS(_gedp, _name, _noisy, _flags)
Definition: ged.h:171
struct bu_vls * ged_result_str
Definition: ged.h:357
const struct rt_functab OBJ[]
Definition: table.c:159
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
#define idb_type
Definition: raytrace.h:198
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
#define RT_CONSTRAINT_MAGIC
Definition: magic.h:154