Exemple #1
0
def strip_auto_print_check():
    if settings.session_manager.isRunning():
        for fpl in env.FPLs.findAll():
            reason_to_print = auto_print_strip_reason(fpl)
            if reason_to_print != None:
                strip = Strip()
                strip.linkFPL(fpl)
                strip.writeDetail(
                    rack_detail,
                    some(settings.auto_print_collecting_rack,
                         default_rack_name))
                strip.writeDetail(auto_printed_detail, True)
                fpl.strip_auto_printed = True
                env.strips.addStrip(strip)
                signals.stripAutoPrinted.emit(strip, reason_to_print)
                signals.selectionChanged.emit()
Exemple #2
0
def new_strip_dialog(parent_widget, rack, linkToSelection=False):
    '''
	Returns the created strip if operation not aborted
	'''
    new_strip = Strip()
    new_strip.writeDetail(rack_detail, rack)
    if linkToSelection:
        new_strip.linkAircraft(selection.acft)
        if settings.strip_autofill_on_ACFT_link:
            new_strip.fillFromXPDR()
        new_strip.linkFPL(selection.fpl)
    dialog = StripDetailSheetDialog(parent_widget, new_strip)
    dialog.exec()
    if dialog.result() > 0:  # not rejected
        new_strip.writeDetail(rack_detail, dialog.selectedRack())
        env.strips.addStrip(new_strip)
        selection.selectStrip(new_strip)
        return new_strip
    else:
        return None
Exemple #3
0
 def createNewTraffic(self, spawn_coords, spawn_hdg):
     dialog = CreateTrafficDialog(spawn_coords, spawn_hdg, parent=self.gui)
     dialog.exec()
     if dialog.result() > 0:
         params = dialog.acftInitParams()
         params.XPDR_mode = new_traffic_XPDR_mode
         acft = ControlledAircraft(dialog.acftCallsign(), dialog.acftType(),
                                   params, None)
         acft.spawned = False
         acft.frozen = dialog.startFrozen()
         acft.tickOnce()
         self.aircraft_list.append(acft)
         if dialog.createStrip():
             strip = Strip()
             strip.writeDetail(FPL.CALLSIGN, acft.identifier)
             strip.writeDetail(FPL.ACFT_TYPE, acft.aircraft_type)
             strip.writeDetail(FPL.WTC, wake_turb_cat(acft.aircraft_type))
             strip.linkAircraft(acft)
             signals.receiveStrip.emit(strip)
         selection.selectAircraft(acft)
    def run(self):
        ## PREPARING QUERY
        pos = env.radarPos()
        qdict = {
            'username': settings.MP_social_name,
            'lon': pos.lon,
            'lat': pos.lat,
            'range': some(settings.ORSX_handover_range, settings.radar_range),
            'xmlVersion': '1.0',
            'contacts': ','.join(
                acft.identifier for acft in
                env.radar.contacts())  # should this be all FGMS connections?
        }
        if settings.publicised_frequency != None:
            qdict['frequency'] = str(settings.publicised_frequency)
        server_response = server_query('getFlightplans', qdict)
        ## USING RESPONSE
        if server_response != None:
            try:
                ww_root = ElementTree.fromstring(server_response)
            except ElementTree.ParseError as parse_error:
                print('Parse error in SX server data: %s' % parse_error)
                return
            new_ATCs = []

            # ATCs first
            for ww_atc in ww_root.find('atcsInRange').iter(
                    'atc'):  # NOTE the server sends the full list each time
                atc = ATC(ww_atc.find('callsign').text)
                atc.social_name = ww_atc.find('username').text
                atc.position = EarthCoords(float(ww_atc.find('lat').text),
                                           float(ww_atc.find('lon').text))
                ww_frq = ww_atc.find('frequency').text
                try:
                    atc.frequency = CommFrequency(ww_frq)
                except ValueError:
                    atc.frequency = None
                new_ATCs.append(atc)
            self.ATCs_on_last_run = new_ATCs

            # Then strip data (contact claims and handover)
            for ww_flightplan in ww_root.iter(
                    'flightplan'
            ):  # NOTE the server only sends those when something changes
                ww_header = ww_flightplan.find('header')
                ww_callsign = ww_header.find('callsign').text
                ww_owner = ww_header.find('owner').text
                if ww_owner == None:
                    if ww_callsign in self.current_contact_claims:
                        del self.current_contact_claims[ww_callsign]
                else:
                    self.current_contact_claims[ww_callsign] = ww_owner

                if ww_header.find(
                        'handover'
                ).text == settings.session_manager.myCallsign(
                ):  # RECEIVE A STRIP!
                    strip = Strip()
                    strip.writeDetail(received_from_detail, ww_owner)
                    strip.writeDetail(
                        assigned_SQ_detail,
                        ck_int(ww_header.find('squawk').text, base=8))
                    strip.writeDetail(assigned_altitude_detail,
                                      ww_header.find('assignedAlt').text)
                    # Ignored from WW header above: <flags>, <assignedRunway>, <assignedRoute>, <status>, <flight>
                    # Ignored from WW data below: <fuelTime>; used with ulterior motive: <pilot>
                    ww_data = ww_flightplan.find('data')
                    # ATC-pie hides a token in <pilot>, wake turb. on its left and callsign to its right
                    # e.g. <pilot>M__ATC-pie__X-FOO</pilot> for M turb. and X-FOO strip callsign
                    # If the token is absent, we know the strip is from OpenRadar
                    hidden_tokens = some(ww_data.find('pilot').text,
                                         '').split(ATCpie_hidden_string,
                                                   maxsplit=1)
                    if len(
                            hidden_tokens
                    ) == 1:  # hidden marker NOT present; previous strip editor was OpenRadar
                        strip.writeDetail(FPL.CALLSIGN, ww_callsign)
                    else:  # recognise strip edited with ATC-pie
                        strip.writeDetail(FPL.WTC, hidden_tokens[0])
                        strip.writeDetail(FPL.CALLSIGN, hidden_tokens[1])
                    strip.writeDetail(FPL.FLIGHT_RULES,
                                      ww_data.find('type').text)
                    strip.writeDetail(FPL.ACFT_TYPE,
                                      ww_data.find('aircraft').text)
                    strip.writeDetail(FPL.ICAO_DEP,
                                      ww_data.find('departure').text)
                    strip.writeDetail(FPL.ICAO_ARR,
                                      ww_data.find('destination').text)
                    strip.writeDetail(FPL.ROUTE, ww_data.find('route').text)
                    strip.writeDetail(FPL.CRUISE_ALT,
                                      ww_data.find('cruisingAlt').text)
                    spd = ck_int(ww_data.find('trueAirspeed').text)
                    if spd != None:
                        strip.writeDetail(FPL.TAS, Speed(spd))
                    strip.writeDetail(FPL.COMMENTS,
                                      ww_data.find('remarks').text)
                    # Possibly ignored details (OpenRadar confuses FPLs and strips): DEP time, EET, alt. AD, souls [*]
                    signals.receiveStrip.emit(strip)
                    send_update(ww_callsign, strip)  # Acknowledge strip
    def generateAircraftAndStrip(self):
        start_angle = uniform(0, 360)
        start_pos = env.radarPos().moved(Heading(start_angle, True),
                                         settings.solo_CTR_range_dist)
        end_pos = env.radarPos().moved(
            Heading(start_angle + 90 + uniform(1, 179), True),
            settings.solo_CTR_range_dist)
        transit_hdg = start_pos.headingTo(end_pos)
        dep_ad = world_navpoint_db.findClosest(env.radarPos().moved(transit_hdg.opposite(), \
          uniform(1.2 * settings.map_range, 5000)), types=[Navpoint.AD])
        dest_ad = world_navpoint_db.findClosest(env.radarPos().moved(transit_hdg, \
          uniform(1.2 * settings.map_range, 5000)), types=[Navpoint.AD])
        if env.pointOnMap(dep_ad.coordinates) or env.pointOnMap(
                dest_ad.coordinates):
            return None, None

        candidate_midpoints = [p for code in settings.solo_CTR_routing_points \
          for p in env.navpoints.findAll(code, types=[Navpoint.NDB, Navpoint.VOR, Navpoint.FIX]) \
          if start_pos.distanceTo(p.coordinates) < start_pos.distanceTo(end_pos)]
        midpoint = None if candidate_midpoints == [] else choice(
            candidate_midpoints)

        FLd10 = randint(settings.solo_CTR_floor_FL // 10,
                        settings.solo_CTR_ceiling_FL // 10)
        if settings.solo_CTR_semi_circular_rule == SemiCircRule.E_W and (FLd10 % 2 == 0) != (transit_hdg.magneticAngle() >= 180) \
         or settings.solo_CTR_semi_circular_rule == SemiCircRule.N_S and (FLd10 % 2 == 1) != (90 <= transit_hdg.magneticAngle() < 270):
            FLd10 += 1
            if 10 * FLd10 > settings.solo_CTR_ceiling_FL:
                return None, None
        p_alt = StdPressureAlt.fromFL(10 * FLd10)
        if not self.airbornePositionFullySeparated(start_pos, p_alt):
            return None, None
        acft_type = choice(self.playable_aircraft_types)
        hdg = start_pos.headingTo(some(midpoint, dest_ad).coordinates)
        params = SoloParams(Status(Status.AIRBORNE), start_pos, p_alt, hdg,
                            cruise_speed(acft_type))
        params.XPDR_code = env.nextSquawkCodeAssignment(XPDR_range_IFR_transit)
        new_acft = self.mkAiAcft(acft_type, params, dest_ad)
        dist_key = lambda atc: env.ATCs.getATC(atc).position.distanceTo(
            start_pos)
        received_from = min(env.ATCs.knownATCs(), key=dist_key)

        strip = Strip()
        strip.writeDetail(FPL.CALLSIGN, new_acft.identifier)
        strip.writeDetail(FPL.ACFT_TYPE, new_acft.aircraft_type)
        strip.writeDetail(FPL.WTC, wake_turb_cat(new_acft.aircraft_type))
        strip.writeDetail(FPL.FLIGHT_RULES, 'IFR')
        strip.writeDetail(FPL.ICAO_DEP, dep_ad.code)
        strip.writeDetail(FPL.ICAO_ARR, dest_ad.code)
        strip.writeDetail(FPL.CRUISE_ALT,
                          env.readStdAlt(new_acft.params.altitude))
        strip.writeDetail(assigned_altitude_detail,
                          strip.lookup(FPL.CRUISE_ALT))
        strip.writeDetail(assigned_SQ_detail, new_acft.params.XPDR_code)
        strip.writeDetail(received_from_detail, received_from)
        if midpoint != None:
            strip.insertRouteWaypoint(midpoint)

        new_acft.instructions.append(
            Instruction(Instruction.FOLLOW_ROUTE,
                        arg=strip.lookup(parsed_route_detail).dup()))
        return new_acft, strip
 def generateAircraftAndStrip(self):
     new_acft = received_from = None
     is_arrival = random() >= settings.solo_ARRvsDEP_balance
     if is_arrival:
         dep_ad = choose_dep_dest_AD(True)
         dest_ad = env.airport_data.navpoint
         midpoint = local_ee_point_closest_to(dest_ad,
                                              False)  # None if none found
         if settings.solo_role_APP:
             new_acft = self.new_arrival_APP(midpoint)
             received_from = 'CTR'
         elif settings.solo_role_TWR:
             new_acft = self.new_arrival_TWR()
             received_from = 'APP'
         elif settings.solo_role_GND:
             new_acft = self.new_arrival_GND()
             received_from = 'TWR'
     else:  # Create a departure
         dep_ad = env.airport_data.navpoint
         dest_ad = choose_dep_dest_AD(False)
         midpoint = local_ee_point_closest_to(dep_ad,
                                              True)  # None if none found
         if settings.solo_role_GND:
             new_acft = self.new_departure_GND(midpoint)
             received_from = 'DEL'
         elif settings.solo_role_TWR:
             new_acft = self.new_departure_TWR(midpoint)
             received_from = 'GND'
         elif settings.solo_role_DEP:
             new_acft = self.new_departure_DEP(midpoint)
             received_from = 'TWR'
     if new_acft == None:
         return None, None
     else:
         strip = Strip()
         strip.writeDetail(FPL.CALLSIGN, new_acft.identifier)
         strip.writeDetail(FPL.ACFT_TYPE, new_acft.aircraft_type)
         strip.writeDetail(FPL.WTC, wake_turb_cat(new_acft.aircraft_type))
         strip.writeDetail(FPL.FLIGHT_RULES, 'IFR')
         strip.writeDetail(assigned_SQ_detail, new_acft.params.XPDR_code)
         strip.writeDetail(received_from_detail, received_from)
         if received_from == 'CTR':
             strip.writeDetail(assigned_altitude_detail,
                               env.readStdAlt(new_acft.params.altitude))
         elif received_from == 'TWR' and not settings.solo_role_GND:
             strip.writeDetail(assigned_altitude_detail,
                               settings.solo_initial_climb_reading)
         # routing details
         strip.writeDetail(FPL.ICAO_DEP, dep_ad.code)
         strip.writeDetail(FPL.ICAO_ARR, dest_ad.code)
         if is_arrival and midpoint != None:  # arrival with local entry point
             try:
                 strip.writeDetail(
                     FPL.ROUTE,
                     world_routing_db.shortestRouteStr(dep_ad, midpoint) +
                     ' ' + midpoint.code)
             except ValueError:
                 strip.writeDetail(FPL.ROUTE, 'DCT %s' % midpoint.code)
         elif not is_arrival and midpoint != None:  # departure with local exit point
             try:
                 strip.writeDetail(
                     FPL.ROUTE, midpoint.code + ' ' +
                     world_routing_db.shortestRouteStr(midpoint, dest_ad))
             except ValueError:
                 strip.writeDetail(FPL.ROUTE, '%s DCT' % midpoint.code)
         return new_acft, strip