Added "--with-userdir" to configure script to change the default user settings directory
[synfig.git] / synfig-studio / trunk / src / synfigapp / action_param.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file action_param.cpp
3 **      \brief Template File
4 **
5 **      $Id: action_param.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "action_param.h"
33 #include "action.h"
34 #include "canvasinterface.h"
35
36 #endif
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
43
44 /* === P R O C E D U R E S ================================================= */
45
46 bool
47 Action::canidate_check(const ParamVocab& param_vocab, const ParamList& param_list)
48 {
49         ParamVocab::const_iterator iter;
50         
51         for(iter=param_vocab.begin();iter!=param_vocab.end();++iter)
52         {
53                 int n(param_list.count(iter->get_name()));
54
55 //              if(n && !iter->get_mutual_exclusion().empty() && param_list.count(iter->get_mutual_exclusion()))
56 //                      return false;
57
58                 if(!n && !iter->get_mutual_exclusion().empty() && param_list.count(iter->get_mutual_exclusion()))
59                         continue;
60
61                 if(iter->get_user_supplied() || iter->get_optional())
62                         continue;
63                                                         
64                 if(n==0)
65                         return false;
66                 if(n==1 && iter->get_requires_multiple())
67                         return false;
68                 if(n>1 && !iter->get_supports_multiple())
69                         return false;
70                 
71                 if(iter->get_type()!=param_list.find(iter->get_name())->second.get_type())
72                         return false;
73         }
74         return true;
75 }
76
77 /* === S T A T I C S ======================================================= */
78
79 struct _ParamCounter
80 {
81         static int counter;
82         ~_ParamCounter()
83         {
84                 if(counter)
85                         synfig::error("%d action params not yet deleted!",counter);
86         }
87 } _param_counter;
88
89 int _ParamCounter::counter(0);
90
91 /* === M E T H O D S ======================================================= */
92
93 Param::Param(const Param &rhs):
94         type_(rhs.type_)
95 {
96         _ParamCounter::counter++;
97         switch(type_)
98         {
99         case TYPE_ACTIVEPOINT:
100                 data.activepoint.construct();
101                 data.activepoint.get()=rhs.data.activepoint.get();
102                 break;
103         case TYPE_WAYPOINT:
104                 data.waypoint.construct();
105                 data.waypoint.get()=rhs.data.waypoint.get();
106                 break;
107         case TYPE_WAYPOINTMODEL:
108                 data.waypoint_model.construct();
109                 data.waypoint_model.get()=rhs.data.waypoint_model.get();
110                 break;
111         case TYPE_KEYFRAME:
112                 data.keyframe.construct();
113                 data.keyframe.get()=rhs.data.keyframe.get();
114                 break;
115         case TYPE_CANVAS:
116                 data.canvas.construct();
117                 data.canvas.get()=rhs.data.canvas.get();
118                 break;
119         case TYPE_CANVASINTERFACE:
120                 data.canvas_interface.construct();
121                 data.canvas_interface.get()=rhs.data.canvas_interface.get();
122                 break;
123         case TYPE_LAYER:
124                 data.layer.construct();
125                 data.layer.get()=rhs.data.layer.get();
126                 break;
127         case TYPE_VALUENODE:
128                 data.value_node.construct();
129                 data.value_node.get()=rhs.data.value_node.get();
130                 break;
131         case TYPE_VALUEDESC:
132                 data.value_desc.construct();
133                 data.value_desc.get()=rhs.data.value_desc.get();
134                 break;
135         case TYPE_VALUE:
136                 data.value.construct();
137                 data.value.get()=rhs.data.value.get();
138                 break;
139         case TYPE_STRING:
140                 data.string.construct();
141                 data.string.get()=rhs.data.string.get();
142                 break;
143         case TYPE_RENDDESC:
144                 data.rend_desc.construct();
145                 data.rend_desc.get()=rhs.data.rend_desc.get();
146                 break;
147         case TYPE_TIME:
148                 data.time.construct();
149                 data.time.get()=rhs.data.time.get();
150                 break;
151
152         case TYPE_INTEGER:
153                 data.integer=rhs.data.integer;
154                 break;
155         case TYPE_EDITMODE:
156                 data.edit_mode=rhs.data.edit_mode;
157                 break;
158         case TYPE_REAL:
159                 data.real=rhs.data.real;
160                 break;
161         case TYPE_BOOL:
162                 data.b=rhs.data.b;
163                 break;
164
165         case TYPE_NIL:
166                 break;
167
168         default:
169                 assert(0);
170                 break;
171         }
172 }
173
174 Param::Param(const etl::handle<synfigapp::CanvasInterface>& x):
175         
176         type_(TYPE_CANVASINTERFACE)
177 {
178         _ParamCounter::counter++;
179         data.canvas_interface.construct();
180         data.canvas_interface.get()=x;
181 }
182
183 /*
184 Param::Param(synfigapp::CanvasInterface* x):
185         
186         type_(TYPE_CANVASINTERFACE)
187 {
188         _ParamCounter::counter++;
189         data.canvas_interface.construct();
190         data.canvas_interface=x;
191 }
192 */
193
194 Param::Param(const etl::loose_handle<synfigapp::CanvasInterface>& x):
195         
196         type_(TYPE_CANVASINTERFACE)
197 {
198         _ParamCounter::counter++;
199         data.canvas_interface.construct();
200         data.canvas_interface.get()=x;
201 }
202
203 Param::Param(const synfig::Canvas::Handle& x):  
204         type_(TYPE_CANVAS)
205 {
206         _ParamCounter::counter++;
207         data.canvas.construct();
208         data.canvas.get()=x;
209 }
210
211 Param::Param(const synfig::Canvas::LooseHandle& x):     
212         type_(TYPE_CANVAS)
213 {
214         _ParamCounter::counter++;
215         data.canvas.construct();
216         data.canvas.get()=x;
217 }
218
219 Param::Param(const synfig::Layer::Handle& x):
220         
221         type_(TYPE_LAYER)
222 {
223         _ParamCounter::counter++;
224         data.layer.construct();
225         data.layer.get()=x;
226 }
227
228 Param::Param(const synfig::Layer::LooseHandle& x):
229         
230         type_(TYPE_LAYER)
231 {
232         _ParamCounter::counter++;
233         data.layer.construct();
234         data.layer.get()=x;
235 }
236
237 Param::Param(const synfig::ValueNode::Handle& x):
238         
239         type_(TYPE_VALUENODE)
240 {
241         _ParamCounter::counter++;
242         data.value_node.construct();
243         data.value_node.get()=x;
244 }
245
246 Param::Param(const synfig::ValueNode::LooseHandle& x):
247         
248         type_(TYPE_VALUENODE)
249 {
250         _ParamCounter::counter++;
251         data.value_node.construct();
252         data.value_node.get()=x;
253 }
254
255 Param::Param(const synfig::ValueBase& x):
256         
257         type_(TYPE_VALUE)
258 {
259         _ParamCounter::counter++;
260         data.value.construct();
261         data.value.get()=x;
262 }
263
264 Param::Param(const synfig::RendDesc& x):        
265         type_(TYPE_RENDDESC)
266 {
267         _ParamCounter::counter++;
268         data.rend_desc.construct();
269         data.rend_desc.get()=x;
270 }
271
272 Param::Param(const synfig::Time& x):
273         type_(TYPE_TIME)
274 {
275         _ParamCounter::counter++;
276         data.time.construct();
277         data.time.get()=x;
278 }
279
280 Param::Param(const synfig::Activepoint& x):
281         
282         type_(TYPE_ACTIVEPOINT)
283 {
284         _ParamCounter::counter++;
285         data.activepoint.construct();
286         data.activepoint.get()=x;
287 }
288
289 Param::Param(const synfig::Waypoint& x):        
290         type_(TYPE_WAYPOINT)
291 {
292         _ParamCounter::counter++;
293         data.waypoint.construct();
294         data.waypoint.get()=x;
295 }
296
297 Param::Param(const synfig::Waypoint::Model& x): 
298         type_(TYPE_WAYPOINTMODEL)
299 {
300         _ParamCounter::counter++;
301         data.waypoint_model.construct();
302         data.waypoint_model.get()=x;
303 }
304
305 Param::Param(const synfig::String& x):
306         type_(TYPE_STRING)
307 {
308         _ParamCounter::counter++;
309         data.string.construct();
310         data.string.get()=x;
311 }
312
313 Param::Param(const char * x):
314         type_(TYPE_STRING)
315 {
316         _ParamCounter::counter++;
317         data.string.construct();
318         data.string.get()=x;
319 }
320
321 Param::Param(const synfig::Keyframe& x):
322         
323         type_(TYPE_KEYFRAME)
324 {
325         _ParamCounter::counter++;
326         data.keyframe.construct();
327         data.keyframe.get()=x;
328 }
329
330 Param::Param(const synfigapp::ValueDesc& x):
331         
332         type_(TYPE_VALUEDESC)
333 {
334         _ParamCounter::counter++;
335         data.value_desc.construct();
336         data.value_desc.get()=x;
337 }
338
339 Param::Param(const int& x):
340         type_(TYPE_INTEGER)
341 {
342         _ParamCounter::counter++;
343         data.integer=x;
344 }
345
346 Param::Param(const EditMode& x):
347         type_(TYPE_EDITMODE)
348 {
349         _ParamCounter::counter++;
350         data.edit_mode=x;
351 }
352
353 Param::Param(const synfig::Real& x):
354         
355         type_(TYPE_REAL)
356 {
357         _ParamCounter::counter++;
358         data.real=x;
359 }
360
361 Param::Param(const bool& x):
362         
363         type_(TYPE_BOOL)
364 {
365         _ParamCounter::counter++;
366         data.b=x;
367 }
368
369 Param::~Param()
370 {
371         clear();
372         _ParamCounter::counter--;
373 }
374
375 Param&
376 Param::operator=(const Param& rhs)
377 {
378         clear();
379         type_=rhs.type_;
380         
381         switch(type_)
382         {
383         case TYPE_ACTIVEPOINT:
384                 data.activepoint.construct();
385                 data.activepoint.get()=rhs.data.activepoint.get();
386                 break;
387         case TYPE_WAYPOINT:
388                 data.waypoint.construct();
389                 data.waypoint.get()=rhs.data.waypoint.get();
390                 break;
391         case TYPE_WAYPOINTMODEL:
392                 data.waypoint_model.construct();
393                 data.waypoint_model.get()=rhs.data.waypoint_model.get();
394                 break;
395         case TYPE_KEYFRAME:
396                 data.keyframe.construct();
397                 data.keyframe.get()=rhs.data.keyframe.get();
398                 break;
399         case TYPE_CANVAS:
400                 data.canvas.construct();
401                 data.canvas.get()=rhs.data.canvas.get();
402                 break;
403         case TYPE_CANVASINTERFACE:
404                 data.canvas_interface.construct();
405                 data.canvas_interface.get()=rhs.data.canvas_interface.get();
406                 break;
407         case TYPE_TIME:
408                 data.time.construct();
409                 data.time.get()=rhs.data.time.get();
410                 break;
411         case TYPE_LAYER:
412                 data.layer.construct();
413                 data.layer.get()=rhs.data.layer.get();
414                 break;
415         case TYPE_VALUENODE:
416                 data.value_node.construct();
417                 data.value_node.get()=rhs.data.value_node.get();
418                 break;
419         case TYPE_VALUEDESC:
420                 data.value_desc.construct();
421                 data.value_desc.get()=rhs.data.value_desc.get();
422                 break;
423         case TYPE_VALUE:
424                 data.value.construct();
425                 data.value.get()=rhs.data.value.get();
426                 break;
427         case TYPE_RENDDESC:
428                 data.rend_desc.construct();
429                 data.rend_desc.get()=rhs.data.rend_desc.get();
430                 break;
431         case TYPE_STRING:
432                 data.string.construct();
433                 data.string.get()=rhs.data.string.get();
434                 break;
435
436         case TYPE_INTEGER:
437                 data.integer=rhs.data.integer;
438                 break;
439         case TYPE_EDITMODE:
440                 data.integer=rhs.data.integer;
441                 break;
442         case TYPE_REAL:
443                 data.real=rhs.data.real;
444                 break;
445         case TYPE_BOOL:
446                 data.b=rhs.data.b;
447                 break;
448
449         case TYPE_NIL:
450                 break;
451
452         default:
453                 assert(0);
454                 break;
455         }
456         return *this;
457 }
458
459 void
460 Param::clear()
461 {
462         switch(type_)
463         {
464         case TYPE_ACTIVEPOINT:
465                 data.activepoint.destruct();
466                 break;
467         case TYPE_WAYPOINT:
468                 data.waypoint.destruct();
469                 break;
470         case TYPE_WAYPOINTMODEL:
471                 data.waypoint_model.destruct();
472                 break;
473         case TYPE_KEYFRAME:
474                 data.keyframe.destruct();
475                 break;
476         case TYPE_CANVAS:
477                 data.canvas.destruct();
478                 break;
479         case TYPE_CANVASINTERFACE:
480                 data.canvas_interface.destruct();
481                 break;
482         case TYPE_LAYER:
483                 data.layer.destruct();
484                 break;
485         case TYPE_TIME:
486                 data.time.destruct();
487                 break;
488         case TYPE_VALUENODE:
489                 data.value_node.destruct();
490                 break;
491         case TYPE_VALUEDESC:
492                 data.value_desc.destruct();
493                 break;
494         case TYPE_VALUE:
495                 data.value.destruct();
496                 break;
497         case TYPE_RENDDESC:
498                 data.rend_desc.destruct();
499                 break;
500         case TYPE_STRING:
501                 data.string.destruct();
502                 break;
503
504         case TYPE_NIL:
505         case TYPE_EDITMODE:
506         case TYPE_INTEGER:
507         case TYPE_REAL:
508         case TYPE_BOOL:
509                 break;
510
511         default:
512                 assert(0);
513                 break;
514         }
515         type_=TYPE_NIL;
516 }