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