graph_displayer_canvas.cc
changeset 172 fc1e478697d3
parent 168 a5f82cbbc1e4
child 174 95872af46fc4
equal deleted inserted replaced
48:925ce5b0fcb2 49:eb37f0bf95a4
     5 GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
     5 GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
     6   nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
     6   nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
     7   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
     7   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
     8   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     8   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     9   edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
     9   edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
    10   iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), mytab(mainw)
    10   iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), is_drawn(false), mytab(mainw)
    11 {
    11 {
    12   //base event handler is move tool
    12   //base event handler is move tool
    13   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    13   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    14   actual_tool=MOVE;
    14   actual_tool=MOVE;
    15 
    15 
    61     }
    61     }
    62 }
    62 }
    63 
    63 
    64 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
    64 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
    65 {
    65 {
    66   //dummy=dummy;
       
    67 
       
    68   std::string mapname=mytab.getActiveNodeMap(prop);
    66   std::string mapname=mytab.getActiveNodeMap(prop);
    69 
    67 
    70   if(mapname!="")
    68   if(is_drawn)
    71     {
    69     {
    72       if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
    70       if(mapname!="")
    73 	{
    71 	{
       
    72 	  if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
       
    73 	    {
       
    74 	      switch(prop)
       
    75 		{
       
    76 		case N_RADIUS:
       
    77 		  changeNodeRadius(mapname, node);
       
    78 		  break;
       
    79 		case N_COLOR:
       
    80 		  changeNodeColor(mapname, node);
       
    81 		  break;
       
    82 		case N_TEXT:
       
    83 		  changeNodeText(mapname, node);
       
    84 		  break;
       
    85 		default:
       
    86 		  std::cerr<<"Error\n";
       
    87 		}
       
    88 	    }
       
    89 	}
       
    90       else //mapname==""
       
    91 	{
       
    92 	  Node node=INVALID;	
    74 	  switch(prop)
    93 	  switch(prop)
    75 	    {
    94 	    {
    76 	    case N_RADIUS:
    95 	    case N_RADIUS:
    77 	      changeNodeRadius(mapname, node);
    96 	      resetNodeRadius(node);
    78 	      break;
    97 	      break;
    79 	    case N_COLOR:
    98 	    case N_COLOR:
    80 	      changeNodeColor(mapname, node);
    99 	      resetNodeColor(node);
    81 	      break;
   100 	      break;
    82 	    case N_TEXT:
   101 	    case N_TEXT:
    83 	      changeNodeText(mapname, node);
   102 	      resetNodeText(node);
    84 	      break;
   103 	      break;
    85 	    default:
   104 	    default:
    86 	      std::cerr<<"Error\n";
   105 	      std::cerr<<"Error\n";
    87 	    }
   106 	    }
    88 	}
   107 	}
    89     }
   108     }
    90   else //mapname==""
       
    91     {
       
    92       Node node=INVALID;	
       
    93       switch(prop)
       
    94 	{
       
    95 	case N_RADIUS:
       
    96 	  resetNodeRadius(node);
       
    97 	  break;
       
    98 	case N_COLOR:
       
    99 	  resetNodeColor(node);
       
   100 	  break;
       
   101 	case N_TEXT:
       
   102 	  resetNodeText(node);
       
   103 	  break;
       
   104 	default:
       
   105 	  std::cerr<<"Error\n";
       
   106 	}
       
   107     }
       
   108 
       
   109 }
   109 }
   110 
   110 
   111 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
   111 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
   112 {
   112 {
   113   //dummy=dummy;
       
   114 
       
   115   std::string mapname=mytab.getActiveEdgeMap(prop);
   113   std::string mapname=mytab.getActiveEdgeMap(prop);
   116 
   114 
   117   if(mapname!="")
   115   if(is_drawn)
   118     {
   116     {
   119       if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
   117       if(mapname!="")
       
   118 	{
       
   119 	  if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
       
   120 	    {
       
   121 	      switch(prop)
       
   122 		{
       
   123 		case E_WIDTH:
       
   124 		  changeEdgeWidth(mapname, edge);
       
   125 		  break;
       
   126 		case E_COLOR:
       
   127 		  changeEdgeColor(mapname, edge);
       
   128 		  break;
       
   129 		case E_TEXT:
       
   130 		  changeEdgeText(mapname, edge);
       
   131 		  break;
       
   132 		default:
       
   133 		  std::cerr<<"Error\n";
       
   134 		}
       
   135 	    }
       
   136 	}
       
   137       else //mapname==""
   120 	{
   138 	{
   121 	  switch(prop)
   139 	  switch(prop)
   122 	    {
   140 	    {
   123 	    case E_WIDTH:
   141 	    case E_WIDTH:
   124 	      changeEdgeWidth(mapname, edge);
   142 	      resetEdgeWidth(edge);
   125 	      break;
   143 	      break;
   126 	    case E_COLOR:
   144 	    case E_COLOR:
   127 	      changeEdgeColor(mapname, edge);
   145 	      resetEdgeColor(edge);
   128 	      break;
   146 	      break;
   129 	    case E_TEXT:
   147 	    case E_TEXT:
   130 	      changeEdgeText(mapname, edge);
   148 	      resetEdgeText(edge);
   131 	      break;
   149 	      break;
   132 	    default:
   150 	    default:
   133 	      std::cerr<<"Error\n";
   151 	      std::cerr<<"Error\n";
   134 	    }
   152 	    }
   135 	}
       
   136     }
       
   137   else //mapname==""
       
   138     {
       
   139       switch(prop)
       
   140 	{
       
   141 	case E_WIDTH:
       
   142 	  resetEdgeWidth(edge);
       
   143 	  break;
       
   144 	case E_COLOR:
       
   145 	  resetEdgeColor(edge);
       
   146 	  break;
       
   147 	case E_TEXT:
       
   148 	  resetEdgeText(edge);
       
   149 	  break;
       
   150 	default:
       
   151 	  std::cerr<<"Error\n";
       
   152 	}
   153 	}
   153     }
   154     }
   154 }
   155 }
   155 
   156 
   156 void GraphDisplayerCanvas::drawGraph()
   157 void GraphDisplayerCanvas::drawGraph()
   205     nodetextmap[i]->property_fill_color().set_value("darkblue");
   206     nodetextmap[i]->property_fill_color().set_value("darkblue");
   206     nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
   207     nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
   207     nodetextmap[i]->raise_to_top();
   208     nodetextmap[i]->raise_to_top();
   208   }
   209   }
   209 
   210 
       
   211   is_drawn=true;
       
   212 
       
   213   //upon drawing graph
       
   214   //properties have to
       
   215   //be set in as well
       
   216   for(int i=0;i<NODE_PROPERTY_NUM;i++)
       
   217     {
       
   218       propertyUpdate(Node(INVALID), i);
       
   219     }
       
   220 
       
   221   for(int i=0;i<EDGE_PROPERTY_NUM;i++)
       
   222     {
       
   223       propertyUpdate(Edge(INVALID), i);
       
   224     }
       
   225 
   210   updateScrollRegion();
   226   updateScrollRegion();
   211 }
   227 }
   212 
   228 
   213 void GraphDisplayerCanvas::clear()
   229 void GraphDisplayerCanvas::clear()
   214 {
   230 {
   225   for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
   241   for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
   226   {
   242   {
   227     delete edgesmap[e];
   243     delete edgesmap[e];
   228     delete edgetextmap[e];
   244     delete edgetextmap[e];
   229   }
   245   }
       
   246 
       
   247   is_drawn=false;
   230 }
   248 }
   231 
   249 
   232 void GraphDisplayerCanvas::setView(bool autoscale_p, bool zoomtrack_p, double width_p, double radius_p)
   250 void GraphDisplayerCanvas::setView(bool autoscale_p, bool zoomtrack_p, double width_p, double radius_p)
   233 {
   251 {
   234   autoscale=autoscale_p;
   252   autoscale=autoscale_p;