[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 | import sys, string |
---|
| 42 | |
---|
| 43 | ### Class to hold sage application info |
---|
| 44 | ### An instance of this class should exist for every app Id on SAGE |
---|
| 45 | class SageApp : |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | def __init__(self, name, id, left, right, bottom, top, sailID, zValue, orientation, displayId, title=""): |
---|
| 49 | self.left = left |
---|
| 50 | self.right = right |
---|
| 51 | self.top = top |
---|
| 52 | self.bottom = bottom |
---|
| 53 | self.sailID = sailID |
---|
| 54 | self.appName = name |
---|
| 55 | self.id = id |
---|
| 56 | self.zValue = zValue |
---|
| 57 | self.configNum = 1 |
---|
| 58 | self.title = title |
---|
| 59 | self.capture = -1 # which pointer captured it |
---|
| 60 | self.orientation = 0 # in degrees |
---|
| 61 | self.displayId = 0 |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | def setAll(self, name, id, left, right, bottom, top, sailID, zValue, orientation, displayId): |
---|
| 65 | self.appName = name |
---|
| 66 | self.id = id |
---|
| 67 | self.left = left |
---|
| 68 | self.right = right |
---|
| 69 | self.bottom = bottom |
---|
| 70 | self.top = top |
---|
| 71 | self.sailID = sailID |
---|
| 72 | self.zValue = zValue |
---|
| 73 | self.orientation = orientation |
---|
| 74 | self.displayId = displayId |
---|
| 75 | #self.title = title |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | def getLeft(self): |
---|
| 79 | return self.left |
---|
| 80 | |
---|
| 81 | def getRight(self): |
---|
| 82 | return self.right |
---|
| 83 | |
---|
| 84 | def getTop(self): |
---|
| 85 | return self.top |
---|
| 86 | |
---|
| 87 | def getBottom(self): |
---|
| 88 | return self.bottom |
---|
| 89 | |
---|
| 90 | def getId(self): |
---|
| 91 | return self.id |
---|
| 92 | |
---|
| 93 | def getConfigNum(self): |
---|
| 94 | return self.configNum |
---|
| 95 | |
---|
| 96 | def getTitle(self): |
---|
| 97 | return self.title |
---|
| 98 | |
---|
| 99 | def setTitle(self, newTitle): |
---|
| 100 | self.title = newTitle |
---|
| 101 | |
---|
| 102 | def getWidth(self): |
---|
| 103 | return self.right - self.left |
---|
| 104 | |
---|
| 105 | def getHeight(self): |
---|
| 106 | return self.top - self.bottom |
---|
| 107 | |
---|
| 108 | def getDisplayId(self): |
---|
| 109 | return self.displayId |
---|
| 110 | |
---|
| 111 | def getOrientation(self): |
---|
| 112 | return self.orientation |
---|
| 113 | |
---|
| 114 | def setName(self, appName): |
---|
| 115 | self.appName = appName |
---|
| 116 | |
---|
| 117 | def getName(self): |
---|
| 118 | return self.appName |
---|
| 119 | |
---|
| 120 | #### Get the application window values |
---|
| 121 | #### @return Returns a list Format: [<left>, <right>, <top>, <bottom>] |
---|
| 122 | def getBounds(self) : |
---|
| 123 | return [self.left, self.right, self.top, self.bottom] |
---|
| 124 | |
---|
| 125 | #### Get the app's sailID |
---|
| 126 | def getSailID(self): |
---|
| 127 | return self.sailID |
---|
| 128 | |
---|
| 129 | def setZvalue(self, value): |
---|
| 130 | self.zValue = value |
---|
| 131 | |
---|
| 132 | def getZvalue(self): |
---|
| 133 | return self.zValue |
---|
| 134 | |
---|
| 135 | def hasCapture(self): |
---|
| 136 | if self.capture == -1: |
---|
| 137 | return False |
---|
| 138 | else: |
---|
| 139 | return True |
---|
| 140 | |
---|
| 141 | def captureMouse(self, pointerId): |
---|
| 142 | self.capture = pointerId |
---|
| 143 | |
---|
| 144 | def releaseMouse(self): |
---|
| 145 | self.capture = -1 |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | # checks whether (x,y) hit something on the shape |
---|
| 149 | # calculations are done in the sage coordinate system (bottom left = 0,0) |
---|
| 150 | # 0 = everything else... inside the app |
---|
| 151 | # -2 = hit but not on the corners (BOTTOM) |
---|
| 152 | # -1 = hit but not on the corners (TOP) |
---|
| 153 | # 1 = bottom left corner |
---|
| 154 | # 2 = top left corner |
---|
| 155 | # 3 = top right |
---|
| 156 | # 4 = bottom right |
---|
| 157 | def hitTest(self, x, y, cornerSize=250): |
---|
| 158 | |
---|
| 159 | # utility function |
---|
| 160 | def __inRegion(r): |
---|
| 161 | if x >= r[0] and x <= r[1] and y<=r[2] and y>=r[3]: |
---|
| 162 | return True |
---|
| 163 | return False |
---|
| 164 | |
---|
| 165 | (l,r,t,b,cs) = (self.left, self.right, self.top, self.bottom, cornerSize) |
---|
| 166 | |
---|
| 167 | # define the regions we need to test |
---|
| 168 | testRegions = {} # keyed by -2,-1,1,2,3,4 |
---|
| 169 | testRegions[-2] = (l+cs, r-cs, b+cs, b) |
---|
| 170 | testRegions[-1] = (l+cs, r-cs, t, t-cs) |
---|
| 171 | testRegions[1] = (l, l+cs, b+cs, b) |
---|
| 172 | testRegions[2] = (l, l+cs, t, t-cs) |
---|
| 173 | testRegions[3] = (r-cs, r, t, t-cs) |
---|
| 174 | testRegions[4] = (r-cs, r, b+cs, b) |
---|
| 175 | |
---|
| 176 | # now loop through the regions and test whether x,y is in it |
---|
| 177 | result = 0 |
---|
| 178 | for rid, r in testRegions.iteritems(): |
---|
| 179 | if __inRegion(r): |
---|
| 180 | return rid |
---|
| 181 | |
---|
| 182 | return result |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | ### a class to hold the information about all the available apps that SAGE supports |
---|
| 191 | class SageAppInitial: |
---|
| 192 | |
---|
| 193 | def __init__ (self, name, configNames): |
---|
| 194 | self._name = name |
---|
| 195 | self._configNames = configNames |
---|
| 196 | |
---|
| 197 | def GetName (self): |
---|
| 198 | return self._name |
---|
| 199 | |
---|
| 200 | def SetName (self, name): |
---|
| 201 | self._name = name |
---|
| 202 | |
---|
| 203 | def GetConfigNames(self): |
---|
| 204 | return self._configNames |
---|
| 205 | |
---|
| 206 | ## # execution configurations |
---|
| 207 | ## def AddConfig (self, name, stConfig): |
---|
| 208 | ## self._execConfigs[ len(self._execConfigs)+1 ] = (name, string.strip(stConfig)) |
---|
| 209 | |
---|
| 210 | ## def GetNumConfigs(self): |
---|
| 211 | ## return self._numConfigs |
---|
| 212 | |
---|
| 213 | ## def GetConfigHash (self): |
---|
| 214 | ## return self._execConfigs |
---|
| 215 | |
---|
| 216 | ## def GetConfig (self, configNum): |
---|
| 217 | ## if self._execConfigs.has_key( configNum ): |
---|
| 218 | ## return self._execConfigs[ configNum ] |
---|
| 219 | ## else: |
---|
| 220 | ## print "Error: No configuration number ", configNum |
---|
| 221 | ## return "No Configuration" |
---|
| 222 | |
---|
| 223 | ## # instances already started |
---|
| 224 | ## def AddInstanceId (self, instanceId): |
---|
| 225 | ## self._appInstanceIds.append( instanceId ) |
---|
| 226 | |
---|
| 227 | ## def GetInstanceIds (self): |
---|
| 228 | ## return self._appInstanceIds |
---|
| 229 | |
---|
| 230 | |
---|