source: synfigstudio/trunk/fuentes/src/synfigapp/actions/activepointadd.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 5.6 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file activepointadd.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 "activepointadd.h"
34#include <synfigapp/canvasinterface.h>
35
36#include <synfigapp/general.h>
37
38#endif
39
40using namespace std;
41using namespace etl;
42using namespace synfig;
43using namespace synfigapp;
44using namespace Action;
45
46/* === M A C R O S ========================================================= */
47
48ACTION_INIT(Action::ActivepointAdd);
49ACTION_SET_NAME(Action::ActivepointAdd,"ActivepointAdd");
50ACTION_SET_LOCAL_NAME(Action::ActivepointAdd,N_("Add Activepoint"));
51ACTION_SET_TASK(Action::ActivepointAdd,"add");
52ACTION_SET_CATEGORY(Action::ActivepointAdd,Action::CATEGORY_ACTIVEPOINT);
53ACTION_SET_PRIORITY(Action::ActivepointAdd,0);
54ACTION_SET_VERSION(Action::ActivepointAdd,"0.0");
55ACTION_SET_CVS_ID(Action::ActivepointAdd,"$Id$");
56
57/* === G L O B A L S ======================================================= */
58
59/* === P R O C E D U R E S ================================================= */
60
61/* === M E T H O D S ======================================================= */
62
63Action::ActivepointAdd::ActivepointAdd():
64        index(),
65        time_set(false)
66{
67        activepoint.set_time(Time::begin()-1);
68        set_dirty(true);
69}
70
71Action::ParamVocab
72Action::ActivepointAdd::get_param_vocab()
73{
74        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75
76        ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
77                .set_local_name(_("ValueDesc"))
78        );
79
80        ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
81                .set_local_name(_("New Activepoint"))
82                .set_desc(_("Activepoint to be added"))
83                .set_optional()
84        );
85
86        ret.push_back(ParamDesc("time",Param::TYPE_TIME)
87                .set_local_name(_("Time"))
88                .set_desc(_("Time where activepoint is to be added"))
89                .set_optional()
90        );
91
92        return ret;
93}
94
95bool
96Action::ActivepointAdd::is_candidate(const ParamList &x)
97{
98        if (!candidate_check(get_param_vocab(),x))
99                return false;
100
101        ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
102
103        return (value_desc.parent_is_value_node() &&
104                        // We need a dynamic list.
105                        ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()) &&
106                        // We need either an activepoint or a time.
107                        (x.count("activepoint") || x.count("time")));
108}
109
110bool
111Action::ActivepointAdd::set_param(const synfig::String& name, const Action::Param &param)
112{
113        if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
114        {
115                ValueDesc value_desc(param.get_value_desc());
116
117                if(!value_desc.parent_is_value_node())
118                        return false;
119
120                value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
121
122                if(!value_node)
123                        return false;
124
125                index=value_desc.get_index();
126
127                if(time_set)
128                        calc_activepoint();
129
130                return true;
131        }
132        if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT && !time_set)
133        {
134                activepoint=param.get_activepoint();
135
136                return true;
137        }
138        if(name=="time" && param.get_type()==Param::TYPE_TIME && activepoint.get_time()==Time::begin()-1)
139        {
140                activepoint.set_time(param.get_time());
141                time_set=true;
142
143                if(value_node)
144                        calc_activepoint();
145
146                return true;
147        }
148
149        return Action::CanvasSpecific::set_param(name,param);
150}
151
152bool
153Action::ActivepointAdd::is_ready()const
154{
155        if(!value_node || activepoint.get_time()==(Time::begin()-1))
156                return false;
157        return Action::CanvasSpecific::is_ready();
158}
159
160// This function is called if a time is specified, but not
161// a activepoint. In this case, we need to calculate the value
162// of the activepoint
163void
164Action::ActivepointAdd::calc_activepoint()
165{
166        const Time time(activepoint.get_time());
167        activepoint.set_state(value_node->list[index].status_at_time(time));
168        activepoint.set_priority(0);
169
170        // In this case, nothing is really changing, so there will be
171        // no need to redraw the window
172        set_dirty(false);
173}
174
175void
176Action::ActivepointAdd::perform()
177{
178        try { value_node->list[index].find(activepoint.get_time()); throw Error(_("A Activepoint already exists at this point in time"));}
179        catch(synfig::Exception::NotFound) { }
180
181        try { if(value_node->list[index].find(activepoint)!=value_node->list[index].timing_info.end()) throw Error(_("This activepoint is already in the ValueNode"));}
182        catch(synfig::Exception::NotFound) { }
183
184        value_node->list[index].add(activepoint);
185        value_node->changed();
186
187        /*if(get_canvas_interface())
188        {
189                get_canvas_interface()->signal_value_node_changed()(value_node);
190        }
191        else synfig::warning("CanvasInterface not set on action");
192        */
193}
194
195void
196Action::ActivepointAdd::undo()
197{
198        value_node->list[index].erase(activepoint);
199        value_node->changed();
200        /*
201        // Signal that a layer has been inserted
202        if(get_canvas_interface())
203        {
204                get_canvas_interface()->signal_value_node_changed()(value_node);
205        }
206        else synfig::warning("CanvasInterface not set on action");
207        */
208}
Note: See TracBrowser for help on using the repository browser.