1 /* Copyright (C) 1992-1998 The Geometry Center
2 * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3 *
4 * This file is part of Geomview.
5 *
6 * Geomview is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * Geomview 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 Geomview; see the file COPYING. If not, write
18 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19 * USA, or visit http://www.gnu.org.
20 */
21
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #if 0
27 static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
28 Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
29 #endif
30
31 /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
32
33 /*
34 * Inst creation, editing, retrieval and deletion.
35 */
36
37 #include "instP.h"
38 #include "transobj.h"
39 #include "ntransobj.h"
40 #include "freelist.h"
41 #include "nodedata.h"
42
43 void
InstDelete(Inst * inst)44 InstDelete(Inst *inst)
45 {
46 if (inst) {
47 if (inst->geomhandle) HandlePDelete(&inst->geomhandle);
48 if (inst->geom) GeomDelete(inst->geom);
49 if (inst->tlisthandle) HandlePDelete(&inst->tlisthandle);
50 if (inst->tlist) GeomDelete(inst->tlist);
51 if (inst->txtlisthandle) HandlePDelete(&inst->txtlisthandle);
52 if (inst->txtlist) GeomDelete(inst->txtlist);
53 if (inst->axishandle) HandlePDelete(&inst->axishandle);
54 if (inst->NDaxishandle) HandlePDelete(&inst->NDaxishandle);
55 if (inst->NDaxis) NTransDelete(inst->NDaxis);
56 }
57 }
58
InstCopy(Inst * inst)59 Inst *InstCopy(Inst *inst)
60 {
61 Inst *ni;
62
63 ni = OOGLNewE(Inst, "InstCopy: Inst");
64 GGeomInit(ni, inst->Class, inst->magic, NULL);
65 TmCopy(inst->axis, ni->axis);
66 if (inst->NDaxis) {
67 ni->NDaxis = NTransCreate(inst->NDaxis);
68 }
69 ni->geom = GeomCopy(inst->geom);
70 ni->geomhandle = NULL;
71 ni->tlist = GeomCopy(inst->tlist);
72 ni->tlisthandle = NULL;
73 ni->txtlist = GeomCopy(inst->txtlist);
74 ni->txtlisthandle = NULL;
75 ni->axishandle = NULL;
76 ni->NDaxishandle = NULL;
77 ni->geomflags = inst->geomflags;
78 ni->location = inst->location;
79 ni->origin = inst->origin;
80 ni->originpt = inst->originpt;
81
82 return ni;
83
84 }
85
InstReplace(Inst * inst,Geom * geom)86 Geom *InstReplace(Inst *inst, Geom *geom)
87 {
88 Geom *old;
89
90 if(inst == NULL)
91 return NULL;
92
93 old = inst->geom;
94 inst->geom = geom;
95
96 return old;
97 }
98
InstGet(Inst * inst,int attr,void * attrp)99 int InstGet(Inst *inst, int attr, void *attrp)
100 {
101 switch(attr) {
102 case CR_GEOM: *(Geom **)attrp = inst->geom; break;
103 case CR_GEOMHANDLE: *(Handle **)attrp = inst->geomhandle; break;
104 case CR_TLIST: *(Geom **)attrp = inst->tlist; break;
105 case CR_TLISTHANDLE: *(Geom **)attrp = (Geom *)inst->tlisthandle; break;
106 case CR_TXTLIST: *(Geom **)attrp = inst->txtlist; break;
107 case CR_TXTLISTHANDLE: *(Geom **)attrp = (Geom *)inst->txtlisthandle; break;
108 case CR_NDAXISHANDLE: *(Handle **)attrp = inst->NDaxishandle; break;
109 case CR_NDAXIS: *(TransformN **)attrp = inst->NDaxis; break;
110 case CR_AXISHANDLE: *(Handle **)attrp = inst->axishandle; break;
111 case CR_AXIS:
112 TmCopy(inst->axis, (void *)attrp);
113 return (inst->tlist == NULL && inst->tlisthandle == NULL) ? 1 : 0;
114 case CR_LOCATION: *(int *)attrp = inst->location; break;
115 default:
116 return -1;
117 }
118 return 1;
119 }
120
InstCreate(Inst * exist,GeomClass * classp,va_list * a_list)121 Inst *InstCreate(Inst *exist, GeomClass *classp, va_list *a_list)
122 {
123 Inst *inst;
124 int attr;
125 int copy = 1;
126 TransformPtr t;
127 TransformN *nt;
128 Geom *g;
129 Handle *h;
130 bool tree_changed = false;
131
132 if (exist == NULL) {
133 inst = OOGLNewE(Inst, "InstCreate inst");
134 GGeomInit (inst, classp, INSTMAGIC, NULL);
135 TmIdentity(inst->axis);
136 inst->NDaxis = NULL;
137 inst->geomhandle = NULL;
138 inst->geom = NULL;
139 inst->tlisthandle = NULL;
140 inst->tlist = NULL;
141 inst->txtlisthandle = NULL;
142 inst->txtlist = NULL;
143 inst->axishandle = NULL;
144 inst->NDaxishandle = NULL;
145 inst->location = L_NONE;
146 inst->origin = L_NONE;
147 } else {
148 /* Check that exist is an inst. */
149 inst = exist;
150 }
151
152 while ((attr = va_arg (*a_list, int))) {
153 switch(attr) {
154 case CR_GEOMHANDLE:
155 h = va_arg(*a_list, Handle *);
156 if (copy) {
157 REFINCR(h);
158 }
159 if (inst->geomhandle) {
160 HandlePDelete(&inst->geomhandle);
161 }
162 inst->geomhandle = h;
163 HandleRegister(&inst->geomhandle, (Ref *)inst, &inst->geom, HandleUpdRef);
164 tree_changed = true;
165 break;
166 case CR_HANDLE_GEOM:
167 h = va_arg(*a_list, Handle *);
168 g = va_arg(*a_list, Geom *);
169 if (copy) {
170 REFINCR(h);
171 REFINCR(g);
172 }
173 if (inst->geomhandle) {
174 HandlePDelete(&inst->geomhandle);
175 }
176 if (inst->geom) {
177 GeomDelete(inst->geom);
178 }
179 inst->geomhandle = h;
180 inst->geom = g;
181 if (h) {
182 HandleRegister(&inst->geomhandle,
183 (Ref *)inst, &inst->geom, HandleUpdRef);
184 HandleSetObject(inst->geomhandle, (Ref *)g);
185 }
186 tree_changed = true;
187 break;
188 case CR_GEOM:
189 g = va_arg(*a_list, Geom *);
190 if (copy) {
191 REFINCR(g);
192 }
193 if (inst->geom) {
194 GeomDelete(inst->geom);
195 }
196 inst->geom = g;
197 if (inst->geomhandle) {
198 HandlePDelete(&inst->geomhandle);
199 }
200 tree_changed = true;
201 break;
202 case CR_AXIS:
203 t = va_arg(*a_list, TransformPtr);
204 InstTransformTo(inst, t, NULL);
205 tree_changed = true;
206 break;
207 case CR_NDAXIS:
208 nt = va_arg(*a_list, TransformN *);
209 InstTransformTo(inst, NULL, nt);
210 tree_changed = true;
211 break;
212 case CR_AXISHANDLE:
213 h = va_arg(*a_list, Handle *);
214 if (copy) {
215 REFINCR(h);
216 }
217 if (inst->axishandle) {
218 HandlePDelete(&inst->axishandle);
219 }
220 inst->axishandle = h;
221 if (h) {
222 HandleRegister(&inst->axishandle, (Ref *)inst, inst->axis, TransUpdate);
223 }
224 tree_changed = true;
225 break;
226 case CR_NDAXISHANDLE:
227 h = va_arg(*a_list, Handle *);
228 if(copy) {
229 REFINCR(h);
230 }
231 if(inst->NDaxishandle) {
232 HandlePDelete(&inst->NDaxishandle);
233 }
234 inst->NDaxishandle = h;
235 HandleRegister(&inst->NDaxishandle,
236 (Ref *)inst, &inst->NDaxis, HandleUpdRef);
237 tree_changed = true;
238 break;
239 case CR_TLIST:
240 g = va_arg (*a_list, Geom *);
241 if(copy) {
242 REFINCR(g);
243 }
244 if(inst->tlist) {
245 GeomDelete(inst->tlist);
246 }
247 inst->tlist = g;
248 tree_changed = true;
249 break;
250 case CR_TLISTHANDLE:
251 h = va_arg(*a_list, Handle *);
252 if(copy) {
253 REFINCR(h);
254 }
255 if(inst->tlisthandle != NULL) {
256 HandlePDelete(&inst->tlisthandle);
257 }
258 inst->tlisthandle = h;
259 HandleRegister(&inst->tlisthandle, (Ref *)inst, &inst->tlist,
260 HandleUpdRef);
261 tree_changed = true;
262 break;
263 case CR_TXTLIST:
264 g = va_arg (*a_list, Geom *);
265 if(copy) {
266 REFINCR(g);
267 }
268 if(inst->txtlist) {
269 GeomDelete(inst->txtlist);
270 }
271 inst->txtlist = g;
272 break;
273 case CR_TXTLISTHANDLE:
274 h = va_arg(*a_list, Handle *);
275 if(copy) {
276 REFINCR(h);
277 }
278 if(inst->txtlisthandle != NULL) {
279 HandlePDelete(&inst->txtlisthandle);
280 }
281 inst->txtlisthandle = h;
282 HandleRegister(&inst->txtlisthandle, (Ref *)inst, &inst->txtlist,
283 HandleUpdRef);
284 break;
285 case CR_LOCATION:
286 inst->location = va_arg(*a_list, int);
287 break;
288 default:
289 if(GeomDecorate(inst, ©, attr, a_list)) {
290 OOGLError (0, "InstCreate: Undefined option: %d", attr);
291 if(exist == NULL) {
292 GeomDelete ((Geom *)inst);
293 }
294 return NULL;
295 }
296 }
297 }
298
299 if (tree_changed) {
300 GeomNodeDataPrune((Geom *)inst);
301 }
302
303 return inst;
304 }
305
306 /*
307 * Local Variables: ***
308 * c-basic-offset: 2 ***
309 * End: ***
310 */
311