BRL-CAD
tclcad.c
Go to the documentation of this file.
1 /* T C L C A D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program 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 program 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  */
21 /** @file libtclcad/tclcad.c
22  *
23  * Initialize BRL-CAD's Tcl interface.
24  *
25  */
26 
27 #include "common.h"
28 
29 #define RESOURCE_INCLUDED 1
30 #include <tcl.h>
31 #ifdef HAVE_TK
32 # include <tk.h>
33 #endif
34 
35 #include "dm.h"
36 #include "fb.h"
37 #include "bn.h"
38 #include "vmath.h"
39 #include "raytrace.h"
40 #include "tclcad.h"
41 
42 /* Private headers */
43 #include "brlcad_version.h"
44 #include "tclcad_private.h"
45 
46 
47 /* defined in cmdhist_obj.c */
48 extern int Cho_Init(Tcl_Interp *interp);
49 
50 
51 int
53 {
54  static int initialized = 0;
55  if (setit)
56  initialized = 1;
57 
58  return initialized;
59 }
60 
61 
62 static int
63 wrapper_func(ClientData data, Tcl_Interp *interp, int argc, const char *argv[])
64 {
65  struct bu_cmdtab *ctp = (struct bu_cmdtab *)data;
66 
67  return ctp->ct_func(interp, argc, argv);
68 }
69 
70 
71 void
72 tclcad_register_cmds(Tcl_Interp *interp, struct bu_cmdtab *cmds)
73 {
74  struct bu_cmdtab *ctp = NULL;
75 
76  for (ctp = cmds; ctp->ct_name != (char *)NULL; ctp++) {
77  (void)Tcl_CreateCommand(interp, ctp->ct_name, wrapper_func, (ClientData)ctp, (Tcl_CmdDeleteProc *)NULL);
78  }
79 }
80 
81 
82 int
83 Tclcad_Init(Tcl_Interp *interp)
84 {
85  if (library_initialized(0))
86  return TCL_OK;
87 
88  if (Tcl_Init(interp) == TCL_ERROR) {
89  return TCL_ERROR;
90  }
91 
92 #ifdef HAVE_TK
93  if (Tk_Init(interp) == TCL_ERROR) {
94  return TCL_ERROR;
95  }
96 #endif
97 
98  /* Locate the BRL-CAD-specific Tcl scripts, set the auto_path */
99  tclcad_auto_path(interp);
100 
101  /* Initialize [incr Tcl] */
102  if (Tcl_Eval(interp, "package require Itcl") != TCL_OK) {
103  bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
104  return TCL_ERROR;
105  }
106 
107 #ifdef HAVE_TK
108  /* Initialize [incr Tk] */
109  if (Tcl_Eval(interp, "package require Itk") != TCL_OK) {
110  bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
111  return TCL_ERROR;
112  }
113 #endif
114 
115  /* Initialize the Iwidgets package */
116  if (Tcl_Eval(interp, "package require Iwidgets") != TCL_OK) {
117  bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
118  return TCL_ERROR;
119  }
120 
121  /* Initialize libdm */
122  if (Dm_Init(interp) == TCL_ERROR) {
123  bu_log("Dm_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
124  return TCL_ERROR;
125  }
126 
127  /* Initialize libfb */
128  if (Fb_Init(interp) == TCL_ERROR) {
129  bu_log("Fb_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
130  return TCL_ERROR;
131  }
132 
133  /* Initialize libbu */
134  if (Bu_Init(interp) == TCL_ERROR) {
135  bu_log("Bu_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
136  return TCL_ERROR;
137  }
138 
139  /* Initialize libbn */
140  if (Bn_Init(interp) == TCL_ERROR) {
141  bu_log("Bn_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
142  return TCL_ERROR;
143  }
144 
145  /* Initialize librt */
146  if (Rt_Init(interp) == TCL_ERROR) {
147  bu_log("Rt_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
148  return TCL_ERROR;
149  }
150 
151  /* Initialize the GED object */
152  if (Go_Init(interp) == TCL_ERROR) {
153  bu_log("Go_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
154  return TCL_ERROR;
155  }
156 
157  /* initialize command history objects */
158  Cho_Init(interp);
159 
160  Tcl_PkgProvide(interp, "Tclcad", brlcad_version());
161 
162  (void)library_initialized(1);
163 
164  return TCL_OK;
165 }
166 
167 /*
168  * Local Variables:
169  * mode: C
170  * tab-width: 8
171  * indent-tabs-mode: t
172  * c-file-style: "stroustrup"
173  * End:
174  * ex: shiftwidth=4 tabstop=8
175  */
Definition: cmd.h:48
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
ustring interp
int Bu_Init(void *interp)
Definition: tcl.c:422
Header file for the BRL-CAD common definitions.
int Tclcad_Init(Tcl_Interp *interp)
Definition: tclcad.c:83
int Cho_Init(Tcl_Interp *interp)
Definition: cmdhist_obj.c:160
COMPLEX data[64]
Definition: fftest.c:34
void tclcad_register_cmds(Tcl_Interp *interp, struct bu_cmdtab *cmds)
Definition: tclcad.c:72
int Go_Init(Tcl_Interp *interp)
create the Tcl command for to_open
Definition: tclcad_obj.c:1421
const char * ct_name
Definition: cmd.h:49
int Rt_Init(Tcl_Interp *interp)
Definition: tcl.c:719
Header file for the BRL-CAD TclCAD Library, LIBTCLCAD.
int library_initialized(int setit)
Definition: tclcad.c:52
int(* ct_func)(void *data, int argc, const char *argv[])
Definition: cmd.h:50
void tclcad_auto_path(Tcl_Interp *interp)
int Dm_Init(void *interp)
Definition: tcl.c:127
int Fb_Init(Tcl_Interp *interp)
Definition: tcl.c:113
int Bn_Init(Tcl_Interp *interp)
Allows LIBBN to be dynamically loaded to a vanilla tclsh/wish with "load /usr/brlcad/lib/libbn.so".
Definition: tcl.c:1043