11#include "Poco/DOM/AutoPtr.h"
12#include "Poco/DOM/DOMParser.h"
13#include "Poco/DOM/Document.h"
14#include "Poco/DOM/NodeFilter.h"
15#include "Poco/DOM/NodeIterator.h"
16#include "Poco/SAX/InputSource.h"
17#include "Poco/SAX/SAXException.h"
24constexpr const char *SAMPLEGEOMETRY_TAG =
"samplegeometry";
25constexpr const char *VAL_ATT =
"val";
39 NodeIterator nodeIter(root, NodeFilter::SHOW_ELEMENT);
40 Node *node = nodeIter.nextNode();
42 auto *element =
static_cast<Element *
>(node);
43 auto argIter = args.find(node->nodeName());
44 if (argIter != args.end()) {
47 node = nodeIter.nextNode();
96 throw std::runtime_error(
"Can::createSampleShape() - No definition found "
97 "for the sample geometry.");
101 InputSource src(instrm);
103 AutoPtr<Document> doc;
105 doc = parser.parse(&src);
106 }
catch (SAXParseException &exc) {
107 std::ostringstream os;
108 os <<
"Can::createSampleShape() - Error parsing XML: " << exc.what();
109 throw std::invalid_argument(os.str());
111 Element *root = doc->documentElement();
113 updateTreeValues(root, args);
127 std::istringstream instrm(sampleShapeXML);
128 InputSource src(instrm);
130 AutoPtr<Document> doc = parser.parse(&src);
131 if (doc->documentElement()->nodeName() != SAMPLEGEOMETRY_TAG) {
132 std::ostringstream msg;
133 msg <<
"Can::setSampleShape() - XML definition "
134 "expected to be contained within a <"
135 << SAMPLEGEOMETRY_TAG <<
"> tag. Found " << doc->documentElement()->nodeName() <<
"instead.";
136 throw std::invalid_argument(msg.str());
147 if (
auto csgObj = std::dynamic_pointer_cast<CSGObject>(
m_shape)) {
Constructive Solid Geometry object.
Models a Container is used to hold a sample in the beam.
bool hasFixedSampleShape() const
IObject_sptr getSampleShape() const
std::unordered_map< std::string, double > ShapeArgs
Container & operator=(const Container &container)
bool hasCustomizableSampleShape() const
void setSampleShape(const std::string &sampleShapeXML)
Set the definition of the sample shape for this can.
IObject_sptr m_sampleShape
std::string m_sampleShapeXML
IObject_sptr createSampleShape(const ShapeArgs &args) const
Return an object that represents the sample shape from the current definition but override the defaul...
void setID(const std::string &id) override
Set the ID of the shape, if it is a CSG Object.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
std::string to_string(const wide_integer< Bits, Signed > &n)