• 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
latexexporter.cc
Go to the documentation of this file.
1 // Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
2 // Copyright (C) 2010,2011 Raoul Bourquin (asymptote exporter part)
3 // Copyright (C) 2012 Raoul Bourquin (PGF/TikZ exporter part)
4 
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 
20 #include "latexexporter.h"
21 #include "latexexporteroptions.h"
22 
23 #include "asyexporterimpvisitor.h"
24 #include "pgfexporterimpvisitor.h"
25 
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"
46 
47 #include <math.h>
48 #include <algorithm>
49 
50 #include <qcheckbox.h>
51 #include <qcolor.h>
52 #include <qfile.h>
53 #include <qtextstream.h>
54 
55 #include <klocale.h>
56 #include <kmessagebox.h>
57 
58 #include <config-kig.h>
59 
60 #ifdef HAVE_TRUNC
61 #define KDE_TRUNC(a) trunc(a)
62 #else
63 #define KDE_TRUNC(a) rint(a)
64 #endif
65 
66 struct ColorMap {
67  QColor color;
68  QString name;
69 };
70 
71 LatexExporter::~LatexExporter()
72 {
73 }
74 
75 QString LatexExporter::exportToStatement() const
76 {
77  return i18n( "Export to &Latex..." );
78 }
79 
80 QString LatexExporter::menuEntryName() const
81 {
82  return i18n( "&Latex..." );
83 }
84 
85 QString LatexExporter::menuIcon() const
86 {
87  return "text-x-tex";
88 }
89 
90 class PSTricksExportImpVisitor
91  : public ObjectImpVisitor
92 {
93  QTextStream& mstream;
94  ObjectHolder* mcurobj;
95  const KigWidget& mw;
96  Rect msr;
97  std::vector<ColorMap> mcolors;
98  QString mcurcolorid;
99 public:
100  void visit( ObjectHolder* obj );
101  void mapColor( const QColor& color );
102 
103  PSTricksExportImpVisitor( QTextStream& s, const KigWidget& w )
104  : mstream( s ), mw( w ), msr( mw.showingRect() )
105  {
106  }
107  using ObjectImpVisitor::visit;
108  void visit( const LineImp* imp );
109  void visit( const PointImp* imp );
110  void visit( const TextImp* imp );
111  void visit( const AngleImp* imp );
112  void visit( const VectorImp* imp );
113  void visit( const LocusImp* imp );
114  void visit( const CircleImp* imp );
115  void visit( const ConicImp* imp );
116  void visit( const CubicImp* imp );
117  void visit( const SegmentImp* imp );
118  void visit( const RayImp* imp );
119  void visit( const ArcImp* imp );
120  void visit( const FilledPolygonImp* imp );
121  void visit( const ClosedPolygonalImp* imp );
122  void visit( const OpenPolygonalImp* imp );
123  void visit( const BezierImp* imp );
124  void visit( const RationalBezierImp* imp );
125 
126  double unit;
127 
128 private:
133  void emitCoord( const Coordinate& c );
137  void emitLine( const Coordinate& a, const Coordinate& b, const int width,
138  const Qt::PenStyle s, bool vector = false );
142  void newLine();
147  int findColor( const QColor& c );
152  double dimRealToCoord( int dim );
156  QString writeStyle( Qt::PenStyle style );
160  void plotGenericCurve( const CurveImp* imp );
161 };
162 
163 void PSTricksExportImpVisitor::emitCoord( const Coordinate& c )
164 {
165  mstream << "(" << c.x - msr.left() << "," << c.y - msr.bottom() << ")";
166 }
167 
168 void PSTricksExportImpVisitor::emitLine( const Coordinate& a, const Coordinate& b,
169  const int width, const Qt::PenStyle s,
170  bool vector )
171 {
172  mstream << "\\psline[linecolor=" << mcurcolorid << ",linewidth=" << width / 100.0
173  << "," << writeStyle( s );
174  if ( vector )
175  mstream << ",arrowscale=3,arrowinset=1.3";
176  mstream << "]";
177  if ( vector )
178  mstream << "{->}";
179  emitCoord( a );
180  emitCoord( b );
181  newLine();
182 }
183 
184 void PSTricksExportImpVisitor::newLine()
185 {
186  mstream << "\n";
187 }
188 
189 int PSTricksExportImpVisitor::findColor( const QColor& c )
190 {
191  for ( uint i = 0; i < mcolors.size(); ++i )
192  {
193  if ( c == mcolors[i].color )
194  return i;
195  }
196  return -1;
197 }
198 
199 void PSTricksExportImpVisitor::mapColor( const QColor& color )
200 {
201  if ( findColor( color ) == -1 )
202  {
203  ColorMap newcolor;
204  newcolor.color = color;
205  QString tmpname = color.name();
206  tmpname.remove( '#' );
207  newcolor.name = tmpname;
208  mcolors.push_back( newcolor );
209  mstream << "\\newrgbcolor{" << tmpname << "}{"
210  << color.red() / 255.0 << " " << color.green() / 255.0 << " "
211  << color.blue() / 255.0 << "}\n";
212  }
213 }
214 
215 double PSTricksExportImpVisitor::dimRealToCoord( int dim )
216 {
217  QRect qr( 0, 0, dim, dim );
218  Rect r = mw.screenInfo().fromScreen( qr );
219  return fabs( r.width() );
220 }
221 
222 QString PSTricksExportImpVisitor::writeStyle( Qt::PenStyle style )
223 {
224  QString ret( "linestyle=" );
225  if ( style == Qt::DashLine )
226  ret += "dashed";
227  else if ( style == Qt::DotLine )
228  ret += "dotted,dotsep=2pt";
229  else
230  ret += "solid";
231  return ret;
232 }
233 
234 void PSTricksExportImpVisitor::plotGenericCurve( const CurveImp* imp )
235 {
236  int width = mcurobj->drawer()->width();
237  if ( width == -1 ) width = 1;
238 
239  QString prefix = QString( "\\pscurve[linecolor=%1,linewidth=%2,%3]" )
240  .arg( mcurcolorid )
241  .arg( width / 100.0 )
242  .arg( writeStyle( mcurobj->drawer()->style() ) );
243 
244  std::vector< std::vector< Coordinate > > coordlist;
245  coordlist.push_back( std::vector< Coordinate >() );
246  uint curid = 0;
247 
248  Coordinate c;
249  Coordinate prev = Coordinate::invalidCoord();
250  for ( double i = 0.0; i <= 1.0; i += 0.005 )
251  {
252  c = imp->getPoint( i, mw.document() );
253  if ( !c.valid() )
254  {
255  if ( coordlist[curid].size() > 0 )
256  {
257  coordlist.push_back( std::vector< Coordinate >() );
258  ++curid;
259  prev = Coordinate::invalidCoord();
260  }
261  continue;
262  }
263  if ( ! ( ( fabs( c.x ) <= 1000 ) && ( fabs( c.y ) <= 1000 ) ) )
264  continue;
265  // if there's too much distance between this coordinate and the previous
266  // one, then it's another piece of curve not joined with the rest
267  if ( prev.valid() && ( c.distance( prev ) > 4.0 ) )
268  {
269  coordlist.push_back( std::vector< Coordinate >() );
270  ++curid;
271  }
272  coordlist[curid].push_back( c );
273  prev = c;
274  }
275  // special case for ellipse
276  if ( const ConicImp* conic = dynamic_cast< const ConicImp* >( imp ) )
277  {
278  // if ellipse, close its path
279  if ( conic->conicType() == 1 && coordlist.size() == 1 && coordlist[0].size() > 1 )
280  {
281  coordlist[0].push_back( coordlist[0][0] );
282  }
283  }
284  for ( uint i = 0; i < coordlist.size(); ++i )
285  {
286  uint s = coordlist[i].size();
287  // there's no point in draw curves empty or with only one point
288  if ( s <= 1 )
289  continue;
290 
291  mstream << prefix;
292  for ( uint j = 0; j < s; ++j )
293  emitCoord( coordlist[i][j] );
294  newLine();
295  }
296 }
297 
298 void PSTricksExportImpVisitor::visit( ObjectHolder* obj )
299 {
300  if ( ! obj->drawer()->shown() )
301  return;
302  const int id = findColor( obj->drawer()->color() );
303  if ( id == -1 )
304  return;
305  mcurcolorid = mcolors[id].name;
306  mcurobj = obj;
307  obj->imp()->visit( this );
308 }
309 
310 void PSTricksExportImpVisitor::visit( const LineImp* imp )
311 {
312  Coordinate a = imp->data().a;
313  Coordinate b = imp->data().b;
314  calcBorderPoints( a, b, msr );
315 
316  int width = mcurobj->drawer()->width();
317  if ( width == -1 ) width = 1;
318 
319  emitLine( a, b, width, mcurobj->drawer()->style() );
320 }
321 
322 void PSTricksExportImpVisitor::visit( const PointImp* imp )
323 {
324  int width = mcurobj->drawer()->width();
325  if ( width == -1 ) width = 5;
326  width /= 5;
327 
328  mstream << "\\psdots[linecolor=" << mcurcolorid
329  << ",dotscale=" << width << ",dotstyle=";
330  const int ps = mcurobj->drawer()->pointStyle();
331  QString pss( "*,fillstyle=solid,fillcolor=" + mcurcolorid );
332  if ( ps == 1 )
333  pss = "o,fillstyle=none";
334  else if ( ps == 2 )
335  pss = "square*,fillstyle=solid,fillcolor=" + mcurcolorid;
336  else if ( ps == 3 )
337  pss = "square,fillstyle=none";
338  else if ( ps == 4 )
339  pss = "+,dotangle=45";
340  mstream << pss << "]";
341  emitCoord( imp->coordinate() );
342  newLine();
343 }
344 
345 void PSTricksExportImpVisitor::visit( const TextImp* imp )
346 {
347  // FIXME: support multiline texts...
348  mstream << "\\rput[tl]";
349  emitCoord( imp->coordinate() );
350  newLine();
351  mstream << "{";
352  newLine();
353  if ( imp->hasFrame() )
354  {
355  mstream << " \\psframebox[linecolor=c5c2c5,linewidth=0.01"
356  << ",fillstyle=solid,fillcolor=ffffde]"
357  << "{" << imp->text() << "}";
358  }
359  else
360  {
361  mstream << imp->text();
362  }
363  newLine();
364  mstream << "}";
365  newLine();
366 }
367 
368 void PSTricksExportImpVisitor::visit( const AngleImp* imp )
369 {
370  const Coordinate center = imp->point();
371  const double radius = dimRealToCoord( 50 ) * unit;
372  double startangle = imp->startAngle();
373  double endangle = startangle + imp->angle();
374 // if ( startangle > M_PI )
375 // startangle -= 2 * M_PI;
376  startangle = Goniometry::convert( startangle, Goniometry::Rad, Goniometry::Deg );
377 // if ( endangle > 2 * M_PI )
378 // endangle -= 2 * M_PI;
379  endangle = Goniometry::convert( endangle, Goniometry::Rad, Goniometry::Deg );
380  int width = mcurobj->drawer()->width();
381  if ( width == -1 ) width = 1;
382 
383  mstream << "\\psarc[linecolor=" << mcurcolorid << ",linewidth=" << width / 100.0
384  << "," << writeStyle( mcurobj->drawer()->style() ) << ",arrowscale=3,arrowinset=0]{->}";
385  emitCoord( center );
386  mstream << "{" << radius << "}{" << startangle << "}{" << endangle << "}";
387  newLine();
388 }
389 
390 void PSTricksExportImpVisitor::visit( const VectorImp* imp )
391 {
392  Coordinate a = imp->data().a;
393  Coordinate b = imp->data().b;
394 
395  int width = mcurobj->drawer()->width();
396  if ( width == -1 ) width = 1;
397 
398  emitLine( a, b, width, mcurobj->drawer()->style(), true );
399 }
400 
401 void PSTricksExportImpVisitor::visit( const LocusImp* imp )
402 {
403  plotGenericCurve( imp );
404 }
405 
406 void PSTricksExportImpVisitor::visit( const CircleImp* imp )
407 {
408  int width = mcurobj->drawer()->width();
409  if ( width == -1 ) width = 1;
410 
411  mstream << "\\pscircle[linecolor=" << mcurcolorid << ",linewidth=" << width / 100.0
412  << "," << writeStyle( mcurobj->drawer()->style() ) << "]";
413  emitCoord( imp->center() );
414  mstream << "{" << imp->radius() * unit << "}";
415  newLine();
416 }
417 
418 void PSTricksExportImpVisitor::visit( const ConicImp* imp )
419 {
420  plotGenericCurve( imp );
421 }
422 
423 void PSTricksExportImpVisitor::visit( const CubicImp* )
424 {
425  // FIXME: cubic are not drawn correctly with plotGenericCurve
426 // plotGenericCurve( imp );
427 }
428 
429 void PSTricksExportImpVisitor::visit( const SegmentImp* imp )
430 {
431  Coordinate a = imp->data().a;
432  Coordinate b = imp->data().b;
433 
434  int width = mcurobj->drawer()->width();
435  if ( width == -1 ) width = 1;
436 
437  emitLine( a, b, width, mcurobj->drawer()->style() );
438 }
439 
440 void PSTricksExportImpVisitor::visit( const RayImp* imp )
441 {
442  Coordinate a = imp->data().a;
443  Coordinate b = imp->data().b;
444  calcRayBorderPoints( a, b, msr );
445 
446  int width = mcurobj->drawer()->width();
447  if ( width == -1 ) width = 1;
448 
449  emitLine( a, b, width, mcurobj->drawer()->style() );
450 }
451 
452 void PSTricksExportImpVisitor::visit( const ArcImp* imp )
453 {
454  const Coordinate center = imp->center();
455  const double radius = imp->radius() * unit;
456  double startangle = imp->startAngle();
457  double endangle = startangle + imp->angle();
458 // if ( startangle > M_PI )
459 // startangle -= 2 * M_PI;
460  startangle = Goniometry::convert( startangle, Goniometry::Rad, Goniometry::Deg );
461 // if ( endangle > M_PI )
462 // endangle -= 2 * M_PI;
463  endangle = Goniometry::convert( endangle, Goniometry::Rad, Goniometry::Deg );
464  int width = mcurobj->drawer()->width();
465  if ( width == -1 ) width = 1;
466 
467  mstream << "\\psarc[linecolor=" << mcurcolorid << ",linewidth=" << width / 100.0
468  << "," << writeStyle( mcurobj->drawer()->style() ) << "]";
469  emitCoord( center );
470  mstream << "{" << radius << "}{" << startangle << "}{" << endangle << "}";
471  newLine();
472 }
473 
474 void PSTricksExportImpVisitor::visit( const FilledPolygonImp* imp )
475 {
476  int width = mcurobj->drawer()->width();
477  if ( width == -1 ) width = 1;
478 
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]";
483 
484  std::vector<Coordinate> pts = imp->points();
485  for ( uint i = 0; i < pts.size(); i++ )
486  {
487  emitCoord( pts[i] );
488  }
489  newLine();
490 }
491 
492 void PSTricksExportImpVisitor::visit(const ClosedPolygonalImp* imp)
493 {
494  int width = mcurobj->drawer()->width();
495  if ( width == -1 ) width = 1;
496 
497  mstream << "\\pspolygon[linecolor=" << mcurcolorid << ",linewidth=0"
498  << "," << writeStyle( mcurobj->drawer()->style() ) << ']';
499 
500  std::vector<Coordinate> pts = imp->points();
501  for ( uint i = 0; i < pts.size(); i++ )
502  {
503  emitCoord( pts[i] );
504  }
505  newLine();
506 }
507 
508 void PSTricksExportImpVisitor::visit(const OpenPolygonalImp* imp)
509 {
510  int width = mcurobj->drawer()->width();
511  if ( width == -1 ) width = 1;
512 
513  mstream << "\\psline[linecolor=" << mcurcolorid << ",linewidth=0"
514  << "," << writeStyle( mcurobj->drawer()->style() ) << ']';
515 
516  std::vector<Coordinate> pts = imp->points();
517  for ( uint i = 0; i < pts.size(); i++ )
518  {
519  emitCoord( pts[i] );
520  }
521  newLine();
522 }
523 
524 // TODO: Just a quick fix, improve when reviewing PSTricks exporter
525 void PSTricksExportImpVisitor::visit(const BezierImp* imp)
526 {
527  plotGenericCurve(imp);
528 }
529 
530 // TODO: Just a quick fix, improve when reviewing PSTricks exporter
531 void PSTricksExportImpVisitor::visit(const RationalBezierImp* imp)
532 {
533  plotGenericCurve(imp);
534 }
535 
536 void LatexExporter::run( const KigPart& doc, KigWidget& w )
537 {
538  KigFileDialog* kfd = new KigFileDialog(
539  QString(), i18n( "*.tex|Latex Documents (*.tex)" ),
540  i18n( "Export as Latex" ), &w );
541  kfd->setOptionCaption( i18n( "Latex Options" ) );
542  LatexExporterOptions* opts = new LatexExporterOptions( 0L );
543  kfd->setOptionsWidget( opts );
544 
545  opts->setGrid( doc.document().grid() );
546  opts->setAxes( doc.document().axes() );
547  opts->setExtraFrame( false );
548 
549  KConfigGroup cg = KGlobal::config()->group("Latex Exporter");
550 
551  int fmt = cg.readEntry<int>("OutputFormat", LatexExporterOptions::PSTricks);
552  if (fmt > -1 && fmt < LatexExporterOptions::FormatCount)
553  {
554  opts->setFormat((LatexExporterOptions::LatexOutputFormat)fmt);
555  }
556  opts->setStandalone(cg.readEntry("Standalone", true));
557 
558  if ( !kfd->exec() )
559  return;
560 
561  QString file_name = kfd->selectedFile();
562  bool showgrid = opts->showGrid();
563  bool showaxes = opts->showAxes();
564  bool showframe = opts->showExtraFrame();
565  LatexExporterOptions::LatexOutputFormat format = opts->format();
566  bool standalone = opts->standalone();
567 
568  delete opts;
569  delete kfd;
570 
571  cg.writeEntry("OutputFormat", (int)format);
572  cg.writeEntry("Standalone", standalone);
573 
574  QFile file( file_name );
575  if ( ! file.open( QIODevice::WriteOnly ) )
576  {
577  KMessageBox::sorry( &w, i18n( "The file \"%1\" could not be opened. Please "
578  "check if the file permissions are set correctly." ,
579  file_name ) );
580  return;
581  };
582 
583  QTextStream stream( &file );
584  std::vector<ObjectHolder*> os = doc.document().objects();
585 
586  if (format == LatexExporterOptions::PSTricks)
587  {
588  if (standalone)
589  {
590  stream << "\\documentclass[a4paper]{minimal}\n";
591  // stream << "\\usepackage[latin1]{inputenc}\n";
592  stream << "\\usepackage{pstricks}\n";
593  stream << "\\usepackage{pst-plot}\n";
594  stream << "\\author{Kig " << KIGVERSION << "}\n";
595  stream << "\\begin{document}\n";
596  }
597 
598  const double bottom = w.showingRect().bottom();
599  const double left = w.showingRect().left();
600  const double height = w.showingRect().height();
601  const double width = w.showingRect().width();
602 
603  /*
604  // TODO: calculating aspect ratio...
605  if ( 297 / 210 >= height / width )
606  {
607 
608  }
609  */
610  const double tmpwidth = 15.0;
611  const double xunit = tmpwidth / width;
612  const double yunit = xunit;
613 
614  stream << "\\begin{pspicture*}(0,0)(" << tmpwidth << "," << yunit * height << ")\n";
615  stream << "\\psset{xunit=" << xunit << "}\n";
616  stream << "\\psset{yunit=" << yunit << "}\n";
617 
618  PSTricksExportImpVisitor visitor( stream, w );
619  visitor.unit = xunit;
620 
621  for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
622  i != os.end(); ++i )
623  {
624  if ( ! ( *i )->shown() ) continue;
625  visitor.mapColor( ( *i )->drawer()->color() );
626  };
627  visitor.mapColor( QColor( 255, 255, 222 ) ); // ffffde - text label background
628  visitor.mapColor( QColor( 197, 194, 197 ) ); // c5c2c5 - text label border line
629  visitor.mapColor( QColor( 160, 160, 164 ) ); // a0a0a4 - axes color
630  visitor.mapColor( QColor( 192, 192, 192 ) ); // c0c0c0 - grid color
631 
632  // extra frame
633  if ( showframe )
634  {
635  stream << "\\psframe[linecolor=black,linewidth=0.02]"
636  << "(0,0)"
637  << "(" << width << "," << height << ")"
638  << "\n";
639  }
640 
641  // grid
642  if ( showgrid )
643  {
644  // vertical lines...
645  double startingpoint = - left - 1 + static_cast<int>( KDE_TRUNC( left ) );
646  for ( double i = startingpoint; i < width; ++i )
647  {
648  stream << "\\psline[linecolor=c0c0c0,linewidth=0.01,linestyle=dashed]"
649  << "(" << i << ",0)"
650  << "(" << i << "," << height << ")"
651  << "\n";
652  }
653 
654  // horizontal lines...
655  startingpoint = - bottom - 1 + static_cast<int>( KDE_TRUNC( bottom ) );
656  for ( double i = startingpoint; i < height; ++i )
657  {
658  stream << "\\psline[linecolor=c0c0c0,linewidth=0.01,linestyle=dashed]"
659  << "(0," << i << ")"
660  << "(" << width << "," << i << ")"
661  << "\n";
662  }
663  }
664 
665  // axes
666  if ( showaxes )
667  {
668  stream << "\\psaxes[linecolor=a0a0a4,linewidth=0.03,ticks=none,arrowinset=0]{->}"
669  << "(" << -left << "," << -bottom << ")"
670  << "(0,0)"
671  << "(" << width << "," << height << ")"
672  << "\n";
673  }
674 
675  for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
676  i != os.end(); ++i )
677  {
678  visitor.visit( *i );
679  };
680 
681  stream << "\\end{pspicture*}\n";
682  if (standalone)
683  {
684  stream << "\\end{document}\n";
685  }
686  }
687  else if (format == LatexExporterOptions::TikZ)
688  {
689  if (standalone)
690  {
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";
696  }
697  PGFExporterImpVisitor visitor( stream, w );
698 
699  Rect frameRect = w.showingRect();
700 
701  double size = qMax(frameRect.height(),frameRect.width());
702  double scale = (size == 0) ? 1 : 10/size;
703 
704  // Start a figure and set its global options
705  stream << "\\begin{tikzpicture}"
706  << "[%\n"
707  << "scale=" << scale << ",\n"
708  << "]\n";
709 
710  double gLeft = frameRect.left();
711  double gBottom = frameRect.bottom();
712  double gRight = frameRect.right();
713  double gTop = frameRect.top();
714 
715  // extra frame for clipping
716  stream << "\\clip (" << gLeft << ',' << gBottom << ") rectangle (" << gRight << ',' << gTop << ");\n";
717 
718  if (showgrid)
719  {
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";
728  }
729  if (showaxes)
730  {
731  if (gBottom < 0 && gTop > 0)
732  {
733  stream << "\\draw [color=black,->] (" << gLeft << ",0) -- (" << gRight << ",0);\n";
734  }
735  if (gLeft < 0 && gRight > 0)
736  {
737  stream << "\\draw [color=black,->] (0," << gBottom <<") -- (0," << gTop << ");\n";
738  }
739  }
740  if (showframe)
741  {
742  stream << "\\draw [color=black] (" << gLeft << ',' << gBottom << ") rectangle (" << gRight << ',' << gTop << ");\n";
743  }
744 
745  // Visit all the objects
746  for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
747  {
748  visitor.visit( *i );
749  };
750 
751  stream << "\\end{tikzpicture}\n";
752 
753  // The file footer in case we embed into full latex document
754  if (standalone)
755  {
756  stream << "\\end{document}\n";
757  }
758 
759  }
760  else if (format == LatexExporterOptions::Asymptote)
761  {
762  const double bottom = w.showingRect().bottom();
763  const double left = w.showingRect().left();
764  const double height = w.showingRect().height();
765  const double width = w.showingRect().width();
766 
767  if (standalone)
768  {
769  // The header if we embed into latex
770  stream << "\\documentclass[a4paper,10pt]{article}\n";
771  stream << "\\usepackage{asymptote}\n";
772  stream << "\n";
773  stream << "\\pagestyle{empty}";
774  stream << "\n";
775  stream << "\\begin{document}\n";
776  }
777 
778  stream << "\\begin{asy}[width=\\the\\linewidth]\n";
779  stream << "\n";
780  stream << "import math;\n";
781  stream << "import graph;\n";
782  stream << "\n";
783  stream << "real textboxmargin = 2mm;\n";
784  stream << "\n";
785 
786  // grid
787  if ( showgrid )
788  {
789  // TODO: Polar grid
790  // vertical lines...
791  double startingpoint = static_cast<double>( KDE_TRUNC( left ) );
792  for ( double i = startingpoint; i < left+width; ++i )
793  {
794  stream << "draw((" << i << "," << bottom << ")--(" << i << "," << bottom+height << "),gray);\n";
795  }
796  // horizontal lines...
797  startingpoint = static_cast<double>( KDE_TRUNC( bottom ) );
798  for ( double i = startingpoint; i < bottom+height; ++i )
799  {
800  stream << "draw((" << left << "," << i << ")--(" << left+width << "," << i << "),gray);\n";
801  }
802  }
803 
804  // axes
805  if ( showaxes )
806  {
807  stream << "draw(("<<left<<",0)--("<<left+width<<",0), black, Arrow);\n";
808  stream << "draw((0,"<<bottom<<")--(0,"<<bottom+height<<"), black, Arrow);\n";
809  }
810 
811  // Visit all the objects
812  AsyExporterImpVisitor visitor( stream, w );
813 
814  for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
815  {
816  visitor.visit( *i );
817  }
818 
819  // extra frame for clipping
820  stream << "path frame = ("<<left<<","<<bottom<<")--("
821  <<left<<","<<bottom+height<<")--("
822  <<left+width<<","<<bottom+height<<")--("
823  <<left+width<<","<<bottom<<")--cycle;\n";
824 
825  if ( showframe )
826  {
827  stream << "draw(frame, black);\n";
828  }
829  stream << "clip(frame);\n";
830  stream << "\n";
831  stream << "\\end{asy}\n";
832 
833  // The file footer in case we embed into latex
834  if ( standalone )
835  {
836  stream << "\\end{document}\n";
837  }
838  }
839 
840  // And close the output file
841  file.close();
842 }
calcRayBorderPoints
void calcRayBorderPoints(const Coordinate &a, Coordinate &b, const Rect &r)
this does the same as the above function, but only for b.
Definition: common.cpp:131
ClosedPolygonalImp
An ObjectImp representing a closed polygonal.
Definition: polygon_imp.h:130
BezierImp
An ObjectImp representing polynomial Bézier Curve.
Definition: bezier_imp.h:31
CubicImp
An ObjectImp representing a cubic.
Definition: cubic_imp.h:29
LocusImp
LocusImp is an imp that consists of a copy of the curveimp that the moving point moves over...
Definition: locus_imp.h:57
AbstractLineImp::data
LineData data() const
Get the LineData for this AbstractLineImp.
Definition: line_imp.cc:359
latexexporter.h
LatexExporterOptions::setExtraFrame
void setExtraFrame(bool frame)
Definition: latexexporteroptions.cc:112
VectorImp::data
LineData data() const
Get the LineData for this vector.
Definition: other_imp.cc:771
TextImp::coordinate
const Coordinate coordinate() const
Definition: text_imp.cc:125
LatexExporter::menuEntryName
QString menuEntryName() const
Returns a string like i18n( "Image..." )
Definition: latexexporter.cc:80
Rect::width
double width() const
Definition: rect.cc:204
OpenPolygonalImp
An ObjectImp representing an open polygonal.
Definition: polygon_imp.h:157
ObjectDrawer::shown
bool shown() const
returns whether the object this ObjectDrawer is responsible for will be drawn or not.
Definition: object_drawer.cc:52
AngleImp::point
const Coordinate point() const
Return the center of this angle.
Definition: other_imp.h:79
KigFileDialog
This file dialog is pretty like KFileDialog, but allow us to make an option widget popup to the user...
Definition: kigfiledialog.h:27
LineData::b
Coordinate b
Another point on the line.
Definition: misc/common.h:68
LatexExporterOptions::PSTricks
Definition: latexexporteroptions.h:36
Goniometry::Deg
Definition: goniometry.h:31
ObjectImpVisitor::visit
void visit(const ObjectImp *imp)
Definition: object_imp.cc:81
CircleImp
An ObjectImp representing a circle.
Definition: circle_imp.h:27
KigDocument::grid
bool grid() const
Definition: kig_document.cc:186
ObjectImp::visit
virtual void visit(ObjectImpVisitor *vtor) const =0
TextImp
Definition: text_imp.h:26
Rect::left
double left() const
Definition: rect.cc:186
PGFExporterImpVisitor
Definition: pgfexporterimpvisitor.h:41
RayImp
An ObjectImp representing a ray.
Definition: line_imp.h:136
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
LatexExporter::menuIcon
QString menuIcon() const
Returns a string with the name of the icon.
Definition: latexexporter.cc:85
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
RationalBezierImp
An ObjectImp representing a rational Bézier curve.
Definition: bezier_imp.h:100
CircleImp::center
const Coordinate center() const
Return the center of this circle.
Definition: circle_imp.cc:210
KDE_TRUNC
#define KDE_TRUNC(a)
Definition: latexexporter.cc:63
LatexExporter::~LatexExporter
~LatexExporter()
Definition: latexexporter.cc:71
ObjectHolder::drawer
const ObjectDrawer * drawer() const
Definition: object_holder.cc:58
PointImp::coordinate
const Coordinate & coordinate() const
Get the coordinate of this PointImp.
Definition: point_imp.h:50
LatexExporter::run
void run(const KigPart &doc, KigWidget &w)
Do what you need to do.
Definition: latexexporter.cc:536
Rect::right
double right() const
Definition: rect.cc:190
AbstractPolygonImp::points
const std::vector< Coordinate > points() const
Returns the vector with polygon points.
Definition: polygon_imp.cc:571
ArcImp::radius
double radius() const
Return the radius of this arc.
Definition: other_imp.cc:537
LatexExporter::exportToStatement
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
Definition: latexexporter.cc:75
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
CurveImp::getPoint
virtual const Coordinate getPoint(double param, const KigDocument &) const =0
AsyExporterImpVisitor
Definition: asyexporterimpvisitor.h:40
VectorImp
An ObjectImp representing a vector.
Definition: other_imp.h:99
LatexExporterOptions::FormatCount
Definition: latexexporteroptions.h:39
LatexExporterOptions::setGrid
void setGrid(bool grid)
Definition: latexexporteroptions.cc:92
LatexExporterOptions::LatexOutputFormat
LatexOutputFormat
Definition: latexexporteroptions.h:34
TextImp::text
QString text() const
Definition: text_imp.cc:115
ArcImp::angle
double angle() const
Return the dimension in radians of this arc.
Definition: other_imp.cc:547
ObjectHolder
An ObjectHolder represents an object as it is known to the document.
Definition: object_holder.h:40
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Coordinate::distance
double distance(const Coordinate &p) const
Distance to another Coordinate.
Definition: coordinate.cpp:139
pgfexporterimpvisitor.h
LatexExporterOptions::setFormat
void setFormat(LatexOutputFormat format)
Definition: latexexporteroptions.cc:40
Rect::bottom
double bottom() const
Definition: rect.cc:194
AngleImp::angle
double angle() const
Return the dimension in radians of this angle.
Definition: other_imp.h:87
LineData::a
Coordinate a
One point on the line.
Definition: misc/common.h:64
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
asyexporterimpvisitor.h
Rect::top
double top() const
Definition: rect.cc:199
LatexExporterOptions::showAxes
bool showAxes() const
Definition: latexexporteroptions.cc:107
latexexporteroptions.h
KigDocument::objects
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
Definition: kig_document.cc:46
LatexExporterOptions::format
LatexOutputFormat format()
Definition: latexexporteroptions.cc:59
ConicImp
An ObjectImp representing a conic.
Definition: conic_imp.h:39
Goniometry::convert
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 ...
Definition: goniometry.cc:87
ArcImp::center
const Coordinate center() const
Return the center of this arc.
Definition: other_imp.cc:532
ObjectHolder::imp
const ObjectImp * imp() const
Definition: object_holder.cc:48
ArcImp::startAngle
double startAngle() const
Return the start angle in radians of this arc.
Definition: other_imp.cc:542
LatexExporterOptions::setStandalone
void setStandalone(bool standalone)
Definition: latexexporteroptions.cc:75
LatexExporterOptions::Asymptote
Definition: latexexporteroptions.h:38
AngleImp::startAngle
double startAngle() const
Return the start angle in radians of this angle.
Definition: other_imp.h:83
Coordinate::invalidCoord
static Coordinate invalidCoord()
Create an invalid Coordinate.
Definition: coordinate.cpp:171
Goniometry::Rad
Definition: goniometry.h:31
CircleImp::radius
double radius() const
Return the radius of this circle.
Definition: circle_imp.cc:215
visit
static bool visit(const ObjectCalcer *o, const std::vector< ObjectCalcer * > &from, std::vector< ObjectCalcer * > &ret)
Definition: calcpaths.cc:193
calcBorderPoints
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...
Definition: common.cpp:82
LatexExporterOptions
Definition: latexexporteroptions.h:25
KigFileDialog::setOptionCaption
void setOptionCaption(const QString &caption)
Set the caption of the option dialog.
Definition: kigfiledialog.cc:75
LatexExporterOptions::standalone
bool standalone()
Definition: latexexporteroptions.cc:87
Rect::height
double height() const
Definition: rect.cc:209
PGFExporterImpVisitor::visit
void visit(ObjectHolder *obj)
Definition: pgfexporterimpvisitor.cc:215
LineImp
An ObjectImp representing a line.
Definition: line_imp.h:184
ArcImp
An ObjectImp representing an arc.
Definition: other_imp.h:169
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
ObjectDrawer::color
QColor color() const
returns the color that the object will be drawn in
Definition: object_drawer.cc:57
KigFileDialog::setOptionsWidget
void setOptionsWidget(QWidget *w)
Use this to set the widget containing the options of eg an export filter.
Definition: kigfiledialog.cc:37
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
KigPart
This is a "Part".
Definition: kig_part.h:68
LatexExporterOptions::setAxes
void setAxes(bool axes)
Definition: latexexporteroptions.cc:102
LatexExporterOptions::TikZ
Definition: latexexporteroptions.h:37
FilledPolygonImp
An ObjectImp representing a filled polygon.
Definition: polygon_imp.h:101
KigDocument::axes
bool axes() const
Definition: kig_document.cc:206
LatexExporterOptions::showExtraFrame
bool showExtraFrame() const
Definition: latexexporteroptions.cc:117
TextImp::hasFrame
bool hasFrame() const
Definition: text_imp.cc:138
AsyExporterImpVisitor::visit
void visit(ObjectHolder *obj)
Definition: asyexporterimpvisitor.cc:143
uint
unsigned int uint
Definition: object_imp.h:87
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
LatexExporterOptions::showGrid
bool showGrid() const
Definition: latexexporteroptions.cc:97
ObjectImpVisitor
Definition: object_imp.h:56
AngleImp
An ObjectImp representing an angle.
Definition: other_imp.h:28
KigWidget::showingRect
const Rect showingRect() const
Mapping between Internal Coordinate Systems there are two coordinate systems: 1 the widget's coordina...
Definition: kig_view.cpp:277
CurveImp
This class represents a curve: something which is composed of points, like a line, a circle, a locus.
Definition: curve_imp.h:27
SegmentImp
An ObjectImp representing a segment.
Definition: line_imp.h:81
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