• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • LoadSave
  • Plugins
  • tikzFileFormat
TikzFileFormatPlugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
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 as
7  published by the Free Software Foundation; either version 2 of
8  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, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "TikzFileFormatPlugin.h"
20 #include "Document.h"
21 #include <KAboutData>
22 #include <KGenericFactory>
23 #include <KUrl>
24 #include <QFile>
25 #include <DataStructure.h>
26 #include <Data.h>
27 #include <Pointer.h>
28 #include <Modifiers/Topology.h>
29 #include <DataStructureBackendManager.h>
30 
31 static const KAboutData aboutdata("rocs_tikzfileformat",
32  0,
33  ki18nc("@title Displayed plugin name", "PGF/TikZ Export File Backend"),
34  "0.1",
35  ki18n("Export graph documents in PGF/TikZ format."),
36  KAboutData::License_GPL_V2);
37 
38 K_PLUGIN_FACTORY(FilePluginFactory, registerPlugin<TikzFileFormatPlugin>();)
39 K_EXPORT_PLUGIN(FilePluginFactory(aboutdata))
40 
41 
42 TikzFileFormatPlugin::TikzFileFormatPlugin(QObject* parent, const QList<QVariant>&) :
43  GraphFilePluginInterface(FilePluginFactory(aboutdata,0).componentData().aboutData(), parent)
44 {
45 }
46 
47 TikzFileFormatPlugin::~TikzFileFormatPlugin()
48 {
49 }
50 
51 const QStringList TikzFileFormatPlugin::extensions() const
52 {
53  return QStringList()
54  << i18n("*.pgf|TikZ (PGF) Format") + '\n';
55 }
56 
57 GraphFilePluginInterface::PluginType TikzFileFormatPlugin::pluginCapability() const
58 {
59  return GraphFilePluginInterface::ExportOnly;
60 }
61 
62 
63 void TikzFileFormatPlugin::readFile()
64 {
65  kWarning() << "This plugin cannot import documents.";
66  setError(NotSupportedOperation);
67 }
68 
69 
70 void TikzFileFormatPlugin::writeFile(Document &graph)
71 {
72  // TODO allow selection which data structure shall be exported
73  QFile fileHandle(file().toLocalFile());
74  if (!fileHandle.open(QFile::WriteOnly | QFile::Text)) {
75  setError(FileIsReadOnly, i18n("Could not open file \"%1\" in write mode: %2", file().fileName(), fileHandle.errorString()));
76  return;
77  }
78 
79  QTextStream out(&fileHandle);
80  DataStructurePtr g = graph.activeDataStructure();
81  if (!g) {
82  setError(NoGraphFound, i18n("No data structure specified for output in this document."));
83  return;
84  }
85 
86  // use this value to scale all coordinates
87  int resize = 50;
88 
89  // start picture
90  out << "\\begin{tikzpicture}\n";
91 
92  // style information
93  out << "\\tikzstyle{value} = [font=\\small]\n";
94  foreach(int type, graph.dataTypeList()) {
95  // TODO set type specific style information
96  QString dataTypeStyle = QString("\\tikzstyle{data%1}=[circle,thin,fill=black!25,minimum size=20pt,inner sep=0pt]").
97  arg(type);
98  out << dataTypeStyle << "\n";
99  }
100  foreach(int type, graph.pointerTypeList()) {
101  // set style attributes
102  QString styleAttributes = QString("draw,thick");
103 
104  // direction
105  if (graph.pointerType(type)->direction() == PointerType::Unidirectional) {
106  styleAttributes.append(",->");
107  } else {
108  styleAttributes.append(",-");
109  }
110 
111  // line style
112  switch(graph.pointerType(type)->lineStyle()) {
113  case Qt::SolidLine:
114  styleAttributes.append(",solid");
115  break;
116  case Qt::DashLine:
117  styleAttributes.append(",dashed");
118  break;
119  case Qt::DotLine:
120  styleAttributes.append(",dotted");
121  break;
122  default:
123  styleAttributes.append(",solid");
124  }
125 
126  // set style
127  QString pointerTypeStyle = QString("\\tikzstyle{edge%1} = [%2]").arg(type).arg(styleAttributes);
128  out << pointerTypeStyle << "\n";
129  }
130 
131  // export data elements
132  // y-axis is mirrowed in tikz-format
133  foreach(int type, graph.dataTypeList()) {
134  foreach(DataPtr n, g->dataList(type)) {
135  QString dataStr = QString("\\node[data%1] (%2) at (%3,%4) [label=left:%5] {%6};").
136  arg(n->dataType()).
137  arg(n->identifier()).
138  arg(n->x()/resize).
139  arg(n->y()*(-1)/resize).
140  arg(n->property("name").toString()).
141  arg(n->property("value").toString());
142  out << dataStr;
143  out << '\n';
144  }
145  }
146 
147  // export pointers
148  foreach(int type, graph.pointerTypeList()) {
149  foreach(PointerPtr e, g->pointers(type)) {
150  QString pointerStr = QString("\\path[edge%1] (%2) -- node[value] {%3} (%4);").
151  arg(e->pointerType()).
152  arg(e->from()->identifier()).
153  arg(e->property("value").toString()).
154  arg(e->to()->identifier());
155  out << pointerStr;
156  out << '\n';
157  }
158  }
159 
160  out << "\\end{tikzpicture}\n";
161 
162  setError(None);
163 }
GraphFilePluginInterface::None
Definition: GraphFilePluginInterface.h:51
Topology.h
DataStructurePtr
boost::shared_ptr< DataStructure > DataStructurePtr
Definition: CoreTypes.h:38
GraphFilePluginInterface::ExportOnly
Definition: GraphFilePluginInterface.h:67
TikzFileFormatPlugin::writeFile
virtual void writeFile(Document &graph)
Writes given graph document to formerly specified file.
Definition: TikzFileFormatPlugin.cpp:70
TikzFileFormatPlugin::~TikzFileFormatPlugin
~TikzFileFormatPlugin()
Definition: TikzFileFormatPlugin.cpp:47
TikzFileFormatPlugin.h
QObject
TikzFileFormatPlugin::readFile
virtual void readFile()
Open given file and imports it into internal format.
Definition: TikzFileFormatPlugin.cpp:63
Data.h
Document.h
PointerType::Unidirectional
Definition: PointerType.h:47
PointerPtr
boost::shared_ptr< Pointer > PointerPtr
Definition: CoreTypes.h:35
DataStructure.h
TikzFileFormatPlugin
class TikzFileFormatPlugin: Export Plugin for PGF/TikZ files
Definition: TikzFileFormatPlugin.h:29
GraphFilePluginInterface::setError
void setError(Error error, QString message=QString())
Definition: GraphFilePluginInterface.cpp:83
Document::activeDataStructure
DataStructurePtr activeDataStructure() const
Definition: Document.cpp:431
TikzFileFormatPlugin::pluginCapability
virtual GraphFilePluginInterface::PluginType pluginCapability() const
Returns PluginType to indicate whether the plugin only provides import, only export or both capabilit...
Definition: TikzFileFormatPlugin.cpp:57
aboutdata
static const KAboutData aboutdata("rocs_tikzfileformat", 0, ki18nc("@title Displayed plugin name","PGF/TikZ Export File Backend"),"0.1", ki18n("Export graph documents in PGF/TikZ format."), KAboutData::License_GPL_V2)
GraphFilePluginInterface::NoGraphFound
Definition: GraphFilePluginInterface.h:55
GraphFilePluginInterface::PluginType
PluginType
Describes the capability of the plugin, i.e., if the plugin can be used to read and/or write files...
Definition: GraphFilePluginInterface.h:65
Document
Definition: Document.h:41
Document::pointerType
PointerTypePtr pointerType(int pointerType) const
Definition: Document.cpp:207
Pointer.h
GraphFilePluginInterface::FileIsReadOnly
Definition: GraphFilePluginInterface.h:53
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
Document::pointerTypeList
QList< int > pointerTypeList() const
Getter for all registered pointer types.
Definition: Document.cpp:165
Document::dataTypeList
QList< int > dataTypeList() const
Getter for all registered data types.
Definition: Document.cpp:160
GraphFilePluginInterface::NotSupportedOperation
Definition: GraphFilePluginInterface.h:58
DataStructureBackendManager.h
GraphFilePluginInterface::file
const KUrl & file() const
Definition: GraphFilePluginInterface.cpp:120
GraphFilePluginInterface
This class provides an interface for graph file format plugins.
Definition: GraphFilePluginInterface.h:42
TikzFileFormatPlugin::extensions
virtual const QStringList extensions() const
File extensions that are common for this file type.
Definition: TikzFileFormatPlugin.cpp:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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