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

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

First release to xenial

File size: 4.1 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file waypointsimpleadd.cpp
3**      \brief Simple add waypoint File
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2004 Adrian Bentley
9**
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.
14**
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.
19**      \endlegal
20*/
21/* ========================================================================= */
22
23/* === H E A D E R S ======================================================= */
24
25#ifdef USING_PCH
26#       include "pch.h"
27#else
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include "waypointsimpleadd.h"
33#include <synfigapp/canvasinterface.h>
34
35#include <synfigapp/general.h>
36
37#endif
38
39using namespace std;
40using namespace etl;
41using namespace synfig;
42using namespace synfigapp;
43using namespace Action;
44
45/* === M A C R O S ========================================================= */
46
47ACTION_INIT(Action::WaypointSimpleAdd);
48ACTION_SET_NAME(Action::WaypointSimpleAdd,"WaypointSimpleAdd");
49ACTION_SET_LOCAL_NAME(Action::WaypointSimpleAdd,N_("Simply Add Waypoint"));
50ACTION_SET_TASK(Action::WaypointSimpleAdd,"add");
51ACTION_SET_CATEGORY(Action::WaypointSimpleAdd,Action::CATEGORY_WAYPOINT);
52ACTION_SET_PRIORITY(Action::WaypointSimpleAdd,0);
53ACTION_SET_VERSION(Action::WaypointSimpleAdd,"0.0");
54ACTION_SET_CVS_ID(Action::WaypointSimpleAdd,"$Id$");
55
56/* === G L O B A L S ======================================================= */
57
58/* === P R O C E D U R E S ================================================= */
59
60/* === M E T H O D S ======================================================= */
61
62Action::WaypointSimpleAdd::WaypointSimpleAdd():
63        time_overwrite()
64{
65        set_dirty(true);
66        waypoint.set_time(Time::begin()-1);
67}
68
69Action::ParamVocab
70Action::WaypointSimpleAdd::get_param_vocab()
71{
72        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73
74        ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
75                .set_local_name(_("Destination ValueNode (Animated)"))
76        );
77
78        ret.push_back(ParamDesc("waypoint",Param::TYPE_WAYPOINT)
79                .set_local_name(_("Waypoint"))
80                .set_desc(_("Waypoint to be added"))
81        );
82
83        return ret;
84}
85
86bool
87Action::WaypointSimpleAdd::is_candidate(const ParamList &x)
88{
89        return candidate_check(get_param_vocab(),x);
90}
91
92bool
93Action::WaypointSimpleAdd::set_param(const synfig::String& name, const Action::Param &param)
94{
95        if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
96        {
97                value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node());
98
99                return static_cast<bool>(value_node);
100        }
101        if(name=="waypoint" && param.get_type()==Param::TYPE_WAYPOINT)
102        {
103                waypoint = param.get_waypoint();
104
105                return true;
106        }
107
108        return Action::CanvasSpecific::set_param(name,param);
109}
110
111bool
112Action::WaypointSimpleAdd::is_ready()const
113{
114        if(!value_node && waypoint.get_time() != (Time::begin()-1))
115                return false;
116        return Action::CanvasSpecific::is_ready();
117}
118
119void
120Action::WaypointSimpleAdd::perform()
121{
122        //remove any pretenders that lie at our destination
123        ValueNode_Animated::findresult iter = value_node->find_time(waypoint.get_time());
124
125        time_overwrite = false;
126        if(iter.second)
127        {
128                overwritten_wp = *iter.first;
129                time_overwrite = true;
130                value_node->erase(overwritten_wp);
131        }
132
133        //add the value node in since it's safe
134        value_node->add(waypoint);
135
136        // Signal that a valuenode has been changed
137        value_node->changed();
138}
139
140void
141Action::WaypointSimpleAdd::undo()
142{
143        //remove our old version...
144        ValueNode_Animated::findresult iter = value_node->find_uid(waypoint);
145
146        if(!iter.second)
147        {
148                throw Error(_("The waypoint to remove no longer exists"));
149        }
150
151        //remove the offending value
152        value_node->erase(*iter.first); //could also just use waypoint
153
154        if(time_overwrite)
155        {
156                value_node->add(overwritten_wp);
157        }
158
159        // Signal that a valuenode has been changed
160        value_node->changed();
161}
Note: See TracBrowser for help on using the repository browser.