QDomElement Masked_grid_geometry_xml_io::
  write_grid_geometry( QDir dir, QDomDocument& dom, const  Geostat_grid* grid) const{

	const Reduced_grid *mgrid =  dynamic_cast<const Reduced_grid*>( grid );

  Cartesian_grid_geometry_xml_io cgrid_io;

  QDomElement elem = cgrid_io.write_grid_geometry(dir, dom, grid);
	elem.setAttribute("nActiveCells",mgrid->size());

  QFile file( dir.absoluteFilePath("gridmask.sgems" ) );
  if( !file.open( QIODevice::WriteOnly ) ) {
  	elem.clear();
  	return elem;
  }
	QDataStream stream( &file );
	#if QT_VERSION >= 0x040600
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
	#endif

	const std::vector<bool> mask = mgrid->mask();
	std::vector<bool>::const_iterator it_mask = mask.begin();
	for(; it_mask != mask.end(); ++it_mask) stream<< *it_mask;
	file.close();
	return elem;
}
QDomElement Pointset_geometry_xml_io::
  write_grid_geometry( QDir dir, QDomDocument& dom, const  Geostat_grid* grid) const{


	const Point_set* pset = dynamic_cast<const Point_set*>(grid);
	QDomElement elemGeom = dom.createElement("Geometry");

  QFile file( dir.absoluteFilePath("coordinates.sgems" ) );
  if( !file.open( QIODevice::WriteOnly ) ) {
  	elemGeom.clear();
  	return elemGeom;
  }

	QDataStream stream( &file );
	#if QT_VERSION >= 0x040600
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
	#endif


	elemGeom.setAttribute("size",pset->size());
//	elemGeom.setAttribute("coordinates",pset->size());

	// write the x,y,z coordinates of each point
	const std::vector<Point_set::location_type>& locs = pset->point_locations();
	std::vector<Point_set::location_type>::const_iterator vec_it = locs.begin();
	for( ; vec_it != locs.end(); ++vec_it ) {
		stream << vec_it->x() << vec_it->y() << vec_it->z();
	}
	file.close();

	return elemGeom;
}
Beispiel #3
0
bool Xml::elementAt(QDomElement root, QString path, QDomElement &element) {
    element.clear();

    QStringList pathFragments = path.split('/');

    if(pathFragments.isEmpty())
        return false;

    return ::elementAt(root.firstChildElement(pathFragments[0]), pathFragments, 0, element);
}
Beispiel #4
0
bool Xml::elementAt(QDomDocument doc, QString path, QDomElement &element) {
    element.clear();

    QDomElement root = doc.documentElement();
    QStringList pathFragments = path.split('/');

    if(pathFragments.count() < 2 || !pathFragments[0].isEmpty())
        return false;

    return ::elementAt(root, pathFragments, 1, element);
}
// Clears nodes within the specified nodeMap
void clearNodes( DefSections &nodeMap )
{
	DefSections::iterator myIter;

	for( myIter = nodeMap.begin(); myIter != nodeMap.end(); ++myIter )
	{
		QDomElement node = myIter.data();
		node.clear(); // Delete all subnodes - i'm unsure if this delets all data
	}

	nodeMap.clear(); // Delete it's contents
}
/**
 * This method is used to read a child XML object of a XML object
 * @param parent The parent XML object
 * @param key The name of the child
 * @return The child node
 */
QDomElement CMapFileFilterXML::readChildElement(QDomElement *parent,QString key)
{
	QDomElement e;
	
	// Find Root Zone
    QDomNode n = parent->namedItem(key);
    if (n.isNull())
    {
		e.clear();
		return e;
    }

    e = n.toElement();

    return e;
}
void CGrammarManagerFromProgram::GetMacroDataFromXml(QList<QString>& categoryList)
{
	QDomElement currentElement = m_domDocument->documentElement();

	/*遍历分类列表*/
	for (int i = 0; i < categoryList.size(); i++)
	{
		/*所查找的分类*/
		QString strCategory = categoryList.at(i);
		/*当前分类下所有子节点*/
		QDomNodeList childNodes = currentElement.childNodes();
		/*遍历子节点*/
		for (int j = 0; j < childNodes.size(); j++)
		{
			if (childNodes.at(j).isElement())
			{
				QDomElement childElement = childNodes.at(j).toElement();
				/*若找到该分类,则遍历该分类下的子节点*/
				if (childElement.attribute(XML_ATTRIBUTE_NAME) == strCategory)
				{
					currentElement.clear();
					currentElement = childElement;
					break;
				}
			}
		}
	}

	/*宏命令列表*/
	QList<QString> strListMacro;
	QDomNodeList childNodes = currentElement.childNodes();
	for (int i = 0; i < childNodes.size(); i++)
	{
		if (childNodes.at(i).isElement())
		{
			strListMacro << childNodes.at(i).toElement().attribute(XML_ATTRIBUTE_NAME);

		}
	}

	//m_modelMacro->UpdateData(strListMacro);

}
QDomElement Log_data_grid_geometry_xml_io::
  write_grid_geometry( QDir dir, QDomDocument& dom, const  Geostat_grid* grid) const{

	const Log_data_grid* lgrid = dynamic_cast<const Log_data_grid*>(grid);

	QDomElement elemGeom = dom.createElement("Geometry");
	  QFile file( dir.absoluteFilePath("coordinates.sgems" ) );
	  if( !file.open( QIODevice::WriteOnly ) ) {
	  	elemGeom.clear();
	  	return elemGeom;
	  }

	QDataStream stream( &file );
	#if QT_VERSION >= 0x040600
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
	#endif

	// write the x,y,z coordinates of each point
	const std::vector<Point_set::location_type>& locs = lgrid->point_locations();
	std::vector<Point_set::location_type>::const_iterator vec_it = locs.begin();
	for( ; vec_it != locs.end(); ++vec_it ) {
		stream << vec_it->x() << vec_it->y() << vec_it->z();
	}
	file.close();



	 elemGeom.setAttribute("size",lgrid->size());
	 elemGeom.setAttribute("number_of_logs",lgrid->number_of_logs());

	 for(int i=0; i< lgrid->number_of_logs(); ++i) {
		 Log_data ldata = lgrid->get_log_data(i);
		 QDomElement elem_log = this->write_log_data_geometry(dom,&ldata);
		 elemGeom.appendChild(elem_log);

	 }

	 return elemGeom;

}
QDomElement Structured_grid_geometry_xml_io::
  write_grid_geometry( QDir dir, QDomDocument& dom, const  Geostat_grid* grid) const{

	const Reduced_grid *mgrid =  dynamic_cast<const Reduced_grid*>( grid );

	const Structured_grid* struct_grid = dynamic_cast<const Structured_grid*>(grid);

	 QDomElement elemGeom = dom.createElement("Geometry");
	 elemGeom.setAttribute("nx",struct_grid->nx());
	 elemGeom.setAttribute("ny",struct_grid->ny());
	 elemGeom.setAttribute("nz",struct_grid->nz());
   elemGeom.setAttribute("rotation_z_angle",struct_grid->rotation_z());

  QFile file( dir.absoluteFilePath("corner_coordinates.sgems" ) );
  if( !file.open( QIODevice::WriteOnly ) ) {
  	elemGeom.clear();
  	return elemGeom;
  }
	QDataStream stream( &file );
  /*
	#if QT_VERSION >= 0x040600
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
	#endif
  */
  stream.setFloatingPointPrecision(QDataStream::DoublePrecision);

  int n_points = (struct_grid->nx()+1)*(struct_grid->ny()+1)*(struct_grid->nz()+1);

	for(int i=0; i<n_points; ++i) {
    GsTLPoint pt = struct_grid->get_corner_point_locations(i);
    stream<< pt.x();
    stream<< pt.y();
    stream<< pt.z();
  }
	file.close();
	return elemGeom;

}