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::link_count()const
178 case ValueBase::TYPE_VECTOR:
180 case ValueBase::TYPE_COLOR:
182 case ValueBase::TYPE_SEGMENT:
184 case ValueBase::TYPE_BLINEPOINT:
187 synfig::warning(string("ValueNode_Composite::component_count():")+_("Bad type for composite"));
193 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
195 assert(i>=0 && i<link_count());
197 if(PlaceholderValueNode::Handle::cast_dynamic(x))
205 case ValueBase::TYPE_VECTOR:
206 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
213 case ValueBase::TYPE_COLOR:
214 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
221 case ValueBase::TYPE_SEGMENT:
222 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
229 case ValueBase::TYPE_BLINEPOINT:
230 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
235 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
240 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
253 ValueNode::LooseHandle
254 ValueNode_Composite::get_link_vfunc(int i)const
256 assert(i>=0 && i<link_count());
258 return components[i];
262 ValueNode_Composite::link_local_name(int i)const
264 assert(i>=0 && i<link_count());
268 case ValueBase::TYPE_VECTOR:
269 return strprintf("%c-Axis",'X'+i);
271 case ValueBase::TYPE_COLOR:
281 case ValueBase::TYPE_SEGMENT:
283 return _("Vertex 1");
285 return _("Tangent 1");
287 return _("Vertex 2");
289 return _("Tangent 2");
291 case ValueBase::TYPE_BLINEPOINT:
299 return _("Split Tangents");
301 return _("Tangent 1");
303 return _("Tangent 2");
307 // notice that Composite counts from 1 and Radial Composite counts
308 // from 0! we need to keep it like that to correctly load old
309 // animations, but let's not save "c%d" format link names in future
310 return etl::strprintf(_("C%d"),i+1);
316 ValueNode_Composite::link_name(int i)const
318 assert(i>=0 && i<link_count());
320 if (get_file_version() < RELEASE_VERSION_0_61_08)
321 return strprintf("c%d",i+1);
325 case ValueBase::TYPE_COLOR:
328 case 0: return "red";
329 case 1: return "green";
330 case 2: return "blue";
331 case 3: return "alpha";
334 case ValueBase::TYPE_SEGMENT:
343 case ValueBase::TYPE_VECTOR:
350 case ValueBase::TYPE_BLINEPOINT:
353 case 0: return "point";
354 case 1: return "width";
355 case 2: return "origin";
356 case 3: return "split";
366 // notice that Composite counts from 1 and Radial Composite counts
367 // from 0! we need to keep it like that to correctly load old
368 // animations, but let's not save "c%d" format link names in future
369 return strprintf("c%d",i+1);
373 ValueNode_Composite::get_link_index_from_name(const String &name)const
376 throw Exception::BadLinkName(name);
378 if(name[0]=='c' && name.size() == 2 && name[1]-'1' >= 0 && name[1]-'1' < link_count())
383 case ValueBase::TYPE_COLOR:
392 case ValueBase::TYPE_SEGMENT:
401 case ValueBase::TYPE_VECTOR:
406 if(name[0]=='z') // \todo "z"? really?
408 case ValueBase::TYPE_BLINEPOINT:
409 if(name[0]=='p' || name=="v1" || name=="p1")
411 if(name=="w" || name=="width")
413 if(name=="o" || name=="origin")
425 throw Exception::BadLinkName(name);
429 ValueNode_Composite::get_name()const
435 ValueNode_Composite::get_local_name()const
437 return _("Composite");
441 ValueNode_Composite::check_type(ValueBase::Type type)
444 type==ValueBase::TYPE_SEGMENT ||
445 type==ValueBase::TYPE_VECTOR ||
446 type==ValueBase::TYPE_COLOR ||
447 type==ValueBase::TYPE_BLINEPOINT;
450 LinkableValueNode::Vocab
451 ValueNode_Composite::get_children_vocab_vfunc()const
453 if(children_vocab.size())
454 return children_vocab;
456 LinkableValueNode::Vocab ret;
460 case ValueBase::TYPE_COLOR:
461 ret.push_back(ParamDesc(ValueBase(),"red")
462 .set_local_name(_("Red"))
463 .set_description(_("The red component of the color"))
465 ret.push_back(ParamDesc(ValueBase(),"green")
466 .set_local_name(_("Green"))
467 .set_description(_("The green component of the color"))
469 ret.push_back(ParamDesc(ValueBase(),"blue")
470 .set_local_name(_("Blue"))
471 .set_description(_("The blue component of the color"))
473 ret.push_back(ParamDesc(ValueBase(),"alpha")
474 .set_local_name(_("Alpha"))
475 .set_description(_("The alpha of the color"))
478 case ValueBase::TYPE_SEGMENT:
479 ret.push_back(ParamDesc(ValueBase(),"p1")
480 .set_local_name(_("Vertex 1"))
481 .set_description(_("The first vertex of the segment"))
483 ret.push_back(ParamDesc(ValueBase(),"t1")
484 .set_local_name(_("Tangent 1"))
485 .set_description(_("The first tangent of the segment"))
487 ret.push_back(ParamDesc(ValueBase(),"p2")
488 .set_local_name(_("Vertex 2"))
489 .set_description(_("The second vertex of the segment"))
491 ret.push_back(ParamDesc(ValueBase(),"t2")
492 .set_local_name(_("Tangent 2"))
493 .set_description(_("The second tangent of the segment"))
496 case ValueBase::TYPE_VECTOR:
497 ret.push_back(ParamDesc(ValueBase(),"x")
498 .set_local_name(_("X-Axis"))
499 .set_description(_("The X-Axis component of the vector"))
501 ret.push_back(ParamDesc(ValueBase(),"y")
502 .set_local_name(_("Y-Axis"))
503 .set_description(_("The Y-Axis component of the vector"))
506 case ValueBase::TYPE_BLINEPOINT:
507 ret.push_back(ParamDesc(ValueBase(),"point")
508 .set_local_name(_("Vertex"))
509 .set_description(_("The vertex of the BLine Point"))
511 ret.push_back(ParamDesc(ValueBase(),"width")
512 .set_local_name(_("Width"))
513 .set_description(_("The width of the BLine Point"))
515 ret.push_back(ParamDesc(ValueBase(),"origin")
516 .set_local_name(_("Origin"))
517 .set_description(_("Defines the Off and On position relative to neighbours"))
519 ret.push_back(ParamDesc(ValueBase(),"split")
520 .set_local_name(_("Split"))
521 .set_description(_("When checked, tangents are independent"))
523 ret.push_back(ParamDesc(ValueBase(),"t1")
524 .set_local_name(_("Tangent 1"))
525 .set_description(_("The first tangent of the BLine Point"))
527 ret.push_back(ParamDesc(ValueBase(),"t2")
528 .set_local_name(_("Tangent 2"))
529 .set_description(_("The second tangent of the BLine Point"))