22 #include "../kig/kig_document.h"
23 #include "../kig/kig_part.h"
24 #include "../kig/kig_view.h"
25 #include "../misc/common.h"
26 #include "../misc/kigfiledialog.h"
27 #include "../misc/kigpainter.h"
28 #include "../objects/circle_imp.h"
29 #include "../objects/line_imp.h"
30 #include "../objects/object_drawer.h"
31 #include "../objects/object_holder.h"
32 #include "../objects/object_imp.h"
33 #include "../objects/other_imp.h"
34 #include "../objects/point_imp.h"
35 #include "../objects/polygon_imp.h"
36 #include "../objects/text_imp.h"
40 #include <qtextstream.h>
43 #include <kmessagebox.h>
60 return i18n(
"Export to &XFig file" );
66 return i18n(
"&XFig File..." );
74 class XFigExportImpVisitor
81 std::map<QColor, int> mcolormap;
88 ret.
y = msr.height() - ret.
y;
103 : mstream( s ), mw( w ), msr( mw.showingRect() ),
107 mcolormap[Qt::black] = 0;
108 mcolormap[Qt::blue] = 1;
109 mcolormap[Qt::green] = 2;
110 mcolormap[Qt::cyan] = 3;
111 mcolormap[Qt::red] = 4;
112 mcolormap[Qt::magenta] = 5;
113 mcolormap[Qt::yellow] = 6;
114 mcolormap[Qt::white] = 7;
134 void XFigExportImpVisitor::mapColor(
const ObjectDrawer* obj )
136 if ( ! obj->
shown() )
return;
138 if ( mcolormap.find( color ) == mcolormap.end() )
140 int newcolorid = mnextcolorid++;
143 << color.
name() <<
"\n";
144 mcolormap[color] = newcolorid;
151 assert( mcolormap.find( obj->
drawer()->
color() ) != mcolormap.end() );
162 int width = mcurobj->drawer()->width();
163 if ( width == -1 ) width = 1;
166 emitLine( a, b, width );
169 void XFigExportImpVisitor::emitLine(
const Coordinate& a,
const Coordinate& b,
int width,
bool vector )
174 mstream << width <<
" ";
175 mstream << mcurcolorid <<
" ";
205 QPoint ca = convertCoord( a );
206 QPoint cb = convertCoord( b );
208 mstream << ca.
x() <<
" " << ca.
y() <<
" " << cb.
x() <<
" " << cb.
y() <<
"\n";
214 int width = mcurobj->drawer()->width();
215 if ( width == -1 ) width = 5;
221 mstream <<
"1 " <<
" "
222 << mcurcolorid <<
" "
223 << mcurcolorid <<
" "
231 << center.
x() <<
" " << center.
y() <<
" "
232 << width <<
" " << width <<
" "
235 << center.
x() + width <<
" "
236 << center.
y() <<
"\n";
246 << mcurcolorid <<
" "
266 int width = mcurobj->drawer()->width();
267 if ( width == -1 ) width = 1;
268 emitLine( imp->
a(), imp->
b(), width, true );
285 int width = mcurobj->drawer()->width();
286 if ( width == -1 ) width = 1;
287 mstream << width <<
" "
288 << mcurcolorid <<
" "
297 << center.
x() <<
" " << center.
y() <<
" "
298 << radius <<
" " << radius <<
" "
301 << center.
x() + radius <<
" "
302 << center.
y() <<
"\n";
307 int width = mcurobj->drawer()->width();
308 if ( width == -1 ) width = 1;
321 double radiusx = data.
pdimen / ( 1 - e * e );
324 double d = -e * data.
pdimen / ( 1 - e * e );
328 double radiusy = sqrt( r*r - d*d );
331 const QPoint qcenter = convertCoord( center );
332 const int radius_x = ( convertCoord( center +
Coordinate( radiusx, 0 ) ) -
333 convertCoord( center ) ).x();
334 const int radius_y = ( convertCoord( center +
Coordinate( radiusy, 0 ) ) -
335 convertCoord( center ) ).x();
336 const QPoint qpoint2 = convertCoord( center +
Coordinate( -sin( anglex ), cos( anglex ) ) * radiusy );
342 << mcurcolorid <<
" "
350 << qcenter.
x() <<
" "
351 << qcenter.
y() <<
" "
354 << qcenter.
x() <<
" "
355 << qcenter.
y() <<
" "
356 << qpoint2.
x() <<
" "
357 << qpoint2.
y() <<
" ";
370 int width = mcurobj->drawer()->width();
371 if ( width == -1 ) width = 1;
373 emitLine( a, b, width );
382 int width = mcurobj->drawer()->width();
383 if ( width == -1 ) width = 1;
385 emitLine( a, b, width );
391 const double radius = imp->
radius();
393 const double endangle = startangle + imp->
angle();
394 const double middleangle = ( startangle + endangle ) / 2;
398 const QPoint a = convertCoord( center + ad );
399 const QPoint b = convertCoord( center + bd );
400 const QPoint c = convertCoord( center + cd );
401 const QPoint cent = convertCoord( center );
406 int width = mcurobj->drawer()->width();
407 if ( width == -1 ) width = 1;
408 mstream << width <<
" "
409 << mcurcolorid <<
" "
418 int direction = imp->
angle() > 0 ? 1 : 0;
420 mstream << direction <<
" "
423 << cent.
x() <<
" " << cent.
y() <<
" "
424 << a.
x() <<
" " << a.
y() <<
" "
425 << b.
x() <<
" " << b.
y() <<
" "
426 << c.
x() <<
" " << c.
y() <<
" "
432 int width = mcurobj->drawer()->width();
433 if ( width == -1 ) width = 1;
434 const std::vector<Coordinate> oldpts = imp->
points();
436 std::vector<Coordinate> pts;
437 std::copy( oldpts.begin(), oldpts.end(), std::back_inserter( pts ) );
438 pts.push_back( pts[0] );
442 mstream << width <<
" ";
443 mstream << mcurcolorid <<
" ";
444 mstream << mcurcolorid <<
" ";
456 mstream << pts.size();
460 bool in_line =
false;
461 for (
uint i = 0; i < pts.size(); ++i )
469 QPoint p = convertCoord( pts[i] );
470 mstream <<
" " << p.
x() <<
" " << p.
y();
483 int width = mcurobj->drawer()->width();
484 if ( width == -1 ) width = 1;
485 const std::vector<Coordinate> oldpts = imp->
points();
487 std::vector<Coordinate> pts;
488 std::copy( oldpts.begin(), oldpts.end(), std::back_inserter( pts ) );
489 pts.push_back( pts[0] );
493 mstream << width <<
" ";
494 mstream << mcurcolorid <<
" ";
495 mstream << mcurcolorid <<
" ";
507 mstream << pts.size();
511 bool in_line =
false;
512 for (
uint i = 0; i < pts.size(); ++i )
520 QPoint p = convertCoord( pts[i] );
521 mstream <<
" " << p.
x() <<
" " << p.
y();
533 int width = mcurobj->drawer()->width();
534 if ( width == -1 ) width = 1;
535 const std::vector<Coordinate> pts = imp->
points();
539 mstream << width <<
" ";
540 mstream << mcurcolorid <<
" ";
541 mstream << mcurcolorid <<
" ";
553 mstream << pts.size();
557 bool in_line =
false;
558 for (
uint i = 0; i < pts.size(); ++i )
566 QPoint p = convertCoord( pts[i] );
567 mstream <<
" " << p.
x() <<
" " << p.
y();
581 ":document", i18n(
"*.fig|XFig Documents (*.fig)" ),
582 i18n(
"Export as XFig File" ), &w );
586 QString file_name = kfd->selectedFile();
590 QFile file( file_name );
591 if ( ! file.
open( QIODevice::WriteOnly ) )
593 KMessageBox::sorry( &w, i18n(
"The file \"%1\" could not be opened. Please "
594 "check if the file permissions are set correctly." ,
599 stream <<
"#FIG 3.2 Produced by Kig\n";
600 stream <<
"Landscape\n";
601 stream <<
"Center\n";
602 stream <<
"Metric\n";
604 stream <<
"100.00\n";
605 stream <<
"Single\n";
607 stream <<
"1200 2\n";
610 XFigExportImpVisitor visitor( stream, w );
612 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
615 visitor.mapColor( ( *i )->drawer() );
618 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
void calcRayBorderPoints(const Coordinate &a, Coordinate &b, const Rect &r)
this does the same as the above function, but only for b.
An ObjectImp representing a closed polygonal.
Rect surroundingRect() const
An ObjectImp representing a cubic.
LocusImp is an imp that consists of a copy of the curveimp that the moving point moves over...
LineData data() const
Get the LineData for this AbstractLineImp.
double esintheta0
The esintheta0 value from the polar equation.
An ObjectImp representing an open polygonal.
bool shown() const
returns whether the object this ObjectDrawer is responsible for will be drawn or not.
This file dialog is pretty like KFileDialog, but allow us to make an option widget popup to the user...
Coordinate b
Another point on the line.
void visit(const ObjectImp *imp)
An ObjectImp representing a circle.
Coordinate bottomLeft() const
virtual void visit(ObjectImpVisitor *vtor) const =0
An ObjectImp representing a ray.
This file is part of Kig, a KDE program for Interactive Geometry...
const KigDocument & document() const
const Coordinate center() const
Return the center of this circle.
const ObjectDrawer * drawer() const
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
const std::vector< Coordinate > points() const
Returns the vector with polygon points.
void run(const KigPart &doc, KigWidget &w)
Do what you need to do.
double radius() const
Return the radius of this arc.
The Coordinate class is the basic class representing a 2D location by its x and y components...
An ObjectImp representing a vector.
const Coordinate normalize(double length=1) const
Normalize.
double angle() const
Return the dimension in radians of this arc.
An ObjectHolder represents an object as it is known to the document.
An ObjectImp representing a point.
Coordinate focus1
The first focus of this conic.
Coordinate a
One point on the line.
double pdimen
The pdimen value from the polar equation.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
double ecostheta0
The ecostheta0 value from the polar equation.
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
An ObjectImp representing a conic.
const Coordinate center() const
Return the center of this arc.
const ObjectImp * imp() const
double startAngle() const
Return the start angle in radians of this arc.
const Coordinate a() const
Return the start point of this vector.
A class holding some information about how a certain object is drawn on the window.
virtual const ConicPolarData polarData() const =0
Return the polar representation of this conic.
double radius() const
Return the radius of this circle.
static bool visit(const ObjectCalcer *o, const std::vector< ObjectCalcer * > &from, std::vector< ObjectCalcer * > &ret)
void calcBorderPoints(Coordinate &p1, Coordinate &p2, const Rect &r)
this sets p1 and p2 to p1' and p2' so that p1'p2' is the same line as p1p2, and so that p1' and p2' a...
QString menuEntryName() const
Returns a string like i18n( "Image..." )
static bool operator<(const QColor &a, const QColor &b)
virtual int conicType() const
Type of conic.
An ObjectImp representing a line.
An ObjectImp representing an arc.
QColor color() const
returns the color that the object will be drawn in
const Coordinate b() const
Return the end point of this vector.
QString menuIcon() const
Returns a string with the name of the icon.
An ObjectImp representing a filled polygon.
QByteArray toAscii() const
An ObjectImp representing an angle.
This class represents an equation of a conic in the form .
An ObjectImp representing a segment.