def __init__(self, yawStart, yawEnd, pitchStart, pitchEnd, yawFov, pitchFov, yawCameraFov, pitchCameraFov, parent=None): """ Init shooting scene. @param yawStart: yaw start position (°) @type yawStart: float @param yawEnd: yaw end position (°) @type yawEnd: float @param pitchStart: pitch start position (°) @type pitchStart: float @param pitchEnd: pitch end position (°) @type pitchEnd: float @param yawFov: yaw fov (°) @type yawFov: float @param pitchFov: pitch fov (°) @type pitchFov: float @param yawCameraFov: pict yaw fov (°) @type yawCameraFov: float @param pitchCameraFov: pict pitch fov (°) @type pitchCameraFov: float """ QtGui.QGraphicsScene.__init__(self, parent) self._yawStart = yawStart self._yawEnd = yawEnd self._pitchStart = pitchStart self._pitchEnd = pitchEnd self._yawFov = yawFov self._pitchFov = pitchFov self._yawCameraFov = yawCameraFov self._pitchCameraFov = pitchCameraFov self._pictures = {} # Head position crosshair self._headCrosshair = CrosshairCusrsor( math.sqrt(self._yawFov**2 + self._pitchFov**2) / 10) self._headCrosshair.setZValue(9999) self.addItem(self._headCrosshair) self._init()
def __init__(self, yawStart, yawEnd, pitchStart, pitchEnd, yawFov, pitchFov, yawCameraFov, pitchCameraFov, parent=None): """ Init shooting scene. @param yawStart: yaw start position (°) @type yawStart: float @param yawEnd: yaw end position (°) @type yawEnd: float @param pitchStart: pitch start position (°) @type pitchStart: float @param pitchEnd: pitch end position (°) @type pitchEnd: float @param yawFov: yaw fov (°) @type yawFov: float @param pitchFov: pitch fov (°) @type pitchFov: float @param yawCameraFov: pict yaw fov (°) @type yawCameraFov: float @param pitchCameraFov: pict pitch fov (°) @type pitchCameraFov: float """ QtGui.QGraphicsScene.__init__(self, parent) self._yawStart = yawStart self._yawEnd = yawEnd self._pitchStart = pitchStart self._pitchEnd = pitchEnd self._yawFov = yawFov self._pitchFov = pitchFov self._yawCameraFov = yawCameraFov self._pitchCameraFov = pitchCameraFov self._pictures = {} # Head position crosshair self._headCrosshair = CrosshairCusrsor(math.sqrt(self._yawFov ** 2 + self._pitchFov ** 2) / 10) self._headCrosshair.setZValue(9999) self.addItem(self._headCrosshair) self._init()
class AbstractShootingScene(QtGui.QGraphicsScene): """ Qt ShootingScene widget """ def __init__(self, yawStart, yawEnd, pitchStart, pitchEnd, yawFov, pitchFov, yawCameraFov, pitchCameraFov, parent=None): """ Init shooting scene. @param yawStart: yaw start position (°) @type yawStart: float @param yawEnd: yaw end position (°) @type yawEnd: float @param pitchStart: pitch start position (°) @type pitchStart: float @param pitchEnd: pitch end position (°) @type pitchEnd: float @param yawFov: yaw fov (°) @type yawFov: float @param pitchFov: pitch fov (°) @type pitchFov: float @param yawCameraFov: pict yaw fov (°) @type yawCameraFov: float @param pitchCameraFov: pict pitch fov (°) @type pitchCameraFov: float """ QtGui.QGraphicsScene.__init__(self, parent) self._yawStart = yawStart self._yawEnd = yawEnd self._pitchStart = pitchStart self._pitchEnd = pitchEnd self._yawFov = yawFov self._pitchFov = pitchFov self._yawCameraFov = yawCameraFov self._pitchCameraFov = pitchCameraFov self._pictures = {} # Head position crosshair self._headCrosshair = CrosshairCusrsor(math.sqrt(self._yawFov ** 2 + self._pitchFov ** 2) / 10) self._headCrosshair.setZValue(9999) self.addItem(self._headCrosshair) self._init() def _init(self): """ Init the scene rect. """ raise NotImplementedError("ShootingScene._init() is abstract and must be overidden") # Signals def pictureClicked(self, index): """ User clicked on a picture in the scene. """ self.emit(QtCore.SIGNAL("pictureClicked"), index) # Qt handlers def mousePressEvent(self, event): Logger().trace("ShootingScene.mousePressEvent()") picture = self.itemAt(event.scenePos()) Logger().debug("ShootingScene.mousePressEvent(): picture=%s" % picture) try: index = picture.parentItem().getIndex() Logger().debug("ShootingScene.mousePressEvent(): picture index=%d" % index) self.pictureClicked(index) except AttributeError: Logger().exception("ShootingScene.mousePressEvent()", debug=True) # Interface def addPicture(self, index, yaw, pitch, state='preview'): """ Add a pict at yaw/pitch coordinates. @param yaw: yaw pict position (°) @type yaw: float @param pitch: pitch pict position (°) @type pitch: float @param state: state of the shooting at this position @type state: str """ raise NotImplementedError("ShootingScene.addPicture() is abstract and must be overidden") def setPictureState(self, index, state): """ Set the picture state. @param index: index of the picture to set the state @type index: int @param state: new state of the picture @type state: str """ self._pictures[index].setState(state) def selectNextPicture(self, index): """ Set the picture at index the next to shoot. @param index: index of the next picture to shoot @type index: int """ previousIndex = AbstractPictureItem.nextIndex AbstractPictureItem.nextIndex = index for picture in self._pictures.itervalues(): if previousIndex <= picture.getIndex() <= index or \ index <= picture.getIndex() <= previousIndex: picture.refresh() def resetState(self): """ Reset state of pictures in the shooting area. """ for picture in self._pictures.itervalues(): if picture.getState() != 'invalid': picture.setState(state='preview') AbstractPictureItem.nextIndex = 1 picture.refresh() def clear(self): """ Clear the shooting area. """ while True: try: index, picture = self._pictures.popitem() self.removeItem(picture) except KeyError: Logger().exception("ShootingScene.clear()", debug=True) break def setHeadPosition(self, yaw, pitch): """ Set the current head position. """ self._headCrosshair.setPos(yaw, -pitch) def refresh(self): """ Force refresh the scene. This method is mainly called by the view resizeEvent, and ask the items to recompute their width according to the new view size. """ for picture in self._pictures.itervalues(): picture.refresh() self._headCrosshair.refresh()
class AbstractShootingScene(QtGui.QGraphicsScene): """ Qt ShootingScene widget """ def __init__(self, yawStart, yawEnd, pitchStart, pitchEnd, yawFov, pitchFov, yawCameraFov, pitchCameraFov, parent=None): """ Init shooting scene. @param yawStart: yaw start position (°) @type yawStart: float @param yawEnd: yaw end position (°) @type yawEnd: float @param pitchStart: pitch start position (°) @type pitchStart: float @param pitchEnd: pitch end position (°) @type pitchEnd: float @param yawFov: yaw fov (°) @type yawFov: float @param pitchFov: pitch fov (°) @type pitchFov: float @param yawCameraFov: pict yaw fov (°) @type yawCameraFov: float @param pitchCameraFov: pict pitch fov (°) @type pitchCameraFov: float """ QtGui.QGraphicsScene.__init__(self, parent) self._yawStart = yawStart self._yawEnd = yawEnd self._pitchStart = pitchStart self._pitchEnd = pitchEnd self._yawFov = yawFov self._pitchFov = pitchFov self._yawCameraFov = yawCameraFov self._pitchCameraFov = pitchCameraFov self._pictures = {} # Head position crosshair self._headCrosshair = CrosshairCusrsor( math.sqrt(self._yawFov**2 + self._pitchFov**2) / 10) self._headCrosshair.setZValue(9999) self.addItem(self._headCrosshair) self._init() def _init(self): """ Init the scene rect. """ raise NotImplementedError( "ShootingScene._init() is abstract and must be overidden") # Signals def pictureClicked(self, index): """ User clicked on a picture in the scene. """ self.emit(QtCore.SIGNAL("pictureClicked"), index) # Qt handlers def mousePressEvent(self, event): Logger().trace("ShootingScene.mousePressEvent()") picture = self.itemAt(event.scenePos()) Logger().debug("ShootingScene.mousePressEvent(): picture=%s" % picture) try: index = picture.parentItem().getIndex() Logger().debug( "ShootingScene.mousePressEvent(): picture index=%d" % index) self.pictureClicked(index) except AttributeError: Logger().exception("ShootingScene.mousePressEvent()", debug=True) # Interface def addPicture(self, index, yaw, pitch, state='preview'): """ Add a pict at yaw/pitch coordinates. @param yaw: yaw pict position (°) @type yaw: float @param pitch: pitch pict position (°) @type pitch: float @param state: state of the shooting at this position @type state: str """ raise NotImplementedError( "ShootingScene.addPicture() is abstract and must be overidden") def setPictureState(self, index, state): """ Set the picture state. @param index: index of the picture to set the state @type index: int @param state: new state of the picture @type state: str """ self._pictures[index].setState(state) def selectNextPicture(self, index): """ Set the picture at index the next to shoot. @param index: index of the next picture to shoot @type index: int """ previousIndex = AbstractPictureItem.nextIndex AbstractPictureItem.nextIndex = index for picture in self._pictures.itervalues(): if previousIndex <= picture.getIndex() <= index or \ index <= picture.getIndex() <= previousIndex: picture.refresh() def resetState(self): """ Reset state of pictures in the shooting area. """ for picture in self._pictures.itervalues(): if picture.getState() != 'invalid': picture.setState(state='preview') AbstractPictureItem.nextIndex = 1 picture.refresh() def clear(self): """ Clear the shooting area. """ while True: try: index, picture = self._pictures.popitem() self.removeItem(picture) except KeyError: Logger().exception("ShootingScene.clear()", debug=True) break def setHeadPosition(self, yaw, pitch): """ Set the current head position. """ self._headCrosshair.setPos(yaw, -pitch) def refresh(self): """ Force refresh the scene. This method is mainly called by the view resizeEvent, and ask the items to recompute their width according to the new view size. """ for picture in self._pictures.itervalues(): picture.refresh() self._headCrosshair.refresh()