controls/DebugVariablePanel.py
changeset 912 bf855ccf3705
parent 909 852af7c6f0ef
child 916 697d8b77d716
equal deleted inserted replaced
910:f6d06bdd31e8 912:bf855ccf3705
   270                 row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
   270                 row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
   271                 if row == wx.NOT_FOUND:
   271                 if row == wx.NOT_FOUND:
   272                     row = self.ParentWindow.Table.GetNumberRows()
   272                     row = self.ParentWindow.Table.GetNumberRows()
   273                 self.ParentWindow.InsertValue(values[0], row, force=True)
   273                 self.ParentWindow.InsertValue(values[0], row, force=True)
   274             else:
   274             else:
   275                 x, y = self.ParentWindow.GraphicsCanvasWindow.CalcUnscrolledPosition(x, y)
       
   276                 width, height = self.ParentWindow.GraphicsCanvas.GetSize()
   275                 width, height = self.ParentWindow.GraphicsCanvas.GetSize()
   277                 target = None
   276                 target = None
   278                 merge_type = GRAPH_PARALLEL
   277                 merge_type = GRAPH_PARALLEL
   279                 for infos in self.ParentWindow.GraphicsAxes:
   278                 for infos in self.ParentWindow.GraphicsAxes:
   280                     ax, ay, aw, ah = infos["axes"].get_position().bounds
   279                     if infos["axes"] != self.ParentWindow.Graphics3DAxes:
   281                     rect = wx.Rect(ax * width, height - (ay + ah) * height,
   280                         ax, ay, aw, ah = infos["axes"].get_position().bounds
   282                                    aw * width, ah * height)
   281                         rect = wx.Rect(ax * width, height - (ay + ah) * height,
   283                     if rect.InsideXY(x, y):
   282                                        aw * width, ah * height)
   284                         target = infos
   283                         if rect.InsideXY(x, y):
   285                         merge_rect = wx.Rect(ax * width, height - (ay + ah) * height,
   284                             target = infos
   286                                              aw * width / 2., ah * height)
   285                             merge_rect = wx.Rect(ax * width, height - (ay + ah) * height,
   287                         if merge_rect.InsideXY(x, y):
   286                                                  aw * width / 2., ah * height)
   288                             merge_type = GRAPH_ORTHOGONAL
   287                             if merge_rect.InsideXY(x, y):
   289                         break
   288                                 merge_type = GRAPH_ORTHOGONAL
       
   289                             break
   290                 self.ParentWindow.MergeGraphs(values[0], target, merge_type, force=True)
   290                 self.ParentWindow.MergeGraphs(values[0], target, merge_type, force=True)
   291             
   291             
   292     def ShowMessage(self, message):
   292     def ShowMessage(self, message):
   293         dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   293         dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   294         dialog.ShowModal()
   294         dialog.ShowModal()
   851                     "plots": []})
   851                     "plots": []})
   852                 
   852                 
   853                 self.ResetGraphics()
   853                 self.ResetGraphics()
   854                 self.RefreshGrid()
   854                 self.RefreshGrid()
   855             
   855             
   856             elif target_infos is not None:
   856             elif target_infos is not None and target_infos != source_infos:
   857                 if (merge_type == GRAPH_PARALLEL and target_infos["type"] != merge_type or
   857                 if (merge_type == GRAPH_PARALLEL and target_infos["type"] != merge_type or
   858                     merge_type == GRAPH_ORTHOGONAL and 
   858                     merge_type == GRAPH_ORTHOGONAL and 
   859                     (target_infos["type"] == GRAPH_PARALLEL and len(target_infos["items"]) > 1 or
   859                     (target_infos["type"] == GRAPH_PARALLEL and len(target_infos["items"]) > 1 or
   860                      target_infos["type"] == GRAPH_ORTHOGONAL and len(target_infos["items"]) >= 3)):
   860                      target_infos["type"] == GRAPH_ORTHOGONAL and len(target_infos["items"]) >= 3)):
       
   861                     print "Graphs not compatible"
   861                     return
   862                     return
   862                 
   863                 
   863                 if source_infos is not None:
   864                 if source_infos is not None:
   864                     source_infos["items"].remove(source_item)
   865                     source_infos["items"].remove(source_item)
   865                     if len(source_infos["items"]) == 0:
   866                     if len(source_infos["items"]) == 0:
   869                 target_infos["type"] = merge_type
   870                 target_infos["type"] = merge_type
   870                 
   871                 
   871                 self.ResetGraphics()
   872                 self.ResetGraphics()
   872                 self.RefreshGrid()
   873                 self.RefreshGrid()
   873             
   874             
       
   875             else:
       
   876                 print "No modification to do"
       
   877             
   874     def GetDebugVariables(self):
   878     def GetDebugVariables(self):
   875         return [item.GetVariable() for item in self.Table.GetData()]
   879         return [item.GetVariable() for item in self.Table.GetData()]
   876     
   880     
   877     def OnGraphicsCanvasClick(self, event):
   881     def OnGraphicsCanvasClick(self, event):
   878         for infos in self.GraphicsAxes:
   882         for infos in self.GraphicsAxes:
   879             if infos["axes"] == event.inaxes:
   883             if infos["axes"] == event.inaxes:
   880                 if len(infos["items"]) == 1:
   884                 if len(infos["items"]) == 1:
   881                     data = wx.TextDataObject(str((infos["items"][0].GetVariable(), "debug")))
   885                     data = wx.TextDataObject(str((infos["items"][0].GetVariable(), "debug")))
   882                     dragSource = wx.DropSource(self.GraphicsCanvas)
   886                     dragSource = wx.DropSource(self)
   883                     dragSource.SetData(data)
   887                     dragSource.SetData(data)
   884                     dragSource.DoDragDrop()
   888                     dragSource.DoDragDrop()
   885                     if self.GraphicsCanvas.HasCapture():
   889                     if self.GraphicsCanvas.HasCapture():
   886                         self.GraphicsCanvas.ReleaseMouse()
   890                         self.GraphicsCanvas.ReleaseMouse()
   887                 break
   891                 break
   908             idx = 1
   912             idx = 1
   909             for infos in self.GraphicsAxes:
   913             for infos in self.GraphicsAxes:
   910                 if infos["type"] != GRAPH_ORTHOGONAL or len(infos["items"]) < 3:
   914                 if infos["type"] != GRAPH_ORTHOGONAL or len(infos["items"]) < 3:
   911                     axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx)
   915                     axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx)
   912                     infos["axes"] = axes
   916                     infos["axes"] = axes
       
   917                     idx += 1
   913                 else:
   918                 else:
   914                     infos["axes"] = self.Graphics3DAxes
   919                     infos["axes"] = self.Graphics3DAxes
   915                 infos["plots"] = []
   920                 infos["plots"] = []
   916                 idx += 1
       
   917             self.RefreshGraphicsCanvasWindowScrollbars()
   921             self.RefreshGraphicsCanvasWindowScrollbars()
   918             self.GraphicsCanvas.draw()
   922             self.GraphicsCanvas.draw()
   919     
   923     
   920     def OnGraphics3DMotion(self, event):
   924     def OnGraphics3DMotion(self, event):
   921         current_time = gettime()
   925         current_time = gettime()
   924             Axes3D._on_move(self.Graphics3DAxes, event)
   928             Axes3D._on_move(self.Graphics3DAxes, event)
   925     
   929     
   926     def RefreshGraphicsCanvasWindowScrollbars(self):
   930     def RefreshGraphicsCanvasWindowScrollbars(self):
   927         xstart, ystart = self.GraphicsCanvasWindow.GetViewStart()
   931         xstart, ystart = self.GraphicsCanvasWindow.GetViewStart()
   928         window_size = self.GraphicsCanvasWindow.GetClientSize()
   932         window_size = self.GraphicsCanvasWindow.GetClientSize()
   929         vwidth, vheight = (window_size[0], (len(self.GraphicsAxes) + 1) * 100)
   933         axes_num = 0
       
   934         for infos in self.GraphicsAxes:
       
   935             if infos["type"] != GRAPH_ORTHOGONAL or len(infos["items"]) < 3:
       
   936                 axes_num += 1
       
   937         vwidth, vheight = (window_size[0], (axes_num + 1) * 80)
   930         self.GraphicsCanvas.SetMinSize(wx.Size(vwidth, vheight))
   938         self.GraphicsCanvas.SetMinSize(wx.Size(vwidth, vheight))
   931         posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
   939         posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
   932         posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
   940         posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
   933         self.GraphicsCanvasWindow.Scroll(posx, posy)
   941         self.GraphicsCanvasWindow.Scroll(posx, posy)
   934         self.GraphicsCanvasWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   942         self.GraphicsCanvasWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,