COIN-OR::LEMON - Graph Library

Changeset 94:adfdc2f70548 in glemon-0.x for graph_displayer_canvas-event.cc


Ignore:
Timestamp:
11/29/05 20:31:58 (19 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2389
Message:

Structure of GUI is now more clear-cut than before.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r92 r94  
    9595      active_item=(get_item_at(clicked_x, clicked_y));
    9696      active_node=INVALID;
    97       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     97      for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    9898        {
    9999          if(nodesmap[i]==active_item)
     
    126126      if(active_node!=INVALID)
    127127      {
    128         mapstorage.modified = true;
     128        (mainwin.mapstorage).modified = true;
    129129
    130130        //new coordinates will be the old values,
     
    145145
    146146        // the new coordinates of the centre of the node
    147         double coord_x = new_x - (clicked_x - mapstorage.coords[active_node].x);
    148         double coord_y = new_y - (clicked_y - mapstorage.coords[active_node].y);
     147        double coord_x = new_x - (clicked_x - (mainwin.mapstorage).coords[active_node].x);
     148        double coord_y = new_y - (clicked_y - (mainwin.mapstorage).coords[active_node].y);
    149149
    150150        clicked_x=new_x;
     
    152152
    153153        // write back the new coordinates to the coords map
    154         mapstorage.coords.set(active_node, xy<double>(coord_x, coord_y));
     154        (mainwin.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
    155155
    156156        // reposition the coordinates text
    157157        std::ostringstream ostr;
    158158        ostr << "(" <<
    159           mapstorage.coords[active_node].x << ", " <<
    160           mapstorage.coords[active_node].y << ")";
     159          (mainwin.mapstorage).coords[active_node].x << ", " <<
     160          (mainwin.mapstorage).coords[active_node].y << ")";
    161161        double radius =
    162162          (nodesmap[active_node]->property_x2().get_value() -
     
    165165        {
    166166          coord_text->property_text().set_value(ostr.str());
    167           coord_text->property_x().set_value(mapstorage.coords[active_node].x +
     167          coord_text->property_x().set_value((mainwin.mapstorage).coords[active_node].x +
    168168              radius);
    169           coord_text->property_y().set_value(mapstorage.coords[active_node].y -
     169          coord_text->property_y().set_value((mainwin.mapstorage).coords[active_node].y -
    170170              radius);
    171171        }
     
    174174          coord_text = new Gnome::Canvas::Text(
    175175              displayed_graph,
    176               mapstorage.coords[active_node].x + radius,
    177               mapstorage.coords[active_node].y - radius,
     176              (mainwin.mapstorage).coords[active_node].x + radius,
     177              (mainwin.mapstorage).coords[active_node].y - radius,
    178178              ostr.str());
    179179          coord_text->property_fill_color().set_value("black");
     
    182182
    183183        //all the edges connected to the moved point has to be redrawn
    184         for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
     184        for(OutEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei)
    185185        {
    186186            Gnome::Canvas::Points coos;
    187187            double x1, x2, y1, y2;
    188188
    189             nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
     189            nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    190190            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    191191
    192             nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
     192            nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    193193            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    194194
     
    209209        }
    210210
    211         for(InEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
     211        for(InEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei)
    212212        {
    213213            Gnome::Canvas::Points coos;
    214214            double x1, x2, y1, y2;
    215215
    216             nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
     216            nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    217217            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    218218
    219             nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
     219            nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    220220            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    221221
     
    257257
    258258    case GDK_BUTTON_RELEASE:
    259       mapstorage.modified = true;
     259      (mainwin.mapstorage).modified = true;
    260260
    261261      isbutton=1;
    262262
    263       active_node=mapstorage.graph.addNode();
     263      active_node=(mainwin.mapstorage).graph.addNode();
    264264
    265265      //initiating values corresponding to new node in maps
     
    268268
    269269      // update coordinates
    270       mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
     270      (mainwin.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y));
    271271
    272272      // update all other maps
    273273      for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    274           mapstorage.nodemap_storage.begin(); it !=
    275           mapstorage.nodemap_storage.end(); ++it)
     274          (mainwin.mapstorage).nodemap_storage.begin(); it !=
     275          (mainwin.mapstorage).nodemap_storage.end(); ++it)
    276276      {
    277277        if ((it->first != "coordinates_x") &&
     
    279279        {
    280280          (*(it->second))[active_node] =
    281             mapstorage.nodemap_default[it->first];
     281            (mainwin.mapstorage).nodemap_default[it->first];
    282282        }
    283283      }
    284284      // increment the id map's default value
    285       mapstorage.nodemap_default["id"] += 1.0;
     285      (mainwin.mapstorage).nodemap_default["id"] += 1.0;
    286286
    287287      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
     
    302302      nodetextmap[active_node]->raise_to_top();
    303303
    304       mapwin.updateNode(active_node);
     304//       mapwin.updateNode(active_node);
     305      propertyUpdate(active_node);
    305306
    306307      isbutton=0;
     
    332333          active_item=(get_item_at(clicked_x, clicked_y));
    333334          active_node=INVALID;
    334           for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     335          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    335336          {
    336337            if(nodesmap[i]==active_item)
     
    361362          target_item=(get_item_at(clicked_x, clicked_y));
    362363          Node target_node=INVALID;
    363           for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     364          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    364365          {
    365366            if(nodesmap[i]==target_item)
     
    373374            if(target_node!=active_node)               
    374375            {
    375               mapstorage.modified = true;
     376              (mainwin.mapstorage).modified = true;
    376377
    377378              *(nodesmap[target_node]) <<
     
    379380
    380381              //creating new edge
    381               active_edge=mapstorage.graph.addEdge(active_node,
     382              active_edge=(mainwin.mapstorage).graph.addEdge(active_node,
    382383                  target_node);
    383384
     
    385386              for (std::map<std::string,
    386387                  Graph::EdgeMap<double>*>::const_iterator it =
    387                   mapstorage.edgemap_storage.begin(); it !=
    388                   mapstorage.edgemap_storage.end(); ++it)
     388                  (mainwin.mapstorage).edgemap_storage.begin(); it !=
     389                  (mainwin.mapstorage).edgemap_storage.end(); ++it)
    389390              {
    390391                (*(it->second))[active_edge] =
    391                   mapstorage.edgemap_default[it->first];
     392                  (mainwin.mapstorage).edgemap_default[it->first];
    392393              }
    393394              // increment the id map's default value
    394               mapstorage.edgemap_default["id"] += 1.0;
     395              (mainwin.mapstorage).edgemap_default["id"] += 1.0;
    395396
    396397              //calculating coordinates of new edge
     
    424425
    425426              //updating its properties
    426               mapwin.updateEdge(active_edge);
     427//               mapwin.updateEdge(active_edge);
     428              propertyUpdate(active_edge);
    427429            }
    428430            else
     
    479481      active_edge=INVALID;
    480482      //was it a node?
    481       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     483      for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    482484        {
    483485          if(nodesmap[i]==active_item)
     
    489491      if(active_node==INVALID)
    490492        {
    491           for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     493          for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    492494            {
    493495              if(edgesmap[i]==active_item)
     
    515517              if(active_node!=INVALID)
    516518                {
    517                   mapstorage.modified = true;
     519                  (mainwin.mapstorage).modified = true;
    518520
    519521                  std::set<Graph::Edge> edges_to_delete;
    520522
    521                   for(OutEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
     523                  for(OutEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e)
    522524                    {
    523525                      edges_to_delete.insert(e);
    524526                    }
    525527                 
    526                   for(InEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
     528                  for(InEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e)
    527529                    {
    528530                      edges_to_delete.insert(e);
     
    588590
    589591          //find the activated item between texts
    590           for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     592          for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    591593          {
    592594            //at the same time only one can be active
     
    600602          if(clicked_edge==INVALID)
    601603          {
    602             for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     604            for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    603605            {
    604606              //at the same time only one can be active
     
    623625
    624626              //create a dialog
    625               Gtk::Dialog dialog("Edit value", *parentwin, true);
     627              Gtk::Dialog dialog("Edit value", mainwin, true);
    626628              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    627629              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     
    640642                case Gtk::RESPONSE_ACCEPT:
    641643                  double new_value = spin.get_value();
    642                   (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
     644                  (*(mainwin.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
    643645                    new_value;
    644646                  std::ostringstream ostr;
     
    647649                      ostr.str());
    648650                  //mapwin.updateEdge(active_edge);
    649                   mapwin.updateEdge(Edge(INVALID));
     651//                   mapwin.updateEdge(Edge(INVALID));
     652                  propertyUpdate(Edge(INVALID));
    650653              }
    651654            }
     
    675678
    676679          //find the activated item between texts
    677           for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     680          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    678681          {
    679682            //at the same time only one can be active
     
    687690          if(clicked_node==INVALID)
    688691          {
    689             for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     692            for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    690693            {
    691694              //at the same time only one can be active
     
    710713
    711714              //create a dialog
    712               Gtk::Dialog dialog("Edit value", *parentwin, true);
     715              Gtk::Dialog dialog("Edit value", mainwin, true);
    713716              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    714717              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     
    727730                case Gtk::RESPONSE_ACCEPT:
    728731                  double new_value = spin.get_value();
    729                   (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
     732                  (*(mainwin.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
    730733                    new_value;
    731734                  std::ostringstream ostr;
     
    734737                      ostr.str());
    735738                  //mapwin.updateNode(active_node);
    736                   mapwin.updateNode(Node(INVALID));
     739//                   mapwin.updateNode(Node(INVALID));
     740                  propertyUpdate(Node(INVALID));
    737741              }
    738742            }
     
    751755  delete(nodetextmap[node_to_delete]);
    752756  delete(nodesmap[node_to_delete]);
    753   mapstorage.graph.erase(node_to_delete);
     757  (mainwin.mapstorage).graph.erase(node_to_delete);
    754758}
    755759
     
    758762  delete(edgetextmap[edge_to_delete]);
    759763  delete(edgesmap[edge_to_delete]);
    760   mapstorage.graph.erase(edge_to_delete);
     764  (mainwin.mapstorage).graph.erase(edge_to_delete);
    761765}
    762766
     
    778782      else
    779783        {
    780           for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     784          for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    781785            {
    782786              if(edgesmap[i]==active_bre)
     
    804808{
    805809  //create the new map
    806   Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
     810  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mainwin.mapstorage).graph, default_value);
    807811
    808812  //if addition was not successful addEdgeMap returns one.
    809813  //cause can be that there is already a map named like the new one
    810   if(mapstorage.addEdgeMap(mapname,emptr, default_value))
     814  if((mainwin.mapstorage).addEdgeMap(mapname,emptr, default_value))
    811815    {
    812816      return 1;
     
    815819
    816820  //add it to the list of the displayable maps
    817   mapwin.registerNewEdgeMap(mapname);
     821  mainwin.registerNewEdgeMap(mapname);
    818822
    819823  //display it
     
    826830{
    827831  //create the new map
    828   Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
     832  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mainwin.mapstorage).graph,default_value);
    829833
    830834  //if addition was not successful addNodeMap returns one.
    831835  //cause can be that there is already a map named like the new one
    832   if(mapstorage.addNodeMap(mapname,emptr, default_value))
     836  if((mainwin.mapstorage).addNodeMap(mapname,emptr, default_value))
    833837    {
    834838      return 1;
     
    836840
    837841  //add it to the list of the displayable maps
    838   mapwin.registerNewNodeMap(mapname);
     842  mainwin.registerNewNodeMap(mapname);
    839843
    840844  //display it
Note: See TracChangeset for help on using the changeset viewer.