An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authoredcb41520a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# PlotAC.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import logging
from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
logger = logging.getLogger()
class PlotAC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, data=None, toolbar=None,
parent=None):
super(PlotAC, self).__init__(
canvas=canvas,
trad=trad,
data=data,
toolbar=toolbar,
parent=parent
)
self._isometric_axis = False
self._auto_relim_update = True
self._autoscale_update = True
self.label_x = self._trad["transverse_abscissa"]
self.label_y = self._trad["unit_height"]
self.label_previous_plot_selected = self._trad["prev_cs"]
self.label_plot_selected = self._trad["cs"]
self.label_next_plot_selected = self._trad["next_cs"]
self.previous_plot_selected = None
self.plot_selected = None
self.next_plot_selected = None
@timer
def draw(self):
self.init_axes()
if self.data.number_profiles == 0:
return
np = len(self.data.profiles)
if np < 2:
return
self.draw_current()
self.draw_gl()
self.canvas.axes.legend(fancybox=True, shadow=True, fontsize=8)
self.idle()
self._init = True
def draw_current(self):
profile_id = 0
profile = self.data.profile(profile_id)
station = profile.get_station()
elevation = profile.z()
gl = profile.names()
self.previous_plot_selected, = self.canvas.axes.plot(
[], [],
label=self.label_previous_plot_selected,
lw=1.5, linestyle='--', color=self.color_plot_previous
)
self.plot_selected, = self.canvas.axes.plot(
station, elevation,
label=self.label_plot_selected,
color=self.color_plot_current, lw=1.5
)
next_id = profile_id + 1
station_next = self.data.profile(next_id).get_station()
elevation_next = self.data.profile(next_id).z()
self.next_plot_selected, = self.canvas.axes.plot(
station_next, elevation_next,
label=self.label_next_plot_selected,
color=self.color_plot_next, lw=1.6, linestyle='--'
)
self.canvas.axes.set_visible(False)
def draw_gl(self):
if self._current_data_update:
profile_id = self._current_data
else:
profile_id = 0
profile = self.data.profile(profile_id)
if profile is None:
return
station = profile.get_station()
elevation = profile.z()
gl = profile.names()
self.annotation = []
self.complete_gl, self.incomplete_gl = self.data.compute_guidelines()
lcomplete = list(self.complete_gl)
lincomplete = list(self.incomplete_gl)
self.color_complete_gl = self.colors
self.color_incomplete_gl = 2 * ["grey"]
x_gl_complete = []
y_gl_complete = []
x_gl_incomplete = []
y_gl_incomplete = []
for i, txt in enumerate(gl):
if txt == "":
continue
if txt.strip() in self.complete_gl:
color = self.color_complete_gl[
lcomplete.index(txt) % len(self.color_complete_gl)
]
else:
color = self.color_incomplete_gl[
lincomplete.index(txt)
]
annotation = self.canvas.axes.annotate(
txt, (station[i], elevation[i]),
horizontalalignment='left',
verticalalignment='top',
annotation_clip=True,
fontsize=11, color=color
)
annotation.set_position((station[i] + 0., elevation[i] + 0.))
self.annotation.append(annotation)
if txt.strip() in self.complete_gl:
x_gl_complete.append(station[i])
y_gl_complete.append(elevation[i])
else:
x_gl_incomplete.append(station[i])
y_gl_incomplete.append(elevation[i])
@timer
def update(self):
if not self._init:
self.draw()
return
if self.data is None:
return
self.update_current()
self.update_gl()
self.update_idle()
def update_current(self):
if self._current_data_update:
profile_id = self._current_data
previous_id = profile_id - 1
next_id = profile_id + 1
self.previous_plot_selected.set_visible(False)
self.plot_selected.set_visible(False)
self.next_plot_selected.set_visible(False)
self.previous_plot_selected.set_data([], [])
self.plot_selected.set_data([], [])
self.next_plot_selected.set_data([], [])
if 0 <= previous_id < self.data.number_profiles:
self.previous_plot_selected.set_data(
self.data.profile(previous_id).get_station(),
self.data.profile(previous_id).z()
)
self.previous_plot_selected.set_visible(True)
if 0 <= profile_id < self.data.number_profiles:
self.plot_selected.set_data(
self.data.profile(profile_id).get_station(),
self.data.profile(profile_id).z()
)
self.plot_selected.set_visible(True)
if 0 <= next_id < self.data.number_profiles:
self.next_plot_selected.set_data(
self.data.profile(next_id).get_station(),
self.data.profile(next_id).z()
)
self.next_plot_selected.set_visible(True)
self.canvas.axes.set_visible(True)
def update_full(self):
self.draw()
def update_gl(self):
for a in self.annotation:
a.remove()
self.annotation[:] = []
self.draw_gl()