1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_const.cpp
3 ** \brief Implementation of the "Constant" valuenode conversion.
4 **
5 ** $Id$
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 "valuenode_const.h"
33 #include "valuenode_bone.h"
34 #include "valuenode_boneweightpair.h"
35 #include "valuenode_composite.h"
36 #include <synfig/canvas.h>
37 #include <synfig/general.h>
38 #include <synfig/localization.h>
39 #include <synfig/pair.h>
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48
49 /* === M A C R O S ========================================================= */
50
51 /* === G L O B A L S ======================================================= */
52
53 /* === P R O C E D U R E S ================================================= */
54
55 /* === M E T H O D S ======================================================= */
56
ValueNode_Const()57 ValueNode_Const::ValueNode_Const()
58 {
59 }
60
61
ValueNode_Const(const ValueBase & x,Canvas::LooseHandle canvas)62 ValueNode_Const::ValueNode_Const(const ValueBase &x, Canvas::LooseHandle canvas):
63 ValueNode (x.get_type()),
64 value (x)
65 {
66 if (getenv("SYNFIG_DEBUG_SET_PARENT_CANVAS"))
67 printf("%s:%d set parent canvas for const %lx to %lx\n", __FILE__, __LINE__, uintptr_t(this), uintptr_t(canvas.get()));
68
69 if (x.get_type() == type_bone_valuenode)
70 add_child(x.get(ValueNode_Bone::Handle()).get());
71
72 set_parent_canvas(canvas);
73 }
74
75
76 ValueNode*
create(const ValueBase & x,Canvas::LooseHandle canvas)77 ValueNode_Const::create(const ValueBase &x, Canvas::LooseHandle canvas)
78 {
79 // this is nasty - shouldn't it be done somewhere else?
80 if (x.get_type() == type_bone_object)
81 {
82 printf("%s:%d forcing convert to ValueNode_Bone\n", __FILE__, __LINE__);
83 return ValueNode_Bone::create(x, canvas);
84 }
85
86 // this too
87 if (x.get_type() == type_bone_weight_pair)
88 {
89 printf("%s:%d forcing convert to ValueNode_BoneWeightPair\n", __FILE__, __LINE__);
90 return ValueNode_BoneWeightPair::create(x, canvas);
91 }
92
93 // and this
94 if (dynamic_cast<types_namespace::TypePairBase*>(&x.get_type()))
95 {
96 printf("%s:%d forcing convert to ValueNode_Composite\n", __FILE__, __LINE__);
97 return ValueNode_Composite::create(x, canvas);
98 }
99
100 return new ValueNode_Const(x, canvas);
101 }
102
103
104 ValueNode::Handle
clone(etl::loose_handle<Canvas> canvas,const GUID & deriv_guid) const105 ValueNode_Const::clone(etl::loose_handle<Canvas> canvas, const GUID& deriv_guid)const
106 {
107 { ValueNode* x(find_value_node(get_guid()^deriv_guid).get()); if(x)return x; }
108 ValueNode* ret(new ValueNode_Const(value));
109 ret->set_guid(get_guid()^deriv_guid);
110 ret->set_parent_canvas(canvas);
111 return ret;
112 }
113
114
~ValueNode_Const()115 ValueNode_Const::~ValueNode_Const()
116 {
117 if (get_value().get_type() == type_bone_valuenode)
118 remove_child(get_value().get(ValueNode_Bone::Handle()).get());
119 }
120
121
122 ValueBase
operator ()(Time) const123 ValueNode_Const::operator()(Time /*t*/)const
124 {
125 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
126 printf("%s:%d operator()\n", __FILE__, __LINE__);
127
128 return value;
129 }
130
131
132 const ValueBase &
get_value() const133 ValueNode_Const::get_value()const
134 {
135 return value;
136 }
137
138 ValueBase &
get_value()139 ValueNode_Const::get_value()
140 {
141 return value;
142 }
143
144 void
set_value(const ValueBase & data)145 ValueNode_Const::set_value(const ValueBase &data)
146 {
147 if(data!=value)
148 {
149 if (value.get_type() == type_bone_valuenode)
150 remove_child(value.get(ValueNode_Bone::Handle()).get());
151
152 if (data.get_type() == type_bone_valuenode)
153 add_child(data.get(ValueNode_Bone::Handle()).get());
154
155 value=data;
156 changed();
157 }
158 }
159
160
161 String
get_name() const162 ValueNode_Const::get_name()const
163 {
164 return "constant";
165 }
166
167 String
get_local_name() const168 ValueNode_Const::get_local_name()const
169 {
170 return _("Constant");
171 }
172 #ifdef _DEBUG
173 String
get_string() const174 ValueNode_Const::get_string()const
175 {
176 return strprintf("ValueNode_Const (%s)", get_value().get_string().c_str());
177 }
178 #endif // _DEBUG
get_times_vfunc(Node::time_set &) const179 void ValueNode_Const::get_times_vfunc(Node::time_set &/*set*/) const
180 {
181 }
182
get_values_vfunc(std::map<Time,ValueBase> & x) const183 void ValueNode_Const::get_values_vfunc(std::map<Time, ValueBase> &x) const
184 {
185 add_value_to_map(x, 0, value);
186 }
187