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 "base_type.h"
20 #include "point_imp.h"
22 #include "bogus_imp.h"
23 #include "object_calcer.h"
25 #include "../misc/common.h"
27 ObjectABType::ObjectABType( const char* fulltypename
, const ArgsParser::spec
* spec
, int n
)
28 : ArgsParserObjectType( fulltypename
, spec
, n
)
32 ObjectABType::~ObjectABType()
36 ObjectImp
* ObjectABType::calc( const Args
& parents
, const KigDocument
& ) const
38 if ( ! margsparser
.checkArgs( parents
) )
39 return new InvalidImp
;
41 Coordinate a
= static_cast<const PointImp
*>( parents
[0] )->coordinate();
42 Coordinate b
= static_cast<const PointImp
*>( parents
[1] )->coordinate();
47 bool ObjectABType::canMove( const ObjectTypeCalcer
& o
) const
49 return isFreelyTranslatable( o
);
51 * as observed by domi: this object is actually movable also
52 * if one point is FreelyTranslatable and the other is
53 * only movable, but then the "move" itself requires some
58 bool ObjectABType::isFreelyTranslatable( const ObjectTypeCalcer
& o
) const
60 std::vector
<ObjectCalcer
*> parents
= o
.parents();
61 return parents
[0]->isFreelyTranslatable() && parents
[1]->isFreelyTranslatable();
64 void ObjectABType::move( ObjectTypeCalcer
& o
, const Coordinate
& to
,
65 const KigDocument
& d
) const
67 std::vector
<ObjectCalcer
*> parents
= o
.parents();
68 assert( margsparser
.checkArgs( parents
) );
69 const Coordinate a
= static_cast<const PointImp
*>( parents
[0]->imp() )->coordinate();
70 const Coordinate b
= static_cast<const PointImp
*>( parents
[1]->imp() )->coordinate();
71 const Coordinate dist
= b
- a
;
72 if ( parents
[0]->canMove() )
73 parents
[0]->move( to
, d
);
74 if ( parents
[1]->canMove() )
75 parents
[1]->move( to
+ dist
, d
);
78 ObjectLPType::ObjectLPType( const char* fullname
, const ArgsParser::spec
* spec
, int n
)
79 : ArgsParserObjectType( fullname
, spec
, n
)
83 ObjectLPType::~ObjectLPType()
87 ObjectImp
* ObjectLPType::calc( const Args
& args
, const KigDocument
& ) const
89 if ( ! margsparser
.checkArgs( args
) ) return new InvalidImp
;
90 LineData l
= static_cast<const AbstractLineImp
*>( args
[0] )->data();
91 Coordinate c
= static_cast<const PointImp
*>( args
[1] )->coordinate();
95 const Coordinate
ObjectABType::moveReferencePoint( const ObjectTypeCalcer
& o
) const
97 std::vector
<ObjectCalcer
*> parents
= o
.parents();
98 assert( margsparser
.checkArgs( parents
) );
99 return static_cast<const PointImp
*>( parents
[0]->imp() )->coordinate();
102 std::vector
<ObjectCalcer
*> ObjectABType::movableParents( const ObjectTypeCalcer
& ourobj
) const
104 std::vector
<ObjectCalcer
*> parents
= ourobj
.parents();
105 std::set
<ObjectCalcer
*> ret
;
106 std::vector
<ObjectCalcer
*> tmp
= parents
[0]->movableParents();
107 ret
.insert( tmp
.begin(), tmp
.end() );
108 tmp
= parents
[1]->movableParents();
109 ret
.insert( tmp
.begin(), tmp
.end() );
110 ret
.insert( parents
.begin(), parents
.end() );
111 return std::vector
<ObjectCalcer
*>( ret
.begin(), ret
.end() );