]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/ogl/_diagram.py
   1 # -*- coding: iso-8859-1 -*- 
   2 #---------------------------------------------------------------------------- 
   4 # Purpose:      Diagram class 
   6 # Author:       Pierre Hjälm (from C++ original by Julian Smart) 
  10 # Copyright:    (c) 2004 Pierre Hjälm - 1998 Julian Smart 
  11 # Licence:      wxWindows license 
  12 #---------------------------------------------------------------------------- 
  16 DEFAULT_MOUSE_TOLERANCE 
= 3 
  20 class Diagram(object): 
  21     """Encapsulates an entire diagram, with methods for drawing. A diagram has 
  22     an associated ShapeCanvas. 
  28         self
._diagramCanvas 
= None 
  29         self
._quickEditMode 
= False 
  30         self
._snapToGrid 
= True 
  31         self
._gridSpacing 
= 5.0 
  33         self
._mouseTolerance 
= DEFAULT_MOUSE_TOLERANCE
 
  36         """Draw the shapes in the diagram on the specified device context.""" 
  39                 self
.GetCanvas().SetCursor(wx
.HOURGLASS_CURSOR
) 
  40             for object in self
._shapeList
: 
  43                 self
.GetCanvas().SetCursor(wx
.STANDARD_CURSOR
) 
  46         """Clear the specified device context.""" 
  49     def AddShape(self
, object, addAfter 
= None): 
  50         """Adds a shape to the diagram. If addAfter is not None, the shape 
  51         will be added after addAfter. 
  53         if not object in self
._shapeList
: 
  55                 self
._shapeList
.insert(self
._shapeList
.index(addAfter
) + 1, object) 
  57                 self
._shapeList
.append(object) 
  59             object.SetCanvas(self
.GetCanvas()) 
  61     def InsertShape(self
, object): 
  62         """Insert a shape at the front of the shape list.""" 
  63         self
._shapeList
.insert(0, object) 
  65     def RemoveShape(self
, object): 
  66         """Remove the shape from the diagram (non-recursively) but do not 
  69         if object in self
._shapeList
: 
  70             self
._shapeList
.remove(object) 
  72     def RemoveAllShapes(self
): 
  73         """Remove all shapes from the diagram but do not delete the shapes.""" 
  76     def DeleteAllShapes(self
): 
  77         """Remove and delete all shapes in the diagram.""" 
  78         for shape 
in self
._shapeList
[:]: 
  79             if not shape
.GetParent(): 
  80                 self
.RemoveShape(shape
) 
  82     def ShowAll(self
, show
): 
  83         """Call Show for each shape in the diagram.""" 
  84         for shape 
in self
._shapeList
: 
  87     def DrawOutline(self
, dc
, x1
, y1
, x2
, y2
): 
  88         """Draw an outline rectangle on the current device context.""" 
  89         dc
.SetPen(wx
.Pen(wx
.Color(0, 0, 0), 1, wx
.DOT
)) 
  90         dc
.SetBrush(wx
.TRANSPARENT_BRUSH
) 
  92         dc
.DrawLines([[x1
, y1
], [x2
, y1
], [x2
, y2
], [x1
, y2
], [x1
, y1
]]) 
  94     def RecentreAll(self
, dc
): 
  95         """Make sure all text that should be centred, is centred.""" 
  96         for shape 
in self
._shapeList
: 
  99     def SetCanvas(self
, canvas
): 
 100         """Set the canvas associated with this diagram.""" 
 101         self
._diagramCanvas 
= canvas
 
 104         """Return the shape canvas associated with this diagram.""" 
 105         return self
._diagramCanvas
 
 107     def FindShape(self
, id): 
 108         """Return the shape for the given identifier.""" 
 109         for shape 
in self
._shapeList
: 
 110             if shape
.GetId() == id: 
 114     def Snap(self
, x
, y
): 
 115         """'Snaps' the coordinate to the nearest grid position, if 
 116         snap-to-grid is on.""" 
 118             return self
._gridSpacing 
* int(x 
/ self
._gridSpacing 
+ 0.5), self
._gridSpacing 
* int(y 
/ self
._gridSpacing 
+ 0.5) 
 121     def SetGridSpacing(self
, spacing
):  
 122         """Sets grid spacing."""  
 123         self
._gridSpacing 
= spacing 
 
 125     def SetSnapToGrid(self
, snap
):  
 126         """Sets snap-to-grid mode."""  
 127         self
._snapToGrid 
= snap 
 
 129     def GetGridSpacing(self
): 
 130         """Return the grid spacing.""" 
 131         return self
._gridSpacing
 
 133     def GetSnapToGrid(self
): 
 134         """Return snap-to-grid mode.""" 
 135         return self
._snapToGrid
 
 137     def SetQuickEditMode(self
, mode
): 
 138         """Set quick-edit-mode on of off. 
 140         In this mode, refreshes are minimized, but the diagram may need 
 141         manual refreshing occasionally. 
 143         self
._quickEditMode 
= mode
 
 145     def GetQuickEditMode(self
): 
 146         """Return quick edit mode.""" 
 147         return self
._quickEditMode
 
 149     def SetMouseTolerance(self
, tolerance
): 
 150         """Set the tolerance within which a mouse move is ignored. 
 152         The default is 3 pixels. 
 154         self
._mouseTolerance 
= tolerance
 
 156     def GetMouseTolerance(self
): 
 157         """Return the tolerance within which a mouse move is ignored.""" 
 158         return self
._mouseTolerance
 
 160     def GetShapeList(self
): 
 161         """Return the internal shape list.""" 
 162         return self
._shapeList
 
 165         """Return the number of shapes in the diagram.""" 
 166         return len(self
._shapeList
)