my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / activepointremove.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file activepointremove.cpp
3 **      \brief Template File
4 **
5 **      $Id: activepointremove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
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 "activepointremove.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::ActivepointRemove);
45 ACTION_SET_NAME(Action::ActivepointRemove,"activepoint_remove");
46 ACTION_SET_LOCAL_NAME(Action::ActivepointRemove,"Remove Activepoint");
47 ACTION_SET_TASK(Action::ActivepointRemove,"remove");
48 ACTION_SET_CATEGORY(Action::ActivepointRemove,Action::CATEGORY_ACTIVEPOINT);
49 ACTION_SET_PRIORITY(Action::ActivepointRemove,0);
50 ACTION_SET_VERSION(Action::ActivepointRemove,"0.0");
51 ACTION_SET_CVS_ID(Action::ActivepointRemove,"$Id: activepointremove.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::ActivepointRemove::ActivepointRemove()
60 {
61         activepoint.set_time(Time::begin()-1);
62         set_dirty(true);
63 }
64
65 Action::ParamVocab
66 Action::ActivepointRemove::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(_("ValueDesc"))
72         );
73
74         ret.push_back(ParamDesc("activepoint",Param::TYPE_ACTIVEPOINT)
75                 .set_local_name(_("Activepoint"))
76                 .set_desc(_("Activepoint to be changed"))
77         );
78
79         return ret;
80 }
81
82 bool
83 Action::ActivepointRemove::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 false;
94 }
95
96 bool
97 Action::ActivepointRemove::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::ActivepointRemove::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::ActivepointRemove::perform()
135 {       
136         ValueNode_DynamicList::ListEntry::ActivepointList::iterator iter;
137         
138         try { iter=value_node->list[index].find(activepoint); }
139         catch(synfig::Exception::NotFound)
140         {
141                 throw Error(_("Unable to find activepoint"));
142         }       
143
144         value_node->list[index].erase(activepoint);
145         value_node->changed();
146         
147         /*
148         // Signal that a layer has been inserted
149         if(get_canvas_interface())
150         {
151                 get_canvas_interface()->signal_value_node_changed()(value_node);
152         }
153         else synfig::warning("CanvasInterface not set on action");
154         */
155 }
156
157 void
158 Action::ActivepointRemove::undo()
159 {
160         try { value_node->list[index].find(activepoint.get_time()); throw Error(_("A Activepoint already exists at this point in time"));}
161         catch(synfig::Exception::NotFound) { }  
162
163         try { if(value_node->list[index].find(activepoint)!=value_node->list[index].timing_info.end()) throw Error(_("This activepoint is already in the ValueNode"));}
164         catch(synfig::Exception::NotFound) { }  
165         
166         value_node->list[index].add(activepoint);
167         value_node->changed();
168         /*
169         // Signal that a layer has been inserted
170         if(get_canvas_interface())
171         {
172                 get_canvas_interface()->signal_value_node_changed()(value_node);
173         }
174         else synfig::warning("CanvasInterface not set on action");
175         */
176 }