Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@814: #based on the plcopen standard. Laurent@814: # Laurent@814: #Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD Laurent@814: # Laurent@814: #See COPYING file for copyrights details. Laurent@814: # Laurent@814: #This library is free software; you can redistribute it and/or Laurent@814: #modify it under the terms of the GNU General Public Laurent@814: #License as published by the Free Software Foundation; either Laurent@814: #version 2.1 of the License, or (at your option) any later version. Laurent@814: # Laurent@814: #This library is distributed in the hope that it will be useful, Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: #General Public License for more details. Laurent@814: # Laurent@814: #You should have received a copy of the GNU General Public Laurent@814: #License along with this library; if not, write to the Free Software Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@814: Laurent@916: from types import TupleType, ListType, FloatType Laurent@887: from time import time as gettime Laurent@902: import math Laurent@887: import numpy Laurent@814: Laurent@814: import wx Laurent@814: import wx.lib.buttons Laurent@888: Laurent@888: try: Laurent@888: import matplotlib Laurent@888: matplotlib.use('WX') Laurent@888: import matplotlib.pyplot Laurent@902: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas Laurent@925: from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap Laurent@925: from matplotlib.backends.backend_agg import FigureCanvasAgg Laurent@888: from mpl_toolkits.mplot3d import Axes3D Laurent@930: color_cycle = ['r', 'b', 'g', 'm', 'y', 'k'] Laurent@930: cursor_color = '#800080' Laurent@888: USE_MPL = True Laurent@888: except: Laurent@888: USE_MPL = False Laurent@887: Laurent@1176: from graphics.DebugDataConsumer import DebugDataConsumer Laurent@1176: from editors.DebugViewer import DebugViewer, REFRESH_PERIOD Laurent@814: from controls import CustomGrid, CustomTable Laurent@1193: from controls.DebugVariablePanel.DebugVariableItem import DebugVariableItem Laurent@814: from dialogs.ForceVariableDialog import ForceVariableDialog Laurent@814: from util.BitmapLibrary import GetBitmap Laurent@814: Laurent@814: def AppendMenu(parent, help, id, kind, text): Laurent@814: parent.Append(help=help, id=id, kind=kind, text=text) Laurent@814: Laurent@814: def GetDebugVariablesTableColnames(): Laurent@814: _ = lambda x : x Laurent@909: return [_("Variable"), _("Value")] Laurent@924: Laurent@814: class DebugVariableTable(CustomTable): Laurent@814: Laurent@814: def GetValue(self, row, col): Laurent@814: if row < self.GetNumberRows(): Laurent@814: return self.GetValueByName(row, self.GetColLabelValue(col, False)) Laurent@814: return "" Laurent@814: Laurent@814: def SetValue(self, row, col, value): Laurent@814: if col < len(self.colnames): Laurent@814: self.SetValueByName(row, self.GetColLabelValue(col, False), value) Laurent@814: Laurent@814: def GetValueByName(self, row, colname): Laurent@814: if row < self.GetNumberRows(): Laurent@814: if colname == "Variable": Laurent@814: return self.data[row].GetVariable() Laurent@814: elif colname == "Value": Laurent@814: return self.data[row].GetValue() Laurent@814: return "" Laurent@814: Laurent@814: def SetValueByName(self, row, colname, value): Laurent@814: if row < self.GetNumberRows(): Laurent@814: if colname == "Variable": Laurent@814: self.data[row].SetVariable(value) Laurent@814: elif colname == "Value": Laurent@814: self.data[row].SetValue(value) Laurent@814: Laurent@814: def IsForced(self, row): Laurent@814: if row < self.GetNumberRows(): Laurent@814: return self.data[row].IsForced() Laurent@814: return False Laurent@814: Laurent@887: def IsNumVariable(self, row): Laurent@887: if row < self.GetNumberRows(): Laurent@887: return self.data[row].IsNumVariable() Laurent@887: return False Laurent@887: Laurent@814: def _updateColAttrs(self, grid): Laurent@814: """ Laurent@814: wx.grid.Grid -> update the column attributes to add the Laurent@814: appropriate renderer given the column name. Laurent@814: Laurent@814: Otherwise default to the default renderer. Laurent@814: """ Laurent@814: Laurent@814: for row in range(self.GetNumberRows()): Laurent@814: for col in range(self.GetNumberCols()): Laurent@887: colname = self.GetColLabelValue(col, False) Laurent@909: if colname == "Value": Laurent@909: if self.IsForced(row): Laurent@909: grid.SetCellTextColour(row, col, wx.BLUE) Laurent@814: else: Laurent@909: grid.SetCellTextColour(row, col, wx.BLACK) Laurent@909: grid.SetReadOnly(row, col, True) Laurent@814: self.ResizeRow(grid, row) Laurent@814: Laurent@814: def AppendItem(self, data): Laurent@814: self.data.append(data) Laurent@814: Laurent@814: def InsertItem(self, idx, data): Laurent@814: self.data.insert(idx, data) Laurent@814: Laurent@814: def RemoveItem(self, idx): Laurent@814: self.data.pop(idx) Laurent@814: Laurent@814: def MoveItem(self, idx, new_idx): Laurent@814: self.data.insert(new_idx, self.data.pop(idx)) Laurent@814: Laurent@814: def GetItem(self, idx): Laurent@814: return self.data[idx] Laurent@814: Laurent@814: class DebugVariableDropTarget(wx.TextDropTarget): Laurent@814: Laurent@916: def __init__(self, parent, control=None): Laurent@814: wx.TextDropTarget.__init__(self) Laurent@814: self.ParentWindow = parent Laurent@909: self.ParentControl = control Laurent@814: Laurent@916: def __del__(self): Laurent@916: self.ParentWindow = None Laurent@916: self.ParentControl = None Laurent@916: Laurent@928: def OnDragOver(self, x, y, d): Laurent@1008: if not isinstance(self.ParentControl, CustomGrid): Laurent@1008: if self.ParentControl is not None: Laurent@1008: self.ParentControl.OnMouseDragging(x, y) Laurent@1008: else: Laurent@1008: self.ParentWindow.RefreshHighlight(x, y) Laurent@928: return wx.TextDropTarget.OnDragOver(self, x, y, d) Laurent@928: Laurent@814: def OnDropText(self, x, y, data): Laurent@814: message = None Laurent@814: try: Laurent@814: values = eval(data) Laurent@814: except: Laurent@814: message = _("Invalid value \"%s\" for debug variable")%data Laurent@814: values = None Laurent@814: if not isinstance(values, TupleType): Laurent@814: message = _("Invalid value \"%s\" for debug variable")%data Laurent@814: values = None Laurent@909: Laurent@814: if message is not None: Laurent@814: wx.CallAfter(self.ShowMessage, message) Laurent@909: elif values is not None and values[1] == "debug": Laurent@916: if isinstance(self.ParentControl, CustomGrid): Laurent@916: x, y = self.ParentControl.CalcUnscrolledPosition(x, y) Laurent@916: row = self.ParentControl.YToRow(y - self.ParentControl.GetColLabelSize()) Laurent@909: if row == wx.NOT_FOUND: Laurent@909: row = self.ParentWindow.Table.GetNumberRows() Laurent@909: self.ParentWindow.InsertValue(values[0], row, force=True) Laurent@916: elif self.ParentControl is not None: Laurent@943: width, height = self.ParentControl.GetSize() Laurent@916: target_idx = self.ParentControl.GetIndex() Laurent@909: merge_type = GRAPH_PARALLEL Laurent@945: if isinstance(self.ParentControl, DebugVariableGraphic): Laurent@945: if self.ParentControl.Is3DCanvas(): Laurent@945: if y > height / 2: Laurent@945: target_idx += 1 Laurent@945: if len(values) > 1 and values[2] == "move": Laurent@945: self.ParentWindow.MoveValue(values[0], target_idx) Laurent@945: else: Laurent@945: self.ParentWindow.InsertValue(values[0], target_idx, force=True) Laurent@945: Laurent@945: else: Laurent@945: rect = self.ParentControl.GetAxesBoundingBox() Laurent@945: if rect.InsideXY(x, y): Laurent@945: merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height) Laurent@945: if merge_rect.InsideXY(x, y): Laurent@945: merge_type = GRAPH_ORTHOGONAL Laurent@945: wx.CallAfter(self.ParentWindow.MergeGraphs, values[0], target_idx, merge_type, force=True) Laurent@945: else: Laurent@945: if y > height / 2: Laurent@945: target_idx += 1 Laurent@952: if len(values) > 2 and values[2] == "move": Laurent@945: self.ParentWindow.MoveValue(values[0], target_idx) Laurent@945: else: Laurent@945: self.ParentWindow.InsertValue(values[0], target_idx, force=True) Laurent@945: else: Laurent@919: if y > height / 2: Laurent@919: target_idx += 1 Laurent@952: if len(values) > 2 and values[2] == "move": Laurent@945: self.ParentWindow.MoveValue(values[0], target_idx) Laurent@916: else: Laurent@929: self.ParentWindow.InsertValue(values[0], target_idx, force=True) Laurent@945: Laurent@952: elif len(values) > 2 and values[2] == "move": Laurent@945: self.ParentWindow.MoveValue(values[0]) Laurent@945: else: Laurent@945: self.ParentWindow.InsertValue(values[0], force=True) Laurent@928: Laurent@928: def OnLeave(self): Laurent@1008: if not isinstance(self.ParentControl, CustomGrid): Laurent@1008: self.ParentWindow.ResetHighlight() Laurent@928: return wx.TextDropTarget.OnLeave(self) Laurent@934: Laurent@814: def ShowMessage(self, message): Laurent@814: dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) Laurent@814: dialog.ShowModal() Laurent@814: dialog.Destroy() Laurent@814: Laurent@916: if USE_MPL: Laurent@924: MILLISECOND = 1000000 Laurent@924: SECOND = 1000 * MILLISECOND Laurent@916: MINUTE = 60 * SECOND Laurent@916: HOUR = 60 * MINUTE Laurent@924: DAY = 24 * HOUR Laurent@916: Laurent@916: ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)]) Laurent@1191: RANGE_VALUES = \ Laurent@1191: [("%dms" % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \ Laurent@1191: [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \ Laurent@1191: [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \ Laurent@1191: [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)] Laurent@916: Laurent@916: GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2) Laurent@916: Laurent@916: SCROLLBAR_UNIT = 10 Laurent@916: Laurent@945: #CANVAS_HIGHLIGHT_TYPES Laurent@945: [HIGHLIGHT_NONE, Laurent@945: HIGHLIGHT_BEFORE, Laurent@945: HIGHLIGHT_AFTER, Laurent@945: HIGHLIGHT_LEFT, Laurent@945: HIGHLIGHT_RIGHT, Laurent@945: HIGHLIGHT_RESIZE] = range(6) Laurent@945: Laurent@945: HIGHLIGHT_DROP_PEN = wx.Pen(wx.Colour(0, 128, 255)) Laurent@945: HIGHLIGHT_DROP_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128)) Laurent@945: HIGHLIGHT_RESIZE_PEN = wx.Pen(wx.Colour(200, 200, 200)) Laurent@945: HIGHLIGHT_RESIZE_BRUSH = wx.Brush(wx.Colour(200, 200, 200)) Laurent@945: Laurent@945: #CANVAS_SIZE_TYPES Laurent@945: [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200] Laurent@945: Laurent@945: DEFAULT_CANVAS_HEIGHT = 200. Laurent@945: CANVAS_BORDER = (20., 10.) Laurent@945: CANVAS_PADDING = 8.5 Laurent@945: VALUE_LABEL_HEIGHT = 17. Laurent@945: AXES_LABEL_HEIGHT = 12.75 Laurent@945: Laurent@945: def compute_mask(x, y): Laurent@945: mask = [] Laurent@945: for xp, yp in zip(x, y): Laurent@945: if xp == yp: Laurent@945: mask.append(xp) Laurent@945: else: Laurent@945: mask.append("*") Laurent@945: return mask Laurent@945: Laurent@916: def NextTick(variables): Laurent@916: next_tick = None Laurent@924: for item, data in variables: Laurent@916: if len(data) > 0: Laurent@916: if next_tick is None: Laurent@916: next_tick = data[0][0] Laurent@916: else: Laurent@916: next_tick = min(next_tick, data[0][0]) Laurent@916: return next_tick Laurent@916: Laurent@916: def OrthogonalData(item, start_tick, end_tick): Laurent@916: data = item.GetData(start_tick, end_tick) Laurent@1193: min_value, max_value = item.GetValueRange() Laurent@916: if min_value is not None and max_value is not None: Laurent@916: center = (min_value + max_value) / 2. Laurent@916: range = max(1.0, max_value - min_value) Laurent@916: else: Laurent@916: center = 0.5 Laurent@916: range = 1.0 Laurent@916: return data, center - range * 0.55, center + range * 0.55 Laurent@916: Laurent@945: class GraphButton(): Laurent@945: Laurent@945: def __init__(self, x, y, bitmap, callback): Laurent@945: self.Position = wx.Point(x, y) Laurent@945: self.Bitmap = bitmap Laurent@945: self.Shown = True Laurent@945: self.Enabled = True Laurent@945: self.Callback = callback Laurent@945: Laurent@945: def __del__(self): Laurent@945: self.callback = None Laurent@945: Laurent@945: def GetSize(self): Laurent@945: return self.Bitmap.GetSize() Laurent@945: Laurent@945: def SetPosition(self, x, y): Laurent@945: self.Position = wx.Point(x, y) Laurent@945: Laurent@945: def Show(self): Laurent@945: self.Shown = True Laurent@945: Laurent@945: def Hide(self): Laurent@945: self.Shown = False Laurent@945: Laurent@945: def IsShown(self): Laurent@945: return self.Shown Laurent@945: Laurent@945: def Enable(self): Laurent@945: self.Enabled = True Laurent@945: Laurent@945: def Disable(self): Laurent@945: self.Enabled = False Laurent@945: Laurent@945: def IsEnabled(self): Laurent@945: return self.Enabled Laurent@945: Laurent@945: def HitTest(self, x, y): Laurent@945: if self.Shown and self.Enabled: Laurent@945: w, h = self.Bitmap.GetSize() Laurent@945: rect = wx.Rect(self.Position.x, self.Position.y, w, h) Laurent@945: if rect.InsideXY(x, y): Laurent@945: return True Laurent@945: return False Laurent@945: Laurent@945: def ProcessCallback(self): Laurent@945: if self.Callback is not None: Laurent@945: wx.CallAfter(self.Callback) Laurent@945: Laurent@945: def Draw(self, dc): Laurent@945: if self.Shown and self.Enabled: Laurent@945: dc.DrawBitmap(self.Bitmap, self.Position.x, self.Position.y, True) Laurent@945: Laurent@943: class DebugVariableViewer: Laurent@943: Laurent@943: def __init__(self, window, items=[]): Laurent@916: self.ParentWindow = window Laurent@916: self.Items = items Laurent@916: Laurent@943: self.Highlight = HIGHLIGHT_NONE Laurent@943: self.Buttons = [] Laurent@943: Laurent@916: def __del__(self): Laurent@916: self.ParentWindow = None Laurent@943: Laurent@916: def GetIndex(self): Laurent@916: return self.ParentWindow.GetViewerIndex(self) Laurent@916: Laurent@916: def GetItem(self, variable): Laurent@916: for item in self.Items: Laurent@916: if item.GetVariable() == variable: Laurent@916: return item Laurent@916: return None Laurent@916: Laurent@916: def GetItems(self): Laurent@916: return self.Items Laurent@916: Laurent@916: def GetVariables(self): Laurent@916: if len(self.Items) > 1: Laurent@916: variables = [item.GetVariable() for item in self.Items] Laurent@916: if self.GraphType == GRAPH_ORTHOGONAL: Laurent@916: return tuple(variables) Laurent@916: return variables Laurent@916: return self.Items[0].GetVariable() Laurent@916: Laurent@916: def AddItem(self, item): Laurent@916: self.Items.append(item) Laurent@928: Laurent@916: def RemoveItem(self, item): Laurent@916: if item in self.Items: Laurent@916: self.Items.remove(item) Laurent@916: Laurent@916: def Clear(self): Laurent@916: for item in self.Items: Laurent@916: self.ParentWindow.RemoveDataConsumer(item) Laurent@916: self.Items = [] Laurent@928: Laurent@916: def IsEmpty(self): Laurent@916: return len(self.Items) == 0 Laurent@916: Laurent@916: def UnregisterObsoleteData(self): Laurent@916: for item in self.Items[:]: Laurent@1102: iec_path = item.GetVariable() Laurent@916: if self.ParentWindow.GetDataType(iec_path) is None: Laurent@916: self.ParentWindow.RemoveDataConsumer(item) Laurent@916: self.RemoveItem(item) Laurent@916: else: Laurent@1102: self.ParentWindow.AddDataConsumer(iec_path.upper(), item) Laurent@916: item.RefreshVariableType() Laurent@928: Laurent@916: def ResetData(self): Laurent@916: for item in self.Items: Laurent@916: item.ResetData() Laurent@916: Laurent@943: def RefreshViewer(self): Laurent@916: pass Laurent@943: Laurent@943: def SetHighlight(self, highlight): Laurent@943: if self.Highlight != highlight: Laurent@943: self.Highlight = highlight Laurent@943: return True Laurent@943: return False Laurent@943: Laurent@943: def GetButtons(self): Laurent@943: return self.Buttons Laurent@943: Laurent@943: def HandleButtons(self, x, y): Laurent@943: for button in self.GetButtons(): Laurent@943: if button.HitTest(x, y): Laurent@943: button.ProcessCallback() Laurent@943: return True Laurent@943: return False Laurent@943: Laurent@943: def IsOverButton(self, x, y): Laurent@943: for button in self.GetButtons(): Laurent@943: if button.HitTest(x, y): Laurent@943: return True Laurent@943: return False Laurent@943: Laurent@943: def ShowButtons(self, show): Laurent@943: for button in self.Buttons: Laurent@943: if show: Laurent@943: button.Show() Laurent@943: else: Laurent@943: button.Hide() Laurent@943: self.RefreshButtonsState() Laurent@943: self.ParentWindow.ForceRefresh() Laurent@943: Laurent@943: def RefreshButtonsState(self, refresh_positions=False): Laurent@943: if self: Laurent@943: width, height = self.GetSize() Laurent@943: if refresh_positions: Laurent@943: offset = 0 Laurent@943: buttons = self.Buttons[:] Laurent@943: buttons.reverse() Laurent@943: for button in buttons: Laurent@1044: w, h = button.GetSize() Laurent@1044: button.SetPosition(width - 5 - w - offset, 5) Laurent@1044: offset += w + 2 Laurent@943: self.ParentWindow.ForceRefresh() Laurent@943: Laurent@943: def DrawCommonElements(self, dc, buttons=None): Laurent@943: width, height = self.GetSize() Laurent@943: Laurent@943: dc.SetPen(HIGHLIGHT_DROP_PEN) Laurent@943: dc.SetBrush(HIGHLIGHT_DROP_BRUSH) Laurent@943: if self.Highlight in [HIGHLIGHT_BEFORE]: Laurent@943: dc.DrawLine(0, 1, width - 1, 1) Laurent@943: elif self.Highlight in [HIGHLIGHT_AFTER]: Laurent@943: dc.DrawLine(0, height - 1, width - 1, height - 1) Laurent@943: Laurent@943: if buttons is None: Laurent@943: buttons = self.Buttons Laurent@943: for button in buttons: Laurent@943: button.Draw(dc) Laurent@943: Laurent@943: if self.ParentWindow.IsDragging(): Laurent@943: destBBox = self.ParentWindow.GetDraggingAxesClippingRegion(self) Laurent@943: srcPos = self.ParentWindow.GetDraggingAxesPosition(self) Laurent@943: if destBBox.width > 0 and destBBox.height > 0: Laurent@943: srcPanel = self.ParentWindow.DraggingAxesPanel Laurent@943: srcBBox = srcPanel.GetAxesBoundingBox() Laurent@943: Laurent@943: if destBBox.x == 0: Laurent@943: srcX = srcBBox.x - srcPos.x Laurent@943: else: Laurent@943: srcX = srcBBox.x Laurent@943: if destBBox.y == 0: Laurent@943: srcY = srcBBox.y - srcPos.y Laurent@943: else: Laurent@943: srcY = srcBBox.y Laurent@943: Laurent@943: srcBmp = _convert_agg_to_wx_bitmap(srcPanel.get_renderer(), None) Laurent@943: srcDC = wx.MemoryDC() Laurent@943: srcDC.SelectObject(srcBmp) Laurent@943: Laurent@943: dc.Blit(destBBox.x, destBBox.y, Laurent@943: int(destBBox.width), int(destBBox.height), Laurent@943: srcDC, srcX, srcY) Laurent@943: Laurent@943: def OnEnter(self, event): Laurent@943: self.ShowButtons(True) Laurent@916: event.Skip() Laurent@943: Laurent@943: def OnLeave(self, event): Laurent@943: if self.Highlight != HIGHLIGHT_RESIZE or self.CanvasStartSize is None: Laurent@943: x, y = event.GetPosition() Laurent@943: width, height = self.GetSize() Laurent@943: if (x <= 0 or x >= width - 1 or Laurent@943: y <= 0 or y >= height - 1): Laurent@943: self.ShowButtons(False) Laurent@916: event.Skip() Laurent@916: Laurent@943: def OnCloseButton(self): Laurent@943: wx.CallAfter(self.ParentWindow.DeleteValue, self) Laurent@943: Laurent@943: def OnForceButton(self): Laurent@943: wx.CallAfter(self.ForceValue, self.Items[0]) Laurent@943: Laurent@943: def OnReleaseButton(self): Laurent@943: wx.CallAfter(self.ReleaseValue, self.Items[0]) Laurent@943: Laurent@943: def OnResizeWindow(self, event): Laurent@943: wx.CallAfter(self.RefreshButtonsState, True) Laurent@916: event.Skip() Laurent@943: Laurent@943: def OnMouseDragging(self, x, y): Laurent@943: xw, yw = self.GetPosition() Laurent@943: self.ParentWindow.RefreshHighlight(x + xw, y + yw) Laurent@943: Laurent@943: def OnDragging(self, x, y): Laurent@943: width, height = self.GetSize() Laurent@943: if y < height / 2: Laurent@943: if self.ParentWindow.IsViewerFirst(self): Laurent@943: self.SetHighlight(HIGHLIGHT_BEFORE) Laurent@943: else: Laurent@943: self.SetHighlight(HIGHLIGHT_NONE) Laurent@943: self.ParentWindow.HighlightPreviousViewer(self) Laurent@943: else: Laurent@943: self.SetHighlight(HIGHLIGHT_AFTER) Laurent@943: Laurent@988: def OnEraseBackground(self, event): Laurent@988: pass Laurent@988: Laurent@943: def OnResize(self, event): Laurent@943: wx.CallAfter(self.RefreshButtonsState, True) Laurent@943: event.Skip() Laurent@916: Laurent@916: def ForceValue(self, item): Laurent@1102: iec_path = item.GetVariable() Laurent@916: iec_type = self.ParentWindow.GetDataType(iec_path) Laurent@916: if iec_type is not None: Laurent@916: dialog = ForceVariableDialog(self, iec_type, str(item.GetValue())) Laurent@916: if dialog.ShowModal() == wx.ID_OK: Laurent@1102: self.ParentWindow.ForceDataValue(iec_path.upper(), dialog.GetValue()) Laurent@916: Laurent@916: def ReleaseValue(self, item): Laurent@916: iec_path = item.GetVariable().upper() Laurent@916: self.ParentWindow.ReleaseDataValue(iec_path) Laurent@943: Laurent@943: Laurent@943: class DebugVariableText(DebugVariableViewer, wx.Panel): Laurent@916: Laurent@929: def __init__(self, parent, window, items=[]): Laurent@943: DebugVariableViewer.__init__(self, window, items) Laurent@943: Laurent@943: wx.Panel.__init__(self, parent) Laurent@943: self.SetBackgroundColour(wx.WHITE) Laurent@943: self.SetDropTarget(DebugVariableDropTarget(window, self)) Laurent@945: self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) Laurent@943: self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) Laurent@943: self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) Laurent@943: self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) Laurent@943: self.Bind(wx.EVT_SIZE, self.OnResize) Laurent@988: self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) Laurent@943: self.Bind(wx.EVT_PAINT, self.OnPaint) Laurent@943: Laurent@943: self.SetMinSize(wx.Size(0, 25)) Laurent@943: Laurent@943: self.Buttons.append( Laurent@943: GraphButton(0, 0, GetBitmap("force"), self.OnForceButton)) Laurent@943: self.Buttons.append( Laurent@943: GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton)) Laurent@943: self.Buttons.append( Laurent@943: GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton)) Laurent@943: Laurent@943: self.ShowButtons(False) Laurent@943: Laurent@943: def RefreshViewer(self): Laurent@943: width, height = self.GetSize() Laurent@943: bitmap = wx.EmptyBitmap(width, height) Laurent@943: Laurent@946: dc = wx.BufferedDC(wx.ClientDC(self), bitmap) Laurent@943: dc.Clear() Laurent@943: dc.BeginDrawing() Laurent@943: Laurent@943: gc = wx.GCDC(dc) Laurent@943: Laurent@943: item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask()) Laurent@943: w, h = gc.GetTextExtent(item_name) Laurent@945: gc.DrawText(item_name, 20, (height - h) / 2) Laurent@943: Laurent@916: if self.Items[0].IsForced(): Laurent@943: gc.SetTextForeground(wx.BLUE) Laurent@943: self.Buttons[0].Disable() Laurent@943: self.Buttons[1].Enable() Laurent@943: else: Laurent@943: self.Buttons[1].Disable() Laurent@943: self.Buttons[0].Enable() Laurent@943: self.RefreshButtonsState(True) Laurent@943: Laurent@943: item_value = self.Items[0].GetValue() Laurent@943: w, h = gc.GetTextExtent(item_value) Laurent@943: gc.DrawText(item_value, width - 40 - w, (height - h) / 2) Laurent@943: Laurent@943: self.DrawCommonElements(gc) Laurent@943: Laurent@943: gc.EndDrawing() Laurent@943: Laurent@945: def OnLeftDown(self, event): Laurent@945: width, height = self.GetSize() Laurent@945: item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask()) Laurent@945: w, h = self.GetTextExtent(item_name) Laurent@945: x, y = event.GetPosition() Laurent@945: rect = wx.Rect(20, (height - h) / 2, w, h) Laurent@945: if rect.InsideXY(x, y): Laurent@945: data = wx.TextDataObject(str((self.Items[0].GetVariable(), "debug", "move"))) Laurent@945: dragSource = wx.DropSource(self) Laurent@945: dragSource.SetData(data) Laurent@945: dragSource.DoDragDrop() Laurent@945: else: Laurent@945: event.Skip() Laurent@945: Laurent@943: def OnLeftUp(self, event): Laurent@943: x, y = event.GetPosition() Laurent@943: wx.CallAfter(self.HandleButtons, x, y) Laurent@943: event.Skip() Laurent@943: Laurent@943: def OnPaint(self, event): Laurent@943: self.RefreshViewer() Laurent@943: event.Skip() Laurent@916: Laurent@943: class DebugVariableGraphic(DebugVariableViewer, FigureCanvas): Laurent@943: Laurent@943: def __init__(self, parent, window, items, graph_type): Laurent@943: DebugVariableViewer.__init__(self, window, items) Laurent@943: Laurent@1044: self.CanvasSize = SIZE_MINI Laurent@943: self.GraphType = graph_type Laurent@943: self.CursorTick = None Laurent@943: self.MouseStartPos = None Laurent@943: self.StartCursorTick = None Laurent@943: self.CanvasStartSize = None Laurent@930: self.ContextualButtons = [] Laurent@930: self.ContextualButtonsItem = None Laurent@930: Laurent@943: self.Figure = matplotlib.figure.Figure(facecolor='w') Laurent@943: self.Figure.subplotpars.update(top=0.95, left=0.1, bottom=0.1, right=0.95) Laurent@943: Laurent@943: FigureCanvas.__init__(self, parent, -1, self.Figure) Laurent@1190: self.SetWindowStyle(wx.WANTS_CHARS) Laurent@943: self.SetBackgroundColour(wx.WHITE) Laurent@1174: self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) Laurent@943: self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) Laurent@943: self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) Laurent@988: self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) Laurent@943: self.Bind(wx.EVT_SIZE, self.OnResize) Laurent@943: Laurent@1043: canvas_size = self.GetCanvasMinSize() Laurent@1043: self.SetMinSize(canvas_size) Laurent@943: self.SetDropTarget(DebugVariableDropTarget(self.ParentWindow, self)) Laurent@943: self.mpl_connect('button_press_event', self.OnCanvasButtonPressed) Laurent@943: self.mpl_connect('motion_notify_event', self.OnCanvasMotion) Laurent@943: self.mpl_connect('button_release_event', self.OnCanvasButtonReleased) Laurent@943: self.mpl_connect('scroll_event', self.OnCanvasScroll) Laurent@943: Laurent@937: for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI], Laurent@937: ["minimize_graph", "middle_graph", "maximize_graph"]): Laurent@937: self.Buttons.append(GraphButton(0, 0, GetBitmap(bitmap), self.GetOnChangeSizeButton(size))) Laurent@930: self.Buttons.append( Laurent@936: GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportGraphButton)) Laurent@936: self.Buttons.append( Laurent@930: GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton)) Laurent@929: Laurent@943: self.ResetGraphics() Laurent@1043: self.RefreshLabelsPosition(canvas_size.height) Laurent@929: self.ShowButtons(False) Laurent@928: Laurent@925: def draw(self, drawDC=None): Laurent@925: FigureCanvasAgg.draw(self) Laurent@925: Laurent@925: self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None) Laurent@928: self.bitmap.UseAlpha() Laurent@928: width, height = self.GetSize() Laurent@928: bbox = self.GetAxesBoundingBox() Laurent@928: Laurent@928: destDC = wx.MemoryDC() Laurent@928: destDC.SelectObject(self.bitmap) Laurent@928: Laurent@928: destGC = wx.GCDC(destDC) Laurent@930: Laurent@928: destGC.BeginDrawing() Laurent@937: if self.Highlight == HIGHLIGHT_RESIZE: Laurent@937: destGC.SetPen(HIGHLIGHT_RESIZE_PEN) Laurent@937: destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH) Laurent@937: destGC.DrawRectangle(0, height - 5, width, 5) Laurent@937: else: Laurent@937: destGC.SetPen(HIGHLIGHT_DROP_PEN) Laurent@937: destGC.SetBrush(HIGHLIGHT_DROP_BRUSH) Laurent@943: if self.Highlight == HIGHLIGHT_LEFT: Laurent@937: destGC.DrawRectangle(bbox.x, bbox.y, Laurent@937: bbox.width / 2, bbox.height) Laurent@937: elif self.Highlight == HIGHLIGHT_RIGHT: Laurent@937: destGC.DrawRectangle(bbox.x + bbox.width / 2, bbox.y, Laurent@937: bbox.width / 2, bbox.height) Laurent@928: Laurent@943: self.DrawCommonElements(destGC, self.Buttons + self.ContextualButtons) Laurent@943: Laurent@928: destGC.EndDrawing() Laurent@928: Laurent@925: self._isDrawn = True Laurent@925: self.gui_repaint(drawDC=drawDC) Laurent@929: Laurent@943: def GetButtons(self): Laurent@943: return self.Buttons + self.ContextualButtons Laurent@930: Laurent@931: def PopupContextualButtons(self, item, rect, style=wx.RIGHT): Laurent@930: if self.ContextualButtonsItem is not None and item != self.ContextualButtonsItem: Laurent@930: self.DismissContextualButtons() Laurent@930: Laurent@930: if self.ContextualButtonsItem is None: Laurent@930: self.ContextualButtonsItem = item Laurent@930: Laurent@930: if self.ContextualButtonsItem.IsForced(): Laurent@930: self.ContextualButtons.append( Laurent@930: GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton)) Laurent@1044: self.ContextualButtons.append( Laurent@1044: GraphButton(0, 0, GetBitmap("force"), self.OnForceButton)) Laurent@930: self.ContextualButtons.append( Laurent@936: GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportItemGraphButton)) Laurent@936: self.ContextualButtons.append( Laurent@930: GraphButton(0, 0, GetBitmap("delete_graph"), self.OnRemoveItemButton)) Laurent@930: Laurent@930: offset = 0 Laurent@930: buttons = self.ContextualButtons[:] Laurent@931: if style in [wx.TOP, wx.LEFT]: Laurent@930: buttons.reverse() Laurent@930: for button in buttons: Laurent@930: w, h = button.GetSize() Laurent@931: if style in [wx.LEFT, wx.RIGHT]: Laurent@931: if style == wx.LEFT: Laurent@931: x = rect.x - w - offset Laurent@931: else: Laurent@931: x = rect.x + rect.width + offset Laurent@930: y = rect.y + (rect.height - h) / 2 Laurent@930: offset += w Laurent@930: else: Laurent@930: x = rect.x + (rect.width - w ) / 2 Laurent@931: if style == wx.TOP: Laurent@931: y = rect.y - h - offset Laurent@931: else: Laurent@931: y = rect.y + rect.height + offset Laurent@930: offset += h Laurent@930: button.SetPosition(x, y) Laurent@934: self.ParentWindow.ForceRefresh() Laurent@930: Laurent@930: def DismissContextualButtons(self): Laurent@930: if self.ContextualButtonsItem is not None: Laurent@930: self.ContextualButtonsItem = None Laurent@930: self.ContextualButtons = [] Laurent@934: self.ParentWindow.ForceRefresh() Laurent@930: Laurent@930: def IsOverContextualButton(self, x, y): Laurent@930: for button in self.ContextualButtons: Laurent@930: if button.HitTest(x, y): Laurent@930: return True Laurent@930: return False Laurent@930: Laurent@937: def SetMinSize(self, size): Laurent@937: wx.Window.SetMinSize(self, size) Laurent@937: wx.CallAfter(self.RefreshButtonsState) Laurent@929: Laurent@935: def GetOnChangeSizeButton(self, size): Laurent@935: def OnChangeSizeButton(): Laurent@935: self.CanvasSize = size Laurent@943: self.SetCanvasSize(200, self.CanvasSize) Laurent@935: return OnChangeSizeButton Laurent@930: Laurent@936: def OnExportGraphButton(self): Laurent@943: self.ExportGraph() Laurent@930: Laurent@930: def OnForceButton(self): Laurent@943: wx.CallAfter(self.ForceValue, Laurent@930: self.ContextualButtonsItem) Laurent@930: self.DismissContextualButtons() Laurent@930: Laurent@930: def OnReleaseButton(self): Laurent@943: wx.CallAfter(self.ReleaseValue, Laurent@930: self.ContextualButtonsItem) Laurent@930: self.DismissContextualButtons() Laurent@936: Laurent@936: def OnExportItemGraphButton(self): Laurent@943: wx.CallAfter(self.ExportGraph, Laurent@936: self.ContextualButtonsItem) Laurent@936: self.DismissContextualButtons() Laurent@930: Laurent@930: def OnRemoveItemButton(self): Laurent@943: wx.CallAfter(self.ParentWindow.DeleteValue, self, Laurent@930: self.ContextualButtonsItem) Laurent@930: self.DismissContextualButtons() Laurent@936: Laurent@935: def RefreshLabelsPosition(self, height): Laurent@935: canvas_ratio = 1. / height Laurent@935: graph_ratio = 1. / ((1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) * height) Laurent@935: Laurent@935: self.Figure.subplotpars.update( Laurent@935: top= 1.0 - CANVAS_BORDER[1] * canvas_ratio, Laurent@935: bottom= CANVAS_BORDER[0] * canvas_ratio) Laurent@935: Laurent@930: if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): Laurent@930: num_item = len(self.Items) Laurent@930: for idx in xrange(num_item): Laurent@930: if not self.Is3DCanvas(): Laurent@935: self.AxesLabels[idx].set_position( Laurent@935: (0.05, Laurent@935: 1.0 - (CANVAS_PADDING + AXES_LABEL_HEIGHT * idx) * graph_ratio)) Laurent@935: self.Labels[idx].set_position( Laurent@935: (0.95, Laurent@935: CANVAS_PADDING * graph_ratio + Laurent@935: (num_item - idx - 1) * VALUE_LABEL_HEIGHT * graph_ratio)) Laurent@935: else: Laurent@935: self.AxesLabels[0].set_position((0.1, CANVAS_PADDING * graph_ratio)) Laurent@935: self.Labels[0].set_position((0.95, CANVAS_PADDING * graph_ratio)) Laurent@935: self.AxesLabels[1].set_position((0.05, 2 * CANVAS_PADDING * graph_ratio)) Laurent@935: self.Labels[1].set_position((0.05, 1.0 - CANVAS_PADDING * graph_ratio)) Laurent@935: Laurent@930: self.Figure.subplots_adjust() Laurent@935: Laurent@937: def GetCanvasMinSize(self): Laurent@937: return wx.Size(200, Laurent@937: CANVAS_BORDER[0] + CANVAS_BORDER[1] + Laurent@937: 2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items)) Laurent@937: Laurent@935: def SetCanvasSize(self, width, height): Laurent@937: height = max(height, self.GetCanvasMinSize()[1]) Laurent@943: self.SetMinSize(wx.Size(width, height)) Laurent@935: self.RefreshLabelsPosition(height) Laurent@1044: self.RefreshButtonsState() Laurent@929: self.ParentWindow.RefreshGraphicsSizer() Laurent@930: Laurent@925: def GetAxesBoundingBox(self, absolute=False): Laurent@943: width, height = self.GetSize() Laurent@943: ax, ay, aw, ah = self.figure.gca().get_position().bounds Laurent@943: bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1, Laurent@943: aw * width + 2, ah * height + 1) Laurent@925: if absolute: Laurent@925: xw, yw = self.GetPosition() Laurent@925: bbox.x += xw Laurent@925: bbox.y += yw Laurent@925: return bbox Laurent@925: Laurent@929: def OnCanvasButtonPressed(self, event): Laurent@943: width, height = self.GetSize() Laurent@930: x, y = event.x, height - event.y Laurent@943: if not self.IsOverButton(x, y): Laurent@938: if event.inaxes == self.Axes: Laurent@937: item_idx = None Laurent@937: for i, t in ([pair for pair in enumerate(self.AxesLabels)] + Laurent@937: [pair for pair in enumerate(self.Labels)]): Laurent@937: (x0, y0), (x1, y1) = t.get_window_extent().get_points() Laurent@937: rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) Laurent@937: if rect.InsideXY(x, y): Laurent@937: item_idx = i Laurent@937: break Laurent@937: if item_idx is not None: Laurent@943: self.ShowButtons(False) Laurent@943: self.DismissContextualButtons() Laurent@937: xw, yw = self.GetPosition() Laurent@937: self.ParentWindow.StartDragNDrop(self, Laurent@937: self.Items[item_idx], x + xw, y + yw, x + xw, y + yw) Laurent@938: elif not self.Is3DCanvas(): Laurent@938: self.MouseStartPos = wx.Point(x, y) Laurent@938: if event.button == 1 and event.inaxes == self.Axes: Laurent@938: self.StartCursorTick = self.CursorTick Laurent@938: self.HandleCursorMove(event) Laurent@938: elif event.button == 2 and self.GraphType == GRAPH_PARALLEL: Laurent@943: width, height = self.GetSize() Laurent@938: start_tick, end_tick = self.ParentWindow.GetRange() Laurent@938: self.StartCursorTick = start_tick Laurent@937: Laurent@937: elif event.button == 1 and event.y <= 5: Laurent@930: self.MouseStartPos = wx.Point(x, y) Laurent@943: self.CanvasStartSize = self.GetSize() Laurent@928: Laurent@928: def OnCanvasButtonReleased(self, event): Laurent@925: if self.ParentWindow.IsDragging(): Laurent@943: width, height = self.GetSize() Laurent@925: xw, yw = self.GetPosition() Laurent@925: self.ParentWindow.StopDragNDrop( Laurent@931: self.ParentWindow.DraggingAxesPanel.Items[0].GetVariable(), Laurent@925: xw + event.x, Laurent@925: yw + height - event.y) Laurent@928: else: Laurent@928: self.MouseStartPos = None Laurent@928: self.StartCursorTick = None Laurent@937: self.CanvasStartSize = None Laurent@943: width, height = self.GetSize() Laurent@943: self.HandleButtons(event.x, height - event.y) Laurent@943: if event.y > 5 and self.SetHighlight(HIGHLIGHT_NONE): Laurent@943: self.SetCursor(wx.NullCursor) Laurent@937: self.ParentWindow.ForceRefresh() Laurent@916: Laurent@924: def OnCanvasMotion(self, event): Laurent@943: width, height = self.GetSize() Laurent@925: if self.ParentWindow.IsDragging(): Laurent@925: xw, yw = self.GetPosition() Laurent@925: self.ParentWindow.MoveDragNDrop( Laurent@925: xw + event.x, Laurent@925: yw + height - event.y) Laurent@937: else: Laurent@937: if not self.Is3DCanvas(): Laurent@937: if event.button == 1 and self.CanvasStartSize is None: Laurent@937: if event.inaxes == self.Axes: Laurent@937: if self.MouseStartPos is not None: Laurent@937: self.HandleCursorMove(event) Laurent@937: elif self.MouseStartPos is not None and len(self.Items) == 1: Laurent@937: xw, yw = self.GetPosition() Laurent@937: self.ParentWindow.SetCursorTick(self.StartCursorTick) Laurent@937: self.ParentWindow.StartDragNDrop(self, Laurent@937: self.Items[0], Laurent@937: event.x + xw, height - event.y + yw, Laurent@937: self.MouseStartPos.x + xw, self.MouseStartPos.y + yw) Laurent@937: elif event.button == 2 and self.GraphType == GRAPH_PARALLEL: Laurent@937: start_tick, end_tick = self.ParentWindow.GetRange() Laurent@937: rect = self.GetAxesBoundingBox() Laurent@937: self.ParentWindow.SetCanvasPosition( Laurent@937: self.StartCursorTick + (self.MouseStartPos.x - event.x) * Laurent@937: (end_tick - start_tick) / rect.width) Laurent@937: Laurent@937: if event.button == 1 and self.CanvasStartSize is not None: Laurent@943: width, height = self.GetSize() Laurent@937: self.SetCanvasSize(width, Laurent@937: self.CanvasStartSize.height + height - event.y - self.MouseStartPos.y) Laurent@937: Laurent@936: elif event.button in [None, "up", "down"]: Laurent@930: if self.GraphType == GRAPH_PARALLEL: Laurent@938: orientation = [wx.RIGHT] * len(self.AxesLabels) + [wx.LEFT] * len(self.Labels) Laurent@929: elif len(self.AxesLabels) > 0: Laurent@931: orientation = [wx.RIGHT, wx.TOP, wx.LEFT, wx.BOTTOM] Laurent@938: else: Laurent@938: orientation = [wx.LEFT] * len(self.Labels) Laurent@929: item_idx = None Laurent@929: item_style = None Laurent@931: for (i, t), style in zip([pair for pair in enumerate(self.AxesLabels)] + Laurent@931: [pair for pair in enumerate(self.Labels)], Laurent@931: orientation): Laurent@929: (x0, y0), (x1, y1) = t.get_window_extent().get_points() Laurent@929: rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) Laurent@929: if rect.InsideXY(event.x, height - event.y): Laurent@929: item_idx = i Laurent@929: item_style = style Laurent@929: break Laurent@929: if item_idx is not None: Laurent@943: self.PopupContextualButtons(self.Items[item_idx], rect, item_style) Laurent@929: return Laurent@943: if not self.IsOverContextualButton(event.x, height - event.y): Laurent@943: self.DismissContextualButtons() Laurent@937: Laurent@937: if event.y <= 5: Laurent@943: if self.SetHighlight(HIGHLIGHT_RESIZE): Laurent@943: self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) Laurent@937: self.ParentWindow.ForceRefresh() Laurent@937: else: Laurent@943: if self.SetHighlight(HIGHLIGHT_NONE): Laurent@943: self.SetCursor(wx.NullCursor) Laurent@937: self.ParentWindow.ForceRefresh() Laurent@928: Laurent@928: def OnCanvasScroll(self, event): Laurent@1040: if event.inaxes is not None and event.guiEvent.ControlDown(): Laurent@928: if self.GraphType == GRAPH_ORTHOGONAL: Laurent@928: start_tick, end_tick = self.ParentWindow.GetRange() Laurent@928: tick = (start_tick + end_tick) / 2. Laurent@928: else: Laurent@928: tick = event.xdata Laurent@928: self.ParentWindow.ChangeRange(int(-event.step) / 3, tick) Laurent@1040: self.ParentWindow.VetoScrollEvent = True Laurent@928: Laurent@943: def OnDragging(self, x, y): Laurent@943: width, height = self.GetSize() Laurent@943: bbox = self.GetAxesBoundingBox() Laurent@943: if bbox.InsideXY(x, y) and not self.Is3DCanvas(): Laurent@943: rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height) Laurent@943: if rect.InsideXY(x, y): Laurent@943: self.SetHighlight(HIGHLIGHT_LEFT) Laurent@943: else: Laurent@943: self.SetHighlight(HIGHLIGHT_RIGHT) Laurent@943: elif y < height / 2: Laurent@943: if self.ParentWindow.IsViewerFirst(self): Laurent@943: self.SetHighlight(HIGHLIGHT_BEFORE) Laurent@943: else: Laurent@943: self.SetHighlight(HIGHLIGHT_NONE) Laurent@943: self.ParentWindow.HighlightPreviousViewer(self) Laurent@943: else: Laurent@943: self.SetHighlight(HIGHLIGHT_AFTER) Laurent@943: Laurent@943: def OnLeave(self, event): Laurent@943: if self.CanvasStartSize is None and self.SetHighlight(HIGHLIGHT_NONE): Laurent@943: self.SetCursor(wx.NullCursor) Laurent@937: self.ParentWindow.ForceRefresh() Laurent@943: DebugVariableViewer.OnLeave(self, event) Laurent@934: Laurent@1174: KEY_CURSOR_INCREMENT = { Laurent@1174: wx.WXK_LEFT: -1, Laurent@1174: wx.WXK_RIGHT: 1, Laurent@1174: wx.WXK_UP: -10, Laurent@1174: wx.WXK_DOWN: 10} Laurent@1174: def OnKeyDown(self, event): Laurent@1174: if self.CursorTick is not None: Laurent@1194: move = self.KEY_CURSOR_INCREMENT.get(event.GetKeyCode(), None) Laurent@1194: if move is not None: Laurent@1194: self.ParentWindow.MoveCursorTick(move) Laurent@1174: event.Skip() Laurent@1174: Laurent@928: def HandleCursorMove(self, event): Laurent@928: start_tick, end_tick = self.ParentWindow.GetRange() Laurent@928: cursor_tick = None Laurent@928: if self.GraphType == GRAPH_ORTHOGONAL: Laurent@928: x_data = self.Items[0].GetData(start_tick, end_tick) Laurent@928: y_data = self.Items[1].GetData(start_tick, end_tick) Laurent@928: if len(x_data) > 0 and len(y_data) > 0: Laurent@928: length = min(len(x_data), len(y_data)) Laurent@928: d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + (y_data[:length,1]-event.ydata) ** 2) Laurent@928: cursor_tick = x_data[numpy.argmin(d), 0] Laurent@928: else: Laurent@928: data = self.Items[0].GetData(start_tick, end_tick) Laurent@928: if len(data) > 0: Laurent@928: cursor_tick = data[numpy.argmin(numpy.abs(data[:,0] - event.xdata)), 0] Laurent@928: if cursor_tick is not None: Laurent@928: self.ParentWindow.SetCursorTick(cursor_tick) Laurent@928: Laurent@928: def OnAxesMotion(self, event): Laurent@928: if self.Is3DCanvas(): Laurent@928: current_time = gettime() Laurent@928: if current_time - self.LastMotionTime > REFRESH_PERIOD: Laurent@928: self.LastMotionTime = current_time Laurent@928: Axes3D._on_move(self.Axes, event) Laurent@924: Laurent@916: def ResetGraphics(self): Laurent@916: self.Figure.clear() Laurent@916: if self.Is3DCanvas(): Laurent@916: self.Axes = self.Figure.gca(projection='3d') Laurent@916: self.Axes.set_color_cycle(['b']) Laurent@916: self.LastMotionTime = gettime() Laurent@924: setattr(self.Axes, "_on_move", self.OnAxesMotion) Laurent@916: self.Axes.mouse_init() Laurent@930: self.Axes.tick_params(axis='z', labelsize='small') Laurent@916: else: Laurent@916: self.Axes = self.Figure.gca() Laurent@930: self.Axes.set_color_cycle(color_cycle) Laurent@930: self.Axes.tick_params(axis='x', labelsize='small') Laurent@930: self.Axes.tick_params(axis='y', labelsize='small') Laurent@916: self.Plots = [] Laurent@924: self.VLine = None Laurent@924: self.HLine = None Laurent@928: self.Labels = [] Laurent@929: self.AxesLabels = [] Laurent@930: if not self.Is3DCanvas(): Laurent@930: text_func = self.Axes.text Laurent@930: else: Laurent@930: text_func = self.Axes.text2D Laurent@929: if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): Laurent@928: num_item = len(self.Items) Laurent@928: for idx in xrange(num_item): Laurent@930: if num_item == 1: Laurent@930: color = 'k' Laurent@930: else: Laurent@930: color = color_cycle[idx % len(color_cycle)] Laurent@930: if not self.Is3DCanvas(): Laurent@930: self.AxesLabels.append( Laurent@935: text_func(0, 0, "", size='small', Laurent@935: verticalalignment='top', Laurent@930: color=color, Laurent@930: transform=self.Axes.transAxes)) Laurent@928: self.Labels.append( Laurent@930: text_func(0, 0, "", size='large', Laurent@929: horizontalalignment='right', Laurent@930: color=color, Laurent@929: transform=self.Axes.transAxes)) Laurent@929: else: Laurent@929: self.AxesLabels.append( Laurent@930: self.Axes.text(0, 0, "", size='small', Laurent@929: transform=self.Axes.transAxes)) Laurent@929: self.Labels.append( Laurent@930: self.Axes.text(0, 0, "", size='large', Laurent@929: horizontalalignment='right', Laurent@929: transform=self.Axes.transAxes)) Laurent@929: self.AxesLabels.append( Laurent@930: self.Axes.text(0, 0, "", size='small', Laurent@929: rotation='vertical', Laurent@929: verticalalignment='bottom', Laurent@929: transform=self.Axes.transAxes)) Laurent@929: self.Labels.append( Laurent@930: self.Axes.text(0, 0, "", size='large', Laurent@929: rotation='vertical', Laurent@929: verticalalignment='top', Laurent@929: transform=self.Axes.transAxes)) Laurent@943: width, height = self.GetSize() Laurent@935: self.RefreshLabelsPosition(height) Laurent@929: Laurent@916: def AddItem(self, item): Laurent@916: DebugVariableViewer.AddItem(self, item) Laurent@916: self.ResetGraphics() Laurent@916: Laurent@916: def RemoveItem(self, item): Laurent@916: DebugVariableViewer.RemoveItem(self, item) Laurent@916: if not self.IsEmpty(): Laurent@929: if len(self.Items) == 1: Laurent@929: self.GraphType = GRAPH_PARALLEL Laurent@916: self.ResetGraphics() Laurent@916: Laurent@916: def UnregisterObsoleteData(self): Laurent@916: DebugVariableViewer.UnregisterObsoleteData(self) Laurent@916: if not self.IsEmpty(): Laurent@916: self.ResetGraphics() Laurent@916: Laurent@916: def Is3DCanvas(self): Laurent@916: return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3 Laurent@916: Laurent@924: def SetCursorTick(self, cursor_tick): Laurent@924: self.CursorTick = cursor_tick Laurent@924: Laurent@943: def RefreshViewer(self, refresh_graphics=True): Laurent@916: Laurent@916: if refresh_graphics: Laurent@916: start_tick, end_tick = self.ParentWindow.GetRange() Laurent@916: Laurent@916: if self.GraphType == GRAPH_PARALLEL: Laurent@916: min_value = max_value = None Laurent@916: Laurent@916: for idx, item in enumerate(self.Items): Laurent@916: data = item.GetData(start_tick, end_tick) Laurent@916: if data is not None: Laurent@1193: item_min_value, item_max_value = item.GetValueRange() Laurent@916: if min_value is None: Laurent@916: min_value = item_min_value Laurent@916: elif item_min_value is not None: Laurent@916: min_value = min(min_value, item_min_value) Laurent@916: if max_value is None: Laurent@916: max_value = item_max_value Laurent@916: elif item_max_value is not None: Laurent@916: max_value = max(max_value, item_max_value) Laurent@916: Laurent@916: if len(self.Plots) <= idx: Laurent@916: self.Plots.append( Laurent@916: self.Axes.plot(data[:, 0], data[:, 1])[0]) Laurent@916: else: Laurent@916: self.Plots[idx].set_data(data[:, 0], data[:, 1]) Laurent@916: Laurent@916: if min_value is not None and max_value is not None: Laurent@916: y_center = (min_value + max_value) / 2. Laurent@916: y_range = max(1.0, max_value - min_value) Laurent@916: else: Laurent@916: y_center = 0.5 Laurent@916: y_range = 1.0 Laurent@916: x_min, x_max = start_tick, end_tick Laurent@916: y_min, y_max = y_center - y_range * 0.55, y_center + y_range * 0.55 Laurent@916: Laurent@928: if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: Laurent@924: if self.VLine is None: Laurent@930: self.VLine = self.Axes.axvline(self.CursorTick, color=cursor_color) Laurent@924: else: Laurent@924: self.VLine.set_xdata((self.CursorTick, self.CursorTick)) Laurent@924: self.VLine.set_visible(True) Laurent@924: else: Laurent@924: if self.VLine is not None: Laurent@924: self.VLine.set_visible(False) Laurent@916: else: Laurent@916: min_start_tick = reduce(max, [item.GetData()[0, 0] Laurent@916: for item in self.Items Laurent@916: if len(item.GetData()) > 0], 0) Laurent@916: start_tick = max(start_tick, min_start_tick) Laurent@916: end_tick = max(end_tick, min_start_tick) Laurent@916: x_data, x_min, x_max = OrthogonalData(self.Items[0], start_tick, end_tick) Laurent@916: y_data, y_min, y_max = OrthogonalData(self.Items[1], start_tick, end_tick) Laurent@924: if self.CursorTick is not None: Laurent@924: x_cursor, x_forced = self.Items[0].GetValue(self.CursorTick, raw=True) Laurent@924: y_cursor, y_forced = self.Items[1].GetValue(self.CursorTick, raw=True) Laurent@916: length = 0 Laurent@916: if x_data is not None and y_data is not None: Laurent@916: length = min(len(x_data), len(y_data)) Laurent@916: if len(self.Items) < 3: Laurent@916: if x_data is not None and y_data is not None: Laurent@916: if len(self.Plots) == 0: Laurent@916: self.Plots.append( Laurent@916: self.Axes.plot(x_data[:, 1][:length], Laurent@916: y_data[:, 1][:length])[0]) Laurent@916: else: Laurent@916: self.Plots[0].set_data( Laurent@916: x_data[:, 1][:length], Laurent@916: y_data[:, 1][:length]) Laurent@924: Laurent@928: if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: Laurent@924: if self.VLine is None: Laurent@930: self.VLine = self.Axes.axvline(x_cursor, color=cursor_color) Laurent@924: else: Laurent@924: self.VLine.set_xdata((x_cursor, x_cursor)) Laurent@924: if self.HLine is None: Laurent@930: self.HLine = self.Axes.axhline(y_cursor, color=cursor_color) Laurent@924: else: Laurent@924: self.HLine.set_ydata((y_cursor, y_cursor)) Laurent@924: self.VLine.set_visible(True) Laurent@924: self.HLine.set_visible(True) Laurent@924: else: Laurent@924: if self.VLine is not None: Laurent@924: self.VLine.set_visible(False) Laurent@924: if self.HLine is not None: Laurent@924: self.HLine.set_visible(False) Laurent@916: else: Laurent@916: while len(self.Axes.lines) > 0: Laurent@916: self.Axes.lines.pop() Laurent@916: z_data, z_min, z_max = OrthogonalData(self.Items[2], start_tick, end_tick) Laurent@924: if self.CursorTick is not None: Laurent@924: z_cursor, z_forced = self.Items[2].GetValue(self.CursorTick, raw=True) Laurent@916: if x_data is not None and y_data is not None and z_data is not None: Laurent@916: length = min(length, len(z_data)) Laurent@916: self.Axes.plot(x_data[:, 1][:length], Laurent@916: y_data[:, 1][:length], Laurent@916: zs = z_data[:, 1][:length]) Laurent@916: self.Axes.set_zlim(z_min, z_max) Laurent@928: if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: Laurent@924: for kwargs in [{"xs": numpy.array([x_min, x_max])}, Laurent@924: {"ys": numpy.array([y_min, y_max])}, Laurent@924: {"zs": numpy.array([z_min, z_max])}]: Laurent@924: for param, value in [("xs", numpy.array([x_cursor, x_cursor])), Laurent@924: ("ys", numpy.array([y_cursor, y_cursor])), Laurent@924: ("zs", numpy.array([z_cursor, z_cursor]))]: Laurent@924: kwargs.setdefault(param, value) Laurent@930: kwargs["color"] = cursor_color Laurent@924: self.Axes.plot(**kwargs) Laurent@924: Laurent@916: self.Axes.set_xlim(x_min, x_max) Laurent@916: self.Axes.set_ylim(y_min, y_max) Laurent@916: Laurent@928: variable_name_mask = self.ParentWindow.GetVariableNameMask() Laurent@924: if self.CursorTick is not None: Laurent@924: values, forced = apply(zip, [item.GetValue(self.CursorTick) for item in self.Items]) Laurent@924: else: Laurent@924: values, forced = apply(zip, [(item.GetValue(), item.IsForced()) for item in self.Items]) Laurent@929: labels = [item.GetVariable(variable_name_mask) for item in self.Items] Laurent@930: styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced) Laurent@930: if self.Is3DCanvas(): Laurent@930: for idx, label_func in enumerate([self.Axes.set_xlabel, Laurent@930: self.Axes.set_ylabel, Laurent@930: self.Axes.set_zlabel]): Laurent@930: label_func(labels[idx], fontdict={'size': 'small','color': color_cycle[idx]}) Laurent@930: else: Laurent@930: for label, text in zip(self.AxesLabels, labels): Laurent@930: label.set_text(text) Laurent@930: for label, value, style in zip(self.Labels, values, styles): Laurent@929: label.set_text(value) Laurent@930: label.set_style(style) Laurent@931: Laurent@943: self.draw() Laurent@916: Laurent@936: def ExportGraph(self, item=None): Laurent@936: if item is not None: Laurent@936: variables = [(item, [entry for entry in item.GetData()])] Laurent@936: else: Laurent@936: variables = [(item, [entry for entry in item.GetData()]) Laurent@936: for item in self.Items] Laurent@936: self.ParentWindow.CopyDataToClipboard(variables) Laurent@936: Laurent@916: class DebugVariablePanel(wx.Panel, DebugViewer): Laurent@814: Laurent@902: def __init__(self, parent, producer, window): Laurent@916: wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL) Laurent@902: Laurent@902: self.ParentWindow = window Laurent@902: Laurent@814: self.HasNewData = False Laurent@1008: self.Force = False Laurent@887: Laurent@888: if USE_MPL: Laurent@1008: self.SetBackgroundColour(wx.WHITE) Laurent@1008: Laurent@916: main_sizer = wx.BoxSizer(wx.VERTICAL) Laurent@916: Laurent@916: self.Ticks = numpy.array([]) Laurent@916: self.StartTick = 0 Laurent@916: self.Fixed = False Laurent@928: self.CursorTick = None Laurent@925: self.DraggingAxesPanel = None Laurent@925: self.DraggingAxesBoundingBox = None Laurent@925: self.DraggingAxesMousePos = None Laurent@1040: self.VetoScrollEvent = False Laurent@931: self.VariableNameMask = [] Laurent@924: Laurent@916: self.GraphicPanels = [] Laurent@888: Laurent@902: graphics_button_sizer = wx.BoxSizer(wx.HORIZONTAL) Laurent@916: main_sizer.AddSizer(graphics_button_sizer, border=5, flag=wx.GROW|wx.ALL) Laurent@916: Laurent@916: range_label = wx.StaticText(self, label=_('Range:')) Laurent@902: graphics_button_sizer.AddWindow(range_label, flag=wx.ALIGN_CENTER_VERTICAL) Laurent@902: Laurent@916: self.CanvasRange = wx.ComboBox(self, style=wx.CB_READONLY) Laurent@902: self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange) Laurent@905: graphics_button_sizer.AddWindow(self.CanvasRange, 1, Laurent@905: border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) Laurent@902: Laurent@1191: self.CanvasRange.Clear() Laurent@1192: default_range_idx = 0 Laurent@1192: for idx, (text, value) in enumerate(RANGE_VALUES): Laurent@1191: self.CanvasRange.Append(text) Laurent@1192: if text == "1s": Laurent@1192: default_range_idx = idx Laurent@1192: self.CanvasRange.SetSelection(default_range_idx) Laurent@1191: Laurent@902: for name, bitmap, help in [ Laurent@902: ("CurrentButton", "current", _("Go to current value")), Laurent@902: ("ExportGraphButton", "export_graph", _("Export graph values to clipboard"))]: Laurent@916: button = wx.lib.buttons.GenBitmapButton(self, Laurent@902: bitmap=GetBitmap(bitmap), Laurent@902: size=wx.Size(28, 28), style=wx.NO_BORDER) Laurent@902: button.SetToolTipString(help) Laurent@902: setattr(self, name, button) Laurent@902: self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button) Laurent@902: graphics_button_sizer.AddWindow(button, border=5, flag=wx.LEFT) Laurent@902: Laurent@916: self.CanvasPosition = wx.ScrollBar(self, Laurent@902: size=wx.Size(0, 16), style=wx.SB_HORIZONTAL) Laurent@902: self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, Laurent@902: self.OnPositionChanging, self.CanvasPosition) Laurent@902: self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, Laurent@902: self.OnPositionChanging, self.CanvasPosition) Laurent@902: self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, Laurent@902: self.OnPositionChanging, self.CanvasPosition) Laurent@902: self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, Laurent@902: self.OnPositionChanging, self.CanvasPosition) Laurent@902: self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, Laurent@902: self.OnPositionChanging, self.CanvasPosition) Laurent@916: main_sizer.AddWindow(self.CanvasPosition, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) Laurent@916: Laurent@928: self.TickSizer = wx.BoxSizer(wx.HORIZONTAL) Laurent@928: main_sizer.AddSizer(self.TickSizer, border=5, flag=wx.ALL|wx.GROW) Laurent@928: Laurent@928: self.TickLabel = wx.StaticText(self) Laurent@931: self.TickSizer.AddWindow(self.TickLabel, border=5, flag=wx.RIGHT) Laurent@931: Laurent@931: self.MaskLabel = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_CENTER|wx.NO_BORDER) Laurent@931: self.TickSizer.AddWindow(self.MaskLabel, 1, border=5, flag=wx.RIGHT|wx.GROW) Laurent@928: Laurent@928: self.TickTimeLabel = wx.StaticText(self) Laurent@928: self.TickSizer.AddWindow(self.TickTimeLabel) Laurent@928: Laurent@916: self.GraphicsWindow = wx.ScrolledWindow(self, style=wx.HSCROLL|wx.VSCROLL) Laurent@928: self.GraphicsWindow.SetBackgroundColour(wx.WHITE) Laurent@916: self.GraphicsWindow.SetDropTarget(DebugVariableDropTarget(self)) Laurent@988: self.GraphicsWindow.Bind(wx.EVT_ERASE_BACKGROUND, self.OnGraphicsWindowEraseBackground) Laurent@988: self.GraphicsWindow.Bind(wx.EVT_PAINT, self.OnGraphicsWindowPaint) Laurent@916: self.GraphicsWindow.Bind(wx.EVT_SIZE, self.OnGraphicsWindowResize) Laurent@1040: self.GraphicsWindow.Bind(wx.EVT_MOUSEWHEEL, self.OnGraphicsWindowMouseWheel) Laurent@1040: Laurent@916: main_sizer.AddWindow(self.GraphicsWindow, 1, flag=wx.GROW) Laurent@916: Laurent@916: self.GraphicsSizer = wx.BoxSizer(wx.VERTICAL) Laurent@916: self.GraphicsWindow.SetSizer(self.GraphicsSizer) Laurent@916: Laurent@888: else: Laurent@916: main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) Laurent@916: main_sizer.AddGrowableCol(0) Laurent@916: main_sizer.AddGrowableRow(1) Laurent@916: Laurent@916: button_sizer = wx.BoxSizer(wx.HORIZONTAL) Laurent@916: main_sizer.AddSizer(button_sizer, border=5, Laurent@916: flag=wx.ALIGN_RIGHT|wx.ALL) Laurent@916: Laurent@916: for name, bitmap, help in [ Laurent@916: ("DeleteButton", "remove_element", _("Remove debug variable")), Laurent@916: ("UpButton", "up", _("Move debug variable up")), Laurent@916: ("DownButton", "down", _("Move debug variable down"))]: Laurent@916: button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), Laurent@916: size=wx.Size(28, 28), style=wx.NO_BORDER) Laurent@916: button.SetToolTipString(help) Laurent@916: setattr(self, name, button) Laurent@916: button_sizer.AddWindow(button, border=5, flag=wx.LEFT) Laurent@916: Laurent@916: self.VariablesGrid = CustomGrid(self, size=wx.Size(-1, 150), style=wx.VSCROLL) Laurent@916: self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self, self.VariablesGrid)) Laurent@916: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, Laurent@916: self.OnVariablesGridCellRightClick) Laurent@916: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, Laurent@916: self.OnVariablesGridCellLeftClick) Laurent@916: main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) Laurent@916: Laurent@916: self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames()) Laurent@916: self.VariablesGrid.SetTable(self.Table) Laurent@916: self.VariablesGrid.SetButtons({"Delete": self.DeleteButton, Laurent@916: "Up": self.UpButton, Laurent@916: "Down": self.DownButton}) Laurent@916: Laurent@916: def _AddVariable(new_row): Laurent@916: return self.VariablesGrid.GetGridCursorRow() Laurent@916: setattr(self.VariablesGrid, "_AddRow", _AddVariable) Laurent@916: Laurent@916: def _DeleteVariable(row): Laurent@916: item = self.Table.GetItem(row) Laurent@916: self.RemoveDataConsumer(item) Laurent@916: self.Table.RemoveItem(row) Laurent@916: self.RefreshView() Laurent@916: setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) Laurent@916: Laurent@916: def _MoveVariable(row, move): Laurent@916: new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1)) Laurent@916: if new_row != row: Laurent@916: self.Table.MoveItem(row, new_row) Laurent@916: self.RefreshView() Laurent@916: return new_row Laurent@916: setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) Laurent@916: Laurent@916: self.VariablesGrid.SetRowLabelSize(0) Laurent@916: Laurent@916: self.GridColSizes = [200, 100] Laurent@916: Laurent@916: for col in range(self.Table.GetNumberCols()): Laurent@916: attr = wx.grid.GridCellAttr() Laurent@916: attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) Laurent@916: self.VariablesGrid.SetColAttr(col, attr) Laurent@916: self.VariablesGrid.SetColSize(col, self.GridColSizes[col]) Laurent@916: Laurent@916: self.Table.ResetView(self.VariablesGrid) Laurent@916: self.VariablesGrid.RefreshButtons() Laurent@916: Laurent@1192: DebugViewer.__init__(self, producer, True) Laurent@1192: Laurent@916: self.SetSizer(main_sizer) Laurent@1192: Laurent@1192: def SetTickTime(self, ticktime=0): Laurent@1192: if USE_MPL: Laurent@1192: self.Ticktime = ticktime Laurent@1192: if self.Ticktime == 0: Laurent@1192: self.Ticktime = MILLISECOND Laurent@1192: self.CurrentRange = RANGE_VALUES[ Laurent@1192: self.CanvasRange.GetSelection()][1] / self.Ticktime Laurent@1192: Laurent@902: def SetDataProducer(self, producer): Laurent@902: DebugViewer.SetDataProducer(self, producer) Laurent@902: Laurent@916: if USE_MPL: Laurent@916: if self.DataProducer is not None: Laurent@1192: self.SetTickTime(self.DataProducer.GetTicktime()) Laurent@902: Laurent@902: def RefreshNewData(self, *args, **kwargs): Laurent@902: if self.HasNewData or self.Force: Laurent@814: self.HasNewData = False Laurent@916: self.RefreshView(only_values=True) Laurent@902: DebugViewer.RefreshNewData(self, *args, **kwargs) Laurent@902: Laurent@902: def NewDataAvailable(self, tick, *args, **kwargs): Laurent@916: if USE_MPL and tick is not None: Laurent@927: if len(self.Ticks) == 0: Laurent@927: self.StartTick = tick Laurent@902: self.Ticks = numpy.append(self.Ticks, [tick]) Laurent@902: if not self.Fixed or tick < self.StartTick + self.CurrentRange: Laurent@902: self.StartTick = max(self.StartTick, tick - self.CurrentRange) Laurent@928: if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange: Laurent@928: self.Force = True Laurent@902: DebugViewer.NewDataAvailable(self, tick, *args, **kwargs) Laurent@814: Laurent@924: def ForceRefresh(self): Laurent@924: self.Force = True Laurent@924: wx.CallAfter(self.NewDataAvailable, None, True) Laurent@924: Laurent@916: def RefreshGraphicsSizer(self): Laurent@916: self.GraphicsSizer.Clear() Laurent@916: Laurent@916: for panel in self.GraphicPanels: Laurent@916: self.GraphicsSizer.AddWindow(panel, flag=wx.GROW) Laurent@916: Laurent@916: self.GraphicsSizer.Layout() Laurent@916: self.RefreshGraphicsWindowScrollbars() Laurent@916: Laurent@928: def SetCanvasPosition(self, tick): Laurent@928: tick = max(self.Ticks[0], min(tick, self.Ticks[-1] - self.CurrentRange)) Laurent@928: self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - tick))] Laurent@928: self.Fixed = True Laurent@928: self.RefreshCanvasPosition() Laurent@928: self.ForceRefresh() Laurent@928: Laurent@928: def SetCursorTick(self, cursor_tick): Laurent@928: self.CursorTick = cursor_tick Laurent@928: self.Fixed = True Laurent@1084: self.UpdateCursorTick() Laurent@924: Laurent@1174: def MoveCursorTick(self, move): Laurent@1174: if self.CursorTick is not None: Laurent@1174: cursor_tick = max(self.Ticks[0], Laurent@1174: min(self.CursorTick + move, Laurent@1174: self.Ticks[-1])) Laurent@1192: cursor_tick_idx = numpy.argmin(numpy.abs(self.Ticks - cursor_tick)) Laurent@1192: if self.Ticks[cursor_tick_idx] == self.CursorTick: Laurent@1192: cursor_tick_idx = max(0, Laurent@1192: min(cursor_tick_idx + abs(move) / move, Laurent@1192: len(self.Ticks) - 1)) Laurent@1192: self.CursorTick = self.Ticks[cursor_tick_idx] Laurent@1174: self.StartTick = max(self.Ticks[ Laurent@1174: numpy.argmin(numpy.abs(self.Ticks - Laurent@1174: self.CursorTick + self.CurrentRange))], Laurent@1174: min(self.StartTick, self.CursorTick)) Laurent@1174: self.RefreshCanvasPosition() Laurent@1174: self.UpdateCursorTick() Laurent@1174: Laurent@928: def ResetCursorTick(self): Laurent@928: self.CursorTick = None Laurent@1084: self.UpdateCursorTick() Laurent@1084: Laurent@1084: def UpdateCursorTick(self): Laurent@924: for panel in self.GraphicPanels: Laurent@924: if isinstance(panel, DebugVariableGraphic): Laurent@928: panel.SetCursorTick(self.CursorTick) Laurent@928: self.ForceRefresh() Laurent@928: Laurent@929: def StartDragNDrop(self, panel, item, x_mouse, y_mouse, x_mouse_start, y_mouse_start): Laurent@929: if len(panel.GetItems()) > 1: Laurent@929: self.DraggingAxesPanel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL) Laurent@929: self.DraggingAxesPanel.SetCursorTick(self.CursorTick) Laurent@929: width, height = panel.GetSize() Laurent@943: self.DraggingAxesPanel.SetSize(wx.Size(width, height)) Laurent@1044: self.DraggingAxesPanel.ResetGraphics() Laurent@929: self.DraggingAxesPanel.SetPosition(wx.Point(0, -height)) Laurent@929: else: Laurent@929: self.DraggingAxesPanel = panel Laurent@925: self.DraggingAxesBoundingBox = panel.GetAxesBoundingBox(absolute=True) Laurent@925: self.DraggingAxesMousePos = wx.Point( Laurent@928: x_mouse_start - self.DraggingAxesBoundingBox.x, Laurent@928: y_mouse_start - self.DraggingAxesBoundingBox.y) Laurent@928: self.MoveDragNDrop(x_mouse, y_mouse) Laurent@925: Laurent@925: def MoveDragNDrop(self, x_mouse, y_mouse): Laurent@925: self.DraggingAxesBoundingBox.x = x_mouse - self.DraggingAxesMousePos.x Laurent@925: self.DraggingAxesBoundingBox.y = y_mouse - self.DraggingAxesMousePos.y Laurent@934: self.RefreshHighlight(x_mouse, y_mouse) Laurent@934: Laurent@934: def RefreshHighlight(self, x_mouse, y_mouse): Laurent@929: for idx, panel in enumerate(self.GraphicPanels): Laurent@928: x, y = panel.GetPosition() Laurent@943: width, height = panel.GetSize() Laurent@928: rect = wx.Rect(x, y, width, height) Laurent@929: if (rect.InsideXY(x_mouse, y_mouse) or Laurent@929: idx == 0 and y_mouse < 0 or Laurent@929: idx == len(self.GraphicPanels) - 1 and y_mouse > panel.GetPosition()[1]): Laurent@943: panel.OnDragging(x_mouse - x, y_mouse - y) Laurent@943: else: Laurent@943: panel.SetHighlight(HIGHLIGHT_NONE) Laurent@962: if wx.Platform == "__WXMSW__": Laurent@962: self.RefreshView() Laurent@962: else: Laurent@962: self.ForceRefresh() Laurent@934: Laurent@934: def ResetHighlight(self): Laurent@934: for panel in self.GraphicPanels: Laurent@943: panel.SetHighlight(HIGHLIGHT_NONE) Laurent@962: if wx.Platform == "__WXMSW__": Laurent@962: self.RefreshView() Laurent@962: else: Laurent@962: self.ForceRefresh() Laurent@925: Laurent@925: def IsDragging(self): Laurent@925: return self.DraggingAxesPanel is not None Laurent@925: Laurent@925: def GetDraggingAxesClippingRegion(self, panel): Laurent@925: x, y = panel.GetPosition() Laurent@943: width, height = panel.GetSize() Laurent@925: bbox = wx.Rect(x, y, width, height) Laurent@925: bbox = bbox.Intersect(self.DraggingAxesBoundingBox) Laurent@925: bbox.x -= x Laurent@925: bbox.y -= y Laurent@925: return bbox Laurent@925: Laurent@943: def GetDraggingAxesPosition(self, panel): Laurent@943: x, y = panel.GetPosition() Laurent@943: return wx.Point(self.DraggingAxesBoundingBox.x - x, Laurent@943: self.DraggingAxesBoundingBox.y - y) Laurent@943: Laurent@925: def StopDragNDrop(self, variable, x_mouse, y_mouse): Laurent@943: if self.DraggingAxesPanel not in self.GraphicPanels: Laurent@943: self.DraggingAxesPanel.Destroy() Laurent@925: self.DraggingAxesPanel = None Laurent@925: self.DraggingAxesBoundingBox = None Laurent@925: self.DraggingAxesMousePos = None Laurent@925: for idx, panel in enumerate(self.GraphicPanels): Laurent@943: panel.SetHighlight(HIGHLIGHT_NONE) Laurent@925: xw, yw = panel.GetPosition() Laurent@943: width, height = panel.GetSize() Laurent@925: bbox = wx.Rect(xw, yw, width, height) Laurent@925: if bbox.InsideXY(x_mouse, y_mouse): Laurent@943: panel.ShowButtons(True) Laurent@925: merge_type = GRAPH_PARALLEL Laurent@943: if isinstance(panel, DebugVariableText) or panel.Is3DCanvas(): Laurent@925: if y_mouse > yw + height / 2: Laurent@925: idx += 1 Laurent@945: wx.CallAfter(self.MoveValue, variable, idx) Laurent@925: else: Laurent@925: rect = panel.GetAxesBoundingBox(True) Laurent@925: if rect.InsideXY(x_mouse, y_mouse): Laurent@925: merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height) Laurent@925: if merge_rect.InsideXY(x_mouse, y_mouse): Laurent@925: merge_type = GRAPH_ORTHOGONAL Laurent@925: wx.CallAfter(self.MergeGraphs, variable, idx, merge_type, force=True) Laurent@925: else: Laurent@925: if y_mouse > yw + height / 2: Laurent@925: idx += 1 Laurent@945: wx.CallAfter(self.MoveValue, variable, idx) Laurent@929: self.ForceRefresh() Laurent@929: return Laurent@929: width, height = self.GraphicsWindow.GetVirtualSize() Laurent@929: rect = wx.Rect(0, 0, width, height) Laurent@929: if rect.InsideXY(x_mouse, y_mouse): Laurent@945: wx.CallAfter(self.MoveValue, variable, len(self.GraphicPanels)) Laurent@925: self.ForceRefresh() Laurent@925: Laurent@916: def RefreshView(self, only_values=False): Laurent@909: if USE_MPL: Laurent@916: self.RefreshCanvasPosition() Laurent@916: Laurent@929: width, height = self.GraphicsWindow.GetVirtualSize() Laurent@929: bitmap = wx.EmptyBitmap(width, height) Laurent@946: dc = wx.BufferedDC(wx.ClientDC(self.GraphicsWindow), bitmap) Laurent@929: dc.Clear() Laurent@929: dc.BeginDrawing() Laurent@929: if self.DraggingAxesPanel is not None: Laurent@929: destBBox = self.DraggingAxesBoundingBox Laurent@929: srcBBox = self.DraggingAxesPanel.GetAxesBoundingBox() Laurent@929: Laurent@943: srcBmp = _convert_agg_to_wx_bitmap(self.DraggingAxesPanel.get_renderer(), None) Laurent@929: srcDC = wx.MemoryDC() Laurent@929: srcDC.SelectObject(srcBmp) Laurent@929: Laurent@929: dc.Blit(destBBox.x, destBBox.y, Laurent@929: int(destBBox.width), int(destBBox.height), Laurent@929: srcDC, srcBBox.x, srcBBox.y) Laurent@929: dc.EndDrawing() Laurent@929: Laurent@909: if not self.Fixed or self.Force: Laurent@909: self.Force = False Laurent@916: refresh_graphics = True Laurent@916: else: Laurent@916: refresh_graphics = False Laurent@916: Laurent@929: if self.DraggingAxesPanel is not None and self.DraggingAxesPanel not in self.GraphicPanels: Laurent@943: self.DraggingAxesPanel.RefreshViewer(refresh_graphics) Laurent@916: for panel in self.GraphicPanels: Laurent@916: if isinstance(panel, DebugVariableGraphic): Laurent@943: panel.RefreshViewer(refresh_graphics) Laurent@907: else: Laurent@943: panel.RefreshViewer() Laurent@928: Laurent@928: if self.CursorTick is not None: Laurent@928: tick = self.CursorTick Laurent@928: elif len(self.Ticks) > 0: Laurent@928: tick = self.Ticks[-1] Laurent@928: else: Laurent@928: tick = None Laurent@928: if tick is not None: Laurent@928: self.TickLabel.SetLabel("Tick: %d" % tick) Laurent@1192: tick_duration = int(tick * self.Ticktime) Laurent@1192: not_null = False Laurent@1192: duration = "" Laurent@1192: for value, format in [(tick_duration / DAY, "%dd"), Laurent@1192: ((tick_duration % DAY) / HOUR, "%dh"), Laurent@1192: ((tick_duration % HOUR) / MINUTE, "%dm"), Laurent@1192: ((tick_duration % MINUTE) / SECOND, "%ds")]: Laurent@928: Laurent@1192: if value > 0 or not_null: Laurent@1192: duration += format % value Laurent@1192: not_null = True Laurent@1192: Laurent@1192: duration += "%gms" % (float(tick_duration % SECOND) / MILLISECOND) Laurent@1192: self.TickTimeLabel.SetLabel("t: %s" % duration) Laurent@928: else: Laurent@928: self.TickLabel.SetLabel("") Laurent@928: self.TickTimeLabel.SetLabel("") Laurent@928: self.TickSizer.Layout() Laurent@916: else: Laurent@916: self.Freeze() Laurent@916: Laurent@916: if only_values: Laurent@916: for col in xrange(self.Table.GetNumberCols()): Laurent@916: if self.Table.GetColLabelValue(col, False) == "Value": Laurent@916: for row in xrange(self.Table.GetNumberRows()): Laurent@916: self.VariablesGrid.SetCellValue(row, col, str(self.Table.GetValueByName(row, "Value"))) Laurent@916: else: Laurent@916: self.Table.ResetView(self.VariablesGrid) Laurent@916: self.VariablesGrid.RefreshButtons() Laurent@916: Laurent@916: self.Thaw() Laurent@916: Laurent@814: def UnregisterObsoleteData(self): Laurent@1176: self.SubscribeAllDataConsumers() Laurent@916: if USE_MPL: Laurent@916: if self.DataProducer is not None: Laurent@1192: if self.DataProducer is not None: Laurent@1192: self.SetTickTime(self.DataProducer.GetTicktime()) Laurent@916: Laurent@916: for panel in self.GraphicPanels: Laurent@916: panel.UnregisterObsoleteData() Laurent@924: if panel.IsEmpty(): Laurent@943: if panel.HasCapture(): Laurent@943: panel.ReleaseMouse() Laurent@924: self.GraphicPanels.remove(panel) Laurent@924: panel.Destroy() Laurent@924: Laurent@928: self.ResetVariableNameMask() Laurent@924: self.RefreshGraphicsSizer() Laurent@924: self.ForceRefresh() Laurent@916: Laurent@916: else: Laurent@916: items = [(idx, item) for idx, item in enumerate(self.Table.GetData())] Laurent@916: items.reverse() Laurent@916: for idx, item in items: Laurent@1102: iec_path = item.GetVariable() Laurent@916: if self.GetDataType(iec_path) is None: Laurent@916: self.RemoveDataConsumer(item) Laurent@916: self.Table.RemoveItem(idx) Laurent@916: else: Laurent@1102: self.AddDataConsumer(iec_path.upper(), item) Laurent@916: item.RefreshVariableType() Laurent@916: self.Freeze() Laurent@916: self.Table.ResetView(self.VariablesGrid) Laurent@916: self.VariablesGrid.RefreshButtons() Laurent@916: self.Thaw() Laurent@916: Laurent@916: def ResetView(self): Laurent@1176: self.UnsubscribeAllDataConsumers() Laurent@916: if USE_MPL: Laurent@927: self.Fixed = False Laurent@916: for panel in self.GraphicPanels: Laurent@916: panel.Destroy() Laurent@916: self.GraphicPanels = [] Laurent@928: self.ResetVariableNameMask() Laurent@916: self.RefreshGraphicsSizer() Laurent@916: else: Laurent@916: self.Table.Empty() Laurent@916: self.Freeze() Laurent@916: self.Table.ResetView(self.VariablesGrid) Laurent@916: self.VariablesGrid.RefreshButtons() Laurent@916: self.Thaw() Laurent@814: Laurent@916: def RefreshCanvasPosition(self): Laurent@902: if len(self.Ticks) > 0: Laurent@902: pos = int(self.StartTick - self.Ticks[0]) Laurent@902: range = int(self.Ticks[-1] - self.Ticks[0]) Laurent@902: else: Laurent@902: pos = 0 Laurent@902: range = 0 Laurent@902: self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange) Laurent@902: Laurent@814: def GetForceVariableMenuFunction(self, iec_path, item): Laurent@814: iec_type = self.GetDataType(iec_path) Laurent@814: def ForceVariableFunction(event): Laurent@814: if iec_type is not None: Laurent@814: dialog = ForceVariableDialog(self, iec_type, str(item.GetValue())) Laurent@814: if dialog.ShowModal() == wx.ID_OK: Laurent@1102: self.ForceDataValue(iec_path.upper(), dialog.GetValue()) Laurent@814: return ForceVariableFunction Laurent@814: Laurent@814: def GetReleaseVariableMenuFunction(self, iec_path): Laurent@814: def ReleaseVariableFunction(event): Laurent@814: self.ReleaseDataValue(iec_path) Laurent@814: return ReleaseVariableFunction Laurent@814: Laurent@892: def OnVariablesGridCellLeftClick(self, event): Laurent@892: if event.GetCol() == 0: Laurent@892: row = event.GetRow() Laurent@898: data = wx.TextDataObject(str((self.Table.GetValueByName(row, "Variable"), "debug"))) Laurent@892: dragSource = wx.DropSource(self.VariablesGrid) Laurent@892: dragSource.SetData(data) Laurent@892: dragSource.DoDragDrop() Laurent@892: event.Skip() Laurent@892: Laurent@814: def OnVariablesGridCellRightClick(self, event): Laurent@814: row, col = event.GetRow(), event.GetCol() Laurent@814: if self.Table.GetColLabelValue(col, False) == "Value": Laurent@814: iec_path = self.Table.GetValueByName(row, "Variable").upper() Laurent@814: Laurent@814: menu = wx.Menu(title='') Laurent@814: Laurent@814: new_id = wx.NewId() Laurent@814: AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value")) Laurent@814: self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id) Laurent@814: Laurent@814: new_id = wx.NewId() Laurent@814: AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value")) Laurent@814: self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id) Laurent@814: Laurent@814: if self.Table.IsForced(row): Laurent@814: menu.Enable(new_id, True) Laurent@814: else: Laurent@814: menu.Enable(new_id, False) Laurent@814: Laurent@814: self.PopupMenu(menu) Laurent@814: Laurent@814: menu.Destroy() Laurent@814: event.Skip() Laurent@814: Laurent@932: def ChangeRange(self, dir, tick=None): Laurent@928: current_range = self.CurrentRange Laurent@928: current_range_idx = self.CanvasRange.GetSelection() Laurent@1191: new_range_idx = max(0, min(current_range_idx + dir, len(RANGE_VALUES) - 1)) Laurent@928: if new_range_idx != current_range_idx: Laurent@928: self.CanvasRange.SetSelection(new_range_idx) Laurent@1191: self.CurrentRange = RANGE_VALUES[new_range_idx][1] / self.Ticktime Laurent@928: if len(self.Ticks) > 0: Laurent@932: if tick is None: Laurent@932: tick = self.StartTick + self.CurrentRange / 2. Laurent@928: new_start_tick = tick - (tick - self.StartTick) * self.CurrentRange / current_range Laurent@928: self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - new_start_tick))] Laurent@928: self.Fixed = self.StartTick < self.Ticks[-1] - self.CurrentRange Laurent@928: self.ForceRefresh() Laurent@928: Laurent@902: def RefreshRange(self): Laurent@902: if len(self.Ticks) > 0: Laurent@902: if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange: Laurent@902: self.Fixed = False Laurent@902: if self.Fixed: Laurent@902: self.StartTick = min(self.StartTick, self.Ticks[-1] - self.CurrentRange) Laurent@902: else: Laurent@902: self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange) Laurent@924: self.ForceRefresh() Laurent@902: Laurent@902: def OnRangeChanged(self, event): Laurent@902: try: Laurent@1191: self.CurrentRange = RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime Laurent@902: except ValueError, e: Laurent@902: self.CanvasRange.SetValue(str(self.CurrentRange)) Laurent@902: wx.CallAfter(self.RefreshRange) Laurent@902: event.Skip() Laurent@902: Laurent@902: def OnCurrentButton(self, event): Laurent@902: if len(self.Ticks) > 0: Laurent@902: self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange) Laurent@902: self.Fixed = False Laurent@928: self.ResetCursorTick() Laurent@902: event.Skip() Laurent@902: Laurent@902: def CopyDataToClipboard(self, variables): Laurent@924: text = "tick;%s;\n" % ";".join([item.GetVariable() for item, data in variables]) Laurent@902: next_tick = NextTick(variables) Laurent@902: while next_tick is not None: Laurent@902: values = [] Laurent@924: for item, data in variables: Laurent@902: if len(data) > 0: Laurent@902: if next_tick == data[0][0]: Laurent@924: var_type = item.GetVariableType() Laurent@924: if var_type in ["STRING", "WSTRING"]: Laurent@924: value = item.GetRawValue(int(data.pop(0)[2])) Laurent@924: if var_type == "STRING": Laurent@924: values.append("'%s'" % value) Laurent@924: else: Laurent@924: values.append('"%s"' % value) Laurent@924: else: Laurent@924: values.append("%.3f" % data.pop(0)[1]) Laurent@902: else: Laurent@902: values.append("") Laurent@902: else: Laurent@902: values.append("") Laurent@902: text += "%d;%s;\n" % (next_tick, ";".join(values)) Laurent@902: next_tick = NextTick(variables) Laurent@902: self.ParentWindow.SetCopyBuffer(text) Laurent@902: Laurent@902: def OnExportGraphButton(self, event): Laurent@902: variables = [] Laurent@924: if USE_MPL: Laurent@924: items = [] Laurent@924: for panel in self.GraphicPanels: Laurent@924: items.extend(panel.GetItems()) Laurent@924: else: Laurent@924: items = self.Table.GetData() Laurent@924: for item in items: Laurent@902: if item.IsNumVariable(): Laurent@924: variables.append((item, [entry for entry in item.GetData()])) Laurent@902: wx.CallAfter(self.CopyDataToClipboard, variables) Laurent@902: event.Skip() Laurent@902: Laurent@902: def OnPositionChanging(self, event): Laurent@902: if len(self.Ticks) > 0: Laurent@902: self.StartTick = self.Ticks[0] + event.GetPosition() Laurent@902: self.Fixed = True Laurent@924: self.ForceRefresh() Laurent@902: event.Skip() Laurent@902: Laurent@916: def GetRange(self): Laurent@916: return self.StartTick, self.StartTick + self.CurrentRange Laurent@916: Laurent@916: def GetViewerIndex(self, viewer): Laurent@916: if viewer in self.GraphicPanels: Laurent@916: return self.GraphicPanels.index(viewer) Laurent@916: return None Laurent@916: Laurent@934: def IsViewerFirst(self, viewer): Laurent@934: return viewer == self.GraphicPanels[0] Laurent@934: Laurent@934: def IsViewerLast(self, viewer): Laurent@934: return viewer == self.GraphicPanels[-1] Laurent@934: Laurent@934: def HighlightPreviousViewer(self, viewer): Laurent@934: if self.IsViewerFirst(viewer): Laurent@934: return Laurent@934: idx = self.GetViewerIndex(viewer) Laurent@934: if idx is None: Laurent@934: return Laurent@943: self.GraphicPanels[idx-1].SetHighlight(HIGHLIGHT_AFTER) Laurent@934: Laurent@928: def ResetVariableNameMask(self): Laurent@928: items = [] Laurent@928: for panel in self.GraphicPanels: Laurent@928: items.extend(panel.GetItems()) Laurent@928: if len(items) > 1: Laurent@928: self.VariableNameMask = reduce(compute_mask, Laurent@928: [item.GetVariable().split('.') for item in items]) Laurent@928: elif len(items) > 0: Laurent@928: self.VariableNameMask = items[0].GetVariable().split('.')[:-1] + ['*'] Laurent@928: else: Laurent@928: self.VariableNameMask = [] Laurent@931: self.MaskLabel.ChangeValue(".".join(self.VariableNameMask)) Laurent@931: self.MaskLabel.SetInsertionPoint(self.MaskLabel.GetLastPosition()) Laurent@928: Laurent@928: def GetVariableNameMask(self): Laurent@928: return self.VariableNameMask Laurent@928: Laurent@909: def InsertValue(self, iec_path, idx = None, force=False): Laurent@916: if USE_MPL: Laurent@916: for panel in self.GraphicPanels: Laurent@916: if panel.GetItem(iec_path) is not None: Laurent@916: return Laurent@916: if idx is None: Laurent@916: idx = len(self.GraphicPanels) Laurent@916: else: Laurent@916: for item in self.Table.GetData(): Laurent@916: if iec_path == item.GetVariable(): Laurent@916: return Laurent@916: if idx is None: Laurent@916: idx = self.Table.GetNumberRows() Laurent@1193: item = DebugVariableItem(self, iec_path, USE_MPL) Laurent@814: result = self.AddDataConsumer(iec_path.upper(), item) Laurent@814: if result is not None or force: Laurent@916: Laurent@916: if USE_MPL: Laurent@916: if item.IsNumVariable(): Laurent@916: panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL) Laurent@928: if self.CursorTick is not None: Laurent@928: panel.SetCursorTick(self.CursorTick) Laurent@916: else: Laurent@916: panel = DebugVariableText(self.GraphicsWindow, self, [item]) Laurent@916: if idx is not None: Laurent@916: self.GraphicPanels.insert(idx, panel) Laurent@916: else: Laurent@916: self.GraphicPanels.append(panel) Laurent@928: self.ResetVariableNameMask() Laurent@916: self.RefreshGraphicsSizer() Laurent@1008: self.ForceRefresh() Laurent@916: else: Laurent@916: self.Table.InsertItem(idx, item) Laurent@1008: self.RefreshView() Laurent@916: Laurent@945: def MoveValue(self, iec_path, idx = None): Laurent@919: if idx is None: Laurent@919: idx = len(self.GraphicPanels) Laurent@919: source_panel = None Laurent@919: item = None Laurent@919: for panel in self.GraphicPanels: Laurent@919: item = panel.GetItem(iec_path) Laurent@919: if item is not None: Laurent@919: source_panel = panel Laurent@919: break Laurent@919: if source_panel is not None: Laurent@919: source_panel.RemoveItem(item) Laurent@1041: source_size = source_panel.GetSize() Laurent@919: if source_panel.IsEmpty(): Laurent@943: if source_panel.HasCapture(): Laurent@943: source_panel.ReleaseMouse() Laurent@919: self.GraphicPanels.remove(source_panel) Laurent@919: source_panel.Destroy() Laurent@919: Laurent@945: if item.IsNumVariable(): Laurent@945: panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL) Laurent@1041: panel.SetCanvasSize(source_size.width, source_size.height) Laurent@945: if self.CursorTick is not None: Laurent@945: panel.SetCursorTick(self.CursorTick) Laurent@945: else: Laurent@945: panel = DebugVariableText(self.GraphicsWindow, self, [item]) Laurent@919: self.GraphicPanels.insert(idx, panel) Laurent@928: self.ResetVariableNameMask() Laurent@919: self.RefreshGraphicsSizer() Laurent@924: self.ForceRefresh() Laurent@919: Laurent@916: def MergeGraphs(self, source, target_idx, merge_type, force=False): Laurent@909: source_item = None Laurent@916: source_panel = None Laurent@916: for panel in self.GraphicPanels: Laurent@916: source_item = panel.GetItem(source) Laurent@916: if source_item is not None: Laurent@916: source_panel = panel Laurent@916: break Laurent@909: if source_item is None: Laurent@1193: item = DebugVariableItem(self, source, USE_MPL) Laurent@909: if item.IsNumVariable(): Laurent@909: result = self.AddDataConsumer(source.upper(), item) Laurent@909: if result is not None or force: Laurent@909: source_item = item Laurent@945: if source_item is not None and source_item.IsNumVariable(): Laurent@1041: if source_panel is not None: Laurent@1041: source_size = source_panel.GetSize() Laurent@1041: else: Laurent@1041: source_size = None Laurent@916: target_panel = self.GraphicPanels[target_idx] Laurent@916: graph_type = target_panel.GraphType Laurent@916: if target_panel != source_panel: Laurent@916: if (merge_type == GRAPH_PARALLEL and graph_type != merge_type or Laurent@909: merge_type == GRAPH_ORTHOGONAL and Laurent@916: (graph_type == GRAPH_PARALLEL and len(target_panel.Items) > 1 or Laurent@916: graph_type == GRAPH_ORTHOGONAL and len(target_panel.Items) >= 3)): Laurent@909: return Laurent@909: Laurent@916: if source_panel is not None: Laurent@916: source_panel.RemoveItem(source_item) Laurent@916: if source_panel.IsEmpty(): Laurent@943: if source_panel.HasCapture(): Laurent@943: source_panel.ReleaseMouse() Laurent@916: self.GraphicPanels.remove(source_panel) Laurent@916: source_panel.Destroy() Laurent@936: elif (merge_type != graph_type and len(target_panel.Items) == 2): Laurent@936: target_panel.RemoveItem(source_item) Laurent@936: else: Laurent@936: target_panel = None Laurent@936: Laurent@936: if target_panel is not None: Laurent@916: target_panel.AddItem(source_item) Laurent@916: target_panel.GraphType = merge_type Laurent@1041: size = target_panel.GetSize() Laurent@1041: if merge_type == GRAPH_ORTHOGONAL: Laurent@1041: target_panel.SetCanvasSize(size.width, size.width) Laurent@1041: elif source_size is not None: Laurent@1041: target_panel.SetCanvasSize(size.width, size.height + source_size.height) Laurent@1041: else: Laurent@1041: target_panel.SetCanvasSize(size.width, size.height) Laurent@916: target_panel.ResetGraphics() Laurent@909: Laurent@928: self.ResetVariableNameMask() Laurent@916: self.RefreshGraphicsSizer() Laurent@924: self.ForceRefresh() Laurent@916: Laurent@916: def DeleteValue(self, source_panel, item=None): Laurent@916: source_idx = self.GetViewerIndex(source_panel) Laurent@916: if source_idx is not None: Laurent@916: Laurent@916: if item is None: Laurent@916: source_panel.Clear() Laurent@916: source_panel.Destroy() Laurent@916: self.GraphicPanels.remove(source_panel) Laurent@928: self.ResetVariableNameMask() Laurent@916: self.RefreshGraphicsSizer() Laurent@916: else: Laurent@916: source_panel.RemoveItem(item) Laurent@916: if source_panel.IsEmpty(): Laurent@916: source_panel.Destroy() Laurent@916: self.GraphicPanels.remove(source_panel) Laurent@928: self.ResetVariableNameMask() Laurent@916: self.RefreshGraphicsSizer() Laurent@924: self.ForceRefresh() Laurent@916: Laurent@887: def ResetGraphicsValues(self): Laurent@888: if USE_MPL: Laurent@916: self.Ticks = numpy.array([]) Laurent@916: self.StartTick = 0 Laurent@927: self.Fixed = False Laurent@916: for panel in self.GraphicPanels: Laurent@916: panel.ResetData() Laurent@1084: self.ResetCursorTick() Laurent@916: Laurent@916: def RefreshGraphicsWindowScrollbars(self): Laurent@916: xstart, ystart = self.GraphicsWindow.GetViewStart() Laurent@916: window_size = self.GraphicsWindow.GetClientSize() Laurent@916: vwidth, vheight = self.GraphicsSizer.GetMinSize() Laurent@887: posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT)) Laurent@887: posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT)) Laurent@916: self.GraphicsWindow.Scroll(posx, posy) Laurent@916: self.GraphicsWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, Laurent@887: vwidth / SCROLLBAR_UNIT, vheight / SCROLLBAR_UNIT, posx, posy) Laurent@887: Laurent@988: def OnGraphicsWindowEraseBackground(self, event): Laurent@988: pass Laurent@988: Laurent@988: def OnGraphicsWindowPaint(self, event): Laurent@988: self.RefreshView() Laurent@988: event.Skip() Laurent@988: Laurent@916: def OnGraphicsWindowResize(self, event): Laurent@1041: size = self.GetSize() Laurent@1041: for panel in self.GraphicPanels: Laurent@1041: panel_size = panel.GetSize() Laurent@1193: if (isinstance(panel, DebugVariableGraphic) and Laurent@1193: panel.GraphType == GRAPH_ORTHOGONAL and Laurent@1193: panel_size.width == panel_size.height): Laurent@1041: panel.SetCanvasSize(size.width, size.width) Laurent@916: self.RefreshGraphicsWindowScrollbars() Laurent@1194: self.GraphicsSizer.Layout() Laurent@924: event.Skip() Laurent@1040: Laurent@1040: def OnGraphicsWindowMouseWheel(self, event): Laurent@1040: if self.VetoScrollEvent: Laurent@1040: self.VetoScrollEvent = False Laurent@1040: else: Laurent@1040: event.Skip()