1 // Copyright (C) 2003 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
18 #include "builtin_stuff.h"
22 #include "object_constructor.h"
24 #include "special_constructors.h"
25 #include "guiaction.h"
27 #include "../objects/angle_type.h"
28 #include "../objects/arc_type.h"
29 #include "../objects/circle_type.h"
30 #include "../objects/conic_types.h"
31 #include "../objects/cubic_type.h"
32 #include "../objects/intersection_types.h"
33 #include "../objects/inversion_type.h"
34 #include "../objects/line_imp.h"
35 #include "../objects/line_type.h"
36 #include "../objects/object_imp.h"
37 #include "../objects/other_imp.h"
38 #include "../objects/other_type.h"
39 #include "../objects/point_type.h"
40 #include "../objects/tests_type.h"
41 #include "../objects/transform_types.h"
42 #include "../objects/vector_type.h"
43 #include "../objects/polygon_type.h"
47 void setupBuiltinStuff()
49 static bool done
= false;
52 ObjectConstructorList
* ctors
= ObjectConstructorList::instance();
53 GUIActionList
* actions
= GUIActionList::instance();
54 ObjectConstructor
* c
= 0;
57 c
= new SimpleObjectTypeConstructor(
58 SegmentABType::instance(), I18N_NOOP( "Segment" ),
59 I18N_NOOP( "A segment constructed from its start and end point" ),
62 actions
->add( new ConstructibleAction( c
, "objects_new_segment", Qt::Key_S
) );
64 // line by two points..
65 c
= new SimpleObjectTypeConstructor(
66 LineABType::instance(), I18N_NOOP( "Line by Two Points" ),
67 I18N_NOOP( "A line constructed through two points"), "line" );
69 actions
->add( new ConstructibleAction( c
, "objects_new_linettp", Qt::Key_L
) );
71 // ray by two points..
72 c
= new SimpleObjectTypeConstructor(
73 RayABType::instance(), I18N_NOOP( "Half-Line" ),
74 I18N_NOOP( "A half-line by its start point, and another point somewhere on it." ),
77 actions
->add( new ConstructibleAction( c
, "objects_new_ray", Qt::Key_R
) );
80 c
= new SimpleObjectTypeConstructor(
81 LinePerpendLPType::instance(), I18N_NOOP( "Perpendicular" ),
82 I18N_NOOP( "A line constructed through a point, perpendicular to another line or segment." ),
85 actions
->add( new ConstructibleAction( c
, "objects_new_lineperpend" ) );
88 c
= new SimpleObjectTypeConstructor(
89 LineParallelLPType::instance(), I18N_NOOP( "Parallel" ),
90 I18N_NOOP( "A line constructed through a point, and parallel to another line or segment" ),
93 actions
->add( new ConstructibleAction( c
, "objects_new_lineparallel" ) );
96 c
= new SimpleObjectTypeConstructor(
97 CircleBCPType::instance(), I18N_NOOP( "Circle by Center && Point" ),
98 I18N_NOOP( "A circle constructed by its center and a point that pertains to it" ),
101 actions
->add( new ConstructibleAction( c
, "objects_new_circlebcp", Qt::Key_C
) );
103 c
= new SimpleObjectTypeConstructor(
104 CircleBTPType::instance(), I18N_NOOP( "Circle by Three Points" ),
105 I18N_NOOP( "A circle constructed through three points" ),
108 actions
->add( new ConstructibleAction( c
, "objects_new_circlebtp" ) );
110 // declare this object static to this function, so it gets deleted
111 // at the end of the program, without us having to wonder about
112 // deleting it.. We don't want to register this
113 // object-constructor, because that way, "construct the bisector"
114 // would appear twice in the angle popup menu: once as the generic
115 // construct a property stuff, and once because of this ctor..
116 // we only register the guiaction, cause it makes sense to have a
117 // toolbar icon for this..
118 static PropertyObjectConstructor
anglebisectionctor(
120 I18N_NOOP( "Construct Bisector of This Angle" ),
121 I18N_NOOP( "Select the angle you want to construct the bisector of..." ),
122 I18N_NOOP( "Angle Bisector" ),
123 I18N_NOOP( "The bisector of an angle" ),
126 actions
->add( new ConstructibleAction( &anglebisectionctor
, "objects_new_angle_bisector" ) );
129 c
= new SimpleObjectTypeConstructor(
130 ConicB5PType::instance(), I18N_NOOP( "Conic by Five Points" ),
131 I18N_NOOP( "A conic constructed through five points" ),
134 actions
->add( new ConstructibleAction( c
, "objects_new_conicb5p" ) );
136 c
= new SimpleObjectTypeConstructor(
137 ConicBAAPType::instance(),
138 I18N_NOOP( "Hyperbola by Asymptotes && Point" ),
139 I18N_NOOP( "A hyperbola with given asymptotes through a point" ),
142 actions
->add( new ConstructibleAction( c
, "objects_new_conicbaap" ) );
144 c
= new SimpleObjectTypeConstructor(
145 EllipseBFFPType::instance(),
146 I18N_NOOP( "Ellipse by Focuses && Point" ), // focuses is used in preference to foci
147 I18N_NOOP( "An ellipse constructed by its focuses and a point that pertains to it" ),
150 actions
->add( new ConstructibleAction( c
, "objects_new_ellipsebffp" ) );
152 c
= new SimpleObjectTypeConstructor(
153 HyperbolaBFFPType::instance(),
154 I18N_NOOP( "Hyperbola by Focuses && Point" ), // focuses is used in preference to foci
155 I18N_NOOP( "A hyperbola constructed by its focuses and a point that pertains to it" ),
158 actions
->add( new ConstructibleAction( c
, "objects_new_hyperbolabffp" ) );
160 c
= new SimpleObjectTypeConstructor(
161 ConicBDFPType::instance(),
162 I18N_NOOP( "Conic by Directrix, Focus && Point" ),
163 I18N_NOOP( "A conic with given directrix and focus, through a point" ),
166 actions
->add( new ConstructibleAction( c
, "objects_new_conicbdfp" ) );
168 c
= new SimpleObjectTypeConstructor(
169 ParabolaBTPType::instance(),
170 I18N_NOOP( "Vertical Parabola by Three Points" ),
171 I18N_NOOP( "A vertical parabola constructed through three points" ),
174 actions
->add( new ConstructibleAction( c
, "objects_new_parabolabtp" ) );
176 c
= new SimpleObjectTypeConstructor(
177 CubicB9PType::instance(),
178 I18N_NOOP( "Cubic Curve by Nine Points" ),
179 I18N_NOOP( "A cubic curve constructed through nine points" ),
182 actions
->add( new ConstructibleAction( c
, "objects_new_cubicb9p" ) );
184 c
= new SimpleObjectTypeConstructor(
185 ConicPolarPointType::instance(),
186 I18N_NOOP( "Polar Point of a Line" ),
187 I18N_NOOP( "The polar point of a line with respect to a conic." ),
190 actions
->add( new ConstructibleAction( c
, "objects_new_pointpolar" ) );
192 c
= new SimpleObjectTypeConstructor(
193 ConicPolarLineType::instance(),
194 I18N_NOOP( "Polar Line of a Point" ),
195 I18N_NOOP( "The polar line of a point with respect to a conic." ),
198 actions
->add( new ConstructibleAction( c
, "objects_new_linepolar" ) );
200 c
= new SimpleObjectTypeConstructor(
201 CubicNodeB6PType::instance(),
202 I18N_NOOP( "Cubic Curve with Node by Six Points" ),
203 I18N_NOOP( "A cubic curve with a nodal point at the origin through six points" ),
206 actions
->add( new ConstructibleAction( c
, "objects_new_cubicnodeb6p" ) );
208 c
= new SimpleObjectTypeConstructor(
209 CubicCuspB4PType::instance(),
210 I18N_NOOP( "Cubic Curve with Cusp by Four Points" ),
211 I18N_NOOP( "A cubic curve with a horizontal cusp at the origin through four points" ),
214 actions
->add( new ConstructibleAction( c
, "objects_new_cubiccuspb4p" ) );
216 c
= new SimpleObjectTypeConstructor(
217 ConicDirectrixType::instance(),
218 I18N_NOOP( "Directrix of a Conic" ),
219 I18N_NOOP( "The directrix line of a conic." ),
222 actions
->add( new ConstructibleAction( c
, "objects_new_linedirectrix" ) );
224 c
= new SimpleObjectTypeConstructor(
225 AngleType::instance(),
226 I18N_NOOP( "Angle by Three Points" ),
227 I18N_NOOP( "An angle defined by three points" ),
230 actions
->add( new ConstructibleAction( c
, "objects_new_angle", Qt::Key_A
) );
232 c
= new SimpleObjectTypeConstructor(
233 EquilateralHyperbolaB4PType::instance(),
234 I18N_NOOP( "Equilateral Hyperbola by Four Points" ),
235 I18N_NOOP( "An equilateral hyperbola constructed through four points" ),
236 "equilateralhyperbolab4p" );
238 actions
->add( new ConstructibleAction( c
, "objects_new_equilateralhyperbolab4p" ) );
241 // now for the Mid Point action. It does both the mid point of
242 // a segment, and the mid point of two points. The midpoint of
243 // two segments just shows the mid point property, and therefore
244 // doesn't need to be added to the ctors, because there are
245 // already facilities to construct an object's properties..
246 // therefore, we add only an mpotp to the ctors, and add the
247 // merged constructor only to the actions..
248 ctors
->add( new MidPointOfTwoPointsConstructor() );
250 ObjectConstructor
* mpotp
= new MidPointOfTwoPointsConstructor();
251 ObjectConstructor
* mpos
= new PropertyObjectConstructor(
252 SegmentImp::stype(), I18N_NOOP( "Construct the midpoint of this segment" ),
253 "", "", "", "", "mid-point" );
255 // make this a static object, so it gets deleted at the end of
257 static MergeObjectConstructor
m(
258 I18N_NOOP( "Mid Point" ),
259 I18N_NOOP( "The midpoint of a segment or two other points" ),
263 actions
->add( new ConstructibleAction( &m
, "objects_new_midpoint", Qt::Key_M
) );
266 c
= new SimpleObjectTypeConstructor(
267 VectorType::instance(),
268 I18N_NOOP( "Vector" ),
269 I18N_NOOP( "Construct a vector from two given points." ),
272 actions
->add( new ConstructibleAction( c
, "objects_new_vector", Qt::Key_V
) );
274 c
= new SimpleObjectTypeConstructor(
275 VectorSumType::instance(),
276 I18N_NOOP( "Vector Sum" ),
277 I18N_NOOP( "Construct the vector sum of two vectors." ),
280 actions
->add( new ConstructibleAction( c
, "objects_new_vectorsum", 0 ) );
282 c
= new SimpleObjectTypeConstructor(
283 LineByVectorType::instance(),
284 I18N_NOOP( "Line by Vector" ),
285 I18N_NOOP( "Construct the line by a given vector though a given point." ),
288 actions
->add( new ConstructibleAction( c
, "objects_new_linebyvector", 0 ) );
290 c
= new SimpleObjectTypeConstructor(
291 HalflineByVectorType::instance(),
292 I18N_NOOP( "Half-Line by Vector" ),
293 I18N_NOOP( "Construct the half-line by a given vector starting at given point." ),
294 "halflinebyvector" );
296 actions
->add( new ConstructibleAction( c
, "objects_new_halflinebyvector", 0 ) );
298 c
= new SimpleObjectTypeConstructor(
299 ArcBTPType::instance(),
300 I18N_NOOP( "Arc by Three Points" ),
301 I18N_NOOP( "Construct an arc through three points." ),
304 actions
->add( new ConstructibleAction( c
, "objects_new_arcbtp" ) );
306 c
= new SimpleObjectTypeConstructor(
307 ArcBCPAType::instance(),
308 I18N_NOOP( "Arc by Center, Angle && Point" ),
309 I18N_NOOP( "Construct an arc by its center and a given angle, "
310 "starting at a given point" ),
313 actions
->add( new ConstructibleAction( c
, "objects_new_arcbcpa" ) );
315 c
= new SimpleObjectTypeConstructor(
316 ParabolaBDPType::instance(),
317 I18N_NOOP( "Parabola by Directrix && Focus" ),
318 I18N_NOOP( "A parabola defined by its directrix and focus" ),
321 actions
->add( new ConstructibleAction( c
, "objects_new_parabolabdp" ) );
323 // Transformation stuff..
324 c
= new InversionConstructor();
326 actions
->add( new ConstructibleAction( c
, "objects_new_inversion" ) );
328 c
= new SimpleObjectTypeConstructor(
329 TranslatedType::instance(),
330 I18N_NOOP( "Translate" ),
331 I18N_NOOP( "The translation of an object by a vector" ),
334 actions
->add( new ConstructibleAction( c
, "objects_new_translation" ) );
336 c
= new SimpleObjectTypeConstructor(
337 PointReflectionType::instance(),
338 I18N_NOOP( "Reflect in Point" ),
339 I18N_NOOP( "An object reflected in a point" ),
342 actions
->add( new ConstructibleAction( c
, "objects_new_pointreflection" ) );
344 c
= new SimpleObjectTypeConstructor(
345 LineReflectionType::instance(),
346 I18N_NOOP( "Reflect in Line" ),
347 I18N_NOOP( "An object reflected in a line" ),
350 actions
->add( new ConstructibleAction( c
, "objects_new_linereflection" ) );
352 c
= new SimpleObjectTypeConstructor(
353 RotationType::instance(),
354 I18N_NOOP( "Rotate" ),
355 I18N_NOOP( "An object rotated by an angle around a point" ),
358 actions
->add( new ConstructibleAction( c
, "objects_new_rotation" ) );
360 c
= new SimpleObjectTypeConstructor(
361 ScalingOverCenterType::instance(),
362 I18N_NOOP( "Scale" ),
363 I18N_NOOP( "Scale an object over a point, by the ratio given by the length of a segment" ),
366 actions
->add( new ConstructibleAction( c
, "objects_new_scalingovercenter" ) );
368 c
= new SimpleObjectTypeConstructor(
369 ScalingOverLineType::instance(),
370 I18N_NOOP( "Scale over Line" ),
371 I18N_NOOP( "An object scaled over a line, by the ratio given by the length of a segment" ),
374 actions
->add( new ConstructibleAction( c
, "objects_new_scalingoverline" ) );
376 c
= new SimpleObjectTypeConstructor(
377 ScalingOverCenter2Type::instance(),
378 I18N_NOOP( "Scale (ratio given by two segments)" ),
379 I18N_NOOP( "Scale an object over a point, by the ratio given by the length of two segments" ),
382 actions
->add( new ConstructibleAction( c
, "objects_new_scalingovercenter2" ) );
384 c
= new SimpleObjectTypeConstructor(
385 ScalingOverLine2Type::instance(),
386 I18N_NOOP( "Scale over Line (ratio given by two segments)" ),
387 I18N_NOOP( "An object scaled over a line, by the ratio given by the length of two segments" ),
390 actions
->add( new ConstructibleAction( c
, "objects_new_scalingoverline2" ) );
392 c
= new SimpleObjectTypeConstructor(
393 SimilitudeType::instance(),
394 I18N_NOOP( "Apply Similitude" ),
395 I18N_NOOP( "Apply a similitude to an object ( the sequence of a scaling and rotation around a center )" ),
398 actions
->add( new ConstructibleAction( c
, "objects_new_similitude" ) );
400 c
= new SimpleObjectTypeConstructor(
401 HarmonicHomologyType::instance(),
402 I18N_NOOP( "Harmonic Homology" ),
403 I18N_NOOP( "The harmonic homology with a given center and a given axis (this is a projective transformation)" ),
404 "harmonichomology" );
406 actions
->add( new ConstructibleAction( c
, "objects_new_harmonichomology" ) );
408 c
= new GenericAffinityConstructor();
410 actions
->add( new ConstructibleAction( c
, "objects_new_genericaffinity" ) );
412 c
= new GenericProjectivityConstructor();
414 actions
->add( new ConstructibleAction( c
, "objects_new_genericprojectivity" ) );
416 c
= new SimpleObjectTypeConstructor(
417 CastShadowType::instance(),
418 I18N_NOOP( "Draw Projective Shadow" ),
419 I18N_NOOP( "The shadow of an object with a given light source and projection plane (indicated by a line)" ),
422 actions
->add( new ConstructibleAction( c
, "objects_new_castshadow" ) );
424 // c = new SimpleObjectTypeConstructor(
425 // ProjectiveRotationType::instance(),
426 // I18N_NOOP( "Rotate Projectively" ),
427 // I18N_NOOP( "An object projectively rotated by an angle and a half-line" ),
428 // "projectiverotation" );
430 // actions->add( new ConstructibleAction( c, "objects_new_projectiverotation" ) );
432 c
= new MultiObjectTypeConstructor(
433 ConicAsymptoteType::instance(),
434 I18N_NOOP( "Asymptotes of a Hyperbola" ),
435 I18N_NOOP( "The two asymptotes of a hyperbola." ),
436 "conicasymptotes", -1, 1 );
438 actions
->add( new ConstructibleAction( c
, "objects_new_lineconicasymptotes" ) );
440 c
= new ConicRadicalConstructor();
442 actions
->add( new ConstructibleAction( c
, "objects_new_lineconicradical") );
444 /* ----------- start polygons --------- */
446 c
= new SimpleObjectTypeConstructor(
447 TriangleB3PType::instance(),
448 I18N_NOOP( "Triangle by Its Vertices" ),
449 I18N_NOOP( "Construct a triangle given its three vertices." ),
452 actions
->add( new ConstructibleAction( c
, "objects_new_trianglebtp" ) );
454 c
= new PolygonBNPTypeConstructor();
456 actions
->add( new ConstructibleAction( c
, "objects_new_polygonbnp" ));
458 c
= new PolygonBCVConstructor();
460 actions
->add( new ConstructibleAction( c
, "objects_new_polygonbcv" ) );
462 c
= new PolygonVertexTypeConstructor();
464 actions
->add( new ConstructibleAction( c
, "objects_new_polygonvertices" ));
466 c
= new PolygonSideTypeConstructor();
468 actions
->add( new ConstructibleAction( c
, "objects_new_polygonsides" ));
470 c
= new SimpleObjectTypeConstructor(
471 ConvexHullType::instance(), I18N_NOOP( "Convex Hull" ),
472 I18N_NOOP( "A polygon that corresponds to the convex hull of another polygon" ),
475 actions
->add( new ConstructibleAction( c
, "objects_new_convexhull" ) );
477 /* ----------- end polygons --------- */
479 c
= new LocusConstructor();
481 actions
->add( new ConstructibleAction( c
, "objects_new_locus" ) );
484 c
= new TestConstructor(
485 AreParallelType::instance(),
486 I18N_NOOP( "Parallel Test" ),
487 I18N_NOOP( "Test whether two given lines are parallel" ),
490 actions
->add( new ConstructibleAction( c
, "objects_new_areparallel" ) );
492 c
= new TestConstructor(
493 AreOrthogonalType::instance(),
494 I18N_NOOP( "Orthogonal Test" ),
495 I18N_NOOP( "Test whether two given lines are orthogonal" ),
498 actions
->add( new ConstructibleAction( c
, "objects_new_areorthogonal" ) );
500 c
= new TestConstructor(
501 AreCollinearType::instance(),
502 I18N_NOOP( "Collinear Test" ),
503 I18N_NOOP( "Test whether three given points are collinear" ),
506 actions
->add( new ConstructibleAction( c
, "objects_new_arecollinear" ) );
508 c
= new TestConstructor(
509 ContainsTestType::instance(),
510 I18N_NOOP( "Contains Test" ),
511 I18N_NOOP( "Test whether a given curve contains a given point" ),
514 actions
->add( new ConstructibleAction( c
, "objects_new_containstest" ) );
516 c
= new TestConstructor(
517 InPolygonTestType::instance(),
518 I18N_NOOP( "In Polygon Test" ),
519 I18N_NOOP( "Test whether a given polygon contains a given point" ),
522 actions
->add( new ConstructibleAction( c
, "objects_new_inpolygontest" ) );
524 c
= new TestConstructor(
525 ConvexPolygonTestType::instance(),
526 I18N_NOOP( "Convex Polygon Test" ),
527 I18N_NOOP( "Test whether a given polygon is convex" ),
530 actions
->add( new ConstructibleAction( c
, "objects_new_convexpolygontest" ) );
532 c
= new TestConstructor(
533 SameDistanceType::instance(),
534 I18N_NOOP( "Distance Test" ),
535 I18N_NOOP( "Test whether a given point have the same distance from a given point "
536 "and from another given point" ),
540 actions
->add( new ConstructibleAction( c
, "objects_new_distancetest" ) );
542 c
= new TestConstructor(
543 VectorEqualityTestType::instance(),
544 I18N_NOOP( "Vector Equality Test" ),
545 I18N_NOOP( "Test whether two vectors are equal" ),
549 actions
->add( new ConstructibleAction( c
, "objects_new_vectorequalitytest" ) );
551 c
= new MeasureTransportConstructor();
553 actions
->add( new ConstructibleAction( c
, "objects_new_measuretransport" ));
555 // c = new SimpleObjectTypeConstructor(
556 // MeasureTransportType::instance(),
557 // I18N_NOOP( "Measure Transport" ),
558 // I18N_NOOP( "Transport the measure of a segment or arc over a line or circle." ),
559 // "measuretransport" );
561 // actions->add( new ConstructibleAction( c, "objects_new_measuretransport" ) );
563 // the generic intersection constructor..
564 c
= new GenericIntersectionConstructor();
566 actions
->add( new ConstructibleAction( c
, "objects_new_intersection", Qt::Key_I
) );
568 // the generic tangent constructor
569 c
= new TangentConstructor();
571 actions
->add( new ConstructibleAction( c
, "objects_new_tangent", Qt::Key_T
) );
573 // the generic center of curvature constructor
574 c
= new CocConstructor();
576 actions
->add( new ConstructibleAction( c
, "objects_new_centerofcurvature" ) );
578 actions
->add( new ConstructPointAction( "objects_new_normalpoint" ) );
579 actions
->add( new ConstructTextLabelAction( "objects_new_textlabel" ) );
580 actions
->add( new AddFixedPointAction( "objects_new_point_xy" ) );
582 #ifdef KIG_ENABLE_PYTHON_SCRIPTING
583 #include "../scripting/script-common.h"
584 actions
->add( new NewScriptAction(
585 I18N_NOOP( "Python Script" ),
586 I18N_NOOP( "Construct a new Python script." ),
587 "objects_new_script_python",
588 ScriptType::Python
) );
592 actions
->add( new TestAction( "test_stuff" ) );