1
/* This file is part of KGraphViewer.
2
Copyright (C) 2006-2007 Gael de Chalendar <kleag@free.fr>
4
KGraphViewer is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public
6
License as published by the Free Software Foundation, version 2.
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 GNU
11
General Public License for more details.
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
20
#include "GMLGraphParsingHelper.h"
21
// #include "dotgraph.h"
22
#include "GMLGrammar.h"
23
// #include "dotdefaults.h"
24
//#include "graphsubgraph.h"
25
// #include "graphnode.h"
26
// #include "graphedge.h"
28
#include <boost/throw_exception.hpp>
29
#include <boost/spirit/include/classic_core.hpp>
30
#include <boost/spirit/include/classic_distinct.hpp>
31
#include <boost/spirit/include/classic_loops.hpp>
32
#include <boost/spirit/include/classic_confix.hpp>
41
#include "DynamicPropertiesList.h"
45
// using namespace std;
47
using namespace GMLPlugin;
49
extern GMLGraphParsingHelper* phelper;
51
#define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<int>::max()
53
GMLGraphParsingHelper::GMLGraphParsingHelper():
63
void GMLGraphParsingHelper::startList(const QString& key){
64
kDebug () << "starting a list with key:" <<key;
65
if (_actualState == begin && key.compare("graph", Qt::CaseInsensitive) == 0){
68
}else if (_actualState == graph ){
69
if(key.compare("node", Qt::CaseInsensitive)==0){
72
}else if(key.compare("edge", Qt::CaseInsensitive)==0){
77
_properties.append(key);
81
void GMLGraphParsingHelper::endList(){
82
if (!_properties.isEmpty()){
83
_properties.removeLast();
86
switch (_actualState){
87
case begin: kDebug () << "Ending a list without begin a item??"; break;
88
case node: actualNode.reset();
91
case edge: actualEdge.reset();
103
const QString GMLGraphParsingHelper::processKey(const QString& key){
105
if (key.compare("id", Qt::CaseInsensitive) == 0){
113
void GMLGraphParsingHelper::setAtribute(const QString& key, const QString& value)
115
kDebug() << "Setting attibute " << key;
116
switch(_actualState){
119
if (!_properties.isEmpty()){
120
QString joined = _properties.join(".");
121
joined.append('.').append(key);
122
actualGraph->setProperty(joined.toAscii(),value);
124
kDebug() << "seting property to graph" << key << value;
125
// if (!actualGraph->setProperty(processKey(key).toAscii(),value)){
126
actualGraph->addDynamicProperty(processKey(key),value); //is a dinamic property
131
if (!_properties.isEmpty()){ //is a list of properties of edge
132
QString joined = _properties.join(".");
133
joined.append('.').append(key);
135
actualEdge->setProperty(joined.toAscii(),value);
137
_edgeProperties.insert(joined, value);
139
}else if (key.compare("source", Qt::CaseInsensitive) == 0){ // search for source....
142
}else if (key.compare("target", Qt::CaseInsensitive) == 0){ // .... and target
145
}else if (actualEdge){ //if edge was created.
146
// if(!actualEdge->setProperty(processKey(key).toAscii(),value)){
147
kDebug() << "inserting edge key: " << key;
148
actualEdge->addDynamicProperty(processKey(key),value);
151
kDebug() << "Saving edge key: " << key;
152
_edgeProperties.insert(processKey(key), value); //store to be inserted later
156
if (!_properties.isEmpty()){
157
QString joined = _properties.join(".");
158
joined.append('.').append(key);
159
actualNode->setProperty(joined.toAscii(),value);
161
kDebug() << "seting property to node" << key << value;
162
// if(!actualNode->setProperty(processKey(key).toAscii(),value)){
163
actualNode->addDynamicProperty(processKey(key), value);
171
void GMLGraphParsingHelper::createGraph(){
172
if (_actualState == begin){
173
actualGraph = gd->addDataStructure();
174
_actualState = graph;
178
void GMLGraphParsingHelper::createNode(){
179
if (_actualState == graph){
180
kDebug () << "Creating a node";
182
actualNode = actualGraph->addData("NewNode");
188
void GMLGraphParsingHelper::createEdge(){
189
if (!edgeSource.isEmpty() && !edgeTarget.isEmpty()){
190
kDebug() << "Creating a edge";
192
actualEdge = actualGraph->addPointer(edgeSource, edgeTarget);
195
while( ! _edgeProperties.isEmpty()){
196
QString property = _edgeProperties.keys().at(0);
197
actualEdge->addDynamicProperty(property, _edgeProperties.value(property));
198
_edgeProperties.remove(property);
200
}else if (_actualState == graph){
201
kDebug () << "changing state Edge";