COIN-OR::LEMON - Graph Library

Changeset 1594:0bd9e53c8b28 in lemon-0.x


Ignore:
Timestamp:
07/27/05 12:47:38 (14 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2098
Message:

Documentation was added to GUI.

Location:
gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas-event.cc

    r1592 r1594  
    425425    {
    426426    case GDK_BUTTON_PRESS:
     427      //finding the clicked items
    427428      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    428429      active_item=(get_item_at(clicked_x, clicked_y));
    429430      active_node=INVALID;
    430431      active_edge=INVALID;
     432
     433      //was it a node?
    431434      for (NodeIt i(g); i!=INVALID; ++i)
    432435        {
     
    436439            }
    437440        }
     441      //or was it an edge?
    438442      if(active_node==INVALID)
    439443        {
     
    446450            }
    447451        }
     452
     453      //recolor activated item
    448454      if(active_item)
    449455        {
     
    456462      if(active_item)
    457463        {
     464          //the cursor was not moved since pressing it
    458465          if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
    459466            {
     467              //a node was found
    460468              if(active_node!=INVALID)
    461469                {
     
    523531    {
    524532    case GDK_KEY_PRESS:
     533      //for Escape or Enter hide the displayed widget
    525534      {
    526535        nodeMapEditEventHandler(e);
     
    528537      }
    529538    case GDK_BUTTON_PRESS:
     539      //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    530540      {
     541        //find the activated item
    531542        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    532543        active_item=(get_item_at(clicked_x, clicked_y));
     544
     545        //determine, whether it was an edge
    533546        Graph::EdgeIt clicked_edge=INVALID;
    534547        for (EdgeIt i(g); i!=INVALID; ++i)
     
    539552              }
    540553          }
     554        //if it was really an edge...
    541555        if(clicked_edge!=INVALID)
    542556          {
    543             if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    544               {
    545                 active_edge=clicked_edge;
    546                 if(canvasentrywidget)
     557            //If there is already edited edge, it has to be saved first
     558            if(entrywidget.is_visible())
     559              {
     560                GdkEvent * generated=new GdkEvent();
     561                generated->type=GDK_KEY_PRESS;
     562                ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
     563                entryWidgetChangeHandler(generated);
     564              }
     565            //If the previous value could be saved, we can go further, otherwise not
     566            if(!entrywidget.is_visible())
     567              {
     568                //and there is activated map
     569                if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    547570                  {
    548                     delete(canvasentrywidget);
     571                    //activate the general variable for it
     572                    active_edge=clicked_edge;
     573                    //delete visible widget if there is
     574                    if(canvasentrywidget)
     575                      {
     576                        delete(canvasentrywidget);
     577                      }
     578
     579                    //initialize the entry
     580                    entrywidget.show();
     581
     582                    //fill in the correct value
     583                    entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
     584
     585                    //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
     586                    xy<double> entry_coos;
     587                    entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
     588                    entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
     589                    entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
     590                    entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
     591                    canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
     592                    canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
     593                    canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
    549594                  }
    550                 entrywidget.show();
    551                 entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
    552                 xy<double> entry_coos;
    553                 entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
    554                 entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
    555                 entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
    556                 entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
    557                 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
    558                 canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
    559                 canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
    560595              }
    561596          }
     597        //if it was not an edge...
    562598        else
    563599          {
     600            //In this case the click did not happen on an edge
     601            //if there is visible entry we save the value in it
     602            //we pretend like an Enter was presse din the Entry widget
    564603            GdkEvent * generated=new GdkEvent();
    565604            generated->type=GDK_KEY_PRESS;
     
    580619    {
    581620    case GDK_KEY_PRESS:
     621      //for Escape or Enter hide the displayed widget
    582622      {
    583623        switch(((GdkEventKey*)e)->keyval)
     
    597637      }
    598638    case GDK_BUTTON_PRESS:
     639      //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    599640      {
     641        //find the activated item
    600642        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    601643        active_item=(get_item_at(clicked_x, clicked_y));
     644
     645        //determine, whether it was a node
    602646        Graph::NodeIt clicked_node=INVALID;
    603647        for (NodeIt i(g); i!=INVALID; ++i)
     
    608652              }
    609653          }
     654
     655        //if it was really an edge...
    610656        if(clicked_node!=INVALID)
    611657          {
     
    621667            if(!entrywidget.is_visible())
    622668              {
    623 
     669                //and there is activated map
    624670                if(nodetextmap[clicked_node]->property_text().get_value()!="")
    625671                  {
     672                    //activate the general variable for it
    626673                    active_node=clicked_node;
     674                    //delete visible widget if there is
    627675                    if(canvasentrywidget)
    628676                      {
    629677                        delete(canvasentrywidget);
    630678                      }
     679
     680                    //initialize the entry
    631681                    entrywidget.show();
     682
     683                    //fill in the correct value
    632684                    entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
     685
     686                    //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
    633687                    xy<double> entry_coos;
    634688                    entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
     
    642696              }
    643697          }
     698        //if it was not an edge...
    644699        else
    645700          {
     701            //In this case the click did not happen on an edge
     702            //if there is visible entry we save the value in it
     703            //we pretend like an Enter was presse din the Entry widget
    646704            GdkEvent * generated=new GdkEvent();
    647705            generated->type=GDK_KEY_PRESS;
     
    671729            case GDK_Return:
    672730              {
     731                //these variables check whether the text in the entry is valid
    673732                bool valid_double=true;
    674733                int point_num=0;
     734
     735                //getting the value from the entry and converting it to double
    675736                Glib::ustring mapvalue_str = entrywidget.get_text();
    676737
     
    694755                double mapvalue_d=atof(mapvalue_ch);
    695756
    696 //              double double_map_fract_value=0;
    697 //              double double_map_value=0;
    698 //              int offset=0;
    699 //              int found_letter=0;
    700                 //converting text to double
    701 //              for(int i=0;i<(int)(mapvalue.length());i++)
    702 //                {
    703 //                  if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.'))
    704 //                    {
    705 //                      if(mapvalue[i]=='.')
    706 //                        {
    707 //                          //for calculating non-integer part of double we step backward from the end
    708 //                          //after each step the number will be divided by ten, and the new value will be added
    709 //                          //to step backward from the end until the point the actual character of the string is the following:
    710 //                          // mapvalue.length()-(i-position_of_point)
    711 //                          //if i was the number of the first character after the decimal point the selected character will be the last
    712 //                          //if i was the number of the last character, the selected character will be the first after the decimal point
    713 //                          offset=mapvalue.length()+i;
    714 //                        }
    715 //                      else
    716 //                        {
    717 //                          if(!offset)
    718 //                            {
    719 //                              double_map_value=10*double_map_value+mapvalue[i]-'0';
    720 //                            }
    721 //                          else
    722 //                            {
    723 //                              double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10;
    724 //                            }
    725 //                        }
    726 //                    }
    727 //                  else
    728 //                    {
    729 //                      found_letter++;
    730 //                      continue;
    731 //                    }
    732 //                }
    733 
     757                //if the text in the entry was correct
    734758                if((point_num<=1)&&(valid_double))
    735759                  {
     760                    //save the value to the correct place
    736761                    switch(actual_tool)
    737762                      {
     
    749774                    entrywidget.hide();
    750775                  }
     776                //the text in the entry was not correct for a double
    751777                else
    752778                  {
     
    827853void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
    828854{
     855  //create the new map
    829856  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
    830857  mapstorage.addEdgeMap(mapname,emptr);
     858
     859  //add it to the list of the displayable maps
    831860  mapwin->registerNewEdgeMap(mapname);
     861
     862  //display it
    832863  changeEdgeText(mapname);
    833864}
     
    835866void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
    836867{
     868  //create the new map
    837869  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
    838870  mapstorage.addNodeMap(mapname,emptr);
     871
     872  //add it to the list of the displayable maps
    839873  mapwin->registerNewNodeMap(mapname);
     874
     875  //display it
    840876  changeNodeText(mapname);
    841877}
  • gui/map_win.cc

    r1592 r1594  
    260260    e_combo_array[i].set_popdown_strings(listStrings);
    261261  }
     262  //setting text property for the new map
    262263  Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
    263264  entry->set_text((Glib::ustring)newmapname);
     
    273274    n_combo_array[i].set_popdown_strings(listStrings);
    274275  }
     276  //setting text property for the new map
    275277  Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry();
    276278  entry->set_text((Glib::ustring)newmapname);
Note: See TracChangeset for help on using the changeset viewer.