moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / objects / special_calcers.cc
blob52669498bcc9cf0474318375dd9e6eb79788b7a1
1 // Copyright (C) 2004 Dominique Devriese <devriese@kde.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
16 // 02111-1307, USA.
18 #include "special_calcers.h"
20 static const ArgsParser::spec argsspecMeasureTransport[] =
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" ) }
27 static ArgsParser measuretransportargsparser( argsspecMeasureTransport, 3 );
29 std::vector<ObjectCalcer*> MeasureTransportCalcer::parents() const
31 std::vector<ObjectCalcer*> ret;
32 ret.push_back( mcircle );
33 ret.push_back( mpoint );
34 ret.push_back( msegment );
35 return ret;
38 MeasureTransportCalcer::MeasureTransportCalcer(ObjectCalcer* circle, ObjectCalcer* point, ObjectCalcer* segment )
39 : mcircle( circle ), mpoint( point ), msegment( segment ), mimp( 0 )
43 MeasureTransportCalcer::~MeasureTransportCalcer()
47 void MeasureTransportCalcer::calc( const KigDocument& )
49 if ( ! measuretransportargsparser.checkArgs( parents() ) )
50 return new InvalidImp();
52 if ( ! isPointOnCurve( mpoint, mcircle ) )
53 return new InvalidImp();
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;
64 const Coordinate nc = c->getPoint( param, doc );
65 if ( nc.valid() ) return new PointImp( nc );
66 else return new InvalidImp;
69 const ObjectImpType* MeasureTransportCalcer::impRequirement(
70 ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const
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
80 assert( false );
81 return 0;