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_const.h>
36 #include <synfig/canvas.h>
38 /* === M A C R O S ========================================================= */
40 /* === T Y P E D E F S ===================================================== */
42 /* === C L A S S E S & S T R U C T S ======================================= */
48 // Info for Layer parent
49 synfig::Layer::Handle layer;
52 // Info for ValueNode parent
53 synfig::ValueNode::Handle parent_value_node;
56 // Info for exported ValueNode
57 synfig::Canvas::Handle canvas;
60 bool operator==(const ValueDesc &rhs)const
62 if((layer||rhs.layer) && layer!=rhs.layer)
64 if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
68 if((canvas||rhs.canvas) && canvas!=rhs.canvas)
70 if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
72 if((index>-1||rhs.index>-1) && index!=rhs.index)
76 bool operator!=(const ValueDesc &rhs)const
78 return !operator==(rhs);
82 ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
86 ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
90 ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
91 parent_value_node(parent_value_node),
94 // ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,const synfig::String& param_name):
95 // parent_value_node(parent_value_node),
96 // index(parent_value_node->get_link_index_from_name(param_name)) { }
98 ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
102 ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
103 parent_value_node(parent_value_node),
108 bool is_valid()const { return layer || parent_value_node || canvas; }
109 operator bool()const { return is_valid(); }
111 bool parent_is_layer_param()const { return (bool)layer; }
112 bool parent_is_value_node()const { return (bool)parent_value_node; }
113 bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; }
114 bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; }
115 bool parent_is_canvas()const { return (bool)canvas; }
117 bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); }
118 bool is_const()const { return (parent_is_layer_param() && !layer->dynamic_param_list().count(name)) || parent_is_value_node_const(); }
120 synfig::Layer::Handle get_layer()const { assert(parent_is_layer_param()); return layer; }
121 const synfig::String& get_param_name()const { assert(parent_is_layer_param()); return name; }
123 synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; }
124 int get_index()const { assert(parent_is_linkable_value_node()); return index; }
126 const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
128 synfig::Canvas::Handle get_canvas()const
133 return layer->get_canvas();
134 if(parent_value_node)
135 return parent_value_node->get_root_canvas();
139 synfig::ValueNode::Handle
140 get_value_node()const
142 if(parent_is_canvas())
143 return canvas->find_value_node(name);
144 if(parent_is_layer_param() && layer->dynamic_param_list().count(name))
145 return layer->dynamic_param_list().find(name)->second;
146 if(parent_is_linkable_value_node())
147 return (synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node))->get_link(index);
148 // return reinterpret_cast<synfig::LinkableValueNode*>(parent_value_node.get())->get_link(index);
149 if(parent_is_value_node_const())
150 return parent_value_node;
155 get_value(synfig::Time time=0)const
157 // if the value is constant, return that constant value (at *any* time, it doesn't matter which)
158 if(parent_is_value_node_const())
159 return (*parent_value_node)(0);
160 if(is_value_node() && get_value_node())
161 return (*get_value_node())(time);
162 if(parent_is_layer_param() && layer)
163 return layer->get_param(name);
164 return synfig::ValueBase();
167 synfig::ValueBase::Type
168 get_value_type()const
170 synfig::ValueNode::Handle value_node=get_value_node();
172 return value_node->get_type();
173 return get_value().get_type();
179 return is_value_node() && get_value_node()->is_exported();
183 get_description(bool show_exported_name = true)const;
184 }; // END of class ValueDesc
186 }; // END of namespace synfigapp_instance
188 /* === E N D =============================================================== */