Fix missing back slash to do not stop all the extra dist files list
[synfig.git] / synfig-studio / src / synfigapp / actions / activepointseton.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file activepointseton.cpp
3 **      \brief Template File
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 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "activepointseton.h"
34 #include "activepointsetsmart.h"
35 #include "valuenodelinkconnect.h"
36 #include "valuenodereplace.h"
37
38 #include "activepointset.h"
39 #include "activepointadd.h"
40
41 #include "valuedescconnect.h"
42 #include <synfigapp/canvasinterface.h>
43
44 #include <synfigapp/general.h>
45
46 #endif
47
48 using namespace std;
49 using namespace etl;
50 using namespace synfig;
51 using namespace synfigapp;
52 using namespace Action;
53
54 /* === M A C R O S ========================================================= */
55
56 ACTION_INIT(Action::ActivepointSetOn);
57 ACTION_SET_NAME(Action::ActivepointSetOn,"ActivepointSetOn");
58 ACTION_SET_LOCAL_NAME(Action::ActivepointSetOn,N_("Mark Activepoint as \"On\""));
59 ACTION_SET_TASK(Action::ActivepointSetOn,"set_on");
60 ACTION_SET_CATEGORY(Action::ActivepointSetOn,Action::CATEGORY_ACTIVEPOINT|Action::CATEGORY_VALUEDESC);
61 ACTION_SET_PRIORITY(Action::ActivepointSetOn,-10);
62 ACTION_SET_VERSION(Action::ActivepointSetOn,"0.0");
63 ACTION_SET_CVS_ID(Action::ActivepointSetOn,"$Id$");
64
65 /* === G L O B A L S ======================================================= */
66
67 /* === P R O C E D U R E S ================================================= */
68
69 /* === M E T H O D S ======================================================= */
70
71 Action::ActivepointSetOn::ActivepointSetOn()
72 {
73         activepoint.set_time(Time::begin()-1);
74         time_set=false;
75         set_dirty(true);
76 }
77
78 Action::ParamVocab
79 Action::ActivepointSetOn::get_param_vocab()
80 {
81         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
82
83         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
84                 .set_local_name(_("ValueDesc"))
85         );
86
87         ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
88                 .set_local_name(_("Activepoint"))
89                 .set_optional()
90         );
91
92         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
93                 .set_local_name(_("Time"))
94                 .set_optional()
95         );
96
97         return ret;
98 }
99
100 bool
101 Action::ActivepointSetOn::is_candidate(const ParamList &x)
102 {
103         if (!candidate_check(get_param_vocab(),x))
104                 return false;
105
106         ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
107
108         if (!(value_desc.parent_is_value_node() &&
109                   // We need a dynamic list.
110                   ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node())))
111                 return false;
112
113         Canvas::Handle canvas(x.find("canvas")->second.get_canvas());
114
115         // We are only a candidate if this canvas is animated.
116         return (canvas->rend_desc().get_time_start() != canvas->rend_desc().get_time_end() &&
117                         // We need either an activepoint or a time.
118                         (x.count("activepoint") || x.count("time")));
119 }
120
121 bool
122 Action::ActivepointSetOn::set_param(const synfig::String& name, const Action::Param &param)
123 {
124         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
125         {
126                 value_desc=param.get_value_desc();
127
128                 if(!value_desc.parent_is_value_node())
129                         return false;
130
131                 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
132
133                 if(!value_node)
134                         return false;
135
136                 index=value_desc.get_index();
137
138                 if(time_set)
139                         calc_activepoint();
140
141                 return true;
142         }
143         if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT && !time_set)
144         {
145                 activepoint=param.get_activepoint();
146
147                 return true;
148         }
149         if(name=="time" && param.get_type()==Param::TYPE_TIME && activepoint.get_time()==Time::begin()-1)
150         {
151                 activepoint.set_time(param.get_time());
152                 time_set=true;
153
154                 if(value_node)
155                         calc_activepoint();
156
157                 return true;
158         }
159
160         return Action::CanvasSpecific::set_param(name,param);
161 }
162
163 bool
164 Action::ActivepointSetOn::is_ready()const
165 {
166         if(!value_node)
167                 synfig::error("Missing value_node");
168
169         if(activepoint.get_time()==(Time::begin()-1))
170                 synfig::error("Missing activepoint");
171
172         if(!value_node || activepoint.get_time()==(Time::begin()-1))
173                 return false;
174         return Action::CanvasSpecific::is_ready();
175 }
176
177 // This function is called if a time is specified, but not
178 // a activepoint. In this case, we need to calculate the value
179 // of the activepoint
180 void
181 Action::ActivepointSetOn::calc_activepoint()
182 {
183         const Time time(activepoint.get_time());
184
185         try { activepoint=*value_node->list[index].find(time); }
186         catch(...)
187         {
188                 activepoint.set_time(time);
189                 activepoint.set_state(value_node->list[index].status_at_time(time));
190                 activepoint.set_priority(0);
191         }
192 }
193
194 void
195 Action::ActivepointSetOn::prepare()
196 {
197         clear();
198
199         // Turn the activepoint off
200         activepoint.set_state(true);
201
202         Action::Handle action(ActivepointSetSmart::create());
203
204         action->set_param("edit_mode",get_edit_mode());
205         action->set_param("canvas",get_canvas());
206         action->set_param("canvas_interface",get_canvas_interface());
207         action->set_param("value_desc",value_desc);
208         action->set_param("activepoint",activepoint);
209
210         assert(action->is_ready());
211         if(!action->is_ready())
212                 throw Error(Error::TYPE_NOTREADY);
213
214         add_action_front(action);
215
216 }