#!/usr/bin/env python #**************************************************************************** # palndata.py, provides non-GUI base classes for flight plan data # # FlyWay, a VFR/IFR Route Planner for Pilots # Copyright (C) 2002, Douglas W. Bell # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License, Version 2. This program is # distributed in the hope that it will be useful, but WITTHOUT ANY WARRANTY. #***************************************************************************** class PlanData: """Stores flight plan data and sets defaults""" type1 = 0 type2 = 1 type3 = 2 craftID = 3 equip = 4 altitude = 5 route1 = 6 route2 = 7 route3 = 8 route4 = 9 remark1 = 10 remark2 = 11 remark3 = 12 fuelHr = 13 fuelMin = 14 alternate = 15 pilot1 = 16 pilot2 = 17 pilot3 = 18 numAboard = 19 color = 20 listLength = 21 intData = ((altitude, 0, 60000), (fuelHr, 0, 24), \ (fuelMin, 0, 59), (numAboard, 1, 99)) optionData = ('PlanType1', 'PlanType2', 'PlanType3', 'PlanCraftID', \ 'PlanEquip', 'PlanAltitude', '', '', '', '', \ 'PlanRemark1', 'PlanRemark2', 'PlanRemark3', \ 'PlanFuelHr', 'PlanFuelMin', '', 'PlanPilot1', \ 'PlanPilot2', 'PlanPilot3', 'PlanNumAboard', 'PlanColor') def __init__(self, option, list=None): self.data = [''] * PlanData.listLength self.option = option self.intList = [data[0] for data in PlanData.intData] self.intMinList = [None] * PlanData.listLength self.intMaxList = [None] * PlanData.listLength for data in PlanData.intData: self.intMinList[data[0]] = data[1] self.intMaxList[data[0]] = data[2] if list: self.readFile(list) def readFile(self, list): """Set plan data to list from open file""" self.data = list self.data.extend([''] * (PlanData.listLength - len(self.data))) def writeFile(self): """Return list to write to a file""" return [line + '\n' for line in self.data] def setToDefaults(self): """Set this plan to all current option settings""" for i in range(PlanData.listLength): if PlanData.optionData[i]: if i in self.intList: self.data[i] = str(self.option.\ intData(PlanData.optionData[i], \ self.intMinList[i], \ self.intMaxList[i])) else: self.data[i] = self.option.strData(PlanData.\ optionData[i], 1) def setDefaultRoute(self, route): """Add direct routing based on route""" self.data[PlanData.route1] = ' .. '.join([wp.ident() for wp in \ route.wpList[1:-1]]) self.data[PlanData.route2] = self.data[PlanData.route3] = \ self.data[PlanData.route4] = '' self.data[PlanData.alternate] = '' def updateDefaults(self): """Update options with entries from this plan""" for i in range(PlanData.listLength): if PlanData.optionData[i]: self.option.changeData(PlanData.optionData[i], self.data[i], 1) self.option.writeChanges()