1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_composite.cpp
3 ** \brief Implementation of the "Composite" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
10 ** Copyright (c) 2009 Nikita Kitaev
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "valuenode_composite.h"
35 #include "valuenode_const.h"
38 #include "valuenode_radialcomposite.h"
42 #include "savecanvas.h"
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 synfig::ValueNode_Composite::ValueNode_Composite(const ValueBase &value):
61 LinkableValueNode(value.get_type())
63 Vocab ret(get_children_vocab());
64 set_children_vocab(ret);
67 case ValueBase::TYPE_VECTOR:
68 set_link("x",ValueNode_Const::create(value.get(Vector())[0]));
69 set_link("y",ValueNode_Const::create(value.get(Vector())[1]));
71 case ValueBase::TYPE_COLOR:
72 set_link("r",ValueNode_Const::create(value.get(Color()).get_r()));
73 set_link("g",ValueNode_Const::create(value.get(Color()).get_g()));
74 set_link("b",ValueNode_Const::create(value.get(Color()).get_b()));
75 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
77 case ValueBase::TYPE_SEGMENT:
78 set_link("p1",ValueNode_Const::create(value.get(Segment()).p1));
79 set_link("t1",ValueNode_Const::create(value.get(Segment()).t1));
80 set_link("p2",ValueNode_Const::create(value.get(Segment()).p2));
81 set_link("t2",ValueNode_Const::create(value.get(Segment()).t2));
83 case ValueBase::TYPE_BLINEPOINT:
85 BLinePoint bline_point(value);
86 set_link("point",ValueNode_Const::create(bline_point.get_vertex()));
87 set_link("width",ValueNode_Const::create(bline_point.get_width()));
88 set_link("origin",ValueNode_Const::create(bline_point.get_origin()));
89 set_link("split",ValueNode_Const::create(bline_point.get_split_tangent_flag()));
90 set_link("t1",ValueNode_RadialComposite::create(bline_point.get_tangent1()));
91 set_link("t2",ValueNode_RadialComposite::create(bline_point.get_tangent2()));
96 throw Exception::BadType(ValueBase::type_local_name(get_type()));
100 ValueNode_Composite::~ValueNode_Composite()
106 ValueNode_Composite::create(const ValueBase &value)
108 return new ValueNode_Composite(value);
112 ValueNode_Composite::create_new()const
114 return new ValueNode_Composite(ValueBase(get_type()));
118 synfig::ValueNode_Composite::operator()(Time t)const
120 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
121 printf("%s:%d operator()\n", __FILE__, __LINE__);
125 case ValueBase::TYPE_VECTOR:
128 assert(components[0] && components[1]);
129 vect[0]=(*components[0])(t).get(Vector::value_type());
130 vect[1]=(*components[1])(t).get(Vector::value_type());
133 case ValueBase::TYPE_COLOR:
136 assert(components[0] && components[1] && components[2] && components[3]);
137 color.set_r((*components[0])(t).get(Vector::value_type()));
138 color.set_g((*components[1])(t).get(Vector::value_type()));
139 color.set_b((*components[2])(t).get(Vector::value_type()));
140 color.set_a((*components[3])(t).get(Vector::value_type()));
143 case ValueBase::TYPE_SEGMENT:
146 assert(components[0] && components[1] && components[2] && components[3]);
147 seg.p1=(*components[0])(t).get(Point());
148 seg.t1=(*components[1])(t).get(Vector());
149 seg.p2=(*components[2])(t).get(Point());
150 seg.t2=(*components[3])(t).get(Vector());
153 case ValueBase::TYPE_BLINEPOINT:
156 assert(components[0] && components[1] && components[2] && components[3] && components[4] && components[5]);
157 ret.set_vertex((*components[0])(t).get(Point()));
158 ret.set_width((*components[1])(t).get(Real()));
159 ret.set_origin((*components[2])(t).get(Real()));
160 ret.set_split_tangent_flag((*components[3])(t).get(bool()));
161 ret.set_tangent1((*components[4])(t).get(Vector()));
162 if(ret.get_split_tangent_flag())
163 ret.set_tangent2((*components[5])(t).get(Vector()));
167 synfig::error(string("ValueNode_Composite::operator():")+_("Bad type for composite"));
168 assert(components[0]);
169 return (*components[0])(t);
174 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
176 assert(i>=0 && i<link_count());
178 if(PlaceholderValueNode::Handle::cast_dynamic(x))
186 case ValueBase::TYPE_VECTOR:
187 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
194 case ValueBase::TYPE_COLOR:
195 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
202 case ValueBase::TYPE_SEGMENT:
203 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
210 case ValueBase::TYPE_BLINEPOINT:
211 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
216 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
221 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
234 ValueNode::LooseHandle
235 ValueNode_Composite::get_link_vfunc(int i)const
237 assert(i>=0 && i<link_count());
239 return components[i];
243 ValueNode_Composite::link_name(int i)const
245 assert(i>=0 && i<link_count());
247 if (get_file_version() < RELEASE_VERSION_0_61_08)
248 return strprintf("c%d",i+1);
250 return LinkableValueNode::link_name(i);
254 ValueNode_Composite::get_link_index_from_name(const String &name)const
256 // Here we don't use the LinkableValueNode::get_link_index_from_name
257 // due to the particularities of the link index from name for old files.
258 // So we keep this alive to maintain old file compatibilities.
260 throw Exception::BadLinkName(name);
262 if(name[0]=='c' && name.size() == 2 && name[1]-'1' >= 0 && name[1]-'1' < link_count())
267 case ValueBase::TYPE_COLOR:
276 case ValueBase::TYPE_SEGMENT:
285 case ValueBase::TYPE_VECTOR:
290 if(name[0]=='z') // \todo "z"? really?
292 case ValueBase::TYPE_BLINEPOINT:
293 if(name[0]=='p' || name=="v1" || name=="p1")
295 if(name=="w" || name=="width")
297 if(name=="o" || name=="origin")
309 throw Exception::BadLinkName(name);
313 ValueNode_Composite::get_name()const
319 ValueNode_Composite::get_local_name()const
321 return _("Composite");
325 ValueNode_Composite::check_type(ValueBase::Type type)
328 type==ValueBase::TYPE_SEGMENT ||
329 type==ValueBase::TYPE_VECTOR ||
330 type==ValueBase::TYPE_COLOR ||
331 type==ValueBase::TYPE_BLINEPOINT;
334 LinkableValueNode::Vocab
335 ValueNode_Composite::get_children_vocab_vfunc()const
337 if(children_vocab.size())
338 return children_vocab;
340 LinkableValueNode::Vocab ret;
344 case ValueBase::TYPE_COLOR:
345 ret.push_back(ParamDesc(ValueBase(),"red")
346 .set_local_name(_("Red"))
347 .set_description(_("The red component of the color"))
349 ret.push_back(ParamDesc(ValueBase(),"green")
350 .set_local_name(_("Green"))
351 .set_description(_("The green component of the color"))
353 ret.push_back(ParamDesc(ValueBase(),"blue")
354 .set_local_name(_("Blue"))
355 .set_description(_("The blue component of the color"))
357 ret.push_back(ParamDesc(ValueBase(),"alpha")
358 .set_local_name(_("Alpha"))
359 .set_description(_("The alpha of the color"))
362 case ValueBase::TYPE_SEGMENT:
363 ret.push_back(ParamDesc(ValueBase(),"p1")
364 .set_local_name(_("Vertex 1"))
365 .set_description(_("The first vertex of the segment"))
367 ret.push_back(ParamDesc(ValueBase(),"t1")
368 .set_local_name(_("Tangent 1"))
369 .set_description(_("The first tangent of the segment"))
371 ret.push_back(ParamDesc(ValueBase(),"p2")
372 .set_local_name(_("Vertex 2"))
373 .set_description(_("The second vertex of the segment"))
375 ret.push_back(ParamDesc(ValueBase(),"t2")
376 .set_local_name(_("Tangent 2"))
377 .set_description(_("The second tangent of the segment"))
380 case ValueBase::TYPE_VECTOR:
381 ret.push_back(ParamDesc(ValueBase(),"x")
382 .set_local_name(_("X-Axis"))
383 .set_description(_("The X-Axis component of the vector"))
385 ret.push_back(ParamDesc(ValueBase(),"y")
386 .set_local_name(_("Y-Axis"))
387 .set_description(_("The Y-Axis component of the vector"))
390 case ValueBase::TYPE_BLINEPOINT:
391 ret.push_back(ParamDesc(ValueBase(),"point")
392 .set_local_name(_("Vertex"))
393 .set_description(_("The vertex of the BLine Point"))
395 ret.push_back(ParamDesc(ValueBase(),"width")
396 .set_local_name(_("Width"))
397 .set_description(_("The width of the BLine Point"))
399 ret.push_back(ParamDesc(ValueBase(),"origin")
400 .set_local_name(_("Origin"))
401 .set_description(_("Defines the Off and On position relative to neighbours"))
403 ret.push_back(ParamDesc(ValueBase(),"split")
404 .set_local_name(_("Split"))
405 .set_description(_("When checked, tangents are independent"))
407 ret.push_back(ParamDesc(ValueBase(),"t1")
408 .set_local_name(_("Tangent 1"))
409 .set_description(_("The first tangent of the BLine Point"))
411 ret.push_back(ParamDesc(ValueBase(),"t2")
412 .set_local_name(_("Tangent 2"))
413 .set_description(_("The second tangent of the BLine Point"))