source: trunk/src/testing/dim/globals.py @ 4

Revision 4, 6.5 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
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)
42OVERLAY_POINTER = "pointer"   
43OVERLAY_APP = "app"      # app checker
44OVERLAY_WALL = "wall"
45
46# btnIDs
47BTN_LEFT   = 1
48BTN_RIGHT  = 2
49BTN_MIDDLE = 3
50
51# arrow IDs
52ARROW_UP    = 1
53ARROW_DOWN  = 2
54ARROW_LEFT  = 3
55ARROW_RIGHT = 4
56
57
58# pointer orientations
59BOTTOM_LEFT  = 1
60TOP_LEFT     = 2
61TOP_RIGHT    = 3
62BOTTOM_RIGHT = 4
63
64
65# z order
66BOTTOM_Z = 99999
67TOP_Z    = -1
68
69
70# draw order for SAGE
71POST_DRAW = 0
72INTER_DRAW = 1
73PRE_DRAW = 2
74
75
76#-----------------------------------------------------
77#       EVENTS
78#-----------------------------------------------------
79
80# EVENT TYPES
81DEVICE_EVENT    = 1  # position dependent
82GENERIC_EVENT   = 2  # sent to everybody that is listening
83
84# device event IDs
85EVT_CLICK   = 0
86EVT_MOVE    = 2
87EVT_ANALOG1 = 3
88EVT_PAN     = 3 # alias
89EVT_DRAG    = 3 # alias
90EVT_ANALOG2 = 4
91EVT_ROTATE  = 4 # alias
92EVT_ANALOG3 = 5
93EVT_ZOOM    = 5 # alias
94EVT_ARROW   = 6
95EVT_KEY     = 7
96EVT_CUSTOM  = 8
97EVT_ENTERED_WINDOW = 9
98EVT_LEFT_WINDOW = 10
99
100# special device events
101EVT_CLICK_SPECIAL   = 20
102EVT_MOVE_SPECIAL    = 22
103EVT_ANALOG1_SPECIAL = 23
104EVT_PAN_SPECIAL     = 23 # alias
105EVT_DRAG_SPECIAL    = 23 # alias
106EVT_ANALOG2_SPECIAL = 24
107EVT_ROTATE_SPECIAL  = 24 # alias
108EVT_ANALOG3_SPECIAL = 25
109EVT_ZOOM_SPECIAL    = 25 # alias
110EVT_ARROW_SPECIAL   = 26
111EVT_KEY_SPECIAL     = 27
112EVT_CUSTOM_SPECIAL  = 28
113EVT_ENTERED_WINDOW_SPECIAL = 29
114EVT_LEFT_WINDOW_SPECIAL = 30
115
116# generic event IDs
117EVT_APP_INFO  = 50
118EVT_PERF_INFO = 51
119EVT_NEW_APP   = 52
120EVT_APP_KILLED = 53
121EVT_Z_CHANGE  = 54
122EVT_OBJECT_INFO = 55
123EVT_DISPLAY_INFO = 56
124
125
126
127#-----------------------------------------------------
128#       GLOBAL ACCESS VARIABLES
129#-----------------------------------------------------
130
131# EventManager - so that everybody can access it
132global evtMgr
133def setEvtMgr(em):
134    global evtMgr
135    evtMgr = em
136
137def getEvtMgr():
138    return evtMgr
139
140
141
142# DeviceManager - so that everybody can access it
143global devMgr
144def setDevMgr(dm):
145    global devMgr
146    devMgr = dm
147
148def getDevMgr():
149    return devMgr
150
151
152
153# OverlayManager - so that everybody can access it
154global overlayMgr
155def setOverlayMgr(om):
156    global overlayMgr
157    overlayMgr = om
158
159def getOverlayMgr():
160    return overlayMgr
161
162
163
164# SageGate - so that everybody can access it
165global sageGate
166def setSageGate(q):
167    global sageGate
168    sageGate = q
169
170def getSageGate():
171    return sageGate
172
173
174# SageData - so that everybody can access it
175global sageData
176def setSageData(d):
177    global sageData
178    sageData = d
179
180def getSageData():
181    return sageData
182
183
184
185   
186sageServer = "localhost"
187def setSAGEServer(server):
188    global sageServer
189    sageServer = server
190
191def getSAGEServer():
192    return sageServer
193
194
195
196# for quitting the whole application
197global run
198run = True
199def exitApp():
200    global run
201    run = False
202    getOverlayMgr().removeAllOverlays()
203def doRun():
204    return run
205
206
207
208
209class 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
Note: See TracBrowser for help on using the repository browser.