• 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
other_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 "other_type.h"
19 
20 #include "bogus_imp.h"
21 #include "point_imp.h"
22 #include "locus_imp.h"
23 
24 #include "../misc/common.h"
25 #include "../misc/calcpaths.h"
26 #include "../misc/goniometry.h"
27 #include "../kig/kig_part.h"
28 #include "../kig/kig_view.h"
29 #include "../kig/kig_commands.h"
30 
31 #include <functional>
32 #include <algorithm>
33 #include <cmath>
34 #include <iterator>
35 
36 using std::find;
37 
38 static const struct ArgsParser::spec argsspecLocus[] =
39 {
40  { HierarchyImp::stype(), "hierarchy", "SHOULD NOT BE SEEN", false },
41  { CurveImp::stype(), "curve", "SHOULD NOT BE SEEN", false }
42 };
43 
44 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LocusType )
45 
46 LocusType::LocusType()
47  : ArgsParserObjectType( "Locus", argsspecLocus, 2 )
48 {
49 }
50 
51 LocusType::~LocusType()
52 {
53 }
54 
55 ObjectImp* LocusType::calc( const Args& args, const KigDocument& ) const
56 {
57  using namespace std;
58 
59  assert( args.size() >= 2 );
60  const Args firsttwo( args.begin(), args.begin() + 2 );
61  Args fixedargs( args.begin() + 2, args.end() );
62 
63  if ( ! margsparser.checkArgs( firsttwo ) ) return new InvalidImp;
64  for ( Args::iterator i = fixedargs.begin(); i != fixedargs.end(); ++i )
65  if ( ! (*i)->valid() )
66  return new InvalidImp;
67 
68  const ObjectHierarchy& hier =
69  static_cast<const HierarchyImp*>( args[0] )->data();
70  const CurveImp* curveimp = static_cast<const CurveImp*>( args[1] );
71 
72  return new LocusImp( curveimp->copy(), hier.withFixedArgs( fixedargs ) );
73 }
74 
75 bool LocusType::inherits( int type ) const
76 {
77  return type == ID_LocusType ? true : Parent::inherits( type );
78 }
79 
80 const ObjectImpType* LocusType::resultId() const
81 {
82  return LocusImp::stype();
83 }
84 
85 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( CopyObjectType )
86 
87 CopyObjectType::CopyObjectType()
88  : ObjectType( "Copy" )
89 {
90 }
91 
92 CopyObjectType::~CopyObjectType()
93 {
94 }
95 
96 CopyObjectType* CopyObjectType::instance()
97 {
98  static CopyObjectType t;
99  return &t;
100 }
101 
102 bool CopyObjectType::inherits( int ) const
103 {
104  return false;
105 }
106 
107 ObjectImp* CopyObjectType::calc( const Args& parents, const KigDocument& ) const
108 {
109  assert( parents.size() == 1 );
110  return parents[0]->copy();
111 }
112 
113 const ObjectImpType* CopyObjectType::impRequirement( const ObjectImp*, const Args& ) const
114 {
115  return ObjectImp::stype();
116 }
117 
118 const ObjectImpType* CopyObjectType::resultId() const
119 {
120  // we don't know what we return..
121  return ObjectImp::stype();
122 }
123 
124 const ObjectImpType* LocusType::impRequirement( const ObjectImp* o, const Args& parents ) const
125 {
126  assert( parents.size() >= 2 );
127  Args firsttwo( parents.begin(), parents.begin() + 2 );
128  if ( o == parents[0] || o == parents[1] )
129  return margsparser.impRequirement( o, firsttwo );
130  else
131  {
132  const HierarchyImp* h = dynamic_cast<const HierarchyImp*>( parents[0] );
133  if ( h )
134  {
135  PointImp* p = new PointImp( Coordinate() );
136  Args hargs( parents.begin()+ 2, parents.end() );
137  hargs.push_back( p );
138  ArgsParser hparser = h->data().argParser();
139  const ObjectImpType* ret = hparser.impRequirement( o, hargs );
140  delete p;
141  return ret;
142  }
143  else
144  return ObjectImp::stype();
145  };
146 }
147 
148 const LocusType* LocusType::instance()
149 {
150  static const LocusType t;
151  return &t;
152 }
153 
154 std::vector<ObjectCalcer*> CopyObjectType::sortArgs( const std::vector<ObjectCalcer*>& os ) const
155 {
156  assert( os.size() == 1 );
157  return os;
158 }
159 
160 std::vector<ObjectCalcer*> LocusType::sortArgs( const std::vector<ObjectCalcer*>& args ) const
161 {
162  assert( args.size() >= 2 );
163  std::vector<ObjectCalcer*> firsttwo( args.begin(), args.begin() + 2 );
164  firsttwo = margsparser.parse( firsttwo );
165  std::copy( args.begin() + 2, args.end(), std::back_inserter( firsttwo ) );
166  return firsttwo;
167 }
168 
169 Args LocusType::sortArgs( const Args& args ) const
170 {
171  assert( args.size() >= 2 );
172  Args firsttwo( args.begin(), args.begin() + 2 );
173  firsttwo = margsparser.parse( firsttwo );
174  std::copy( args.begin() + 2, args.end(), std::back_inserter( firsttwo ) );
175  return firsttwo;
176 }
177 
178 Args CopyObjectType::sortArgs( const Args& args ) const
179 {
180  assert( args.size() == 1 );
181  return args;
182 }
183 
184 bool CopyObjectType::isDefinedOnOrThrough( const ObjectImp*, const Args& ) const
185 {
186  // TODO: vragen aan parent ?
187  // TODO: translate the above TODO ?
188  return false;
189 }
190 
HierarchyImp::stype
static const ObjectImpType * stype()
Definition: bogus_imp.cc:227
locus_imp.h
LocusImp
LocusImp is an imp that consists of a copy of the curveimp that the moving point moves over...
Definition: locus_imp.h:57
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
ObjectHierarchy
Definition: object_hierarchy.h:30
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(SegmentAxisType)
CopyObjectType::sortArgs
std::vector< ObjectCalcer * > sortArgs(const std::vector< ObjectCalcer * > &os) const
Definition: other_type.cc:154
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
ObjectType::inherits
virtual bool inherits(int type) const
Definition: object_type.cc:64
CopyObjectType::instance
static CopyObjectType * instance()
Definition: other_type.cc:96
CopyObjectType
Definition: other_type.h:44
CopyObjectType::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: other_type.cc:184
CopyObjectType::~CopyObjectType
~CopyObjectType()
Definition: other_type.cc:92
LocusType::sortArgs
std::vector< ObjectCalcer * > sortArgs(const std::vector< ObjectCalcer * > &args) const
Definition: other_type.cc:160
ArgsParser::spec::type
const ObjectImpType * type
Definition: argsparser.h:113
ObjectImp::stype
static const ObjectImpType * stype()
The ObjectImpType representing the base ObjectImp class.
Definition: object_imp.cc:284
argsspecLocus
static const struct ArgsParser::spec argsspecLocus[]
Definition: other_type.cc:38
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
LocusImp::stype
static const ObjectImpType * stype()
Definition: locus_imp.cc:200
CopyObjectType::inherits
bool inherits(int type) const
Definition: other_type.cc:102
LocusType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: other_type.cc:55
bogus_imp.h
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
LocusType::impRequirement
const ObjectImpType * impRequirement(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: other_type.cc:124
CopyObjectType::calc
ObjectImp * calc(const Args &parents, const KigDocument &d) const
Definition: other_type.cc:107
ArgsParser::checkArgs
bool checkArgs(const std::vector< ObjectCalcer * > &os) const
Definition: argsparser.cpp:222
HierarchyImp
Definition: bogus_imp.h:203
LocusType
Definition: other_type.h:24
CopyObjectType::impRequirement
const ObjectImpType * impRequirement(const ObjectImp *o, const Args &parents) const
Supposing that parents would be given as parents to this type's calc function, this function returns ...
Definition: other_type.cc:113
other_type.h
ArgsParser::spec
Definition: argsparser.h:113
ArgsParser
This class is meant to take care of checking the types of the parents to ObjectCalcer's, and to put them in the correct order.
Definition: argsparser.h:106
ObjectType
The ObjectType class is a thing that represents the "behaviour" for a certain type.
Definition: object_type.h:32
CopyObjectType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: other_type.cc:118
ObjectHierarchy::argParser
ArgsParser argParser() const
Definition: object_hierarchy.cc:598
ObjectType::ID_LocusType
Definition: object_type.h:42
ArgsParser::impRequirement
const ObjectImpType * impRequirement(const ObjectImp *o, const Args &parents) const
returns the minimal ObjectImp ID that o needs to inherit in order to be useful.
Definition: argsparser.cpp:185
LocusType::instance
static const LocusType * instance()
Definition: other_type.cc:148
HierarchyImp::data
const ObjectHierarchy & data() const
Definition: bogus_imp.h:213
CurveImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CurveImp type.
Definition: curve_imp.cc:27
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
LocusType::inherits
bool inherits(int type) const
Definition: other_type.cc:75
ObjectImp::copy
virtual ObjectImp * copy() const =0
Returns a copy of this ObjectImp.
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
LocusType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: other_type.cc:80
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
CurveImp
This class represents a curve: something which is composed of points, like a line, a circle, a locus.
Definition: curve_imp.h:27
ArgsParser::parse
Args parse(const Args &os) const
Definition: argsparser.cpp:135
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