my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / activepointsimpleadd.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file activepointsimpleadd.cpp
3 **      \brief Simple add activepoint File
4 **
5 **      $Id: activepointsimpleadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "activepointsimpleadd.h"
32 #include <synfigapp/canvasinterface.h>
33
34 #endif
35
36 using namespace std;
37 using namespace etl;
38 using namespace synfig;
39 using namespace synfigapp;
40 using namespace Action;
41
42 /* === M A C R O S ========================================================= */
43
44 ACTION_INIT(Action::ActivepointSimpleAdd);
45 ACTION_SET_NAME(Action::ActivepointSimpleAdd,"waypoint_simpleadd");
46 ACTION_SET_LOCAL_NAME(Action::ActivepointSimpleAdd,"Simply Add Waypoint");
47 ACTION_SET_TASK(Action::ActivepointSimpleAdd,"add");
48 ACTION_SET_CATEGORY(Action::ActivepointSimpleAdd,Action::CATEGORY_WAYPOINT);
49 ACTION_SET_PRIORITY(Action::ActivepointSimpleAdd,0);
50 ACTION_SET_VERSION(Action::ActivepointSimpleAdd,"0.0");
51 ACTION_SET_CVS_ID(Action::ActivepointSimpleAdd,"$Id: activepointsimpleadd.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Action::ActivepointSimpleAdd::ActivepointSimpleAdd()
60 {
61         set_dirty(true);
62         activepoint.set_time(Time::begin()-1);
63 }
64
65 Action::ParamVocab
66 Action::ActivepointSimpleAdd::get_param_vocab()
67 {
68         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69         
70         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
71                 .set_local_name(_("Destination ValueNode (Animated)"))
72         );
73
74         ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
75                 .set_local_name(_("Activepoint"))
76                 .set_desc(_("Activepoint to be added"))
77         );
78
79         return ret;
80 }
81
82 bool
83 Action::ActivepointSimpleAdd::is_canidate(const ParamList &x)
84 {
85         if(canidate_check(get_param_vocab(),x))
86         {
87                 ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
88                 if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
89                         return false;
90
91                 return true;
92         }
93         return canidate_check(get_param_vocab(),x);
94 }
95
96 bool
97 Action::ActivepointSimpleAdd::set_param(const synfig::String& name, const Action::Param &param)
98 {
99         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
100         {
101                 ValueDesc value_desc(param.get_value_desc());
102                 
103                 if(!value_desc.parent_is_value_node())
104                         return false;
105                 
106                 value_node=ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node());
107                 
108                 if(!value_node)
109                         return false;
110                 
111                 index=value_desc.get_index();
112                 
113                 return true;
114         }
115         if(name=="activepoint" && param.get_type()==Param::TYPE_ACTIVEPOINT)
116         {
117                 activepoint = param.get_activepoint();
118                 
119                 return true;
120         }
121
122         return Action::CanvasSpecific::set_param(name,param);
123 }
124
125 bool
126 Action::ActivepointSimpleAdd::is_ready()const
127 {
128         if(!value_node && activepoint.get_time() != (Time::begin()-1))
129                 return false;
130         return Action::CanvasSpecific::is_ready();
131 }
132
133 void
134 Action::ActivepointSimpleAdd::perform()
135 {       
136         //remove any pretenders that lie at our destination
137         ValueNode_DynamicList::ListEntry::findresult iter = value_node->list[index]
138                                                                                                                         .find_time(activepoint.get_time());
139         
140         time_overwrite = false;
141         if(iter.second)
142         {
143                 overwritten_ap = *iter.first;
144                 time_overwrite = true;
145                 value_node->list[index].erase(overwritten_ap);
146         }
147         
148         //add the value node in since it's safe
149         value_node->list[index].add(activepoint);
150         
151         //sort them...
152         value_node->list[index].timing_info.sort();
153         
154         // Signal that a valuenode has been changed
155         value_node->changed();
156 }
157
158 void
159 Action::ActivepointSimpleAdd::undo()
160 {
161         //remove our old version...
162         ValueNode_DynamicList::ListEntry::findresult iter = value_node->list[index].find_uid(activepoint);
163         
164         if(!iter.second)
165         {
166                 throw Error(_("The activepoint to remove no longer exists"));
167         }
168         
169         //remove the offending value
170         value_node->list[index].erase(*iter.first); //could also just use waypoint
171         
172         if(time_overwrite)
173         {
174                 value_node->list[index].add(overwritten_ap);                            
175         }
176         
177         //sort them...
178         value_node->list[index].timing_info.sort();
179         
180         // Signal that a valuenode has been changed
181         value_node->changed();
182 }