23 #include "../kig/kig_document.h"
24 #include "../kig/kig_part.h"
25 #include "../misc/common.h"
26 #include "../misc/coordinate.h"
27 #include "../objects/angle_type.h"
28 #include "../objects/arc_type.h"
29 #include "../objects/bogus_imp.h"
30 #include "../objects/circle_imp.h"
31 #include "../objects/circle_type.h"
32 #include "../objects/conic_imp.h"
33 #include "../objects/conic_types.h"
34 #include "../objects/curve_imp.h"
35 #include "../objects/intersection_types.h"
36 #include "../objects/line_imp.h"
37 #include "../objects/line_type.h"
38 #include "../objects/object_calcer.h"
39 #include "../objects/object_drawer.h"
40 #include "../objects/object_factory.h"
41 #include "../objects/object_holder.h"
42 #include "../objects/object_type.h"
43 #include "../objects/other_imp.h"
44 #include "../objects/other_type.h"
45 #include "../objects/point_imp.h"
46 #include "../objects/point_type.h"
47 #include "../objects/polygon_type.h"
48 #include "../objects/transform_types.h"
49 #include "../objects/vector_type.h"
54 #include <qnamespace.h>
55 #include <QDomDocument>
57 #include <kinputdialog.h>
63 struct DrGeoHierarchyElement
66 std::vector<QString> parents;
79 return mime ==
"application/x-drgeo";
85 if ( ! f.
open( QIODevice::ReadOnly ) )
101 if ( e.
isNull() )
continue;
102 else if ( e.
tagName() ==
"drgeo" )
104 else if ( e.
tagName() ==
"macro" )
109 warning( i18n(
"The Dr. Geo file \"%1\" is a macro file so it contains no "
110 "figures.", file ) );
112 warning( i18n(
"There are no figures in Dr. Geo file \"%1\".", file ) );
116 int nfig = figures.
count();
127 myfig = KInputDialog::getItem(
128 i18n(
"Dr. Geo Filter" ),
129 i18n(
"The current Dr. Geo file contains more than one figure.\n"
130 "Please select which to import:" ),
131 figures, 0,
false, &ok );
137 kDebug() <<
"drgeo file " << file;
143 if ( e.
isNull() )
continue;
144 else if ( e.
tagName() ==
"drgeo" )
149 kDebug() <<
"- Figure: '" << e.
attribute(
"name") <<
"'";
153 return importFigure( e.
firstChild(), file, grid );
163 for (
uint i = 0; i < es.size(); ++i )
164 if ( es[i].
id == myid )
171 const double n = ( param - 0.5 ) * M_PI;
179 const double n = param * M_PI * 0.5;
190 std::vector<DrGeoHierarchyElement> elems;
197 if ( domelem.
isNull() )
continue;
200 DrGeoHierarchyElement elem;
202 kDebug() <<
" * " << domelem.
tagName() <<
"(" << domelem.
attribute(
"type") <<
")";
207 if ( ce.
isNull() )
continue;
208 else if ( ce.
tagName() ==
"parent" )
209 elem.parents.push_back( ce.
attribute(
"ref" ) );
213 elems.push_back( elem );
219 kDebug() <<
"+++ elems";
220 for (
uint i = 0; i < elems.size(); ++i )
223 for (
uint j = 0; j < elems[i].parents.size(); ++j )
225 x += elems[i].parents[j] +
'_';
227 kDebug() <<
" --> " << i <<
" - " << elems[i].id <<
" - " << x;
234 std::vector<ObjectHolder*> holders;
235 std::vector<ObjectHolder*> holders2;
245 kDebug() <<
"+++ id: " << curid;
247 const DrGeoHierarchyElement& el = elems[curid];
248 std::vector<ObjectCalcer*> parents;
249 for (
uint j = 0; j < el.parents.size(); ++j )
252 if ( parentid == -1 )
254 parents.push_back( holders[parentid-nignored]->calcer() );
259 if ( parents.size() > 0 )
260 for (
uint j = 0; j < parents.size(); ++j )
262 kDebug() <<
"+++++++++ parent[" << j <<
"]: " << parents[j] <<
" - "
263 << parents[j]->imp()->type()->internalName() << endl;
266 kDebug() <<
"+++++++++ parents: NO";
267 kDebug() <<
"+++++++++ " << domelem.
tagName() <<
" - " << domelem.
attribute(
"type");
270 if ( domelem.
isNull() )
continue;
271 else if ( domelem.
tagName() ==
"point" )
279 if ( ce.
isNull() )
continue;
280 else if ( ce.
tagName() ==
"x" )
282 else if ( ce.
tagName() ==
"y" )
284 else if ( ce.
tagName() ==
"value" )
287 if ( domelem.
attribute(
"type" ) ==
"Free" )
293 if ( ! ( ok && ok2 ) )
295 oc = fact->fixedPointCalcer(
Coordinate( x, y ) );
297 else if ( domelem.
attribute(
"type" ) ==
"Middle_2pts" )
299 else if ( domelem.
attribute(
"type" ) ==
"Middle_segment" )
308 std::vector<ObjectCalcer*> args;
309 args.push_back( o1 );
310 args.push_back( o2 );
313 else if ( domelem.
attribute(
"type" ) ==
"On_curve" )
316 double value = values.
toDouble( &ok3 );
321 oc = fact->constrainedPointCalcer( parents[0], value );
324 const LineData l =
static_cast<const LineImp*
>( parents[0]->imp() )->data();
326 oc = fact->constrainedPointCalcer( parents[0], p, *ret );
330 const LineData l =
static_cast<const RayImp*
>( parents[0]->imp() )->data();
332 oc = fact->constrainedPointCalcer( parents[0], p, *ret );
335 oc = fact->constrainedPointCalcer( parents[0], 1 - value );
339 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
340 "which Kig does not currently support.", domelem.
tagName() ,
345 else if ( domelem.
attribute(
"type" ) ==
"Intersection" )
355 if ( which == 1 ) which = -1;
356 else if ( which == 0 ) which = 1;
358 std::vector<ObjectCalcer*> args = parents;
369 else if ( ( parents[0]->imp()->inherits(
ArcImp::stype() ) &&
376 notSupported( file, i18n(
"This Dr. Geo file contains an intersection type, "
377 "which Kig does not currently support." ) );
383 else if ( domelem.
attribute(
"type" ) ==
"Coordinate" )
385 else if ( domelem.
attribute(
"type" ) ==
"Reflexion" )
387 else if ( domelem.
attribute(
"type" ) ==
"Symmetry" )
389 else if ( domelem.
attribute(
"type" ) ==
"Translation" )
391 else if ( domelem.
attribute(
"type" ) ==
"Rotation" )
393 else if ( domelem.
attribute(
"type" ) ==
"Scale" )
397 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
398 "which Kig does not currently support.", domelem.
tagName() ,
403 kDebug() <<
"+++++++++ oc:" << oc;
406 else if( ( domelem.
tagName() ==
"line" ) ||
407 ( domelem.
tagName() ==
"halfLine" ) ||
408 ( domelem.
tagName() ==
"segment" ) ||
409 ( domelem.
tagName() ==
"vector" ) ||
410 ( domelem.
tagName() ==
"circle" ) ||
411 ( domelem.
tagName() ==
"arcCircle" ) ||
412 ( domelem.
tagName() ==
"polygon" ) )
415 if ( domelem.
attribute(
"type" ) ==
"2pts" )
417 if( domelem.
tagName() ==
"line" )
419 else if( domelem.
tagName() ==
"halfLine" )
421 else if( domelem.
tagName() ==
"segment" )
423 else if( domelem.
tagName() ==
"vector" )
425 else if( domelem.
tagName() ==
"circle" )
429 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
430 "which Kig does not currently support.", domelem.
tagName() ,
436 else if( domelem.
attribute(
"type" ) ==
"3pts" )
438 if( domelem.
tagName() ==
"arcCircle" )
442 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
443 "which Kig does not currently support.", domelem.
tagName() ,
449 else if ( ( domelem.
attribute(
"type" ) ==
"segment" ) ||
450 ( domelem.
attribute(
"type" ) ==
"radius" ) )
452 if( domelem.
tagName() ==
"circle" )
455 if ( domelem.
attribute(
"type" ) ==
"segment" )
460 parents.push_back( o );
465 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
466 "which Kig does not currently support.", domelem.
tagName() ,
472 else if( domelem.
attribute(
"type" ) ==
"npts" )
474 if( domelem.
tagName() ==
"polygon" )
481 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
482 "which Kig does not currently support.", domelem.
tagName() ,
488 else if ( domelem.
attribute(
"type" ) ==
"perpendicular" )
490 else if ( domelem.
attribute(
"type" ) ==
"parallel" )
492 else if ( domelem.
attribute(
"type" ) ==
"Reflexion" )
494 else if ( domelem.
attribute(
"type" ) ==
"Symmetry" )
496 else if ( domelem.
attribute(
"type" ) ==
"Translation" )
498 else if ( domelem.
attribute(
"type" ) ==
"Rotation" )
500 else if ( domelem.
attribute(
"type" ) ==
"Scale" )
504 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
505 "which Kig does not currently support.", domelem.
tagName() ,
510 kDebug() <<
"+++++++++ oc:" << oc;
513 else if( ( domelem.
tagName() ==
"numeric" ) ||
514 ( domelem.
tagName() ==
"equation" ) )
522 if ( ce.
isNull() )
continue;
523 else if ( ce.
tagName() ==
"x" )
525 else if ( ce.
tagName() ==
"y" )
527 else if ( ce.
tagName() ==
"value" )
534 if ( ! ( ok && ok2 ) )
538 if ( domelem.
attribute(
"type" ) ==
"value" )
541 double dvalue = value.
toDouble( &ok3 );
544 oc = fact->numericValueCalcer( dvalue, m, *ret );
546 else if ( domelem.
attribute(
"type" ) ==
"pt_abscissa" )
551 else if ( domelem.
attribute(
"type" ) ==
"pt_ordinate" )
556 else if ( domelem.
attribute(
"type" ) ==
"segment_length" )
561 else if ( domelem.
attribute(
"type" ) ==
"circle_perimeter" )
566 else if ( domelem.
attribute(
"type" ) ==
"arc_length" )
571 else if ( domelem.
attribute(
"type" ) ==
"distance_2pts" )
578 else if ( domelem.
attribute(
"type" ) ==
"vector_norm" )
583 else if ( domelem.
attribute(
"type" ) ==
"vector_abscissa" )
588 else if ( domelem.
attribute(
"type" ) ==
"vector_ordinate" )
593 else if ( domelem.
attribute(
"type" ) ==
"slope" )
598 else if ( domelem.
attribute(
"type" ) ==
"distance_pt_line" )
601 std::vector<ObjectCalcer*> args;
602 args.push_back( parents[1] );
603 args.push_back( parents[0] );
607 args.push_back( parents[1] );
608 args.push_back( po );
612 args.push_back( parents[0] );
613 args.push_back( io );
619 else if ( domelem.
attribute(
"type" ) ==
"line" )
624 else if ( domelem.
attribute(
"type" ) ==
"circle" )
631 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
632 "which Kig does not currently support.", domelem.
tagName() ,
637 kDebug() <<
"+++++++++ oc:" << oc;
640 else if ( domelem.
tagName() ==
"angle" )
642 if ( domelem.
attribute(
"type" ) ==
"3pts" )
649 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
650 "which Kig does not currently support.", domelem.
tagName() ,
655 kDebug() <<
"+++++++++ oc:" << oc;
658 else if ( domelem.
tagName() ==
"script" )
666 if ( ce.
isNull() )
continue;
667 else if ( ce.
tagName() ==
"x" )
669 else if ( ce.
tagName() ==
"y" )
671 else if ( ce.
tagName() ==
"code" )
678 if ( ! ( ok && ok2 ) )
686 if ( domelem.
attribute(
"type" ) ==
"nitems" )
687 oc = fact->labelCalcer( text,
Coordinate( x, y ),
false, std::vector<ObjectCalcer*>(), *ret );
690 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
691 "which Kig does not currently support.", domelem.
tagName() ,
696 else if ( domelem.
tagName() ==
"locus" )
698 if ( domelem.
attribute(
"type" ) ==
"None" )
699 oc = fact->locusCalcer( parents[0], parents[1] );
702 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
703 "which Kig does not currently support.", domelem.
tagName() ,
708 kDebug() <<
"+++++++++ oc:" << oc;
711 else if ( ( domelem.
tagName() ==
"boundingBox" ) ||
712 ( domelem.
tagName() ==
"customUI" ) )
720 kDebug() <<
">>>>>>>>> UNKNOWN OBJECT";
722 notSupported( file, i18n(
"This Dr. Geo file contains a \"%1 %2\" object, "
723 "which Kig does not currently support.", domelem.
tagName() ,
733 if ( ! co.isValid() )
735 if ( domelem.
attribute(
"color" ) ==
"Bordeaux" )
745 Qt::PenStyle s = Qt::SolidLine;
746 if ( domelem.
tagName() ==
"point" )
748 if ( domelem.
attribute(
"thickness" ) ==
"Normal" )
750 else if ( domelem.
attribute(
"thickness" ) ==
"Thick" )
755 if ( domelem.
attribute(
"thickness" ) ==
"Dashed" )
757 if ( domelem.
attribute(
"thickness" ) ==
"Thick" )
763 bool show = ( ( domelem.
attribute(
"masked" ) !=
"True" ) &&
764 ( domelem.
attribute(
"masked" ) !=
"Alway" ) );
773 holders.push_back( o );
776 kDebug() <<
">>>>>>>>> calc";
778 holders[curid-1-nignored]->calc( *ret );
780 kDebug() <<
"+++++++++ oc: " << oc <<
" - "
781 << oc->imp()->type()->internalName() << endl;
784 if ( domelem.
tagName() ==
"point" )
788 std::vector<ObjectCalcer*> args2;
791 static_cast<const PointImp*>( oc->imp() )->coordinate(),
792 false, args2, *ret );
796 else if ( domelem.
tagName() ==
"angle" )
799 static_cast<const PointImp*>( holders[curid-1-nignored]->calcer()->parents()[1]->imp() )->coordinate(),
800 holders[curid-1-nignored]->calcer(),
"angle-degrees", *ret,
false );
810 holders2.push_back( o2 );
static const ObjectFactory * instance()
static const ArcLineIntersectionType * instance()
static const ArcBTPType * instance()
static const PointReflectionType * instance()
This ObjectImp is a BogusImp containing only a string value.
static const RotationType * instance()
static const TranslatedType * instance()
Simple class representing a line.
This is an ObjectCalcer that keeps an ObjectImp, and never calculates a new one.
const Coordinate dir() const
The direction of the line.
static LinePerpendLPType * instance()
QString attribute(const QString &name, const QString &defValue) const
int main(int argc, char **argv)
An ObjectImp representing a ray.
const T & at(int i) const
static const CircleBPRType * instance()
static const CircleCircleIntersectionType * instance()
static const ObjectImpType * stype()
Returns the ObjectImpType representing the RayImp type.
QDomElement documentElement() const
static const RayABType * instance()
static const HalfAngleType * instance()
void addObjects(const std::vector< ObjectHolder * > &os)
Add the objects os to the document.
static const Coordinate convertDrgeoLineParam(const double param, const LineData &line)
static KigFilterDrgeo * instance()
void setRgb(int r, int g, int b, int a)
double toDouble(bool *ok) const
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
static const ObjectImpType * stype()
Returns the ObjectImpType representing the LineImp type.
const ObjectConstCalcer * nameCalcer() const
This ObjectImp is a BogusImp containing only an int value.
The Coordinate class is the basic class representing a 2D location by its x and y components...
static const Coordinate convertDrgeoHalflineParam(const double param, const LineData &line)
QDomElement toElement() const
double length() const
Length.
void setGrid(bool showgrid)
set to show/hide the grid.
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
static const LineLineIntersectionType * instance()
This is an import filter for the GNOME geometry program DrGeo.
An ObjectHolder represents an object as it is known to the document.
static LineParallelLPType * instance()
int toInt(bool *ok, int base) const
static const VectorType * instance()
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
ObjectTypeCalcer * filtersConstructTextObject(const Coordinate &c, ObjectCalcer *o, const QByteArray &arg, const KigDocument &doc, bool needframe)
constructs a text object with text "%1", location c, and variable parts given by the argument arg of ...
KigDocument * load(const QString &file)
load file fromfile and build a KigDocument from it.
void notSupported(const QString &file, const QString &explanation) const
Coordinate a
One point on the line.
static const ObjectImpType * stype()
Returns the ObjectImpType representing the SegmentImp type.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
This is an ObjectCalcer that has a single parent, and gets a certain property from it in its calc() m...
static const ObjectImpType * stype()
Returns the ObjectImpType representing the ArcImp type.
static const CircleBCPType * instance()
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CircleImp type.
The ObjectType class is a thing that represents the "behaviour" for a certain type.
static int pointStyleFromString(const QString &style)
Note that this returns a valid point style in every case, even if the given style string is unknown...
static const ScalingOverCenterType * instance()
A class holding some information about how a certain object is drawn on the window.
void setAxes(bool showaxes)
set to show/hide the grid.
QDomNode firstChild() const
static int convertDrgeoIndex(const std::vector< DrGeoHierarchyElement > &es, const QString &myid)
KigDocument is the class holding the real data in a Kig document.
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AbstractLineImp type.
static const ConicLineIntersectionType * instance()
An ObjectImp representing a line.
static const PolygonBNPType * instance()
static const MidPointType * instance()
QString fromLatin1(const char *str, int size)
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
#define KIG_FILTER_PARSE_ERROR
static const SegmentABType * instance()
bool supportMime(const QString &mime)
can the filter handle the mimetype mime ?
void warning(const QString &explanation) const
static const LineReflectionType * instance()
void fileNotFound(const QString &file) const
static const PointByCoordsType * instance()
static const LineABType * instance()
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)