my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / blinepointtangentmerge.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file blinepointtangentmerge.cpp
3 **      \brief Template File
4 **
5 **      $Id: blinepointtangentmerge.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 "blinepointtangentmerge.h"
32 #include "valuedescset.h"
33
34 #include "activepointset.h"
35 #include "activepointadd.h"
36
37 #include "valuedescconnect.h"
38 #include <synfigapp/canvasinterface.h>
39
40 #endif
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45 using namespace synfigapp;
46 using namespace Action;
47
48 /* === M A C R O S ========================================================= */
49
50 ACTION_INIT(Action::BLinePointTangentMerge);
51 ACTION_SET_NAME(Action::BLinePointTangentMerge,"bline_point_tangent_merge");
52 ACTION_SET_LOCAL_NAME(Action::BLinePointTangentMerge,_("Merge Tangents"));
53 ACTION_SET_TASK(Action::BLinePointTangentMerge,"merge");
54 ACTION_SET_CATEGORY(Action::BLinePointTangentMerge,Action::CATEGORY_VALUENODE);
55 ACTION_SET_PRIORITY(Action::BLinePointTangentMerge,0);
56 ACTION_SET_VERSION(Action::BLinePointTangentMerge,"0.0");
57 ACTION_SET_CVS_ID(Action::BLinePointTangentMerge,"$Id: blinepointtangentmerge.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
58
59 /* === G L O B A L S ======================================================= */
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 Action::BLinePointTangentMerge::BLinePointTangentMerge()
66 {
67         time=(Time::begin()-1);
68         set_dirty(true);
69 }
70
71 Action::ParamVocab
72 Action::BLinePointTangentMerge::get_param_vocab()
73 {
74         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
75         
76         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
77                 .set_local_name(_("ValueNode of BLinePoint"))
78         );
79
80         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
81                 .set_local_name(_("Time"))
82         );
83         
84         return ret;
85 }
86
87 bool
88 Action::BLinePointTangentMerge::is_canidate(const ParamList &x)
89 {
90         if(canidate_check(get_param_vocab(),x))
91         {
92                 ValueNode_Composite::Handle value_node;
93                 value_node=ValueNode_Composite::Handle::cast_dynamic(x.find("value_node")->second.get_value_node());
94                 if(!value_node || value_node->get_type()!=ValueBase::TYPE_BLINEPOINT)
95                         return false;
96                 synfig::Time time(x.find("time")->second.get_time());
97                 if((*value_node->get_link("split"))(time).get(bool())==false)
98                         return false;
99                 return true;
100         }
101         return false;
102 }
103
104 bool
105 Action::BLinePointTangentMerge::set_param(const synfig::String& name, const Action::Param &param)
106 {
107         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
108         {
109                 value_node=value_node.cast_dynamic(param.get_value_node());
110                 
111                 return (bool)(value_node);
112         }
113         if(name=="time" && param.get_type()==Param::TYPE_TIME)
114         {
115                 time=param.get_time();
116                 
117                 return true;
118         }
119
120         return Action::CanvasSpecific::set_param(name,param);
121 }
122
123 bool
124 Action::BLinePointTangentMerge::is_ready()const
125 {
126         if(!value_node)
127                 synfig::error("Missing or bad value_node");
128
129         if(time==(Time::begin()-1))
130                 synfig::error("Missing time");
131         
132         if(!value_node || time==(Time::begin()-1))
133                 return false;
134         return Action::CanvasSpecific::is_ready();
135 }
136
137 void
138 Action::BLinePointTangentMerge::prepare()
139 {
140         clear();
141
142         Action::Handle action;
143         
144         {
145                 action=Action::create("value_desc_set");
146                 if(!action)
147                         throw Error(_("Couldn't find action \"value_desc_set\""));
148                 
149                 action->set_param("canvas",get_canvas());
150                 action->set_param("canvas_interface",get_canvas_interface());
151                 action->set_param("value_desc",ValueDesc(value_node,3));
152                 action->set_param("time",time);
153                 action->set_param("new_value",synfig::ValueBase(false));
154         
155                 assert(action->is_ready());
156                 if(!action->is_ready())
157                         throw Error(Error::TYPE_NOTREADY);
158         
159                 add_action(action);
160         }
161         {
162                 action=Action::create("value_desc_set");
163                 if(!action)
164                         throw Error(_("Couldn't find action \"value_desc_set\""));
165                 
166                 action->set_param("canvas",get_canvas());
167                 action->set_param("canvas_interface",get_canvas_interface());
168                 action->set_param("value_desc",ValueDesc(value_node,5));
169                 action->set_param("time",time);
170                 action->set_param("new_value",(*value_node->get_link("t1"))(time));
171         
172                 assert(action->is_ready());
173                 if(!action->is_ready())
174                         throw Error(Error::TYPE_NOTREADY);
175         
176                 add_action(action);
177         }
178         
179 }