kig
base_type.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "base_type.h"
00019
00020 #include "point_imp.h"
00021 #include "line_imp.h"
00022 #include "bogus_imp.h"
00023 #include "object_calcer.h"
00024
00025 #include "../misc/common.h"
00026
00027 ObjectABType::ObjectABType( const char* fulltypename, const ArgsParser::spec* spec, int n )
00028 : ArgsParserObjectType( fulltypename, spec, n )
00029 {
00030 }
00031
00032 ObjectABType::~ObjectABType()
00033 {
00034 }
00035
00036 ObjectImp* ObjectABType::calc( const Args& parents, const KigDocument& ) const
00037 {
00038 if ( ! margsparser.checkArgs( parents ) )
00039 return new InvalidImp;
00040
00041 Coordinate a = static_cast<const PointImp*>( parents[0] )->coordinate();
00042 Coordinate b = static_cast<const PointImp*>( parents[1] )->coordinate();
00043
00044 return calc( a, b );
00045 }
00046
00047 bool ObjectABType::canMove( const ObjectTypeCalcer& o ) const
00048 {
00049 return isFreelyTranslatable( o );
00050
00051
00052
00053
00054
00055
00056 }
00057
00058 bool ObjectABType::isFreelyTranslatable( const ObjectTypeCalcer& o ) const
00059 {
00060 std::vector<ObjectCalcer*> parents = o.parents();
00061 return parents[0]->isFreelyTranslatable() && parents[1]->isFreelyTranslatable();
00062 }
00063
00064 void ObjectABType::move( ObjectTypeCalcer& o, const Coordinate& to,
00065 const KigDocument& d ) const
00066 {
00067 std::vector<ObjectCalcer*> parents = o.parents();
00068 assert( margsparser.checkArgs( parents ) );
00069 const Coordinate a = static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
00070 const Coordinate b = static_cast<const PointImp*>( parents[1]->imp() )->coordinate();
00071 const Coordinate dist = b - a;
00072 if ( parents[0]->canMove() )
00073 parents[0]->move( to, d );
00074 if ( parents[1]->canMove() )
00075 parents[1]->move( to + dist, d );
00076 }
00077
00078 ObjectLPType::ObjectLPType( const char* fullname, const ArgsParser::spec* spec, int n )
00079 : ArgsParserObjectType( fullname, spec, n )
00080 {
00081 }
00082
00083 ObjectLPType::~ObjectLPType()
00084 {
00085 }
00086
00087 ObjectImp* ObjectLPType::calc( const Args& args, const KigDocument& ) const
00088 {
00089 if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
00090 LineData l = static_cast<const AbstractLineImp*>( args[0] )->data();
00091 Coordinate c = static_cast<const PointImp*>( args[1] )->coordinate();
00092 return calc( l, c );
00093 }
00094
00095 const Coordinate ObjectABType::moveReferencePoint( const ObjectTypeCalcer& o ) const
00096 {
00097 std::vector<ObjectCalcer*> parents = o.parents();
00098 assert( margsparser.checkArgs( parents ) );
00099 return static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
00100 }
00101
00102 std::vector<ObjectCalcer*> ObjectABType::movableParents( const ObjectTypeCalcer& ourobj ) const
00103 {
00104 std::vector<ObjectCalcer*> parents = ourobj.parents();
00105 std::set<ObjectCalcer*> ret;
00106 std::vector<ObjectCalcer*> tmp = parents[0]->movableParents();
00107 ret.insert( tmp.begin(), tmp.end() );
00108 tmp = parents[1]->movableParents();
00109 ret.insert( tmp.begin(), tmp.end() );
00110 ret.insert( parents.begin(), parents.end() );
00111 return std::vector<ObjectCalcer*>( ret.begin(), ret.end() );
00112 }