1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program 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 this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 #include "transform_types.h"
20 #include "bogus_imp.h"
21 #include "point_imp.h"
23 #include "other_imp.h"
24 #include "polygon_imp.h"
25 #include "../misc/coordinate.h"
26 #include "../misc/kigtransform.h"
30 static const ArgsParser::spec argsspecTranslation
[] =
32 { ObjectImp::stype(), I18N_NOOP("Translate this object"),
33 I18N_NOOP( "Select the object to translate..." ), false },
34 { VectorImp::stype(), I18N_NOOP("Translate by this vector"),
35 I18N_NOOP( "Select the vector to translate by..." ), false }
38 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( TranslatedType
)
40 TranslatedType::TranslatedType()
41 : ArgsParserObjectType( "Translation", argsspecTranslation
, 2 )
45 TranslatedType::~TranslatedType()
49 const TranslatedType
* TranslatedType::instance()
51 static const TranslatedType t
;
55 ObjectImp
* TranslatedType::calc( const Args
& args
, const KigDocument
& ) const
57 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
59 Coordinate dir
= static_cast<const VectorImp
*>( args
[1] )->dir();
60 Transformation t
= Transformation::translation( dir
);
62 return args
[0]->transform( t
);
65 static const ArgsParser::spec argsspecPointReflection
[] =
67 { ObjectImp::stype(), I18N_NOOP( "Reflect this object" ),
68 I18N_NOOP( "Select the object to reflect..." ), false },
69 { PointImp::stype(), I18N_NOOP( "Reflect in this point" ),
70 I18N_NOOP( "Select the point to reflect in..." ), false }
73 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( PointReflectionType
)
75 PointReflectionType::PointReflectionType()
76 : ArgsParserObjectType( "PointReflection", argsspecPointReflection
, 2 )
80 PointReflectionType::~PointReflectionType()
84 const PointReflectionType
* PointReflectionType::instance()
86 static const PointReflectionType t
;
90 ObjectImp
* PointReflectionType::calc( const Args
& args
, const KigDocument
& ) const
92 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
94 Coordinate center
= static_cast<const PointImp
*>( args
[1] )->coordinate();
95 Transformation t
= Transformation::pointReflection( center
);
97 return args
[0]->transform( t
);
100 static const ArgsParser::spec argsspecLineReflection
[] =
102 { ObjectImp::stype(), I18N_NOOP( "Reflect this object" ),
103 I18N_NOOP( "Select the object to reflect..." ), false },
104 { AbstractLineImp::stype(), I18N_NOOP( "Reflect in this line" ),
105 I18N_NOOP( "Select the line to reflect in..." ), false }
108 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineReflectionType
)
110 LineReflectionType::LineReflectionType()
111 : ArgsParserObjectType( "LineReflection", argsspecLineReflection
, 2 )
115 LineReflectionType::~LineReflectionType()
119 const LineReflectionType
* LineReflectionType::instance()
121 static const LineReflectionType t
;
125 ObjectImp
* LineReflectionType::calc( const Args
& args
, const KigDocument
& ) const
127 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
129 LineData d
= static_cast<const AbstractLineImp
*>( args
[1] )->data();
130 Transformation t
= Transformation::lineReflection( d
);
132 return args
[0]->transform( t
);
135 static const ArgsParser::spec argsspecRotation
[] =
137 { ObjectImp::stype(), I18N_NOOP( "Rotate this object" ),
138 I18N_NOOP( "Select the object to rotate..." ), false },
139 { PointImp::stype(), I18N_NOOP( "Rotate around this point" ),
140 I18N_NOOP( "Select the center point of the rotation..." ), false },
141 { AngleImp::stype(), I18N_NOOP( "Rotate by this angle" ),
142 I18N_NOOP( "Select the angle of the rotation..." ), false }
145 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( RotationType
)
147 RotationType::RotationType()
148 : ArgsParserObjectType( "Rotation", argsspecRotation
, 3 )
152 RotationType::~RotationType()
156 const RotationType
* RotationType::instance()
158 static const RotationType t
;
162 ObjectImp
* RotationType::calc( const Args
& args
, const KigDocument
& ) const
164 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
166 Coordinate center
= static_cast<const PointImp
*>( args
[1] )->coordinate();
167 double angle
= static_cast<const AngleImp
*>( args
[2] )->size();
169 return args
[0]->transform( Transformation::rotation( angle
, center
) );
172 static const ArgsParser::spec argsspecScalingOverCenter
[] =
174 { ObjectImp::stype(), I18N_NOOP( "Scale this object" ),
175 I18N_NOOP( "Select the object to scale..." ), false },
176 { PointImp::stype(), I18N_NOOP( "Scale with this center" ),
177 I18N_NOOP( "Select the center point of the scaling..." ), false },
178 { SegmentImp::stype(), I18N_NOOP( "Scale by the length of this segment" ),
179 I18N_NOOP( "Select a segment whose length is the factor of the scaling..." ), false }
182 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ScalingOverCenterType
)
184 ScalingOverCenterType::ScalingOverCenterType()
185 : ArgsParserObjectType( "ScalingOverCenter", argsspecScalingOverCenter
, 3 )
189 ScalingOverCenterType::~ScalingOverCenterType()
193 const ScalingOverCenterType
* ScalingOverCenterType::instance()
195 static const ScalingOverCenterType t
;
199 ObjectImp
* ScalingOverCenterType::calc( const Args
& args
, const KigDocument
& ) const
201 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
203 Coordinate center
= static_cast<const PointImp
*>( args
[1] )->coordinate();
204 double ratio
= static_cast<const SegmentImp
*>( args
[2] )->length();
206 return args
[0]->transform( Transformation::scalingOverPoint( ratio
, center
) );
209 static const ArgsParser::spec argsspecScalingOverCenter2
[] =
211 { ObjectImp::stype(), I18N_NOOP( "Scale this object" ),
212 I18N_NOOP( "Select the object to scale..." ), false },
213 { PointImp::stype(), I18N_NOOP( "Scale with this center" ),
214 I18N_NOOP( "Select the center point of the scaling..." ), false },
215 { SegmentImp::stype(), I18N_NOOP( "Scale the length of this segment..." ),
216 I18N_NOOP( "Select the first of two segments whose ratio is the factor of the scaling..." ), false },
217 { SegmentImp::stype(), I18N_NOOP( "...to the length of this other segment" ),
218 I18N_NOOP( "Select the second of two segments whose ratio is the factor of the scaling..." ), false }
221 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ScalingOverCenter2Type
)
223 ScalingOverCenter2Type::ScalingOverCenter2Type()
224 : ArgsParserObjectType( "ScalingOverCenter2", argsspecScalingOverCenter2
, 4 )
228 ScalingOverCenter2Type::~ScalingOverCenter2Type()
232 const ScalingOverCenter2Type
* ScalingOverCenter2Type::instance()
234 static const ScalingOverCenter2Type t
;
238 ObjectImp
* ScalingOverCenter2Type::calc( const Args
& args
, const KigDocument
& ) const
240 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
242 Coordinate center
= static_cast<const PointImp
*>( args
[1] )->coordinate();
243 double ratio
= static_cast<const SegmentImp
*>( args
[3] )->length()/
244 static_cast<const SegmentImp
*>( args
[2] )->length();
246 return args
[0]->transform( Transformation::scalingOverPoint( ratio
, center
) );
249 static const ArgsParser::spec argsspecScalingOverLine
[] =
251 { ObjectImp::stype(), I18N_NOOP( "Scale this object" ), I18N_NOOP( "Select the object to scale" ), false },
252 { AbstractLineImp::stype(), I18N_NOOP( "Scale over this line" ), I18N_NOOP( "Select the line to scale over" ), false },
253 { SegmentImp::stype(), I18N_NOOP( "Scale by the length of this segment" ), I18N_NOOP( "Select a segment whose length is the factor for the scaling" ), false }
256 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ScalingOverLineType
)
258 ScalingOverLineType::ScalingOverLineType()
259 : ArgsParserObjectType( "ScalingOverLine", argsspecScalingOverLine
, 3 )
263 ScalingOverLineType::~ScalingOverLineType()
267 const ScalingOverLineType
* ScalingOverLineType::instance()
269 static const ScalingOverLineType t
;
273 ObjectImp
* ScalingOverLineType::calc( const Args
& args
, const KigDocument
& ) const
275 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
277 LineData line
= static_cast<const AbstractLineImp
*>( args
[1] )->data();
278 double ratio
= static_cast<const SegmentImp
*>( args
[2] )->length();
280 return args
[0]->transform( Transformation::scalingOverLine( ratio
, line
) );
283 static const ArgsParser::spec argsspecScalingOverLine2
[] =
285 { ObjectImp::stype(), I18N_NOOP( "Scale this object" ), I18N_NOOP( "Select the object to scale" ), false },
286 { AbstractLineImp::stype(), I18N_NOOP( "Scale over this line" ), I18N_NOOP( "Select the line to scale over" ), false },
287 { SegmentImp::stype(), I18N_NOOP( "Scale the length of this segment..." ), I18N_NOOP( "Select the first of two segments whose ratio is the factor for the scaling" ), false },
288 { SegmentImp::stype(), I18N_NOOP( "...to the length of this segment" ), I18N_NOOP( "Select the second of two segments whose ratio is the factor for the scaling" ), false }
291 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ScalingOverLine2Type
)
293 ScalingOverLine2Type::ScalingOverLine2Type()
294 : ArgsParserObjectType( "ScalingOverLine2", argsspecScalingOverLine2
, 4 )
298 ScalingOverLine2Type::~ScalingOverLine2Type()
302 const ScalingOverLine2Type
* ScalingOverLine2Type::instance()
304 static const ScalingOverLine2Type t
;
308 ObjectImp
* ScalingOverLine2Type::calc( const Args
& args
, const KigDocument
& ) const
310 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
312 LineData line
= static_cast<const AbstractLineImp
*>( args
[1] )->data();
313 double ratio
= static_cast<const SegmentImp
*>( args
[3] )->length()/
314 static_cast<const SegmentImp
*>( args
[2] )->length();
316 return args
[0]->transform( Transformation::scalingOverLine( ratio
, line
) );
319 static const ArgsParser::spec argsspecProjectiveRotation
[] =
321 { ObjectImp::stype(), I18N_NOOP( "Projectively rotate this object" ), I18N_NOOP( "Select the object to rotate projectively" ), false },
322 { RayImp::stype(), I18N_NOOP( "Projectively rotate with this half-line" ), I18N_NOOP( "Select the half line of the projective rotation that you want to apply to the object" ), false },
323 { AngleImp::stype(), I18N_NOOP( "Projectively rotate by this angle" ), I18N_NOOP( "Select the angle of the projective rotation that you want to apply to the object" ), false }
326 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ProjectiveRotationType
)
328 ProjectiveRotationType::ProjectiveRotationType()
329 : ArgsParserObjectType( "ProjectiveRotation", argsspecProjectiveRotation
, 3 )
333 ProjectiveRotationType::~ProjectiveRotationType()
337 const ProjectiveRotationType
* ProjectiveRotationType::instance()
339 static const ProjectiveRotationType t
;
343 ObjectImp
* ProjectiveRotationType::calc( const Args
& args
, const KigDocument
& ) const
345 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
347 const RayImp
* ray
= static_cast<const RayImp
*>( args
[1] );
348 Coordinate c1
= ray
->data().a
;
349 Coordinate dir
= ray
->data().dir().normalize();
350 double alpha
= static_cast<const AngleImp
*>( args
[2] )->size();
352 return args
[0]->transform(
353 Transformation::projectiveRotation( alpha
, dir
, c1
) );
356 static const ArgsParser::spec argsspecHarmonicHomology
[] =
358 { ObjectImp::stype(), I18N_NOOP( "Harmonic Homology of this object" ),
359 I18N_NOOP( "Select the object to transform..." ), false },
360 { PointImp::stype(), I18N_NOOP( "Harmonic Homology with this center" ),
361 I18N_NOOP( "Select the center point of the harmonic homology..." ), false },
362 { AbstractLineImp::stype(), I18N_NOOP( "Harmonic Homology with this axis" ),
363 I18N_NOOP( "Select the axis of the harmonic homology..." ), false }
366 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( HarmonicHomologyType
)
368 HarmonicHomologyType::HarmonicHomologyType()
369 : ArgsParserObjectType( "HarmonicHomology", argsspecHarmonicHomology
, 3 )
373 HarmonicHomologyType::~HarmonicHomologyType()
377 const HarmonicHomologyType
* HarmonicHomologyType::instance()
379 static const HarmonicHomologyType t
;
383 ObjectImp
* HarmonicHomologyType::calc( const Args
& args
, const KigDocument
& ) const
385 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
387 Coordinate center
= static_cast<const PointImp
*>( args
[1] )->coordinate();
388 LineData axis
= static_cast<const AbstractLineImp
*>( args
[2] )->data();
389 return args
[0]->transform(
390 Transformation::harmonicHomology( center
, axis
) );
393 static const ArgsParser::spec argsspecAffinityB2Tr
[] =
395 { ObjectImp::stype(), I18N_NOOP( "Generic affinity of this object" ),
396 I18N_NOOP( "Select the object to transform..." ), false },
397 { PolygonImp::stype3(), I18N_NOOP( "Map this triangle" ),
398 I18N_NOOP( "Select the triangle that has to be transformed onto a given triangle..." ), false },
399 { PolygonImp::stype3(), I18N_NOOP( "onto this other triangle" ),
400 I18N_NOOP( "Select the triangle that is the image by the affinity of the first triangle..." ), false }
403 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AffinityB2TrType
)
405 AffinityB2TrType::AffinityB2TrType()
406 : ArgsParserObjectType( "AffinityB2Tr", argsspecAffinityB2Tr
, 3 )
410 AffinityB2TrType::~AffinityB2TrType()
414 const AffinityB2TrType
* AffinityB2TrType::instance()
416 static const AffinityB2TrType t
;
420 ObjectImp
* AffinityB2TrType::calc( const Args
& args
, const KigDocument
& ) const
422 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
424 std::vector
<Coordinate
> frompoints
= static_cast<const PolygonImp
*>( args
[1] )->points();
425 std::vector
<Coordinate
> topoints
= static_cast<const PolygonImp
*>( args
[2] )->points();
428 Transformation t
= Transformation::affinityGI3P( frompoints
, topoints
,
431 if (valid
== false) return new InvalidImp
;
432 return args
[0]->transform( t
);
435 static const ArgsParser::spec argsspecAffinityGI3P
[] =
437 { ObjectImp::stype(), I18N_NOOP( "Generic affinity of this object" ),
438 I18N_NOOP( "Select the object to transform..." ), false },
439 { PointImp::stype(), I18N_NOOP( "First of 3 starting points" ),
440 I18N_NOOP( "Select the first of the three starting points of the generic affinity..." ), false },
441 { PointImp::stype(), I18N_NOOP( "Second of 3 starting points" ),
442 I18N_NOOP( "Select the second of the three starting points of the generic affinity..." ), false },
443 { PointImp::stype(), I18N_NOOP( "Third of 3 starting points" ),
444 I18N_NOOP( "Select the third of the three starting points of the generic affinity..." ), false },
445 { PointImp::stype(), I18N_NOOP( "Transformed position of first point" ),
446 I18N_NOOP( "Select the first of the three end points of the generic affinity..." ), false },
447 { PointImp::stype(), I18N_NOOP( "Transformed position of second point" ),
448 I18N_NOOP( "Select the second of the three end points of the generic affinity..." ), false },
449 { PointImp::stype(), I18N_NOOP( "Transformed position of third point" ),
450 I18N_NOOP( "Select the third of the three end points of the generic affinity..." ), false },
453 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AffinityGI3PType
)
455 AffinityGI3PType::AffinityGI3PType()
456 : ArgsParserObjectType( "AffinityGI3P", argsspecAffinityGI3P
, 7 )
460 AffinityGI3PType::~AffinityGI3PType()
464 const AffinityGI3PType
* AffinityGI3PType::instance()
466 static const AffinityGI3PType t
;
470 ObjectImp
* AffinityGI3PType::calc( const Args
& args
, const KigDocument
& ) const
472 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
474 std::vector
<Coordinate
> frompoints
;
475 std::vector
<Coordinate
> topoints
;
476 for ( uint i
= 0; i
< 3; ++i
)
478 frompoints
.push_back(
479 static_cast<const PointImp
*>( args
[i
+1] )->coordinate() );
481 static_cast<const PointImp
*>( args
[i
+4] )->coordinate() );
485 Transformation t
= Transformation::affinityGI3P( frompoints
, topoints
,
488 if (valid
== false) return new InvalidImp
;
489 return args
[0]->transform( t
);
492 static const ArgsParser::spec argsspecProjectivityB2Qu
[] =
494 { ObjectImp::stype(), I18N_NOOP( "Generic projective transformation of this object" ),
495 I18N_NOOP( "Select the object to transform..." ), false },
496 { PolygonImp::stype4(), I18N_NOOP( "Map this quadrilateral" ),
497 I18N_NOOP( "Select the quadrilateral that has to be transformed onto a given quadrilateral..." ), false },
498 { PolygonImp::stype4(), I18N_NOOP( "onto this other quadrilateral" ),
499 I18N_NOOP( "Select the quadrilateral that is the image by the projective transformation of the first quadrilateral..." ), false }
502 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ProjectivityB2QuType
)
504 ProjectivityB2QuType::ProjectivityB2QuType()
505 : ArgsParserObjectType( "ProjectivityB2Qu", argsspecProjectivityB2Qu
, 3 )
509 ProjectivityB2QuType::~ProjectivityB2QuType()
513 const ProjectivityB2QuType
* ProjectivityB2QuType::instance()
515 static const ProjectivityB2QuType t
;
519 ObjectImp
* ProjectivityB2QuType::calc( const Args
& args
, const KigDocument
& ) const
521 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
523 std::vector
<Coordinate
> frompoints
= static_cast<const PolygonImp
*>( args
[1] )->points();
524 std::vector
<Coordinate
> topoints
= static_cast<const PolygonImp
*>( args
[2] )->points();
527 Transformation t
= Transformation::projectivityGI4P( frompoints
, topoints
,
530 if (valid
== false) return new InvalidImp
;
531 return args
[0]->transform( t
);
534 static const ArgsParser::spec argsspecProjectivityGI4P
[] =
536 { ObjectImp::stype(), I18N_NOOP( "Generic projective transformation of this object" ),
537 I18N_NOOP( "Select the object to transform..." ), false },
538 { PointImp::stype(), I18N_NOOP( "First of 4 starting points" ),
539 I18N_NOOP( "Select the first of the four starting points of the generic projectivity..." ), false },
540 { PointImp::stype(), I18N_NOOP( "Second of 4 starting points" ),
541 I18N_NOOP( "Select the second of the four starting points of the generic projectivity..." ), false },
542 { PointImp::stype(), I18N_NOOP( "Third of 4 starting points" ),
543 I18N_NOOP( "Select the third of the four starting points of the generic projectivity..." ), false },
544 { PointImp::stype(), I18N_NOOP( "Fourth of 4 starting points" ),
545 I18N_NOOP( "Select the fourth of the four starting points of the generic projectivity..." ), false },
546 { PointImp::stype(), I18N_NOOP( "Transformed position of first point" ),
547 I18N_NOOP( "Select the first of the four end points of the generic projectivity..." ), false },
548 { PointImp::stype(), I18N_NOOP( "Transformed position of second point" ),
549 I18N_NOOP( "Select the second of the four end points of the generic projectivity..." ), false },
550 { PointImp::stype(), I18N_NOOP( "Transformed position of third point" ),
551 I18N_NOOP( "Select the third of the four end points of the generic projectivity..." ), false },
552 { PointImp::stype(), I18N_NOOP( "Transformed position of fourth point" ),
553 I18N_NOOP( "Select the fourth of the four end points of the generic projectivity..." ), false }
556 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ProjectivityGI4PType
)
558 ProjectivityGI4PType::ProjectivityGI4PType()
559 : ArgsParserObjectType( "ProjectivityGI4P", argsspecProjectivityGI4P
, 9 )
563 ProjectivityGI4PType::~ProjectivityGI4PType()
567 const ProjectivityGI4PType
* ProjectivityGI4PType::instance()
569 static const ProjectivityGI4PType t
;
573 ObjectImp
* ProjectivityGI4PType::calc( const Args
& args
, const KigDocument
& ) const
575 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
577 std::vector
<Coordinate
> frompoints
;
578 std::vector
<Coordinate
> topoints
;
579 for ( uint i
= 0; i
< 4; ++i
)
581 frompoints
.push_back(
582 static_cast<const PointImp
*>( args
[i
+1] )->coordinate() );
584 static_cast<const PointImp
*>( args
[i
+5] )->coordinate() );
588 Transformation t
= Transformation::projectivityGI4P( frompoints
, topoints
,
591 if (valid
== false) return new InvalidImp
;
592 return args
[0]->transform( t
);
595 static const ArgsParser::spec argsspecCastShadow
[] =
597 { ObjectImp::stype(), I18N_NOOP( "Cast the shadow of this object" ),
598 I18N_NOOP( "Select the object of which you want to construct the shadow..." ), false },
599 { PointImp::stype(), I18N_NOOP( "Cast a shadow from this light source" ),
600 I18N_NOOP( "Select the light source from which the shadow should originate..." ), false },
601 { AbstractLineImp::stype(),
602 I18N_NOOP( "Cast a shadow on the horizon represented by this line" ),
603 I18N_NOOP( "Select the horizon for the shadow..." ), false }
606 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( CastShadowType
)
608 CastShadowType::CastShadowType()
609 : ArgsParserObjectType( "CastShadow", argsspecCastShadow
, 3 )
613 CastShadowType::~CastShadowType()
617 const CastShadowType
* CastShadowType::instance()
619 static const CastShadowType t
;
623 ObjectImp
* CastShadowType::calc( const Args
& args
, const KigDocument
& ) const
625 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
627 Coordinate lightsrc
= static_cast<const PointImp
*>( args
[1] )->coordinate();
628 LineData d
= static_cast<const AbstractLineImp
*>( args
[2] )->data();
629 return args
[0]->transform(
630 Transformation::castShadow( lightsrc
, d
) );
633 const ObjectImpType
* TranslatedType::resultId() const
635 return ObjectImp::stype();
638 const ObjectImpType
* PointReflectionType::resultId() const
640 return ObjectImp::stype();
643 const ObjectImpType
* LineReflectionType::resultId() const
645 return ObjectImp::stype();
648 const ObjectImpType
* RotationType::resultId() const
650 return ObjectImp::stype();
653 const ObjectImpType
* ScalingOverCenterType::resultId() const
655 return ObjectImp::stype();
658 const ObjectImpType
* ScalingOverCenter2Type::resultId() const
660 return ObjectImp::stype();
663 const ObjectImpType
* ScalingOverLineType::resultId() const
665 return ObjectImp::stype();
668 const ObjectImpType
* ScalingOverLine2Type::resultId() const
670 return ObjectImp::stype();
673 const ObjectImpType
* ProjectiveRotationType::resultId() const
675 return ObjectImp::stype();
678 const ObjectImpType
* HarmonicHomologyType::resultId() const
680 return ObjectImp::stype();
683 const ObjectImpType
* AffinityB2TrType::resultId() const
685 return ObjectImp::stype();
688 const ObjectImpType
* AffinityGI3PType::resultId() const
690 return ObjectImp::stype();
693 const ObjectImpType
* ProjectivityB2QuType::resultId() const
695 return ObjectImp::stype();
698 const ObjectImpType
* ProjectivityGI4PType::resultId() const
700 return ObjectImp::stype();
703 const ObjectImpType
* CastShadowType::resultId() const
705 return ObjectImp::stype();
708 bool TranslatedType::isTransform() const
713 bool PointReflectionType::isTransform() const
718 bool LineReflectionType::isTransform() const
723 bool RotationType::isTransform() const
728 bool ScalingOverCenterType::isTransform() const
733 bool ScalingOverCenter2Type::isTransform() const
738 bool ScalingOverLineType::isTransform() const
743 bool ScalingOverLine2Type::isTransform() const
748 bool ProjectiveRotationType::isTransform() const
753 bool HarmonicHomologyType::isTransform() const
758 bool AffinityB2TrType::isTransform() const
763 bool AffinityGI3PType::isTransform() const
768 bool ProjectivityB2QuType::isTransform() const
773 bool ProjectivityGI4PType::isTransform() const
778 bool CastShadowType::isTransform() const
783 static const ArgsParser::spec argsspecApplyTransformation
[] =
785 { ObjectImp::stype(), I18N_NOOP( "Transform this object" ), "SHOULD NOT BE SEEN", false },
786 { TransformationImp::stype(), I18N_NOOP( "Transform using this transformation" ), "SHOULD NOT BE SEEN", false }
789 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( ApplyTransformationObjectType
)
791 ApplyTransformationObjectType::ApplyTransformationObjectType()
792 : ArgsParserObjectType( "ApplyTransformation", argsspecApplyTransformation
, 2 )
796 ApplyTransformationObjectType::~ApplyTransformationObjectType()
800 const ApplyTransformationObjectType
* ApplyTransformationObjectType::instance()
802 static const ApplyTransformationObjectType t
;
806 ObjectImp
* ApplyTransformationObjectType::calc( const Args
& args
, const KigDocument
& ) const
808 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
809 return args
[0]->transform( static_cast<const TransformationImp
*>( args
[1] )->data() );
812 const ObjectImpType
* ApplyTransformationObjectType::resultId() const
814 return ObjectImp::stype();
817 bool ApplyTransformationObjectType::isTransform() const
822 bool SimilitudeType::isTransform() const
827 const ObjectImpType
* SimilitudeType::resultId() const
829 return ObjectImp::stype();
832 const SimilitudeType
* SimilitudeType::instance()
834 static const SimilitudeType t
;
838 ObjectImp
* SimilitudeType::calc( const Args
& args
, const KigDocument
& ) const
840 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
842 Coordinate c
= static_cast<const PointImp
*>( args
[1] )->coordinate();
843 Coordinate a
= static_cast<const PointImp
*>( args
[2] )->coordinate();
844 Coordinate b
= static_cast<const PointImp
*>( args
[3] )->coordinate();
847 double factor
= sqrt( b
.squareLength()/a
.squareLength() );
848 double theta
= atan2( b
.y
, b
.x
) - atan2( a
.y
, a
.x
);
850 return args
[0]->transform( Transformation::similitude( c
, theta
, factor
) );
853 SimilitudeType::~SimilitudeType()
857 static const ArgsParser::spec argsspecSimilitude
[] =
859 { ObjectImp::stype(), I18N_NOOP( "Apply a similitude to this object" ),
860 I18N_NOOP( "Select the object to transform..." ), false },
861 { PointImp::stype(), I18N_NOOP( "Apply a similitude with this center" ),
862 I18N_NOOP( "Select the center for the similitude..." ), false },
863 { PointImp::stype(), I18N_NOOP( "Apply a similitude mapping this point onto another point" ),
864 I18N_NOOP( "Select the point which the similitude should map onto another point..." ), false },
865 { PointImp::stype(), I18N_NOOP( "Apply a similitude mapping a point onto this point" ),
866 I18N_NOOP( "Select the point onto which the similitude should map the first point..." ), false }
869 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( SimilitudeType
)
871 SimilitudeType::SimilitudeType()
872 : ArgsParserObjectType( "Similitude", argsspecSimilitude
, 4 )