Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / synfigapp / value_desc.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file value_desc.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_APP_VALUE_DESC_H
27 #define __SYNFIG_APP_VALUE_DESC_H
28
29 /* === H E A D E R S ======================================================= */
30
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>
38
39 /* === M A C R O S ========================================================= */
40
41 /* === T Y P E D E F S ===================================================== */
42
43 /* === C L A S S E S & S T R U C T S ======================================= */
44
45 namespace synfigapp {
46
47 class ValueDesc
48 {
49         // Info for Layer parent
50         synfig::Layer::Handle layer;
51         synfig::String name;
52
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;
57
58         // Info for exported ValueNode
59         synfig::Canvas::Handle canvas;
60
61 public:
62         bool operator==(const ValueDesc &rhs)const
63         {
64                 if((layer||rhs.layer) && layer!=rhs.layer)
65                         return false;
66                 if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
67                         return false;
68                 if(layer)
69                         return true;
70                 if((canvas||rhs.canvas) && canvas!=rhs.canvas)
71                         return false;
72                 if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
73                         return false;
74                 if(index!=rhs.index)
75                         return false;
76                 return true;
77         }
78         bool operator!=(const ValueDesc &rhs)const
79         {
80                 return !operator==(rhs);
81         }
82
83
84         ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
85                 layer(layer),
86                 name(param_name) { }
87
88         ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
89                 layer(layer),
90                 name(param_name) { }
91
92         ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
93                 parent_value_node(parent_value_node),
94                 index(index) { }
95
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)) { }
99
100         ValueDesc(synfig::ValueNode_Animated::Handle parent_value_node,synfig::Time waypoint_time):
101                 parent_value_node(parent_value_node),
102                 index(-2),
103                 waypoint_time(waypoint_time) { }
104
105         ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
106                 name(name),
107                 canvas(canvas) { }
108
109         ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
110                 parent_value_node(parent_value_node),
111                 index(-1) { }
112
113         ValueDesc() { }
114
115         bool is_valid()const { return layer || parent_value_node || canvas; }
116         operator bool()const { return is_valid(); }
117
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; }
124
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(); }
127
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; }
130
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; }
134
135         const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
136
137         synfig::Canvas::Handle get_canvas()const
138         {
139                 if(canvas)
140                         return canvas;
141                 if(layer)
142                         return layer->get_canvas();
143                 if(parent_value_node)
144                         return parent_value_node->get_root_canvas();
145                 return 0;
146         }
147
148         synfig::ValueNode::Handle
149         get_value_node()const
150         {
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();
162                 return 0;
163         }
164
165         synfig::ValueBase
166         get_value(synfig::Time time=0)const
167         {
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();
176         }
177
178         synfig::ValueBase::Type
179         get_value_type()const
180         {
181                 synfig::ValueNode::Handle value_node=get_value_node();
182                 if(value_node)
183                         return value_node->get_type();
184                 return get_value().get_type();
185         }
186
187         bool
188         is_exported()const
189         {
190                 return is_value_node() && get_value_node()->is_exported();
191         }
192
193         synfig::String
194         get_description(bool show_exported_name = true)const;
195 }; // END of class ValueDesc
196
197 }; // END of namespace synfigapp_instance
198
199 /* === E N D =============================================================== */
200
201 #endif