def drawEllipse(self, refX, refY, radiusX, radiusY, startDeg, endDeg, lineWidth, color, painter): unused(startDeg, endDeg) pen = QPen(painter.pen().style()) pen.setWidth(self.refLineWidthToPen(lineWidth)) pen.setColor(color) painter.setPen(pen) painter.drawEllipse(QPointF(self.refToScreenX(refX), self.refToScreenY(refY)), self.refToScreenX(radiusX), self.refToScreenY(radiusY))
def updateGlobalPosition(self, sourceUAS, timestamp, latitude, longitude, altitude): self.latitude = self.latitude if math.isnan(latitude) else latitude self.longitude = self.longitude if math.isnan(longitude) else longitude self.GPSAltitude = self.GPSAltitude if math.isnan( altitude) else altitude unused(sourceUAS, timestamp)
def verify_business_type_existance(self, b_type: int): try: c_b_t = CompanyBusinessType(b_type) utils.unused(c_b_t) return True except: return False
def updateGroundSpeed(self, uas, timestamp, gndspd): unused(uas) # only update if we haven't gotten a full 3D speed update in a while if timestamp - self.lastSpeedUpdate > 1e6: self.totalAcc = (gndspd - self.totalSpeed) / ((self.lastSpeedUpdate - timestamp)/1000.0) self.totalSpeed = gndspd self.lastSpeedUpdate = timestamp
def updateNavigationControllerOutput(self, uas, desiredRoll, desiredPitch, desiredHeading, targetBearing, wpDist): unused(uas) self.desiredRoll = desiredRoll self.desiredPitch = desiredPitch self.desiredHeading = desiredHeading self.targetBearing = targetBearing self.wpDist = wpDist
def updateGPSFixStatus(self, sourceUAS, timestamp, fix, hdop, vdop, nosv, hacc, vacc, velacc, hdgacc): unused(sourceUAS, timestamp, hdop, vdop, nosv, hacc, vacc, velacc, hdgacc) if fix in GPS_FIX_LABELS: self.gpsLbl.setText(GPS_FIX_LABELS[fix]) else: self.gpsLbl.setText(GPS_FIX_LABELS[mavlink.GPS_FIX_TYPE_NO_FIX])
def updateMode(self, uas, mode): ''' Updates the current system mode, but only if the uas matches the currently monitored uas. :param uas: the system the state message originates from :param mode: short mode text, displayed in HUD ''' unused(uas) # Only one UAS is connected at a time self.mode = mode
def updateVelocity(self, uas, timestamp, x, y, z): unused(uas) self.xSpeed = x self.ySpeed = y self.zSpeed = z newTotalSpeed = sqrt(self.xSpeed*self.xSpeed + self.ySpeed*self.ySpeed + self.zSpeed*self.zSpeed) self.totalAcc = (newTotalSpeed - self.totalSpeed) / ((self.lastSpeedUpdate - timestamp)/1000.0) self.totalSpeed = newTotalSpeed self.lastSpeedUpdate = timestamp
def updateBattery(self, uas, timestamp, voltage, current, percent): unused(uas, timestamp, current) self.fuelStatus = 'BAT [{}% | {:.1f}V]'.format(percent, voltage) if percent < 20.0: self.fuelColor = self.warningColor elif percent < 10.0: self.fuelColor = self.criticalColor else: self.fuelColor = self.infoColor
def updateAttitude(self, uas, timestamp, roll, pitch, yaw): unused(uas, timestamp) if isnan(roll) == False and isinf(roll) == False \ and isnan(pitch) == False and isinf(pitch)== False \ and isnan(yaw) == False and isinf(yaw) == False: self.roll = roll self.pitch = pitch*3.35 # Constant here is the 'focal length' of the projection onto the plane self.yaw = yaw self.attitudes[0] = QVector3D(roll, pitch*3.35, yaw)
def updateAttitudeSpeed(self, sourceUAS, timestamp, rollspeed, pitchspeed, yawspeed): scale = 180 / math.pi self.rollspeed = self.rollspeed if math.isnan( rollspeed) else rollspeed * scale self.pitchspeed = self.pitchspeed if math.isnan( pitchspeed) else pitchspeed * scale self.yawspeed = self.yawspeed if math.isnan( yawspeed) else yawspeed * scale unused(sourceUAS, timestamp)
def short_client_data(self, cmd): utils.unused(cmd) player_data = self.client_data.player_data.get_player_value_info( ) # Money and stock's money news_list = self.logic_handler.news_handler.get_news_list_byamount(3) msg = CommunicationProtocol.prepare_short_info( self.client_data.login, player_data, self.logic_handler.server_time, self.logic_handler.game_cycle, news_list) self.ws.write_message(msg)
def request_client_data(self, cmd): utils.unused(cmd) s_list = self.client_data.player_data.get_all_stocks_to_list() c_list = self.client_data.player_data.get_all_own_companies() client_data_msg = CommunicationProtocol.create_client_data_msg( login=self.client_data.login, money=self.client_data.player_data.money, stock_list=s_list, companies_list=c_list, server_time=self.logic_handler.server_time) self.ws.write_message(client_data_msg)
def styleChanged(self, newTheme = 0): unused(newTheme) # Generate a background image that's dependent on the current color scheme. fill = QImage(self.width(), self.height(), QImage.Format_Indexed8) fill.fill(0) self.DEFAULT_BACKGROUND_IMAGE = QGLWidget.convertToGLFormat(fill) self.defaultColor = QColor(0x66, 0xff, 0x00) # bright green self.setPointColor = QColor(0x82, 0x17, 0x82) self.warningColor = QColor(0xff, 0xff, 0x00) self.criticalColor = QColor(0xff, 0x00, 0x00) self.infoColor = self.defaultColor self.fuelColor = self.criticalColor
def updateBatteryStatus(self, sourceUAS, timestamp, voltage, current, remaining): unused(sourceUAS, timestamp) self.battVoltLabel.setText('{:.1f}V/{:.1f}A'.format( voltage, abs(current))) self.battBar.setValue(remaining) if remaining >= 60: self.battBar.setStyleSheet( BATTERY_BAR_STYLE_TEMPLATE.format('green')) elif remaining >= 30: self.battBar.setStyleSheet( BATTERY_BAR_STYLE_TEMPLATE.format('yellow')) else: self.battBar.setStyleSheet( BATTERY_BAR_STYLE_TEMPLATE.format('red'))
def generate_stocks51(self, amount: int): # Change type to open. This is kind of default stocks initialization self.company_type = CompanyType.OPEN # Create stocks main_stock = self.stock_handler.create_stock(self.uuid, StockType.GOLD, 0.51) main_stock.set_as_main() self.stocks[main_stock.uuid] = main_stock self.__gold_amount_full += 1 # Generate others value = (49 / amount) / 100 for _unused in range(0, amount): utils.unused(_unused) stock = self.stock_handler.create_stock(self.uuid, StockType.SILVER, value) self.stocks[stock.uuid] = stock self.__silver_amount_full += 1 # After generation need to calculate stock cost self.recalculate_stocks_cost()
def paintEvent(self, event): unused(event) compassAIIntrusion = 0 compassHalfSpan = 180 painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) tapeGaugeWidth = self.tapesGaugeWidthFor(self.width(), self.width()) aiheight = self.height() aiwidth = self.width() - tapeGaugeWidth * 2 if (aiheight > aiwidth): aiheight = aiwidth AIMainArea = QRectF(tapeGaugeWidth, 0, aiwidth, aiheight) AIPaintArea = QRectF(0, 0, self.width(), self.height()) velocityMeterArea = QRectF(0, 0, tapeGaugeWidth, aiheight) altimeterArea = QRectF(AIMainArea.right(), 0, tapeGaugeWidth, aiheight) # calc starts compassRelativeWidth = 0.75 compassBottomMargin = 0.78 compassSize = compassRelativeWidth * AIMainArea.width( ) # Diameter is this times the width. compassCenterY = AIMainArea.bottom() + compassSize / 4 if self.height( ) - compassCenterY > AIMainArea.width() / 2 * compassBottomMargin: compassCenterY = self.height( ) - AIMainArea.width() / 2 * compassBottomMargin compassCenterY = (compassCenterY * 2 + AIMainArea.bottom() + compassSize / 4) / 3 compassArea = QRectF( AIMainArea.x() + (1 - compassRelativeWidth) / 2 * AIMainArea.width(), compassCenterY - compassSize / 2, compassSize, compassSize) if self.height() - compassCenterY < compassSize / 2: compassHalfSpan = math.acos( (compassCenterY - self.height()) * 2 / compassSize) * 180 / math.pi + self.COMPASS_DISK_RESOLUTION if compassHalfSpan > 180: compassHalfSpan = 180 compassAIIntrusion = compassSize / 2 + AIMainArea.bottom( ) - compassCenterY if compassAIIntrusion < 0: compassAIIntrusion = 0 #calc ends hadClip = painter.hasClipping() painter.setClipping(True) painter.setClipRect(AIPaintArea) self.drawAIGlobalFeatures(painter, AIMainArea, AIPaintArea) self.drawAIAttitudeScales(painter, AIMainArea, compassAIIntrusion) self.drawAIAirframeFixedFeatures(painter, AIMainArea) self.drawAICompassDisk(painter, compassArea, compassHalfSpan) painter.setClipping(hadClip) if self.isGPSAltitudePrimary: self.drawAltimeter(painter, altimeterArea, self.GPSAltitude, self.primaryAltitude, self.verticalVelocity) else: self.drawAltimeter(painter, altimeterArea, self.primaryAltitude, self.GPSAltitude, self.verticalVelocity) if self.isGPSSpeedPrimary: self.drawVelocityMeter(painter, velocityMeterArea, self.groundspeed, self.primarySpeed) else: self.drawVelocityMeter(painter, velocityMeterArea, self.primarySpeed, self.groundspeed) painter.end()
def updateGPSReception(self, sourceUAS, timestamp, fixType, hdop, vdop, satelliteCount, hacc, vacc, velacc, hdgacc): self.additionalParameters['gps_fix'] = fixType self.additionalParameters['gps_satellite'] = satelliteCount unused(sourceUAS, timestamp, hdop, vdop, hacc, vacc, velacc, hdgacc)
def request_open_companies_list(self, cmd): utils.unused(cmd) c_list = self.logic_handler.companies_open_list_client() c_list_msg = CommunicationProtocol.create_companies_open_list(c_list) self.ws.write_message(c_list_msg)
def wrong_command(self, cmd): utils.unused(cmd) print("Wrong type")
def market_elements_list(self, cmd: CommunitcationParserResult): utils.unused(cmd) body = self.stock_market.get_market_list() msg = CommunicationProtocol.create_market_list(body) self.ws.write_message(msg)
def companies_name_list(self, cmd: CommunitcationParserResult): utils.unused(cmd) c_list = self.logic_handler.companies_handler.get_companies_id_to_list( ) msg = CommunicationProtocol.create_companies_name_list(c_list) self.ws.write_message(msg)
def list_invest_market(self, cmd: CommunitcationParserResult): utils.unused(cmd) m_list = self.investment_market.list_of_investment_offers() msg = CommunicationProtocol.invest_market_list(m_list) self.ws.write(msg)
def updateAttitude(self, sourceUAS, timestamp, roll, pitch, yaw): unused(sourceUAS, timestamp, roll, pitch) self.setHeading(yaw)
def updateAirPressure(self, sourceUAS, timestamp, absPressure, diffPressure, temperature): unused(sourceUAS, timestamp, diffPressure, temperature) self.setBarometer(absPressure)
def __getMessageTime(self, msg): unused(msg) if self.time0 == 0: self.time0 = int(time()) * 50 return 1 return int(time()) * 50 - self.time0
def drawVelocityMeter(self, painter, area, speed, secondarySpeed): unused(secondarySpeed) painter.resetTransform() self.fillInstrumentBackground(painter, area) pen = QPen() pen.setWidthF(self.lineWidth) h = area.height() w = area.width() effectiveHalfHeight = h * 0.45 markerHalfHeight = self.mediumTextSize leftEdge = self.instrumentEdgePen.widthF() * 2 tickmarkRight = w - leftEdge tickmarkLeftMajor = tickmarkRight - w * self.TAPE_GAUGES_TICKWIDTH_MAJOR tickmarkLeftMinor = tickmarkRight - w * self.TAPE_GAUGES_TICKWIDTH_MINOR numbersRight = 0.42 * w markerTip = (tickmarkLeftMajor + tickmarkRight * 2) / 3 # Select between air and ground speed: centerScaleSpeed = 0 if speed == self.UNKNOWN_SPEED else speed start = centerScaleSpeed - self.AIRSPEED_LINEAR_SPAN / 2 end = centerScaleSpeed + self.AIRSPEED_LINEAR_SPAN / 2 firstTick = math.ceil( start / self.AIRSPEED_LINEAR_RESOLUTION) * self.AIRSPEED_LINEAR_RESOLUTION lastTick = math.floor( end / self.AIRSPEED_LINEAR_RESOLUTION) * self.AIRSPEED_LINEAR_RESOLUTION tickSpeed = firstTick while tickSpeed <= lastTick: if tickSpeed < 0: pen.setColor(Qt.red) else: pen.setColor(Qt.white) painter.setPen(pen) y = (tickSpeed - centerScaleSpeed) * effectiveHalfHeight / ( self.AIRSPEED_LINEAR_SPAN / 2) hasText = tickSpeed % self.AIRSPEED_LINEAR_MAJOR_RESOLUTION == 0 painter.resetTransform() painter.translate(area.left(), area.center().y() - y) if hasText: painter.drawLine(tickmarkLeftMajor, 0, tickmarkRight, 0) self.drawTextRightCenter(painter, '{0}'.format(abs(tickSpeed)), self.mediumTextSize, numbersRight, 0) else: painter.drawLine(tickmarkLeftMinor, 0, tickmarkRight, 0) tickSpeed += self.AIRSPEED_LINEAR_RESOLUTION markerPath = QPainterPath(QPoint(markerTip, 0)) markerPath.lineTo(markerTip - markerHalfHeight, markerHalfHeight) markerPath.lineTo(leftEdge, markerHalfHeight) markerPath.lineTo(leftEdge, -markerHalfHeight) markerPath.lineTo(markerTip - markerHalfHeight, -markerHalfHeight) markerPath.closeSubpath() painter.resetTransform() painter.translate(area.left(), area.center().y()) pen.setWidthF(self.lineWidth) pen.setColor(Qt.white) painter.setPen(pen) painter.setBrush(Qt.SolidPattern) painter.drawPath(markerPath) painter.setBrush(Qt.NoBrush) pen.setColor(Qt.white) painter.setPen(pen) xCenter = (markerTip + leftEdge) / 2 spdtxt = '---' if speed == self.UNKNOWN_SPEED else '%3.1f' % speed self.drawTextCenter(painter, spdtxt, self.mediumTextSize, xCenter, 0)
def drawAltimeter(self, painter, area, primaryAltitude, secondaryAltitude, vv): unused(secondaryAltitude) painter.resetTransform() self.fillInstrumentBackground(painter, area) pen = QPen() pen.setWidthF(self.lineWidth) pen.setColor(Qt.white) painter.setPen(pen) h = area.height() w = area.width() #float secondaryAltitudeBoxHeight = mediumTextSize * 2; # The height where we being with new tickmarks. effectiveHalfHeight = h * 0.45 # not yet implemented: Display of secondary altitude. # if (isAirplane()) # effectiveHalfHeight-= secondaryAltitudeBoxHeight; markerHalfHeight = self.mediumTextSize * 0.8 leftEdge = self.instrumentEdgePen.widthF() * 2 rightEdge = w - leftEdge tickmarkLeft = leftEdge tickmarkRightMajor = tickmarkLeft + self.TAPE_GAUGES_TICKWIDTH_MAJOR * w tickmarkRightMinor = tickmarkLeft + self.TAPE_GAUGES_TICKWIDTH_MINOR * w numbersLeft = 0.42 * w markerTip = (tickmarkLeft * 2 + tickmarkRightMajor) / 3 scaleCenterAltitude = 0 if primaryAltitude == self.UNKNOWN_ALTITUDE else primaryAltitude # altitude scale start = scaleCenterAltitude - self.ALTIMETER_LINEAR_SPAN / 2 end = scaleCenterAltitude + self.ALTIMETER_LINEAR_SPAN / 2 firstTick = math.ceil(start / self.ALTIMETER_LINEAR_RESOLUTION ) * self.ALTIMETER_LINEAR_RESOLUTION lastTick = math.floor(end / self.ALTIMETER_LINEAR_RESOLUTION ) * self.ALTIMETER_LINEAR_RESOLUTION tickAlt = firstTick while tickAlt <= lastTick: y = (tickAlt - scaleCenterAltitude) * effectiveHalfHeight / ( self.ALTIMETER_LINEAR_SPAN / 2) isMajor = tickAlt % self.ALTIMETER_LINEAR_MAJOR_RESOLUTION == 0 painter.resetTransform() painter.translate(area.left(), area.center().y() - y) pen.setColor(Qt.red if tickAlt < 0 else Qt.white) painter.setPen(pen) if isMajor: painter.drawLine(tickmarkLeft, 0, tickmarkRightMajor, 0) self.drawTextLeftCenter(painter, '{0}'.format(abs(tickAlt)), self.mediumTextSize, numbersLeft, 0) else: painter.drawLine(tickmarkLeft, 0, tickmarkRightMinor, 0) tickAlt += self.ALTIMETER_LINEAR_RESOLUTION markerPath = QPainterPath(QPoint(markerTip, 0)) markerPath.lineTo(markerTip + markerHalfHeight, markerHalfHeight) markerPath.lineTo(rightEdge, markerHalfHeight) markerPath.lineTo(rightEdge, -markerHalfHeight) markerPath.lineTo(markerTip + markerHalfHeight, -markerHalfHeight) markerPath.closeSubpath() painter.resetTransform() painter.translate(area.left(), area.center().y()) pen.setWidthF(self.lineWidth) pen.setColor(Qt.white) painter.setPen(pen) painter.setBrush(Qt.SolidPattern) painter.drawPath(markerPath) painter.setBrush(Qt.NoBrush) pen.setColor(Qt.white) painter.setPen(pen) xCenter = (markerTip + rightEdge) / 2 alttxt = '---' if primaryAltitude == self.UNKNOWN_ALTITUDE else '%3.0f' % primaryAltitude self.drawTextCenter(painter, alttxt, self.mediumTextSize, xCenter, 0) if vv == self.UNKNOWN_ALTITUDE: return vvPixHeight = -vv / self.ALTIMETER_VVI_SPAN * effectiveHalfHeight if abs(vvPixHeight) < markerHalfHeight: return # hidden behind marker. vvSign = -1 if vvPixHeight > 0: vvSign = 1 # QRectF vvRect(rightEdge - w*ALTIMETER_VVI_WIDTH, markerHalfHeight*vvSign, w*ALTIMETER_VVI_WIDTH, abs(vvPixHeight)*vvSign); vvArrowBegin = QPointF(rightEdge - w * self.ALTIMETER_VVI_WIDTH / 2, markerHalfHeight * vvSign) vvArrowEnd = QPointF(rightEdge - w * self.ALTIMETER_VVI_WIDTH / 2, vvPixHeight) painter.drawLine(vvArrowBegin, vvArrowEnd) # Yeah this is a repitition of above code but we are goigd to trash it all anyway, so no fix. vvArowHeadSize = abs(vvPixHeight - markerHalfHeight * vvSign) if vvArowHeadSize > w * self.ALTIMETER_VVI_WIDTH / 3: vvArowHeadSize = w * self.ALTIMETER_VVI_WIDTH / 3 xcenter = rightEdge - w * self.ALTIMETER_VVI_WIDTH / 2 vvArrowHead = QPointF(xcenter + vvArowHeadSize, vvPixHeight - vvSign * vvArowHeadSize) painter.drawLine(vvArrowHead, vvArrowEnd) vvArrowHead = QPointF(xcenter - vvArowHeadSize, vvPixHeight - vvSign * vvArowHeadSize) painter.drawLine(vvArrowHead, vvArrowEnd)
def drawPitchScale(self, painter, area, intrusion, drawNumbersLeft, drawNumbersRight): unused(intrusion) # The area should be quadratic but if not width is the major size. w = area.width() if w < area.height(): w = area.height() pen = QPen() pen.setWidthF(self.lineWidth) pen.setColor(Qt.white) painter.setPen(pen) savedTransform = painter.transform() # find the mark nearest center snap = qRound( self.pitch / self.PITCH_SCALE_RESOLUTION) * self.PITCH_SCALE_RESOLUTION _min = snap - self.PITCH_SCALE_HALFRANGE _max = snap + self.PITCH_SCALE_HALFRANGE degrees = _min while degrees <= _max: isMajor = degrees % (self.PITCH_SCALE_RESOLUTION * 2) == 0 linewidth = self.PITCH_SCALE_MINORWIDTH if isMajor: linewidth = self.PITCH_SCALE_MAJORWIDTH if abs(degrees) > self.PITCH_SCALE_WIDTHREDUCTION_FROM: # we want: 1 at PITCH_SCALE_WIDTHREDUCTION_FROM and PITCH_SCALE_WIDTHREDUCTION at 90. # That is PITCH_SCALE_WIDTHREDUCTION + (1-PITCH_SCALE_WIDTHREDUCTION) * f(pitch) # where f(90)=0 and f(PITCH_SCALE_WIDTHREDUCTION_FROM)=1 # f(p) = (90-p) * 1/(90-PITCH_SCALE_WIDTHREDUCTION_FROM) # or PITCH_SCALE_WIDTHREDUCTION + f(pitch) - f(pitch) * PITCH_SCALE_WIDTHREDUCTION # or PITCH_SCALE_WIDTHREDUCTION (1-f(pitch)) + f(pitch) fromVertical = -90 - self.pitch if self.pitch >= 0: fromVertical = 90 - self.pitch if fromVertical < 0: fromVertical = -fromVertical temp = fromVertical * 1 / ( 90.0 - self.PITCH_SCALE_WIDTHREDUCTION_FROM) linewidth *= (self.PITCH_SCALE_WIDTHREDUCTION * (1 - temp) + temp) shift = self.pitchAngleToTranslation(w, self.pitch - degrees) # TODO: Intrusion detection and evasion. That is, don't draw # where the compass has intruded. painter.translate(0, shift) start = QPointF(-linewidth * w, 0) end = QPointF(linewidth * w, 0) painter.drawLine(start, end) if isMajor and (drawNumbersLeft or drawNumbersRight): displayDegrees = degrees if displayDegrees > 90: displayDegrees = 180 - displayDegrees elif displayDegrees < -90: displayDegrees = -180 - displayDegrees if self.SHOW_ZERO_ON_SCALES or degrees: if drawNumbersLeft: self.drawTextRightCenter( painter, '{0}'.format(displayDegrees), self.mediumTextSize, -self.PITCH_SCALE_MAJORWIDTH * w - 10, 0) if drawNumbersRight: self.drawTextLeftCenter( painter, '{0}'.format(displayDegrees), self.mediumTextSize, self.PITCH_SCALE_MAJORWIDTH * w + 10, 0) painter.setTransform(savedTransform) degrees += self.PITCH_SCALE_RESOLUTION
def updateGPSSpeed(self, sourceUAS, timestamp, speed): self.groundspeed = self.groundspeed if math.isnan(speed) else speed unused(sourceUAS, timestamp)