my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / keyframewaypointset.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file keyframeset.cpp
3 **      \brief Template File
4 **
5 **      $Id: keyframewaypointset.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 "keyframewaypointset.h"
32 #include <synfigapp/canvasinterface.h>
33 #include <synfig/valuenode_dynamiclist.h>
34 #include <synfig/valuenode_animated.h>
35 #include "activepointsetsmart.h"
36 #include "waypointsetsmart.h"
37
38 #endif
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
45
46 /* === M A C R O S ========================================================= */
47
48 ACTION_INIT(Action::KeyframeWaypointSet);
49 ACTION_SET_NAME(Action::KeyframeWaypointSet,"keyframe_waypoint_set");
50 ACTION_SET_LOCAL_NAME(Action::KeyframeWaypointSet,"Set Waypoints at Keyframe");
51 ACTION_SET_TASK(Action::KeyframeWaypointSet,"set");
52 ACTION_SET_CATEGORY(Action::KeyframeWaypointSet,Action::CATEGORY_KEYFRAME);
53 ACTION_SET_PRIORITY(Action::KeyframeWaypointSet,0);
54 ACTION_SET_VERSION(Action::KeyframeWaypointSet,"0.0");
55 ACTION_SET_CVS_ID(Action::KeyframeWaypointSet,"$Id: keyframewaypointset.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
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
63 Action::KeyframeWaypointSet::KeyframeWaypointSet()
64 {
65         keyframe.set_time(Time::begin()-1);
66         set_dirty(false);
67 }
68
69 Action::ParamVocab
70 Action::KeyframeWaypointSet::get_param_vocab()
71 {
72         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
73         
74         ret.push_back(ParamDesc("keyframe",Param::TYPE_KEYFRAME)
75                 .set_local_name(_("Keyframe"))
76         );
77
78         ret.push_back(ParamDesc("model",Param::TYPE_WAYPOINTMODEL)
79                 .set_local_name(_("Waypoint Model"))
80         );
81
82         return ret;
83 }
84
85 bool
86 Action::KeyframeWaypointSet::is_canidate(const ParamList &x)
87 {
88         return canidate_check(get_param_vocab(),x);
89 }
90
91 bool
92 Action::KeyframeWaypointSet::set_param(const synfig::String& name, const Action::Param &param)
93 {
94         if(name=="keyframe" && param.get_type()==Param::TYPE_KEYFRAME)
95         {
96                 keyframe=param.get_keyframe();
97                 
98                 return true;
99         }
100         if(name=="model" && param.get_type()==Param::TYPE_WAYPOINTMODEL)
101         {
102                 waypoint_model=param.get_waypoint_model();
103                 
104                 return true;
105         }
106
107         return Action::CanvasSpecific::set_param(name,param);
108 }
109
110 bool
111 Action::KeyframeWaypointSet::is_ready()const
112 {
113         if(keyframe.get_time()==(Time::begin()-1) || waypoint_model.is_trivial())
114                 return false;
115         return Action::CanvasSpecific::is_ready();
116 }
117
118 void
119 Action::KeyframeWaypointSet::prepare()
120 {
121         clear();
122
123         try { get_canvas()->keyframe_list().find(keyframe);}
124         catch(synfig::Exception::NotFound)
125         {
126                 throw Error(_("Unable to find the given keyframe"));
127         }       
128
129         {
130                 std::vector<synfigapp::ValueDesc> value_desc_list;
131                 get_canvas_interface()->find_important_value_descs(value_desc_list);
132                 while(!value_desc_list.empty())
133                 {
134                         process_value_desc(value_desc_list.back());
135                         value_desc_list.pop_back();
136                 }
137         }
138 }
139
140 void
141 Action::KeyframeWaypointSet::process_value_desc(const synfigapp::ValueDesc& value_desc)
142 {       
143         if(value_desc.is_value_node())
144         {
145                 ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node()));
146         
147                 if(value_node)
148                 {                       
149                         Action::Handle action(WaypointSetSmart::create());
150                         
151                         action->set_param("canvas",get_canvas());
152                         action->set_param("canvas_interface",get_canvas_interface());
153                         action->set_param("value_node",ValueNode::Handle(value_node));
154                         
155                         Waypoint waypoint;
156                         try
157                         {
158                                 waypoint=*value_node->find(keyframe.get_time());
159                         }
160                         catch(...)
161                         {
162                                 waypoint.set_time(keyframe.get_time());
163                                 waypoint.set_value((*value_node)(keyframe.get_time()));
164                         }
165                         waypoint.apply_model(waypoint_model);
166                         
167                         action->set_param("waypoint",waypoint);
168         
169                         assert(action->is_ready());
170                         if(!action->is_ready())
171                                 throw Error(Error::TYPE_NOTREADY);
172                 
173                         add_action_front(action);                                               
174                 }
175         }
176 }