Update procedures
[shapes.git] / source / tagtypes.cc
blobc011b6ede8072e489f323dd5f6f970b2dcd7d45f
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #include "tagtypes.h"
20 #include "globals.h"
21 #include "ast.h"
23 using namespace Shapes;
25 Lang::Tagged2D::Tagged2D( const RefCountPtr< const Lang::Symbol > & key )
26 : key_( key->getKey( ) )
27 { }
29 Lang::Tagged2D::Tagged2D( const Lang::Symbol::KeyType key )
30 : key_( key )
31 { }
33 Lang::Tagged2D::~Tagged2D( )
34 { }
36 Lang::Symbol::KeyType
37 Lang::Tagged2D::key( ) const
39 return key_;
43 Lang::TaggedValue2D::TaggedValue2D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Value > & val )
44 : Lang::Tagged2D( key ), val_( val )
45 { }
47 Lang::TaggedValue2D::TaggedValue2D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Value > & val )
48 : Lang::Tagged2D( key ), val_( val )
49 { }
51 Lang::TaggedValue2D::~TaggedValue2D( )
52 { }
54 void
55 Lang::TaggedValue2D::shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf ) const
57 // Do nothing!
60 RefCountPtr< const Lang::ElementaryPath2D >
61 Lang::TaggedValue2D::bbox( Lang::Drawable2D::BoxType boxType ) const
63 return Lang::THE_EMPTYPATH2D;
66 RefCountPtr< const Lang::Geometric3D >
67 Lang::TaggedValue2D::to3D( const RefCountPtr< const Lang::Geometric2D > & self ) const
69 return RefCountPtr< const Lang::Geometric3D >( new Lang::TaggedValue3D( key_, val_ ) );
72 void
73 Lang::TaggedValue2D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
75 // tf is ignored for this type of tag.
76 if( key_ == key )
78 dst->push_back( val_ );
82 bool
83 Lang::TaggedValue2D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
85 // tf is ignored for this type of tag.
86 if( key_ == key )
88 Kernel::ContRef cont = evalState->cont_;
89 cont->takeValue( val_,
90 evalState );
91 return true;
93 return false;
96 void
97 Lang::TaggedValue2D::show( std::ostream & os ) const
99 try
101 os << "Value with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
103 catch( ... )
105 os << "Value with unique tag." ;
109 RefCountPtr< const Lang::Value >
110 Lang::TaggedValue2D::val( ) const
112 return val_;
115 void
116 Lang::TaggedValue2D::gcMark( Kernel::GCMarkedSet & marked )
118 const_cast< Lang::Value * >( val_.getPtr( ) )->gcMark( marked );
122 Lang::TaggedGeometric2D::TaggedGeometric2D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Geometric2D > & val )
123 : Lang::Tagged2D( key ), val_( val )
126 Lang::TaggedGeometric2D::TaggedGeometric2D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Geometric2D > & val )
127 : Lang::Tagged2D( key ), val_( val )
130 Lang::TaggedGeometric2D::~TaggedGeometric2D( )
133 void
134 Lang::TaggedGeometric2D::shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf ) const
136 // Do nothing!
139 RefCountPtr< const Lang::ElementaryPath2D >
140 Lang::TaggedGeometric2D::bbox( Lang::Drawable2D::BoxType boxType ) const
142 return Lang::THE_EMPTYPATH2D;
145 RefCountPtr< const Lang::Geometric3D >
146 Lang::TaggedGeometric2D::to3D( const RefCountPtr< const Lang::Geometric2D > & self ) const
148 return RefCountPtr< const Lang::Geometric3D >( new Lang::TaggedGeometric3D( key_, val_->to3D( val_ ) ) );
151 void
152 Lang::TaggedGeometric2D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
154 // tf is ignored for this type of tag.
155 if( key_ == key )
157 dst->push_back( val_->transformed( tf, val_ ) );
161 bool
162 Lang::TaggedGeometric2D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
164 // tf is ignored for this type of tag.
165 if( key_ == key )
167 Kernel::ContRef cont = evalState->cont_;
168 cont->takeValue( val_->transformed( tf, val_ ),
169 evalState );
170 return true;
172 return false;
175 void
176 Lang::TaggedGeometric2D::show( std::ostream & os ) const
180 os << "Geometric value with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
182 catch( ... )
184 os << "Geometric value with unique tag." ;
188 void
189 Lang::TaggedGeometric2D::gcMark( Kernel::GCMarkedSet & marked )
191 const_cast< Lang::Geometric2D * >( val_.getPtr( ) )->gcMark( marked );
195 Lang::TaggedDrawable2D::TaggedDrawable2D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Drawable2D > & val )
196 : Lang::Tagged2D( key ), val_( val )
199 Lang::TaggedDrawable2D::TaggedDrawable2D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Drawable2D > & val )
200 : Lang::Tagged2D( key ), val_( val )
203 Lang::TaggedDrawable2D::~TaggedDrawable2D( )
206 void
207 Lang::TaggedDrawable2D::shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf ) const
209 val_->shipout( os, pdfState, tf );
212 RefCountPtr< const Lang::ElementaryPath2D >
213 Lang::TaggedDrawable2D::bbox( Lang::Drawable2D::BoxType boxType ) const
215 return val_->bbox( boxType );
218 RefCountPtr< const Lang::Geometric3D >
219 Lang::TaggedDrawable2D::to3D( const RefCountPtr< const Lang::Geometric2D > & self ) const
221 return RefCountPtr< const Lang::Geometric3D >( new Lang::TaggedDrawable3D
222 ( key_,
223 RefCountPtr< const Lang::Drawable3D >( new Lang::Drawable2Din3D( val_ ) ) ) );
226 void
227 Lang::TaggedDrawable2D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
229 // tf is ignored for this type of tag.
230 if( key_ == key )
232 dst->push_back( val_->transformed( tf, val_ ) );
236 bool
237 Lang::TaggedDrawable2D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform2D & tf ) const
239 // tf is ignored for this type of tag.
240 if( key_ == key )
242 Kernel::ContRef cont = evalState->cont_;
243 cont->takeValue( val_->transformed( tf, val_ ),
244 evalState );
245 return true;
247 return false;
250 void
251 Lang::TaggedDrawable2D::show( std::ostream & os ) const
255 os << "Drawable value with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
257 catch( ... )
259 os << "Drawable value with unique tag." ;
263 void
264 Lang::TaggedDrawable2D::gcMark( Kernel::GCMarkedSet & marked )
266 const_cast< Lang::Drawable2D * >( val_.getPtr( ) )->gcMark( marked );
270 Lang::Tagged3D::Tagged3D( const RefCountPtr< const Lang::Symbol > & key )
271 : key_( key->getKey( ) )
274 Lang::Tagged3D::Tagged3D( const Lang::Symbol::KeyType key )
275 : key_( key )
278 Lang::Tagged3D::~Tagged3D( )
281 Lang::Symbol::KeyType
282 Lang::Tagged3D::key( ) const
284 return key_;
288 Lang::TaggedValue3D::TaggedValue3D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Value > & val )
289 : Lang::Tagged3D( key ), val_( val )
292 Lang::TaggedValue3D::TaggedValue3D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Value > & val )
293 : Lang::Tagged3D( key ), val_( val )
296 Lang::TaggedValue3D::~TaggedValue3D( )
299 RefCountPtr< const Lang::Drawable2D >
300 Lang::TaggedValue3D::typed_to2D( const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
302 return RefCountPtr< const Lang::Drawable2D >( new Lang::TaggedValue2D( key_, val_ ) );
305 void
306 Lang::TaggedValue3D::polygonize( std::list< RefCountPtr< Computation::PaintedPolygon3D > > * zBufPile, std::list< RefCountPtr< Computation::StrokedLine3D > > * linePile, const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
308 // Note that polygonization eats tags.
311 void
312 Lang::TaggedValue3D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
314 // tf is ignored for this type of tag.
315 if( key_ == key )
317 dst->push_back( val_ );
321 bool
322 Lang::TaggedValue3D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
324 // tf is ignored for this type of tag.
325 if( key_ == key )
327 Kernel::ContRef cont = evalState->cont_;
328 cont->takeValue( val_,
329 evalState );
330 return true;
332 return false;
335 void
336 Lang::TaggedValue3D::show( std::ostream & os ) const
340 os << "Value (3D) with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
342 catch( ... )
344 os << "Value (3D) with unique tag." ;
348 void
349 Lang::TaggedValue3D::gcMark( Kernel::GCMarkedSet & marked )
351 const_cast< Lang::Value * >( val_.getPtr( ) )->gcMark( marked );
355 Lang::TaggedGeometric3D::TaggedGeometric3D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Geometric3D > & val )
356 : Lang::Tagged3D( key ), val_( val )
359 Lang::TaggedGeometric3D::TaggedGeometric3D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Geometric3D > & val )
360 : Lang::Tagged3D( key ), val_( val )
363 Lang::TaggedGeometric3D::~TaggedGeometric3D( )
367 RefCountPtr< const Lang::Drawable2D >
368 Lang::TaggedGeometric3D::typed_to2D( const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
370 RefCountPtr< const Lang::Geometric3D > tfVal = val_->transformed( tf, val_ );
371 return RefCountPtr< const Lang::Drawable2D >( new Lang::TaggedGeometric2D( key_, tfVal->to2D( dyn, tfVal ) ) );
374 void
375 Lang::TaggedGeometric3D::polygonize( std::list< RefCountPtr< Computation::PaintedPolygon3D > > * zBufPile, std::list< RefCountPtr< Computation::StrokedLine3D > > * linePile, const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
377 // Note that polygonization eats tags.
380 void
381 Lang::TaggedGeometric3D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
383 // tf is ignored for this type of tag.
384 if( key_ == key )
386 dst->push_back( val_->transformed( tf, val_ ) );
390 bool
391 Lang::TaggedGeometric3D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
393 // tf is ignored for this type of tag.
394 if( key_ == key )
396 Kernel::ContRef cont = evalState->cont_;
397 cont->takeValue( val_->transformed( tf, val_ ),
398 evalState );
399 return true;
401 return false;
404 void
405 Lang::TaggedGeometric3D::show( std::ostream & os ) const
409 os << "Geometric value (3D) with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
411 catch( ... )
413 os << "Geometric value (3D) with unique tag." ;
417 void
418 Lang::TaggedGeometric3D::gcMark( Kernel::GCMarkedSet & marked )
420 const_cast< Lang::Geometric3D * >( val_.getPtr( ) )->gcMark( marked );
424 Lang::TaggedDrawable3D::TaggedDrawable3D( const RefCountPtr< const Lang::Symbol > & key, const RefCountPtr< const Lang::Drawable3D > & val )
425 : Lang::Tagged3D( key ), val_( val )
428 Lang::TaggedDrawable3D::TaggedDrawable3D( const Lang::Symbol::KeyType key, const RefCountPtr< const Lang::Drawable3D > & val )
429 : Lang::Tagged3D( key ), val_( val )
432 Lang::TaggedDrawable3D::~TaggedDrawable3D( )
435 RefCountPtr< const Lang::Drawable2D >
436 Lang::TaggedDrawable3D::typed_to2D( const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
438 return RefCountPtr< const Lang::Drawable2D >( new Lang::TaggedDrawable2D( key_, val_->typed_to2D( dyn, tf, val_ ) ) );
441 void
442 Lang::TaggedDrawable3D::polygonize( std::list< RefCountPtr< Computation::PaintedPolygon3D > > * zBufPile, std::list< RefCountPtr< Computation::StrokedLine3D > > * linePile, const Kernel::PassedDyn & dyn, const Lang::Transform3D & tf, const RefCountPtr< const Lang::Drawable3D > & self ) const
444 // Note that polygonization eats tags.
446 val_->polygonize( zBufPile, linePile, dyn, tf, val_ );
450 void
451 Lang::TaggedDrawable3D::findTags( std::vector< Kernel::ValueRef > * dst, const Kernel::PassedDyn & dyn, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
453 // tf is ignored for this type of tag.
454 if( key_ == key )
456 dst->push_back( val_->transformed( tf, val_ ) );
460 bool
461 Lang::TaggedDrawable3D::findOneTag( Kernel::EvalState * evalState, Lang::Symbol::KeyType key, const Lang::Transform3D & tf ) const
463 // tf is ignored for this type of tag.
464 if( key_ == key )
466 Kernel::ContRef cont = evalState->cont_;
467 cont->takeValue( val_->transformed( tf, val_ ),
468 evalState );
469 return true;
471 return false;
474 void
475 Lang::TaggedDrawable3D::show( std::ostream & os ) const
479 os << "Drawable value (3D) with the tag " << Lang::Symbol::nameFromKey( key_ ).getPtr( ) ;
481 catch( ... )
483 os << "Drawable value (3D) with unique tag." ;
487 void
488 Lang::TaggedDrawable3D::gcMark( Kernel::GCMarkedSet & marked )
490 const_cast< Lang::Drawable3D * >( val_.getPtr( ) )->gcMark( marked );