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@151
|
160 |
if (mytab.mapstorage.graph.source(i) == mytab.mapstorage.graph.target(i))
|
ladanyi@151
|
161 |
{
|
ladanyi@151
|
162 |
edgesmap[i]=new LoopEdge(displayed_graph, i, *this);
|
ladanyi@151
|
163 |
}
|
ladanyi@151
|
164 |
else
|
ladanyi@151
|
165 |
{
|
ladanyi@151
|
166 |
edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
|
ladanyi@151
|
167 |
}
|
ladanyi@6
|
168 |
//initializing edge-text as well, to empty string
|
ladanyi@6
|
169 |
|
ladanyi@98
|
170 |
XY text_pos=mytab.mapstorage.arrow_pos[i];
|
ladanyi@98
|
171 |
text_pos+=(XY(10,10));
|
hegyi@25
|
172 |
|
hegyi@25
|
173 |
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@28
|
174 |
edgetextmap[i]->property_fill_color().set_value("darkgreen");
|
hegyi@149
|
175 |
edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
|
ladanyi@63
|
176 |
edgetextmap[i]->raise_to_top();
|
ladanyi@6
|
177 |
}
|
ladanyi@6
|
178 |
|
ladanyi@6
|
179 |
//afterwards nodes come to be drawn
|
ladanyi@6
|
180 |
|
hegyi@96
|
181 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
ladanyi@6
|
182 |
{
|
ladanyi@6
|
183 |
//drawing bule nodes, with black line around them
|
ladanyi@6
|
184 |
|
ladanyi@53
|
185 |
nodesmap[i]=new Gnome::Canvas::Ellipse(
|
ladanyi@53
|
186 |
displayed_graph,
|
hegyi@96
|
187 |
(mytab.mapstorage).coords[i].x-20,
|
hegyi@96
|
188 |
(mytab.mapstorage).coords[i].y-20,
|
hegyi@96
|
189 |
(mytab.mapstorage).coords[i].x+20,
|
hegyi@96
|
190 |
(mytab.mapstorage).coords[i].y+20);
|
ladanyi@6
|
191 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@6
|
192 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
ladanyi@63
|
193 |
nodesmap[i]->raise_to_top();
|
hegyi@28
|
194 |
|
hegyi@28
|
195 |
//initializing edge-text as well, to empty string
|
hegyi@28
|
196 |
|
hegyi@150
|
197 |
XY text_pos(
|
hegyi@96
|
198 |
((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
|
hegyi@96
|
199 |
((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
|
hegyi@28
|
200 |
|
ladanyi@53
|
201 |
nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@53
|
202 |
text_pos.x, text_pos.y, "");
|
hegyi@28
|
203 |
nodetextmap[i]->property_fill_color().set_value("darkblue");
|
hegyi@149
|
204 |
nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
|
ladanyi@63
|
205 |
nodetextmap[i]->raise_to_top();
|
ladanyi@6
|
206 |
}
|
ladanyi@6
|
207 |
|
ladanyi@6
|
208 |
updateScrollRegion();
|
ladanyi@6
|
209 |
}
|
ladanyi@6
|
210 |
|
ladanyi@53
|
211 |
void GraphDisplayerCanvas::clear()
|
ladanyi@6
|
212 |
{
|
ladanyi@53
|
213 |
active_node=INVALID;
|
ladanyi@53
|
214 |
active_edge=INVALID;
|
ladanyi@53
|
215 |
forming_edge=INVALID;
|
ladanyi@6
|
216 |
|
hegyi@96
|
217 |
for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
|
ladanyi@6
|
218 |
{
|
ladanyi@53
|
219 |
delete nodesmap[n];
|
ladanyi@53
|
220 |
delete nodetextmap[n];
|
ladanyi@6
|
221 |
}
|
ladanyi@6
|
222 |
|
hegyi@96
|
223 |
for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
|
ladanyi@53
|
224 |
{
|
ladanyi@53
|
225 |
delete edgesmap[e];
|
ladanyi@53
|
226 |
delete edgetextmap[e];
|
ladanyi@53
|
227 |
}
|
ladanyi@6
|
228 |
}
|