93 } |
93 } |
94 |
94 |
95 int GraphDisplayerCanvas::changeLineWidth (std::string mapname) |
95 int GraphDisplayerCanvas::changeLineWidth (std::string mapname) |
96 { |
96 { |
97 for (EdgeIt i(g); i!=INVALID; ++i) |
97 for (EdgeIt i(g); i!=INVALID; ++i) |
98 { |
98 { |
99 int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i]; |
99 int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i]; |
100 edgesmap[i]->property_width_pixels().set_value(w); |
100 if(w>=0) |
101 } |
101 { |
|
102 edgesmap[i]->property_width_pixels().set_value(w); |
|
103 } |
|
104 } |
102 return 0; |
105 return 0; |
103 }; |
106 }; |
104 |
107 |
105 int GraphDisplayerCanvas::changeColor (std::string mapname) |
108 int GraphDisplayerCanvas::changeColor (std::string mapname) |
106 { |
109 { |
139 //in that case empty string will be written, because |
142 //in that case empty string will be written, because |
140 //that is the deleter map |
143 //that is the deleter map |
141 //\todo isn't it a bit woodcutter? |
144 //\todo isn't it a bit woodcutter? |
142 |
145 |
143 for (EdgeIt i(g); i!=INVALID; ++i) |
146 for (EdgeIt i(g); i!=INVALID; ++i) |
144 { |
147 { |
145 if(mapname!="Text") |
148 if(mapname!="Text") |
146 { |
149 { |
147 double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
150 double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
148 int length=(int)(floor(log(number)/log(10)))+1; |
151 int length=1; |
149 int maxpos=(int)(pow(10,length-1)); |
152 //if number is smaller than one, length would be negative, or invalid |
150 int strl=length+1+RANGE; |
153 if(number>=1) |
151 char * str=new char[strl]; |
154 { |
152 str[length]='.'; |
155 length=(int)(floor(log(number)/log(10)))+1; |
153 str[strl]='\0'; |
156 } |
|
157 int maxpos=(int)(pow(10,length-1)); |
|
158 int strl=length+1+RANGE; |
|
159 char * str=new char[strl]; |
|
160 str[length]='.'; |
|
161 str[strl]='\0'; |
154 |
162 |
155 for(int j=0;j<strl;j++) |
163 for(int j=0;j<strl;j++) |
156 { |
164 { |
157 if(j!=length) |
165 if(j!=length) |
158 { |
166 { |
159 int digit=(int)(number/maxpos); |
167 int digit=(int)(number/maxpos); |
160 str[j]=(digit+'0'); |
168 str[j]=(digit+'0'); |
161 number-=digit*maxpos; |
169 number-=digit*maxpos; |
162 number*=10; |
170 number*=10; |
163 } |
171 } |
164 } |
172 } |
165 |
173 |
166 edgetextmap[i]->property_text().set_value(str); |
174 edgetextmap[i]->property_text().set_value(str); |
167 } |
175 } |
168 else |
176 else |
169 { |
177 { |
170 edgetextmap[i]->property_text().set_value(""); |
178 edgetextmap[i]->property_text().set_value(""); |
171 } |
179 } |
172 } |
180 } |
173 return 0; |
181 return 0; |
174 }; |
182 }; |
175 |
183 |
176 //Deprecated |
184 //Deprecated |
177 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) |
185 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) |
472 //draw the new node in red at the clicked place |
480 //draw the new node in red at the clicked place |
473 case GDK_BUTTON_PRESS: |
481 case GDK_BUTTON_PRESS: |
474 isbutton=1; |
482 isbutton=1; |
475 |
483 |
476 active_node=NodeIt(g,g.addNode()); |
484 active_node=NodeIt(g,g.addNode()); |
|
485 |
|
486 //initiating values corresponding to new node in maps |
|
487 |
477 |
488 |
478 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
489 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
479 |
490 |
480 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
491 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
481 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
492 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
514 bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e) |
525 bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e) |
515 { |
526 { |
516 switch(e->type) |
527 switch(e->type) |
517 { |
528 { |
518 case GDK_BUTTON_PRESS: |
529 case GDK_BUTTON_PRESS: |
519 //in edge creatino right button has special meaning |
530 //in edge creation right button has special meaning |
520 if(e->button.button!=3) |
531 if(e->button.button!=3) |
521 { |
532 { |
522 //there is not yet selected node |
533 //there is not yet selected node |
523 if(active_node==INVALID) |
534 if(active_node==INVALID) |
524 { |
535 { |
567 { |
578 { |
568 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); |
579 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); |
569 |
580 |
570 //creating new edge |
581 //creating new edge |
571 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
582 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
|
583 |
|
584 //initiating values corresponding to new edge in maps |
|
585 mapstorage.init_maps_for_edge(active_edge); |
572 |
586 |
573 //calculating coordinates of new edge |
587 //calculating coordinates of new edge |
574 Gnome::Canvas::Points coos; |
588 Gnome::Canvas::Points coos; |
575 double x1, x2, y1, y2; |
589 double x1, x2, y1, y2; |
576 |
590 |