controls/DebugVariablePanel.py
changeset 919 4a36e38e51d3
parent 916 697d8b77d716
child 924 5f2cc382be8c
equal deleted inserted replaced
918:aa136ef12506 919:4a36e38e51d3
   271             elif self.ParentControl is not None:
   271             elif self.ParentControl is not None:
   272                 width, height = self.ParentControl.Canvas.GetSize()
   272                 width, height = self.ParentControl.Canvas.GetSize()
   273                 target_idx = self.ParentControl.GetIndex()
   273                 target_idx = self.ParentControl.GetIndex()
   274                 merge_type = GRAPH_PARALLEL
   274                 merge_type = GRAPH_PARALLEL
   275                 if self.ParentControl.Is3DCanvas():
   275                 if self.ParentControl.Is3DCanvas():
   276                     self.ParentWindow.InsertValue(values[0], target_idx, force=True)
   276                     if y > height / 2:
       
   277                         target_idx += 1
       
   278                     if len(values) > 2 and values[2] == "move":
       
   279                         self.ParentWindow.MoveGraph(values[0], target_idx)
       
   280                     else:
       
   281                         self.ParentWindow.InsertValue(values[0], target_idx, force=True)
   277                 else:
   282                 else:
   278                     ax, ay, aw, ah = self.ParentControl.Axes.get_position().bounds
   283                     ax, ay, aw, ah = self.ParentControl.Axes.get_position().bounds
   279                     rect = wx.Rect(ax * width, height - (ay + ah) * height,
   284                     rect = wx.Rect(ax * width, height - (ay + ah) * height,
   280                                    aw * width, ah * height)
   285                                    aw * width, ah * height)
   281                     if rect.InsideXY(x, y):
   286                     if rect.InsideXY(x, y):
   283                                              aw * width / 2., ah * height)
   288                                              aw * width / 2., ah * height)
   284                         if merge_rect.InsideXY(x, y):
   289                         if merge_rect.InsideXY(x, y):
   285                             merge_type = GRAPH_ORTHOGONAL
   290                             merge_type = GRAPH_ORTHOGONAL
   286                         wx.CallAfter(self.ParentWindow.MergeGraphs, values[0], target_idx, merge_type, force=True)
   291                         wx.CallAfter(self.ParentWindow.MergeGraphs, values[0], target_idx, merge_type, force=True)
   287                     else:
   292                     else:
   288                         self.ParentWindow.InsertValue(values[0], target_idx, force=True)
   293                         if y > height / 2:
       
   294                             target_idx += 1
       
   295                         if len(values) > 2 and values[2] == "move":
       
   296                             self.ParentWindow.MoveGraph(values[0], target_idx)
       
   297                         else:
       
   298                             self.ParentWindow.InsertValue(values[0], target_idx, force=True)
       
   299             elif len(values) > 2 and values[2] == "move":
       
   300                 self.ParentWindow.MoveGraph(values[0])
   289             else:
   301             else:
   290                 self.ParentWindow.InsertValue(values[0], force=True)
   302                 self.ParentWindow.InsertValue(values[0], force=True)
   291             
   303             
   292     def ShowMessage(self, message):
   304     def ShowMessage(self, message):
   293         dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   305         dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   570                 setattr(self, name, button)
   582                 setattr(self, name, button)
   571                 self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
   583                 self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
   572                 button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
   584                 button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
   573     
   585     
   574         def OnCanvasClick(self, event):
   586         def OnCanvasClick(self, event):
       
   587             x, y = event.GetPosition()
       
   588             width, height = self.Canvas.GetSize()
   575             if len(self.Items) == 1:
   589             if len(self.Items) == 1:
   576                 width, height = self.Canvas.GetSize()
       
   577                 x, y = event.GetPosition()
       
   578                 ax, ay, aw, ah = self.Axes.get_position().bounds
   590                 ax, ay, aw, ah = self.Axes.get_position().bounds
   579                 rect = wx.Rect(ax * width, height - (ay + ah) * height,
   591                 rect = wx.Rect(ax * width, height - (ay + ah) * height,
   580                                aw * width, ah * height)
   592                                aw * width, ah * height)
   581                 if rect.InsideXY(x, y):
   593                 if rect.InsideXY(x, y):
   582                     data = wx.TextDataObject(str((self.Items[0].GetVariable(), "debug")))
   594                     self.DoDragDrop(0)
   583                     dragSource = wx.DropSource(self.Canvas)
   595                     return
   584                     dragSource.SetData(data)
   596             elif self.Legend is not None:
   585                     dragSource.DoDragDrop()
   597                 item_idx = None
   586         
   598                 for i, t in enumerate(self.Legend.get_texts()):
       
   599                     (x0, y0), (x1, y1) = t.get_window_extent().get_points()
       
   600                     rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
       
   601                     if rect.InsideXY(x, y):
       
   602                         item_idx = i
       
   603                         break
       
   604                 if item_idx is not None:
       
   605                     self.DoDragDrop(item_idx)
       
   606                     return
       
   607             event.Skip()
       
   608         
       
   609         def DoDragDrop(self, item_idx):
       
   610             data = wx.TextDataObject(str((self.Items[item_idx].GetVariable(), "debug", "move")))
       
   611             dragSource = wx.DropSource(self.Canvas)
       
   612             dragSource.SetData(data)
       
   613             dragSource.DoDragDrop()
       
   614             
   587         def OnMotion(self, event):
   615         def OnMotion(self, event):
   588             current_time = gettime()
   616             if self.Is3DCanvas():
   589             if current_time - self.LastMotionTime > REFRESH_PERIOD:
   617                 current_time = gettime()
   590                 self.LastMotionTime = current_time
   618                 if current_time - self.LastMotionTime > REFRESH_PERIOD:
   591                 Axes3D._on_move(self.Axes, event)
   619                     self.LastMotionTime = current_time
       
   620                     Axes3D._on_move(self.Axes, event)
   592         
   621         
   593         def OnSplitButton(self, event):
   622         def OnSplitButton(self, event):
   594             if len(self.Items) == 2 or self.GraphType == GRAPH_ORTHOGONAL:
   623             if len(self.Items) == 2 or self.GraphType == GRAPH_ORTHOGONAL:
   595                 wx.CallAfter(self.ParentWindow.SplitGraphs, self)
   624                 wx.CallAfter(self.ParentWindow.SplitGraphs, self)
   596             else:
   625             else:
   711                         self.Axes.set_zlim(z_min, z_max)
   740                         self.Axes.set_zlim(z_min, z_max)
   712                 
   741                 
   713                 self.Axes.set_xlim(x_min, x_max)
   742                 self.Axes.set_xlim(x_min, x_max)
   714                 self.Axes.set_ylim(y_min, y_max)
   743                 self.Axes.set_ylim(y_min, y_max)
   715             
   744             
   716             labels = ["%s: %s" % (item.GetVariable(), item.GetValue())
   745             labels = ["%s: %s" % (item.GetVariable(40), item.GetValue())
   717                       for item in self.Items]
   746                       for item in self.Items]
   718             colors = [{True: 'b', False: 'k'}[item.IsForced()] for item in self.Items]
   747             colors = [{True: 'b', False: 'k'}[item.IsForced()] for item in self.Items]
   719             if self.GraphType == GRAPH_PARALLEL:
   748             if self.GraphType == GRAPH_PARALLEL:
   720                 legend = self.Axes.legend(self.Plots, labels, 
   749                 self.Legend = self.Axes.legend(self.Plots, labels, 
   721                     loc="upper left", frameon=False,
   750                     loc="upper left", frameon=False,
   722                     prop={'size':'small'})
   751                     prop={'size':'small'})
   723                 for t, color in zip(legend.get_texts(), colors):
   752                 for t, color in zip(self.Legend.get_texts(), colors):
   724                     t.set_color(color)
   753                     t.set_color(color)
   725             else:
   754             else:
       
   755                 self.Legend = None
   726                 self.Axes.set_xlabel(labels[0], fontdict={'size':'small','color':colors[0]})
   756                 self.Axes.set_xlabel(labels[0], fontdict={'size':'small','color':colors[0]})
   727                 self.Axes.set_ylabel(labels[1], fontdict={'size':'small','color':colors[1]})
   757                 self.Axes.set_ylabel(labels[1], fontdict={'size':'small','color':colors[1]})
   728                 if len(labels) > 2:
   758                 if len(labels) > 2:
   729                     self.Axes.set_zlabel(labels[2], fontdict={'size':'small','color':colors[2]})
   759                     self.Axes.set_zlabel(labels[2], fontdict={'size':'small','color':colors[2]})
   730             self.Canvas.draw()
   760             self.Canvas.draw()
  1155                     self.GraphicPanels.append(panel)
  1185                     self.GraphicPanels.append(panel)
  1156                 self.RefreshGraphicsSizer()
  1186                 self.RefreshGraphicsSizer()
  1157             else:
  1187             else:
  1158                 self.Table.InsertItem(idx, item)
  1188                 self.Table.InsertItem(idx, item)
  1159             
  1189             
       
  1190             self.RefreshView()
       
  1191     
       
  1192     def MoveGraph(self, iec_path, idx = None):
       
  1193         if idx is None:
       
  1194             idx = len(self.GraphicPanels)
       
  1195         source_panel = None
       
  1196         item = None
       
  1197         for panel in self.GraphicPanels:
       
  1198             item = panel.GetItem(iec_path)
       
  1199             if item is not None:
       
  1200                 source_panel = panel
       
  1201                 break
       
  1202         if source_panel is not None:
       
  1203             source_panel.RemoveItem(item)
       
  1204             if source_panel.IsEmpty():
       
  1205                 if source_panel.Canvas.HasCapture():
       
  1206                     source_panel.Canvas.ReleaseMouse()
       
  1207                 self.GraphicPanels.remove(source_panel)
       
  1208                 source_panel.Destroy()
       
  1209             
       
  1210             panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
       
  1211             self.GraphicPanels.insert(idx, panel)
       
  1212             self.RefreshGraphicsSizer()
  1160             self.RefreshView()
  1213             self.RefreshView()
  1161     
  1214     
  1162     def SplitGraphs(self, source_panel, item=None):
  1215     def SplitGraphs(self, source_panel, item=None):
  1163         source_idx = self.GetViewerIndex(source_panel)
  1216         source_idx = self.GetViewerIndex(source_panel)
  1164         if source_idx is not None:
  1217         if source_idx is not None: