Changeset View
Changeset View
Standalone View
Standalone View
src/part/DotGraphParsingHelper.cpp
Show All 10 Lines | 1 | /* This file is part of KGraphViewer. | |||
---|---|---|---|---|---|
11 | General Public License for more details. | 11 | General Public License for more details. | ||
12 | 12 | | |||
13 | You should have received a copy of the GNU General Public License | 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 | 14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA | 16 | 02110-1301, USA | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | | ||||
20 | #include "DotGraphParsingHelper.h" | 19 | #include "DotGraphParsingHelper.h" | ||
21 | #include "dotgraph.h" | | |||
22 | #include "dotgrammar.h" | | |||
23 | #include "dotdefaults.h" | 20 | #include "dotdefaults.h" | ||
21 | #include "dotgrammar.h" | ||||
22 | #include "dotgraph.h" | ||||
24 | //#include "graphsubgraph.h" | 23 | //#include "graphsubgraph.h" | ||
25 | #include "graphnode.h" | | |||
26 | #include "graphedge.h" | 24 | #include "graphedge.h" | ||
25 | #include "graphnode.h" | ||||
27 | #include "kgraphviewerlib_debug.h" | 26 | #include "kgraphviewerlib_debug.h" | ||
28 | 27 | | |||
29 | #include <boost/throw_exception.hpp> | 28 | #include <boost/spirit/include/classic_confix.hpp> | ||
30 | #include <boost/spirit/include/classic_core.hpp> | 29 | #include <boost/spirit/include/classic_core.hpp> | ||
31 | #include <boost/spirit/include/classic_distinct.hpp> | 30 | #include <boost/spirit/include/classic_distinct.hpp> | ||
32 | #include <boost/spirit/include/classic_loops.hpp> | 31 | #include <boost/spirit/include/classic_loops.hpp> | ||
33 | #include <boost/spirit/include/classic_confix.hpp> | 32 | #include <boost/throw_exception.hpp> | ||
34 | | ||||
35 | 33 | | |||
36 | #include <iostream> | 34 | #include <iostream> | ||
37 | 35 | | |||
38 | #include <QDebug> | 36 | #include <QDebug> | ||
39 | 37 | | |||
40 | #include <QFile> | 38 | #include <QFile> | ||
41 | #include<QUuid> | 39 | #include <QUuid> | ||
42 | 40 | | |||
43 | using namespace std; | 41 | using namespace std; | ||
44 | 42 | | |||
45 | extern KGraphViewer::DotGraphParsingHelper* phelper; | 43 | extern KGraphViewer::DotGraphParsingHelper *phelper; | ||
46 | 44 | | |||
47 | namespace KGraphViewer | 45 | namespace KGraphViewer { | ||
48 | { | | |||
49 | #define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<int>::max() | 46 | #define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<int>::max() | ||
50 | 47 | | |||
51 | DotGraphParsingHelper::DotGraphParsingHelper(): | 48 | DotGraphParsingHelper::DotGraphParsingHelper() | ||
52 | attrid(), | 49 | : attrid(), valid(), attributed(), subgraphid(), uniq(0), attributes(), | ||
53 | valid(), | 50 | graphAttributes(), nodesAttributes(), edgesAttributes(), | ||
54 | attributed(), | 51 | graphAttributesStack(), nodesAttributesStack(), edgesAttributesStack(), | ||
55 | subgraphid(), | 52 | edgebounds(), z(0), maxZ(0), graph(nullptr), gs(nullptr), gn(nullptr), | ||
56 | uniq(0), | 53 | ge(nullptr) {} | ||
57 | attributes(), | | |||
58 | graphAttributes(), | | |||
59 | nodesAttributes(), | | |||
60 | edgesAttributes(), | | |||
61 | graphAttributesStack(), | | |||
62 | nodesAttributesStack(), | | |||
63 | edgesAttributesStack(), | | |||
64 | edgebounds(), | | |||
65 | z(0), | | |||
66 | maxZ(0), | | |||
67 | graph(nullptr), | | |||
68 | gs(nullptr), | | |||
69 | gn(nullptr), | | |||
70 | ge(nullptr) | | |||
71 | { | | |||
72 | } | | |||
73 | 54 | | |||
74 | void DotGraphParsingHelper::setgraphelementattributes(GraphElement* ge, const AttributesMap& attributes) | 55 | void DotGraphParsingHelper::setgraphelementattributes( | ||
75 | { | 56 | GraphElement *ge, const AttributesMap &attributes) { | ||
76 | AttributesMap::const_iterator it, it_end; | 57 | AttributesMap::const_iterator it, it_end; | ||
77 | it = attributes.begin(); it_end = attributes.end(); | 58 | it = attributes.begin(); | ||
78 | for (; it != it_end; it++) | 59 | it_end = attributes.end(); | ||
79 | { | 60 | for (; it != it_end; it++) { | ||
80 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << QString::fromStdString((*it).first) << "\t=\t'" << QString::fromStdString((*it).second) <<"'"; | 61 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << | ||
81 | if ((*it).first=="label") | 62 | // QString::fromStdString((*it).first) << "\t=\t'" << | ||
82 | { | 63 | // QString::fromStdString((*it).second) <<"'"; | ||
64 | if ((*it).first == "label") { | ||||
83 | QString label = QString::fromUtf8((*it).second.c_str()); | 65 | QString label = QString::fromUtf8((*it).second.c_str()); | ||
84 | label.replace("\\n","\n"); | 66 | label.replace("\\n", "\n"); | ||
85 | (*ge).attributes()["label"] = label; | 67 | (*ge).attributes()["label"] = label; | ||
86 | } | 68 | } else { | ||
87 | else | | |||
88 | { | | |||
89 | (*ge).attributes()[QString::fromStdString((*it).first)] = | 69 | (*ge).attributes()[QString::fromStdString((*it).first)] = | ||
90 | QString::fromStdString((*it).second); | 70 | QString::fromStdString((*it).second); | ||
91 | } | 71 | } | ||
92 | } | 72 | } | ||
93 | 73 | | |||
94 | DotRenderOpVec ops = ge->renderOperations(); | 74 | DotRenderOpVec ops = ge->renderOperations(); | ||
95 | if (attributes.find("_draw_") != attributes.end()) | 75 | if (attributes.find("_draw_") != attributes.end()) { | ||
96 | { | | |||
97 | parse_renderop((attributes.find("_draw_"))->second, ops); | 76 | parse_renderop((attributes.find("_draw_"))->second, ops); | ||
98 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ge->renderOperations().size(); | 77 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is | ||
78 | // now " << ge->renderOperations().size(); | ||||
99 | } | 79 | } | ||
100 | if (attributes.find("_ldraw_") != attributes.end()) | 80 | if (attributes.find("_ldraw_") != attributes.end()) { | ||
101 | { | | |||
102 | parse_renderop(attributes.find("_ldraw_")->second, ops); | 81 | parse_renderop(attributes.find("_ldraw_")->second, ops); | ||
103 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ge->renderOperations().size(); | 82 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is | ||
83 | // now " << ge->renderOperations().size(); | ||||
104 | } | 84 | } | ||
105 | if (attributes.find("_hldraw_") != attributes.end()) | 85 | if (attributes.find("_hldraw_") != attributes.end()) { | ||
106 | { | | |||
107 | parse_renderop(attributes.find("_hldraw_")->second, ops); | 86 | parse_renderop(attributes.find("_hldraw_")->second, ops); | ||
108 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ge->renderOperations().size(); | 87 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is | ||
88 | // now " << ge->renderOperations().size(); | ||||
109 | } | 89 | } | ||
110 | if (attributes.find("_tldraw_") != attributes.end()) | 90 | if (attributes.find("_tldraw_") != attributes.end()) { | ||
111 | { | | |||
112 | parse_renderop(attributes.find("_tldraw_")->second, ops); | 91 | parse_renderop(attributes.find("_tldraw_")->second, ops); | ||
113 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ge->renderOperations().size(); | 92 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is | ||
93 | // now " << ge->renderOperations().size(); | ||||
114 | } | 94 | } | ||
115 | ge->setRenderOperations(ops); | 95 | ge->setRenderOperations(ops); | ||
116 | } | 96 | } | ||
117 | 97 | | |||
118 | void DotGraphParsingHelper::setgraphattributes() | 98 | void DotGraphParsingHelper::setgraphattributes() { | ||
119 | { | | |||
120 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for graph are : "; | 99 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for graph are : "; | ||
121 | setgraphelementattributes(graph, graphAttributes); | 100 | setgraphelementattributes(graph, graphAttributes); | ||
122 | } | 101 | } | ||
123 | 102 | | |||
124 | void DotGraphParsingHelper::setsubgraphattributes() | 103 | void DotGraphParsingHelper::setsubgraphattributes() { | ||
125 | { | | |||
126 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for subgraph are : "; | 104 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for subgraph are : "; | ||
127 | gs->setZ(z); | 105 | gs->setZ(z); | ||
128 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<gs->z(); | 106 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<gs->z(); | ||
129 | setgraphelementattributes(gs, graphAttributes); | 107 | setgraphelementattributes(gs, graphAttributes); | ||
130 | } | 108 | } | ||
131 | 109 | | |||
132 | void DotGraphParsingHelper::setnodeattributes() | 110 | void DotGraphParsingHelper::setnodeattributes() { | ||
133 | { | | |||
134 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setnodeattributes with z = " << z; | 111 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setnodeattributes with z = " << z; | ||
135 | 112 | | |||
136 | if (gn == nullptr) | 113 | if (gn == nullptr) { | ||
137 | { | | |||
138 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "gn is null"; | 114 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "gn is null"; | ||
139 | return; | 115 | return; | ||
140 | } | 116 | } | ||
141 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for node " << gn->id() << " are : "; | 117 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for node " << gn->id() << " | ||
118 | // are : "; | ||||
142 | gn->setZ(z+1); | 119 | gn->setZ(z + 1); | ||
143 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<gn->z(); | 120 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<gn->z(); | ||
144 | setgraphelementattributes(gn, nodesAttributes); | 121 | setgraphelementattributes(gn, nodesAttributes); | ||
145 | } | 122 | } | ||
146 | 123 | | |||
147 | void DotGraphParsingHelper::setedgeattributes() | 124 | void DotGraphParsingHelper::setedgeattributes() { | ||
148 | { | | |||
149 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setedgeattributeswith z = " << z; | 125 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setedgeattributeswith z = " << z; | ||
150 | 126 | | |||
151 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for edge " << ge->fromNode()->id() << "->" << ge->toNode()->id() << " are : "; | 127 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Attributes for edge " << | ||
128 | // ge->fromNode()->id() << "->" << ge->toNode()->id() << " are : "; | ||||
152 | ge->setZ(z+1); | 129 | ge->setZ(z + 1); | ||
153 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<ge->z(); | 130 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "z="<<ge->z(); | ||
154 | setgraphelementattributes(ge, edgesAttributes); | 131 | setgraphelementattributes(ge, edgesAttributes); | ||
155 | 132 | | |||
156 | DotRenderOpVec ops = ge->renderOperations(); | 133 | DotRenderOpVec ops = ge->renderOperations(); | ||
157 | if (edgesAttributes.find("_tdraw_") != edgesAttributes.end()) | 134 | if (edgesAttributes.find("_tdraw_") != edgesAttributes.end()) { | ||
158 | { | | |||
159 | parse_renderop(edgesAttributes["_tdraw_"], ops); | 135 | parse_renderop(edgesAttributes["_tdraw_"], ops); | ||
160 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "edge renderOperations size is now " << ge->renderOperations().size(); | 136 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "edge renderOperations size is | ||
137 | // now " | ||||
138 | // << ge->renderOperations().size(); | ||||
161 | DotRenderOpVec::const_iterator it, it_end; | 139 | DotRenderOpVec::const_iterator it, it_end; | ||
162 | it = ops.constBegin(); it_end = ops.constEnd(); | 140 | it = ops.constBegin(); | ||
141 | it_end = ops.constEnd(); | ||||
163 | for (; it != it_end; it++) | 142 | for (; it != it_end; it++) | ||
164 | ge->arrowheads().push_back(*it); | 143 | ge->arrowheads().push_back(*it); | ||
165 | } | 144 | } | ||
166 | if (edgesAttributes.find("_hdraw_") != edgesAttributes.end()) | 145 | if (edgesAttributes.find("_hdraw_") != edgesAttributes.end()) { | ||
167 | { | | |||
168 | parse_renderop(edgesAttributes["_hdraw_"], ops); | 146 | parse_renderop(edgesAttributes["_hdraw_"], ops); | ||
169 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "edge renderOperations size is now " << ge->renderOperations().size(); | 147 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "edge renderOperations size is | ||
148 | // now " | ||||
149 | // << ge->renderOperations().size(); | ||||
170 | DotRenderOpVec::const_iterator it, it_end; | 150 | DotRenderOpVec::const_iterator it, it_end; | ||
171 | it = ops.constBegin(); it_end = ops.constEnd(); | 151 | it = ops.constBegin(); | ||
152 | it_end = ops.constEnd(); | ||||
172 | for (; it != it_end; it++) | 153 | for (; it != it_end; it++) | ||
173 | ge->arrowheads().push_back(*it); | 154 | ge->arrowheads().push_back(*it); | ||
174 | } | 155 | } | ||
175 | ge->setRenderOperations(ops); | 156 | ge->setRenderOperations(ops); | ||
176 | } | 157 | } | ||
177 | 158 | | |||
178 | void DotGraphParsingHelper::setattributedlist() | 159 | void DotGraphParsingHelper::setattributedlist() { | ||
179 | { | 160 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << "Setting attributes list for " << | ||
180 | // // qCDebug(KGRAPHVIEWERLIB_LOG) << "Setting attributes list for " << QString::fromStdString(attributed); | 161 | // QString::fromStdString(attributed); | ||
181 | if (attributed == "graph") | 162 | if (attributed == "graph") { | ||
182 | { | 163 | if (attributes.find("bb") != attributes.end()) { | ||
183 | if (attributes.find("bb") != attributes.end()) | | |||
184 | { | | |||
185 | std::vector< int > v; | 164 | std::vector<int> v; | ||
186 | parse_integers(attributes["bb"].c_str(), v); | 165 | parse_integers(attributes["bb"].c_str(), v); | ||
187 | if (v.size()>=4) | 166 | if (v.size() >= 4) { | ||
188 | { | 167 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setting width and | ||
189 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "setting width and height to " << v[2] << v[3]; | 168 | // height to " << v[2] << v[3]; | ||
190 | graph->width(v[2]); | 169 | graph->width(v[2]); | ||
191 | graph->height(v[3]); | 170 | graph->height(v[3]); | ||
192 | } | 171 | } | ||
193 | } | 172 | } | ||
194 | AttributesMap::const_iterator it, it_end; | 173 | AttributesMap::const_iterator it, it_end; | ||
195 | it = attributes.begin(); it_end = attributes.end(); | 174 | it = attributes.begin(); | ||
196 | for (; it != it_end; it++) | 175 | it_end = attributes.end(); | ||
197 | { | 176 | for (; it != it_end; it++) { | ||
198 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << QString::fromStdString((*it).first) << " = " << QString::fromStdString((*it).second); | 177 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << | ||
178 | // QString::fromStdString((*it).first) << " = " << | ||||
179 | // QString::fromStdString((*it).second); | ||||
199 | graphAttributes[(*it).first] = (*it).second; | 180 | graphAttributes[(*it).first] = (*it).second; | ||
200 | } | 181 | } | ||
201 | } | 182 | } else if (attributed == "node") { | ||
202 | else if (attributed == "node") | | |||
203 | { | | |||
204 | AttributesMap::const_iterator it, it_end; | 183 | AttributesMap::const_iterator it, it_end; | ||
205 | it = attributes.begin(); it_end = attributes.end(); | 184 | it = attributes.begin(); | ||
206 | for (; it != it_end; it++) | 185 | it_end = attributes.end(); | ||
207 | { | 186 | for (; it != it_end; it++) { | ||
208 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << QString::fromStdString((*it).first) << " = " << QString::fromStdString((*it).second); | 187 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << | ||
188 | // QString::fromStdString((*it).first) << " = " << | ||||
189 | // QString::fromStdString((*it).second); | ||||
209 | nodesAttributes[(*it).first] = (*it).second; | 190 | nodesAttributes[(*it).first] = (*it).second; | ||
210 | } | 191 | } | ||
211 | } | 192 | } else if (attributed == "edge") { | ||
212 | else if (attributed == "edge") | | |||
213 | { | | |||
214 | AttributesMap::const_iterator it, it_end; | 193 | AttributesMap::const_iterator it, it_end; | ||
215 | it = attributes.begin(); it_end = attributes.end(); | 194 | it = attributes.begin(); | ||
216 | for (; it != it_end; it++) | 195 | it_end = attributes.end(); | ||
217 | { | 196 | for (; it != it_end; it++) { | ||
218 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << QString::fromStdString((*it).first) << " = " << QString::fromStdString((*it).second); | 197 | // qCDebug(KGRAPHVIEWERLIB_LOG) << " " << | ||
198 | // QString::fromStdString((*it).first) << " = " << | ||||
199 | // QString::fromStdString((*it).second); | ||||
219 | edgesAttributes[(*it).first] = (*it).second; | 200 | edgesAttributes[(*it).first] = (*it).second; | ||
220 | } | 201 | } | ||
221 | } | 202 | } | ||
222 | attributes.clear(); | 203 | attributes.clear(); | ||
223 | } | 204 | } | ||
224 | 205 | | |||
225 | void DotGraphParsingHelper::createnode(const std::string& nodeid) | 206 | void DotGraphParsingHelper::createnode(const std::string &nodeid) { | ||
226 | { | | |||
227 | QString id = QString::fromStdString(nodeid); | 207 | QString id = QString::fromStdString(nodeid); | ||
228 | // qCDebug(KGRAPHVIEWERLIB_LOG) << id; | 208 | // qCDebug(KGRAPHVIEWERLIB_LOG) << id; | ||
229 | gn = dynamic_cast<GraphNode*>(graph->elementNamed(id)); | 209 | gn = dynamic_cast<GraphNode *>(graph->elementNamed(id)); | ||
230 | if (gn==nullptr && graph->nodes().size() < KGV_MAX_ITEMS_TO_LOAD) | 210 | if (gn == nullptr && graph->nodes().size() < KGV_MAX_ITEMS_TO_LOAD) { | ||
231 | { | 211 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating a new node" << z << | ||
232 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating a new node" << z << (void*)gs; | 212 | // (void*)gs; | ||
233 | gn = new GraphNode(); | 213 | gn = new GraphNode(); | ||
234 | gn->setId(id); | 214 | gn->setId(id); | ||
235 | // gn->label(QString::fromStdString(nodeid)); | 215 | // gn->label(QString::fromStdString(nodeid)); | ||
236 | if (z>0 && gs) | 216 | if (z > 0 && gs) { | ||
237 | { | 217 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding node" << id << "in | ||
238 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding node" << id << "in subgraph" << gs->id(); | 218 | // subgraph" << gs->id(); | ||
239 | gs->content().push_back(gn); | 219 | gs->content().push_back(gn); | ||
240 | } | 220 | } else { | ||
241 | else | | |||
242 | { | | |||
243 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding node" << id; | 221 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding node" << id; | ||
244 | graph->nodes()[id] = gn; | 222 | graph->nodes()[id] = gn; | ||
245 | } | 223 | } | ||
246 | } | 224 | } | ||
247 | edgebounds.clear(); | 225 | edgebounds.clear(); | ||
248 | } | 226 | } | ||
249 | 227 | | |||
250 | void DotGraphParsingHelper::createsubgraph() | 228 | void DotGraphParsingHelper::createsubgraph() { | ||
251 | { | | |||
252 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | 229 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | ||
253 | if (phelper) | 230 | if (phelper) { | ||
254 | { | | |||
255 | std::string str = phelper->subgraphid; | 231 | std::string str = phelper->subgraphid; | ||
256 | if (str.empty()) | 232 | if (str.empty()) { | ||
257 | { | | |||
258 | std::ostringstream oss; | 233 | std::ostringstream oss; | ||
259 | oss << "kgv_id_" << phelper->uniq++; | 234 | oss << "kgv_id_" << phelper->uniq++; | ||
260 | str = oss.str(); | 235 | str = oss.str(); | ||
261 | } | 236 | } | ||
262 | // qCDebug(KGRAPHVIEWERLIB_LOG) << QString::fromStdString(str); | 237 | // qCDebug(KGRAPHVIEWERLIB_LOG) << QString::fromStdString(str); | ||
263 | if (graph->subgraphs().find(QString::fromStdString(str)) == graph->subgraphs().end()) | 238 | if (graph->subgraphs().find(QString::fromStdString(str)) == | ||
264 | { | 239 | graph->subgraphs().end()) { | ||
265 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating a new subgraph"; | 240 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating a new subgraph"; | ||
266 | gs = new GraphSubgraph(); | 241 | gs = new GraphSubgraph(); | ||
267 | gs->setId(QString::fromStdString(str)); | 242 | gs->setId(QString::fromStdString(str)); | ||
268 | // gs->label(QString::fromStdString(str)); | 243 | // gs->label(QString::fromStdString(str)); | ||
269 | graph->subgraphs().insert(QString::fromStdString(str), gs); | 244 | graph->subgraphs().insert(QString::fromStdString(str), gs); | ||
270 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "there is now"<<graph->subgraphs().size()<<"subgraphs in" << graph; | 245 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "there is | ||
271 | } | 246 | // now"<<graph->subgraphs().size()<<"subgraphs in" << graph; | ||
272 | else | 247 | } else { | ||
273 | { | | |||
274 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Found existing subgraph"; | 248 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Found existing subgraph"; | ||
275 | gs = *(graph->subgraphs().find(QString::fromStdString(str))); | 249 | gs = *(graph->subgraphs().find(QString::fromStdString(str))); | ||
276 | } | 250 | } | ||
277 | phelper->subgraphid = ""; | 251 | phelper->subgraphid = ""; | ||
278 | } | 252 | } | ||
279 | } | 253 | } | ||
280 | 254 | | |||
281 | void DotGraphParsingHelper::createedges() | 255 | void DotGraphParsingHelper::createedges() { | ||
282 | { | | |||
283 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 256 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
284 | std::string node1Name, node2Name; | 257 | std::string node1Name, node2Name; | ||
285 | node1Name = edgebounds.front(); | 258 | node1Name = edgebounds.front(); | ||
286 | edgebounds.pop_front(); | 259 | edgebounds.pop_front(); | ||
287 | while (!edgebounds.empty()) | 260 | while (!edgebounds.empty()) { | ||
288 | { | | |||
289 | node2Name = edgebounds.front(); | 261 | node2Name = edgebounds.front(); | ||
290 | edgebounds.pop_front(); | 262 | edgebounds.pop_front(); | ||
291 | 263 | | |||
292 | if (graph->nodes().size() >= KGV_MAX_ITEMS_TO_LOAD || graph->edges().size() >= KGV_MAX_ITEMS_TO_LOAD) | 264 | if (graph->nodes().size() >= KGV_MAX_ITEMS_TO_LOAD || | ||
293 | { | 265 | graph->edges().size() >= KGV_MAX_ITEMS_TO_LOAD) { | ||
294 | return; | 266 | return; | ||
295 | } | 267 | } | ||
296 | // qCDebug(KGRAPHVIEWERLIB_LOG) << QString::fromStdString(node1Name) << ", " << QString::fromStdString(node2Name); | 268 | // qCDebug(KGRAPHVIEWERLIB_LOG) << QString::fromStdString(node1Name) | ||
269 | // << | ||||
270 | // ", " << QString::fromStdString(node2Name); | ||||
297 | ge = new GraphEdge(); | 271 | ge = new GraphEdge(); | ||
298 | GraphElement* gn1 = graph->elementNamed(QString::fromStdString(node1Name)); | 272 | GraphElement *gn1 = | ||
299 | if (gn1 == nullptr) | 273 | graph->elementNamed(QString::fromStdString(node1Name)); | ||
300 | { | 274 | if (gn1 == nullptr) { | ||
301 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "new node 1"; | 275 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "new node 1"; | ||
302 | gn1 = new GraphNode(); | 276 | gn1 = new GraphNode(); | ||
303 | gn1->setId(QString::fromStdString(node1Name)); | 277 | gn1->setId(QString::fromStdString(node1Name)); | ||
304 | graph->nodes()[QString::fromStdString(node1Name)] = dynamic_cast<GraphNode*>(gn1); | 278 | graph->nodes()[QString::fromStdString(node1Name)] = | ||
279 | dynamic_cast<GraphNode *>(gn1); | ||||
305 | } | 280 | } | ||
306 | GraphElement* gn2 = graph->elementNamed(QString::fromStdString(node2Name)); | 281 | GraphElement *gn2 = | ||
307 | if (gn2 == nullptr) | 282 | graph->elementNamed(QString::fromStdString(node2Name)); | ||
308 | { | 283 | if (gn2 == nullptr) { | ||
309 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "new node 2"; | 284 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "new node 2"; | ||
310 | gn2 = new GraphNode(); | 285 | gn2 = new GraphNode(); | ||
311 | gn2->setId(QString::fromStdString(node2Name)); | 286 | gn2->setId(QString::fromStdString(node2Name)); | ||
312 | graph->nodes()[QString::fromStdString(node2Name)] = dynamic_cast<GraphNode*>(gn2); | 287 | graph->nodes()[QString::fromStdString(node2Name)] = | ||
288 | dynamic_cast<GraphNode *>(gn2); | ||||
313 | } | 289 | } | ||
314 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Found gn1="<<gn1<<" and gn2=" << gn2; | 290 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Found gn1="<<gn1<<" and gn2=" << | ||
315 | if (gn1 == nullptr || gn2 == nullptr) | 291 | // gn2; | ||
316 | { | 292 | if (gn1 == nullptr || gn2 == nullptr) { | ||
317 | qCWarning(KGRAPHVIEWERLIB_LOG) << "Unable to find or create edge bound(s) gn1=" << gn1 << "; gn2=" << gn2; | 293 | qCWarning(KGRAPHVIEWERLIB_LOG) | ||
294 | << "Unable to find or create edge bound(s) gn1=" << gn1 | ||||
295 | << "; gn2=" << gn2; | ||||
318 | } | 296 | } | ||
319 | ge->setFromNode(gn1); | 297 | ge->setFromNode(gn1); | ||
320 | ge->setToNode(gn2); | 298 | ge->setToNode(gn2); | ||
321 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->fromNode()->id() << " -> " << ge->toNode()->id(); | 299 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->fromNode()->id() << " -> " << | ||
300 | // ge->toNode()->id(); | ||||
322 | setedgeattributes(); | 301 | setedgeattributes(); | ||
323 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->id(); | 302 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->id(); | ||
324 | if (ge->id().isEmpty()) | 303 | if (ge->id().isEmpty()) { | ||
325 | { | 304 | ge->setId( | ||
326 | ge->setId(QString::fromStdString(node1Name)+QString::fromStdString(node2Name)+QUuid::createUuid().toString().remove('{').remove('}').remove('-')); | 305 | QString::fromStdString(node1Name) + | ||
306 | QString::fromStdString(node2Name) + | ||||
307 | QUuid::createUuid().toString().remove('{').remove('}').remove( | ||||
308 | '-')); | ||||
327 | } | 309 | } | ||
328 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->id(); | 310 | // qCDebug(KGRAPHVIEWERLIB_LOG) << ge->id(); | ||
329 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "num before=" << graph->edges().size(); | 311 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "num before=" << | ||
312 | // graph->edges().size(); | ||||
330 | graph->edges().insert(ge->id(), ge); | 313 | graph->edges().insert(ge->id(), ge); | ||
331 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "num after=" << graph->edges().size(); | 314 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "num after=" << | ||
332 | 315 | // graph->edges().size(); | |||
333 | 316 | | |||
334 | node1Name = node2Name; | 317 | node1Name = node2Name; | ||
335 | } | 318 | } | ||
336 | edgebounds.clear(); | 319 | edgebounds.clear(); | ||
337 | } | 320 | } | ||
338 | 321 | | |||
339 | void DotGraphParsingHelper::finalactions() | 322 | void DotGraphParsingHelper::finalactions() { | ||
340 | { | | |||
341 | GraphEdgeMap::iterator it, it_end; | 323 | GraphEdgeMap::iterator it, it_end; | ||
342 | it = graph->edges().begin(); it_end = graph->edges().end(); | 324 | it = graph->edges().begin(); | ||
343 | for (; it != it_end; it++) | 325 | it_end = graph->edges().end(); | ||
344 | { | 326 | for (; it != it_end; it++) { | ||
345 | (*it)->setZ(maxZ+1); | 327 | (*it)->setZ(maxZ + 1); | ||
346 | } | 328 | } | ||
347 | } | 329 | } | ||
348 | 330 | | |||
349 | } | 331 | } // namespace KGraphViewer |