diff --git a/bluesky/simulation/screenio.py b/bluesky/simulation/screenio.py index c602023cb0..40c2661c6d 100644 --- a/bluesky/simulation/screenio.py +++ b/bluesky/simulation/screenio.py @@ -26,7 +26,6 @@ class ScreenIO(Entity): """Class within sim task which sends/receives data to/from GUI task""" - pub_panzoom = StatePublisher('PANZOOM') pub_defwpt = StatePublisher('DEFWPT', collect=True) pub_route = StatePublisher('ROUTEDATA') @@ -65,9 +64,6 @@ def update(self): self.samplecount += 1 def reset(self): - self.client_pan = dict() - self.client_zoom = dict() - self.client_ar = dict() self.client_route = dict() self.route_all = '' self.custacclr = dict() @@ -101,58 +97,6 @@ def getviewbounds(self): lon1 = lon + 1.0 / (zoom * np.cos(np.radians(lat))) return lat0, lat1, lon0, lon1 - @pub_panzoom.payload - def senddefault(self): - return dict(pan=self.def_pan, zoom=self.def_zoom) - - def zoom(self, zoom, absolute=True): - sender = stack.sender() - if sender: - if not absolute: - zoom *= self.client_zoom.get(sender, self.def_zoom) - self.client_zoom[sender] = zoom - - else: - zoom *= (1.0 if absolute else self.def_zoom) - self.def_zoom = zoom - self.client_zoom.clear() - - self.pub_panzoom.send_replace(zoom=zoom) - - def pan(self, *args): - ''' Move center of display, relative of to absolute position lat,lon ''' - lat, lon = 0, 0 - absolute = False - if args[0] == "LEFT": - lon = -0.5 - elif args[0] == "RIGHT": - lon = 0.5 - elif args[0] == "UP": - lat = 0.5 - elif args[0] == "DOWN": - lat = -0.5 - else: - absolute = True - lat, lon = args - - sender = stack.sender() - if sender: - if absolute: - self.client_pan[sender] = (lat, lon) - else: - ll = self.client_pan.get(sender) or self.def_pan - lat += ll[0] - lon += ll[1] - self.client_pan[sender] = (lat, lon) - else: - if not absolute: - lat += self.def_pan[0] - lon += self.def_pan[1] - self.def_pan = (lat,lon) - self.client_pan.clear() - - self.pub_panzoom.send_replace(pan=[lat,lon]) - def showroute(self, acid): ''' Toggle show route for this aircraft ''' if not stack.sender(): diff --git a/bluesky/stack/basecmds.py b/bluesky/stack/basecmds.py index 7c24c94b6b..ae4fc68017 100644 --- a/bluesky/stack/basecmds.py +++ b/bluesky/stack/basecmds.py @@ -299,12 +299,6 @@ def initbasecmds(): bs.sim.op, "Start/Run simulation or continue after hold" ], - "PAN": [ - "PAN latlon/acid/airport/waypoint/LEFT/RIGHT/ABOVE/DOWN", - "pandir/latlon", - bs.scr.pan, - "Pan screen (move view) to a waypoint, direction or aircraft", - ], "PLOT": [ "PLOT [x], y [,dt,colour,figure]", "[word,word,float,txt,int]", @@ -373,17 +367,6 @@ def initbasecmds(): bs.traf.groups.ungroup, "Remove aircraft from a group", ], - - "ZOOM": [ - "ZOOM IN/OUT or factor", - "float/txt", - lambda a: bs.scr.zoom(1.4142135623730951) - if a == "IN" - else bs.scr.zoom(0.7071067811865475) - if a == "OUT" - else bs.scr.zoom(a, True), - "Zoom display in/out, you can also use +++ or -----", - ], } # diff --git a/bluesky/ui/pygame/screen.py b/bluesky/ui/pygame/screen.py index d2d6fd932c..243b842cbb 100644 --- a/bluesky/ui/pygame/screen.py +++ b/bluesky/ui/pygame/screen.py @@ -956,12 +956,24 @@ def onradar(self, lat, lon): return sw - - - def zoom(self, factor, absolute = False): - """Zoom function""" + @stack.command(annotations='float/txt', brief='ZOOM IN/OUT/factor') + def zoom(self, factor): + ''' ZOOM: Zoom in and out in the radar view. + + Arguments: + - factor: IN/OUT to zoom in/out by a factor sqrt(2), or + 'factor' to set zoom to specific value. + ''' oldvalues = self.lat0, self.lat1, self.lon0, self.lon1 - + absolute = True + if isinstance(factor, str): + absolute = False + if factor == 'IN': + factor = 1.4142135623730951 + elif factor == 'OUT': + factor = 0.7071067811865475 + else: + return False, f'ZOOM: argument {factor} not recognised' # Zoom factor: 2.0 means halving the display size in degrees lat/lon # ZOom out with e.g. 0.5 @@ -1002,41 +1014,12 @@ def zoom(self, factor, absolute = False): self.satsel = () self.geosel = () - return + return True + @stack.command(annotations="pandir/latlon", brief="PAN latlon/acid/airport/waypoint/LEFT/RIGHT/UP/DOWN") def pan(self, *args): - """Pan function: - absolute: lat,lon; - relative: ABOVE/DOWN/LEFT/RIGHT""" - lat, lon = self.ctrlat, self.ctrlon - if type(args[0])==str: - if args[0].upper() == "LEFT": - lon = lon - 0.5 * (self.lon1 - self.lon0) - elif args[0].upper() == "RIGHT": - lon = lon + 0.5 * (self.lon1 - self.lon0) - elif args[0].upper() == "ABOVE" or args[0].upper() == "UP": - lat = lat + 0.5 * (self.lat1 - self.lat0) - elif args[0].upper() == "DOWN": - lat = lat - 0.5 * (self.lat1 - self.lat0) - else: - i = bs.navdb.getwpidx(args[0],self.ctrlat,self.ctrlon) - if i<0: - i = bs.navdb.getaptidx(args[0],self.ctrlat,self.ctrlon) - if i>0: - lat = bs.navdb.aptlat[i] - lon = bs.navdb.aptlon[i] - else: - lat = bs.navdb.wplat[i] - lon = bs.navdb.wplon[i] - - if i<0: - return False,args[0]+"not found." - - else: - if len(args)>1: - lat, lon = args[:2] - else: - return False + "Pan screen (move view) to a waypoint, direction or aircraft" + lat, lon = args # Maintain size & avoid getting out of range dellat2 = (self.lat1 - self.lat0) * 0.5 @@ -1059,14 +1042,8 @@ def pan(self, *args): self.satsel = () self.geosel = () - # print "Pan lat,lon:",lat,lon - # print "Latitude range:",int(self.lat0),int(self.ctrlat),int(self.lat1) - # print "Longitude range:",int(self.lon0),int(self.ctrlon),int(self.lon1) - # print "dellon2 =",dellon2 - return True - def fullscreen(self, switch): # full screen switch """Switch to (True) /from (False) full screen mode""" diff --git a/bluesky/ui/qtgl/mainwindow.py b/bluesky/ui/qtgl/mainwindow.py index 73ec4d2e4e..464c517da8 100644 --- a/bluesky/ui/qtgl/mainwindow.py +++ b/bluesky/ui/qtgl/mainwindow.py @@ -2,7 +2,7 @@ from pathlib import Path import platform -from bluesky.core.base import Base +from bluesky.core import Base, Signal from bluesky.network.discovery import Discovery try: @@ -25,6 +25,7 @@ # Local imports import bluesky as bs from bluesky import stack +from bluesky.stack.argparser import PosArg from bluesky.pathfinder import ResourcePath from bluesky.tools.misc import tim2txt from bluesky.network import subscriber, context as ctx @@ -42,8 +43,9 @@ if platform.system().lower() == "windows": from bluesky.ui.pygame.dialog import fileopen + # Register settings defaults -bs.settings.set_variable_defaults(gfx_path='graphics') +bs.settings.set_variable_defaults(gfx_path='graphics', start_location='EHAM') palette.set_default_colours(stack_text=(0, 255, 0), stack_background=(102, 102, 102)) @@ -188,6 +190,14 @@ def __init__(self, mode): # Tell BlueSky that this is the screen object for this client bs.scr = self + # Signals we want to emit + self.panzoom_event = Signal('state-changed.panzoom') + + # Set position default from settings + lat, lon, _ = PosArg().parse(bs.settings.start_location) + ss.setdefault('pan', [lat, lon], group='panzoom') + + # self.nodetree.setVisible(False) self.nodetree.setIndentation(0) self.nodetree.setColumnCount(2) @@ -217,6 +227,40 @@ def setStyleSheet(self, contents=''): with open(bs.resource(bs.settings.gfx_path) / 'bluesky.qss') as style: super().setStyleSheet(style.read()) + @stack.command(annotations='pandir/latlon', brief='PAN latlon/acid/airport/waypoint/LEFT/RIGHT/UP/DOWN') + def pan(self, *args): + "Pan screen (move view) to a waypoint, direction or aircraft" + store = ss.get(group='panzoom') + store.pan = list(args) + self.panzoom_event.emit(store) + return True + + @stack.command(annotations='float/txt', brief='ZOOM IN/OUT/factor') + def zoom(self, factor): + ''' ZOOM: Zoom in and out in the radar view. + + Arguments: + - factor: IN/OUT to zoom in/out by a factor sqrt(2), or + 'factor' to set zoom to specific value. + ''' + store = ss.get(group='panzoom') + if isinstance(factor, float): + store.zoom = factor + elif factor == 'IN': + store.zoom *= 1.4142135623730951 + elif factor == 'OUT': + store.zoom *= 0.7071067811865475 + else: + return False, f'ZOOM: argument {factor} not recognised' + self.panzoom_event.emit(store) + return True + + def getviewctr(self): + return self.radarwidget.pan + + def getviewbounds(self): # Return current viewing area in lat, lon + return self.radarwidget.viewportlatlon() + def keyPressEvent(self, event): if event.modifiers() & Qt.KeyboardModifier.ShiftModifier \ and event.key() in [Qt.Key.Key_Up, Qt.Key.Key_Down, Qt.Key.Key_Left, Qt.Key.Key_Right]: diff --git a/bluesky/ui/qtgl/radarwidget.py b/bluesky/ui/qtgl/radarwidget.py index 503b3c9dae..3122ccdafc 100644 --- a/bluesky/ui/qtgl/radarwidget.py +++ b/bluesky/ui/qtgl/radarwidget.py @@ -9,7 +9,6 @@ import bluesky as bs from bluesky.core import Signal -from bluesky.network import subscribe import bluesky.network.context as ctx import bluesky.network.sharedstate as ss from bluesky.ui.qtgl import glhelpers as glh @@ -19,6 +18,8 @@ from .glnavdata import Navdata from .glpoly import Poly from .gltiledmap import TiledMap + + # Register settings defaults bs.settings.set_variable_defaults(gfx_path='graphics') @@ -128,7 +129,7 @@ def __init__(self, parent=None): self.mouse_event = Signal('radarmouse') self.radarclick_event = Signal('radarclick') self.panzoom_event = Signal('state-changed.panzoom') - subscribe('PANZOOM').connect(self.on_panzoom) + self.panzoom_event.connect(self.on_panzoom) def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" @@ -189,7 +190,7 @@ def viewportlatlon(self): self.pan[0] - 1.0 / (self.zoom * self.ar), self.pan[1] + 1.0 / (self.zoom * self.flat_earth)) - def on_panzoom(self, data, finished=True): + def on_panzoom(self, data=None, finished=True): if not self.initialized: return False