1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_APP_VALUE_DESC_H
27 #define __SYNFIG_APP_VALUE_DESC_H
29 /* === H E A D E R S ======================================================= */
31 #include <synfig/valuenode.h>
32 #include <synfig/string.h>
33 #include <synfig/layer.h>
34 #include <synfig/value.h>
35 #include <synfig/valuenode_animated.h>
36 #include <synfig/valuenode_const.h>
37 #include <synfig/canvas.h>
39 /* === M A C R O S ========================================================= */
41 /* === T Y P E D E F S ===================================================== */
43 /* === C L A S S E S & S T R U C T S ======================================= */
49 // Info for Layer parent
50 synfig::Layer::Handle layer;
53 // Info for ValueNode parent
54 synfig::ValueNode::Handle parent_value_node;
55 int index; // -2 if it's a waypoint, -1 if it's const, >=0 if it's LinkableValueNode
56 synfig::Time waypoint_time;
58 // Info for exported ValueNode
59 synfig::Canvas::Handle canvas;
62 bool operator==(const ValueDesc &rhs)const
64 if((layer||rhs.layer) && layer!=rhs.layer)
66 if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
70 if((canvas||rhs.canvas) && canvas!=rhs.canvas)
72 if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
78 bool operator!=(const ValueDesc &rhs)const
80 return !operator==(rhs);
84 ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
88 ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
92 ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
93 parent_value_node(parent_value_node),
96 // ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,const synfig::String& param_name):
97 // parent_value_node(parent_value_node),
98 // index(parent_value_node->get_link_index_from_name(param_name)) { }
100 ValueDesc(synfig::ValueNode_Animated::Handle parent_value_node,synfig::Time waypoint_time):
101 parent_value_node(parent_value_node),
103 waypoint_time(waypoint_time) { }
105 ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
109 ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
110 parent_value_node(parent_value_node),
115 bool is_valid()const { return layer || parent_value_node || canvas; }
116 operator bool()const { return is_valid(); }
118 bool parent_is_layer_param()const { return (bool)layer; }
119 bool parent_is_value_node()const { return (bool)parent_value_node; }
120 bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; }
121 bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; }
122 bool parent_is_waypoint()const { return parent_is_value_node() && index==-2; }
123 bool parent_is_canvas()const { return (bool)canvas; }
125 bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); }
126 bool is_const()const { return (parent_is_layer_param() && !layer->dynamic_param_list().count(name)) || parent_is_value_node_const(); }
128 synfig::Layer::Handle get_layer()const { assert(parent_is_layer_param()); return layer; }
129 const synfig::String& get_param_name()const { assert(parent_is_layer_param()); return name; }
131 synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; }
132 int get_index()const { assert(parent_is_linkable_value_node()); return index; }
133 synfig::Time get_waypoint_time()const { assert(parent_is_waypoint()); return waypoint_time; }
135 const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
137 synfig::Canvas::Handle get_canvas()const
142 return layer->get_canvas();
143 if(parent_value_node)
144 return parent_value_node->get_root_canvas();
148 synfig::ValueNode::Handle
149 get_value_node()const
151 if(parent_is_canvas())
152 return canvas->find_value_node(name);
153 if(parent_is_layer_param() && layer->dynamic_param_list().count(name))
154 return layer->dynamic_param_list().find(name)->second;
155 if(parent_is_linkable_value_node())
156 return (synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node))->get_link(index);
157 // return reinterpret_cast<synfig::LinkableValueNode*>(parent_value_node.get())->get_link(index);
158 if(parent_is_value_node_const())
159 return parent_value_node;
160 if(parent_is_waypoint())
161 return (synfig::ValueNode_Animated::Handle::cast_reinterpret(parent_value_node))->find(waypoint_time)->get_value_node();
166 get_value(synfig::Time time=0)const
168 // if the value is constant, return that constant value (at *any* time, it doesn't matter which)
169 if(parent_is_value_node_const())
170 return (*parent_value_node)(0);
171 if(is_value_node() && get_value_node())
172 return (*get_value_node())(time);
173 if(parent_is_layer_param() && layer)
174 return layer->get_param(name);
175 return synfig::ValueBase();
178 synfig::ValueBase::Type
179 get_value_type()const
181 synfig::ValueNode::Handle value_node=get_value_node();
183 return value_node->get_type();
184 return get_value().get_type();
190 return is_value_node() && get_value_node()->is_exported();
194 get_description(bool show_exported_name = true)const;
195 }; // END of class ValueDesc
197 }; // END of namespace synfigapp_instance
199 /* === E N D =============================================================== */