[4] | 1 | ############################################################################ |
---|
| 2 | # |
---|
| 3 | # DIM - A Direct Interaction Manager for SAGE |
---|
| 4 | # Copyright (C) 2007 Electronic Visualization Laboratory, |
---|
| 5 | # University of Illinois at Chicago |
---|
| 6 | # |
---|
| 7 | # All rights reserved. |
---|
| 8 | # |
---|
| 9 | # Redistribution and use in source and binary forms, with or without |
---|
| 10 | # modification, are permitted provided that the following conditions are met: |
---|
| 11 | # |
---|
| 12 | # * Redistributions of source code must retain the above copyright |
---|
| 13 | # notice, this list of conditions and the following disclaimer. |
---|
| 14 | # * Redistributions in binary form must reproduce the above |
---|
| 15 | # copyright notice, this list of conditions and the following disclaimer |
---|
| 16 | # in the documentation and/or other materials provided with the distribution. |
---|
| 17 | # * Neither the name of the University of Illinois at Chicago nor |
---|
| 18 | # the names of its contributors may be used to endorse or promote |
---|
| 19 | # products derived from this software without specific prior written permission. |
---|
| 20 | # |
---|
| 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 22 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 23 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 24 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 25 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 26 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 28 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | # |
---|
| 33 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum |
---|
| 34 | # |
---|
| 35 | # Author: Ratko Jagodic |
---|
| 36 | # |
---|
| 37 | ############################################################################ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | # overlay types (these are same as SAGEDrawObject types) |
---|
| 42 | OVERLAY_POINTER = "pointer" |
---|
| 43 | OVERLAY_APP = "app" # app checker |
---|
| 44 | OVERLAY_WALL = "wall" |
---|
| 45 | |
---|
| 46 | # btnIDs |
---|
| 47 | BTN_LEFT = 1 |
---|
| 48 | BTN_RIGHT = 2 |
---|
| 49 | BTN_MIDDLE = 3 |
---|
| 50 | |
---|
| 51 | # arrow IDs |
---|
| 52 | ARROW_UP = 1 |
---|
| 53 | ARROW_DOWN = 2 |
---|
| 54 | ARROW_LEFT = 3 |
---|
| 55 | ARROW_RIGHT = 4 |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | # pointer orientations |
---|
| 59 | BOTTOM_LEFT = 1 |
---|
| 60 | TOP_LEFT = 2 |
---|
| 61 | TOP_RIGHT = 3 |
---|
| 62 | BOTTOM_RIGHT = 4 |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | # z order |
---|
| 66 | BOTTOM_Z = 99999 |
---|
| 67 | TOP_Z = -1 |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | # draw order for SAGE |
---|
| 71 | POST_DRAW = 0 |
---|
| 72 | INTER_DRAW = 1 |
---|
| 73 | PRE_DRAW = 2 |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | #----------------------------------------------------- |
---|
| 77 | # EVENTS |
---|
| 78 | #----------------------------------------------------- |
---|
| 79 | |
---|
| 80 | # EVENT TYPES |
---|
| 81 | DEVICE_EVENT = 1 # position dependent |
---|
| 82 | GENERIC_EVENT = 2 # sent to everybody that is listening |
---|
| 83 | |
---|
| 84 | # device event IDs |
---|
| 85 | EVT_CLICK = 0 |
---|
| 86 | EVT_MOVE = 2 |
---|
| 87 | EVT_ANALOG1 = 3 |
---|
| 88 | EVT_PAN = 3 # alias |
---|
| 89 | EVT_DRAG = 3 # alias |
---|
| 90 | EVT_ANALOG2 = 4 |
---|
| 91 | EVT_ROTATE = 4 # alias |
---|
| 92 | EVT_ANALOG3 = 5 |
---|
| 93 | EVT_ZOOM = 5 # alias |
---|
| 94 | EVT_ARROW = 6 |
---|
| 95 | EVT_KEY = 7 |
---|
| 96 | EVT_CUSTOM = 8 |
---|
| 97 | EVT_ENTERED_WINDOW = 9 |
---|
| 98 | EVT_LEFT_WINDOW = 10 |
---|
| 99 | |
---|
| 100 | # special device events |
---|
| 101 | EVT_CLICK_SPECIAL = 20 |
---|
| 102 | EVT_MOVE_SPECIAL = 22 |
---|
| 103 | EVT_ANALOG1_SPECIAL = 23 |
---|
| 104 | EVT_PAN_SPECIAL = 23 # alias |
---|
| 105 | EVT_DRAG_SPECIAL = 23 # alias |
---|
| 106 | EVT_ANALOG2_SPECIAL = 24 |
---|
| 107 | EVT_ROTATE_SPECIAL = 24 # alias |
---|
| 108 | EVT_ANALOG3_SPECIAL = 25 |
---|
| 109 | EVT_ZOOM_SPECIAL = 25 # alias |
---|
| 110 | EVT_ARROW_SPECIAL = 26 |
---|
| 111 | EVT_KEY_SPECIAL = 27 |
---|
| 112 | EVT_CUSTOM_SPECIAL = 28 |
---|
| 113 | EVT_ENTERED_WINDOW_SPECIAL = 29 |
---|
| 114 | EVT_LEFT_WINDOW_SPECIAL = 30 |
---|
| 115 | |
---|
| 116 | # generic event IDs |
---|
| 117 | EVT_APP_INFO = 50 |
---|
| 118 | EVT_PERF_INFO = 51 |
---|
| 119 | EVT_NEW_APP = 52 |
---|
| 120 | EVT_APP_KILLED = 53 |
---|
| 121 | EVT_Z_CHANGE = 54 |
---|
| 122 | EVT_OBJECT_INFO = 55 |
---|
| 123 | EVT_DISPLAY_INFO = 56 |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | #----------------------------------------------------- |
---|
| 128 | # GLOBAL ACCESS VARIABLES |
---|
| 129 | #----------------------------------------------------- |
---|
| 130 | |
---|
| 131 | # EventManager - so that everybody can access it |
---|
| 132 | global evtMgr |
---|
| 133 | def setEvtMgr(em): |
---|
| 134 | global evtMgr |
---|
| 135 | evtMgr = em |
---|
| 136 | |
---|
| 137 | def getEvtMgr(): |
---|
| 138 | return evtMgr |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | # DeviceManager - so that everybody can access it |
---|
| 143 | global devMgr |
---|
| 144 | def setDevMgr(dm): |
---|
| 145 | global devMgr |
---|
| 146 | devMgr = dm |
---|
| 147 | |
---|
| 148 | def getDevMgr(): |
---|
| 149 | return devMgr |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | # OverlayManager - so that everybody can access it |
---|
| 154 | global overlayMgr |
---|
| 155 | def setOverlayMgr(om): |
---|
| 156 | global overlayMgr |
---|
| 157 | overlayMgr = om |
---|
| 158 | |
---|
| 159 | def getOverlayMgr(): |
---|
| 160 | return overlayMgr |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | # SageGate - so that everybody can access it |
---|
| 165 | global sageGate |
---|
| 166 | def setSageGate(q): |
---|
| 167 | global sageGate |
---|
| 168 | sageGate = q |
---|
| 169 | |
---|
| 170 | def getSageGate(): |
---|
| 171 | return sageGate |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | # SageData - so that everybody can access it |
---|
| 175 | global sageData |
---|
| 176 | def setSageData(d): |
---|
| 177 | global sageData |
---|
| 178 | sageData = d |
---|
| 179 | |
---|
| 180 | def getSageData(): |
---|
| 181 | return sageData |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | sageServer = "localhost" |
---|
| 187 | def setSAGEServer(server): |
---|
| 188 | global sageServer |
---|
| 189 | sageServer = server |
---|
| 190 | |
---|
| 191 | def getSAGEServer(): |
---|
| 192 | return sageServer |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | # for quitting the whole application |
---|
| 197 | global run |
---|
| 198 | run = True |
---|
| 199 | def exitApp(): |
---|
| 200 | global run |
---|
| 201 | run = False |
---|
| 202 | getOverlayMgr().removeAllOverlays() |
---|
| 203 | def doRun(): |
---|
| 204 | return run |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | class Bounds: |
---|
| 210 | """ used in event conversion """ |
---|
| 211 | def __init__(self, left=0, right=0, top=0, bottom=0): |
---|
| 212 | self.left = left |
---|
| 213 | self.right = right |
---|
| 214 | self.top = top |
---|
| 215 | self.bottom = bottom |
---|
| 216 | self.setAspectRatio() |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | def setAll(self, left, right, top, bottom): |
---|
| 220 | self.left = left |
---|
| 221 | self.right = right |
---|
| 222 | self.top = top |
---|
| 223 | self.bottom = bottom |
---|
| 224 | self.setAspectRatio() |
---|
| 225 | |
---|
| 226 | def getAll(self): |
---|
| 227 | return self.left, self.right, self.top, self.bottom |
---|
| 228 | |
---|
| 229 | def setAspectRatio(self): |
---|
| 230 | if self.getHeight() != 0: |
---|
| 231 | self.aspectRatio = self.getWidth() / float(self.getHeight()) |
---|
| 232 | else: |
---|
| 233 | self.aspectRatio = 1.0 |
---|
| 234 | |
---|
| 235 | def getAspectRatio(self): |
---|
| 236 | return self.aspectRatio |
---|
| 237 | |
---|
| 238 | def getWidth(self): |
---|
| 239 | return self.right - self.left |
---|
| 240 | |
---|
| 241 | def setWidth(self, w): |
---|
| 242 | self.right = self.left + w |
---|
| 243 | self.setAspectRatio() |
---|
| 244 | |
---|
| 245 | def getHeight(self): |
---|
| 246 | return self.top - self.bottom |
---|
| 247 | |
---|
| 248 | def setHeight(self, h): |
---|
| 249 | self.top = self.bottom + h |
---|
| 250 | self.setAspectRatio() |
---|
| 251 | |
---|
| 252 | def setSize(self, w, h): |
---|
| 253 | self.setWidth(w) |
---|
| 254 | self.setHeight(h) |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | def getX(self): |
---|
| 258 | return self.left |
---|
| 259 | |
---|
| 260 | def getY(self): |
---|
| 261 | return self.bottom |
---|
| 262 | |
---|
| 263 | def setPos(self, x, y): |
---|
| 264 | self.setX(x) |
---|
| 265 | self.setY(y) |
---|
| 266 | |
---|
| 267 | def setX(self, x): |
---|
| 268 | w = self.getWidth() |
---|
| 269 | self.left = x |
---|
| 270 | self.right = x + w |
---|
| 271 | |
---|
| 272 | def setY(self, y): |
---|
| 273 | h = self.getHeight() |
---|
| 274 | self.bottom = y |
---|
| 275 | self.top = y + h |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | def isIn(self, x, y): |
---|
| 279 | """ returns True if the (x,y) is in Bounds, False otherwise """ |
---|
| 280 | if self.left <= x and self.right >= x and self.bottom <= y and self.top >= y: |
---|
| 281 | return True |
---|
| 282 | else: |
---|
| 283 | return False |
---|