COIN-OR::LEMON - Graph Library

Changeset 28:fa28f1071bd6 in glemon-0.x


Ignore:
Timestamp:
06/24/05 20:16:12 (19 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@1996
Message:

NodeMap? values are now visualizable. Todo: default map-values

Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r27 r28  
    88        graph_displayer_canvas.cc \
    99        graph_displayer_canvas-edge.cc \
     10        graph_displayer_canvas-node.cc \
    1011        graph_displayer_canvas-event.cc \
    1112        graph_displayer_canvas-zoom.cc \
  • all_include.h

    r23 r28  
    1717#include <lemon/xy.h>
    1818
    19 enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties;
     19enum {E_WIDTH, E_COLOR, E_TEXT, EDGE_PROPERTY_NUM}; // edge properties;
     20enum {N_RADIUS, N_COLOR, N_TEXT, NODE_PROPERTY_NUM}; // node properties;
    2021enum {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, EDGE_MAP_EDIT, TOOL_NUM}; // tools;
    2122#define RANGE 3
     
    2526
    2627#ifndef MAIN_PART
    27 extern std::vector <std::string> property_strings;
    28 extern std::vector <double> property_defaults;
     28extern std::vector <std::string> edge_property_strings;
     29extern std::vector <double> edge_property_defaults;
     30extern std::vector <std::string> node_property_strings;
     31extern std::vector <double> node_property_defaults;
    2932#endif //MAIN_PART
    3033
  • graph-displayer.cc

    r24 r28  
    77#define MAIN_PART
    88
    9 std::vector <std::string> property_strings;
    10 std::vector <double> property_defaults;
     9std::vector <std::string> edge_property_strings;
     10std::vector <double> edge_property_defaults;
     11std::vector <std::string> node_property_strings;
     12std::vector <double> node_property_defaults;
    1113
    1214
     
    1618  //initializing
    1719
    18   property_strings.resize(PROPERTY_NUM);
    19   property_strings[WIDTH]="Width";
    20   property_strings[COLOR]="Color";
    21   property_strings[TEXT]="Text";
     20  edge_property_strings.resize(EDGE_PROPERTY_NUM);
     21  edge_property_strings[E_WIDTH]="Edge Width";
     22  edge_property_strings[E_COLOR]="Edge Color";
     23  edge_property_strings[E_TEXT]="Edge Text";
    2224
    23   property_defaults.resize(PROPERTY_NUM);
    24   property_defaults[WIDTH]=10.0;
    25   property_defaults[COLOR]=100;
    26   property_defaults[TEXT]=0;
     25  edge_property_defaults.resize(EDGE_PROPERTY_NUM);
     26  edge_property_defaults[E_WIDTH]=10.0;
     27  edge_property_defaults[E_COLOR]=100;
     28  edge_property_defaults[E_TEXT]=0;
     29
     30  node_property_strings.resize(NODE_PROPERTY_NUM);
     31  node_property_strings[N_RADIUS]="Node Radius";
     32  node_property_strings[N_COLOR]="Node Color";
     33  node_property_strings[N_TEXT]="Node Text";
     34
     35  node_property_defaults.resize(NODE_PROPERTY_NUM);
     36  node_property_defaults[N_RADIUS]=20.0;
     37  node_property_defaults[N_COLOR]=100;
     38  node_property_defaults[N_TEXT]=0;
    2739
    2840  if(argc<2)
  • graph_displayer_canvas-edge.cc

    r27 r28  
    44
    55
    6 int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
     6int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
    77{
    8   for (EdgeIt i(g); i!=INVALID; ++i)
     8  if(edge==INVALID)
    99    {
    10       int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
     10      for (EdgeIt i(g); i!=INVALID; ++i)
     11        {
     12          int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
     13          if(w>=0)
     14            {
     15              edgesmap[i]->property_width_pixels().set_value(w);
     16            }
     17        }
     18    }
     19  else
     20    {
     21      int w=(int)(*(mapstorage.edgemap_storage)[mapname])[edge];
    1122      if(w>=0)
    1223        {
    13           edgesmap[i]->property_width_pixels().set_value(w);
     24          edgesmap[edge]->property_width_pixels().set_value(w);
    1425        }
    1526    }
     
    1728};
    1829
    19 int GraphDisplayerCanvas::changeColor (std::string mapname)
     30int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
    2031
    2132
     
    2334  //the minimum of the nodemap to the range of
    2435  //green in RGB
     36  if(edge==INVALID)
     37    {
    2538
    26   for (EdgeIt i(g); i!=INVALID; ++i)
    27   {
    28     double w=(*(mapstorage.edgemap_storage)[mapname])[i];
    29     double max=mapstorage.maxOfEdgeMap(mapname);
    30     double min=mapstorage.minOfEdgeMap(mapname);
     39      for (EdgeIt i(g); i!=INVALID; ++i)
     40        {
     41          double w=(*(mapstorage.edgemap_storage)[mapname])[i];
     42          double max=mapstorage.maxOfEdgeMap(mapname);
     43          double min=mapstorage.minOfEdgeMap(mapname);
    3144     
    32     //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    33     Gdk::Color color;
    34     if(max!=min)
     45          //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
     46          Gdk::Color color;
     47          if(max!=min)
     48            {
     49              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
     50            }
     51          else
     52            {
     53              color.set_rgb_p (0, 100, 0);
     54            }
     55
     56          edgesmap[i]->property_fill_color_gdk().set_value(color);
     57        }
     58    }
     59  else
    3560    {
    36       color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
     61      double w=(*(mapstorage.edgemap_storage)[mapname])[edge];
     62      double max=mapstorage.maxOfEdgeMap(mapname);
     63      double min=mapstorage.minOfEdgeMap(mapname);
     64     
     65      //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
     66      Gdk::Color color;
     67      if(max!=min)
     68        {
     69          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
     70        }
     71      else
     72        {
     73          color.set_rgb_p (0, 100, 0);
     74        }
     75
     76      edgesmap[edge]->property_fill_color_gdk().set_value(color);
    3777    }
    38     else
    39     {
    40       color.set_rgb_p (0, 100, 0);
    41     }
    42 
    43     edgesmap[i]->property_fill_color_gdk().set_value(color);
    44   }
    4578  return 0;
    4679};
    4780
    48 int GraphDisplayerCanvas::changeText (std::string mapname)
     81int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
    4982{
    5083
     
    5588  //\todo isn't it a bit woodcutter?
    5689
    57   for (EdgeIt i(g); i!=INVALID; ++i)
     90  if(edge==INVALID)
    5891    {
    59       if(mapname!="Text")
     92      for (EdgeIt i(g); i!=INVALID; ++i)
    6093        {
    61           double number=(*(mapstorage.edgemap_storage)[mapname])[i];
     94          if(mapname!=edge_property_strings[E_TEXT])
     95            {
     96              double number=(*(mapstorage.edgemap_storage)[mapname])[i];
     97              int length=1;
     98              //if number is smaller than one, length would be negative, or invalid
     99              if(number>=1)
     100                {
     101                  length=(int)(floor(log(number)/log(10)))+1;
     102                }
     103              int maxpos=(int)(pow(10,length-1));
     104              int strl=length+1+RANGE;
     105              char * str=new char[strl];
     106              str[length]='.';
     107              str[strl]='\0';
     108     
     109              for(int j=0;j<strl;j++)
     110                {
     111                  if(j!=length)
     112                    {
     113                      int digit=(int)(number/maxpos);
     114                      str[j]=(digit+'0');
     115                      number-=digit*maxpos;
     116                      number*=10;
     117                    }
     118                }
     119     
     120              edgetextmap[i]->property_text().set_value(str);
     121            }
     122          else
     123            {
     124              edgetextmap[i]->property_text().set_value("");
     125            }
     126        }
     127
     128    }
     129  else
     130    {
     131      if(mapname!=edge_property_strings[E_TEXT])
     132        {
     133          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
    62134          int length=1;
    63135          //if number is smaller than one, length would be negative, or invalid
     
    83155            }
    84156     
    85           edgetextmap[i]->property_text().set_value(str);
     157          edgetextmap[edge]->property_text().set_value(str);
    86158        }
    87159      else
    88160        {
    89           edgetextmap[i]->property_text().set_value("");
     161          edgetextmap[edge]->property_text().set_value("");
    90162        }
     163         
    91164    }
     165
    92166  return 0;
     167
    93168};
  • graph_displayer_canvas-event.cc

    r27 r28  
    100100        double dy=e->motion.y-clicked_y;
    101101
     102        //repositioning node and its text
    102103        active_item->move(dx, dy);
     104        nodetextmap[active_node]->move(dx, dy);
    103105
    104106        clicked_x=e->motion.x;
     
    130132              }
    131133
     134            //reposition of edgetext
    132135            xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
    133136            text_pos+=(xy<double>(10,10));
     
    190193      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
    191194      (nodesmap[active_node])->show();
     195
     196      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, "");
     197      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
     198
     199      mapwin->update_node(active_node);
     200
    192201      break;
    193202
     
    273282              if(target_node!=INVALID)
    274283                {
    275                   *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
    276 
    277                   //creating new edge
    278                   active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
    279 
    280                   //initiating values corresponding to new edge in maps
    281                   mapstorage.init_maps_for_edge(active_edge);
     284                  if(target_node!=active_node)         
     285                    {
     286                      *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
     287
     288                      //creating new edge
     289                      active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
     290
     291                      //initiating values corresponding to new edge in maps
     292                      mapstorage.init_maps_for_edge(active_edge);
    282293         
    283                   //calculating coordinates of new edge
    284                   Gnome::Canvas::Points coos;
    285                   double x1, x2, y1, y2;
     294                      //calculating coordinates of new edge
     295                      Gnome::Canvas::Points coos;
     296                      double x1, x2, y1, y2;
    286297         
    287                   active_item->get_bounds(x1, y1, x2, y2);
    288                   coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    289 
    290                   target_item->get_bounds(x1, y1, x2, y2);
    291                   coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    292 
    293                   //drawing new edge
    294                   edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
    295                   *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
    296                   edgesmap[active_edge]->property_width_pixels().set_value(10);
    297 
    298                   //redraw nodes to blank terminations of the new edge
    299                   target_item->raise_to_top();
    300                   active_item->raise_to_top();
    301 
    302                   //initializing edge-text as well, to empty string
    303                   xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
    304                   text_pos+=(xy<double>(10,10));
    305 
    306                   edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    307                   edgetextmap[active_edge]->property_fill_color().set_value("black");
     298                      active_item->get_bounds(x1, y1, x2, y2);
     299                      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     300
     301                      target_item->get_bounds(x1, y1, x2, y2);
     302                      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     303
     304                      //drawing new edge
     305                      edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
     306                      *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
     307                      edgesmap[active_edge]->property_width_pixels().set_value(10);
     308
     309                      //redraw nodes to blank terminations of the new edge
     310                      target_item->raise_to_top();
     311                      active_item->raise_to_top();
     312
     313                      //initializing edge-text as well, to empty string
     314                      xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
     315                      text_pos+=(xy<double>(10,10));
     316
     317                      edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
     318                      edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
     319
     320                      //updating its properties
     321                      mapwin->update_edge(active_edge);
     322                    }
     323                  else
     324                    {
     325                      target_node=INVALID;
     326                      std::cout << "Loop edge is not yet implemented!" << std::endl;
     327                    }
    308328                }
    309329              //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
     
    436456void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete)
    437457{
     458  delete(nodetextmap[node_to_delete]);
    438459  delete(nodesmap[node_to_delete]);
    439460  g.erase(node_to_delete);
     
    442463void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete)
    443464{
     465  delete(edgetextmap[edge_to_delete]);
    444466  delete(edgesmap[edge_to_delete]);
    445467  g.erase(edge_to_delete);
     
    448470void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete)
    449471{
     472  delete(edgetextmap[edge_to_delete]);
    450473  delete(edgesmap[edge_to_delete]);
    451474  g.erase(edge_to_delete);
  • graph_displayer_canvas.cc

    r27 r28  
    33#include <math.h>
    44
    5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL)
     5GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),mapwin(mw)
    66{
    77 
     
    3535
    3636    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    37     edgetextmap[i]->property_fill_color().set_value("black");
     37    edgetextmap[i]->property_fill_color().set_value("darkgreen");
    3838  }
    3939
     
    5757    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    5858    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    59     //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
     59
     60    //initializing edge-text as well, to empty string
     61
     62    xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
     63
     64    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
     65    nodetextmap[i]->property_fill_color().set_value("darkblue");
    6066  }
    6167
  • graph_displayer_canvas.h

    r25 r28  
    77
    88#include <all_include.h>
     9#include <map_win.h>
    910#include <mapstorage.h>
    1011#include <broken_edge.h>
     
    1819
    1920public:
    20   GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
     21  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *);
    2122  virtual ~GraphDisplayerCanvas();
    2223
    2324  ///Changes the linewidth attribute according to the given map.
    2425  ///\param mapname is the name of the map which contains the new values
    25   int changeLineWidth (std::string mapname);
     26  int changeEdgeWidth (std::string mapname, Graph::Edge new_item=INVALID);
    2627
    2728  ///Changes the linecolor attribute according to the given map.
    2829  ///\param mapname is the name of the map which contains the new values
    29   int changeColor (std::string mapname);
     30  int changeEdgeColor (std::string mapname, Graph::Edge new_item=INVALID);
    3031
    3132  ///Changes the text of line attribute according to the given map.
    3233  ///\param mapname is the name of the map which contains the new values
    33   int changeText (std::string mapname);
     34  int changeEdgeText (std::string mapname, Graph::Edge new_item=INVALID);
     35
     36  ///Changes the linewidth attribute according to the given map.
     37  ///\param mapname is the name of the map which contains the new values
     38  int changeNodeRadius (std::string mapname, Graph::Node new_item=INVALID);
     39
     40  ///Changes the linecolor attribute according to the given map.
     41  ///\param mapname is the name of the map which contains the new values
     42  int changeNodeColor (std::string mapname, Graph::Node new_item=INVALID);
     43
     44  ///Changes the text of line attribute according to the given map.
     45  ///\param mapname is the name of the map which contains the new values
     46  int changeNodeText (std::string mapname, Graph::Node new_item=INVALID);
    3447
    3548  ///Callback for 'ViewZoomIn' action.
     
    108121  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
    109122
     123  ///Map of texts to write on nodes
     124  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
     125
    110126  ///Group of graphical elements of displayed_graph
    111127  Gnome::Canvas::Group displayed_graph;
     
    134150  static const int zoom_step = 5;
    135151
     152  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
     153  MapWin * mapwin;
     154
    136155};
    137156
  • main_win.cc

    r22 r28  
    22
    33MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
    4     MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
     4    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
    55{
    66  set_title (title);
  • map_win.cc

    r8 r28  
    1111}
    1212
    13 MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst),table(PROPERTY_NUM, 2, false)
     13MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
    1414{
    1515  set_title(title);
     
    1818  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::close_if_escape_is_pressed));
    1919
    20   combo_array=new Gtk::Combo [PROPERTY_NUM];
    21 
    22   for(int i=0;i<PROPERTY_NUM;i++)
     20  e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM];
     21
     22  table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false);
     23
     24  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    2325  {
    2426
     
    3638        actprop=j;
    3739      }
    38       //this is the other maps to show for this property
    39       for(int k=0;k<PROPERTY_NUM;k++)
     40      //these are the maps NOT to show for this property
     41      for(int k=0;k<EDGE_PROPERTY_NUM;k++)
    4042      {
    4143        if(emsi->second==&(ms.default_edgemaps[k]))
     
    4648      emsi++;
    4749    }
    48 
    49     //combo_array[i].set_group(group);
    5050
    5151    //filling in combo box with choices
     
    6565    }
    6666
    67     combo_array[i].set_popdown_strings(listStrings);
     67    e_combo_array[i].set_popdown_strings(listStrings);
    6868
    6969    //Restrict it to these choices only:
    70     combo_array[i].set_value_in_list();
    71 
    72     //binding signal to thew actual entry
    73     combo_array[i].get_entry()->signal_changed().connect
     70    e_combo_array[i].set_value_in_list();
     71
     72    //binding signal to the actual entry
     73    e_combo_array[i].get_entry()->signal_changed().connect
    7474    (
    7575     sigc::bind
    7676     (
    77       sigc::mem_fun(*this, &MapWin::combo_changed),
     77      sigc::mem_fun(*this, &MapWin::e_combo_changed),
    7878      i
    7979     )
     
    8383
    8484    label=new Gtk::Label;
    85     label->set_text(property_strings[i]);
    86 
    87     //    labelpluscombo=new Gtk::HBox;
    88     //    labelpluscombo->pack_start(*label);
    89     //    labelpluscombo->pack_start(combo_array[i]);
     85    label->set_text(edge_property_strings[i]);
    9086       
    91     table.attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    92     table.attach(combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    93 
    94     /*
    95     if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
    96     {
    97       vbox_r1.pack_start(*labelpluscombo);
    98     }
    99     else
    100     {
    101       vbox_r2.pack_start(*labelpluscombo);
    102     }
    103     actpos++;
    104     //*/
    105 
    106   }
    107 
    108   combos.pack_start(vbox_r1);
    109   combos.pack_start(vbox_r2);
    110 
    111   //add(combos);
    112   add(table);
     87    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     88    (*table).attach(e_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     89
     90
     91  }
     92
     93  vbox.pack_start(*(new Gtk::Label("Edge properties")));
     94
     95  vbox.pack_start(*table);
     96
     97  vbox.pack_start(*(new Gtk::HSeparator));
     98
     99  n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM];
     100
     101  table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false);
     102
     103  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     104  {
     105
     106    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
     107    std::set<int> props;
     108
     109    int actprop;
     110
     111    //here we find out, which map is the default in MapStorage for this property, which are not
     112    for(int j=0;j<ms.numOfNodeMaps();j++)
     113    {
     114      //these are the maps NOT to show for this property
     115      if(emsi->second==&(ms.default_nodemaps[i]))
     116      {
     117        actprop=j;
     118      }
     119      //this is the other maps to show for this property
     120      for(int k=0;k<NODE_PROPERTY_NUM;k++)
     121      {
     122        if(emsi->second==&(ms.default_nodemaps[k]))
     123        {
     124          props.insert(j);
     125        }
     126      }
     127      emsi++;
     128    }
     129
     130    //filling in combo box with choices
     131    std::list<Glib::ustring> listStrings;
     132
     133    listStrings.push_back("Default");
     134
     135    emsi=ms.beginOfNodeMaps();
     136
     137    for(int j=0;j<ms.numOfNodeMaps();j++)
     138    {
     139      if( ( props.find(j) )==( props.end() ) )
     140      {
     141        listStrings.push_back(emsi->first);
     142      }
     143      emsi++;
     144    }
     145
     146    n_combo_array[i].set_popdown_strings(listStrings);
     147
     148    //Restrict it to these choices only:
     149    n_combo_array[i].set_value_in_list();
     150
     151    //binding signal to thew actual entry
     152    n_combo_array[i].get_entry()->signal_changed().connect
     153    (
     154     sigc::bind
     155     (
     156      sigc::mem_fun(*this, &MapWin::n_combo_changed),
     157      i
     158     )
     159    );
     160
     161    //placing actual entry in the right place
     162
     163    label=new Gtk::Label;
     164    label->set_text(node_property_strings[i]);
     165       
     166    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     167    (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     168
     169
     170  }
     171
     172  add(vbox);
     173
     174  vbox.pack_start(*(new Gtk::Label("Node properties")));
     175
     176  vbox.pack_start(*table);
    113177
    114178  show_all_children();
     
    116180}
    117181
    118 void MapWin::combo_changed(int prop)
    119 {
    120 
    121   //most nem kommentezem fel, mert ugyis valtozik
    122   Gtk::Entry* entry = combo_array[prop].get_entry();
     182void MapWin::e_combo_changed(int prop)
     183{
     184  Gtk::Entry* entry = e_combo_array[prop].get_entry();
    123185
    124186  if(entry)
     
    129191      if(mapname=="Default")
    130192      {
    131         mapname=property_strings[prop];
     193        mapname=edge_property_strings[prop];
    132194      }
    133195
     
    136198        switch(prop)
    137199        {
    138           case WIDTH:
    139             gdc.changeLineWidth(mapname);
    140             break;
    141           case COLOR:
    142             gdc.changeColor(mapname);
    143             break;
    144           case TEXT:
    145             gdc.changeText(mapname);
     200          case E_WIDTH:
     201            gdc.changeEdgeWidth(mapname);
     202            break;
     203          case E_COLOR:
     204            gdc.changeEdgeColor(mapname);
     205            break;
     206          case E_TEXT:
     207            gdc.changeEdgeText(mapname);
    146208            break;
    147209          default:
     
    152214  }
    153215};
     216
     217void MapWin::n_combo_changed(int prop)
     218{
     219
     220  Gtk::Entry* entry = n_combo_array[prop].get_entry();
     221
     222  if(entry)
     223  {
     224    Glib::ustring mapname = entry->get_text();
     225    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
     226    {
     227      if(mapname=="Default")
     228      {
     229        mapname=node_property_strings[prop];
     230      }
     231
     232      if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
     233      {
     234        switch(prop)
     235        {
     236          case N_RADIUS:
     237            gdc.changeNodeRadius(mapname);
     238            break;
     239          case N_COLOR:
     240            gdc.changeNodeColor(mapname);
     241            break;
     242          case N_TEXT:
     243            gdc.changeNodeText(mapname);
     244            break;
     245          default:
     246            std::cout<<"Error\n";
     247        }
     248      }
     249    }
     250  }
     251};
     252
     253void MapWin::update_node(Graph::Node node)
     254{
     255  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     256    {
     257      Gtk::Entry* entry = n_combo_array[i].get_entry();
     258
     259      if(entry)
     260        {
     261          Glib::ustring mapname = entry->get_text();
     262          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
     263            {
     264              if(mapname=="Default")
     265                {
     266                  mapname=node_property_strings[i];
     267                }
     268
     269              if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
     270                {
     271                  switch(i)
     272                    {
     273                    case N_RADIUS:
     274                      //gdc.changeNodeRadius(mapname, node);
     275                      std::cout << "If default map-value problem is solved, uncomment line in MapWin::node_update!" << std::endl;
     276                      break;
     277                    case N_COLOR:
     278                      gdc.changeNodeColor(mapname, node);
     279                      break;
     280                    case N_TEXT:
     281                      gdc.changeNodeText(mapname, node);
     282                      break;
     283                    default:
     284                      std::cout<<"Error\n";
     285                    }
     286                }
     287            }
     288        }
     289    }
     290}
     291
     292void MapWin::update_edge(Graph::Edge edge)
     293{
     294  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     295    {
     296
     297      Gtk::Entry* entry = e_combo_array[i].get_entry();
     298
     299      if(entry)
     300        {
     301          Glib::ustring mapname = entry->get_text();
     302          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
     303            {
     304              if(mapname=="Default")
     305                {
     306                  mapname=edge_property_strings[i];
     307                }
     308
     309              if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
     310                {
     311                  switch(i)
     312                    {
     313                    case E_WIDTH:
     314                      //gdc.changeEdgeWidth(mapname, edge);
     315                      std::cout << "If default map-value problem is solved, uncomment line in MapWin::edge_update!" << std::endl;
     316                      break;
     317                    case E_COLOR:
     318                      gdc.changeEdgeColor(mapname, edge);
     319                      break;
     320                    case E_TEXT:
     321                      gdc.changeEdgeText(mapname, edge);
     322                      break;
     323                    default:
     324                      std::cout<<"Error\n";
     325                    }
     326                }
     327            }
     328        }
     329    }
     330}
  • map_win.h

    r8 r28  
    33#ifndef MAP_WIN_H
    44#define MAP_WIN_H
     5
     6class MapWin;
    57
    68#include <all_include.h>
     
    2527  MapStorage & ms;
    2628
    27   Gtk::Table table;
     29  Gtk::Table * table;
    2830 
    29   Gtk::HBox combos, * labelpluscombo;
    30   Gtk::Combo * combo_array;
    31 
    32   Gtk::VBox vbox_b, vbox_r1, vbox_r2;
     31  Gtk::Combo * e_combo_array, * n_combo_array;
    3332
    3433  Gtk::Label * label;
     34
     35  Gtk::VBox vbox;
    3536
    3637public:
     
    4243  ///appropriate function of the \ref GraphDisplayerCanvas
    4344  ///to change the visible values of that attribute.
    44   virtual void combo_changed(int);
     45  virtual void e_combo_changed(int);
     46  ///If a radiobutton is clicked, this function determines
     47  ///which button was that and after that calls the
     48  ///appropriate function of the \ref GraphDisplayerCanvas
     49  ///to change the visible values of that attribute.
     50  virtual void n_combo_changed(int);
     51
     52  ///This function is created to set the appropriate maps on the newly created node
     53  void update_node(Graph::Node);
     54
     55  ///This function is created to set the appropriate maps on the newly created edge
     56  void update_edge(Graph::Edge);
     57
    4558  virtual bool close_if_escape_is_pressed(GdkEventKey*);
    4659};
  • mapstorage.cc

    r26 r28  
    33MapStorage::MapStorage(Graph & graph):g(graph)
    44{
    5   for(int i=0;i<PROPERTY_NUM;i++)
     5  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    66  {
    7     Graph::EdgeMap<double> emd(g);
     7    Graph::EdgeMap<double> emd(g,edge_property_defaults[i]);
    88    default_edgemaps.push_back(emd);
    9     Graph::NodeMap<double> nmd(g);
     9  }
     10
     11  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     12  {
     13    Graph::NodeMap<double> nmd(g,node_property_defaults[i]);
    1014    default_nodemaps.push_back(nmd);
    1115  }
    12   for(int i=0;i<PROPERTY_NUM;i++)
     16
     17  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    1318  {
    1419      for (EdgeIt j(g); j!=INVALID; ++j)
    1520      {
    16         (default_edgemaps[i])[j]=property_defaults[i];
     21        (default_edgemaps[i])[j]=edge_property_defaults[i];
    1722      }
    18       addEdgeMap(property_strings[i],&(default_edgemaps[i]));
     23      addEdgeMap(edge_property_strings[i],&(default_edgemaps[i]));
     24  }
     25
     26  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     27  {
     28      for (NodeIt j(g); j!=INVALID; ++j)
     29      {
     30        (default_nodemaps[i])[j]=node_property_defaults[i];
     31      }
     32      addNodeMap(node_property_strings[i],&(default_nodemaps[i]));
    1933  }
    2034
     
    100114
    101115// g_closure_invoke...
    102 //   for(int i=0;i<PROPERTY_NUM;i++)
     116//   for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    103117//     {
    104118//       (default_edgemaps[i])[e]=property_defaults[i];
Note: See TracChangeset for help on using the changeset viewer.