• 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
  • dotFileFormat
DotGraphParsingHelper.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2006-2007 Gael de Chalendar <kleag@free.fr>
4  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
5 
6  Rocs is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public
8  License as published by the Free Software Foundation, version 2.
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 GNU
13  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 
21 
22 #include "DotGraphParsingHelper.h"
23 #include "DotGrammar.h"
24 
25 #include <KDebug>
26 
27 #include <QFile>
28 #include <Group.h>
29 
30 extern DotParser::DotGraphParsingHelper* phelper;
31 
32 namespace DotParser
33 {
34 
35 DotGraphParsingHelper::DotGraphParsingHelper():
36  attributeId(),
37  valid(),
38  attributed(),
39  unprocessedAttributes(),
40  dataStructureAttributes(),
41  dataAttributes(),
42  pointerAttributes(),
43  dataStructureAttributeStack(),
44  dataAttributeStack(),
45  pointerAttributeStack(),
46  edgebounds(),
47  currentDataPtr(),
48  currentPointerPtr(),
49  dataMap()
50 {
51 }
52 
53 void DotGraphParsingHelper::setObjectAttributes(QObject *graphElement, const AttributesMap &attributes)
54 {
55  AttributesMap::const_iterator iter;
56  iter = attributes.constBegin();
57  for (; iter != attributes.constEnd(); ++iter) {
58  if (iter.key() == "label" && strcmp(graphElement->metaObject()->className(), "Edge") == 0) {
59  QString label = iter.value();
60  label.replace("\\n", "\n");
61  graphElement->setProperty("name", label);
62  } else {
63  graphElement->setProperty(iter.key().toAscii(), iter.value());
64  }
65  }
66 }
67 
68 void DotGraphParsingHelper::setDataStructureAttributes()
69 {
70  setObjectAttributes(dataStructure.get(), dataStructureAttributes);
71 }
72 
73 void DotGraphParsingHelper::setSubDataStructureAttributes()
74 {
75 }
76 
77 void DotGraphParsingHelper::setDataAttributes()
78 {
79  if (!currentDataPtr) {
80  return;
81  }
82  setObjectAttributes(currentDataPtr.get(), dataAttributes);
83 }
84 
85 void DotGraphParsingHelper::setPointerAttributes()
86 {
87  if (!currentPointerPtr) {
88  return;
89  }
90  setObjectAttributes(currentPointerPtr.get(), pointerAttributes);
91 }
92 
93 void DotGraphParsingHelper::applyAttributedList()
94 {
95  if (attributed == "graph") {
96  if (unprocessedAttributes.find("bb") != unprocessedAttributes.end()) {
97  std::vector< int > v;
98  parseIntegers(unprocessedAttributes["bb"].toStdString().c_str(), v);
99 // if (v.size() >= 4) {
100 // kDebug() << "setting width and height to " << v[2] << v[3];
101 // }
102  }
103  AttributesMap::const_iterator it, it_end;
104  it = unprocessedAttributes.constBegin();
105  it_end = unprocessedAttributes.constEnd();
106  for (; it != it_end; it++) {
107  dataStructureAttributes[it.key()] = it.value();
108  }
109  } else if (attributed == "node") {
110  AttributesMap::const_iterator it, it_end;
111  it = unprocessedAttributes.constBegin();
112  it_end = unprocessedAttributes.constEnd();
113  for (; it != it_end; it++) {
114  dataAttributes[it.key()] = it.value();
115  }
116  } else if (attributed == "edge") {
117  AttributesMap::const_iterator it, it_end;
118  it = unprocessedAttributes.constBegin();
119  it_end = unprocessedAttributes.constEnd();
120  for (; it != it_end; it++) {
121  pointerAttributes[it.key()] = it.value();
122  }
123  }
124  unprocessedAttributes.clear();
125 }
126 
127 void DotGraphParsingHelper::createData(QString identifier)
128 {
129  edgebounds.clear(); //TODO explain meaning of this
130 
131  if (dataMap.contains(identifier)) {
132  kWarning() << "Omitting data element, ID is already used: "<< identifier;
133  return;
134  }
135 
136 // kDebug() << "Creating new data element: " << identifier;
137  currentDataPtr = dataStructure->createData(identifier, 0);
138  dataMap.insert(identifier, currentDataPtr);
139 
140  if (!groupStack.isEmpty()) {
141  groupStack.last()->addData(currentDataPtr);
142  }
143 }
144 
145 void DotGraphParsingHelper::createSubDataStructure()
146 {
147  GroupPtr newGroup = dataStructure->addGroup("Group");
148  groupStack.append(newGroup);
149  currentDataPtr = newGroup->getData();
150 }
151 
152 void DotGraphParsingHelper::setSubDataStructureId(QString identifier)
153 {
154  if(groupStack.isEmpty()) {
155  kError() << "Cannot set sub data structure id: no group on stack";
156  return;
157  }
158  // at this point the currentDataPtr is already the sub data structure
159  dataMap.insert(identifier, currentDataPtr);
160  groupStack.last()->setName(identifier);
161 }
162 
163 void DotGraphParsingHelper::leaveSubDataStructure()
164 {
165  if(groupStack.isEmpty()) {
166  kWarning() << "Cannot leave group: currently not inside any group.";
167  return;
168  }
169  groupStack.removeLast();
170 }
171 
172 void DotGraphParsingHelper::createPointers()
173 {
174  QString fromId, toId;
175 
176  if (edgebounds.isEmpty()) {
177  return;
178  }
179  fromId = edgebounds.first();
180  edgebounds.removeFirst();
181  while (!edgebounds.isEmpty()) {
182  toId = edgebounds.first();
183  edgebounds.removeFirst();
184 
185  // if necessary create from id
186  if (!dataMap.contains(fromId)) {
187  DataPtr from = dataStructure->createData(fromId, 0);
188  dataMap.insert(fromId, from);
189  currentDataPtr = from;
190  setDataAttributes();
191  }
192  DataPtr from = dataMap[fromId];
193 
194  // if necessary create to node
195  if (!dataMap.contains(toId)) {
196  DataPtr to = dataStructure->createData(toId, 0);
197  dataMap.insert(toId, to);
198  currentDataPtr = to;
199  setDataAttributes();
200  }
201  DataPtr to = dataMap[toId];
202 
203  currentPointerPtr = dataStructure->createPointer(from, to, 0);
204 // kDebug() << "Creating new pointer: " << from->identifier() << " -> " << to->identifier();
205  setPointerAttributes();
206 
207  fromId = toId;
208  }
209  edgebounds.clear();
210 }
211 
212 }
DotParser::parseIntegers
bool parseIntegers(const std::string &str, std::vector< int > &v)
Definition: DotGrammar.cpp:461
DotParser::DotGraphParsingHelper::groupStack
QList< GroupPtr > groupStack
Definition: DotGraphParsingHelper.h:90
DotParser::DotGraphParsingHelper::applyAttributedList
void applyAttributedList()
Generates a new attribute list from all unprocessed attributes and set the corresponding attribute li...
Definition: DotGraphParsingHelper.cpp:93
DotParser::DotGraphParsingHelper::pointerAttributes
AttributesMap pointerAttributes
Definition: DotGraphParsingHelper.h:81
DotParser::DotGraphParsingHelper::unprocessedAttributes
AttributesMap unprocessedAttributes
Definition: DotGraphParsingHelper.h:78
Group.h
DotParser::DotGraphParsingHelper::currentDataPtr
DataPtr currentDataPtr
Definition: DotGraphParsingHelper.h:92
DotParser::DotGraphParsingHelper::dataStructure
boost::shared_ptr< Rocs::GraphStructure > dataStructure
Definition: DotGraphParsingHelper.h:88
DotParser::DotGraphParsingHelper::setSubDataStructureAttributes
void setSubDataStructureAttributes()
Definition: DotGraphParsingHelper.cpp:73
QObject
DotGraphParsingHelper.h
DotParser::DotGraphParsingHelper::attributed
std::string attributed
Definition: DotGraphParsingHelper.h:76
phelper
DotParser::DotGraphParsingHelper * phelper
Definition: DotGrammar.cpp:157
DotParser::attributeId
void attributeId(const std::string &str)
Definition: DotGrammar.cpp:291
DotParser::DotGraphParsingHelper::edgebounds
QStringList edgebounds
Definition: DotGraphParsingHelper.h:86
DotParser::DotGraphParsingHelper
Definition: DotGraphParsingHelper.h:35
DotGrammar.h
DotParser::DotGraphParsingHelper::setSubDataStructureId
void setSubDataStructureId(QString identifier)
Definition: DotGraphParsingHelper.cpp:152
DotParser::DotGraphParsingHelper::leaveSubDataStructure
void leaveSubDataStructure()
Leaves current group, i.e., leave current sub data structure and switches focus to ancestor group or ...
Definition: DotGraphParsingHelper.cpp:163
DotParser::DotGraphParsingHelper::setObjectAttributes
void setObjectAttributes(QObject *graphElement, const DotParser::DotGraphParsingHelper::AttributesMap &attributes)
Definition: DotGraphParsingHelper.cpp:53
DotParser::DotGraphParsingHelper::setDataStructureAttributes
void setDataStructureAttributes()
Definition: DotGraphParsingHelper.cpp:68
DotParser::DotGraphParsingHelper::dataAttributes
AttributesMap dataAttributes
Definition: DotGraphParsingHelper.h:80
DotParser::DotGraphParsingHelper::setPointerAttributes
void setPointerAttributes()
Definition: DotGraphParsingHelper.cpp:85
GroupPtr
boost::shared_ptr< Group > GroupPtr
Definition: CoreTypes.h:39
DotParser::DotGraphParsingHelper::createData
void createData(QString identifier)
Creates new data element and registers the identifier in data map.
Definition: DotGraphParsingHelper.cpp:127
DotParser::DotGraphParsingHelper::DotGraphParsingHelper
DotGraphParsingHelper()
Definition: DotGraphParsingHelper.cpp:35
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
DotParser::valid
void valid(const std::string &str)
Definition: DotGrammar.cpp:324
DotParser::DotGraphParsingHelper::AttributesMap
QMap< QString, QString > AttributesMap
Definition: DotGraphParsingHelper.h:36
DotParser::DotGraphParsingHelper::dataMap
QMap< QString, DataPtr > dataMap
Definition: DotGraphParsingHelper.h:95
DotParser::DotGraphParsingHelper::currentPointerPtr
PointerPtr currentPointerPtr
Definition: DotGraphParsingHelper.h:93
DotParser::DotGraphParsingHelper::setDataAttributes
void setDataAttributes()
Definition: DotGraphParsingHelper.cpp:77
DotParser::DotGraphParsingHelper::dataStructureAttributes
AttributesMap dataStructureAttributes
Definition: DotGraphParsingHelper.h:79
DotParser::DotGraphParsingHelper::createSubDataStructure
void createSubDataStructure()
Creates new sub data structure and enters it.
Definition: DotGraphParsingHelper.cpp:145
DotParser::DotGraphParsingHelper::createPointers
void createPointers()
Definition: DotGraphParsingHelper.cpp:172
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:25 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