• 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
  • scripting
python_scripter.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 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 // mp: following a kind suggestion by David Faure the Python.h include has
19 // been moved before all qt includes in order to avoid a clash related to
20 // the "slots" identifier
21 // krazy:excludeall=includes
22 #undef _XOPEN_SOURCE // it will be defined inside Python
23 #include <Python.h>
24 #include "python_scripter.h"
25 
26 #include <iostream>
27 #include <string>
28 
29 #include <boost/python.hpp>
30 #include <boost/mpl/bool.hpp>
31 
32 #include "../misc/common.h"
33 #include "../misc/coordinate.h"
34 #include "../misc/cubic-common.h"
35 #include "../misc/kigtransform.h"
36 #include "../objects/bogus_imp.h"
37 #include "../objects/common.h"
38 #include "../objects/circle_imp.h"
39 #include "../objects/cubic_imp.h"
40 #include "../objects/line_imp.h"
41 #include "../objects/other_imp.h"
42 #include "../objects/point_imp.h"
43 #include "../objects/text_imp.h"
44 #include "../objects/polygon_imp.h"
45 
46 using namespace boost::python;
47 
48 BOOST_PYTHON_MODULE_INIT( kig )
49 {
50  class_<Coordinate>( "Coordinate" )
51  .def( init<double, double>() )
52  .def( init<const Coordinate&>() )
53  .def( "invalidCoord", &Coordinate::invalidCoord )
54  .staticmethod( "invalidCoord" )
55  .def( "valid", &Coordinate::valid )
56  .def( "distance", &Coordinate::distance )
57  .def( "length", &Coordinate::length )
58  .def( "squareLength", &Coordinate::squareLength )
59  .def( "orthogonal", &Coordinate::orthogonal )
60  .def( "round", &Coordinate::round )
61  .def( "normalize", &Coordinate::normalize )
62  .def( -self )
63 // .def( self = self )
64  .def( self += self )
65  .def( self -= self )
66  .def( self *= other<double>() )
67  .def( self *= other<int>() )
68  .def( self /= other<double>() )
69  .def( self / other<double>() )
70  .def( self + self )
71  .def( self - self )
72  .def( self * other<double>() )
73  .def( other<double>() * self )
74  .def( self * self )
75  .def_readwrite( "x", &Coordinate::x )
76  .def_readwrite( "y", &Coordinate::y )
77  ;
78 
79  class_<LineData>( "LineData" )
80  .def( init<Coordinate, Coordinate>() )
81  .def( "dir", &LineData::dir )
82  .def( "length", &LineData::length )
83  .def( "isParallelTo", &LineData::isParallelTo )
84  .def_readwrite( "a", &LineData::a )
85  .def_readwrite( "b", &LineData::b )
86  ;
87 
88  // we need this cause Transformation::apply is overloaded and
89  // otherwise using Transformation::apply would be ambiguous..
90  const Coordinate (Transformation::*transformapplyfunc)( const Coordinate& ) const = &Transformation::apply;
91  class_<Transformation>( "Transformation", no_init )
92  .def( "apply", transformapplyfunc )
93  .def( "isHomothetic", &Transformation::isHomothetic )
94  .def( "inverse", &Transformation::inverse )
95  .def( "identity", &Transformation::identity )
96  .def( "translation", &Transformation::translation )
97  .def( "rotation", &Transformation::rotation )
98  .def( "pointReflection", &Transformation::pointReflection )
99  .def( "lineReflection", &Transformation::lineReflection )
100  .def( "castShadow", &Transformation::castShadow )
101  .def( "projectiveRotation", &Transformation::projectiveRotation )
102  .def( "scalingOverPoint", &Transformation::scalingOverPoint )
103  .def( "scalingOverLine", &Transformation::scalingOverLine )
104  .def( self * self )
105  .def( self == self )
106  .staticmethod( "identity" )
107  .staticmethod( "translation" )
108  .staticmethod( "rotation" )
109  .staticmethod( "pointReflection" )
110  .staticmethod( "lineReflection" )
111  .staticmethod( "castShadow" )
112  .staticmethod( "projectiveRotation" )
113  .staticmethod( "scalingOverPoint" )
114  .staticmethod( "scalingOverLine" )
115  ;
116 
117  class_<ObjectImpType, boost::noncopyable>( "ObjectType", no_init )
118  .def( "fromInternalName", &ObjectImpType::typeFromInternalName,
119  return_value_policy<reference_existing_object>() )
120  .staticmethod( "fromInternalName" )
121  .def( "inherits", &ObjectImpType::inherits )
122  .def( "internalName", &ObjectImpType::internalName )
123  .def( "translatedName", &ObjectImpType::translatedName )
124  .def( "selectStatement", &ObjectImpType::selectStatement )
125  .def( "removeAStatement", &ObjectImpType::removeAStatement )
126  .def( "addAStatement", &ObjectImpType::addAStatement )
127  .def( "moveAStatement", &ObjectImpType::moveAStatement )
128  .def( "attachToThisStatement", &ObjectImpType::attachToThisStatement )
129  ;
130 
131  class_<ObjectImp, boost::noncopyable>( "Object", no_init )
132  .def( "stype", &ObjectImp::stype,
133  return_value_policy<reference_existing_object>() )
134  .staticmethod( "stype" )
135  .def( "inherits", &ObjectImp::inherits )
136  .def( "transform", &ObjectImp::transform,
137  return_value_policy<manage_new_object>() )
138  .def( "valid", &ObjectImp::valid )
139  .def( "copy", &ObjectImp::copy,
140  return_value_policy<manage_new_object>() )
141  .def( "equals", &ObjectImp::equals )
142  ;
143 
144  class_<CurveImp, bases<ObjectImp>, boost::noncopyable>( "Curve", no_init )
145  .def( "stype", &CurveImp::stype,
146  return_value_policy<reference_existing_object>() )
147  .staticmethod( "stype" )
148 // .def( "getParam", &CurveImp::getParam )
149 // .def( "getPoint", &CurveImp::getPoint );
150  ;
151  class_<PointImp, bases<ObjectImp> >( "Point", init<Coordinate>() )
152  .def( "stype", &PointImp::stype,
153  return_value_policy<reference_existing_object>() )
154  .staticmethod( "stype" )
155  .def( "coordinate", &PointImp::coordinate,
156  return_internal_reference<1>() )
157  .def( "setCoordinate", &PointImp::setCoordinate )
158  ;
159 
160  class_<AbstractLineImp, bases<CurveImp>, boost::noncopyable >( "AbstractLine", no_init )
161  .def( "stype", &AbstractLineImp::stype,
162  return_value_policy<reference_existing_object>() )
163  .staticmethod( "stype" )
164  .def( "slope", &AbstractLineImp::slope )
165  .def( "equationString", &AbstractLineImp::equationString )
166  .def( "data", &AbstractLineImp::data )
167  ;
168 
169  class_<SegmentImp, bases<AbstractLineImp> >( "Segment", init<Coordinate, Coordinate>() )
170  .def( "stype", &SegmentImp::stype,
171  return_value_policy<reference_existing_object>() )
172  .staticmethod( "stype" )
173  .def( init<LineData>() )
174  .def( "length", &SegmentImp::length )
175  ;
176 
177  class_<RayImp, bases<AbstractLineImp> >( "Ray", init<Coordinate, Coordinate>() )
178  .def( "stype", &RayImp::stype,
179  return_value_policy<reference_existing_object>() )
180  .staticmethod( "stype" )
181  .def( init<LineData>() )
182  ;
183 
184  class_<LineImp, bases<AbstractLineImp> >( "Line", init<Coordinate, Coordinate>() )
185  .def( "stype", &LineImp::stype,
186  return_value_policy<reference_existing_object>() )
187  .staticmethod( "stype" )
188  .def( init<LineData>() )
189  ;
190 
191  class_<ConicCartesianData>( "ConicCartesianData", init<double,double,double,double,double,double>() )
192  .def( init<ConicPolarData>() )
193  .def( "invalidData", &ConicCartesianData::invalidData )
194  .staticmethod( "invalidData" )
195  .def( "valid", &ConicCartesianData::valid )
196 // .def( init<double[6]>() )
197 // .def_readwrite( "coeffs", &ConicCartesianData::coeffs )
198  ;
199 
200  class_<ConicPolarData>( "ConicPolarData", init<Coordinate, double, double, double>() )
201  .def( init<ConicCartesianData>() )
202  .def_readwrite( "focus1", &ConicPolarData::focus1 )
203  .def_readwrite( "pdimen", &ConicPolarData::pdimen )
204  .def_readwrite( "ecostheta0", &ConicPolarData::ecostheta0 )
205  .def_readwrite( "esintheta0", &ConicPolarData::esintheta0 )
206  ;
207 
208  class_<ConicImp, bases<CurveImp>, boost::noncopyable >( "Conic", no_init )
209  .def( "stype", &ConicImp::stype,
210  return_value_policy<reference_existing_object>() )
211  .staticmethod( "stype" )
212  .def( "conicType", &ConicImp::conicType )
213 // .def( "conicTypeString", &ConicImp::conicTypeString )
214 // .def( "cartesianEquationString", &ConicImp::cartesianEquationString )
215 // .def( "polarEquationString", &ConicImp::polarEquationString )
216  .def( "cartesianData", &ConicImp::cartesianData )
217  .def( "polarData", &ConicImp::polarData )
218  .def( "focus1", &ConicImp::focus1 )
219  .def( "focus2", &ConicImp::focus2 )
220  ;
221 
222  class_<ConicImpCart, bases<ConicImp> >( "CartesianConic", init<ConicCartesianData>() )
223  ;
224  class_<ConicImpPolar, bases<ConicImp> >( "PolarConic", init<ConicPolarData>() )
225  ;
226 
227  class_<CircleImp, bases<ConicImp> >( "Circle", init<Coordinate, double>() )
228  .def( "stype", &CircleImp::stype,
229  return_value_policy<reference_existing_object>() )
230  .staticmethod( "stype" )
231  .def( "center", &CircleImp::center )
232  .def( "radius", &CircleImp::radius )
233  .def( "squareRadius", &CircleImp::squareRadius )
234  .def( "surface", &CircleImp::surface )
235  .def( "circumference", &CircleImp::circumference )
236  ;
237 
238  class_<FilledPolygonImp, bases<ObjectImp>, boost::noncopyable>( "Polygon", no_init )
239  .def( "stype", &FilledPolygonImp::stype,
240  return_value_policy<reference_existing_object>() )
241  .staticmethod( "stype" )
242  .def( "npoints", &FilledPolygonImp::npoints )
243  .def( "perimeter", &FilledPolygonImp::cperimeter )
244  .def( "area", &FilledPolygonImp::area )
245  .def( "windingNumber", &FilledPolygonImp::windingNumber )
246  ;
247 
248  class_<VectorImp, bases<CurveImp> >( "Vector", init<Coordinate, Coordinate>() )
249  .def( "stype", &VectorImp::stype,
250  return_value_policy<reference_existing_object>() )
251  .staticmethod( "stype" )
252  .def( "length", &VectorImp::length )
253  .def( "dir", &VectorImp::dir )
254  .def( "data", &VectorImp::data )
255  ;
256 
257  //TODO find how to mark default
258  class_<AngleImp, bases<ObjectImp> >( "Angle", init<Coordinate, double, double, bool>() )
259  .def( "stype", &AngleImp::stype,
260  return_value_policy<reference_existing_object>() )
261  .staticmethod( "stype" )
262  .def( "size", &AngleImp::size )
263  .def( "point", &AngleImp::point )
264  .def( "startAngle", &AngleImp::startAngle )
265  .def( "angle", &AngleImp::angle )
266  ;
267 
268  class_<ArcImp, bases<ObjectImp> >( "Arc", init<Coordinate, double, double, double>() )
269  .def( "stype", &ArcImp::stype,
270  return_value_policy<reference_existing_object>() )
271  .staticmethod( "stype" )
272  .def( "startAngle", &ArcImp::startAngle )
273  .def( "angle", &ArcImp::angle )
274  .def( "radius", &ArcImp::radius )
275  .def( "center", &ArcImp::center )
276  .def( "firstEndPoint", &ArcImp::firstEndPoint )
277  .def( "secondEndPoint", &ArcImp::secondEndPoint )
278  .def( "sectorSurface", &ArcImp::sectorSurface )
279  ;
280 
281  class_<BogusImp, bases<ObjectImp>, boost::noncopyable >( "BogusObject", no_init )
282  .def( "stype", &BogusImp::stype,
283  return_value_policy<reference_existing_object>() )
284  .staticmethod( "stype" )
285  ;
286 
287  class_<InvalidImp, bases<BogusImp> >( "InvalidObject", init<>() )
288  .def( "stype", &InvalidImp::stype,
289  return_value_policy<reference_existing_object>() )
290  .staticmethod( "stype" )
291  ;
292 
293  class_<DoubleImp, bases<BogusImp> >( "DoubleObject", init<double>() )
294  .def( "stype", &DoubleImp::stype,
295  return_value_policy<reference_existing_object>() )
296  .staticmethod( "stype" )
297  .def( "data", &DoubleImp::data )
298  .def( "setData", &DoubleImp::setData )
299  ;
300 
301  class_<IntImp, bases<BogusImp> >( "IntObject", init<int>() )
302  .def( "stype", &IntImp::stype,
303  return_value_policy<reference_existing_object>() )
304  .staticmethod( "stype" )
305  .def( "data", &IntImp::data )
306  .def( "setData", &IntImp::setData )
307  ;
308 
309  class_<StringImp, bases<BogusImp> >( "StringObject", init<char*>() )
310  .def( "stype", &StringImp::stype,
311  return_value_policy<reference_existing_object>() )
312  .staticmethod( "stype" )
313 // .def( "data", &StringImp::data )
314 // .def( "setData", &StringImp::setData )
315  ;
316 
317  class_<TestResultImp, bases<BogusImp> >( "TestResultObject", no_init )
318  .def( "stype", &TestResultImp::stype,
319  return_value_policy<reference_existing_object>() )
320  .staticmethod( "stype" )
321 // .def( "data", &TestResultImp::data )
322  ;
323 
324 // class_<TextImp, bases<ObjectImp> >( "Text", init<string, Coordinate, bool>() )
325 // .def( "stype", &TextImp::stype,
326 // return_value_policy<reference_existing_object>() )
327 // .staticmethod( "stype" )
328 // .def( "text", &TextImp::text )
329 // .def( "coordinate", &TextImp::coordinate )
330 // .def( "hasFrame", &TextImp::hasFrame )
331 // ;
332 
333  class_<NumericTextImp, bases<ObjectImp> >( "NumericObject", no_init )
334  .def( "stype", &NumericTextImp::stype,
335  return_value_policy<reference_existing_object>() )
336  .staticmethod( "stype" )
337  .def( "value", &NumericTextImp::getValue )
338  ;
339 
340  class_<BoolTextImp, bases<ObjectImp> >( "BooleanObject", no_init )
341  .def( "stype", &BoolTextImp::stype,
342  return_value_policy<reference_existing_object>() )
343  .staticmethod( "stype" )
344  .def( "value", &BoolTextImp::getValue )
345  ;
346 
347  class_<CubicCartesianData>( "CubicCartesianData", init<double,double,double,double,double,double,double,double,double,double>() )
348  .def( "invalidData", &CubicCartesianData::invalidData )
349  .staticmethod( "invalidData" )
350  .def( "valid", &CubicCartesianData::valid )
351 // .def( init<double[10]>() )
352 // .def_readwrite( "coeffs", &CubicCartesianData::coeffs )
353  ;
354 
355  class_<CubicImp, bases<CurveImp> >( "Cubic", init<CubicCartesianData>() )
356  .def( "stype", &CubicImp::stype,
357  return_value_policy<reference_existing_object>() )
358  .staticmethod( "stype" )
359  .def( "data", &CubicImp::data )
360  ;
361 
362 }
363 
364 PythonScripter* PythonScripter::instance()
365 {
366  static PythonScripter t;
367  return &t;
368 }
369 
370 class PythonScripter::Private
371 {
372 public:
373  dict mainnamespace;
374 };
375 
376 // allocates a new string using new [], and copies contents into it..
377 static char* newstring( const char* contents )
378 {
379  char* ret = new char[strlen( contents ) + 1];
380  strcpy( ret, contents );
381  return ret;
382 }
383 
384 PythonScripter::PythonScripter()
385 {
386  d = new Private;
387 
388  // tell the python interpreter about our API..
389 
390  // the newstring stuff is to prevent warnings about conversion from
391  // const char* to char*..
392  char* s = newstring( "kig" );
393  PyImport_AppendInittab( s, initkig );
394  // we can't delete this yet, since python keeps a pointer to it..
395  // This means we have a small but harmless memory leak here, but it
396  // doesn't hurt at all, since it could only be freed at the end of
397  // the program, at which time it is freed by the system anyway if we
398  // don't do it..
399  //delete [] s;
400 
401  Py_Initialize();
402 
403  s = newstring( "import math; from math import *;" );
404  PyRun_SimpleString( s );
405  delete [] s;
406  s = newstring( "import kig; from kig import *;" );
407  PyRun_SimpleString( s );
408  delete [] s;
409  s = newstring( "import traceback;" );
410  PyRun_SimpleString( s );
411  delete [] s;
412 
413  // find the main namespace..
414 
415  s = newstring( "__main__" );
416  handle<> main_module( borrowed( PyImport_AddModule( s ) ) );
417  delete [] s;
418 
419  handle<> mnh(borrowed( PyModule_GetDict(main_module.get()) ));
420  d->mainnamespace = extract<dict>( mnh.get() );
421 }
422 
423 PythonScripter::~PythonScripter()
424 {
425  PyErr_Clear();
426  Py_Finalize();
427  delete d;
428 }
429 
430 class CompiledPythonScript::Private
431 {
432 public:
433  int ref;
434  object calcfunc;
435  // TODO
436 // object movefunc;
437 };
438 
439 ObjectImp* CompiledPythonScript::calc( const Args& args, const KigDocument& )
440 {
441  return PythonScripter::instance()->calc( *this, args );
442 }
443 
444 CompiledPythonScript::~CompiledPythonScript()
445 {
446  --d->ref;
447  if ( d->ref == 0 )
448  delete d;
449 }
450 
451 CompiledPythonScript::CompiledPythonScript( Private* ind )
452  : d( ind )
453 {
454  ++d->ref;
455 }
456 
457 CompiledPythonScript PythonScripter::compile( const char* code )
458 {
459  clearErrors();
460  dict retdict;
461  bool error = false;
462  try
463  {
464  (void) PyRun_String( const_cast<char*>( code ), Py_file_input,
465  d->mainnamespace.ptr(), retdict.ptr() );
466  }
467  catch( ... )
468  {
469  error = true;
470  };
471  error |= static_cast<bool>( PyErr_Occurred() );
472  if ( error )
473  {
474  saveErrors();
475  retdict.clear();
476  }
477 
478  // debugging stuff, removed.
479 // std::string dictstring = extract<std::string>( str( retdict ) );
480 
481  CompiledPythonScript::Private* ret = new CompiledPythonScript::Private;
482  ret->ref = 0;
483  ret->calcfunc = retdict.get( "calc" );
484  return CompiledPythonScript( ret );
485 }
486 
487 CompiledPythonScript::CompiledPythonScript( const CompiledPythonScript& s )
488  : d( s.d )
489 {
490  ++d->ref;
491 }
492 
493 std::string PythonScripter::lastErrorExceptionType() const
494 {
495  return lastexceptiontype;
496 }
497 
498 std::string PythonScripter::lastErrorExceptionValue() const
499 {
500  return lastexceptionvalue;
501 }
502 
503 std::string PythonScripter::lastErrorExceptionTraceback() const
504 {
505  return lastexceptiontraceback;
506 }
507 
508 ObjectImp* PythonScripter::calc( CompiledPythonScript& script, const Args& args )
509 {
510  clearErrors();
511  object calcfunc = script.d->calcfunc;
512  try
513  {
514  std::vector<object> objectvect;
515  objectvect.reserve( args.size() );
516 
517  for ( int i = 0; i < (int) args.size(); ++i )
518  {
519  object o( boost::ref( *args[i] ) );
520  objectvect.push_back( o );
521  }
522 
523  handle<> argstuph( PyTuple_New( args.size() ) );
524  for ( int i = 0; i < (int) objectvect.size(); ++i )
525  {
526  PyTuple_SetItem( argstuph.get(), i, (objectvect.begin() +i)->ptr() );
527  };
528  tuple argstup( argstuph );
529 
530  handle<> reth( PyEval_CallObject( calcfunc.ptr(), argstup.ptr() ) );
531 // object resulto = calcfunc( argstup );
532 // handle<> reth( PyEval_CallObject( calcfunc.ptr(), args ) );
533  object resulto( reth );
534 
535  extract<ObjectImp&> result( resulto );
536  if( ! result.check() ) return new InvalidImp;
537  else
538  {
539  ObjectImp& ret = result();
540  return ret.copy();
541  };
542  }
543  catch( ... )
544  {
545  saveErrors();
546 
547  return new InvalidImp;
548  };
549 }
550 
551 void PythonScripter::saveErrors()
552 {
553  erroroccurred = true;
554  PyObject* poexctype;
555  PyObject* poexcvalue;
556  PyObject* poexctraceback;
557  PyErr_Fetch( &poexctype, &poexcvalue, &poexctraceback );
558  handle<> exctypeh( poexctype );
559  handle<> excvalueh( poexcvalue );
560 
561  object exctype( exctypeh );
562  object excvalue( excvalueh );
563  object exctraceback;
564  if ( poexctraceback )
565  {
566  handle<> exctracebackh( poexctraceback );
567  exctraceback = object( exctracebackh );
568  }
569 
570  lastexceptiontype = extract<std::string>( str( exctype ) )();
571  lastexceptionvalue = extract<std::string>( str( excvalue ) )();
572 
573  object printexcfunc = d->mainnamespace[ "traceback" ].attr( "format_exception" );
574 
575  list tracebacklist = extract<list>( printexcfunc( exctype, excvalue, exctraceback ) )();
576  str tracebackstr( "" );
577  while ( true )
578  {
579  try {
580  str s = extract<str>( tracebacklist.pop() );
581  tracebackstr += s;
582  }
583  catch( ... )
584  {
585  break;
586  }
587  }
588 
589  lastexceptiontraceback = extract<std::string>( tracebackstr )();
590  PyErr_Clear();
591 }
592 
593 void PythonScripter::clearErrors()
594 {
595  PyErr_Clear();
596  lastexceptiontype.clear();
597  lastexceptionvalue.clear();
598  lastexceptiontraceback.clear();
599  erroroccurred = false;
600 }
601 
602 bool CompiledPythonScript::valid()
603 {
604  return !!d->calcfunc;
605 }
606 
607 bool PythonScripter::errorOccurred() const
608 {
609  return erroroccurred;
610 }
611 
AbstractPolygonImp::npoints
uint npoints() const
Returns the number of points of this polygon.
Definition: polygon_imp.cc:576
Transformation::translation
static const Transformation translation(const Coordinate &c)
Translation.
Definition: kigtransform.cpp:273
Transformation::scalingOverLine
static const Transformation scalingOverLine(double factor, const LineData &l)
Scaling over Line.
Definition: kigtransform.cpp:324
Transformation::lineReflection
static const Transformation lineReflection(const LineData &l)
Line Reflection.
Definition: kigtransform.cpp:316
AbstractLineImp::data
LineData data() const
Get the LineData for this AbstractLineImp.
Definition: line_imp.cc:359
PythonScripter::errorOccurred
bool errorOccurred() const
Definition: python_scripter.cc:607
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
DoubleImp::setData
void setData(double d)
Set the contained data to d.
Definition: bogus_imp.h:112
BogusImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the BogusImp type.
Definition: bogus_imp.cc:286
NumericTextImp::getValue
double getValue() const
Definition: text_imp.cc:211
ConicPolarData::esintheta0
double esintheta0
The esintheta0 value from the polar equation.
Definition: conic-common.h:118
SegmentImp::length
double length() const
Get the length of this segment.
Definition: line_imp.cc:494
VectorImp::data
LineData data() const
Get the LineData for this vector.
Definition: other_imp.cc:771
ArcImp::sectorSurface
double sectorSurface() const
Return the size of the sector surface of this arc.
Definition: other_imp.cc:493
Transformation::pointReflection
static const Transformation pointReflection(const Coordinate &c)
Point Reflection.
Definition: kigtransform.cpp:285
LineData::dir
const Coordinate dir() const
The direction of the line.
Definition: misc/common.h:72
AngleImp::point
const Coordinate point() const
Return the center of this angle.
Definition: other_imp.h:79
AbstractLineImp::slope
double slope() const
Get the slope of this AbstractLineImp.
Definition: line_imp.cc:235
LineData::b
Coordinate b
Another point on the line.
Definition: misc/common.h:68
ObjectImpType::internalName
const char * internalName() const
Returns an internal name for this ObjectImp type.
Definition: object_imp.cc:235
CompiledPythonScript::calc
ObjectImp * calc(const Args &a, const KigDocument &doc)
Definition: python_scripter.cc:439
DoubleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the DoubleImp type.
Definition: bogus_imp.cc:270
CircleImp::center
const Coordinate center() const
Return the center of this circle.
Definition: circle_imp.cc:210
ObjectImpType::inherits
bool inherits(const ObjectImpType *t) const
Does the ObjectImp type represented by this instance inherit the ObjectImp type represented by t ...
Definition: object_imp.cc:224
Transformation::projectiveRotation
static const Transformation projectiveRotation(double alpha, const Coordinate &d, const Coordinate &t)
Projective Rotation.
Definition: kigtransform.cpp:591
ArcImp::firstEndPoint
Coordinate firstEndPoint() const
Return the start point of this arc.
Definition: other_imp.cc:552
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
DoubleImp::data
double data() const
Get hold of the contained data.
Definition: bogus_imp.h:108
VectorImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the VectorImp type.
Definition: other_imp.cc:613
PythonScripter::instance
static PythonScripter * instance()
Definition: python_scripter.cc:364
PointImp::coordinate
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
Definition: point_imp.h:50
IntImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the IntImp type.
Definition: bogus_imp.cc:278
VectorImp::length
double length() const
Return the length of this vector.
Definition: other_imp.cc:315
IntImp::setData
void setData(int d)
Set the contained data to d.
Definition: bogus_imp.h:151
ObjectImp::stype
static const ObjectImpType * stype()
The ObjectImpType representing the base ObjectImp class.
Definition: object_imp.cc:284
ConicCartesianData::invalidData
static ConicCartesianData invalidData()
Invalid conic.
Definition: conic-common.cpp:883
LineImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the LineImp type.
Definition: line_imp.cc:528
newstring
static char * newstring(const char *contents)
Definition: python_scripter.cc:377
ArcImp::radius
double radius() const
Return the radius of this arc.
Definition: other_imp.cc:537
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
Coordinate::length
double length() const
Length.
Definition: coordinate.cpp:144
PointImp::setCoordinate
void setCoordinate(const Coordinate &c)
Set the coordinate of this PointImp.
Definition: point_imp.cc:133
Transformation::isHomothetic
bool isHomothetic() const
Returns whether this is a homothetic (affine) transformation.
Definition: kigtransform.cpp:681
CircleImp::surface
double surface() const
Return the surface of this circle.
Definition: circle_imp.cc:220
Transformation::castShadow
static const Transformation castShadow(const Coordinate &ls, const LineData &d)
Cast Shadow.
Definition: kigtransform.cpp:550
PythonScripter::CompiledPythonScript
friend class CompiledPythonScript
Definition: python_scripter.h:44
Coordinate::normalize
const Coordinate normalize(double length=1) const
Normalize.
Definition: coordinate.cpp:154
PythonScripter::compile
CompiledPythonScript compile(const char *code)
Definition: python_scripter.cc:457
ObjectImpType::translatedName
QString translatedName() const
The name of this type, translated to the currently used language.
Definition: object_imp.cc:240
AbstractPolygonImp::windingNumber
int windingNumber() const
Definition: polygon_imp.cc:811
ArcImp::angle
double angle() const
Return the dimension in radians of this arc.
Definition: other_imp.cc:547
ObjectImpType::selectStatement
const char * selectStatement() const
Returns a translatable string of the form "Select this %1".
Definition: object_imp.cc:245
TestResultImp::stype
static const ObjectImpType * stype()
Definition: bogus_imp.cc:294
Coordinate::distance
double distance(const Coordinate &p) const
Distance to another Coordinate.
Definition: coordinate.cpp:139
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
Transformation
Class representing a transformation.
Definition: kigtransform.h:37
CubicCartesianData::valid
bool valid() const
Return whether this is a valid CubicCartesianData.
Definition: cubic-common.cc:539
ConicPolarData::focus1
Coordinate focus1
The first focus of this conic.
Definition: conic-common.h:106
ArcImp::secondEndPoint
Coordinate secondEndPoint() const
Return the end point of this arc.
Definition: other_imp.cc:558
ObjectImpType::moveAStatement
QString moveAStatement() const
Returns a translated string of the form "Move a xxx".
Definition: object_imp.cc:265
python_scripter.h
AngleImp::angle
double angle() const
Return the dimension in radians of this angle.
Definition: other_imp.h:87
Transformation::inverse
const Transformation inverse(bool &valid) const
The inverse Transformation.
Definition: kigtransform.cpp:737
LineData::a
Coordinate a
One point on the line.
Definition: misc/common.h:64
PythonScripter
Definition: python_scripter.h:42
ConicPolarData::pdimen
double pdimen
The pdimen value from the polar equation.
Definition: conic-common.h:110
PythonScripter::lastErrorExceptionValue
std::string lastErrorExceptionValue() const
Definition: python_scripter.cc:498
FilledPolygonImp::stype
static const ObjectImpType * stype()
Definition: polygon_imp.cc:660
IntImp::data
int data() const
Get hold of the contained data.
Definition: bogus_imp.h:147
PythonScripter::lastErrorExceptionType
std::string lastErrorExceptionType() const
Definition: python_scripter.cc:493
SegmentImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the SegmentImp type.
Definition: line_imp.cc:545
ConicPolarData::ecostheta0
double ecostheta0
The ecostheta0 value from the polar equation.
Definition: conic-common.h:114
CompiledPythonScript
Definition: python_scripter.h:28
ArcImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the ArcImp type.
Definition: other_imp.cc:629
ArcImp::center
const Coordinate center() const
Return the center of this arc.
Definition: other_imp.cc:532
CircleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CircleImp type.
Definition: circle_imp.cc:342
Coordinate::squareLength
double squareLength() const
Square length.
Definition: coordinate.h:163
ArcImp::startAngle
double startAngle() const
Return the start angle in radians of this arc.
Definition: other_imp.cc:542
LineData::isParallelTo
bool isParallelTo(const LineData &l) const
Return true if this line is parallel to l.
Definition: common.cpp:459
ObjectImpType::typeFromInternalName
static const ObjectImpType * typeFromInternalName(const char *n)
Returns the type with name n.
Definition: object_imp.cc:270
AngleImp::startAngle
double startAngle() const
Return the start angle in radians of this angle.
Definition: other_imp.h:83
Transformation::scalingOverPoint
static const Transformation scalingOverPoint(double factor, const Coordinate &center=Coordinate())
Scaling over Point.
Definition: kigtransform.cpp:260
Transformation::apply
const Coordinate apply(const double x0, const double x1, const double x2) const
Apply this Tranformation.
Definition: kigtransform.cpp:611
InvalidImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the InvalidImp type.
Definition: bogus_imp.cc:213
ConicImp::focus1
virtual Coordinate focus1() const
Return the first focus of this conic.
Definition: conic_imp.cc:290
Coordinate::invalidCoord
static Coordinate invalidCoord()
Create an invalid Coordinate.
Definition: coordinate.cpp:171
ObjectImpType::removeAStatement
QString removeAStatement() const
Returns a translated string of the form "Remove a xxx".
Definition: object_imp.cc:255
ConicImp::polarData
virtual const ConicPolarData polarData() const =0
Return the polar representation of this conic.
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
CubicImp::data
const CubicCartesianData data() const
Return the cartesian representation of this cubic.
Definition: cubic_imp.cc:331
AbstractLineImp::equationString
const QString equationString() const
Get a string containing the equation of this line in the form "y = a * x + b ".
Definition: line_imp.cc:241
ConicImp::cartesianData
virtual const ConicCartesianData cartesianData() const
Return the cartesian representation of this conic.
Definition: conic_imp.cc:285
ConicImp::conicType
virtual int conicType() const
Type of conic.
Definition: conic_imp.cc:191
BoolTextImp::getValue
bool getValue() const
Definition: text_imp.cc:303
BOOST_PYTHON_MODULE_INIT
BOOST_PYTHON_MODULE_INIT(kig)
Definition: python_scripter.cc:48
CurveImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CurveImp type.
Definition: curve_imp.cc:27
ConicImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the ConicImp type.
Definition: conic_imp.cc:380
Transformation::identity
static const Transformation identity()
Identity.
Definition: kigtransform.cpp:250
AngleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AngleImp type.
Definition: other_imp.cc:597
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
NumericTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:189
PythonScripter::lastErrorExceptionTraceback
std::string lastErrorExceptionTraceback() const
Definition: python_scripter.cc:503
ConicCartesianData::valid
bool valid() const
Test validity.
Definition: conic-common.cpp:890
StringImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the StringImp type.
Definition: bogus_imp.cc:220
ObjectImp::copy
virtual ObjectImp * copy() const =0
Returns a copy of this ObjectImp.
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
Coordinate::orthogonal
const Coordinate orthogonal() const
Orthogonal.
Definition: coordinate.cpp:149
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
ObjectImpType::attachToThisStatement
QString attachToThisStatement() const
Returns a translated string of the form "Attach to this xxx".
Definition: object_imp.cc:311
ObjectImp::valid
bool valid() const
Returns true if this is a valid ObjectImp.
Definition: object_imp.cc:41
ConicImp::focus2
virtual Coordinate focus2() const
Return the second focus of this conic.
Definition: conic_imp.cc:306
ObjectImpType::addAStatement
QString addAStatement() const
Returns a translated string of the form "Add a xxx".
Definition: object_imp.cc:260
ObjectImp::equals
virtual bool equals(const ObjectImp &rhs) const =0
Returns true if this ObjectImp is equal to rhs.
CircleImp::squareRadius
double squareRadius() const
Return the square radius of this circle.
Definition: circle_imp.cc:225
AngleImp::size
double size() const
Return the size in radians of this angle.
Definition: other_imp.cc:181
ObjectImp::transform
virtual ObjectImp * transform(const Transformation &t) const =0
Return this ObjectImp, transformed by the transformation t.
AbstractPolygonImp::cperimeter
double cperimeter() const
Definition: polygon_imp.cc:591
CubicImp::stype
static const ObjectImpType * stype()
Definition: cubic_imp.cc:352
Transformation::rotation
static const Transformation rotation(double angle, const Coordinate &center=Coordinate())
Rotation.
Definition: kigtransform.cpp:658
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
BoolTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:281
PythonScripter::calc
ObjectImp * calc(CompiledPythonScript &script, const Args &args)
Definition: python_scripter.cc:508
CompiledPythonScript::valid
bool valid()
Definition: python_scripter.cc:602
CircleImp::circumference
double circumference() const
Return the circumference of this circle.
Definition: circle_imp.cc:230
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
CompiledPythonScript::~CompiledPythonScript
~CompiledPythonScript()
Definition: python_scripter.cc:444
AbstractPolygonImp::area
double area() const
Returns the area of this polygon.
Definition: polygon_imp.cc:602
CubicCartesianData::invalidData
static CubicCartesianData invalidData()
Create an invalid CubicCartesianData.
Definition: cubic-common.cc:532
Coordinate::round
const Coordinate round() const
Round.
Definition: coordinate.cpp:160
LineData::length
double length() const
The length from a to b.
Definition: misc/common.h:76
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