moreupdates
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_segcalcvertex.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_segcalcvertex.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenode_segcalcvertex.cpp,v 1.1.1.1 2005/01/04 01:23:15 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 "valuenode_segcalcvertex.h"
32 #include "valuenode_const.h"
33 #include "valuenode_composite.h"
34 #include "general.h"
35 #include "exception.h"
36 #include <ETL/hermite>
37 #include "segment.h"
38
39 #endif
40
41 /* === U S I N G =========================================================== */
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
51 /* === P R O C E D U R E S ================================================= */
52
53 /* === M E T H O D S ======================================================= */
54
55 ValueNode_SegCalcVertex::ValueNode_SegCalcVertex(const ValueBase::Type &x):
56         LinkableValueNode(x)
57 {
58         if(x!=ValueBase::TYPE_VECTOR)
59                 throw Exception::BadType(ValueBase::type_name(x));
60         
61         segment_=ValueNode_Composite::create(ValueBase::TYPE_SEGMENT);
62         amount_=ValueNode_Const::create(Real(0.5));
63         
64 }
65
66 ValueNode_SegCalcVertex*
67 ValueNode_SegCalcVertex::create(const ValueBase &x)
68 {
69         return new ValueNode_SegCalcVertex(x.get_type());
70 }
71
72 ValueNode_SegCalcVertex::~ValueNode_SegCalcVertex()
73 {
74         unlink_all();
75 }
76
77 ValueBase
78 ValueNode_SegCalcVertex::operator()(Time t)const
79 {
80         Segment segment((*segment_)(t).get(Segment()));
81
82         etl::hermite<Vector> curve(segment.p1,segment.p2,segment.t1,segment.t2);
83         
84         return curve((*amount_)(t).get(Real()));
85 }
86
87
88 String
89 ValueNode_SegCalcVertex::get_name()const
90 {
91         return "segcalcvertex";
92 }
93
94 String
95 ValueNode_SegCalcVertex::get_local_name()const
96 {
97         return _("SegCalcVertex");
98 }
99                 
100 bool
101 ValueNode_SegCalcVertex::check_type(ValueBase::Type type)
102 {
103         return type==ValueBase::TYPE_VECTOR;
104 }
105
106 bool
107 ValueNode_SegCalcVertex::set_link_vfunc(int i,ValueNode::Handle x)
108 {
109         assert(i==0 || i==1);
110         if(i==0)
111         {
112                 segment_=x;
113                 signal_child_changed()(i);signal_value_changed()();
114                 return true;
115         }
116         if(i==1)
117         {
118                 amount_=x;
119                 signal_child_changed()(i);signal_value_changed()();
120                 return true;
121         }
122         return false;
123 }
124
125 ValueNode::LooseHandle
126 ValueNode_SegCalcVertex::get_link_vfunc(int i)const
127 {
128         assert(i==0 || i==1);
129         if(i==0)
130                 return segment_;
131         if(i==1)
132                 return amount_;
133
134         return 0;
135 }
136
137 int
138 ValueNode_SegCalcVertex::link_count()const
139 {
140         return 2;
141 }
142
143 String
144 ValueNode_SegCalcVertex::link_name(int i)const
145 {
146         assert(i==0 || i==1);
147         if(i==0)
148                 return "segment";
149         if(i==1)
150                 return "amount";
151         return String();
152 }
153
154 String
155 ValueNode_SegCalcVertex::link_local_name(int i)const
156 {
157         assert(i==0 || i==1);
158         if(i==0)
159                 return _("Segment");
160         if(i==1)
161                 return _("Amount");
162         return String();
163 }
164
165 int
166 ValueNode_SegCalcVertex::get_link_index_from_name(const String &name)const
167 {
168         if(name=="segment")
169                 return 0;
170         if(name=="amount")
171                 return 1;
172         
173         throw Exception::BadLinkName(name);
174 }
175
176 LinkableValueNode*
177 ValueNode_SegCalcVertex::create_new()const
178 {
179         return new ValueNode_SegCalcVertex(ValueBase::TYPE_VECTOR);
180 }