• 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
asyexporter.cc
Go to the documentation of this file.
1 // Copyright (C) 2010,2011 Raoul Bourquin
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "asyexporter.h"
19 #include "asyexporterimpvisitor.h"
20 #include "asyexporteroptions.h"
21 
22 #include "../misc/kigfiledialog.h"
23 
24 #include <qfile.h>
25 #include <qtextstream.h>
26 #include <kmessagebox.h>
27 
28 #ifdef HAVE_TRUNC
29 #define KDE_TRUNC(a) trunc(a)
30 #else
31 #define KDE_TRUNC(a) rint(a)
32 #endif
33 
34 AsyExporter::~AsyExporter()
35 {
36 }
37 
38 QString AsyExporter::exportToStatement() const
39 {
40  return i18n( "Export to &Asymptote..." );
41 }
42 
43 QString AsyExporter::menuEntryName() const
44 {
45  return i18n( "&Asymptote..." );
46 }
47 
48 QString AsyExporter::menuIcon() const
49 {
50  return "text-plain";
51 }
52 
53 void AsyExporter::run( const KigPart& doc, KigWidget& w )
54 {
55  KigFileDialog* kfd = new KigFileDialog(
56  QString(), i18n( "*.asy|Asymptote Documents (*.asy)" ),
57  i18n( "Export as Asymptote script" ), &w );
58  kfd->setOptionCaption( i18n( "Asymptote Options" ) );
59  AsyExporterOptions* opts = new AsyExporterOptions( 0L );
60  kfd->setOptionsWidget( opts );
61  opts->setGrid( true );
62  opts->setAxes( true );
63  opts->setExtraFrame( false );
64  if ( !kfd->exec() )
65  return;
66 
67  QString file_name = kfd->selectedFile();
68  bool showgrid = opts->showGrid();
69  bool showaxes = opts->showAxes();
70  bool showframe = opts->showExtraFrame();
71 
72  delete opts;
73  delete kfd;
74 
75  QFile file( file_name );
76  if ( ! file.open( QIODevice::WriteOnly ) )
77  {
78  KMessageBox::sorry( &w, i18n( "The file \"%1\" could not be opened. Please "
79  "check if the file permissions are set correctly." ,
80  file_name ) );
81  return;
82  };
83 
84  const double bottom = w.showingRect().bottom();
85  const double left = w.showingRect().left();
86  const double height = w.showingRect().height();
87  const double width = w.showingRect().width();
88 
89  std::vector<ObjectHolder*> os = doc.document().objects();
90  QTextStream stream( &file );
91  AsyExporterImpVisitor visitor( stream, w );
92 
93  // Start building the output stream containing the asymptote script commands
94 
95  // The file header for pure asymptote
96  stream << "settings.outformat=\"pdf\";\n";
97  stream << "\n";
98  stream << "import math;\n";
99  stream << "import graph;\n";
100  stream << "\n";
101  stream << "size(" << 25*width << "," << 25*height << ");\n";
102  stream << "\n";
103  stream << "real textboxmargin = 2mm;\n";
104  stream << "\n";
105 
106  // Grid
107  if ( showgrid )
108  {
109  // TODO: Polar grid
110  // Vertical lines
111  double startingpoint = static_cast<double>( KDE_TRUNC( left ) );
112  for ( double i = startingpoint; i < left+width; ++i )
113  {
114  stream << "draw((" << i << "," << bottom << ")--(" << i << "," << bottom+height << "),gray);\n";
115  }
116  // Horizontal lines
117  startingpoint = static_cast<double>( KDE_TRUNC( bottom ) );
118  for ( double i = startingpoint; i < bottom+height; ++i )
119  {
120  stream << "draw((" << left << "," << i << ")--(" << left+width << "," << i << "),gray);\n";
121  }
122  }
123 
124  // Axes
125  if ( showaxes )
126  {
127  stream << "draw(("<<left<<",0)--("<<left+width<<",0), black, Arrow);\n";
128  stream << "draw((0,"<<bottom<<")--(0,"<<bottom+height<<"), black, Arrow);\n";
129  }
130 
131  // Visit all the objects
132  for ( std::vector<ObjectHolder*>::const_iterator i = os.begin(); i != os.end(); ++i )
133  {
134  visitor.visit( *i );
135  }
136 
137  stream << "path frame = ("<<left<<","<<bottom<<")--("
138  <<left<<","<<bottom+height<<")--("
139  <<left+width<<","<<bottom+height<<")--("
140  <<left+width<<","<<bottom<<")--cycle;\n";
141 
142  // Extra frame
143  if ( showframe )
144  {
145  stream << "draw(frame, black);\n";
146  }
147  stream << "clip(frame);\n";
148 
149  // And close the output file
150  file.close();
151 }
asyexporter.h
Rect::width
double width() const
Definition: rect.cc:204
KigFileDialog
This file dialog is pretty like KFileDialog, but allow us to make an option widget popup to the user...
Definition: kigfiledialog.h:27
Rect::left
double left() const
Definition: rect.cc:186
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
AsyExporterOptions
Definition: asyexporteroptions.h:25
AsyExporterOptions::setAxes
void setAxes(bool axes)
Definition: asyexporteroptions.cc:50
AsyExporter::~AsyExporter
~AsyExporter()
Definition: asyexporter.cc:34
AsyExporter::menuIcon
QString menuIcon() const
Returns a string with the name of the icon.
Definition: asyexporter.cc:48
AsyExporter::run
void run(const KigPart &doc, KigWidget &w)
Do what you need to do.
Definition: asyexporter.cc:53
KDE_TRUNC
#define KDE_TRUNC(a)
Definition: asyexporter.cc:31
AsyExporterImpVisitor
Definition: asyexporterimpvisitor.h:40
AsyExporterOptions::showExtraFrame
bool showExtraFrame() const
Definition: asyexporteroptions.cc:65
Rect::bottom
double bottom() const
Definition: rect.cc:194
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
asyexporterimpvisitor.h
KigDocument::objects
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
Definition: kig_document.cc:46
AsyExporterOptions::showGrid
bool showGrid() const
Definition: asyexporteroptions.cc:45
AsyExporter::menuEntryName
QString menuEntryName() const
Returns a string like i18n( "Image..." )
Definition: asyexporter.cc:43
asyexporteroptions.h
KigFileDialog::setOptionCaption
void setOptionCaption(const QString &caption)
Set the caption of the option dialog.
Definition: kigfiledialog.cc:75
Rect::height
double height() const
Definition: rect.cc:209
AsyExporterOptions::setGrid
void setGrid(bool grid)
Definition: asyexporteroptions.cc:40
AsyExporter::exportToStatement
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
Definition: asyexporter.cc:38
AsyExporterOptions::setExtraFrame
void setExtraFrame(bool frame)
Definition: asyexporteroptions.cc:60
KigFileDialog::setOptionsWidget
void setOptionsWidget(QWidget *w)
Use this to set the widget containing the options of eg an export filter.
Definition: kigfiledialog.cc:37
KigPart
This is a "Part".
Definition: kig_part.h:68
AsyExporterImpVisitor::visit
void visit(ObjectHolder *obj)
Definition: asyexporterimpvisitor.cc:143
AsyExporterOptions::showAxes
bool showAxes() const
Definition: asyexporteroptions.cc:55
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:38 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