Skip to content
Snippets Groups Projects
Commit 565113a2 authored by Kien Le's avatar Kien Le
Browse files

Merge branch 'bug-#46-program_breaks_when_plotting_waveform_with_no_channel' into 'master'

Fix program breaking when plotting waveform or TPS with no channel chosen

Closes #46

See merge request !77
parents 6c5cf0ea 02b2e295
No related branches found
No related tags found
1 merge request!77Fix program breaking when plotting waveform or TPS with no channel chosen
Pipeline #2259 passed with stage
in 2 minutes and 43 seconds
...@@ -97,9 +97,9 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): ...@@ -97,9 +97,9 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.min_x = max(data_time[0], start_tm) self.min_x = max(data_time[0], start_tm)
self.max_x = min(data_time[1], end_tm) self.max_x = min(data_time[1], end_tm)
if self.axes: self.plotting_axes.fig.clear()
self.plotting_axes.fig.clear() self.draw()
self.draw()
self.date_mode = self.parent.date_format.upper() self.date_mode = self.parent.date_format.upper()
if waveform_data == {}: if waveform_data == {}:
title = "NO WAVEFORM DATA TO DISPLAY." title = "NO WAVEFORM DATA TO DISPLAY."
...@@ -112,17 +112,12 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): ...@@ -112,17 +112,12 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
if waveform_data == {}: if waveform_data == {}:
self.draw() self.draw()
self.clean_up('NO DATA')
return return
self.plotting_data1 = waveform_data self.plotting_data1 = waveform_data
self.min_x = max(data_time[0], start_tm) self.min_x = max(data_time[0], start_tm)
self.max_x = min(data_time[1], end_tm) self.max_x = min(data_time[1], end_tm)
self.plot_total = len(waveform_data)
self.plotting_bot = const.BOTTOM
self.plotting_bot_pixel = const.BOTTOM_PX
self.axes = []
self.rulers = []
self.zoom_marker1s = []
self.zoom_marker2s = []
self.each_day5_min_list = get_each_day_5_min_list(self.min_x, self.each_day5_min_list = get_each_day_5_min_list(self.min_x,
self.max_x) self.max_x)
for chan_id in self.plotting_data1: for chan_id in self.plotting_data1:
...@@ -168,16 +163,28 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): ...@@ -168,16 +163,28 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.axes.append(ax) self.axes.append(ax)
self.processed_channels.append(chan_id) self.processed_channels.append(chan_id)
if len(self.processed_channels) == len(self.channels): if len(self.processed_channels) == len(self.channels):
if chan_id == '': self.clean_up(chan_id)
stopped_msg = 'TPS plot stopped.'
display_tracking_info(self.tracking_box, stopped_msg)
else:
finished_msg = 'TPS plot finished.'
display_tracking_info(self.tracking_box, finished_msg)
self.done()
self.stopped.emit()
self.finished_lock.unlock() self.finished_lock.unlock()
def clean_up(self, chan_id):
"""
Clean up after all available waveform channels have been stopped or
plotted. The cleanup steps are as follows.
Display a finished message
Add finishing touches to the plot
Emit the stopped signal of the widget
"""
if chan_id == '':
msg = 'TPS plot stopped.'
else:
msg = 'TPS plot finished.'
if chan_id != 'NO DATA':
self.done()
display_tracking_info(self.tracking_box, msg)
self.stopped.emit()
def done(self): def done(self):
"""Add finishing touches to the plot and display it on the screen.""" """Add finishing touches to the plot and display it on the screen."""
self.set_legend() self.set_legend()
......
...@@ -8,6 +8,7 @@ from PySide2 import QtCore, QtWidgets ...@@ -8,6 +8,7 @@ from PySide2 import QtCore, QtWidgets
from sohstationviewer.view.plotting.waveform_processor import \ from sohstationviewer.view.plotting.waveform_processor import \
WaveformChannelProcessor WaveformChannelProcessor
from sohstationviewer.view.util.enums import LogType
from sohstationviewer.view.util.plot_func_names import plot_functions from sohstationviewer.view.util.plot_func_names import plot_functions
from sohstationviewer.view.plotting.plotting_widget import plotting_widget from sohstationviewer.view.plotting.plotting_widget import plotting_widget
...@@ -130,6 +131,8 @@ class WaveformWidget(plotting_widget.PlottingWidget): ...@@ -130,6 +131,8 @@ class WaveformWidget(plotting_widget.PlottingWidget):
waveform_data, mass_pos_data) waveform_data, mass_pos_data)
if not ret: if not ret:
self.draw() self.draw()
self.clean_up()
self.finished.emit()
return return
self.create_waveform_channel_processors() self.create_waveform_channel_processors()
self.process_channel() self.process_channel()
...@@ -228,23 +231,33 @@ class WaveformWidget(plotting_widget.PlottingWidget): ...@@ -228,23 +231,33 @@ class WaveformWidget(plotting_widget.PlottingWidget):
channel_processor = self.data_processors[0] channel_processor = self.data_processors[0]
self.thread_pool.start(channel_processor) self.thread_pool.start(channel_processor)
except IndexError: except IndexError:
self.plot_mass_pos_channels() self.clean_up()
if self.is_first_plotting:
self.done()
finished_msg = 'Waveform plot finished'
else:
super().set_lim()
self.draw()
finished_msg = 'Zooming in finished'
display_tracking_info(self.tracking_box, finished_msg, 'info')
self.is_working = False
self.is_first_plotting = False
except Exception as e: except Exception as e:
print(e) print(e)
def clean_up(self):
"""
Clean up after all available waveform channels have been plotted. The
cleanup steps are as follows.
Plot the mass position channels
Display a finish message
Reset all internal flags
"""
self.plot_mass_pos_channels()
if self.is_first_plotting:
self.done()
finished_msg = 'Waveform plot finished'
else:
super().set_lim()
self.draw()
finished_msg = 'Zooming in finished'
display_tracking_info(self.tracking_box, finished_msg, LogType.INFO)
self.is_working = False
self.is_first_plotting = False
def plot_single_channel(self, c_data, chan_id): def plot_single_channel(self, c_data, chan_id):
""" """
Plot the channel chan_id. Plot the channel chan_id.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment