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
10 ** Copyright (c) 2009 Nikita Kitaev
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __SYNFIG_APP_VALUE_DESC_H
28 #define __SYNFIG_APP_VALUE_DESC_H
30 /* === H E A D E R S ======================================================= */
32 #include <synfig/valuenode.h>
33 #include <synfig/string.h>
34 #include <synfig/layer.h>
35 #include <synfig/value.h>
36 #include <synfig/valuenode_animated.h>
37 #include <synfig/valuenode_const.h>
38 #include <synfig/canvas.h>
40 /* === M A C R O S ========================================================= */
42 /* === T Y P E D E F S ===================================================== */
44 /* === C L A S S E S & S T R U C T S ======================================= */
50 // Info for Layer parent
51 synfig::Layer::Handle layer;
54 // Info for ValueNode parent
55 synfig::ValueNode::Handle parent_value_node;
56 int index; // -2 if it's a waypoint, -1 if it's const, >=0 if it's LinkableValueNode
57 synfig::Time waypoint_time;
59 // Info for exported ValueNode
60 synfig::Canvas::Handle canvas;
63 bool operator==(const ValueDesc &rhs)const
65 if((layer||rhs.layer) && layer!=rhs.layer)
67 if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
71 if((canvas||rhs.canvas) && canvas!=rhs.canvas)
73 if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
79 bool operator!=(const ValueDesc &rhs)const
81 return !operator==(rhs);
85 ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
89 ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
93 ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
94 parent_value_node(parent_value_node),
97 // ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,const synfig::String& param_name):
98 // parent_value_node(parent_value_node),
99 // index(parent_value_node->get_link_index_from_name(param_name)) { }
101 ValueDesc(synfig::ValueNode_Animated::Handle parent_value_node,synfig::Time waypoint_time):
102 parent_value_node(parent_value_node),
104 waypoint_time(waypoint_time) { }
106 ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
110 ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
111 parent_value_node(parent_value_node),
116 bool is_valid()const { return layer || parent_value_node || canvas; }
117 operator bool()const { return is_valid(); }
119 bool parent_is_layer_param()const { return (bool)layer; }
120 bool parent_is_value_node()const { return (bool)parent_value_node; }
121 bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; }
122 bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; }
123 bool parent_is_waypoint()const { return parent_is_value_node() && index==-2; }
124 bool parent_is_canvas()const { return (bool)canvas; }
126 bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); }
127 bool is_const()const { return (parent_is_layer_param() && !layer->dynamic_param_list().count(name)) || parent_is_value_node_const(); }
129 synfig::Layer::Handle get_layer()const { assert(parent_is_layer_param()); return layer; }
130 const synfig::String& get_param_name()const { assert(parent_is_layer_param()); return name; }
132 synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; }
133 int get_index()const { assert(parent_is_linkable_value_node()); return index; }
134 synfig::String get_name()const { assert(parent_is_linkable_value_node()); return (synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node))->link_name(index); }
135 synfig::Time get_waypoint_time()const { assert(parent_is_waypoint()); return waypoint_time; }
137 const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
139 synfig::Canvas::Handle get_canvas()const
144 return layer->get_canvas();
145 if(parent_value_node)
146 return parent_value_node->get_root_canvas();
150 synfig::ValueNode::Handle
151 get_value_node()const
153 if(parent_is_canvas())
154 return canvas->find_value_node(name);
155 if(parent_is_layer_param() && layer->dynamic_param_list().count(name))
156 return layer->dynamic_param_list().find(name)->second;
157 if(parent_is_linkable_value_node())
158 return (synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node))->get_link(index);
159 // return reinterpret_cast<synfig::LinkableValueNode*>(parent_value_node.get())->get_link(index);
160 if(parent_is_value_node_const())
161 return parent_value_node;
162 if(parent_is_waypoint())
163 return (synfig::ValueNode_Animated::Handle::cast_reinterpret(parent_value_node))->find(waypoint_time)->get_value_node();
168 get_value(synfig::Time time=0)const
170 // if the value is constant, return that constant value (at *any* time, it doesn't matter which)
171 if(parent_is_value_node_const())
172 return (*parent_value_node)(0);
173 if(is_value_node() && get_value_node())
174 return (*get_value_node())(time);
175 if(parent_is_layer_param() && layer)
176 return layer->get_param(name);
177 return synfig::ValueBase();
180 synfig::ValueBase::Type
181 get_value_type()const
183 synfig::ValueNode::Handle value_node=get_value_node();
185 return value_node->get_type();
186 return get_value().get_type();
192 return is_value_node() && get_value_node()->is_exported();
196 get_description(bool show_exported_name = true)const;
197 }; // END of class ValueDesc
199 }; // END of namespace synfigapp_instance
201 /* === E N D =============================================================== */