ladanyi@53
|
1 |
#include "graph_displayer_canvas.h"
|
alpar@59
|
2 |
#include <cmath>
|
ladanyi@6
|
3 |
|
hegyi@96
|
4 |
GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
|
hegyi@94
|
5 |
nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
|
hegyi@94
|
6 |
nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
|
ladanyi@66
|
7 |
isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
|
hegyi@96
|
8 |
edgemap_to_edit(""), mytab(mainw)
|
ladanyi@6
|
9 |
{
|
ladanyi@53
|
10 |
//base event handler is move tool
|
ladanyi@53
|
11 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
ladanyi@53
|
12 |
actual_tool=MOVE;
|
hegyi@34
|
13 |
|
ladanyi@53
|
14 |
active_node=INVALID;
|
ladanyi@53
|
15 |
active_edge=INVALID;
|
ladanyi@53
|
16 |
forming_edge=INVALID;
|
ladanyi@53
|
17 |
}
|
hegyi@9
|
18 |
|
ladanyi@53
|
19 |
GraphDisplayerCanvas::~GraphDisplayerCanvas()
|
ladanyi@53
|
20 |
{
|
hegyi@96
|
21 |
for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
|
hegyi@94
|
22 |
{
|
hegyi@94
|
23 |
delete nodesmap[n];
|
hegyi@94
|
24 |
delete nodetextmap[n];
|
hegyi@94
|
25 |
}
|
hegyi@94
|
26 |
|
hegyi@96
|
27 |
for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
|
hegyi@94
|
28 |
{
|
hegyi@94
|
29 |
delete edgesmap[e];
|
hegyi@94
|
30 |
delete edgetextmap[e];
|
hegyi@94
|
31 |
}
|
hegyi@94
|
32 |
}
|
ladanyi@6
|
33 |
|
hegyi@94
|
34 |
void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop)
|
hegyi@94
|
35 |
{
|
hegyi@94
|
36 |
if(itisedge)
|
hegyi@94
|
37 |
{
|
hegyi@94
|
38 |
propertyUpdate(Edge(INVALID), prop);
|
hegyi@94
|
39 |
}
|
hegyi@94
|
40 |
else
|
hegyi@94
|
41 |
{
|
hegyi@94
|
42 |
propertyUpdate(Node(INVALID), prop);
|
hegyi@94
|
43 |
}
|
hegyi@94
|
44 |
}
|
hegyi@94
|
45 |
|
hegyi@94
|
46 |
void GraphDisplayerCanvas::propertyUpdate(Edge edge)
|
hegyi@94
|
47 |
{
|
hegyi@94
|
48 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@94
|
49 |
{
|
hegyi@94
|
50 |
propertyUpdate(edge, i);
|
hegyi@94
|
51 |
}
|
hegyi@94
|
52 |
}
|
hegyi@94
|
53 |
|
hegyi@94
|
54 |
void GraphDisplayerCanvas::propertyUpdate(Node node)
|
hegyi@94
|
55 |
{
|
hegyi@94
|
56 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@94
|
57 |
{
|
hegyi@94
|
58 |
propertyUpdate(node, i);
|
hegyi@94
|
59 |
}
|
hegyi@94
|
60 |
}
|
hegyi@94
|
61 |
|
hegyi@118
|
62 |
void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
|
hegyi@94
|
63 |
{
|
hegyi@118
|
64 |
//dummy=dummy;
|
hegyi@94
|
65 |
|
hegyi@96
|
66 |
std::string mapname=mytab.getActiveNodeMap(prop);
|
hegyi@94
|
67 |
|
hegyi@94
|
68 |
if(mapname!="")
|
hegyi@94
|
69 |
{
|
hegyi@96
|
70 |
if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
|
hegyi@94
|
71 |
{
|
hegyi@94
|
72 |
switch(prop)
|
hegyi@94
|
73 |
{
|
hegyi@94
|
74 |
case N_RADIUS:
|
hegyi@94
|
75 |
changeNodeRadius(mapname, node);
|
hegyi@94
|
76 |
break;
|
hegyi@94
|
77 |
case N_COLOR:
|
hegyi@94
|
78 |
changeNodeColor(mapname, node);
|
hegyi@94
|
79 |
break;
|
hegyi@94
|
80 |
case N_TEXT:
|
hegyi@94
|
81 |
changeNodeText(mapname, node);
|
hegyi@94
|
82 |
break;
|
hegyi@94
|
83 |
default:
|
hegyi@94
|
84 |
std::cerr<<"Error\n";
|
hegyi@94
|
85 |
}
|
hegyi@94
|
86 |
}
|
hegyi@94
|
87 |
}
|
hegyi@94
|
88 |
else //mapname==""
|
hegyi@94
|
89 |
{
|
hegyi@94
|
90 |
Node node=INVALID;
|
hegyi@94
|
91 |
switch(prop)
|
hegyi@94
|
92 |
{
|
hegyi@94
|
93 |
case N_RADIUS:
|
hegyi@94
|
94 |
resetNodeRadius(node);
|
hegyi@94
|
95 |
break;
|
hegyi@94
|
96 |
case N_COLOR:
|
hegyi@94
|
97 |
resetNodeColor(node);
|
hegyi@94
|
98 |
break;
|
hegyi@94
|
99 |
case N_TEXT:
|
hegyi@94
|
100 |
resetNodeText(node);
|
hegyi@94
|
101 |
break;
|
hegyi@94
|
102 |
default:
|
hegyi@94
|
103 |
std::cerr<<"Error\n";
|
hegyi@94
|
104 |
}
|
hegyi@94
|
105 |
}
|
hegyi@94
|
106 |
|
hegyi@94
|
107 |
}
|
hegyi@94
|
108 |
|
hegyi@118
|
109 |
void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
|
hegyi@94
|
110 |
{
|
hegyi@118
|
111 |
//dummy=dummy;
|
hegyi@94
|
112 |
|
hegyi@96
|
113 |
std::string mapname=mytab.getActiveEdgeMap(prop);
|
hegyi@94
|
114 |
|
hegyi@94
|
115 |
if(mapname!="")
|
hegyi@94
|
116 |
{
|
hegyi@96
|
117 |
if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
|
hegyi@94
|
118 |
{
|
hegyi@94
|
119 |
switch(prop)
|
hegyi@94
|
120 |
{
|
hegyi@94
|
121 |
case E_WIDTH:
|
hegyi@94
|
122 |
changeEdgeWidth(mapname, edge);
|
hegyi@94
|
123 |
break;
|
hegyi@94
|
124 |
case E_COLOR:
|
hegyi@94
|
125 |
changeEdgeColor(mapname, edge);
|
hegyi@94
|
126 |
break;
|
hegyi@94
|
127 |
case E_TEXT:
|
hegyi@94
|
128 |
changeEdgeText(mapname, edge);
|
hegyi@94
|
129 |
break;
|
hegyi@94
|
130 |
default:
|
hegyi@94
|
131 |
std::cerr<<"Error\n";
|
hegyi@94
|
132 |
}
|
hegyi@94
|
133 |
}
|
hegyi@94
|
134 |
}
|
hegyi@94
|
135 |
else //mapname==""
|
hegyi@94
|
136 |
{
|
hegyi@94
|
137 |
switch(prop)
|
hegyi@94
|
138 |
{
|
hegyi@94
|
139 |
case E_WIDTH:
|
hegyi@94
|
140 |
resetEdgeWidth(edge);
|
hegyi@94
|
141 |
break;
|
hegyi@94
|
142 |
case E_COLOR:
|
hegyi@94
|
143 |
resetEdgeColor(edge);
|
hegyi@94
|
144 |
break;
|
hegyi@94
|
145 |
case E_TEXT:
|
hegyi@94
|
146 |
resetEdgeText(edge);
|
hegyi@94
|
147 |
break;
|
hegyi@94
|
148 |
default:
|
hegyi@94
|
149 |
std::cerr<<"Error\n";
|
hegyi@94
|
150 |
}
|
hegyi@94
|
151 |
}
|
ladanyi@53
|
152 |
}
|
ladanyi@53
|
153 |
|
ladanyi@53
|
154 |
void GraphDisplayerCanvas::drawGraph()
|
ladanyi@53
|
155 |
{
|
ladanyi@6
|
156 |
//first edges are drawn, to hide joining with nodes later
|
ladanyi@6
|
157 |
|
hegyi@96
|
158 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
ladanyi@6
|
159 |
{
|
ladanyi@6
|
160 |
|
ladanyi@53
|
161 |
//drawing green lines, coordinates are from mapstorage.coords
|
ladanyi@6
|
162 |
|
ladanyi@6
|
163 |
Gnome::Canvas::Points coos;
|
ladanyi@53
|
164 |
coos.push_back(Gnome::Art::Point(
|
hegyi@96
|
165 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x,
|
hegyi@96
|
166 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y));
|
ladanyi@53
|
167 |
coos.push_back(Gnome::Art::Point(
|
hegyi@96
|
168 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
|
hegyi@96
|
169 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
|
ladanyi@6
|
170 |
|
ladanyi@98
|
171 |
edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
|
ladanyi@6
|
172 |
|
ladanyi@6
|
173 |
//initializing edge-text as well, to empty string
|
ladanyi@6
|
174 |
|
ladanyi@98
|
175 |
XY text_pos=mytab.mapstorage.arrow_pos[i];
|
ladanyi@98
|
176 |
text_pos+=(XY(10,10));
|
hegyi@25
|
177 |
|
hegyi@25
|
178 |
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@28
|
179 |
edgetextmap[i]->property_fill_color().set_value("darkgreen");
|
hegyi@149
|
180 |
edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
|
ladanyi@63
|
181 |
edgetextmap[i]->raise_to_top();
|
ladanyi@6
|
182 |
}
|
ladanyi@6
|
183 |
|
ladanyi@6
|
184 |
//afterwards nodes come to be drawn
|
ladanyi@6
|
185 |
|
hegyi@96
|
186 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
ladanyi@6
|
187 |
{
|
ladanyi@6
|
188 |
//drawing bule nodes, with black line around them
|
ladanyi@6
|
189 |
|
ladanyi@53
|
190 |
nodesmap[i]=new Gnome::Canvas::Ellipse(
|
ladanyi@53
|
191 |
displayed_graph,
|
hegyi@96
|
192 |
(mytab.mapstorage).coords[i].x-20,
|
hegyi@96
|
193 |
(mytab.mapstorage).coords[i].y-20,
|
hegyi@96
|
194 |
(mytab.mapstorage).coords[i].x+20,
|
hegyi@96
|
195 |
(mytab.mapstorage).coords[i].y+20);
|
ladanyi@6
|
196 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@6
|
197 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
ladanyi@63
|
198 |
nodesmap[i]->raise_to_top();
|
hegyi@28
|
199 |
|
hegyi@28
|
200 |
//initializing edge-text as well, to empty string
|
hegyi@28
|
201 |
|
hegyi@150
|
202 |
XY text_pos(
|
hegyi@96
|
203 |
((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
|
hegyi@96
|
204 |
((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
|
hegyi@28
|
205 |
|
ladanyi@53
|
206 |
nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@53
|
207 |
text_pos.x, text_pos.y, "");
|
hegyi@28
|
208 |
nodetextmap[i]->property_fill_color().set_value("darkblue");
|
hegyi@149
|
209 |
nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
|
ladanyi@63
|
210 |
nodetextmap[i]->raise_to_top();
|
ladanyi@6
|
211 |
}
|
ladanyi@6
|
212 |
|
ladanyi@6
|
213 |
updateScrollRegion();
|
ladanyi@6
|
214 |
}
|
ladanyi@6
|
215 |
|
ladanyi@53
|
216 |
void GraphDisplayerCanvas::clear()
|
ladanyi@6
|
217 |
{
|
ladanyi@53
|
218 |
active_node=INVALID;
|
ladanyi@53
|
219 |
active_edge=INVALID;
|
ladanyi@53
|
220 |
forming_edge=INVALID;
|
ladanyi@6
|
221 |
|
hegyi@96
|
222 |
for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
|
ladanyi@6
|
223 |
{
|
ladanyi@53
|
224 |
delete nodesmap[n];
|
ladanyi@53
|
225 |
delete nodetextmap[n];
|
ladanyi@6
|
226 |
}
|
ladanyi@6
|
227 |
|
hegyi@96
|
228 |
for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
|
ladanyi@53
|
229 |
{
|
ladanyi@53
|
230 |
delete edgesmap[e];
|
ladanyi@53
|
231 |
delete edgetextmap[e];
|
ladanyi@53
|
232 |
}
|
ladanyi@6
|
233 |
}
|