PLaSK library
|
Allow to read geometry from XML. More...
#include <plask/geometry/reader.hpp>
Classes | |
struct | RegisterChangerReader |
Helper which call registerChangerReader in constructor. More... | |
struct | RegisterObjectReader |
Helper which call registerObjectReader in constructor. More... | |
struct | RevertMaterialsAreRequired |
Revert materialsAreRequired flag in destructor. More... | |
struct | SetExpectedSuffix |
Store current expectedSuffix, set new one, and restore old when out of the scope (in destructor). More... | |
Public Types | |
typedef shared_ptr< GeometryObject > | object_read_f(GeometryReader &reader) |
Create new geometry object with parameters reading from XML source. | |
typedef std::function< GeometryObject::Changer *(GeometryReader &reader)> | changer_read_f |
Create new copy transform with parameters reading from XML source. | |
Public Member Functions | |
const AxisNames & | getAxisNames () const |
std::string | getAxisName (std::size_t axis_index) |
Get current axis name. | |
std::string | getAxisLongName () |
Get current lon direction axis name. | |
std::string | getAxisTranName () |
Get current tran direction axis name. | |
std::string | getAxisVertName () |
Get current up direction axis name. | |
shared_ptr< Material > | getMaterial (const std::string &material_full_name) const |
Get material from material source (typically material database) connected with this reader. | |
shared_ptr< MaterialsDB::MixedCompositionFactory > | getMixedCompositionFactory (const std::string &material1_full_name, const std::string &material2_full_name, double shape=1.) const |
shared_ptr< Material > | requireMaterial () const |
Read material from XML source (from attribute with name XML_MATERIAL_ATTR). | |
SolidOrGradientMaterial | requireSolidOrGradientMaterial () const |
Read material or gradient material factory from XML source. | |
GeometryReader (Manager &manager, XMLReader &source, const MaterialsDB &materialsDB=MaterialsDB::getDefault()) | |
shared_ptr< GeometryObject > | readObject () |
Read geometry object from source and add it Manager structures. | |
shared_ptr< GeometryObject > | readExactlyOneChild () |
Helper function to read objects which have exactly one child (typically: transform). | |
template<typename RequiredObjectType > | |
shared_ptr< RequiredObjectType > | readObject () |
Call readObject() and try dynamic cast it to RequiredObjectType. | |
template<typename RequiredObjectType > | |
shared_ptr< RequiredObjectType > | readExactlyOneChild () |
Call readExactlyOneChild() and try dynamic cast it to RequiredObjectType. | |
shared_ptr< Geometry > | readGeometry () |
Try reading calculation space. | |
shared_ptr< GeometryObject > | requireObjectWithName (const std::string &name) const |
Get named objects. | |
shared_ptr< GeometryObject > | requireObjectFromAttribute (const std::string &attr) const |
Get objects from attribute. | |
void | registerObjectName (const std::string &name, shared_ptr< GeometryObject > object) |
Add name of object to register. | |
void | registerObjectName (const plask::optional< std::string > &name, shared_ptr< GeometryObject > object) |
Add name of object to register. | |
void | registerObjectName (const plask::optional< const std::string > &name, shared_ptr< GeometryObject > object) |
Add name of object to register. | |
void | registerObjectNameFromCurrentNode (shared_ptr< GeometryObject > object) |
Add name of object to register. | |
template<> | |
shared_ptr< GeometryObject > | readObject () |
template<> | |
shared_ptr< GeometryObject > | readExactlyOneChild () |
Static Public Member Functions | |
static std::map< std::string, object_read_f * > & | objectReaders () |
static void | registerObjectReader (const std::string &tag_name, object_read_f *reader) |
Add reader to objectReaders. | |
static std::map< std::string, changer_read_f > & | changerReaders () |
static void | registerChangerReader (const std::string &tag_name, changer_read_f reader) |
Add reader to changerReaders. | |
Public Attributes | |
bool | materialsAreRequired |
true if materials in leafs are required, false if we read only shape | |
const char * | expectedSuffix |
Currently expected suffix for names of geometry objects types, can have one of the following values: | |
Manager & | manager |
Geometry manager which stores reading results. | |
XMLReader & | source |
XML data source. | |
const MaterialsDB * | materialsDB |
Source of materials, typically use material database. | |
Static Public Attributes | |
static constexpr const char *const | XML_NAME_ATTR = "name" |
name of the object's/geometry's name attribute in XML | |
static constexpr const char *const | XML_MATERIAL_ATTR = "material" |
name of the material attribute in XML | |
static constexpr const char *const | XML_MATERIAL_TOP_ATTR = "material-top" |
name of the top material attribute in XML | |
static constexpr const char *const | XML_MATERIAL_BOTTOM_ATTR = "material-bottom" |
name of the bottom material attribute in XML | |
static constexpr const char *const | XML_MATERIAL_GRADING_ATTR = "material-shape" |
name of the shape exponent attribute in XML | |
Allow to read geometry from XML.
Have references to both: XML data source reader and geometry manager. Manage names of axis while reading.
Definition at line 34 of file reader.hpp.
typedef std::function<GeometryObject::Changer*(GeometryReader& reader)> plask::GeometryReader::changer_read_f |
Create new copy transform with parameters reading from XML source.
After return reader should point to end of tag of this object. Can call managers methods to read children (GeometryReader::readObject). Should throw exception if can't create object.
Definition at line 98 of file reader.hpp.
typedef shared_ptr< GeometryObject > plask::GeometryReader::object_read_f(GeometryReader &reader) |
Create new geometry object with parameters reading from XML source.
After return reader should point to end of tag of this object. Can call managers methods to read children (GeometryReader::readObject). Should throw exception if can't create object.
Definition at line 57 of file reader.hpp.
plask::GeometryReader::GeometryReader | ( | plask::Manager & | manager, |
plask::XMLReader & | source, | ||
const MaterialsDB & | materialsDB = MaterialsDB::getDefault() |
||
) |
manager | |
source | xml data source from which object data should be read |
materialsDB | materials database used to set leafs materials |
Definition at line 118 of file reader.cpp.
|
static |
Definition at line 91 of file reader.cpp.
|
inline |
Get current lon direction axis name.
Definition at line 137 of file reader.hpp.
std::string plask::GeometryReader::getAxisName | ( | std::size_t | axis_index | ) |
Get current axis name.
axis_index | axis index |
axis_index
Definition at line 102 of file reader.cpp.
Definition at line 100 of file reader.cpp.
|
inline |
Get current tran direction axis name.
Definition at line 143 of file reader.hpp.
|
inline |
Get current up direction axis name.
Definition at line 149 of file reader.hpp.
shared_ptr< Material > plask::GeometryReader::getMaterial | ( | const std::string & | material_full_name | ) | const |
Get material from material source (typically material database) connected with this reader.
Throw exception if can't get material (no material with given name, etc.).
material_full_name | full material name to get |
material_full_name
Definition at line 26 of file reader.cpp.
shared_ptr< MaterialsDB::MixedCompositionFactory > plask::GeometryReader::getMixedCompositionFactory | ( | const std::string & | material1_full_name, |
const std::string & | material2_full_name, | ||
double | shape = 1. |
||
) | const |
Definition at line 38 of file reader.cpp.
|
static |
Definition at line 82 of file reader.cpp.
shared_ptr< GeometryObject > plask::GeometryReader::readExactlyOneChild | ( | ) |
Helper function to read objects which have exactly one child (typically: transform).
Before call source reader should point to parent object tag (typically transform object) and after call it will be point to end of parent object tag.
Definition at line 255 of file reader.cpp.
|
inline |
Call readExactlyOneChild() and try dynamic cast it to RequiredObjectType.
RequiredObjectType | required type of object |
Definition at line 359 of file reader.hpp.
|
inline |
Definition at line 359 of file reader.hpp.
shared_ptr< Geometry > plask::GeometryReader::readGeometry | ( | ) |
Try reading calculation space.
Throw exception if can't.
Definition at line 267 of file reader.cpp.
shared_ptr< GeometryObject > plask::GeometryReader::readObject | ( | ) |
Read geometry object from source
and add it Manager structures.
Typically it creates new geometry object using objectReaders, but it also support references and can return existing objects.
After call source reader point to end of tag which represent read object.
NamesConflictException | if object with read name already exists |
NoSuchGeometryObject | if 'again' object references to object which does not exists |
NoAttrException | if XML tag has no required attributes |
Definition at line 126 of file reader.cpp.
|
inline |
Call readObject() and try dynamic cast it to RequiredObjectType.
RequiredObjectType | required type of object |
UnexpectedGeometryObjectTypeException | if requested object is not of type RequiredObjectType |
NamesConflictException | if object with read name already exists |
NoSuchGeometryObject | if 'again' object references to object which does not exists |
NoAttrException | if XML tag has no required attributes |
Definition at line 345 of file reader.hpp.
|
inline |
Definition at line 345 of file reader.hpp.
|
static |
Add reader to changerReaders.
tag_name | XML tag name |
reader | changer reader function |
Definition at line 96 of file reader.cpp.
|
inline |
Add name of object to register.
Do nothing if name
has no value.
It throws exception in case of names conflict.
name | name of given object (can be auto-generated: in form '#'+number) |
object | geometry object which should be available by given name |
Definition at line 321 of file reader.hpp.
|
inline |
Add name of object to register.
Do nothing if name
has no value.
It throws exception in case of names conflict.
name | name of given object (can be auto-generated: in form '#'+number) |
object | geometry object which should be available by given name |
Definition at line 310 of file reader.hpp.
void plask::GeometryReader::registerObjectName | ( | const std::string & | name, |
shared_ptr< GeometryObject > | object | ||
) |
Add name of object to register.
It throws exception in case of names conflict.
name | name of given object (can be auto-generated: in form '#'+number) |
object | geometry object which should be available by given name |
Definition at line 369 of file reader.cpp.
|
inline |
Add name of object to register.
Read name from current, XML source tag. Do nothing if name attribute is not available.
It throws exception in case of names conflict.
object | geometry object which should be available by name which was read from current tag |
Definition at line 333 of file reader.hpp.
|
static |
Add reader to objectReaders.
tag_name | XML tag name |
reader | object reader function |
Definition at line 87 of file reader.cpp.
|
inline |
Read material from XML source (from attribute with name XML_MATERIAL_ATTR).
Throw exception if there is no XML_MATERIAL_ATTR attribute or can't get material (no material with given name, etc.).
Definition at line 201 of file reader.hpp.
|
inline |
Get objects from attribute.
It support both: named objects (from manager) and auto-named objects.
attr | attribute holding object name |
NoSuchGeometryObject | if object was not found |
Definition at line 285 of file reader.hpp.
shared_ptr< GeometryObject > plask::GeometryReader::requireObjectWithName | ( | const std::string & | name | ) | const |
Get named objects.
It support both: named objects (from manager) and auto-named objects.
name | object name (can be auto-generated: in form '#'+number) |
NoSuchGeometryObject | if object was not found |
Definition at line 351 of file reader.cpp.
SolidOrGradientMaterial plask::GeometryReader::requireSolidOrGradientMaterial | ( | ) | const |
Read material or gradient material factory from XML source.
Definition at line 52 of file reader.cpp.
Currently expected suffix for names of geometry objects types, can have one of the following values:
Definition at line 89 of file reader.hpp.
Manager& plask::GeometryReader::manager |
Geometry manager which stores reading results.
Definition at line 174 of file reader.hpp.
bool plask::GeometryReader::materialsAreRequired |
true
if materials in leafs are required, false
if we read only shape
Definition at line 48 of file reader.hpp.
const MaterialsDB* plask::GeometryReader::materialsDB |
Source of materials, typically use material database.
Definition at line 180 of file reader.hpp.
XMLReader& plask::GeometryReader::source |
XML data source.
Definition at line 177 of file reader.hpp.
name of the material attribute in XML
Definition at line 42 of file reader.hpp.
|
staticconstexpr |
name of the bottom material attribute in XML
Definition at line 44 of file reader.hpp.
|
staticconstexpr |
name of the shape exponent attribute in XML
Definition at line 45 of file reader.hpp.
|
staticconstexpr |
name of the top material attribute in XML
Definition at line 43 of file reader.hpp.
name of the object's/geometry's name attribute in XML
Definition at line 41 of file reader.hpp.