• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kig

base_type.cc

Go to the documentation of this file.
00001 // Copyright (C)  2003  Dominique Devriese <devriese@kde.org>
00002 
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016 // 02110-1301, USA.
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  * as observed by domi: this object is actually movable also
00052  * if one point is FreelyTranslatable and the other is
00053  * only movable, but then the "move" itself requires some
00054  * trickery.
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 }

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal