[53] | 1 | #include "graph_displayer_canvas.h" |
---|
| 2 | #include "broken_edge.h" |
---|
[59] | 3 | #include <cmath> |
---|
[27] | 4 | |
---|
| 5 | |
---|
| 6 | bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event) |
---|
| 7 | { |
---|
| 8 | Gnome::Canvas::CanvasAA::on_expose_event(event); |
---|
| 9 | //usleep(10000); |
---|
| 10 | //rezoom(); |
---|
| 11 | return true; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | void GraphDisplayerCanvas::changeEditorialTool(int newtool) |
---|
| 15 | { |
---|
[34] | 16 | if(actual_tool!=newtool) |
---|
| 17 | { |
---|
[27] | 18 | |
---|
[34] | 19 | actual_handler.disconnect(); |
---|
[27] | 20 | |
---|
[34] | 21 | switch(actual_tool) |
---|
| 22 | { |
---|
| 23 | case CREATE_EDGE: |
---|
| 24 | { |
---|
| 25 | GdkEvent * generated=new GdkEvent(); |
---|
| 26 | generated->type=GDK_BUTTON_RELEASE; |
---|
| 27 | generated->button.button=3; |
---|
| 28 | createEdgeEventHandler(generated); |
---|
| 29 | break; |
---|
| 30 | } |
---|
| 31 | case EDGE_MAP_EDIT: |
---|
[35] | 32 | //has to do the same thing as in the case of NODE_MAP_EDIT |
---|
| 33 | case NODE_MAP_EDIT: |
---|
| 34 | { |
---|
| 35 | GdkEvent * generated=new GdkEvent(); |
---|
| 36 | generated->type=GDK_KEY_PRESS; |
---|
| 37 | ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
---|
| 38 | entryWidgetChangeHandler(generated); |
---|
| 39 | entrywidget.hide(); |
---|
| 40 | break; |
---|
| 41 | } |
---|
[34] | 42 | default: |
---|
| 43 | break; |
---|
| 44 | } |
---|
[27] | 45 | |
---|
[34] | 46 | active_item=NULL; |
---|
| 47 | target_item=NULL; |
---|
| 48 | active_edge=INVALID; |
---|
| 49 | active_node=INVALID; |
---|
[33] | 50 | |
---|
[27] | 51 | |
---|
[34] | 52 | actual_tool=newtool; |
---|
| 53 | |
---|
| 54 | switch(newtool) |
---|
| 55 | { |
---|
| 56 | case MOVE: |
---|
| 57 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); |
---|
| 58 | break; |
---|
[27] | 59 | |
---|
[34] | 60 | case CREATE_NODE: |
---|
| 61 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false); |
---|
| 62 | break; |
---|
[27] | 63 | |
---|
[34] | 64 | case CREATE_EDGE: |
---|
| 65 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false); |
---|
| 66 | break; |
---|
[27] | 67 | |
---|
[34] | 68 | case ERASER: |
---|
| 69 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false); |
---|
| 70 | break; |
---|
[32] | 71 | |
---|
[34] | 72 | case EDGE_MAP_EDIT: |
---|
| 73 | grab_focus(); |
---|
| 74 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); |
---|
| 75 | break; |
---|
[32] | 76 | |
---|
[34] | 77 | case NODE_MAP_EDIT: |
---|
| 78 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); |
---|
| 79 | break; |
---|
| 80 | |
---|
| 81 | default: |
---|
| 82 | break; |
---|
| 83 | } |
---|
[27] | 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
[30] | 87 | int GraphDisplayerCanvas::getActualTool() |
---|
[27] | 88 | { |
---|
| 89 | return actual_tool; |
---|
| 90 | } |
---|
| 91 | |
---|
[30] | 92 | bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) |
---|
[27] | 93 | { |
---|
| 94 | switch(e->type) |
---|
| 95 | { |
---|
| 96 | case GDK_BUTTON_PRESS: |
---|
| 97 | //we mark the location of the event to be able to calculate parameters of dragging |
---|
[31] | 98 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 99 | |
---|
| 100 | active_item=(get_item_at(clicked_x, clicked_y)); |
---|
[27] | 101 | active_node=INVALID; |
---|
[53] | 102 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[27] | 103 | { |
---|
| 104 | if(nodesmap[i]==active_item) |
---|
| 105 | { |
---|
| 106 | active_node=i; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | switch(e->button.button) |
---|
| 110 | { |
---|
| 111 | case 3: |
---|
| 112 | isbutton=3; |
---|
| 113 | break; |
---|
| 114 | default: |
---|
| 115 | isbutton=1; |
---|
| 116 | break; |
---|
| 117 | } |
---|
| 118 | break; |
---|
| 119 | case GDK_BUTTON_RELEASE: |
---|
| 120 | isbutton=0; |
---|
| 121 | active_item=NULL; |
---|
| 122 | active_node=INVALID; |
---|
| 123 | break; |
---|
| 124 | case GDK_MOTION_NOTIFY: |
---|
| 125 | //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes |
---|
| 126 | if(active_node!=INVALID) |
---|
| 127 | { |
---|
[53] | 128 | mapstorage.modified = true; |
---|
| 129 | mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); |
---|
[27] | 130 | //new coordinates will be the old values, |
---|
| 131 | //because the item will be moved to the |
---|
| 132 | //new coordinate therefore the new movement |
---|
| 133 | //has to be calculated from here |
---|
| 134 | |
---|
[31] | 135 | double new_x, new_y; |
---|
| 136 | |
---|
| 137 | window_to_world (e->motion.x, e->motion.y, new_x, new_y); |
---|
| 138 | |
---|
| 139 | double dx=new_x-clicked_x; |
---|
| 140 | double dy=new_y-clicked_y; |
---|
[27] | 141 | |
---|
[28] | 142 | //repositioning node and its text |
---|
[27] | 143 | active_item->move(dx, dy); |
---|
[28] | 144 | nodetextmap[active_node]->move(dx, dy); |
---|
[27] | 145 | |
---|
[31] | 146 | clicked_x=new_x; |
---|
| 147 | clicked_y=new_y; |
---|
[27] | 148 | |
---|
| 149 | //all the edges connected to the moved point has to be redrawn |
---|
| 150 | EdgeIt ei; |
---|
| 151 | |
---|
[53] | 152 | mapstorage.graph.firstOut(ei,active_node); |
---|
[27] | 153 | |
---|
[53] | 154 | for(;ei!=INVALID;mapstorage.graph.nextOut(ei)) |
---|
[27] | 155 | { |
---|
| 156 | Gnome::Canvas::Points coos; |
---|
| 157 | double x1, x2, y1, y2; |
---|
| 158 | |
---|
[53] | 159 | nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
---|
[27] | 160 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
| 161 | |
---|
[53] | 162 | nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
---|
[27] | 163 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
| 164 | |
---|
| 165 | if(isbutton==3) |
---|
| 166 | { |
---|
[30] | 167 | edgesmap[ei]->setPoints(coos); |
---|
[27] | 168 | } |
---|
| 169 | else |
---|
| 170 | { |
---|
[30] | 171 | edgesmap[ei]->setPoints(coos,true); |
---|
[27] | 172 | } |
---|
| 173 | |
---|
[28] | 174 | //reposition of edgetext |
---|
[30] | 175 | xy<double> text_pos=edgesmap[ei]->getArrowPos(); |
---|
[27] | 176 | text_pos+=(xy<double>(10,10)); |
---|
| 177 | edgetextmap[ei]->property_x().set_value(text_pos.x); |
---|
| 178 | edgetextmap[ei]->property_y().set_value(text_pos.y); |
---|
| 179 | } |
---|
| 180 | |
---|
[53] | 181 | mapstorage.graph.firstIn(ei,active_node); |
---|
| 182 | for(;ei!=INVALID;mapstorage.graph.nextIn(ei)) |
---|
[27] | 183 | { |
---|
| 184 | Gnome::Canvas::Points coos; |
---|
| 185 | double x1, x2, y1, y2; |
---|
| 186 | |
---|
[53] | 187 | nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
---|
[27] | 188 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
| 189 | |
---|
[53] | 190 | nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
---|
[27] | 191 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
| 192 | |
---|
| 193 | if(isbutton==3) |
---|
| 194 | { |
---|
[30] | 195 | edgesmap[ei]->setPoints(coos); |
---|
[27] | 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
[30] | 199 | edgesmap[ei]->setPoints(coos,true); |
---|
[27] | 200 | } |
---|
| 201 | |
---|
[30] | 202 | xy<double> text_pos=edgesmap[ei]->getArrowPos(); |
---|
[27] | 203 | text_pos+=(xy<double>(10,10)); |
---|
| 204 | edgetextmap[ei]->property_x().set_value(text_pos.x); |
---|
| 205 | edgetextmap[ei]->property_y().set_value(text_pos.y); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | default: break; |
---|
| 209 | } |
---|
| 210 | |
---|
[31] | 211 | return false; |
---|
[27] | 212 | } |
---|
| 213 | |
---|
[30] | 214 | bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) |
---|
[27] | 215 | { |
---|
| 216 | switch(e->type) |
---|
[63] | 217 | { |
---|
| 218 | //move the new node |
---|
| 219 | case GDK_MOTION_NOTIFY: |
---|
| 220 | { |
---|
| 221 | GdkEvent * generated=new GdkEvent(); |
---|
| 222 | generated->motion.x=e->motion.x; |
---|
| 223 | generated->motion.y=e->motion.y; |
---|
| 224 | generated->type=GDK_MOTION_NOTIFY; |
---|
| 225 | moveEventHandler(generated); |
---|
| 226 | break; |
---|
| 227 | } |
---|
[27] | 228 | |
---|
[63] | 229 | case GDK_BUTTON_RELEASE: |
---|
[53] | 230 | mapstorage.modified = true; |
---|
| 231 | |
---|
[27] | 232 | isbutton=1; |
---|
| 233 | |
---|
[62] | 234 | active_node=mapstorage.graph.addNode(); |
---|
[27] | 235 | |
---|
| 236 | //initiating values corresponding to new node in maps |
---|
| 237 | |
---|
| 238 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 239 | |
---|
[63] | 240 | // update coordinates |
---|
[53] | 241 | mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); |
---|
[63] | 242 | |
---|
| 243 | // update all other maps |
---|
| 244 | for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
---|
| 245 | mapstorage.nodemap_storage.begin(); it != |
---|
| 246 | mapstorage.nodemap_storage.end(); ++it) |
---|
| 247 | { |
---|
[64] | 248 | if ((it->first != "coordinates_x") && |
---|
| 249 | (it->first != "coordinates_y")) |
---|
[63] | 250 | { |
---|
| 251 | (*(it->second))[active_node] = |
---|
| 252 | mapstorage.nodemap_default[it->first]; |
---|
| 253 | } |
---|
| 254 | } |
---|
[64] | 255 | // increment the id map's default value |
---|
| 256 | mapstorage.nodemap_default["id"] += 1.0; |
---|
[63] | 257 | |
---|
[53] | 258 | nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, |
---|
[63] | 259 | clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
---|
[27] | 260 | active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
---|
[63] | 261 | *(nodesmap[active_node]) << |
---|
| 262 | Gnome::Canvas::Properties::fill_color("blue"); |
---|
| 263 | *(nodesmap[active_node]) << |
---|
| 264 | Gnome::Canvas::Properties::outline_color("black"); |
---|
| 265 | active_item->raise_to_top(); |
---|
| 266 | |
---|
[27] | 267 | (nodesmap[active_node])->show(); |
---|
[28] | 268 | |
---|
[53] | 269 | nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, |
---|
[63] | 270 | clicked_x+node_property_defaults[N_RADIUS]+5, |
---|
| 271 | clicked_y+node_property_defaults[N_RADIUS]+5, ""); |
---|
[28] | 272 | nodetextmap[active_node]->property_fill_color().set_value("darkblue"); |
---|
[63] | 273 | nodetextmap[active_node]->raise_to_top(); |
---|
[28] | 274 | |
---|
[53] | 275 | mapwin.updateNode(active_node); |
---|
[28] | 276 | |
---|
[27] | 277 | isbutton=0; |
---|
[31] | 278 | target_item=NULL; |
---|
[27] | 279 | active_item=NULL; |
---|
| 280 | active_node=INVALID; |
---|
[63] | 281 | |
---|
[27] | 282 | break; |
---|
| 283 | default: |
---|
| 284 | break; |
---|
[63] | 285 | } |
---|
[27] | 286 | return false; |
---|
| 287 | } |
---|
| 288 | |
---|
[30] | 289 | bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e) |
---|
[27] | 290 | { |
---|
| 291 | switch(e->type) |
---|
[63] | 292 | { |
---|
[27] | 293 | case GDK_BUTTON_PRESS: |
---|
| 294 | //in edge creation right button has special meaning |
---|
| 295 | if(e->button.button!=3) |
---|
[63] | 296 | { |
---|
| 297 | //there is not yet selected node |
---|
| 298 | if(active_node==INVALID) |
---|
| 299 | { |
---|
| 300 | //we mark the location of the event to be able to calculate parameters of dragging |
---|
[31] | 301 | |
---|
[63] | 302 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
[31] | 303 | |
---|
[63] | 304 | active_item=(get_item_at(clicked_x, clicked_y)); |
---|
| 305 | active_node=INVALID; |
---|
| 306 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 307 | { |
---|
| 308 | if(nodesmap[i]==active_item) |
---|
| 309 | { |
---|
| 310 | active_node=i; |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | //the clicked item is really a node |
---|
| 314 | if(active_node!=INVALID) |
---|
| 315 | { |
---|
| 316 | *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); |
---|
| 317 | isbutton=1; |
---|
| 318 | } |
---|
| 319 | //clicked item was not a node. It could be e.g. edge. |
---|
| 320 | else |
---|
| 321 | { |
---|
| 322 | active_item=NULL; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | //we only have to do sg. if the mouse button |
---|
| 326 | // is pressed already once AND the click was |
---|
| 327 | // on a node that was found in the set of |
---|
| 328 | //nodes, and now we only search for the second |
---|
| 329 | //node |
---|
| 330 | else |
---|
| 331 | { |
---|
| 332 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 333 | target_item=(get_item_at(clicked_x, clicked_y)); |
---|
| 334 | Node target_node=INVALID; |
---|
| 335 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 336 | { |
---|
| 337 | if(nodesmap[i]==target_item) |
---|
| 338 | { |
---|
| 339 | target_node=i; |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | //the clicked item is a node, the edge can be drawn |
---|
| 343 | if(target_node!=INVALID) |
---|
| 344 | { |
---|
| 345 | if(target_node!=active_node) |
---|
| 346 | { |
---|
| 347 | mapstorage.modified = true; |
---|
[53] | 348 | |
---|
[63] | 349 | *(nodesmap[target_node]) << |
---|
| 350 | Gnome::Canvas::Properties::fill_color("red"); |
---|
[27] | 351 | |
---|
[63] | 352 | //creating new edge |
---|
| 353 | active_edge=mapstorage.graph.addEdge(active_node, |
---|
| 354 | target_node); |
---|
[27] | 355 | |
---|
[64] | 356 | // update maps |
---|
[63] | 357 | for (std::map<std::string, |
---|
| 358 | Graph::EdgeMap<double>*>::const_iterator it = |
---|
| 359 | mapstorage.edgemap_storage.begin(); it != |
---|
| 360 | mapstorage.edgemap_storage.end(); ++it) |
---|
| 361 | { |
---|
[64] | 362 | (*(it->second))[active_edge] = |
---|
| 363 | mapstorage.edgemap_default[it->first]; |
---|
[63] | 364 | } |
---|
[64] | 365 | // increment the id map's default value |
---|
| 366 | mapstorage.edgemap_default["id"] += 1.0; |
---|
[27] | 367 | |
---|
[63] | 368 | //calculating coordinates of new edge |
---|
| 369 | Gnome::Canvas::Points coos; |
---|
| 370 | double x1, x2, y1, y2; |
---|
[27] | 371 | |
---|
[63] | 372 | active_item->get_bounds(x1, y1, x2, y2); |
---|
| 373 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
[27] | 374 | |
---|
[63] | 375 | target_item->get_bounds(x1, y1, x2, y2); |
---|
| 376 | coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
---|
[27] | 377 | |
---|
[63] | 378 | //drawing new edge |
---|
| 379 | edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, |
---|
| 380 | *this); |
---|
| 381 | *(edgesmap[active_edge]) << |
---|
| 382 | Gnome::Canvas::Properties::fill_color("green"); |
---|
| 383 | edgesmap[active_edge]->property_width_pixels().set_value(10); |
---|
[27] | 384 | |
---|
[63] | 385 | edgesmap[active_edge]->lower_to_bottom(); |
---|
[28] | 386 | |
---|
[63] | 387 | //initializing edge-text as well, to empty string |
---|
| 388 | xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); |
---|
| 389 | text_pos+=(xy<double>(10,10)); |
---|
| 390 | |
---|
| 391 | edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, |
---|
| 392 | text_pos.x, text_pos.y, ""); |
---|
| 393 | edgetextmap[active_edge]->property_fill_color().set_value( |
---|
| 394 | "darkgreen"); |
---|
| 395 | edgetextmap[active_edge]->raise_to_top(); |
---|
| 396 | |
---|
| 397 | //updating its properties |
---|
| 398 | mapwin.updateEdge(active_edge); |
---|
| 399 | } |
---|
| 400 | else |
---|
| 401 | { |
---|
| 402 | target_node=INVALID; |
---|
| 403 | std::cerr << "Loop edge is not yet implemented!" << std::endl; |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | //clicked item was not a node. it could be an e.g. edge. we do not |
---|
| 407 | //deal with it furthermore. |
---|
| 408 | else |
---|
| 409 | { |
---|
| 410 | target_item=NULL; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | } |
---|
[27] | 414 | break; |
---|
| 415 | case GDK_BUTTON_RELEASE: |
---|
| 416 | isbutton=0; |
---|
| 417 | //we clear settings in two cases |
---|
| 418 | //1: the edge is ready (target_item has valid value) |
---|
| 419 | //2: the edge creation is cancelled with right button |
---|
| 420 | if((target_item)||(e->button.button==3)) |
---|
[63] | 421 | { |
---|
| 422 | if(active_item) |
---|
| 423 | { |
---|
| 424 | *active_item << Gnome::Canvas::Properties::fill_color("blue"); |
---|
| 425 | active_item=NULL; |
---|
| 426 | } |
---|
| 427 | if(target_item) |
---|
| 428 | { |
---|
| 429 | *target_item << Gnome::Canvas::Properties::fill_color("blue"); |
---|
| 430 | target_item=NULL; |
---|
| 431 | } |
---|
| 432 | active_node=INVALID; |
---|
| 433 | active_edge=INVALID; |
---|
| 434 | } |
---|
[27] | 435 | break; |
---|
| 436 | default: |
---|
| 437 | break; |
---|
[63] | 438 | } |
---|
[27] | 439 | return false; |
---|
| 440 | } |
---|
| 441 | |
---|
[30] | 442 | bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) |
---|
[27] | 443 | { |
---|
| 444 | switch(e->type) |
---|
| 445 | { |
---|
| 446 | case GDK_BUTTON_PRESS: |
---|
[43] | 447 | //finding the clicked items |
---|
[31] | 448 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 449 | active_item=(get_item_at(clicked_x, clicked_y)); |
---|
[27] | 450 | active_node=INVALID; |
---|
| 451 | active_edge=INVALID; |
---|
[43] | 452 | //was it a node? |
---|
[53] | 453 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[27] | 454 | { |
---|
| 455 | if(nodesmap[i]==active_item) |
---|
| 456 | { |
---|
| 457 | active_node=i; |
---|
| 458 | } |
---|
| 459 | } |
---|
[43] | 460 | //or was it an edge? |
---|
[27] | 461 | if(active_node==INVALID) |
---|
| 462 | { |
---|
[53] | 463 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[27] | 464 | { |
---|
| 465 | if(edgesmap[i]==active_item) |
---|
| 466 | { |
---|
| 467 | active_edge=i; |
---|
| 468 | } |
---|
| 469 | } |
---|
| 470 | } |
---|
[43] | 471 | |
---|
| 472 | //recolor activated item |
---|
[31] | 473 | if(active_item) |
---|
| 474 | { |
---|
| 475 | *active_item << Gnome::Canvas::Properties::fill_color("red"); |
---|
| 476 | } |
---|
[27] | 477 | break; |
---|
| 478 | |
---|
| 479 | case GDK_BUTTON_RELEASE: |
---|
[31] | 480 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 481 | if(active_item) |
---|
[27] | 482 | { |
---|
[43] | 483 | //the cursor was not moved since pressing it |
---|
[31] | 484 | if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
---|
[27] | 485 | { |
---|
[43] | 486 | //a node was found |
---|
[31] | 487 | if(active_node!=INVALID) |
---|
| 488 | { |
---|
[53] | 489 | mapstorage.modified = true; |
---|
[27] | 490 | |
---|
[31] | 491 | //collecting edges to delete |
---|
| 492 | EdgeIt e; |
---|
| 493 | std::set<Graph::Edge> edges_to_delete; |
---|
[27] | 494 | |
---|
[53] | 495 | mapstorage.graph.firstOut(e,active_node); |
---|
| 496 | for(;e!=INVALID;mapstorage.graph.nextOut(e)) |
---|
[31] | 497 | { |
---|
| 498 | edges_to_delete.insert(e); |
---|
| 499 | } |
---|
| 500 | |
---|
[53] | 501 | mapstorage.graph.firstIn(e,active_node); |
---|
| 502 | for(;e!=INVALID;mapstorage.graph.nextIn(e)) |
---|
[31] | 503 | { |
---|
| 504 | edges_to_delete.insert(e); |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | //deleting collected edges |
---|
| 508 | for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++) |
---|
| 509 | { |
---|
| 510 | deleteItem(*edge_set_it); |
---|
| 511 | } |
---|
| 512 | deleteItem(active_node); |
---|
| 513 | } |
---|
| 514 | //a simple edge was chosen |
---|
| 515 | else |
---|
[27] | 516 | { |
---|
[31] | 517 | deleteItem(active_edge); |
---|
[27] | 518 | } |
---|
| 519 | } |
---|
[31] | 520 | //pointer was moved, deletion is cancelled |
---|
[27] | 521 | else |
---|
| 522 | { |
---|
[31] | 523 | if(active_node!=INVALID) |
---|
| 524 | { |
---|
| 525 | *active_item << Gnome::Canvas::Properties::fill_color("blue"); |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
| 529 | *active_item << Gnome::Canvas::Properties::fill_color("green"); |
---|
| 530 | } |
---|
[27] | 531 | } |
---|
| 532 | } |
---|
| 533 | //reseting datas |
---|
| 534 | active_item=NULL; |
---|
| 535 | active_edge=INVALID; |
---|
| 536 | active_node=INVALID; |
---|
| 537 | break; |
---|
| 538 | |
---|
| 539 | case GDK_MOTION_NOTIFY: |
---|
| 540 | break; |
---|
| 541 | |
---|
| 542 | default: |
---|
| 543 | break; |
---|
| 544 | } |
---|
[31] | 545 | return false; |
---|
[27] | 546 | } |
---|
| 547 | |
---|
[32] | 548 | bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e) |
---|
| 549 | { |
---|
[48] | 550 | if(actual_tool==EDGE_MAP_EDIT) |
---|
[32] | 551 | { |
---|
[48] | 552 | switch(e->type) |
---|
| 553 | { |
---|
| 554 | case GDK_KEY_PRESS: |
---|
| 555 | //for Escape or Enter hide the displayed widget |
---|
| 556 | { |
---|
| 557 | nodeMapEditEventHandler(e); |
---|
| 558 | break; |
---|
| 559 | } |
---|
| 560 | case GDK_BUTTON_PRESS: |
---|
| 561 | //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. |
---|
| 562 | { |
---|
| 563 | //for determine, whether it was an edge |
---|
[62] | 564 | Edge clicked_edge=INVALID; |
---|
[43] | 565 | |
---|
[48] | 566 | //find the activated item between texts |
---|
[65] | 567 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 568 | active_item=(get_item_at(clicked_x, clicked_y)); |
---|
[53] | 569 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[34] | 570 | { |
---|
[48] | 571 | if(edgetextmap[i]==active_item) |
---|
| 572 | { |
---|
| 573 | clicked_edge=i; |
---|
| 574 | } |
---|
[34] | 575 | } |
---|
[48] | 576 | |
---|
| 577 | //if it was not between texts, search for it between edges |
---|
| 578 | if(clicked_edge==INVALID) |
---|
[34] | 579 | { |
---|
[53] | 580 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[48] | 581 | { |
---|
| 582 | //at the same time only one can be active |
---|
| 583 | if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item)) |
---|
| 584 | { |
---|
| 585 | clicked_edge=i; |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | } |
---|
| 589 | //if it was really an edge... |
---|
| 590 | if(clicked_edge!=INVALID) |
---|
| 591 | { |
---|
[63] | 592 | // the id map is not editable |
---|
[65] | 593 | if (edgemap_to_edit == "id") return 0; |
---|
| 594 | |
---|
[48] | 595 | //If there is already edited edge, it has to be saved first |
---|
| 596 | if(entrywidget.is_visible()) |
---|
| 597 | { |
---|
| 598 | GdkEvent * generated=new GdkEvent(); |
---|
| 599 | generated->type=GDK_KEY_PRESS; |
---|
| 600 | ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
---|
| 601 | entryWidgetChangeHandler(generated); |
---|
| 602 | } |
---|
| 603 | //If the previous value could be saved, we can go further, otherwise not |
---|
| 604 | if(!entrywidget.is_visible()) |
---|
| 605 | { |
---|
| 606 | //and there is activated map |
---|
| 607 | if(edgetextmap[clicked_edge]->property_text().get_value()!="") |
---|
| 608 | { |
---|
| 609 | //activate the general variable for it |
---|
| 610 | active_edge=clicked_edge; |
---|
| 611 | //delete visible widget if there is |
---|
| 612 | if(canvasentrywidget) |
---|
| 613 | { |
---|
| 614 | delete(canvasentrywidget); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | //initialize the entry |
---|
| 618 | entrywidget.show(); |
---|
| 619 | |
---|
| 620 | //fill in the correct value |
---|
| 621 | entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value()); |
---|
| 622 | |
---|
| 623 | //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc |
---|
| 624 | xy<double> entry_coos; |
---|
| 625 | entry_coos.x=(edgetextmap[active_edge])->property_x().get_value(); |
---|
| 626 | entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2; |
---|
| 627 | entry_coos.y=(edgetextmap[active_edge])->property_y().get_value(); |
---|
| 628 | entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2; |
---|
| 629 | canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); |
---|
| 630 | canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4); |
---|
| 631 | canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5); |
---|
[55] | 632 | |
---|
| 633 | //setting the focus to newly created widget |
---|
| 634 | parentwin->set_focus(entrywidget); |
---|
| 635 | parentwin->activate_focus(); |
---|
[48] | 636 | } |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | //if it was not an edge... |
---|
| 640 | else |
---|
| 641 | { |
---|
| 642 | //In this case the click did not happen on an edge |
---|
| 643 | //if there is visible entry we save the value in it |
---|
| 644 | //we pretend like an Enter was presse din the Entry widget |
---|
[43] | 645 | GdkEvent * generated=new GdkEvent(); |
---|
| 646 | generated->type=GDK_KEY_PRESS; |
---|
| 647 | ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
---|
| 648 | entryWidgetChangeHandler(generated); |
---|
| 649 | } |
---|
[48] | 650 | break; |
---|
[34] | 651 | } |
---|
[48] | 652 | default: |
---|
| 653 | break; |
---|
| 654 | } |
---|
[32] | 655 | } |
---|
| 656 | return false; |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e) |
---|
| 660 | { |
---|
[48] | 661 | if(actual_tool==NODE_MAP_EDIT) |
---|
[35] | 662 | { |
---|
[48] | 663 | switch(e->type) |
---|
| 664 | { |
---|
| 665 | case GDK_KEY_PRESS: |
---|
| 666 | //for Escape or Enter hide the displayed widget |
---|
[35] | 667 | { |
---|
[48] | 668 | switch(((GdkEventKey*)e)->keyval) |
---|
| 669 | { |
---|
| 670 | case GDK_Escape: |
---|
| 671 | entrywidget.hide(); |
---|
| 672 | break; |
---|
| 673 | case GDK_Return: |
---|
| 674 | case GDK_KP_Enter: |
---|
| 675 | entrywidget.hide(); |
---|
| 676 | break; |
---|
| 677 | default: |
---|
| 678 | break; |
---|
| 679 | } |
---|
| 680 | |
---|
[35] | 681 | break; |
---|
| 682 | } |
---|
[48] | 683 | case GDK_BUTTON_PRESS: |
---|
| 684 | //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. |
---|
| 685 | { |
---|
| 686 | //for determine, whether it was a node |
---|
[62] | 687 | Node clicked_node=INVALID; |
---|
[43] | 688 | |
---|
[48] | 689 | //find the activated item between texts |
---|
| 690 | active_item=(get_item_at(e->button.x, e->button.y)); |
---|
[53] | 691 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[35] | 692 | { |
---|
[48] | 693 | //at the same time only one can be active |
---|
| 694 | if(nodetextmap[i]==active_item) |
---|
| 695 | { |
---|
| 696 | clicked_node=i; |
---|
| 697 | } |
---|
[35] | 698 | } |
---|
[43] | 699 | |
---|
[48] | 700 | //if there was not, search for it between nodes |
---|
| 701 | if(clicked_node==INVALID) |
---|
[35] | 702 | { |
---|
[48] | 703 | window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
---|
| 704 | active_item=(get_item_at(clicked_x, clicked_y)); |
---|
| 705 | |
---|
[53] | 706 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[48] | 707 | { |
---|
| 708 | //at the same time only one can be active |
---|
| 709 | if(nodesmap[i]==active_item) |
---|
| 710 | { |
---|
| 711 | clicked_node=i; |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | } |
---|
| 715 | //if it was really an edge... |
---|
| 716 | if(clicked_node!=INVALID) |
---|
| 717 | { |
---|
[63] | 718 | // the id map is not editable |
---|
| 719 | if (nodemap_to_edit == "id") return 0; |
---|
[48] | 720 | //If there is already edited edge, it has to be saved first |
---|
| 721 | if(entrywidget.is_visible()) |
---|
| 722 | { |
---|
| 723 | GdkEvent * generated=new GdkEvent(); |
---|
| 724 | generated->type=GDK_KEY_PRESS; |
---|
| 725 | ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
---|
| 726 | entryWidgetChangeHandler(generated); |
---|
| 727 | } |
---|
| 728 | //If the previous value could be saved, we can go further, otherwise not |
---|
| 729 | if(!entrywidget.is_visible()) |
---|
| 730 | { |
---|
| 731 | //and there is activated map |
---|
| 732 | if(nodetextmap[clicked_node]->property_text().get_value()!="") |
---|
| 733 | { |
---|
| 734 | //activate the general variable for it |
---|
| 735 | active_node=clicked_node; |
---|
| 736 | //delete visible widget if there is |
---|
| 737 | if(canvasentrywidget) |
---|
| 738 | { |
---|
| 739 | delete(canvasentrywidget); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | //initialize the entry |
---|
| 743 | entrywidget.show(); |
---|
| 744 | |
---|
| 745 | //fill in the correct value |
---|
| 746 | entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); |
---|
| 747 | |
---|
| 748 | //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc |
---|
| 749 | xy<double> entry_coos; |
---|
| 750 | entry_coos.x=(nodetextmap[active_node])->property_x().get_value(); |
---|
| 751 | entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2; |
---|
| 752 | entry_coos.y=(nodetextmap[active_node])->property_y().get_value(); |
---|
| 753 | entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2; |
---|
| 754 | canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); |
---|
| 755 | canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4); |
---|
| 756 | canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5); |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | } |
---|
| 760 | //if it was not an edge... |
---|
| 761 | else |
---|
| 762 | { |
---|
| 763 | //In this case the click did not happen on an edge |
---|
| 764 | //if there is visible entry we save the value in it |
---|
| 765 | //we pretend like an Enter was presse din the Entry widget |
---|
[35] | 766 | GdkEvent * generated=new GdkEvent(); |
---|
| 767 | generated->type=GDK_KEY_PRESS; |
---|
| 768 | ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
---|
| 769 | entryWidgetChangeHandler(generated); |
---|
| 770 | } |
---|
[48] | 771 | break; |
---|
[35] | 772 | } |
---|
[48] | 773 | default: |
---|
| 774 | break; |
---|
| 775 | } |
---|
[35] | 776 | } |
---|
| 777 | return false; |
---|
[32] | 778 | } |
---|
| 779 | |
---|
[34] | 780 | bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e) |
---|
| 781 | { |
---|
[35] | 782 | if(entrywidget.is_visible()) |
---|
| 783 | { |
---|
| 784 | if(e->type==GDK_KEY_PRESS) |
---|
| 785 | { |
---|
| 786 | switch(((GdkEventKey*)e)->keyval) |
---|
| 787 | { |
---|
| 788 | case GDK_Escape: |
---|
| 789 | entrywidget.hide(); |
---|
| 790 | break; |
---|
| 791 | case GDK_KP_Enter: |
---|
| 792 | case GDK_Return: |
---|
| 793 | { |
---|
[43] | 794 | //these variables check whether the text in the entry is valid |
---|
[41] | 795 | bool valid_double=true; |
---|
| 796 | int point_num=0; |
---|
[43] | 797 | |
---|
| 798 | //getting the value from the entry and converting it to double |
---|
[41] | 799 | Glib::ustring mapvalue_str = entrywidget.get_text(); |
---|
[35] | 800 | |
---|
[41] | 801 | char * mapvalue_ch=new char [mapvalue_str.length()]; |
---|
| 802 | for(int i=0;i<(int)(mapvalue_str.length());i++) |
---|
[35] | 803 | { |
---|
[41] | 804 | if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.')) |
---|
[35] | 805 | { |
---|
[41] | 806 | valid_double=false; |
---|
[35] | 807 | } |
---|
| 808 | else |
---|
| 809 | { |
---|
[41] | 810 | if(mapvalue_str[i]=='.') |
---|
| 811 | { |
---|
| 812 | point_num++; |
---|
| 813 | } |
---|
[35] | 814 | } |
---|
[41] | 815 | mapvalue_ch[i]=mapvalue_str[i]; |
---|
[35] | 816 | } |
---|
[45] | 817 | |
---|
[43] | 818 | //if the text in the entry was correct |
---|
[41] | 819 | if((point_num<=1)&&(valid_double)) |
---|
[35] | 820 | { |
---|
[45] | 821 | double mapvalue_d=atof(mapvalue_ch); |
---|
| 822 | |
---|
| 823 | //reconvert the double to string for the correct format |
---|
| 824 | std::ostringstream ostr; |
---|
| 825 | ostr << mapvalue_d; |
---|
| 826 | |
---|
[43] | 827 | //save the value to the correct place |
---|
[35] | 828 | switch(actual_tool) |
---|
| 829 | { |
---|
| 830 | case EDGE_MAP_EDIT: |
---|
[45] | 831 | edgetextmap[active_edge]->property_text().set_value(ostr.str()); |
---|
[41] | 832 | (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d; |
---|
[53] | 833 | mapwin.updateEdge(active_edge); |
---|
[35] | 834 | break; |
---|
| 835 | case NODE_MAP_EDIT: |
---|
[45] | 836 | nodetextmap[active_node]->property_text().set_value(ostr.str()); |
---|
[41] | 837 | (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d; |
---|
[53] | 838 | mapwin.updateNode(active_node); |
---|
[35] | 839 | break; |
---|
| 840 | default: |
---|
| 841 | break; |
---|
| 842 | } |
---|
| 843 | entrywidget.hide(); |
---|
| 844 | } |
---|
[43] | 845 | //the text in the entry was not correct for a double |
---|
[35] | 846 | else |
---|
| 847 | { |
---|
[48] | 848 | std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl; |
---|
[35] | 849 | } |
---|
| 850 | |
---|
| 851 | break; |
---|
| 852 | } |
---|
| 853 | default: |
---|
| 854 | break; |
---|
| 855 | } |
---|
| 856 | } |
---|
| 857 | } |
---|
[34] | 858 | return false; |
---|
| 859 | } |
---|
| 860 | |
---|
[62] | 861 | void GraphDisplayerCanvas::deleteItem(Node node_to_delete) |
---|
[27] | 862 | { |
---|
[28] | 863 | delete(nodetextmap[node_to_delete]); |
---|
[27] | 864 | delete(nodesmap[node_to_delete]); |
---|
[53] | 865 | mapstorage.graph.erase(node_to_delete); |
---|
[27] | 866 | } |
---|
| 867 | |
---|
[62] | 868 | void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) |
---|
[27] | 869 | { |
---|
[28] | 870 | delete(edgetextmap[edge_to_delete]); |
---|
[27] | 871 | delete(edgesmap[edge_to_delete]); |
---|
[53] | 872 | mapstorage.graph.erase(edge_to_delete); |
---|
[27] | 873 | } |
---|
| 874 | |
---|
[30] | 875 | void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
---|
[27] | 876 | { |
---|
| 877 | new_place+=(xy<double>(10,10)); |
---|
[35] | 878 | edgetextmap[forming_edge]->property_x().set_value(new_place.x); |
---|
| 879 | edgetextmap[forming_edge]->property_y().set_value(new_place.y); |
---|
[27] | 880 | } |
---|
| 881 | |
---|
[30] | 882 | void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on) |
---|
[27] | 883 | { |
---|
| 884 | if(on) |
---|
| 885 | { |
---|
[35] | 886 | if(forming_edge!=INVALID) |
---|
[27] | 887 | { |
---|
[48] | 888 | std::cerr << "ERROR!!!! Valid edge found!" << std::endl; |
---|
[27] | 889 | } |
---|
| 890 | else |
---|
| 891 | { |
---|
[53] | 892 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[27] | 893 | { |
---|
| 894 | if(edgesmap[i]==active_bre) |
---|
| 895 | { |
---|
[35] | 896 | forming_edge=i; |
---|
[27] | 897 | } |
---|
| 898 | } |
---|
| 899 | } |
---|
| 900 | } |
---|
| 901 | else |
---|
| 902 | { |
---|
[35] | 903 | if(forming_edge!=INVALID) |
---|
[27] | 904 | { |
---|
[35] | 905 | forming_edge=INVALID; |
---|
[27] | 906 | } |
---|
| 907 | else |
---|
| 908 | { |
---|
[48] | 909 | std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; |
---|
[27] | 910 | } |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | } |
---|
[32] | 914 | |
---|
[46] | 915 | int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
---|
[37] | 916 | { |
---|
[43] | 917 | //create the new map |
---|
[53] | 918 | Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value); |
---|
[46] | 919 | |
---|
| 920 | //if addition was not successful addEdgeMap returns one. |
---|
| 921 | //cause can be that there is already a map named like the new one |
---|
[63] | 922 | if(mapstorage.addEdgeMap(mapname,emptr, default_value)) |
---|
[46] | 923 | { |
---|
| 924 | return 1; |
---|
| 925 | } |
---|
| 926 | |
---|
[43] | 927 | |
---|
| 928 | //add it to the list of the displayable maps |
---|
[53] | 929 | mapwin.registerNewEdgeMap(mapname); |
---|
[43] | 930 | |
---|
| 931 | //display it |
---|
[41] | 932 | changeEdgeText(mapname); |
---|
[46] | 933 | |
---|
| 934 | return 0; |
---|
[37] | 935 | } |
---|
| 936 | |
---|
[46] | 937 | int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
---|
[37] | 938 | { |
---|
[43] | 939 | //create the new map |
---|
[53] | 940 | Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value); |
---|
[46] | 941 | |
---|
| 942 | //if addition was not successful addNodeMap returns one. |
---|
| 943 | //cause can be that there is already a map named like the new one |
---|
[63] | 944 | if(mapstorage.addNodeMap(mapname,emptr, default_value)) |
---|
[46] | 945 | { |
---|
| 946 | return 1; |
---|
| 947 | } |
---|
[43] | 948 | |
---|
| 949 | //add it to the list of the displayable maps |
---|
[53] | 950 | mapwin.registerNewNodeMap(mapname); |
---|
[43] | 951 | |
---|
| 952 | //display it |
---|
[41] | 953 | changeNodeText(mapname); |
---|
[46] | 954 | |
---|
| 955 | return 0; |
---|
[37] | 956 | } |
---|
| 957 | |
---|