26 #include "../kig/kig_document.h"
27 #include "../kig/kig_part.h"
28 #include "../kig/kig_view.h"
29 #include "../misc/common.h"
30 #include "../misc/goniometry.h"
31 #include "../misc/kigfiledialog.h"
32 #include "../misc/rect.h"
33 #include "../objects/circle_imp.h"
34 #include "../objects/cubic_imp.h"
35 #include "../objects/bezier_imp.h"
36 #include "../objects/curve_imp.h"
37 #include "../objects/line_imp.h"
38 #include "../objects/locus_imp.h"
39 #include "../objects/object_drawer.h"
40 #include "../objects/object_holder.h"
41 #include "../objects/object_imp.h"
42 #include "../objects/other_imp.h"
43 #include "../objects/point_imp.h"
44 #include "../objects/polygon_imp.h"
45 #include "../objects/text_imp.h"
50 #include <qcheckbox.h>
53 #include <qtextstream.h>
56 #include <kmessagebox.h>
58 #include <config-kig.h>
61 #define KDE_TRUNC(a) trunc(a)
63 #define KDE_TRUNC(a) rint(a)
77 return i18n(
"Export to &Latex..." );
82 return i18n(
"&Latex..." );
90 class PSTricksExportImpVisitor
97 std::vector<ColorMap> mcolors;
101 void mapColor(
const QColor& color );
104 : mstream( s ), mw( w ), msr( mw.showingRect() )
138 const Qt::PenStyle s,
bool vector =
false );
147 int findColor(
const QColor& c );
152 double dimRealToCoord(
int dim );
156 QString writeStyle( Qt::PenStyle style );
160 void plotGenericCurve(
const CurveImp* imp );
163 void PSTricksExportImpVisitor::emitCoord(
const Coordinate& c )
165 mstream <<
"(" << c.
x - msr.left() <<
"," << c.
y - msr.bottom() <<
")";
169 const int width,
const Qt::PenStyle s,
172 mstream <<
"\\psline[linecolor=" << mcurcolorid <<
",linewidth=" << width / 100.0
173 <<
"," << writeStyle( s );
175 mstream <<
",arrowscale=3,arrowinset=1.3";
184 void PSTricksExportImpVisitor::newLine()
189 int PSTricksExportImpVisitor::findColor(
const QColor& c )
191 for (
uint i = 0; i < mcolors.size(); ++i )
193 if ( c == mcolors[i].color )
199 void PSTricksExportImpVisitor::mapColor(
const QColor& color )
201 if ( findColor( color ) == -1 )
204 newcolor.color = color;
207 newcolor.name = tmpname;
209 mstream <<
"\\newrgbcolor{" << tmpname <<
"}{"
210 << color.
red() / 255.0 <<
" " << color.
green() / 255.0 <<
" "
211 << color.
blue() / 255.0 <<
"}\n";
215 double PSTricksExportImpVisitor::dimRealToCoord(
int dim )
217 QRect qr( 0, 0, dim, dim );
218 Rect r = mw.screenInfo().fromScreen( qr );
219 return fabs( r.
width() );
222 QString PSTricksExportImpVisitor::writeStyle( Qt::PenStyle style )
225 if ( style == Qt::DashLine )
227 else if ( style == Qt::DotLine )
228 ret +=
"dotted,dotsep=2pt";
234 void PSTricksExportImpVisitor::plotGenericCurve(
const CurveImp* imp )
236 int width = mcurobj->drawer()->width();
237 if ( width == -1 ) width = 1;
239 QString prefix =
QString(
"\\pscurve[linecolor=%1,linewidth=%2,%3]" )
241 .
arg( width / 100.0 )
242 .
arg( writeStyle( mcurobj->drawer()->style() ) );
244 std::vector< std::vector< Coordinate > > coordlist;
245 coordlist.
push_back( std::vector< Coordinate >() );
250 for (
double i = 0.0; i <= 1.0; i += 0.005 )
252 c = imp->
getPoint( i, mw.document() );
255 if ( coordlist[curid].size() > 0 )
257 coordlist.push_back( std::vector< Coordinate >() );
263 if ( ! ( ( fabs( c.
x ) <= 1000 ) && ( fabs( c.
y ) <= 1000 ) ) )
269 coordlist.push_back( std::vector< Coordinate >() );
272 coordlist[curid].push_back( c );
276 if (
const ConicImp* conic = dynamic_cast< const ConicImp* >( imp ) )
279 if ( conic->conicType() == 1 && coordlist.size() == 1 && coordlist[0].size() > 1 )
281 coordlist[0].push_back( coordlist[0][0] );
284 for (
uint i = 0; i < coordlist.size(); ++i )
286 uint s = coordlist[i].size();
292 for (
uint j = 0; j < s; ++j )
293 emitCoord( coordlist[i][j] );
302 const int id = findColor( obj->
drawer()->
color() );
305 mcurcolorid = mcolors[id].name;
316 int width = mcurobj->drawer()->width();
317 if ( width == -1 ) width = 1;
319 emitLine( a, b, width, mcurobj->drawer()->style() );
324 int width = mcurobj->drawer()->width();
325 if ( width == -1 ) width = 5;
328 mstream <<
"\\psdots[linecolor=" << mcurcolorid
329 <<
",dotscale=" << width <<
",dotstyle=";
330 const int ps = mcurobj->drawer()->pointStyle();
331 QString pss(
"*,fillstyle=solid,fillcolor=" + mcurcolorid );
333 pss =
"o,fillstyle=none";
335 pss =
"square*,fillstyle=solid,fillcolor=" + mcurcolorid;
337 pss =
"square,fillstyle=none";
339 pss =
"+,dotangle=45";
340 mstream << pss <<
"]";
348 mstream <<
"\\rput[tl]";
355 mstream <<
" \\psframebox[linecolor=c5c2c5,linewidth=0.01"
356 <<
",fillstyle=solid,fillcolor=ffffde]"
357 <<
"{" << imp->
text() <<
"}";
361 mstream << imp->
text();
371 const double radius = dimRealToCoord( 50 ) * unit;
373 double endangle = startangle + imp->
angle();
380 int width = mcurobj->drawer()->width();
381 if ( width == -1 ) width = 1;
383 mstream <<
"\\psarc[linecolor=" << mcurcolorid <<
",linewidth=" << width / 100.0
384 <<
"," << writeStyle( mcurobj->drawer()->style() ) <<
",arrowscale=3,arrowinset=0]{->}";
386 mstream <<
"{" << radius <<
"}{" << startangle <<
"}{" << endangle <<
"}";
395 int width = mcurobj->drawer()->width();
396 if ( width == -1 ) width = 1;
398 emitLine( a, b, width, mcurobj->drawer()->style(), true );
403 plotGenericCurve( imp );
408 int width = mcurobj->drawer()->width();
409 if ( width == -1 ) width = 1;
411 mstream <<
"\\pscircle[linecolor=" << mcurcolorid <<
",linewidth=" << width / 100.0
412 <<
"," << writeStyle( mcurobj->drawer()->style() ) <<
"]";
413 emitCoord( imp->
center() );
414 mstream <<
"{" << imp->
radius() * unit <<
"}";
420 plotGenericCurve( imp );
434 int width = mcurobj->drawer()->width();
435 if ( width == -1 ) width = 1;
437 emitLine( a, b, width, mcurobj->drawer()->style() );
446 int width = mcurobj->drawer()->width();
447 if ( width == -1 ) width = 1;
449 emitLine( a, b, width, mcurobj->drawer()->style() );
455 const double radius = imp->
radius() * unit;
457 double endangle = startangle + imp->
angle();
464 int width = mcurobj->drawer()->width();
465 if ( width == -1 ) width = 1;
467 mstream <<
"\\psarc[linecolor=" << mcurcolorid <<
",linewidth=" << width / 100.0
468 <<
"," << writeStyle( mcurobj->drawer()->style() ) <<
"]";
470 mstream <<
"{" << radius <<
"}{" << startangle <<
"}{" << endangle <<
"}";
476 int width = mcurobj->drawer()->width();
477 if ( width == -1 ) width = 1;
479 mstream <<
"\\pspolygon[linecolor=" << mcurcolorid <<
",linewidth=0"
480 <<
"," << writeStyle( mcurobj->drawer()->style() )
481 <<
",hatchcolor=" << mcurcolorid <<
",hatchwidth=0.5pt,hatchsep=0.5pt"
482 <<
",fillcolor=" << mcurcolorid <<
",fillstyle=crosshatch]";
484 std::vector<Coordinate> pts = imp->
points();
485 for (
uint i = 0; i < pts.size(); i++ )
494 int width = mcurobj->drawer()->width();
495 if ( width == -1 ) width = 1;
497 mstream <<
"\\pspolygon[linecolor=" << mcurcolorid <<
",linewidth=0"
498 <<
"," << writeStyle( mcurobj->drawer()->style() ) <<
']';
500 std::vector<Coordinate> pts = imp->
points();
501 for (
uint i = 0; i < pts.size(); i++ )
510 int width = mcurobj->drawer()->width();
511 if ( width == -1 ) width = 1;
513 mstream <<
"\\psline[linecolor=" << mcurcolorid <<
",linewidth=0"
514 <<
"," << writeStyle( mcurobj->drawer()->style() ) <<
']';
516 std::vector<Coordinate> pts = imp->
points();
517 for (
uint i = 0; i < pts.size(); i++ )
527 plotGenericCurve(imp);
533 plotGenericCurve(imp);
539 QString(), i18n(
"*.tex|Latex Documents (*.tex)" ),
540 i18n(
"Export as Latex" ), &w );
549 KConfigGroup cg = KGlobal::config()->group(
"Latex Exporter");
561 QString file_name = kfd->selectedFile();
571 cg.writeEntry(
"OutputFormat", (
int)format);
572 cg.writeEntry(
"Standalone", standalone);
574 QFile file( file_name );
575 if ( ! file.
open( QIODevice::WriteOnly ) )
577 KMessageBox::sorry( &w, i18n(
"The file \"%1\" could not be opened. Please "
578 "check if the file permissions are set correctly." ,
590 stream <<
"\\documentclass[a4paper]{minimal}\n";
592 stream <<
"\\usepackage{pstricks}\n";
593 stream <<
"\\usepackage{pst-plot}\n";
594 stream <<
"\\author{Kig " << KIGVERSION <<
"}\n";
595 stream <<
"\\begin{document}\n";
610 const double tmpwidth = 15.0;
611 const double xunit = tmpwidth / width;
612 const double yunit = xunit;
614 stream <<
"\\begin{pspicture*}(0,0)(" << tmpwidth <<
"," << yunit * height <<
")\n";
615 stream <<
"\\psset{xunit=" << xunit <<
"}\n";
616 stream <<
"\\psset{yunit=" << yunit <<
"}\n";
618 PSTricksExportImpVisitor visitor( stream, w );
619 visitor.unit = xunit;
621 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
624 if ( ! ( *i )->shown() )
continue;
625 visitor.mapColor( ( *i )->drawer()->color() );
627 visitor.mapColor(
QColor( 255, 255, 222 ) );
628 visitor.mapColor(
QColor( 197, 194, 197 ) );
629 visitor.mapColor(
QColor( 160, 160, 164 ) );
630 visitor.mapColor(
QColor( 192, 192, 192 ) );
635 stream <<
"\\psframe[linecolor=black,linewidth=0.02]"
637 <<
"(" << width <<
"," << height <<
")"
645 double startingpoint = - left - 1 +
static_cast<int>(
KDE_TRUNC( left ) );
646 for (
double i = startingpoint; i < width; ++i )
648 stream <<
"\\psline[linecolor=c0c0c0,linewidth=0.01,linestyle=dashed]"
650 <<
"(" << i <<
"," << height <<
")"
655 startingpoint = - bottom - 1 +
static_cast<int>(
KDE_TRUNC( bottom ) );
656 for (
double i = startingpoint; i < height; ++i )
658 stream <<
"\\psline[linecolor=c0c0c0,linewidth=0.01,linestyle=dashed]"
660 <<
"(" << width <<
"," << i <<
")"
668 stream <<
"\\psaxes[linecolor=a0a0a4,linewidth=0.03,ticks=none,arrowinset=0]{->}"
669 <<
"(" << -left <<
"," << -bottom <<
")"
671 <<
"(" << width <<
"," << height <<
")"
675 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
681 stream <<
"\\end{pspicture*}\n";
684 stream <<
"\\end{document}\n";
691 stream <<
"\\documentclass[a4paper]{minimal}\n";
692 stream <<
"\\usepackage{tikz}\n";
693 stream <<
"\\usetikzlibrary{calc}\n";
694 stream <<
"\\usepgflibrary{fpu}\n";
695 stream <<
"\\begin{document}\n";
701 double size = qMax(frameRect.
height(),frameRect.
width());
702 double scale = (size == 0) ? 1 : 10/size;
705 stream <<
"\\begin{tikzpicture}"
707 <<
"scale=" << scale <<
",\n"
710 double gLeft = frameRect.
left();
711 double gBottom = frameRect.
bottom();
712 double gRight = frameRect.
right();
713 double gTop = frameRect.
top();
716 stream <<
"\\clip (" << gLeft <<
',' << gBottom <<
") rectangle (" << gRight <<
',' << gTop <<
");\n";
720 stream <<
"\\draw [help lines] ("<< floor(qMin(0.0,gRight)) <<
',' << floor(qMin(0.0,gTop))
721 <<
") grid (" << ceil(qMax(0.0,gRight)) <<
',' << ceil(qMax(0.0,gTop)) <<
");\n";
722 stream <<
"\\draw [help lines] ("<< floor(qMin(0.0,gLeft)) <<
',' << floor(qMin(0.0,gTop))
723 <<
") grid (" << ceil(qMax(0.0,gLeft)) <<
',' << ceil(qMax(0.0,gTop)) <<
");\n";
724 stream <<
"\\draw [help lines] ("<< floor(qMin(0.0,gRight)) <<
',' << floor(qMin(0.0,gBottom))
725 <<
") grid (" << ceil(qMax(0.0,gRight)) <<
',' << ceil(qMax(0.0,gBottom)) <<
");\n";
726 stream <<
"\\draw [help lines] ("<< floor(qMin(0.0,gLeft)) <<
',' << floor(qMin(0.0,gBottom))
727 <<
") grid (" << ceil(qMax(0.0,gLeft)) <<
',' << ceil(qMax(0.0,gBottom)) <<
");\n";
731 if (gBottom < 0 && gTop > 0)
733 stream <<
"\\draw [color=black,->] (" << gLeft <<
",0) -- (" << gRight <<
",0);\n";
735 if (gLeft < 0 && gRight > 0)
737 stream <<
"\\draw [color=black,->] (0," << gBottom <<
") -- (0," << gTop <<
");\n";
742 stream <<
"\\draw [color=black] (" << gLeft <<
',' << gBottom <<
") rectangle (" << gRight <<
',' << gTop <<
");\n";
746 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
751 stream <<
"\\end{tikzpicture}\n";
756 stream <<
"\\end{document}\n";
770 stream <<
"\\documentclass[a4paper,10pt]{article}\n";
771 stream <<
"\\usepackage{asymptote}\n";
773 stream <<
"\\pagestyle{empty}";
775 stream <<
"\\begin{document}\n";
778 stream <<
"\\begin{asy}[width=\\the\\linewidth]\n";
780 stream <<
"import math;\n";
781 stream <<
"import graph;\n";
783 stream <<
"real textboxmargin = 2mm;\n";
791 double startingpoint =
static_cast<double>(
KDE_TRUNC( left ) );
792 for (
double i = startingpoint; i < left+width; ++i )
794 stream <<
"draw((" << i <<
"," << bottom <<
")--(" << i <<
"," << bottom+height <<
"),gray);\n";
797 startingpoint =
static_cast<double>(
KDE_TRUNC( bottom ) );
798 for (
double i = startingpoint; i < bottom+height; ++i )
800 stream <<
"draw((" << left <<
"," << i <<
")--(" << left+width <<
"," << i <<
"),gray);\n";
807 stream <<
"draw(("<<left<<
",0)--("<<left+width<<
",0), black, Arrow);\n";
808 stream <<
"draw((0,"<<bottom<<
")--(0,"<<bottom+height<<
"), black, Arrow);\n";
814 for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
820 stream <<
"path frame = ("<<left<<
","<<bottom<<
")--("
821 <<left<<
","<<bottom+height<<
")--("
822 <<left+width<<
","<<bottom+height<<
")--("
823 <<left+width<<
","<<bottom<<
")--cycle;\n";
827 stream <<
"draw(frame, black);\n";
829 stream <<
"clip(frame);\n";
831 stream <<
"\\end{asy}\n";
836 stream <<
"\\end{document}\n";
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.
An ObjectImp representing polynomial Bézier Curve.
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.
void setExtraFrame(bool frame)
LineData data() const
Get the LineData for this vector.
const Coordinate coordinate() const
QString menuEntryName() const
Returns a string like i18n( "Image..." )
An ObjectImp representing an open polygonal.
bool shown() const
returns whether the object this ObjectDrawer is responsible for will be drawn or not.
const Coordinate point() const
Return the center of this angle.
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.
virtual void visit(ObjectImpVisitor *vtor) const =0
An ObjectImp representing a ray.
This file is part of Kig, a KDE program for Interactive Geometry...
QString menuIcon() const
Returns a string with the name of the icon.
const KigDocument & document() const
An ObjectImp representing a rational Bézier curve.
const Coordinate center() const
Return the center of this circle.
const ObjectDrawer * drawer() const
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
void run(const KigPart &doc, KigWidget &w)
Do what you need to do.
QString & remove(int position, int n)
const std::vector< Coordinate > points() const
Returns the vector with polygon points.
double radius() const
Return the radius of this arc.
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
The Coordinate class is the basic class representing a 2D location by its x and y components...
virtual const Coordinate getPoint(double param, const KigDocument &) const =0
An ObjectImp representing a vector.
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.
double distance(const Coordinate &p) const
Distance to another Coordinate.
void setFormat(LatexOutputFormat format)
double angle() const
Return the dimension in radians of this angle.
Coordinate a
One point on the line.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
LatexOutputFormat format()
An ObjectImp representing a conic.
static double convert(const double angle, const Goniometry::System from, const Goniometry::System to)
The most useful method of this class: convert the specified angle from the system from to the system ...
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.
void setStandalone(bool standalone)
double startAngle() const
Return the start angle in radians of this angle.
static Coordinate invalidCoord()
Create an invalid Coordinate.
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...
void setOptionCaption(const QString &caption)
Set the caption of the option dialog.
void visit(ObjectHolder *obj)
An ObjectImp representing a line.
An ObjectImp representing an arc.
QColor color() const
returns the color that the object will be drawn in
void setOptionsWidget(QWidget *w)
Use this to set the widget containing the options of eg an export filter.
An ObjectImp representing a filled polygon.
bool showExtraFrame() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void visit(ObjectHolder *obj)
bool valid() const
Return whether this is a valid Coordinate.
An ObjectImp representing an angle.
This class represents a curve: something which is composed of points, like a line, a circle, a locus.
An ObjectImp representing a segment.