graph_displayer_canvas-event.cc
branchgui
changeset 49 e112465192dc
parent 47 9a0e6e92d06c
child 53 e73d7540bd24
equal deleted inserted replaced
15:d4d50bc26fb6 16:5010eb6a9836
   214   switch(e->type)
   214   switch(e->type)
   215     {
   215     {
   216 
   216 
   217       //draw the new node in red at the clicked place
   217       //draw the new node in red at the clicked place
   218     case GDK_2BUTTON_PRESS:
   218     case GDK_2BUTTON_PRESS:
   219       std::cout << "double click" << std::endl;
   219       //std::cout << "double click" << std::endl;
   220       break;
   220       break;
   221     case GDK_BUTTON_PRESS:
   221     case GDK_BUTTON_PRESS:
   222       isbutton=1;
   222       isbutton=1;
   223 
   223 
   224       active_node=NodeIt(g,g.addNode());
   224       active_node=NodeIt(g,g.addNode());
   379 		      mapwin->updateEdge(active_edge);
   379 		      mapwin->updateEdge(active_edge);
   380 		    }
   380 		    }
   381 		  else
   381 		  else
   382 		    {
   382 		    {
   383 		      target_node=INVALID;
   383 		      target_node=INVALID;
   384 		      std::cout << "Loop edge is not yet implemented!" << std::endl;
   384 		      std::cerr << "Loop edge is not yet implemented!" << std::endl;
   385 		    }
   385 		    }
   386 		}
   386 		}
   387 	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
   387 	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
   388 	      else
   388 	      else
   389 		{
   389 		{
   525   return false;
   525   return false;
   526 }
   526 }
   527 
   527 
   528 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
   528 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
   529 {
   529 {
   530   switch(e->type)
   530   if(actual_tool==EDGE_MAP_EDIT)
   531     {
   531     {
   532     case GDK_KEY_PRESS:
   532       switch(e->type)
   533       //for Escape or Enter hide the displayed widget
   533 	{
   534       {
   534 	case GDK_KEY_PRESS:
   535 	nodeMapEditEventHandler(e);
   535 	  //for Escape or Enter hide the displayed widget
   536 	break;
       
   537       }
       
   538     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.
       
   540       {
       
   541 	//find the activated item
       
   542 	window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
       
   543 	active_item=(get_item_at(clicked_x, clicked_y));
       
   544 
       
   545 	//determine, whether it was an edge
       
   546 	Graph::EdgeIt clicked_edge=INVALID;
       
   547 	for (EdgeIt i(g); i!=INVALID; ++i)
       
   548 	  {
   536 	  {
   549 	    if(edgesmap[i]==active_item)
   537 	    nodeMapEditEventHandler(e);
   550 	      {
   538 	    break;
   551 		clicked_edge=i;
       
   552 	      }
       
   553 	  }
   539 	  }
   554 	//if it was really an edge...
   540 	case GDK_BUTTON_PRESS:
   555 	if(clicked_edge!=INVALID)
   541 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   556 	  {
   542 	  {
   557 	    //If there is already edited edge, it has to be saved first
   543 	    //for determine, whether it was an edge
   558 	    if(entrywidget.is_visible())
   544 	    Graph::EdgeIt clicked_edge=INVALID;
   559 	      {
   545 
       
   546 	    //find the activated item between texts
       
   547 	    active_item=(get_item_at(e->button.x, e->button.y));
       
   548 	    for (EdgeIt i(g); i!=INVALID; ++i)
       
   549 	      {
       
   550 		if(edgetextmap[i]==active_item)
       
   551 		  {
       
   552 		    clicked_edge=i;
       
   553 		  }
       
   554 	      }
       
   555 
       
   556 	    //if it was not between texts, search for it between edges
       
   557 	    if(clicked_edge==INVALID)
       
   558 	      {
       
   559 		window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
       
   560 		active_item=(get_item_at(clicked_x, clicked_y));
       
   561 
       
   562 		for (EdgeIt i(g); i!=INVALID; ++i)
       
   563 		  {
       
   564 		    //at the same time only one can be active
       
   565 		    if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
       
   566 		      {
       
   567 			clicked_edge=i;
       
   568 		      }
       
   569 		  }
       
   570 	      }
       
   571 	    //if it was really an edge...
       
   572 	    if(clicked_edge!=INVALID)
       
   573 	      {
       
   574 		//If there is already edited edge, it has to be saved first
       
   575 		if(entrywidget.is_visible())
       
   576 		  {
       
   577 		    GdkEvent * generated=new GdkEvent();
       
   578 		    generated->type=GDK_KEY_PRESS;
       
   579 		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
       
   580 		    entryWidgetChangeHandler(generated);
       
   581 		  }
       
   582 		//If the previous value could be saved, we can go further, otherwise not
       
   583 		if(!entrywidget.is_visible())
       
   584 		  {
       
   585 		    //and there is activated map
       
   586 		    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
       
   587 		      {
       
   588 			//activate the general variable for it
       
   589 			active_edge=clicked_edge;
       
   590 			//delete visible widget if there is
       
   591 			if(canvasentrywidget)
       
   592 			  {
       
   593 			    delete(canvasentrywidget);
       
   594 			  }
       
   595 
       
   596 			//initialize the entry
       
   597 			entrywidget.show();
       
   598 
       
   599 			//fill in the correct value
       
   600 			entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
       
   601 
       
   602 			//replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
       
   603 			xy<double> entry_coos;
       
   604 			entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
       
   605 			entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
       
   606 			entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
       
   607 			entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
       
   608 			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
       
   609 			canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
       
   610 			canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
       
   611 		      }
       
   612 		  }
       
   613 	      }
       
   614 	    //if it was not an edge...
       
   615 	    else
       
   616 	      {
       
   617 		//In this case the click did not happen on an edge
       
   618 		//if there is visible entry we save the value in it
       
   619 		//we pretend like an Enter was presse din the Entry widget
   560 		GdkEvent * generated=new GdkEvent();
   620 		GdkEvent * generated=new GdkEvent();
   561 		generated->type=GDK_KEY_PRESS;
   621 		generated->type=GDK_KEY_PRESS;
   562 		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   622 		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   563 		entryWidgetChangeHandler(generated);
   623 		entryWidgetChangeHandler(generated);
   564 	      }
   624 	      }
   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()!="")
       
   570 		  {
       
   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()*4);
       
   593 		    canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
       
   594 		  }
       
   595 	      }
       
   596 	  }
       
   597 	//if it was not an edge...
       
   598 	else
       
   599 	  {
       
   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
       
   603 	    GdkEvent * generated=new GdkEvent();
       
   604 	    generated->type=GDK_KEY_PRESS;
       
   605 	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
       
   606 	    entryWidgetChangeHandler(generated);
       
   607 	  }
       
   608 	break;
       
   609       }
       
   610     default:
       
   611       break;
       
   612     }
       
   613   return false;  
       
   614 }
       
   615 
       
   616 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
       
   617 {
       
   618   switch(e->type)
       
   619     {
       
   620     case GDK_KEY_PRESS:
       
   621       //for Escape or Enter hide the displayed widget
       
   622       {
       
   623 	switch(((GdkEventKey*)e)->keyval)
       
   624 	  {
       
   625 	  case GDK_Escape:
       
   626 	    entrywidget.hide();
       
   627 	    break;
       
   628 	  case GDK_Return:
       
   629 	  case GDK_KP_Enter:
       
   630 	    entrywidget.hide();
       
   631 	    break;
       
   632 	  default:
       
   633 	    break;
   625 	    break;
   634 	  }
   626 	  }
       
   627 	default:
       
   628 	  break;
       
   629 	}
       
   630     }
       
   631   return false;  
       
   632 }
       
   633 
       
   634 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
       
   635 {
       
   636   if(actual_tool==NODE_MAP_EDIT)
       
   637     {
       
   638       switch(e->type)
       
   639 	{
       
   640 	case GDK_KEY_PRESS:
       
   641 	  //for Escape or Enter hide the displayed widget
       
   642 	  {
       
   643 	    switch(((GdkEventKey*)e)->keyval)
       
   644 	      {
       
   645 	      case GDK_Escape:
       
   646 		entrywidget.hide();
       
   647 		break;
       
   648 	      case GDK_Return:
       
   649 	      case GDK_KP_Enter:
       
   650 		entrywidget.hide();
       
   651 		break;
       
   652 	      default:
       
   653 		break;
       
   654 	      }
   635   
   655   
   636 	break;
   656 	    break;
   637       }
   657 	  }
   638     case GDK_BUTTON_PRESS:
   658 	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.
   659 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   640       {
       
   641 	//find the activated item
       
   642 	window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
       
   643 	active_item=(get_item_at(clicked_x, clicked_y));
       
   644 
       
   645 	//determine, whether it was a node
       
   646 	Graph::NodeIt clicked_node=INVALID;
       
   647 	for (NodeIt i(g); i!=INVALID; ++i)
       
   648 	  {
   660 	  {
   649 	    if(nodesmap[i]==active_item)
   661 	    //for determine, whether it was a node
   650 	      {
   662 	    Graph::NodeIt clicked_node=INVALID;
   651 		clicked_node=i;
   663 
   652 	      }
   664 	    //find the activated item between texts
   653 	  }
   665 	    active_item=(get_item_at(e->button.x, e->button.y));
   654 
   666 	    for (NodeIt i(g); i!=INVALID; ++i)
   655 	//if it was really an edge...
   667 	      {
   656 	if(clicked_node!=INVALID)
   668 		//at the same time only one can be active
   657 	  {
   669 		if(nodetextmap[i]==active_item)
   658 	    //If there is already edited edge, it has to be saved first
   670 		  {
   659 	    if(entrywidget.is_visible())
   671 		    clicked_node=i;
   660 	      {
   672 		  }
       
   673 	      }
       
   674 
       
   675 	    //if there was not, search for it between nodes
       
   676 	    if(clicked_node==INVALID)
       
   677 	      {
       
   678 		window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
       
   679 		active_item=(get_item_at(clicked_x, clicked_y));
       
   680 
       
   681 		for (NodeIt i(g); i!=INVALID; ++i)
       
   682 		  {
       
   683 		    //at the same time only one can be active
       
   684 		    if(nodesmap[i]==active_item)
       
   685 		      {
       
   686 			clicked_node=i;
       
   687 		      }
       
   688 		  }
       
   689 	      }
       
   690 	    //if it was really an edge...
       
   691 	    if(clicked_node!=INVALID)
       
   692 	      {
       
   693 		//If there is already edited edge, it has to be saved first
       
   694 		if(entrywidget.is_visible())
       
   695 		  {
       
   696 		    GdkEvent * generated=new GdkEvent();
       
   697 		    generated->type=GDK_KEY_PRESS;
       
   698 		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
       
   699 		    entryWidgetChangeHandler(generated);
       
   700 		  }
       
   701 		//If the previous value could be saved, we can go further, otherwise not
       
   702 		if(!entrywidget.is_visible())
       
   703 		  {
       
   704 		    //and there is activated map
       
   705 		    if(nodetextmap[clicked_node]->property_text().get_value()!="")
       
   706 		      {
       
   707 			//activate the general variable for it
       
   708 			active_node=clicked_node;
       
   709 			//delete visible widget if there is
       
   710 			if(canvasentrywidget)
       
   711 			  {
       
   712 			    delete(canvasentrywidget);
       
   713 			  }
       
   714 
       
   715 			//initialize the entry
       
   716 			entrywidget.show();
       
   717 
       
   718 			//fill in the correct value
       
   719 			entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
       
   720 
       
   721 			//replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
       
   722 			xy<double> entry_coos;
       
   723 			entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
       
   724 			entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
       
   725 			entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
       
   726 			entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
       
   727 			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
       
   728 			canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
       
   729 			canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
       
   730 		      }
       
   731 		  }
       
   732 	      }
       
   733 	    //if it was not an edge...
       
   734 	    else
       
   735 	      {
       
   736 		//In this case the click did not happen on an edge
       
   737 		//if there is visible entry we save the value in it
       
   738 		//we pretend like an Enter was presse din the Entry widget
   661 		GdkEvent * generated=new GdkEvent();
   739 		GdkEvent * generated=new GdkEvent();
   662 		generated->type=GDK_KEY_PRESS;
   740 		generated->type=GDK_KEY_PRESS;
   663 		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   741 		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   664 		entryWidgetChangeHandler(generated);
   742 		entryWidgetChangeHandler(generated);
   665 	      }
   743 	      }
   666 	    //If the previous value could be saved, we can go further, otherwise not
   744 	    break;
   667 	    if(!entrywidget.is_visible())
       
   668 	      {
       
   669 		//and there is activated map
       
   670 		if(nodetextmap[clicked_node]->property_text().get_value()!="")
       
   671 		  {
       
   672 		    //activate the general variable for it
       
   673 		    active_node=clicked_node;
       
   674 		    //delete visible widget if there is
       
   675 		    if(canvasentrywidget)
       
   676 		      {
       
   677 			delete(canvasentrywidget);
       
   678 		      }
       
   679 
       
   680 		    //initialize the entry
       
   681 		    entrywidget.show();
       
   682 
       
   683 		    //fill in the correct value
       
   684 		    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
       
   687 		    xy<double> entry_coos;
       
   688 		    entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
       
   689 		    entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
       
   690 		    entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
       
   691 		    entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
       
   692 		    canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
       
   693 		    canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5);
       
   694 		    canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
       
   695 		  }
       
   696 	      }
       
   697 	  }
   745 	  }
   698 	//if it was not an edge...
   746 	default:
   699 	else
   747 	  break;
   700 	  {
   748 	}
   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
       
   704 	    GdkEvent * generated=new GdkEvent();
       
   705 	    generated->type=GDK_KEY_PRESS;
       
   706 	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
       
   707 	    entryWidgetChangeHandler(generated);
       
   708 	  }
       
   709 	break;
       
   710       }
       
   711     default:
       
   712       break;
       
   713     }
   749     }
   714   return false;  
   750   return false;  
   715 }
   751 }
   716 
   752 
   717 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
   753 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
   780 		    entrywidget.hide();
   816 		    entrywidget.hide();
   781 		  }
   817 		  }
   782 		//the text in the entry was not correct for a double
   818 		//the text in the entry was not correct for a double
   783 		else
   819 		else
   784 		  {
   820 		  {
   785 		    std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl;
   821 		    std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
   786 		  }
   822 		  }
   787 
   823 
   788 		break;
   824 		break;
   789 	      }
   825 	      }
   790 	    default:
   826 	    default:
   827 {
   863 {
   828   if(on)
   864   if(on)
   829     {
   865     {
   830       if(forming_edge!=INVALID)
   866       if(forming_edge!=INVALID)
   831 	{
   867 	{
   832 	  std::cout << "ERROR!!!! Valid edge found!" << std::endl;
   868 	  std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
   833 	}
   869 	}
   834       else
   870       else
   835 	{
   871 	{
   836 	  for (EdgeIt i(g); i!=INVALID; ++i)
   872 	  for (EdgeIt i(g); i!=INVALID; ++i)
   837 	    {
   873 	    {
   848 	{
   884 	{
   849 	  forming_edge=INVALID;
   885 	  forming_edge=INVALID;
   850 	}
   886 	}
   851       else
   887       else
   852 	{
   888 	{
   853 	  std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
   889 	  std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
   854 	}
   890 	}
   855     }
   891     }
   856 
   892 
   857 }
   893 }
   858 
   894