moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / objects / line_type.cc
blobaf4b316c628c70dd6599e7d6d9e6f6b5cc260447
1 // Copyright (C) 2002 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 "line_type.h"
20 #include "bogus_imp.h"
21 #include "line_imp.h"
22 #include "object_holder.h"
23 #include "other_imp.h"
24 #include "point_imp.h"
26 #include "../kig/kig_view.h"
27 #include "../kig/kig_part.h"
28 #include "../kig/kig_commands.h"
29 #include "../misc/common.h"
30 #include "../misc/calcpaths.h"
32 #include <qstringlist.h>
34 #include <klocale.h>
36 static const ArgsParser::spec argsspecSegmentAB[] =
38 { PointImp::stype(), I18N_NOOP( "Construct a segment starting at this point" ),
39 I18N_NOOP( "Select the start point of the new segment..." ), true },
40 { PointImp::stype(), I18N_NOOP( "Construct a segment ending at this point" ),
41 I18N_NOOP( "Select the end point of the new segment..." ), true }
44 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( SegmentABType )
46 SegmentABType::SegmentABType()
47 : ObjectABType( "SegmentAB", argsspecSegmentAB, 2 )
51 SegmentABType::~SegmentABType()
55 const SegmentABType* SegmentABType::instance()
57 static const SegmentABType s;
58 return &s;
61 ObjectImp* SegmentABType::calc( const Coordinate& a, const Coordinate& b ) const
63 return new SegmentImp( a, b );
66 static const char constructlineabstat[] = I18N_NOOP( "Construct a line through this point" );
68 static const ArgsParser::spec argsspecLineAB[] =
70 { PointImp::stype(), constructlineabstat,
71 I18N_NOOP( "Select a point for the line to go through..." ), true },
72 { PointImp::stype(), constructlineabstat,
73 I18N_NOOP( "Select another point for the line to go through..." ), true }
76 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineABType )
78 LineABType::LineABType()
79 : ObjectABType( "LineAB", argsspecLineAB, 2 )
83 LineABType::~LineABType()
87 const LineABType* LineABType::instance()
89 static const LineABType s;
90 return &s;
93 ObjectImp* LineABType::calc( const Coordinate& a, const Coordinate& b ) const
95 return new LineImp( a, b );
98 static const char constructhalflinestartingstat[] = I18N_NOOP( "Construct a half-line starting at this point" );
100 static const ArgsParser::spec argsspecRayAB[] =
102 { PointImp::stype(), constructhalflinestartingstat,
103 I18N_NOOP( "Select the start point of the new half-line..." ), true },
104 { PointImp::stype(), I18N_NOOP( "Construct a half-line through this point" ),
105 I18N_NOOP( "Select a point for the half-line to go through..." ), true }
108 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( RayABType )
110 RayABType::RayABType()
111 : ObjectABType( "RayAB", argsspecRayAB, 2 )
115 RayABType::~RayABType()
119 const RayABType* RayABType::instance()
121 static const RayABType s;
122 return &s;
125 ObjectImp* RayABType::calc( const Coordinate& a, const Coordinate& b ) const
127 return new RayImp( a, b );
130 LinePerpendLPType* LinePerpendLPType::instance()
132 static LinePerpendLPType l;
133 return &l;
136 ObjectImp* LinePerpendLPType::calc(
137 const LineData& a,
138 const Coordinate& b ) const
140 Coordinate p = calcPointOnPerpend( a, b );
141 return new LineImp( b, p );
144 static const ArgsParser::spec argsspecLineParallel[] =
146 { AbstractLineImp::stype(), I18N_NOOP( "Construct a line parallel to this line" ),
147 I18N_NOOP( "Select a line parallel to the new line..." ), false },
148 { PointImp::stype(), I18N_NOOP( "Construct the parallel line through this point" ),
149 I18N_NOOP( "Select a point for the new line to go through..." ), true }
152 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineParallelLPType )
154 LineParallelLPType::LineParallelLPType()
155 : ObjectLPType( "LineParallel", argsspecLineParallel, 2 )
159 LineParallelLPType::~LineParallelLPType()
163 LineParallelLPType* LineParallelLPType::instance()
165 static LineParallelLPType l;
166 return &l;
169 ObjectImp* LineParallelLPType::calc(
170 const LineData& a,
171 const Coordinate& b ) const
173 Coordinate r = calcPointOnParallel( a, b );
174 return new LineImp( r, b );
177 static const ArgsParser::spec argsspecLinePerpend[] =
179 { AbstractLineImp::stype(), I18N_NOOP( "Construct a line perpendicular to this line" ),
180 I18N_NOOP( "Select a line perpendicular to the new line..." ), false },
181 { PointImp::stype(), I18N_NOOP( "Construct a perpendicular line through this point" ),
182 I18N_NOOP( "Select a point for the new line to go through..." ), true }
185 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LinePerpendLPType )
187 LinePerpendLPType::LinePerpendLPType()
188 : ObjectLPType( "LinePerpend", argsspecLinePerpend, 2 )
192 LinePerpendLPType::~LinePerpendLPType()
196 const ObjectImpType* SegmentABType::resultId() const
198 return SegmentImp::stype();
201 const ObjectImpType* LineABType::resultId() const
203 return LineImp::stype();
206 const ObjectImpType* RayABType::resultId() const
208 return RayImp::stype();
211 const ObjectImpType* LinePerpendLPType::resultId() const
213 return LineImp::stype();
216 const ObjectImpType* LineParallelLPType::resultId() const
218 return LineImp::stype();
221 QStringList SegmentABType::specialActions() const
223 QStringList ret;
224 ret << i18n( "Set &Length..." );
225 return ret;
228 void SegmentABType::executeAction( int i, ObjectHolder&, ObjectTypeCalcer& c,
229 KigPart& d, KigWidget& w, NormalMode& ) const
231 assert( i == 0 );
232 // pretend to use this var..
233 (void) i;
235 std::vector<ObjectCalcer*> parents = c.parents();
236 assert( margsparser.checkArgs( parents ) );
238 Coordinate a = static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
239 Coordinate b = static_cast<const PointImp*>( parents[1]->imp() )->coordinate();
241 bool ok = true;
242 double length = getDoubleFromUser(
243 i18n( "Set Segment Length" ), i18n( "Choose the new length: " ),
244 (b-a).length(), &w, &ok, -2147483647, 2147483647, 3 );
245 if ( ! ok ) return;
247 Coordinate nb = a + ( b - a ).normalize( length );
249 MonitorDataObjects mon( getAllParents( parents ) );
250 parents[1]->move( nb, d.document() );
251 KigCommand* cd = new KigCommand( d, i18n( "Resize Segment" ) );
252 mon.finish( cd );
253 d.history()->addCommand( cd );
256 static const ArgsParser::spec argsspecLineByVector[] =
258 { VectorImp::stype(), I18N_NOOP( "Construct a line by this vector" ),
259 I18N_NOOP( "Select a vector in the direction of the new line..." ), true },
260 { PointImp::stype(), constructlineabstat,
261 I18N_NOOP( "Select a point for the new line to go through..." ), true }
264 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineByVectorType )
266 LineByVectorType::LineByVectorType()
267 : ArgsParserObjectType( "LineByVector", argsspecLineByVector, 2 )
271 LineByVectorType::~LineByVectorType()
275 const LineByVectorType* LineByVectorType::instance()
277 static const LineByVectorType s;
278 return &s;
281 ObjectImp* LineByVectorType::calc( const Args& args, const KigDocument& ) const
283 if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
285 const VectorImp& a = *static_cast<const VectorImp*>( args[0] );
286 const PointImp& b = *static_cast<const PointImp*>( args[1] );
288 return new LineImp( b.coordinate(), b.coordinate() + a.dir() );
291 const ObjectImpType* LineByVectorType::resultId() const
293 return LineImp::stype();
296 static const ArgsParser::spec argsspecHalflineByVector[] =
298 { VectorImp::stype(), I18N_NOOP( "Construct a half-line by this vector" ),
299 I18N_NOOP( "Select a vector in the direction of the new half-line..." ), true },
300 { PointImp::stype(), constructhalflinestartingstat,
301 I18N_NOOP( "Select the start point of the new half-line..." ), true }
304 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( HalflineByVectorType )
306 HalflineByVectorType::HalflineByVectorType()
307 : ArgsParserObjectType( "HalflineByVector", argsspecHalflineByVector, 2 )
311 HalflineByVectorType::~HalflineByVectorType()
315 const HalflineByVectorType* HalflineByVectorType::instance()
317 static const HalflineByVectorType s;
318 return &s;
321 ObjectImp* HalflineByVectorType::calc( const Args& args, const KigDocument& ) const
323 if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
325 const VectorImp& a = *static_cast<const VectorImp*>( args[0] );
326 const PointImp& b = *static_cast<const PointImp*>( args[1] );
328 return new RayImp( b.coordinate(), b.coordinate() + a.dir() );
331 const ObjectImpType* HalflineByVectorType::resultId() const
333 return RayImp::stype();