graph_displayer_canvas-event.cc
changeset 152 d99e115d0d26
parent 150 86273bfe0e4d
child 153 d79a71382836
equal deleted inserted replaced
41:7720f2b26e08 42:1cf24b73380a
   407             }
   407             }
   408           }
   408           }
   409           //the clicked item is a node, the edge can be drawn
   409           //the clicked item is a node, the edge can be drawn
   410           if(target_node!=INVALID)
   410           if(target_node!=INVALID)
   411           {
   411           {
       
   412             (mytab.mapstorage).modified = true;
       
   413 
       
   414             *(nodesmap[target_node]) <<
       
   415               Gnome::Canvas::Properties::fill_color("red");
       
   416 
       
   417             //creating new edge
       
   418             active_edge=(mytab.mapstorage).graph.addEdge(active_node,
       
   419                 target_node);
       
   420 
       
   421             // update maps
       
   422             for (std::map<std::string,
       
   423                 Graph::EdgeMap<double>*>::const_iterator it =
       
   424                 (mytab.mapstorage).edgemap_storage.begin(); it !=
       
   425                 (mytab.mapstorage).edgemap_storage.end(); ++it)
       
   426             {
       
   427               (*(it->second))[active_edge] =
       
   428                 (mytab.mapstorage).edgemap_default[it->first];
       
   429             }
       
   430             // increment the id map's default value
       
   431             (mytab.mapstorage).edgemap_default["label"] += 1.0;
       
   432 
   412             if(target_node!=active_node)		
   433             if(target_node!=active_node)		
   413             {
   434             {
   414               (mytab.mapstorage).modified = true;
       
   415 
       
   416               *(nodesmap[target_node]) <<
       
   417                 Gnome::Canvas::Properties::fill_color("red");
       
   418 
       
   419               //creating new edge
       
   420               active_edge=(mytab.mapstorage).graph.addEdge(active_node,
       
   421                   target_node);
       
   422 
       
   423               // update maps
       
   424               for (std::map<std::string,
       
   425                   Graph::EdgeMap<double>*>::const_iterator it =
       
   426                   (mytab.mapstorage).edgemap_storage.begin(); it !=
       
   427                   (mytab.mapstorage).edgemap_storage.end(); ++it)
       
   428               {
       
   429                 (*(it->second))[active_edge] =
       
   430                   (mytab.mapstorage).edgemap_default[it->first];
       
   431               }
       
   432               // increment the id map's default value
       
   433               (mytab.mapstorage).edgemap_default["label"] += 1.0;
       
   434 
       
   435               //calculating coordinates of new edge
       
   436               Gnome::Canvas::Points coos;
       
   437               double x1, x2, y1, y2;
       
   438 
       
   439               active_item->get_bounds(x1, y1, x2, y2);
       
   440               coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
       
   441 
       
   442               target_item->get_bounds(x1, y1, x2, y2);
       
   443               coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
       
   444 
       
   445               // set the coordinates of the arrow on the new edge
   435               // set the coordinates of the arrow on the new edge
   446               MapStorage& ms = mytab.mapstorage;
   436               MapStorage& ms = mytab.mapstorage;
   447               ms.arrow_pos.set(active_edge,
   437               ms.arrow_pos.set(active_edge,
   448                   (ms.coords[ms.graph.source(active_edge)] +
   438                   (ms.coords[ms.graph.source(active_edge)] +
   449                    ms.coords[ms.graph.target(active_edge)])/ 2.0);
   439                    ms.coords[ms.graph.target(active_edge)])/ 2.0);
   450 
   440 
   451               //drawing new edge
   441               //drawing new edge
   452               edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
   442               edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
   453                   *this);
   443                   *this);
   454 
       
   455               //initializing edge-text as well, to empty string
       
   456               XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
       
   457               text_pos+=(XY(10,10));
       
   458 
       
   459               edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
       
   460                   text_pos.x, text_pos.y, "");
       
   461               edgetextmap[active_edge]->property_fill_color().set_value(
       
   462                   "darkgreen");
       
   463               edgetextmap[active_edge]->raise_to_top();
       
   464 
       
   465               //updating its properties
       
   466 //               mapwin.updateEdge(active_edge);
       
   467               propertyUpdate(active_edge);
       
   468             }
   444             }
   469             else
   445             else
   470             {
   446             {
   471               target_node=INVALID;
   447               // set the coordinates of the arrow on the new edge
   472               std::cerr << "Loop edge is not yet implemented!" << std::endl;
   448               MapStorage& ms = mytab.mapstorage;
       
   449               ms.arrow_pos.set(active_edge,
       
   450                   (ms.coords[ms.graph.source(active_edge)] +
       
   451                    XY(0.0, 80.0)));
       
   452 
       
   453               //drawing new edge
       
   454               edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
       
   455                   *this);
   473             }
   456             }
       
   457 
       
   458             //initializing edge-text as well, to empty string
       
   459             XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
       
   460             text_pos+=(XY(10,10));
       
   461 
       
   462             edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
       
   463                 text_pos.x, text_pos.y, "");
       
   464             edgetextmap[active_edge]->property_fill_color().set_value(
       
   465                 "darkgreen");
       
   466             edgetextmap[active_edge]->raise_to_top();
       
   467 
       
   468             propertyUpdate(active_edge);
   474           }
   469           }
   475           //clicked item was not a node. it could be an e.g. edge. we do not
   470           //clicked item was not a node. it could be an e.g. edge. we do not
   476           //deal with it furthermore.
   471           //deal with it furthermore.
   477           else
   472           else
   478           {
   473           {