• 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
  • filters
cabri-filter.cc
Go to the documentation of this file.
1 
22 #include "cabri-filter.h"
23 
24 #include "cabri-utils.h"
25 
26 #include "../kig/kig_document.h"
27 #include "../misc/coordinate.h"
28 #include "../misc/rect.h"
29 #include "../objects/arc_type.h"
30 #include "../objects/angle_type.h"
31 #include "../objects/bogus_imp.h"
32 #include "../objects/circle_imp.h"
33 #include "../objects/circle_type.h"
34 #include "../objects/conic_types.h"
35 #include "../objects/curve_imp.h"
36 #include "../objects/intersection_types.h"
37 #include "../objects/inversion_type.h"
38 #include "../objects/line_imp.h"
39 #include "../objects/line_type.h"
40 #include "../objects/object_calcer.h"
41 #include "../objects/object_drawer.h"
42 #include "../objects/object_factory.h"
43 #include "../objects/object_holder.h"
44 #include "../objects/other_imp.h"
45 #include "../objects/other_type.h"
46 #include "../objects/point_imp.h"
47 #include "../objects/point_type.h"
48 #include "../objects/polygon_imp.h"
49 #include "../objects/polygon_type.h"
50 #include "../objects/transform_types.h"
51 #include "../objects/vector_type.h"
52 
53 #include <qcolor.h>
54 #include <qfile.h>
55 #include <qregexp.h>
56 
57 #include <kdebug.h>
58 #include <klocale.h>
59 
60 #include <iterator>
61 
62 static ObjectTypeCalcer* intersectionPoints( const std::vector<ObjectCalcer*>& parents, int which )
63 {
64  if ( parents.size() != 2 ) return 0;
65  int nlines = 0;
66  int ncircles = 0;
67  int nconics = 0;
68  int narcs = 0;
69  for ( int i = 0; i < 2; ++i )
70  {
71  if ( parents[i]->imp()->inherits( AbstractLineImp::stype() ) ) ++nlines;
72  else if ( parents[i]->imp()->inherits( CircleImp::stype() ) ) { ++ncircles; ++nconics; }
73  else if ( parents[i]->imp()->inherits( ConicImp::stype() ) ) ++nconics;
74  else if ( parents[i]->imp()->inherits( ArcImp::stype() ) ) ++narcs;
75  else return 0;
76  };
77 #ifdef CABRI_DEBUG
78  kDebug() << "which: " << which;
79 #endif
80  if ( nlines == 2 )
81  return which == -1 ? new ObjectTypeCalcer( LineLineIntersectionType::instance(), parents ) : 0;
82  else if ( nlines == 1 && nconics == 1 )
83  {
84  std::vector<ObjectCalcer*> intparents( parents );
85  intparents.push_back( new ObjectConstCalcer( new IntImp( which ) ) );
86  return new ObjectTypeCalcer( ConicLineIntersectionType::instance(), intparents );
87  }
88 /*
89  else if ( ncircles == 2 )
90  {
91  std::vector<ObjectCalcer*> intparents( parents );
92  intparents.push_back( new ObjectConstCalcer( new IntImp( which ) ) );
93  return new ObjectTypeCalcer( CircleCircleIntersectionType::instance(), intparents );
94  }
95 */
96  else if ( nlines == 0 && nconics == 2 )
97  {
98  std::vector<ObjectCalcer*> rparents( parents );
99  rparents.push_back( new ObjectConstCalcer( new IntImp( 1 ) ) );
100  rparents.push_back( new ObjectConstCalcer( new IntImp( 1 ) ) );
101  rparents.push_back( new ObjectTypeCalcer( ConicRadicalType::instance(), rparents ) );
102  std::vector<ObjectCalcer*> iparents;
103  iparents.push_back( parents[0] );
104  iparents.push_back( rparents.back() );
105  iparents.push_back( new ObjectConstCalcer( new IntImp( which ) ) );
106  return new ObjectTypeCalcer( ConicLineIntersectionType::instance(), iparents );
107  }
108  else if ( nlines == 1 && narcs == 1 )
109  {
110  std::vector<ObjectCalcer*> intparents( parents );
111  intparents.push_back( new ObjectConstCalcer( new IntImp( which ) ) );
112  return new ObjectTypeCalcer( ArcLineIntersectionType::instance(), intparents );
113  }
114  else return 0;
115 }
116 
117 static int priorTo( const std::vector<uint>& ids, uint id )
118 {
119  int res = 0;
120  for ( std::vector<uint>::const_iterator it = ids.begin(); it != ids.end(); ++it )
121  if ( id > *it ) ++res;
122  return res;
123 }
124 
125 KigFilterCabri::KigFilterCabri()
126 {
127 }
128 
129 KigFilterCabri::~KigFilterCabri()
130 {
131 }
132 
133 bool KigFilterCabri::supportMime( const QString& mime )
134 {
135  // ugly hack to avoid duplicate extension ( XFig and Cabri files
136  // have the same .fig extension ).
137  return ( mime == "image/x-xfig" ) ||
138  ( mime == "application/x-cabri" );
139 }
140 
141 KigDocument* KigFilterCabri::load( const QString& file )
142 {
143  QFile f( file );
144  if ( ! f.open( QIODevice::ReadOnly ) )
145  {
146  fileNotFound( file );
147  return 0;
148  }
149 
150  QString s = CabriNS::readLine( f );
151  QRegExp header( "Figure Cabri\\s?II (Plus )?vers\\. (MS-Windows|DOS) ((\\d+)\\.(\\d+)(\\.(\\d+))?(\\.(\\d+))?|(\\d+)\\.x \\((\\d+)\\.(\\d+)\\))(, ([^,]+), t=(\\d+)s)?" );
152  header.setCaseSensitivity( Qt::CaseInsensitive );
153  if ( !header.exactMatch( s ) )
154  {
155  if ( s.startsWith( "#FIG " ) )
156  {
157  notSupported( file, i18n( "This is an XFig file, not a Cabri figure." ) );
158  return 0;
159  }
160  else
161  KIG_FILTER_PARSE_ERROR;
162  }
163 
164  bool ok = true;
165  QString majorstr = header.cap( 4 );
166  if ( majorstr.isEmpty() )
167  majorstr = header.cap( 11 );
168  int major = majorstr.toInt( &ok );
169  bool ok2 = true;
170  QString minorstr = header.cap( 5 );
171  if ( minorstr.isEmpty() )
172  minorstr = header.cap( 12 );
173  int minor = minorstr.toInt( &ok2 );
174  if ( !ok || !ok2 )
175  KIG_FILTER_PARSE_ERROR;
176 
177  CabriNS::CabriVersion curVer;
178  CabriReader* reader = 0;
179 
180 #ifdef CABRI_DEBUG
181  kDebug() << ">>>>>>>>> version: " << header.cap( 3 );
182  if ( !header.cap( 13 ).isEmpty() )
183  {
184  kDebug() << ">>>>>>>>> session file:";
185  kDebug() << ">>>>>>>>> -> time = " << header.cap( 15 ) << " sec";
186  kDebug() << ">>>>>>>>> -> action = \"" << header.cap( 14 ) << "\"";
187  }
188 #endif
189  if ( ( major == 1 ) && ( minor == 0 ) )
190  {
191  curVer = CabriNS::CV_1_0;
192  reader = new CabriReader_v10( this );
193  }
194  else if ( ( major == 1 ) && ( minor == 2 || minor == 4 ) )
195  {
196  curVer = CabriNS::CV_1_2;
197  reader = new CabriReader_v12( this );
198  }
199  else
200  {
201  notSupported( file,
202  i18n( "This Cabri version (%1) is not supported yet.\n"
203  "Please contact the Kig authors to help supporting this Cabri "
204  "version.", header.cap( 3 ) ) );
205  return 0;
206  }
207 
208  s = CabriNS::readLine( f );
209  if ( !reader->readWindowMetrics( f ) )
210  return 0;
211 
212  // reading center point
213  CabriObject* center_point = reader->readObject( f );
214  if ( !center_point )
215  return 0;
216  // reading axes
217  CabriObject* axes = reader->readObject( f );
218  if ( !axes )
219  return 0;
220  bool haveaxes = axes->visible;
221  bool havegrid = false;
222 
223  KigDocument* ret = new KigDocument();
224 
225  std::vector<ObjectHolder*> holders;
226  std::vector<ObjectCalcer*> calcers;
227 
228  const ObjectFactory* fact = ObjectFactory::instance();
229 
230  std::vector<ObjectCalcer*> args;
231  ObjectCalcer* oc = 0;
232  std::vector<uint> idsToSkip;
233  int previd = 0;
234  uint lowerbound = 2;
235 
236  while ( ! f.atEnd() )
237  {
238 #ifdef CABRI_DEBUG
239  kDebug() << ">>>>>>>>> -------------------------------";
240 #endif
241  // we do one object each iteration..
242  CabriObject* obj = reader->readObject( f );
243  if ( !obj )
244  return 0;
245 
246 #ifdef CABRI_DEBUG
247  kDebug() << "+++++ " << obj->id << " - " << obj->type;
248 #endif
249 
250  if ( obj->type == "Grid" )
251  {
252  havegrid = obj->visible;
253  idsToSkip.push_back( obj->id );
254  if ( obj->id == lowerbound + 1 )
255  ++lowerbound;
256  continue;
257  }
258  else if ( obj->type == "Int" )
259  {
260  int ids = obj->id - previd - 1;
261  for ( int i = 1; i <= ids; ++i )
262  idsToSkip.push_back( obj->id - i );
263  }
264 
265  args.clear();
266  for ( std::vector<int>::iterator i = obj->parents.begin();
267  i != obj->parents.end(); ++i )
268  if ( *i <= static_cast<int>( lowerbound ) )
269  {
270  if ( obj->type == "Pt/" )
271  obj->type = "Pt";
272 #ifdef CABRI_DEBUG
273  else
274  {
275  kDebug() << ">>>>>>>>> OBJECT TO AXIS/GRID: \"" << obj->type << "\"";
276  }
277 #endif
278  }
279  else
280  {
281  args.push_back( calcers[*i-3-priorTo( idsToSkip, *i )] );
282  }
283 
284  if ( obj->id - priorTo( idsToSkip, obj->id ) != calcers.size() + 3 ) KIG_FILTER_PARSE_ERROR;
285  oc = 0;
286 #ifdef CABRI_DEBUG
287  if ( args.size() > 0 )
288  for ( uint j = 0; j < args.size(); ++j )
289  {
290  kDebug() << "+++++++++ arg[" << j << "]: " << args[j] << " - "
291  << args[j]->imp()->type()->internalName() << endl;
292  }
293  else
294  kDebug() << "+++++++++ args: NO";
295  kDebug() << "+++++++++ data: " << obj->data.size();
296 #endif
297  if ( obj->type == "Pt" )
298  {
299  if ( !args.empty() || obj->data.size() != 2 ) KIG_FILTER_PARSE_ERROR;
300  oc = fact->fixedPointCalcer( Coordinate( obj->data[0], obj->data[1] ) );
301  }
302  else if ( obj->type == "Cir" )
303  {
304  if ( args.size() == 1 )
305  {
306  if ( obj->data.size() != 1 ) KIG_FILTER_PARSE_ERROR;
307  ObjectConstCalcer* radc =
308  new ObjectConstCalcer( new DoubleImp( obj->data[0] ) );
309  args.push_back( radc );
310  oc = new ObjectTypeCalcer( CircleBPRType::instance(), args );
311  }
312  else if ( args.size() == 2 )
313  {
314  if ( ! obj->data.empty() ) KIG_FILTER_PARSE_ERROR;
315  oc = new ObjectTypeCalcer( CircleBCPType::instance(), args );
316  }
317  else KIG_FILTER_PARSE_ERROR;
318  }
319  else if ( obj->type == "Line" || obj->type == "Ray" || obj->type == "Seg" ||
320  obj->type == "Vec" )
321  {
322  if ( args.size() == 1 )
323  {
324  if ( obj->data.size() != 2 ) KIG_FILTER_PARSE_ERROR;
325  Coordinate vect( obj->data[0], obj->data[1] );
326  ObjectConstCalcer* vectorcalcer =
327  new ObjectConstCalcer( new VectorImp( Coordinate( 0, 0 ), vect ) );
328  args.push_back( vectorcalcer );
329  ObjectTypeCalcer* secondpoint =
330  new ObjectTypeCalcer( TranslatedType::instance(), args );
331  secondpoint->calc( *ret );
332  args[1] = secondpoint;
333  }
334  if ( args.size() != 2 ) KIG_FILTER_PARSE_ERROR;
335  const ObjectType* t = 0;
336  if ( obj->type == "Line" ) t = LineABType::instance();
337  else if ( obj->type == "Ray" ) t = RayABType::instance();
338  else if ( obj->type == "Seg" ) t = SegmentABType::instance();
339  else if ( obj->type == "Vec" ) t = VectorType::instance();
340  else assert( t );
341  oc = new ObjectTypeCalcer( t, args );
342  }
343  else if ( obj->type == "Pt/" )
344  {
345  if ( args.size() != 1 || obj->data.size() != 2 )
346  KIG_FILTER_PARSE_ERROR;
347  ObjectCalcer* parent = args[0];
348  if ( !parent->imp()->inherits( CurveImp::stype() ) )
349  KIG_FILTER_PARSE_ERROR;
350  oc = fact->constrainedPointCalcer( parent, Coordinate( obj->data[0], obj->data[1] ), *ret );
351  }
352  else if ( obj->type == "Int" && curVer == CabriNS::CV_1_2 ) // Cabri1.2
353  {
354  if ( args.size() != 2 || !obj->data.empty() ) KIG_FILTER_PARSE_ERROR;
355  oc = intersectionPoints( args, obj->intersectionId );
356  }
357  else if ( obj->type == "Perp" || obj->type == "Par" )
358  {
359  if ( args.size() == 2
360  && ( args[1]->imp()->inherits( FilledPolygonImp::stype() )
361  || args[1]->imp()->inherits( FilledPolygonImp::stype3() )
362  || args[1]->imp()->inherits( FilledPolygonImp::stype4() ) ) )
363  {
364  std::vector<ObjectCalcer*> sideargs;
365  sideargs.push_back( args[1] );
366  sideargs.push_back( new ObjectConstCalcer( new IntImp( obj->side ) ) );
367  ObjectCalcer* c =
368  new ObjectTypeCalcer( PolygonSideType::instance(), sideargs );
369  c->calc( *ret );
370  args.pop_back();
371  args.push_back( c );
372  }
373  else if ( args.size() == 2 && args[1]->imp()->inherits( VectorImp::stype() ) )
374  {
375  ObjectCalcer* c =
376  new ObjectTypeCalcer( LineByVectorType::instance(), args );
377  c->calc( *ret );
378  args.pop_back();
379  args.push_back( c );
380  }
381  if ( args.size() != 2 || obj->data.size() != 0 )
382  KIG_FILTER_PARSE_ERROR;
383  const ObjectType* t = 0;
384  if ( obj->type == "Perp" ) t = LinePerpendLPType::instance();
385  else if ( obj->type == "Par" ) t = LineParallelLPType::instance();
386  else assert( false );
387  oc = new ObjectTypeCalcer( t, args );
388  }
389  else if ( obj->type == "Arc" )
390  {
391  if ( args.size() != 3 || ! obj->data.empty() )
392  KIG_FILTER_PARSE_ERROR;
393  oc = new ObjectTypeCalcer( ArcBTPType::instance(), args );
394  }
395  else if ( obj->type == "Con" )
396  {
397  if ( args.size() != 5 || !obj->data.empty() )
398  KIG_FILTER_PARSE_ERROR;
399  oc = new ObjectTypeCalcer( ConicB5PType::instance(), args );
400  }
401  else if ( obj->type == "Mid" )
402  {
403  if ( args.size() == 2 )
404  {
405  ObjectCalcer* c =
406  new ObjectTypeCalcer( SegmentABType::instance(), args );
407  c->calc( *ret );
408  args.clear();
409  args.push_back( c );
410  }
411  if ( args.size() == 1
412  && ( args[0]->imp()->inherits( FilledPolygonImp::stype() )
413  || args[0]->imp()->inherits( FilledPolygonImp::stype3() )
414  || args[0]->imp()->inherits( FilledPolygonImp::stype4() ) ) )
415  {
416  std::vector<ObjectCalcer*> sideargs;
417  sideargs.push_back( args[0] );
418  sideargs.push_back( new ObjectConstCalcer( new IntImp( obj->side ) ) );
419  ObjectCalcer* c =
420  new ObjectTypeCalcer( PolygonSideType::instance(), sideargs );
421  c->calc( *ret );
422  args.clear();
423  args.push_back( c );
424  }
425  // midpoint -> this can be the midpoint of a segment, two
426  // points, or a vector...
427  if ( args.size() != 1 || !obj->data.empty() )
428  KIG_FILTER_PARSE_ERROR;
429  ObjectCalcer* parent = args[0];
430  if ( parent->imp()->inherits( SegmentImp::stype() ) )
431  oc = fact->propertyObjectCalcer( parent, "mid-point" ) ;
432  else if ( parent->imp()->inherits( VectorImp::stype() ) )
433  oc = fact->propertyObjectCalcer( parent, "vect-mid-point" );
434  else KIG_FILTER_PARSE_ERROR;
435  }
436  else if ( obj->type == "PBiss" )
437  {
438  if ( args.size() == 2 )
439  {
440  ObjectCalcer* c =
441  new ObjectTypeCalcer( SegmentABType::instance(), args );
442  c->calc( *ret );
443  args.clear();
444  args.push_back( c );
445  }
446  if ( args.size() == 1
447  && ( args[0]->imp()->inherits( FilledPolygonImp::stype() )
448  || args[0]->imp()->inherits( FilledPolygonImp::stype3() )
449  || args[0]->imp()->inherits( FilledPolygonImp::stype4() ) ) )
450  {
451  std::vector<ObjectCalcer*> sideargs;
452  sideargs.push_back( args[0] );
453  sideargs.push_back( new ObjectConstCalcer( new IntImp( obj->side ) ) );
454  ObjectCalcer* c =
455  new ObjectTypeCalcer( PolygonSideType::instance(), sideargs );
456  c->calc( *ret );
457  args.clear();
458  args.push_back( c );
459  }
460  if ( args.size() != 1 || !obj->data.empty() )
461  KIG_FILTER_PARSE_ERROR;
462  ObjectCalcer* parent = args[0];
463  ObjectCalcer* midpoint = 0;
464  if ( parent->imp()->inherits( SegmentImp::stype() ) )
465  midpoint = fact->propertyObjectCalcer( parent, "mid-point" ) ;
466 // else if ( parent->imp()->inherits( VectorImp::stype() ) )
467 // midpoint = fact->propertyObjectCalcer( parent, "vect-mid-point" );
468  else KIG_FILTER_PARSE_ERROR;
469  midpoint->calc( *ret );
470  args.push_back( midpoint );
471  oc = new ObjectTypeCalcer( LinePerpendLPType::instance(), args );
472  }
473  else if ( obj->type == "Biss" && curVer == CabriNS::CV_1_2 ) // Cabri1.2
474  {
475  if ( args.size() == 3 )
476  {
477  ObjectTypeCalcer* ao = new ObjectTypeCalcer( AngleType::instance(), args );
478  ao->calc( *ret );
479  args.clear();
480  args.push_back( ao );
481  };
482  if ( args.size() != 1 || !obj->data.empty() ) KIG_FILTER_PARSE_ERROR;
483  ObjectCalcer* parent = args[0];
484  if ( parent->imp()->inherits( AngleImp::stype() ) )
485  oc = fact->propertyObjectCalcer( parent, "angle-bisector" ) ;
486  else KIG_FILTER_PARSE_ERROR;
487  }
488  else if ( obj->type == "Angle" )
489  {
490  if ( args.size() != 3 ) KIG_FILTER_PARSE_ERROR;
491  oc = new ObjectTypeCalcer( AngleType::instance(), args );
492  }
493  else if ( obj->type == "Text" )
494  {
495 // if ( !args.empty() /* || obj->data.size() != 2 */ ) KIG_FILTER_PARSE_ERROR;
496  if ( !obj->textRect.valid() ) KIG_FILTER_PARSE_ERROR;
497  // replacing "# with %1, %2, etc.. in the label text
498  QString txt = obj->text;
499  int pos = -1;
500  int index = 1;
501  while ( ( pos = txt.indexOf( "\"#" ) ) > -1 )
502  txt.replace( pos, 2, QString( "%%1" ).arg( index++ ) );
503  // getting the references to the arguments
504  std::vector<ObjectCalcer*> txtincs;
505  for ( std::vector<int>::iterator i = obj->incs.begin();
506  i != obj->incs.end(); ++i )
507  txtincs.push_back( calcers[*i-3-priorTo( idsToSkip, *i )] );
508  oc = fact->labelCalcer( txt, obj->textRect.topLeft(), true, txtincs, *ret );
509  }
510  else if ( obj->type == "Pol" )
511  {
512  if ( args.size() < 3 || !obj->data.empty() )
513  KIG_FILTER_PARSE_ERROR;
514  oc = new ObjectTypeCalcer( PolygonBNPType::instance(), args );
515  }
516  else if ( obj->type == "Lgth" )
517  {
518  if ( args.size() == 2 )
519  {
520  ObjectCalcer* c =
521  new ObjectTypeCalcer( SegmentABType::instance(), args );
522  c->calc( *ret );
523  args.clear();
524  args.push_back( c );
525  }
526  if ( args.size() != 1 /* || !obj->data.empty() */ )
527  KIG_FILTER_PARSE_ERROR;
528  ObjectCalcer* parent = args[0];
529  QByteArray prop;
530  if ( ( parent->imp()->inherits( SegmentImp::stype() ) ) ||
531  ( parent->imp()->inherits( VectorImp::stype() ) ) )
532  prop = "length";
533  else if ( parent->imp()->inherits( ArcImp::stype() ) )
534  prop = "arc-length";
535  else if ( parent->imp()->inherits( CircleImp::stype() ) )
536  prop = "circumference";
537  else
538  KIG_FILTER_PARSE_ERROR;
539  oc = fact->propertyObjectCalcer( parent, prop );
540  }
541  else if ( obj->type == "Slo" )
542  {
543  if ( args.size() != 1 /* || !obj->data.empty() */ )
544  KIG_FILTER_PARSE_ERROR;
545  ObjectCalcer* parent = args[0];
546  if ( !parent->imp()->inherits( AbstractLineImp::stype() ) )
547  KIG_FILTER_PARSE_ERROR;
548  oc = fact->propertyObjectCalcer( parent, "slope" );
549  }
550  else if ( obj->type == "AngVal" )
551  {
552  if ( args.size() == 3 )
553  {
554  ObjectTypeCalcer* angle = new ObjectTypeCalcer( AngleType::instance(), args );
555  angle->calc( *ret );
556  args.clear();
557  args.push_back( angle );
558  }
559  if ( args.size() != 1 /* || !obj->data.empty() */ )
560  KIG_FILTER_PARSE_ERROR;
561  QByteArray prop;
562  switch ( obj->gonio )
563  {
564  case CabriNS::CG_Deg: prop = "angle-degrees"; break;
565  case CabriNS::CG_Rad: prop = "angle-radian"; break;
566  default:
567  KIG_FILTER_PARSE_ERROR;
568  }
569  oc = fact->propertyObjectCalcer( args[0], prop );
570  }
571  else if ( obj->type == "Eq/Co" && curVer == CabriNS::CV_1_0 )
572  {
573  if ( args.size() < 1 )
574  KIG_FILTER_PARSE_ERROR;
575 
576  ObjectCalcer* thisarg = args[0];
577  QByteArray prop;
578  if ( thisarg->imp()->inherits( PointImp::stype() ) )
579  {
580  switch ( obj->specification )
581  {
582  case 0:
583  prop = "coordinate-x";
584  break;
585  case 1:
586  prop = "coordinate-y";
587  break;
588  default:
589  KIG_FILTER_PARSE_ERROR;
590  }
591  }
592  else
593  KIG_FILTER_PARSE_ERROR;
594 
595  assert( !prop.isEmpty() );
596 
597  oc = fact->propertyObjectCalcer( thisarg, prop );
598  }
599  else if ( obj->type == "Tr" )
600  {
601  if ( args.size() != 3 || !obj->data.empty() )
602  KIG_FILTER_PARSE_ERROR;
603  oc = new ObjectTypeCalcer( PolygonBNPType::instance(), args );
604  }
605  else if ( obj->type == "Locus" )
606  {
607  if ( args.size() != 2 || !obj->data.empty() )
608  KIG_FILTER_PARSE_ERROR;
609  oc = fact->locusCalcer( args[0], args[1] );
610  }
611  else if ( obj->type == "Refl" )
612  {
613  if ( args.size() != 2 || !obj->data.empty() )
614  KIG_FILTER_PARSE_ERROR;
615  oc = new ObjectTypeCalcer( LineReflectionType::instance(), args );
616  }
617  else if ( obj->type == "Sym" )
618  {
619  if ( args.size() != 2 || !obj->data.empty() )
620  KIG_FILTER_PARSE_ERROR;
621  oc = new ObjectTypeCalcer( PointReflectionType::instance(), args );
622  }
623  else if ( obj->type == "Tran" )
624  {
625  if ( args.size() != 2 || !obj->data.empty() )
626  KIG_FILTER_PARSE_ERROR;
627  oc = new ObjectTypeCalcer( TranslatedType::instance(), args );
628  }
629  else if ( obj->type == "Rot" )
630  {
631  if ( args.size() == 5 )
632  {
633  std::vector<ObjectCalcer*> angleargs;
634  std::copy( args.begin() + 2, args.end(), std::back_inserter( angleargs ) );
635  ObjectTypeCalcer* angle = new ObjectTypeCalcer( AngleType::instance(), angleargs );
636  angle->calc( *ret );
637  args.pop_back();
638  args.pop_back();
639  args.pop_back();
640  args.push_back( angle );
641  }
642  if ( args.size() == 3 )
643  {
644  if ( ! obj->data.empty() ) KIG_FILTER_PARSE_ERROR;
645  oc = new ObjectTypeCalcer( RotationType::instance(), args );
646  }
647  else KIG_FILTER_PARSE_ERROR;
648  }
649  else if ( obj->type == "Inv" )
650  {
651  if ( args.size() != 2 || !obj->data.empty() )
652  KIG_FILTER_PARSE_ERROR;
653  oc = new ObjectTypeCalcer( InvertPointType::instance(), args );
654  }
655  else
656  {
657  notSupported( file, i18n( "This Cabri file contains a \"%1\" object, "
658  "which Kig does not currently support.", QString( obj->type ) ) );
659  return 0;
660  }
661 #ifdef CABRI_DEBUG
662  kDebug() << "+++++++++ oc: " << oc;
663 #endif
664 
665  if ( oc == 0 ) KIG_FILTER_PARSE_ERROR;
666 
667  oc->calc( *ret );
668 #ifdef CABRI_DEBUG
669  kDebug() << "+++++++++ oc: " << oc << " - "
670  << oc->imp()->type()->internalName() << endl;
671 #endif
672  calcers.push_back( oc );
673 
674  // decoding the style and building the ObjectDrawer
675  Qt::PenStyle ls = Qt::SolidLine;
676  int ps = 0;
677  reader->decodeStyle( obj, ls, ps );
678  ObjectDrawer* d = new ObjectDrawer( obj->color, obj->thick, obj->visible, ls, ps );
679 
680  ObjectHolder* oh = 0;
681  if ( !obj->name.isEmpty() )
682  {
683  ObjectConstCalcer* name = new ObjectConstCalcer( new StringImp( obj->name ) );
684  oh = new ObjectHolder( oc, d, name );
685  }
686  else
687  {
688  oh = new ObjectHolder( oc, d );
689  }
690  assert( oh );
691  holders.push_back( oh );
692 
693  oc = 0;
694  previd = obj->id;
695  delete obj;
696  }
697  // freeing memory
698  delete center_point;
699  delete axes;
700  delete reader;
701 
702  ret->addObjects( holders );
703  ret->setGrid( havegrid );
704  ret->setAxes( haveaxes );
705  return ret;
706 }
707 
708 void KigFilterCabri::publicParseError( const QString& file, const QString& text ) const
709 {
710  parseError( file, text );
711 }
712 
713 KigFilterCabri* KigFilterCabri::instance()
714 {
715  static KigFilterCabri t;
716  return &t;
717 }
CabriObject::side
int side
Definition: cabri-utils.h:85
ObjectFactory::instance
static const ObjectFactory * instance()
Definition: object_factory.cc:90
CabriObject::color
QColor color
Definition: cabri-utils.h:76
ArcLineIntersectionType::instance
static const ArcLineIntersectionType * instance()
Definition: intersection_types.cc:541
ArcBTPType::instance
static const ArcBTPType * instance()
Definition: arc_type.cc:70
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
PointReflectionType::instance
static const PointReflectionType * instance()
Definition: transform_types.cc:87
StringImp
This ObjectImp is a BogusImp containing only a string value.
Definition: bogus_imp.h:167
RotationType::instance
static const RotationType * instance()
Definition: transform_types.cc:161
TranslatedType::instance
static const TranslatedType * instance()
Definition: transform_types.cc:52
ObjectConstCalcer
This is an ObjectCalcer that keeps an ObjectImp, and never calculates a new one.
Definition: object_calcer.h:232
LinePerpendLPType::instance
static LinePerpendLPType * instance()
Definition: line_type.cc:130
Rect::valid
bool valid()
Definition: rect.cc:300
CabriReader_v12
Definition: cabri-utils.h:154
AngleType::instance
static const AngleType * instance()
Definition: angle_type.cc:63
ObjectFactory::fixedPointCalcer
ObjectTypeCalcer * fixedPointCalcer(const Coordinate &c) const
Definition: object_factory.cc:50
ObjectImpType::internalName
const char * internalName() const
Returns an internal name for this ObjectImp type.
Definition: object_imp.cc:235
CabriObject::gonio
CabriNS::CabriGonio gonio
Definition: cabri-utils.h:93
CircleBPRType::instance
static const CircleBPRType * instance()
Definition: circle_type.cc:210
CabriReader::readObject
virtual CabriObject * readObject(QFile &f)=0
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
KigDocument::addObjects
void addObjects(const std::vector< ObjectHolder * > &os)
Add the objects os to the document.
Definition: kig_document.cc:143
ObjectFactory::locusCalcer
ObjectTypeCalcer * locusCalcer(ObjectCalcer *a, ObjectCalcer *b) const
return a locus, defined by the two points ( one constrained, and one following ) a and b ...
Definition: object_factory.cc:355
CabriObject::specification
int specification
Definition: cabri-utils.h:75
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
CabriNS::CabriVersion
CabriVersion
Cabri versions we try to read from.
Definition: cabri-utils.h:41
IntImp
This ObjectImp is a BogusImp containing only an int value.
Definition: bogus_imp.h:128
KigFilterCabri::publicParseError
void publicParseError(const QString &file, const QString &text) const
Definition: cabri-filter.cc:708
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
ObjectFactory::labelCalcer
ObjectTypeCalcer * labelCalcer(const QString &s, const Coordinate &loc, bool needframe, const std::vector< ObjectCalcer * > &parents, const KigDocument &doc) const
Definition: object_factory.cc:394
cabri-filter.h
CabriObject::text
QString text
Definition: cabri-utils.h:90
VectorImp
An ObjectImp representing a vector.
Definition: other_imp.h:99
KigDocument::setGrid
void setGrid(bool showgrid)
set to show/hide the grid.
Definition: kig_document.cc:181
CabriObject::parents
std::vector< int > parents
Definition: cabri-utils.h:87
CabriObject::textRect
Rect textRect
Definition: cabri-utils.h:91
ObjectImp::type
virtual const ObjectImpType * type() const =0
Returns the lowermost ObjectImpType that this object is an instantiation of.
FilledPolygonImp::stype4
static const ObjectImpType * stype4()
Definition: polygon_imp.cc:732
CabriObject::thick
int thick
Definition: cabri-utils.h:78
CabriNS::readLine
QString readLine(QFile &file)
Read a line from a Cabri file, stripping the \n and \r characters.
Definition: cabri-utils.cc:89
LineLineIntersectionType::instance
static const LineLineIntersectionType * instance()
Definition: intersection_types.cc:374
KigFilter::parseError
void parseError(const QString &file, const QString &explanation=QString()) const
Definition: filter.cc:79
KigFilterCabri::instance
static KigFilterCabri * instance()
Definition: cabri-filter.cc:713
CabriNS::CV_1_2
Definition: cabri-utils.h:44
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:163
VectorType::instance
static const VectorType * instance()
Definition: vector_type.cc:43
ObjectCalcer
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
Definition: object_calcer.h:66
Rect::topLeft
Coordinate topLeft() const
Definition: rect.cc:171
InvertPointType::instance
static const InvertPointType * instance()
Definition: inversion_type.cc:308
KigFilter::notSupported
void notSupported(const QString &file, const QString &explanation) const
Definition: filter.cc:92
ObjectFactory::constrainedPointCalcer
ObjectTypeCalcer * constrainedPointCalcer(ObjectCalcer *curve, double param) const
Definition: object_factory.cc:313
ObjectCalcer::calc
virtual void calc(const KigDocument &)=0
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
CabriObject::name
QString name
Definition: cabri-utils.h:89
FilledPolygonImp::stype
static const ObjectImpType * stype()
Definition: polygon_imp.cc:660
SegmentImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the SegmentImp type.
Definition: line_imp.cc:545
CabriNS::CG_Deg
Definition: cabri-utils.h:49
ObjectFactory::propertyObjectCalcer
ObjectPropertyCalcer * propertyObjectCalcer(ObjectCalcer *o, const char *p) const
returns a property object for the property p of object o .
Definition: object_factory.cc:483
ArcImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the ArcImp type.
Definition: other_imp.cc:629
CabriReader_v10
Definition: cabri-utils.h:142
CircleBCPType::instance
static const CircleBCPType * instance()
Definition: circle_type.cc:55
CircleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CircleImp type.
Definition: circle_imp.cc:342
CabriReader::readWindowMetrics
virtual bool readWindowMetrics(QFile &f)=0
ObjectType
The ObjectType class is a thing that represents the "behaviour" for a certain type.
Definition: object_type.h:32
KigFilterCabri
This is an import filter for the output of the commercial program Cabri ("CAhier de BRouillon Interac...
Definition: cabri-filter.h:36
priorTo
static int priorTo(const std::vector< uint > &ids, uint id)
Definition: cabri-filter.cc:117
ObjectDrawer
A class holding some information about how a certain object is drawn on the window.
Definition: object_drawer.h:47
KigDocument::setAxes
void setAxes(bool showaxes)
set to show/hide the grid.
Definition: kig_document.cc:191
LineByVectorType::instance
static const LineByVectorType * instance()
Definition: line_type.cc:275
CabriObject::visible
bool visible
Definition: cabri-utils.h:82
CabriNS::CG_Rad
Definition: cabri-utils.h:50
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
CabriReader
Base reader for a Cabri figure.
Definition: cabri-utils.h:120
ConicB5PType::instance
static const ConicB5PType * instance()
Definition: conic_types.cc:75
ConicRadicalType::instance
static const ConicRadicalType * instance()
Definition: conic_types.cc:562
CabriObject::incs
std::vector< int > incs
Definition: cabri-utils.h:92
PolygonSideType::instance
static const PolygonSideType * instance()
Definition: polygon_type.cc:1036
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
AngleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AngleImp type.
Definition: other_imp.cc:597
DoubleImp
This ObjectImp is a BogusImp containing only a double value.
Definition: bogus_imp.h:89
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
ConicLineIntersectionType::instance
static const ConicLineIntersectionType * instance()
Definition: intersection_types.cc:54
PolygonBNPType::instance
static const PolygonBNPType * instance()
Definition: polygon_type.cc:151
ObjectCalcer::imp
virtual const ObjectImp * imp() const =0
Returns the ObjectImp of this ObjectCalcer.
CabriObject::id
uint id
Definition: cabri-utils.h:73
intersectionPoints
static ObjectTypeCalcer * intersectionPoints(const std::vector< ObjectCalcer * > &parents, int which)
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: cabri-filter.cc:62
ObjectTypeCalcer::calc
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
Definition: object_calcer.cc:32
CabriObject::intersectionId
int intersectionId
Definition: cabri-utils.h:83
CabriObject::data
std::vector< double > data
Definition: cabri-utils.h:88
KIG_FILTER_PARSE_ERROR
#define KIG_FILTER_PARSE_ERROR
Definition: filter.h:53
SegmentABType::instance
static const SegmentABType * instance()
Definition: line_type.cc:55
LineReflectionType::instance
static const LineReflectionType * instance()
Definition: transform_types.cc:122
FilledPolygonImp::stype3
static const ObjectImpType * stype3()
Definition: polygon_imp.cc:714
KigFilter::fileNotFound
void fileNotFound(const QString &file) const
Definition: filter.cc:70
CabriReader::decodeStyle
virtual void decodeStyle(CabriObject *obj, Qt::PenStyle &ps, int &pointType)=0
CabriNS::CV_1_0
Definition: cabri-utils.h:43
KigFilterCabri::load
KigDocument * load(const QString &fromfile)
load file fromfile and build a KigDocument from it.
Definition: cabri-filter.cc:141
ObjectFactory
Definition: object_factory.h:23
uint
unsigned int uint
Definition: object_imp.h:87
cabri-utils.h
CabriObject
Base class representing a Cabri object.
Definition: cabri-utils.h:68
CabriObject::type
QByteArray type
Definition: cabri-utils.h:74
LineABType::instance
static const LineABType * instance()
Definition: line_type.cc:87
KigFilterCabri::supportMime
bool supportMime(const QString &mime)
can the filter handle the mimetype mime ?
Definition: cabri-filter.cc:133
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 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