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
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, 2009 Henrik Tidefelt
21 #include "shapestypes.h"
22 #include "shapesexceptions.h"
32 using namespace Shapes
;
36 Lang::PathSlider2D::PathSlider2D( const Lang::PathSlider2D
& orig
)
37 : path_( orig
.getPath( ) ), t_( orig
.getTime( ) ), info_( orig
.getInfo( ) )
40 Lang::PathSlider2D::PathSlider2D( const RefCountPtr
< const Lang::ElementaryPath2D
> & path
)
41 : path_( path
), t_( 0 ), info_( Kernel::THE_VOID_VARIABLE
)
44 Lang::PathSlider2D::PathSlider2D( const RefCountPtr
< const Lang::ElementaryPath2D
> & path
, Concrete::SplineTime t
)
45 : path_( path
), t_( t
), info_( Kernel::THE_VOID_VARIABLE
)
48 Lang::PathSlider2D::PathSlider2D( const RefCountPtr
< const Lang::ElementaryPath2D
> & path
, Concrete::SplineTime t
, Kernel::VariableHandle info
)
49 : path_( path
), t_( t
), info_( info
)
52 DISPATCHIMPL( PathSlider2D
);
54 Lang::PathSlider2D::~PathSlider2D( )
57 RefCountPtr
< const Lang::Class
> Lang::PathSlider2D::TypeID( new Lang::SystemFinalClass( strrefdup( "PathSlider2D" ) ) );
58 TYPEINFOIMPL( PathSlider2D
);
60 Kernel::VariableHandle
61 Lang::PathSlider2D::getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const
63 if( strcmp( fieldID
, "p" ) == 0 )
65 return Kernel::VariableHandle( new Kernel::Variable( point( ) ) );
67 if( strcmp( fieldID
, "v" ) == 0 )
69 return Kernel::VariableHandle( new Kernel::Variable( speed( ) ) );
71 if( strcmp( fieldID
, "rv" ) == 0 )
73 return Kernel::VariableHandle( new Kernel::Variable( reverse_speed( ) ) );
75 if( strcmp( fieldID
, "T" ) == 0 )
77 return Kernel::VariableHandle( new Kernel::Variable( direction( ) ) );
79 if( strcmp( fieldID
, "rT" ) == 0 )
81 return Kernel::VariableHandle( new Kernel::Variable( reverse_direction( ) ) );
83 if( strcmp( fieldID
, "N" ) == 0 )
85 return Kernel::VariableHandle( new Kernel::Variable( normal( ) ) );
87 if( strcmp( fieldID
, "rN" ) == 0 )
89 return Kernel::VariableHandle( new Kernel::Variable( reverse_normal( ) ) );
91 if( strcmp( fieldID
, "ik" ) == 0 )
93 return Kernel::VariableHandle( new Kernel::Variable( radiusOfCurvature( ) ) );
95 if( strcmp( fieldID
, "rik" ) == 0 )
97 return Kernel::VariableHandle( new Kernel::Variable( reverse_radiusOfCurvature( ) ) );
99 if( strcmp( fieldID
, "time" ) == 0 )
101 return Kernel::VariableHandle( new Kernel::Variable( time( ) ) );
103 if( strcmp( fieldID
, "length" ) == 0 )
105 return Kernel::VariableHandle( new Kernel::Variable( length( ) ) );
107 if( strcmp( fieldID
, "past" ) == 0 )
111 return Kernel::THE_TRUE_VARIABLE
;
113 return Kernel::THE_FALSE_VARIABLE
;
115 if( strcmp( fieldID
, "looped" ) == 0 )
117 if( t_
.t( ) > Concrete::Time( path_
->duration( ) ) ||
118 t_
.t( ) < Concrete::Time( 0 ) )
120 return Kernel::THE_TRUE_VARIABLE
;
122 return Kernel::THE_FALSE_VARIABLE
;
124 if( strcmp( fieldID
, "mod" ) == 0 )
126 return Helpers::newValHandle( new Lang::PathSlider2D( path_
, modPhysical( t_
.t( ), Concrete::Time( path_
->duration( ) ) ) ) );
128 if( strcmp( fieldID
, "info" ) == 0 )
132 throw Exceptions::NonExistentMember( getTypeName( ), fieldID
);
135 RefCountPtr
< Lang::PathSlider2D
>
136 Lang::PathSlider2D::move_time( const Concrete::Time delta
) const
138 Concrete::Time newTime
= t_
.t( ) + delta
;
139 if( path_
->isClosed( ) )
141 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, newTime
) );
143 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
,
144 Concrete::SplineTime( newTime
,
145 Concrete::Time( 0 ) <= newTime
&&
146 newTime
<= Concrete::Time( path_
->duration( ) ) ) ) );
149 RefCountPtr
< Lang::PathSlider2D
>
150 Lang::PathSlider2D::move_length( const Concrete::Length delta
) const
152 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, path_
->arcTime( delta
, t_
.t( ) ) ) );
155 RefCountPtr
< Lang::PathSlider2D
>
156 Lang::PathSlider2D::seek_time( const Concrete::Time newTime
) const
158 if( path_
->isClosed( ) )
160 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, newTime
) );
162 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
,
163 Concrete::SplineTime( newTime
,
164 Concrete::Time( 0 ) <= newTime
&&
165 newTime
<= Concrete::Time( path_
->duration( ) ) ) ) );
168 RefCountPtr
< Lang::PathSlider2D
>
169 Lang::PathSlider2D::seek_start( ) const
171 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, Concrete::ZERO_TIME
) );
174 RefCountPtr
< Lang::PathSlider2D
>
175 Lang::PathSlider2D::seek_end( ) const
177 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, Concrete::Time( path_
->duration( ) ) ) );
180 RefCountPtr
< Lang::PathSlider2D
>
181 Lang::PathSlider2D::seek_length( const Concrete::Length val
) const
183 return RefCountPtr
< Lang::PathSlider2D
>( new Lang::PathSlider2D( path_
, path_
->arcTime( val
) ) );
187 RefCountPtr
< const Lang::Coords2D
>
188 Lang::PathSlider2D::point( ) const
190 return path_
->point( t_
.t( ) );
193 RefCountPtr
< const Lang::Length
>
194 Lang::PathSlider2D::speed( ) const
196 return path_
->speed( t_
.t( ) );
199 RefCountPtr
< const Lang::Length
>
200 Lang::PathSlider2D::reverse_speed( ) const
202 return path_
->reverse_speed( t_
.t( ) );
205 RefCountPtr
< const Lang::FloatPair
>
206 Lang::PathSlider2D::direction( ) const
208 return path_
->direction( t_
.t( ) );
211 RefCountPtr
< const Lang::FloatPair
>
212 Lang::PathSlider2D::reverse_direction( ) const
214 return path_
->reverse_direction( t_
.t( ) );
217 RefCountPtr
< const Lang::FloatPair
>
218 Lang::PathSlider2D::normal( ) const
220 RefCountPtr
< const Lang::FloatPair
> tmp
= path_
->direction( t_
.t( ) );
221 return RefCountPtr
< const Lang::FloatPair
>( new Lang::FloatPair( -tmp
->y_
, tmp
->x_
) );
224 RefCountPtr
< const Lang::FloatPair
>
225 Lang::PathSlider2D::reverse_normal( ) const
227 RefCountPtr
< const Lang::FloatPair
> tmp
= path_
->reverse_direction( t_
.t( ) );
228 return RefCountPtr
< const Lang::FloatPair
>( new Lang::FloatPair( -tmp
->y_
, tmp
->x_
) );
231 RefCountPtr
< const Lang::Length
>
232 Lang::PathSlider2D::radiusOfCurvature( ) const
234 return path_
->radiusOfCurvature( t_
.t( ) );
237 RefCountPtr
< const Lang::Length
>
238 Lang::PathSlider2D::reverse_radiusOfCurvature( ) const
240 return path_
->reverse_radiusOfCurvature( t_
.t( ) );
243 RefCountPtr
< const Lang::Float
>
244 Lang::PathSlider2D::time( ) const
246 return RefCountPtr
< const Lang::Float
>( new Lang::Float( t_
.t( ).offtype
< 0, 1 >( ) ) );
249 RefCountPtr
< const Lang::Length
>
250 Lang::PathSlider2D::length( ) const
252 return RefCountPtr
< const Lang::Length
>( new Lang::Length( path_
->arcLength( t_
.t( ) ) ) );
257 Lang::PathSlider2D::show( std::ostream
& os
) const
259 os
<< "Path slider " ;
260 if( this->getRear( ) != NullPtr
< const Lang::Value
>( ) )
262 os
<< "(with rear) " ;
264 if( this->getFront( ) != NullPtr
< const Lang::Value
>( ) )
266 os
<< "(with front) " ;
268 os
<< "at " << t_
.t( ).offtype
< 0, 1 >( ) ;
273 os
<< " / " << path_
->duration( ) ;
277 Lang::PathSlider2D::gcMark( Kernel::GCMarkedSet
& marked
)
279 const_cast< Lang::ElementaryPath2D
* >( path_
.getPtr( ) )->gcMark( marked
);
283 RefCountPtr
< const Lang::Value
>
284 Lang::PathSlider2D::getRear( ) const
286 return RefCountPtr
< const Lang::Value
>( NullPtr
< const Lang::Value
>( ) );
289 RefCountPtr
< const Lang::Value
>
290 Lang::PathSlider2D::getFront( ) const
292 return RefCountPtr
< const Lang::Value
>( NullPtr
< const Lang::Value
>( ) );
296 Lang::PathSlider2D_rear::PathSlider2D_rear( const Lang::PathSlider2D
& orig
, const RefCountPtr
< const Lang::Value
> & rear
)
297 : PathSlider2D( orig
), rear_( rear
)
300 RefCountPtr
< const Lang::Value
>
301 Lang::PathSlider2D_rear::getRear( ) const
306 Lang::PathSlider2D_front::PathSlider2D_front( const Lang::PathSlider2D
& orig
, const RefCountPtr
< const Lang::Value
> & front
)
307 : PathSlider2D( orig
), front_( front
)
310 RefCountPtr
< const Lang::Value
>
311 Lang::PathSlider2D_front::getFront( ) const