mapViewScannerNavigationStandalone.py (17405B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\mapViewScannerNavigationStandalone.py 2 import blue 3 import geo2 4 import carbonui.const as uiconst 5 import uthread 6 from carbon.client.script.environment.AudioUtil import PlaySound 7 from carbon.common.script.util.mathUtil import RayToPlaneIntersection 8 from carbon.common.script.util.timerstuff import AutoTimer 9 from carbonui.primitives.base import ScaleDpi 10 from carbonui.uicore import uicore 11 from carbonui.util.various_unsorted import SortListOfTuples, IsUnder 12 from eve.client.script.ui.camera.solarSystemMapCameraController import SolarSystemMapCameraController 13 from eve.client.script.ui.control.eveLabel import EveLabelMedium 14 from eve.client.script.ui.inflight.scannerFiles.directionalScanUtil import IsDscanShortcutPressed, GetScanRange, SetScanRange 15 from eve.client.script.ui.shared.mapView.mapViewConst import SOLARSYSTEM_SCALE 16 from eve.client.script.ui.shared.mapView.mapViewNavigation import MapViewNavigation 17 from eve.client.script.ui.shared.mapView.mapViewProbeHandlerStandalone import MODIFY_POSITION, MODIFY_RANGE, MODIFY_SPREAD 18 X_AXIS = (1.0, 0.0, 0.0) 19 Y_AXIS = (0.0, 1.0, 0.0) 20 Z_AXIS = (0.0, 0.0, 1.0) 21 22 class MapViewScannerNavigation(MapViewNavigation): 23 __notifyevents__ = ['OnMarkerMouseDown', 'OnMarkerMouseUp'] 24 movingProbe = None 25 rangeProbe = None 26 activeManipAxis = None 27 modifyHint = None 28 borderPickedProbeControl = None 29 cursorPickedProbeControl = None 30 _keyState = None 31 32 def ApplyAttributes(self, attributes): 33 MapViewNavigation.ApplyAttributes(self, attributes) 34 sm.RegisterNotify(self) 35 36 def ToggleCameraView(self): 37 self.cameraController.ToggleCameraView() 38 39 def ConstructCameraController(self): 40 self.cameraController = SolarSystemMapCameraController(self.mapView.mapViewID, self.mapView.cameraID) 41 42 def PickScene(self, mouseX, mouseY): 43 if uicore.uilib.mouseOver is self: 44 self.mapView.OnMarkerHovered(None) 45 if not (self.movingProbe or self.rangeProbe): 46 probeHandler = self.GetProbeHandler() 47 if probeHandler: 48 picktype, pickobject = self.GetPick() 49 if pickobject and pickobject.name.startswith('cursor'): 50 cursorName, side, probeID = pickobject.name.split('_') 51 probeControl = probeHandler.GetProbeControl(probeID) 52 cursorAxis = cursorName[6:] 53 axis = cursorAxis.lower() 54 else: 55 probeControl = None 56 axis = None 57 probeHandler.HighlightCursors(probeControl, axis) 58 self.cursorPickedProbeControl = probeControl 59 if self.IsProbePickingEnabled() and not probeControl and probeHandler.GetEditMode() not in (MODIFY_RANGE, MODIFY_SPREAD): 60 borderPickedProbeControl = self.PickProbes(pickBorder=True) 61 else: 62 borderPickedProbeControl = None 63 probeHandler.HighlightProbeBorder(borderPickedProbeControl) 64 self.borderPickedProbeControl = borderPickedProbeControl 65 scenePickActive = bool(self.borderPickedProbeControl or self.cursorPickedProbeControl) 66 67 def IsProbePickingEnabled(self): 68 return False 69 70 def MapMarkerPickingOverride(self, *args, **kwds): 71 self.PickScene(uicore.uilib.x, uicore.uilib.y) 72 return bool(self.borderPickedProbeControl or self.cursorPickedProbeControl) 73 74 def OnMouseWheel(self, wheelDelta, *args): 75 self.UpdateCursor() 76 if IsDscanShortcutPressed(): 77 range = GetScanRange() 78 range += uicore.uilib.dz * const.AU / 100000 79 PlaySound('msg_newscan_directional_shape_play') 80 SetScanRange(range) 81 return True 82 if not uicore.uilib.leftbtn: 83 probeHandler = self.GetProbeHandler() 84 scanSvc = sm.GetService('scanSvc') 85 if probeHandler and probeHandler.HasAvailableProbes(): 86 if uicore.uilib.Key(uiconst.VK_CONTROL): 87 scaling = 0.9 88 if wheelDelta > 0: 89 scaling = 1.0 / scaling 90 scanSvc.ScaleFormationSpread(scaling) 91 return True 92 if uicore.uilib.Key(uiconst.VK_MENU): 93 scaling = 0.5 94 if wheelDelta > 0: 95 scaling = 1.0 / scaling 96 scanSvc.ScaleFormation(scaling) 97 return True 98 return MapViewNavigation.OnMouseWheel(self, wheelDelta, *args) 99 100 def OnMouseMove(self, *args): 101 if uicore.IsDragging() or self.destroyed: 102 return 103 self.UpdateCursor() 104 camera = self.mapView.camera 105 if camera is None: 106 return 107 lib = uicore.uilib 108 if lib.leftbtn and (self.movingProbe or self.rangeProbe): 109 return 110 return MapViewNavigation.OnMouseMove(self, *args) 111 112 def OnMouseHover(self, *args): 113 self.UpdateCursor() 114 115 def OnMouseEnter(self, *args): 116 self.UpdateCursor() 117 118 def OnMouseExit(self, *args): 119 self.UpdateCursor() 120 121 def UpdateCursor(self): 122 if IsDscanShortcutPressed(): 123 uicore.uilib.SetCursor(uiconst.UICURSOR_CCALLDIRECTIONS) 124 else: 125 uicore.uilib.SetCursor(uiconst.UICURSOR_DEFAULT) 126 127 def OnDblClick(self, *args): 128 if self.destroyed: 129 return 130 isEventConsumed = False 131 probeHandler = self.GetProbeHandler() 132 if probeHandler: 133 picktype, pickobject = self.GetPick() 134 if pickobject and pickobject.name.startswith('cursor'): 135 cursorName, side, probeID = pickobject.name.split('_') 136 probeHandler.FocusOnProbe(probeID) 137 isEventConsumed = True 138 elif self.IsProbePickingEnabled(): 139 mouseInsideProbes = self.PickProbes() 140 if mouseInsideProbes: 141 try: 142 probeHandler.FocusOnProbe(mouseInsideProbes[0].probeID) 143 isEventConsumed = True 144 except KeyError: 145 pass 146 147 if not isEventConsumed: 148 self.ToggleCameraView() 149 self.ClickPickedObject() 150 151 def CheckDragThread(self): 152 while True: 153 if not uicore.uilib.leftbtn: 154 self.OnMouseUpLeftBtn() 155 return 156 blue.synchro.Yield() 157 158 def GetModifyHint(self): 159 if self.modifyHint is None or self.modifyHint.destroyed: 160 self.modifyHint = EveLabelMedium(parent=self) 161 return self.modifyHint 162 163 def CloseModifyHint(self): 164 if self.modifyHint and not self.modifyHint.destroyed: 165 self.modifyHint.Close() 166 self.modifyHint = None 167 168 def UpdateModifyHintPosition(self): 169 if self.modifyHint and not self.modifyHint.destroyed: 170 left, top = self.GetAbsolutePosition() 171 self.modifyHint.left = uicore.uilib.x + 10 - left 172 self.modifyHint.top = uicore.uilib.y + 16 - top 173 174 def OnMarkerMouseDown(self, button): 175 self.OnMouseDown(button) 176 177 def OnMarkerMouseUp(self, button): 178 self.OnMouseUp(button) 179 180 def OnMouseDown(self, button): 181 probeHandler = self.GetProbeHandler() 182 if probeHandler: 183 if button == uiconst.MOUSELEFT: 184 picktype, pickobject = self.GetPick() 185 rangeProbe = None 186 if pickobject and pickobject.name[:6] == 'cursor': 187 cursorName, side, probeID = pickobject.name.split('_') 188 if probeID: 189 pickedProbeControl = probeHandler.GetProbeControl(probeID) 190 if pickedProbeControl and probeHandler.GetEditMode() in (MODIFY_POSITION, MODIFY_SPREAD): 191 cursorAxis = cursorName[6:] 192 self.movingProbe = pickedProbeControl 193 uthread.new(self.CheckDragThread) 194 self.activeManipAxis = cursorAxis.lower() 195 self.activeTargetPlaneNormal = self.GetAxisTargetPlaneNormal() 196 self.initProbeScenePosition = pickedProbeControl.GetWorldPosition() 197 self.initCenterScenePosition = probeHandler.GetWorldPositionCenterOfActiveProbes() 198 probeHandler.InitProbeMove(self.initProbeScenePosition, self.initCenterScenePosition, self.GetDotInAxisAlignedPlaneFromPosition(self.initProbeScenePosition), self.GetDotInAxisAlignedPlaneFromPosition(self.initCenterScenePosition)) 199 self.scalingOrMoveTimer = AutoTimer(1, self.ScaleOrMoveActiveProbe) 200 return 201 if pickedProbeControl and probeHandler.GetEditMode() == MODIFY_RANGE: 202 rangeProbe = pickedProbeControl 203 if self.IsProbePickingEnabled() and not rangeProbe and self.borderPickedProbeControl: 204 pickedProbeControl = self.PickProbes(pickBorder=True) 205 if pickedProbeControl is self.borderPickedProbeControl: 206 rangeProbe = pickedProbeControl 207 if rangeProbe: 208 self.rangeProbe = pickedProbeControl 209 self.initProbeScenePosition = pickedProbeControl.GetWorldPosition() 210 self.initCenterScenePosition = probeHandler.GetWorldPositionCenterOfActiveProbes() 211 probeHandler.InitProbeScaling(self.initProbeScenePosition, self.initCenterScenePosition, self.GetDotInCameraAlignedPlaneFromPosition(self.initProbeScenePosition), self.GetDotInCameraAlignedPlaneFromPosition(self.initCenterScenePosition)) 212 pickedProbeControl.ShowScanRanges() 213 self.scalingOrMoveTimer = AutoTimer(1, self.ScaleOrMoveActiveProbe) 214 return 215 if probeHandler.GetActiveEditMode(): 216 return 217 self.cameraController.OnMouseDown() 218 self.mouseDownPick = self.GetPickInfo() 219 220 def OnMouseUp(self, button): 221 if button == uiconst.MOUSERIGHT: 222 return self.OnMouseUpRightBtn() 223 if button == uiconst.MOUSELEFT: 224 self.OnMouseUpLeftBtn() 225 return MapViewNavigation.OnMouseUp(self, button) 226 227 def OnMouseUpRightBtn(self): 228 probeHandler = self.GetProbeHandler() 229 if probeHandler: 230 if uicore.uilib.leftbtn and (self.movingProbe or self.rangeProbe): 231 probeHandler.CancelProbeMoveOrScaling() 232 self.movingProbe = None 233 self.rangeProbe = None 234 self.scalingOrMoveTimer = None 235 self.CloseModifyHint() 236 237 def OnMouseUpLeftBtn(self): 238 probeHandler = self.GetProbeHandler() 239 if probeHandler: 240 if self.rangeProbe: 241 probeHandler.RegisterProbeScale(self.rangeProbe) 242 self.scalingOrMoveTimer = None 243 self.rangeProbe = None 244 if self.movingProbe: 245 probeHandler.RegisterProbeMove(self.movingProbe) 246 self.scalingOrMoveTimer = None 247 self.movingProbe = None 248 self.CloseModifyHint() 249 250 def GetMenu(self, *args): 251 mouseInsideProbes = self.PickProbes() 252 if mouseInsideProbes: 253 return sm.StartService('scanSvc').GetProbeMenu(mouseInsideProbes[0].probeID) 254 255 def GetDotInCameraAlignedPlaneFromPosition(self, targetPlanePos, offsetMouse = (0, 0), debug = False): 256 targetPlaneNormal = self.mapView.camera.GetZAxis() 257 return self.GetDotOnTargetPlaneFromPosition(targetPlanePos, targetPlaneNormal, offsetMouse) 258 259 def GetDotInAxisAlignedPlaneFromPosition(self, targetPlanePos, offsetMouse = (0, 0)): 260 if not self.activeTargetPlaneNormal: 261 return None 262 return self.GetDotOnTargetPlaneFromPosition(targetPlanePos, self.activeTargetPlaneNormal, offsetMouse) 263 264 def GetDotOnTargetPlaneFromPosition(self, targetPlanePos, targetPlaneNormal, offsetMouse = (0, 0)): 265 ray, start = self.GetPickVector(offsetMouse) 266 pos = RayToPlaneIntersection(start, ray, targetPlanePos, targetPlaneNormal) 267 return pos 268 269 def GetRayToPlaneDenominator(self, targetPlaneNormal, offsetMouse = (0, 0)): 270 ray, _ = self.GetPickVector(offsetMouse) 271 denom = geo2.Vec3Dot(targetPlaneNormal, ray) 272 return denom 273 274 def GetPickVector(self, offsetMouse): 275 oX, oY = offsetMouse 276 x, y = ScaleDpi(uicore.uilib.x + oX), ScaleDpi(uicore.uilib.y + oY) 277 ray, start = self.cameraController.GetPickVector(x, y) 278 return (ray, start) 279 280 def PickProbes(self, pickBorder = False): 281 mouseInsideProbes = [] 282 borderPick = [] 283 probeHandler = self.GetProbeHandler() 284 if probeHandler: 285 probeData = sm.StartService('scanSvc').GetProbeData() 286 cameraPosition = geo2.Vec3Add(self.mapView.camera._atPosition, self.mapView.camera._eyePosition) 287 probes = probeHandler.GetProbeControls() 288 for probeID, probeControl in probes.iteritems(): 289 if probeID not in probeData or probeData[probeID].state != const.probeStateIdle: 290 continue 291 targetPlanePos = probeControl.GetWorldPosition() 292 cameraDistance = geo2.Vec3Length(geo2.Vec3Subtract(cameraPosition, targetPlanePos)) 293 rad = probeControl.GetRange() * SOLARSYSTEM_SCALE 294 mousePositionOnCameraPlane = self.GetDotInCameraAlignedPlaneFromPosition(targetPlanePos) 295 distanceFromCenter = geo2.Vec3Length(geo2.Vec3Subtract(targetPlanePos, mousePositionOnCameraPlane)) 296 if pickBorder: 297 pickRadiusPos = self.GetDotInCameraAlignedPlaneFromPosition(targetPlanePos, offsetMouse=(-10, 0)) 298 pickRadius = geo2.Vec3Length(geo2.Vec3Subtract(pickRadiusPos, mousePositionOnCameraPlane)) 299 if rad + pickRadius > distanceFromCenter > rad - pickRadius: 300 borderPick.append((abs(rad - distanceFromCenter), probeControl)) 301 elif distanceFromCenter <= rad: 302 mouseInsideProbes.append((cameraDistance, probeControl)) 303 304 if pickBorder: 305 if borderPick: 306 return SortListOfTuples(borderPick)[0] 307 else: 308 return None 309 return SortListOfTuples(mouseInsideProbes) 310 311 def GetPick(self): 312 scene = self.mapView.scene 313 if scene: 314 x, y = uicore.uilib.x, uicore.uilib.y 315 return self.cameraController.GetPick(x, y, scene) 316 return (None, None) 317 318 def GetProbeHandler(self): 319 if self.mapView: 320 solarSystemHander = self.mapView.currentSolarsystem 321 if solarSystemHander and solarSystemHander.solarsystemID == session.solarsystemid2: 322 return solarSystemHander.probeHandler 323 324 def ScaleOrMoveActiveProbe(self, *args): 325 probeHandler = self.GetProbeHandler() 326 if not probeHandler: 327 return 328 if not IsUnder(uicore.uilib.mouseOver, self.parent): 329 return 330 if self.movingProbe: 331 probeHandler.MoveProbe(self.movingProbe, self.activeManipAxis, self.GetDotInAxisAlignedPlaneFromPosition(self.initProbeScenePosition), self.GetDotInAxisAlignedPlaneFromPosition(self.initCenterScenePosition)) 332 elif self.rangeProbe: 333 probeHandler.ScaleProbe(self.rangeProbe, self.GetDotInCameraAlignedPlaneFromPosition(self.initProbeScenePosition), self.GetDotInCameraAlignedPlaneFromPosition(self.initCenterScenePosition)) 334 335 def GetAxisTargetPlaneNormal(self): 336 axisThreshold = 0.15 337 planeThreshold = 0.2 338 if self.activeManipAxis == 'z': 339 if abs(self.GetRayToPlaneDenominator(Y_AXIS)) >= axisThreshold: 340 return Y_AXIS 341 elif abs(self.GetRayToPlaneDenominator(X_AXIS)) >= axisThreshold: 342 return X_AXIS 343 else: 344 return Z_AXIS 345 elif self.activeManipAxis == 'x': 346 if abs(self.GetRayToPlaneDenominator(Y_AXIS)) >= axisThreshold: 347 return Y_AXIS 348 elif abs(self.GetRayToPlaneDenominator(Z_AXIS)) >= axisThreshold: 349 return Z_AXIS 350 else: 351 return X_AXIS 352 elif self.activeManipAxis == 'y': 353 if abs(self.GetRayToPlaneDenominator(Z_AXIS)) >= axisThreshold: 354 return Z_AXIS 355 elif abs(self.GetRayToPlaneDenominator(X_AXIS)) >= axisThreshold: 356 return X_AXIS 357 else: 358 return Y_AXIS 359 elif self.activeManipAxis == 'xz': 360 if abs(self.GetRayToPlaneDenominator(Y_AXIS)) <= planeThreshold: 361 return None 362 else: 363 return Y_AXIS 364 elif self.activeManipAxis == 'xy': 365 if abs(self.GetRayToPlaneDenominator(Z_AXIS)) <= planeThreshold: 366 return None 367 else: 368 return Z_AXIS 369 elif self.activeManipAxis == 'yz': 370 if abs(self.GetRayToPlaneDenominator(X_AXIS)) <= planeThreshold: 371 return None 372 else: 373 return X_AXIS