示例#1
0
int XmlStnInterface::readFile(const QString &fileName)
{
	GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects();
	QFile* file = new QFile(fileName);
	if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
	{
		std::cout << "XmlStnInterface::readFile() - Can't open xml-file." << "\n";
		delete file;
		return 0;
	}
	if (!checkHash(fileName))
	{
		delete file;
		return 0;
	}

	QDomDocument doc("OGS-STN-DOM");
	doc.setContent(file);
	QDomElement docElement = doc.documentElement(); //root element, used for identifying file-type
	if (docElement.nodeName().compare("OpenGeoSysSTN"))
	{
		std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << "\n";
		delete file;
		return 0;
	}

	QDomNodeList lists = docElement.childNodes();
	for (int i = 0; i < lists.count(); i++)
	{
		// read all the station lists
		QDomNodeList stationList = lists.at(i).childNodes();
		std::vector<GEOLIB::Point*>* stations = new std::vector<GEOLIB::Point*>;
		std::string stnName("[NN]");

		for (int j = 0; j < stationList.count(); j++)
		{
			const QDomNode station_node(stationList.at(j));
			const QString station_type(station_node.nodeName());
			if (station_type.compare("name") == 0)
				stnName = station_node.toElement().text().toStdString();
			else if (station_type.compare("stations") == 0)
				this->readStations(station_node, stations, fileName.toStdString());
			else if (station_type.compare("boreholes") == 0)
				this->readStations(station_node, stations, fileName.toStdString());
		}

		if (!stations->empty())
			geoObjects->addStationVec(stations, stnName);
		else
			delete stations;
	}

	delete file;

	return 1;
}
示例#2
0
std::vector<GEOLIB::Point*>* RapidXMLInterface::readStationFile(const std::string& fileName)
{
	std::vector<GEOLIB::Point*>* stations = new std::vector<GEOLIB::Point*>;
	std::ifstream in(fileName.c_str());
	if (in.fail())
	{
		std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file."
		          << "\n";
		return NULL;
	}

	// buffer file
	in.seekg(0, std::ios::end);
	size_t length = in.tellg();
	in.seekg(0, std::ios::beg);
	char* buffer = new char[length + 1];
	in.read(buffer, length);
	buffer[in.gcount()] = '\0';
	in.close();

	// build DOM tree
	rapidxml::xml_document<> doc;
	doc.parse<0>(buffer);

	// parse content
	if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN"))
	{
		std::cout << "XmlStnInterface::readFile() - Unexpected XML root."
		          << "\n";
		return NULL;
	}

	// iterate over all station lists
	for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list;
	     station_list = station_list->next_sibling())
	{
		std::string stnName("[NN]");

		stnName = station_list->first_node("name")->value();
		for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item;
		     list_item = list_item->next_sibling())
		{
			std::string b(list_item->name());
			if (std::string(list_item->name()).compare("stations") == 0)
				RapidXMLInterface::readStations(list_item, stations, fileName);
			if (std::string(list_item->name()).compare("boreholes") == 0)
				RapidXMLInterface::readStations(list_item, stations, fileName);
		}
	}

	doc.clear();
	delete[] buffer;

	return stations;
}
示例#3
0
std::vector<GeoLib::Point*> *RapidStnInterface::readStationFile(const std::string &fileName)
{
    std::ifstream in(fileName.c_str());
    if (in.fail())
    {
        ERR("XmlStnInterface::rapidReadFile() - Can't open xml-file.");
        return nullptr;
    }

    // read the file in a buffer
    std::stringstream sstr;
    sstr << in.rdbuf();
    std::string buffer = sstr.str();
    in.close();

    // build DOM tree
    rapidxml::xml_document<> doc;
    doc.parse<rapidxml::parse_non_destructive>(
        const_cast<char*>(buffer.data()));

    // parse content
    if (std::string(doc.first_node()->name()) != "OpenGeoSysSTN")
    {
        ERR("XmlStnInterface::readFile() - Unexpected XML root.");
        return nullptr;
    }

    auto* stations = new std::vector<GeoLib::Point*>;

    // iterate over all station lists
    for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling())
    {
        std::string stnName("[NN]");

        stnName = station_list->first_node("name")->value();
        for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling())
        {
            std::string b(list_item->name());
            if (b == "stations")
                RapidStnInterface::readStations(list_item, stations, fileName);
            if (b == "boreholes")
                RapidStnInterface::readStations(list_item, stations, fileName);
        }
    }

    doc.clear();

    return stations;
}