21 #include "../misc/goniometry.h"
22 #include "../objects/circle_imp.h"
23 #include "../objects/cubic_imp.h"
24 #include "../objects/bezier_imp.h"
25 #include "../objects/curve_imp.h"
26 #include "../objects/line_imp.h"
27 #include "../objects/locus_imp.h"
28 #include "../objects/object_drawer.h"
29 #include "../objects/object_holder.h"
30 #include "../objects/object_imp.h"
31 #include "../objects/other_imp.h"
32 #include "../objects/point_imp.h"
33 #include "../objects/polygon_imp.h"
34 #include "../objects/text_imp.h"
37 void PGFExporterImpVisitor::newLine()
43 QString PGFExporterImpVisitor::emitPenColor(
const QColor& c )
46 pencolor =
"color={rgb:red," + QString::number(c.red()) +
";green," + QString::number(c.green()) +
";blue," + QString::number(c.blue()) +
"}";
51 QString PGFExporterImpVisitor::emitPenStyle(
const Qt::PenStyle& style )
53 QString penstyle(
"line style=");
56 if ( style == Qt::SolidLine ) {
58 }
else if ( style == Qt::DashLine ) {
60 }
else if ( style == Qt::DotLine ) {
61 penstyle =
"dotted,dotsep=2pt";
62 }
else if ( style == Qt::DashDotLine ) {
64 }
else if ( style == Qt::DashDotDotLine ) {
71 QString PGFExporterImpVisitor::emitPenSize(
const int width )
79 pensize =
"line width=1pt";
84 pensize =
"line width=" + QString::number(width / 2.0) +
"pt";
90 QString PGFExporterImpVisitor::emitPen(
const QColor& c,
const int width,
const Qt::PenStyle& style )
94 pen = emitPenColor(c) +
", " + emitPenSize(width) +
", " + emitPenStyle(style);
99 QString PGFExporterImpVisitor::emitStyle(
const ObjectDrawer* od )
101 int width = od->
width();
102 if ( width == -1 ) width = 1;
107 style = emitPen( od->
color(), width, od->
style() );
112 QString PGFExporterImpVisitor::emitCoord(
const Coordinate& c )
115 ret =
"(" + QString::number(c.
x) +
"," + QString::number(c.
y) +
")";
125 mstream <<
"\\draw[" << emitStyle(od) <<
", ->]";
129 mstream <<
"\\draw[" << emitStyle(od) <<
"]";
131 mstream <<
" " << emitCoord(a)
138 void PGFExporterImpVisitor::plotGenericCurve(
const CurveImp* imp )
140 std::vector< std::vector< Coordinate > > coordlist;
141 coordlist.push_back( std::vector< Coordinate >() );
146 for (
double i = 0.0; i <= 1.0; i += 0.0001 )
151 if ( coordlist[curid].size() > 0 )
153 coordlist.push_back( std::vector< Coordinate >() );
159 if ( ! ( ( fabs( c.
x ) <= 10000 ) && ( fabs( c.
y ) <= 10000 ) ) )
165 coordlist.push_back( std::vector< Coordinate >() );
168 coordlist[curid].push_back( c );
172 for (
uint i = 0; i < coordlist.size(); ++i )
174 uint s = coordlist[i].size();
179 QString tmp =
"\\draw [" + emitStyle( mcurobj->
drawer() ) +
", /pgf/fpu,/pgf/fpu/output format=fixed ] ";
182 uint linelength = tmp.length();
184 for (
uint j = 0; j < s; ++j )
186 tmp = emitCoord( coordlist[i][j] );
188 if(linelength + tmp.length() > maxlinelength)
190 linelength = tmp.length();
195 linelength += tmp.length();
232 emitLine( a, b, mcurobj->
drawer(), false );
240 if ( width == -1) { width = 2.5; }
241 else { width /= 2.5; }
243 mstream <<
"\\filldraw [" << emitPenColor(mcurobj->
drawer()->
color()) <<
"] "
245 <<
" circle (" << width <<
"pt )";
252 mstream <<
"\\node ";
255 mstream <<
"[rectangle,draw] ";
259 <<
" {" << imp->
text() <<
"}";
268 double radius = 0.75;
269 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
",->] "
270 << emitCoord(imp->
point())
271 <<
" +(" << start <<
":" << radius <<
")"
272 <<
" arc (" << start <<
":" << end <<
":" << radius <<
")";
282 emitLine( a, b, mcurobj->
drawer(), true );
288 plotGenericCurve( imp );
294 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] "
295 << emitCoord( imp->
center() )
296 <<
" circle (" << imp->
radius() <<
")";
303 plotGenericCurve(imp);
309 plotGenericCurve(imp);
318 emitLine( a, b, mcurobj->
drawer(), false );
328 emitLine( a, b, mcurobj->
drawer(), false );
336 double radius = imp->
radius();
337 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] "
338 << emitCoord(imp->
center())
339 <<
" +(" << start <<
":" << radius <<
")"
340 <<
" arc (" << start <<
":" << end <<
":" << radius <<
")";
347 mstream <<
"\\filldraw [" << emitStyle( mcurobj->
drawer() ) <<
"] ";
349 std::vector<Coordinate> pts = imp->
points();
350 for (
uint i = 0; i < pts.size(); i++ )
352 mstream << emitCoord( pts[i] );
362 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] ";
364 std::vector<Coordinate> pts = imp->
points();
365 for (
uint i = 0; i < pts.size(); i++ )
367 mstream << emitCoord( pts[i] );
377 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] ";
379 std::vector<Coordinate> pts = imp->
points();
380 for (
uint i = 0; i < pts.size(); i++ )
382 mstream << emitCoord( pts[i] );
383 if (i < pts.size() - 1)
394 std::vector<Coordinate> pts = imp->
points();
401 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] "
402 << emitCoord(pts.at(0))
404 << emitCoord(pts.at(0))
406 << emitCoord(pts.at(1))
408 << emitCoord(pts.at(0))
410 << emitCoord(pts.at(0))
412 << emitCoord(pts.at(1))
414 << emitCoord(pts.at(0))
416 << emitCoord(pts.at(2))
418 << emitCoord(pts.at(0))
420 << emitCoord(pts.at(2));
424 mstream <<
"\\draw [" << emitStyle( mcurobj->
drawer() ) <<
"] "
425 << emitCoord(pts.front())
427 << emitCoord(pts.at(1))
429 << emitCoord(pts.at(2))
431 << emitCoord(pts.back());
435 plotGenericCurve(imp);
443 plotGenericCurve(imp);
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.
LineData data() const
Get the LineData for this vector.
const Coordinate coordinate() const
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.
Coordinate b
Another point on the line.
An ObjectImp representing a circle.
virtual void visit(ObjectImpVisitor *vtor) const =0
An ObjectImp representing a ray.
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.
const std::vector< Coordinate > points() const
Returns the vector with polygon points.
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...
virtual const Coordinate getPoint(double param, const KigDocument &) const =0
An ObjectImp representing a vector.
virtual const ObjectImpType * type() const =0
Returns the lowermost ObjectImpType that this object is an instantiation of.
QString translatedName() const
The name of this type, translated to the currently used language.
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.
double angle() const
Return the dimension in radians of this angle.
Coordinate a
One point on the line.
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 ...
int width() const
return the width of the object
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.
double startAngle() const
Return the start angle in radians of this angle.
static Coordinate invalidCoord()
Create an invalid Coordinate.
A class holding some information about how a certain object is drawn on the window.
double radius() const
Return the radius of this circle.
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 visit(ObjectHolder *obj)
An ObjectImp representing a line.
const std::vector< Coordinate > points() const
Returns the vector with control points.
An ObjectImp representing an arc.
QColor color() const
returns the color that the object will be drawn in
Qt::PenStyle style() const
return PenStyle for all objects except points
An ObjectImp representing a filled polygon.
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.