1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: value_desc.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_APP_VALUE_DESC_H
26 #define __SYNFIG_APP_VALUE_DESC_H
28 /* === H E A D E R S ======================================================= */
30 #include <synfig/valuenode.h>
31 #include <synfig/string.h>
32 #include <synfig/layer.h>
33 #include <synfig/value.h>
34 #include <synfig/valuenode_const.h>
35 #include <synfig/canvas.h>
37 /* === M A C R O S ========================================================= */
39 /* === T Y P E D E F S ===================================================== */
41 /* === C L A S S E S & S T R U C T S ======================================= */
47 // Info for Layer parent
48 synfig::Layer::Handle layer;
51 // Info for ValueNode parent
52 synfig::ValueNode::Handle parent_value_node;
55 // Info for exported ValueNode
56 synfig::Canvas::Handle canvas;
59 bool operator==(const ValueDesc &rhs)const
61 if((layer||rhs.layer) && layer!=rhs.layer)
63 if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
67 if((canvas||rhs.canvas) && canvas!=rhs.canvas)
69 if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
71 if((index>-1||rhs.index>-1) && index!=rhs.index)
75 bool operator!=(const ValueDesc &rhs)const
77 return !operator==(rhs);
81 ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
85 ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
89 ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
90 parent_value_node(parent_value_node),
93 // ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,const synfig::String& param_name):
94 // parent_value_node(parent_value_node),
95 // index(parent_value_node->get_link_index_from_name(param_name)) { }
97 ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
101 ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
102 parent_value_node(parent_value_node),
107 bool is_valid()const { return layer || parent_value_node || canvas; }
108 operator bool()const { return is_valid(); }
110 bool parent_is_layer_param()const { return (bool)layer; }
111 bool parent_is_value_node()const { return (bool)parent_value_node; }
112 bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; }
113 bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; }
114 bool parent_is_canvas()const { return (bool)canvas; }
116 bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); }
117 bool is_const()const { return (parent_is_layer_param() && !layer->dynamic_param_list().count(name)) || parent_is_value_node_const(); }
119 synfig::Layer::Handle get_layer()const { assert(parent_is_layer_param()); return layer; }
120 const synfig::String& get_param_name()const { assert(parent_is_layer_param()); return name; }
122 synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; }
123 int get_index()const { assert(parent_is_linkable_value_node()); return index; }
125 const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
127 synfig::Canvas::Handle get_canvas()const
132 return layer->get_canvas();
133 if(parent_value_node)
134 return parent_value_node->get_root_canvas();
138 synfig::ValueNode::Handle
139 get_value_node()const
141 if(parent_is_canvas())
142 return canvas->find_value_node(name);
143 if(parent_is_layer_param() && layer->dynamic_param_list().count(name))
144 return layer->dynamic_param_list().find(name)->second;
145 if(parent_is_linkable_value_node())
146 return synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node)->get_link(index);
147 // return reinterpret_cast<synfig::LinkableValueNode*>(parent_value_node.get())->get_link(index);
152 get_value(synfig::Time time=0)const
154 if(parent_is_value_node_const() && parent_value_node)
155 return (*parent_value_node)(0);
156 if(is_value_node() && get_value_node())
157 return (*get_value_node())(time);
158 if(parent_is_layer_param() && layer)
159 return layer->get_param(name);
160 return synfig::ValueBase();
163 synfig::ValueBase::Type
164 get_value_type()const
166 synfig::ValueNode::Handle value_node=get_value_node();
168 return value_node->get_type();
169 return get_value().get_type();
175 return is_value_node() && get_value_node()->is_exported();
177 }; // END of class ValueDesc
179 }; // END of namespace synfigapp_instance
181 /* === E N D =============================================================== */