• 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
line_type.cc
Go to the documentation of this file.
1 // Copyright (C) 2002 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 "line_type.h"
19 
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"
25 
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"
31 
32 #include <qstringlist.h>
33 
34 #include <klocale.h>
35 
36 static const ArgsParser::spec argsspecSegmentAB[] =
37 {
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 }
42 };
43 
44 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( SegmentABType )
45 
46 SegmentABType::SegmentABType()
47  : ObjectABType( "SegmentAB", argsspecSegmentAB, 2 )
48 {
49 }
50 
51 SegmentABType::~SegmentABType()
52 {
53 }
54 
55 const SegmentABType* SegmentABType::instance()
56 {
57  static const SegmentABType s;
58  return &s;
59 }
60 
61 ObjectImp* SegmentABType::calcx( const Coordinate& a, const Coordinate& b ) const
62 {
63  return new SegmentImp( a, b );
64 }
65 
66 static const char constructlineabstat[] = I18N_NOOP( "Construct a line through this point" );
67 
68 static const ArgsParser::spec argsspecLineAB[] =
69 {
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 }
74 };
75 
76 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineABType )
77 
78 LineABType::LineABType()
79  : ObjectABType( "LineAB", argsspecLineAB, 2 )
80 {
81 }
82 
83 LineABType::~LineABType()
84 {
85 }
86 
87 const LineABType* LineABType::instance()
88 {
89  static const LineABType s;
90  return &s;
91 }
92 
93 ObjectImp* LineABType::calcx( const Coordinate& a, const Coordinate& b ) const
94 {
95  return new LineImp( a, b );
96 }
97 
98 static const char constructhalflinestartingstat[] = I18N_NOOP( "Construct a half-line starting at this point" );
99 
100 static const ArgsParser::spec argsspecRayAB[] =
101 {
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 }
106 };
107 
108 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( RayABType )
109 
110 RayABType::RayABType()
111  : ObjectABType( "RayAB", argsspecRayAB, 2 )
112 {
113 }
114 
115 RayABType::~RayABType()
116 {
117 }
118 
119 const RayABType* RayABType::instance()
120 {
121  static const RayABType s;
122  return &s;
123 }
124 
125 ObjectImp* RayABType::calcx( const Coordinate& a, const Coordinate& b ) const
126 {
127  return new RayImp( a, b );
128 }
129 
130 static const ArgsParser::spec argspecSegmentAxisABType[] =
131 {
132  { SegmentImp::stype(), I18N_NOOP( "Construct the axis of this segment" ),
133  I18N_NOOP( "Select the segment of which you want to draw the axis..." ), true }
134 };
135 
136 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( SegmentAxisType );
137 
138 SegmentAxisType::SegmentAxisType()
139  : ArgsParserObjectType( "Segment Axis", argspecSegmentAxisABType, 1 )
140 {
141 }
142 
143 SegmentAxisType::~SegmentAxisType()
144 {
145 }
146 
147 const SegmentAxisType* SegmentAxisType::instance()
148 {
149  static const SegmentAxisType s;
150  return &s;
151 }
152 
153 ObjectImp* SegmentAxisType::calc( const Args& args, const KigDocument& ) const
154 {
155  if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
156 
157  const SegmentImp * l = static_cast< const SegmentImp * >( args[0] );
158  const Coordinate a = l->data().a;
159  const Coordinate b = l->data().b;
160  const Coordinate mp = ( a + b ) / 2;
161  const Coordinate dir( b - a );
162  const Coordinate perpPoint = calcPointOnPerpend( dir, mp );
163  return new LineImp( mp, perpPoint );
164 }
165 
166 const ObjectImpType* SegmentAxisType::resultId() const
167 {
168  return LineImp::stype();
169 }
170 
171 LinePerpendLPType* LinePerpendLPType::instance()
172 {
173  static LinePerpendLPType l;
174  return &l;
175 }
176 
177 ObjectImp* LinePerpendLPType::calc(
178  const LineData& a,
179  const Coordinate& b ) const
180 {
181  Coordinate p = calcPointOnPerpend( a, b );
182  return new LineImp( b, p );
183 }
184 
185 static const ArgsParser::spec argsspecLineParallel[] =
186 {
187  { AbstractLineImp::stype(), I18N_NOOP( "Construct a line parallel to this line" ),
188  I18N_NOOP( "Select a line parallel to the new line..." ), false },
189  { PointImp::stype(), I18N_NOOP( "Construct the parallel line through this point" ),
190  I18N_NOOP( "Select a point for the new line to go through..." ), true }
191 };
192 
193 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineParallelLPType )
194 
195 LineParallelLPType::LineParallelLPType()
196  : ObjectLPType( "LineParallel", argsspecLineParallel, 2 )
197 {
198 }
199 
200 LineParallelLPType::~LineParallelLPType()
201 {
202 }
203 
204 LineParallelLPType* LineParallelLPType::instance()
205 {
206  static LineParallelLPType l;
207  return &l;
208 }
209 
210 ObjectImp* LineParallelLPType::calc(
211  const LineData& a,
212  const Coordinate& b ) const
213 {
214  Coordinate r = calcPointOnParallel( a, b );
215  return new LineImp( r, b );
216 }
217 
218 static const ArgsParser::spec argsspecLinePerpend[] =
219 {
220  { AbstractLineImp::stype(), I18N_NOOP( "Construct a line perpendicular to this line" ),
221  I18N_NOOP( "Select a line perpendicular to the new line..." ), false },
222  { PointImp::stype(), I18N_NOOP( "Construct a perpendicular line through this point" ),
223  I18N_NOOP( "Select a point for the new line to go through..." ), true }
224 };
225 
226 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LinePerpendLPType )
227 
228 LinePerpendLPType::LinePerpendLPType()
229  : ObjectLPType( "LinePerpend", argsspecLinePerpend, 2 )
230 {
231 }
232 
233 LinePerpendLPType::~LinePerpendLPType()
234 {
235 }
236 
237 const ObjectImpType* SegmentABType::resultId() const
238 {
239  return SegmentImp::stype();
240 }
241 
242 const ObjectImpType* LineABType::resultId() const
243 {
244  return LineImp::stype();
245 }
246 
247 const ObjectImpType* RayABType::resultId() const
248 {
249  return RayImp::stype();
250 }
251 
252 const ObjectImpType* LinePerpendLPType::resultId() const
253 {
254  return LineImp::stype();
255 }
256 
257 const ObjectImpType* LineParallelLPType::resultId() const
258 {
259  return LineImp::stype();
260 }
261 
262 QStringList SegmentABType::specialActions() const
263 {
264  QStringList ret;
265  ret << i18n( "Set &Length..." );
266  return ret;
267 }
268 
269 void SegmentABType::executeAction( int i, ObjectHolder&, ObjectTypeCalcer& c,
270  KigPart& d, KigWidget& w, NormalMode& ) const
271 {
272  assert( i == 0 );
273  // pretend to use this var..
274  (void) i;
275 
276  std::vector<ObjectCalcer*> parents = c.parents();
277  assert( margsparser.checkArgs( parents ) );
278 
279  Coordinate a = static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
280  Coordinate b = static_cast<const PointImp*>( parents[1]->imp() )->coordinate();
281 
282  bool ok = true;
283  double length = getDoubleFromUser(
284  i18n( "Set Segment Length" ), i18n( "Choose the new length: " ),
285  (b-a).length(), &w, &ok, -2147483647, 2147483647, 3 );
286  if ( ! ok ) return;
287 
288  Coordinate nb = a + ( b - a ).normalize( length );
289 
290  MonitorDataObjects mon( getAllParents( parents ) );
291  parents[1]->move( nb, d.document() );
292  KigCommand* cd = new KigCommand( d, i18n( "Resize Segment" ) );
293  mon.finish( cd );
294  d.history()->push( cd );
295 }
296 
297 static const ArgsParser::spec argsspecLineByVector[] =
298 {
299  { VectorImp::stype(), I18N_NOOP( "Construct a line by this vector" ),
300  I18N_NOOP( "Select a vector in the direction of the new line..." ), true },
301  { PointImp::stype(), constructlineabstat,
302  I18N_NOOP( "Select a point for the new line to go through..." ), true }
303 };
304 
305 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LineByVectorType )
306 
307 LineByVectorType::LineByVectorType()
308  : ArgsParserObjectType( "LineByVector", argsspecLineByVector, 2 )
309 {
310 }
311 
312 LineByVectorType::~LineByVectorType()
313 {
314 }
315 
316 const LineByVectorType* LineByVectorType::instance()
317 {
318  static const LineByVectorType s;
319  return &s;
320 }
321 
322 ObjectImp* LineByVectorType::calc( const Args& args, const KigDocument& ) const
323 {
324  if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
325 
326  const VectorImp& a = *static_cast<const VectorImp*>( args[0] );
327  const PointImp& b = *static_cast<const PointImp*>( args[1] );
328 
329  return new LineImp( b.coordinate(), b.coordinate() + a.dir() );
330 }
331 
332 const ObjectImpType* LineByVectorType::resultId() const
333 {
334  return LineImp::stype();
335 }
336 
337 static const ArgsParser::spec argsspecHalflineByVector[] =
338 {
339  { VectorImp::stype(), I18N_NOOP( "Construct a half-line by this vector" ),
340  I18N_NOOP( "Select a vector in the direction of the new half-line..." ), true },
341  { PointImp::stype(), constructhalflinestartingstat,
342  I18N_NOOP( "Select the start point of the new half-line..." ), true }
343 };
344 
345 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( HalflineByVectorType )
346 
347 HalflineByVectorType::HalflineByVectorType()
348  : ArgsParserObjectType( "HalflineByVector", argsspecHalflineByVector, 2 )
349 {
350 }
351 
352 HalflineByVectorType::~HalflineByVectorType()
353 {
354 }
355 
356 const HalflineByVectorType* HalflineByVectorType::instance()
357 {
358  static const HalflineByVectorType s;
359  return &s;
360 }
361 
362 ObjectImp* HalflineByVectorType::calc( const Args& args, const KigDocument& ) const
363 {
364  if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
365 
366  const VectorImp& a = *static_cast<const VectorImp*>( args[0] );
367  const PointImp& b = *static_cast<const PointImp*>( args[1] );
368 
369  return new RayImp( b.coordinate(), b.coordinate() + a.dir() );
370 }
371 
372 const ObjectImpType* HalflineByVectorType::resultId() const
373 {
374  return RayImp::stype();
375 }
HalflineByVectorType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:372
LineABType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:242
LinePerpendLPType::calc
ObjectImp * calc(const LineData &a, const Coordinate &b) const
Definition: line_type.cc:177
argsspecLinePerpend
static const ArgsParser::spec argsspecLinePerpend[]
Definition: line_type.cc:218
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
AbstractLineImp::data
LineData data() const
Get the LineData for this AbstractLineImp.
Definition: line_imp.cc:359
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(SegmentAxisType)
ObjectABType
Definition: base_type.h:27
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
LineByVectorType
Definition: line_type.h:101
KigCommand
a KigCommand represents almost every action performed in Kig.
Definition: kig_commands.h:44
LineData
Simple class representing a line.
Definition: misc/common.h:49
SegmentABType::specialActions
QStringList specialActions() const
return i18n'd names for the special actions.
Definition: line_type.cc:262
LineParallelLPType::calc
ObjectImp * calc(const LineData &a, const Coordinate &b) const
Definition: line_type.cc:210
LinePerpendLPType::instance
static LinePerpendLPType * instance()
Definition: line_type.cc:171
HalflineByVectorType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: line_type.cc:362
LineData::b
Coordinate b
Another point on the line.
Definition: misc/common.h:68
SegmentABType::executeAction
void executeAction(int i, ObjectHolder &o, ObjectTypeCalcer &c, KigPart &d, KigWidget &w, NormalMode &m) const
execute the i 'th action from the specialActions above.
Definition: line_type.cc:269
RayImp
An ObjectImp representing a ray.
Definition: line_imp.h:136
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:986
KigPart::history
QUndoStack * history()
Definition: kig_part.cpp:630
VectorImp::dir
const Coordinate dir() const
Return the direction of this vector.
Definition: other_imp.cc:300
RayImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the RayImp type.
Definition: line_imp.cc:562
argsspecRayAB
static const ArgsParser::spec argsspecRayAB[]
Definition: line_type.cc:100
LineABType
Definition: line_type.h:44
argsspecLineAB
static const ArgsParser::spec argsspecLineAB[]
Definition: line_type.cc:68
argsspecLineParallel
static const ArgsParser::spec argsspecLineParallel[]
Definition: line_type.cc:185
VectorImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the VectorImp type.
Definition: other_imp.cc:613
RayABType::instance
static const RayABType * instance()
Definition: line_type.cc:119
ObjectLPType
Definition: base_type.h:46
PointImp::coordinate
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
Definition: point_imp.h:50
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
LineImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the LineImp type.
Definition: line_imp.cc:528
calcPointOnPerpend
Coordinate calcPointOnPerpend(const LineData &l, const Coordinate &t)
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: common.cpp:37
constructhalflinestartingstat
static const char constructhalflinestartingstat[]
Definition: line_type.cc:98
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
VectorImp
An ObjectImp representing a vector.
Definition: other_imp.h:99
ArgsParserObjectType::margsparser
const ArgsParser margsparser
Definition: object_type.h:117
SegmentAxisType
Definition: line_type.h:66
getAllParents
std::vector< ObjectCalcer * > getAllParents(const std::vector< ObjectCalcer * > &objs)
This function returns all objects above the given in the dependency graph.
Definition: calcpaths.cc:229
line_type.h
getDoubleFromUser
double getDoubleFromUser(const QString &caption, const QString &label, double value, QWidget *parent, bool *ok, double min, double max, int decimals)
Here, we define some algorithms which we need in various places...
Definition: common.cpp:349
SegmentABType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:237
RayABType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:247
ObjectHolder
An ObjectHolder represents an object as it is known to the document.
Definition: object_holder.h:40
LineParallelLPType::instance
static LineParallelLPType * instance()
Definition: line_type.cc:204
bogus_imp.h
argsspecLineByVector
static const ArgsParser::spec argsspecLineByVector[]
Definition: line_type.cc:297
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
SegmentAxisType::instance
static const SegmentAxisType * instance()
Definition: line_type.cc:147
MonitorDataObjects
this class monitors a set of DataObjects for changes and returns an appropriate ChangeObjectImpsComma...
Definition: kig_commands.h:153
RayABType
Definition: line_type.h:55
HalflineByVectorType
Definition: line_type.h:112
LineData::a
Coordinate a
One point on the line.
Definition: misc/common.h:64
SegmentAxisType::calc
ObjectImp * calc(const Args &parents, const KigDocument &d) const
Definition: line_type.cc:153
argsspecSegmentAB
static const ArgsParser::spec argsspecSegmentAB[]
Definition: line_type.cc:36
LineABType::calcx
ObjectImp * calcx(const Coordinate &a, const Coordinate &b) const
Definition: line_type.cc:93
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
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
argspecSegmentAxisABType
static const ArgsParser::spec argspecSegmentAxisABType[]
Definition: line_type.cc:130
QStringList
ArgsParser::spec
Definition: argsparser.h:113
MonitorDataObjects::finish
void finish(KigCommand *comm)
add the generated KigCommandTasks to the command comm .
Definition: kig_commands.cpp:227
LinePerpendLPType
Definition: line_type.h:77
LineByVectorType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: line_type.cc:322
SegmentABType::calcx
ObjectImp * calcx(const Coordinate &a, const Coordinate &b) const
Definition: line_type.cc:61
argsspecHalflineByVector
static const ArgsParser::spec argsspecHalflineByVector[]
Definition: line_type.cc:337
SegmentABType
Definition: line_type.h:25
LineByVectorType::instance
static const LineByVectorType * instance()
Definition: line_type.cc:316
RayABType::calcx
ObjectImp * calcx(const Coordinate &a, const Coordinate &b) const
Definition: line_type.cc:125
LineParallelLPType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:257
LinePerpendLPType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:252
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
SegmentAxisType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:166
HalflineByVectorType::instance
static const HalflineByVectorType * instance()
Definition: line_type.cc:356
line_imp.h
calcPointOnParallel
Coordinate calcPointOnParallel(const LineData &l, const Coordinate &t)
this returns a point, so that the line through point t and the point returned is parallel with the li...
Definition: common.cpp:47
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
AbstractLineImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AbstractLineImp type.
Definition: line_imp.cc:520
LineImp
An ObjectImp representing a line.
Definition: line_imp.h:184
LineByVectorType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: line_type.cc:332
ObjectTypeCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:105
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
KigPart
This is a "Part".
Definition: kig_part.h:68
object_holder.h
SegmentABType::instance
static const SegmentABType * instance()
Definition: line_type.cc:55
LineParallelLPType
Definition: line_type.h:89
NormalMode
Definition: normal.h:26
QUndoStack::push
void push(QUndoCommand *cmd)
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
LineABType::instance
static const LineABType * instance()
Definition: line_type.cc:87
other_imp.h
constructlineabstat
static const char constructlineabstat[]
Definition: line_type.cc:66
SegmentImp
An ObjectImp representing a segment.
Definition: line_imp.h:81
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