Ejemplo n.º 1
0
/*
   Given a flight system and a file of airport names, each on a line,
   add the airports to the flight system.
 */
void parseAirports(flightSys_t* s, FILE* airportFile) {
    char name[MAX_NAME_LEN];
    while(fgets(name, MAX_NAME_LEN, airportFile)) {
	stripNewLine(name);
	addAirport(s,name);
    }
}
bool ChartElemNavaids::addNewAirport(const QString& airport_id, QString& err_msg)
{
    const Waypoint* existing_airport = getNavaid(airport_id, Waypoint::AIRPORT);
    if (existing_airport)
    {
        err_msg = QString("Navaids:AIRPORT: Airport with ID (%1) already exists").arg(airport_id);
        return false;
    }
    
    Airport *airport = (Airport*)m_chart_model->getNavdata()->getElementsWithSignal(
        airport_id, "", Waypoint::AIRPORT);
    
    if (!airport)
    {
        err_msg = QString("Navaids:AIRPORT: unknown airport with ID (%1)").arg(airport_id);
        delete airport;
        return false;
    }

    QDomDocument dom_doc = m_dom_element.ownerDocument();
    QDomElement new_element = dom_doc.createElement(CHART_NODE_NAME_NAVAIDS_AIRPORT);
    m_dom_element.appendChild(new_element);

    bool ret = addAirport(*airport, new_element, dom_doc, err_msg);
    setProjectionCenterWhenAppropriate(airport);
    delete airport;
    return ret;
}
Ejemplo n.º 3
0
void menuAddAirport(char* passMsg) {
	Airport airport;

	programHeader();
	printf("Dodawanie lotniska:\n\n");

	if (_inputAirport(&airport)) {
		if (NULL != findAirportByNameAndCountry(DB_HANDLE, airport.name, airport.country)) {
			sprintf(passMsg, "Nie mozna dodac lotniska. Lotnisko (%s, %s) juz istnieje.\n", airport.name, airport.country);
		}
		else {
			addAirport(DB_HANDLE, airport.name, airport.country);
			sprintf(passMsg, "Lotnisko (%s, %s) zostalo dodane.\n", airport.name, airport.country);
		}
	}
	else {
		sprintf(passMsg, "Nie mozna dodac lotniska. Niepoprawne dane.\n");
	}

	menuPrintAllAirports(passMsg);
}
Ejemplo n.º 4
0
/*	================== getOption =================
 This function reads in the user's desired chose
 of operation. Calls upon other functions to
 perform the procedure.
 Pre		pHeader - pointer to HEAD structure
 Post
 Return
 */
void getOption (HEAD* pHeader)
{
	//	Local Declarations
    char command;
    DATA target;
    DATA* airport = NULL;
	int i;
    
	//	Statements
    while ((command = menu()) != 'Q') {
        switch (command)
        {
            case 'A':
                if (addAirport(pHeader))
                {
                    while (checkHash(pHeader->pHash) == 1) {
                        pHeader->pHash = upsizeHash(pHeader->pHash);
                    }
					printf ("\n Succesfully added data.\n\n");
                }
                break;
            case 'D':
                printf("Enter the airport code: ");
                scanf(" %s", target.arpCode);
                
				if (deleteHash (pHeader, target))
                {
                    while (checkHash(pHeader->pHash) == -1) {
                        pHeader->pHash = downsizeHash(pHeader->pHash);
                    }
					printf ("\n Succesfully deleted data.\n\n");
                }
                
                break;
            case 'F':
                printf("Enter the airport code: ");
                scanf(" %s", target.arpCode);
				// fix sensitive input cases
				for (i = 0; i < strlen(target.arpCode); i++) {
					target.arpCode[i] = toupper(target.arpCode[i]);
				}
                airport = findHash(pHeader->pHash, &target);
                if (airport != NULL) {
                    processScreen(airport);
                }
                else printf("No airport exists\n");
                
                break;
            case 'L':
                printHash(pHeader->pHash);
                break;
            case 'K':
                BST_Traverse(pHeader->pTree, processScreen);
                break;
            case 'P':
                printTree(pHeader->pTree->root, 0);
				printf("\n");
                break;
            case 'W':
				outputFile (pHeader->pHash);
                break;
            case 'E':
				efficiency(pHeader->pHash);
                break;
			case 'H':
				pHeader->pHash = hashDemo(pHeader->pHash);
				break;
            default:
                printf("Invalid choice. Choose again\n");
                break;
        }
    }
    return;
}	// getOption
bool ChartElemNavaids::loadFromDomElement(QDomElement& dom_element, 
                                          QDomDocument& dom_doc,
                                          QString& err_msg)
{
    MYASSERT(!dom_element.isNull());
    TreeBaseXML::loadFromDomElement(dom_element, dom_doc, err_msg);

    if (m_dom_element.tagName() != CHART_NODE_NAME_NAVAIDS)
    {
        err_msg = QString("Wrong node name (%s), expected (%s)").
                  arg(m_dom_element.tagName()).arg(CHART_NODE_NAME_NAVAIDS);
        return false;
    }

    // loop through all navaids

    QDomNode node = m_dom_element.firstChild();
    for(; !node.isNull(); node = node.nextSibling())
    {
        QDomElement element = node.toElement();
        if (element.isNull()) continue;

        // extract info from node

        QString id = element.attribute(CHART_ATTR_ID);
        QString ctry = element.attribute(CHART_ATTR_CTRY);
        QString name = element.attribute(CHART_ATTR_NAME);
        double lat = element.attribute(CHART_ATTR_LAT).toDouble();
        double lon = element.attribute(CHART_ATTR_LON).toDouble();
        int freq = element.attribute(CHART_ATTR_FREQ).toUInt();
        bool has_dme = element.attribute(CHART_ATTR_DME).toInt();
        int elevation = element.attribute(CHART_ATTR_ELEV).toInt();

        // check info

        if (id.isEmpty())
        {
            err_msg = QString("Navaids: Missing ID at tag named (%1)").arg(element.tagName());
            return false;
        }

        // process element

        if (element.tagName() == CHART_NODE_NAME_NAVAIDS_VOR)
        {
            Vor* vor = 0;

            if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && freq != 0)
                vor = new Vor(id, name, lat, lon, freq, has_dme, 0, 0, ctry);
            else
                vor = (Vor*)m_chart_model->getNavdata()->getElementsWithSignal(
                    id, ctry, Waypoint::VOR);

            if (!vor)
            {
                err_msg = QString("Navaids:VOR: unknown VOR with ID (%1)").arg(id);
                return false;
            }

            if (!addVor(*vor, element, dom_doc, err_msg))
            {
                node = node.previousSibling();
                m_dom_element.removeChild(element);
            }
            
            delete vor;
        }
        else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_NDB)
        {
            Ndb* ndb = 0;

            if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && freq != 0)
                ndb = new Ndb(id, name, lat, lon, freq, 0, 0, ctry);
            else
                ndb = (Ndb*)m_chart_model->getNavdata()->getElementsWithSignal(
                    id, ctry, Waypoint::NDB);

            if (!ndb)
            {
                err_msg = QString("Navaids:NDB: unknown NDB with ID (%1)").arg(id);
                return false;
            }

            if (!addNdb(*ndb, element, dom_doc, err_msg))
            {
                node = node.previousSibling();
                m_dom_element.removeChild(element);
            }
            
            delete ndb;
        }
        else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_AIRPORT)
        {
            Airport* airport = 0;

            if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && 
                element.hasAttribute(CHART_ATTR_ELEV))
                airport = new Airport(id, name, lat, lon, elevation);
            else
                airport = (Airport*)m_chart_model->getNavdata()->getElementsWithSignal(
                    id, ctry, Waypoint::AIRPORT);

            if (!airport)
            {
                err_msg = QString("Navaids:AIRPORT: unknown AIRPORT with ID (%1)").arg(id);
                return false;
            }

            if (!addAirport(*airport, element, dom_doc, err_msg))
            {
                node = node.previousSibling();
                m_dom_element.removeChild(element);
            }

            delete airport;
        }
        else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_INTERSECTION)
        {
            Intersection* intersection = 0;
            
            if (lat != 0.0 && lon != 0.0)
                intersection = new Intersection(id, lat, lon, ctry);
            else
                intersection = (Intersection*)m_chart_model->getNavdata()->getElementsWithSignal(
                    id, ctry, Waypoint::INTERSECTION);

            if (!intersection)
            {
                err_msg = 
                    QString("Navaids:INTERSECTION: unknown INTERSECTION with ID (%1)").arg(id);
                return false;
            }

            if (!addIntersection(*intersection, element, dom_doc, err_msg))
            {
                node = node.previousSibling();
                m_dom_element.removeChild(element);
            }

            delete intersection;
        }
    }
    
    return true;
}