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

kig

  • sources
  • kde-4.14
  • kdeedu
  • kig
  • objects
base_type.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
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.
7 
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.
12 
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., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "base_type.h"
19 
20 #include "point_imp.h"
21 #include "line_imp.h"
22 #include "bogus_imp.h"
23 #include "object_calcer.h"
24 
25 #include "../misc/common.h"
26 
27 ObjectABType::ObjectABType( const char* fulltypename, const ArgsParser::spec* spec, int n )
28  : ArgsParserObjectType( fulltypename, spec, n )
29 {
30 }
31 
32 ObjectABType::~ObjectABType()
33 {
34 }
35 
36 ObjectImp* ObjectABType::calc( const Args& parents, const KigDocument& ) const
37 {
38  if ( ! margsparser.checkArgs( parents ) )
39  return new InvalidImp;
40 
41  Coordinate a = static_cast<const PointImp*>( parents[0] )->coordinate();
42  Coordinate b = static_cast<const PointImp*>( parents[1] )->coordinate();
43 
44  return calcx( a, b );
45 }
46 
47 bool ObjectABType::canMove( const ObjectTypeCalcer& o ) const
48 {
49  return isFreelyTranslatable( o );
50 /*
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
54  * trickery.
55  */
56 }
57 
58 bool ObjectABType::isFreelyTranslatable( const ObjectTypeCalcer& o ) const
59 {
60  std::vector<ObjectCalcer*> parents = o.parents();
61  return parents[0]->isFreelyTranslatable() && parents[1]->isFreelyTranslatable();
62 }
63 
64 void ObjectABType::move( ObjectTypeCalcer& o, const Coordinate& to,
65  const KigDocument& d ) const
66 {
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 );
76 }
77 
78 ObjectLPType::ObjectLPType( const char* fullname, const ArgsParser::spec* spec, int n )
79  : ArgsParserObjectType( fullname, spec, n )
80 {
81 }
82 
83 ObjectLPType::~ObjectLPType()
84 {
85 }
86 
87 ObjectImp* ObjectLPType::calc( const Args& args, const KigDocument& ) const
88 {
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();
92  return calc( l, c );
93 }
94 
95 const Coordinate ObjectABType::moveReferencePoint( const ObjectTypeCalcer& o ) const
96 {
97  std::vector<ObjectCalcer*> parents = o.parents();
98  assert( margsparser.checkArgs( parents ) );
99  return static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
100 }
101 
102 std::vector<ObjectCalcer*> ObjectABType::movableParents( const ObjectTypeCalcer& ourobj ) const
103 {
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() );
112 }
ObjectABType::move
void move(ObjectTypeCalcer &o, const Coordinate &to, const KigDocument &d) const
Definition: base_type.cc:64
point_imp.h
ArgsParserObjectType
This is a convenience subclass of ObjectType that a type should inherit from if its parents can be sp...
Definition: object_type.h:113
AbstractLineImp
An ObjectImp class that is the base of the line-like ObjectImp's: SegmentImp, LineImp and RayImp...
Definition: line_imp.h:31
LineData
Simple class representing a line.
Definition: misc/common.h:49
ObjectABType::movableParents
std::vector< ObjectCalcer * > movableParents(const ObjectTypeCalcer &ourobj) const
Definition: base_type.cc:102
ObjectABType::ObjectABType
ObjectABType(const char *fulltypename, const ArgsParser::spec *argsspec, int n)
Definition: base_type.cc:27
ObjectABType::moveReferencePoint
const Coordinate moveReferencePoint(const ObjectTypeCalcer &o) const
Definition: base_type.cc:95
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
ArgsParserObjectType::margsparser
const ArgsParser margsparser
Definition: object_type.h:117
ObjectLPType::~ObjectLPType
~ObjectLPType()
Definition: base_type.cc:83
bogus_imp.h
ObjectABType::isFreelyTranslatable
bool isFreelyTranslatable(const ObjectTypeCalcer &o) const
Definition: base_type.cc:58
ObjectLPType::ObjectLPType
ObjectLPType(const char *fullname, const ArgsParser::spec *spec, int n)
Definition: base_type.cc:78
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
ObjectABType::~ObjectABType
~ObjectABType()
Definition: base_type.cc:32
ArgsParser::checkArgs
bool checkArgs(const std::vector< ObjectCalcer * > &os) const
Definition: argsparser.cpp:222
ArgsParser::spec
Definition: argsparser.h:113
object_calcer.h
line_imp.h
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
ObjectTypeCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:105
ObjectABType::canMove
bool canMove(const ObjectTypeCalcer &o) const
Definition: base_type.cc:47
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
base_type.h
ObjectABType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: base_type.cc:36
ObjectABType::calcx
virtual ObjectImp * calcx(const Coordinate &a, const Coordinate &b) const =0
ObjectLPType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: base_type.cc:87
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal