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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
special_calcers.cc
Go to the documentation of this file.
1 // Copyright (C) 2004 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 "special_calcers.h"
19 
20 static const ArgsParser::spec argsspecMeasureTransport[] =
21 {
22  { CircleImp::stype(), I18N_NOOP( "Transport a measure on this circle" ) },
23  { PointImp::stype(), I18N_NOOP( "Project this point onto the circle" ) },
24  { SegmentImp::stype(), I18N_NOOP( "Segment to transport" ) }
25 };
26 
27 static ArgsParser measuretransportargsparser( argsspecMeasureTransport, 3 );
28 
29 std::vector<ObjectCalcer*> MeasureTransportCalcer::parents() const
30 {
31  std::vector<ObjectCalcer*> ret;
32  ret.push_back( mcircle );
33  ret.push_back( mpoint );
34  ret.push_back( msegment );
35  return ret;
36 }
37 
38 MeasureTransportCalcer::MeasureTransportCalcer(ObjectCalcer* circle, ObjectCalcer* point, ObjectCalcer* segment )
39  : mcircle( circle ), mpoint( point ), msegment( segment ), mimp( 0 )
40 {
41 }
42 
43 MeasureTransportCalcer::~MeasureTransportCalcer()
44 {
45 }
46 
47 void MeasureTransportCalcer::calc( const KigDocument& )
48 {
49  if ( ! measuretransportargsparser.checkArgs( parents() ) )
50  return new InvalidImp();
51 
52  if ( ! isPointOnCurve( mpoint, mcircle ) )
53  return new InvalidImp();
54 
55  const CircleImp* c = static_cast<const CircleImp*>( mcircle->imp() );
56  const PointImp* p = static_cast<const PointImp*>( mpoint->imp() );
57  const SegmentImp* s = static_cast<const SegmentImp*>( msegment->imp() );
58  double param = c->getParam( p->coordinate(), doc );
59  double measure = s->length();
60  measure /= 2*c->radius()*M_PI;
61  param += measure;
62  while (param > 1) param -= 1;
63 
64  const Coordinate nc = c->getPoint( param, doc );
65  if ( nc.valid() ) return new PointImp( nc );
66  else return new InvalidImp;
67 }
68 
69 const ObjectImpType* MeasureTransportCalcer::impRequirement(
70  ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const
71 {
72  if ( o->imp()->inherits( CircleImp::stype() ) )
73  return CircleImp::stype();
74  else if ( o->imp()->inherits( PointImp::stype() ) )
75  return PointImp::stype();
76  else if ( o->imp()->inherits( SegmentImp::stype() ) )
77  return SegmentImp::stype();
78  else
79  {
80  assert( false );
81  return 0;
82  }
83 }
84 
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
ObjectImp::inherits
bool inherits(const ObjectImpType *t) const
Returns true if this ObjectImp inherits the ObjectImp type represented by t.
Definition: object_imp.cc:279
special_calcers.h
SegmentImp::length
double length() const
Get the length of this segment.
Definition: line_imp.cc:494
CircleImp
An ObjectImp representing a circle.
Definition: circle_imp.h:27
CircleImp::getPoint
const Coordinate getPoint(double param, const KigDocument &) const
Definition: circle_imp.cc:325
argsspecMeasureTransport
static const ArgsParser::spec argsspecMeasureTransport[]
Definition: special_calcers.cc:20
PointImp::coordinate
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
Definition: point_imp.h:50
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
MeasureTransportCalcer::~MeasureTransportCalcer
~MeasureTransportCalcer()
Definition: special_calcers.cc:43
CircleImp::getParam
double getParam(const Coordinate &point, const KigDocument &) const
Definition: circle_imp.cc:317
MeasureTransportCalcer::calc
void calc(const KigDocument &)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
Definition: special_calcers.cc:47
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
ObjectCalcer
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
Definition: object_calcer.h:66
isPointOnCurve
bool isPointOnCurve(const ObjectCalcer *point, const ObjectCalcer *curve)
Return true if the given point is ( by construction ) on the given curve.
Definition: calcpaths.cc:309
measuretransportargsparser
static ArgsParser measuretransportargsparser(argsspecMeasureTransport, 3)
ArgsParser::checkArgs
bool checkArgs(const std::vector< ObjectCalcer * > &os) const
Definition: argsparser.cpp:222
SegmentImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the SegmentImp type.
Definition: line_imp.cc:545
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
CircleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CircleImp type.
Definition: circle_imp.cc:342
CircleImp::radius
double radius() const
Return the radius of this circle.
Definition: circle_imp.cc:215
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
MeasureTransportCalcer::MeasureTransportCalcer
MeasureTransportCalcer(ObjectCalcer *circle, ObjectCalcer *point, ObjectCalcer *segment)
Definition: special_calcers.cc:38
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
ObjectCalcer::imp
virtual const ObjectImp * imp() const =0
Returns the ObjectImp of this ObjectCalcer.
MeasureTransportCalcer::impRequirement
const ObjectImpType * impRequirement(ObjectCalcer *o, const std::vector< ObjectCalcer * > &os) const
An ObjectCalcer expects its parents to have an ObjectImp of a certain type.
Definition: special_calcers.cc:69
MeasureTransportCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: special_calcers.cc:29
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
SegmentImp
An ObjectImp representing a segment.
Definition: line_imp.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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