1 /* === S I N F G =========================================================== */
2 /*! \file valuenode_composite.cpp
3 ** \brief Template File
5 ** $Id: valuenode_composite.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
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.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "valuenode_composite.h"
32 #include "valuenode_const.h"
35 #include "valuenode_radialcomposite.h"
42 /* === U S I N G =========================================================== */
46 using namespace sinfg;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 sinfg::ValueNode_Composite::ValueNode_Composite(const ValueBase &value):
57 LinkableValueNode(value.get_type())
61 case ValueBase::TYPE_VECTOR:
62 set_link("x",ValueNode_Const::create(value.get(Vector())[0]));
63 set_link("y",ValueNode_Const::create(value.get(Vector())[1]));
65 case ValueBase::TYPE_COLOR:
66 set_link("r",ValueNode_Const::create(value.get(Color()).get_r()));
67 set_link("g",ValueNode_Const::create(value.get(Color()).get_g()));
68 set_link("b",ValueNode_Const::create(value.get(Color()).get_b()));
69 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
71 case ValueBase::TYPE_SEGMENT:
72 set_link("p1",ValueNode_Const::create(value.get(Segment()).p1));
73 set_link("t1",ValueNode_Const::create(value.get(Segment()).t1));
74 set_link("p2",ValueNode_Const::create(value.get(Segment()).p2));
75 set_link("t2",ValueNode_Const::create(value.get(Segment()).t2));
77 case ValueBase::TYPE_BLINEPOINT:
79 BLinePoint bline_point(value);
80 set_link(0,ValueNode_Const::create(bline_point.get_vertex()));
81 set_link(1,ValueNode_Const::create(bline_point.get_width()));
82 set_link(2,ValueNode_Const::create(bline_point.get_origin()));
83 set_link(3,ValueNode_Const::create(bline_point.get_split_tangent_flag()));
84 set_link(4,ValueNode_RadialComposite::create(bline_point.get_tangent1()));
85 set_link(5,ValueNode_RadialComposite::create(bline_point.get_tangent2()));
90 throw Exception::BadType(ValueBase::type_name(get_type()));
94 ValueNode_Composite::~ValueNode_Composite()
100 ValueNode_Composite::create(const ValueBase &value)
102 return new ValueNode_Composite(value);
106 ValueNode_Composite::create_new()const
108 return new ValueNode_Composite(ValueBase(get_type()));
112 sinfg::ValueNode_Composite::operator()(Time t)const
116 case ValueBase::TYPE_VECTOR:
119 assert(components[0] && components[1]);
120 vect[0]=(*components[0])(t).get(Vector::value_type());
121 vect[1]=(*components[1])(t).get(Vector::value_type());
124 case ValueBase::TYPE_COLOR:
127 assert(components[0] && components[1] && components[2] && components[3]);
128 color.set_r((*components[0])(t).get(Vector::value_type()));
129 color.set_g((*components[1])(t).get(Vector::value_type()));
130 color.set_b((*components[2])(t).get(Vector::value_type()));
131 color.set_a((*components[3])(t).get(Vector::value_type()));
134 case ValueBase::TYPE_SEGMENT:
137 assert(components[0] && components[1] && components[2] && components[3]);
138 seg.p1=(*components[0])(t).get(Point());
139 seg.t1=(*components[1])(t).get(Vector());
140 seg.p2=(*components[2])(t).get(Point());
141 seg.t2=(*components[3])(t).get(Vector());
144 case ValueBase::TYPE_BLINEPOINT:
147 assert(components[0] && components[1] && components[2] && components[3] && components[4] && components[5]);
148 ret.set_vertex((*components[0])(t).get(Point()));
149 ret.set_width((*components[1])(t).get(Real()));
150 ret.set_origin((*components[2])(t).get(Real()));
151 ret.set_split_tangent_flag((*components[3])(t).get(bool()));
152 ret.set_tangent1((*components[4])(t).get(Vector()));
153 if(ret.get_split_tangent_flag())
154 ret.set_tangent2((*components[5])(t).get(Vector()));
158 sinfg::error(string("ValueNode_Composite::operator():")+_("Bad type for composite"));
159 assert(components[0]);
160 return (*components[0])(t);
165 ValueNode_Composite::link_count()const
169 case ValueBase::TYPE_VECTOR:
171 case ValueBase::TYPE_COLOR:
173 case ValueBase::TYPE_SEGMENT:
175 case ValueBase::TYPE_BLINEPOINT:
178 sinfg::warning(string("ValueNode_Composite::component_count():")+_("Bad type for composite"));
184 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
189 if(PlaceholderValueNode::Handle::cast_dynamic(x))
197 case ValueBase::TYPE_VECTOR:
199 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
206 case ValueBase::TYPE_COLOR:
208 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
215 case ValueBase::TYPE_SEGMENT:
217 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
224 case ValueBase::TYPE_BLINEPOINT:
226 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
231 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
236 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
249 ValueNode::LooseHandle
250 ValueNode_Composite::get_link_vfunc(int i)const
253 return components[i];
257 ValueNode_Composite::link_local_name(int i)const
262 case ValueBase::TYPE_VECTOR:
263 return strprintf("%c-Axis",'X'+i);
265 case ValueBase::TYPE_COLOR:
275 case ValueBase::TYPE_SEGMENT:
277 return _("Vertex 1");
279 return _("Tangent 1");
281 return _("Vertex 2");
283 return _("Tangent 2");
285 case ValueBase::TYPE_BLINEPOINT:
293 return _("Split Tangents");
295 return _("Tangent 1");
297 return _("Tangent 2");
302 return etl::strprintf(_("C%d"),i+1);
307 ValueNode_Composite::link_name(int i)const
310 return strprintf("c%d",i);
314 ValueNode_Composite::get_link_index_from_name(const String &name)const
317 throw Exception::BadLinkName(name);
324 case ValueBase::TYPE_COLOR:
333 case ValueBase::TYPE_SEGMENT:
342 case ValueBase::TYPE_VECTOR:
349 case ValueBase::TYPE_BLINEPOINT:
350 if(name[0]=='p' || name=="v1" || name=="p1")
352 if(name=="w" || name=="width")
354 if(name=="o" || name=="origin")
366 throw Exception::BadLinkName(name);
370 ValueNode_Composite::get_name()const
376 ValueNode_Composite::get_local_name()const
378 return _("Composite");
382 ValueNode_Composite::check_type(ValueBase::Type type)
385 type==ValueBase::TYPE_SEGMENT ||
386 type==ValueBase::TYPE_VECTOR ||
387 type==ValueBase::TYPE_COLOR ||
388 type==ValueBase::TYPE_BLINEPOINT;