37 #include <QStringList>
39 #include <qfileinfo.h>
47 if (!QFileInfo(pathToXml).exists())
49 cx::reportError(QString(
"Cannot find probe config file [%1]").arg(pathToXml));
63 foreach(node, scannerNodes)
65 retval << node.firstChildElement(
"Name").text();
80 foreach(node, probeNodes)
82 retval << node.firstChildElement(
"Name").text();
92 foreach(node, rtSourceNodes)
94 retval << node.firstChildElement(
"Name").text();
102 QList<QDomNode> configNodes = this->
getConfigNodes(scanner, probe, rtSource);
104 foreach(node, configNodes)
106 retval << node.firstChildElement(
"ID").text();
113 QDomElement findElement(QDomNode parent, QString name)
115 QDomNode node = parent.namedItem(name);
116 QDomElement element = node.toElement();
118 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
126 template<
class TYPE>
bool readTextNode(TYPE* retval, QDomNode parent, QString name);
129 bool readTextNode<QString>(QString* retval, QDomNode parent, QString name)
131 QDomElement element = parent.namedItem(name).toElement();
132 bool found = !element.isNull() && !element.text().isNull();
134 *retval = element.text();
136 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
140 bool readTextNode<int>(
int* retval, QDomNode parent, QString name)
143 QDomElement element = parent.namedItem(name).toElement();
144 bool found = !element.isNull() && !element.text().isNull();
146 *retval = element.text().toInt(&ok);
149 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
155 cx::reportWarning(QString(
"Cannot convert node %2/%1 to int").arg(name).arg(parent.toElement().tagName()));
160 bool readTextNode<double>(
double* retval, QDomNode parent, QString name)
163 QDomElement element = parent.namedItem(name).toElement();
164 bool found = !element.isNull() && !element.text().isNull();
166 *retval = element.text().toDouble(&ok);
169 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
175 cx::reportWarning(QString(
"Cannot convert node %2/%1 to double").arg(name).arg(parent.toElement().tagName()));
190 retval.
mNotes =
"Found no notes.";
192 QList<QDomNode> currentScannerNodeList = this->
getScannerNodes(scanner);
193 if(currentScannerNodeList.isEmpty())
198 QDomNode scannerNode = currentScannerNodeList.first();
200 QList<QDomNode> probeList = this->
getProbeNodes(scanner, probe);
201 if(probeList.isEmpty())
206 QDomNode probeNode = probeList.first();
212 QList<QDomNode> currentRtSourceNodeList = this->
getRTSourceNodes(scanner, probe, rtsource);
213 if(currentRtSourceNodeList.isEmpty())
215 cx::reportWarning(QString(
"No rtsources found (Missing temporal calibration) [%1/%2/%3]").arg(scanner).arg(probe).arg(rtsource));
218 QDomNode rtSourceNode = currentRtSourceNodeList.first();
224 QString tempCalPlatformName =
"None";
227 tempCalPlatformName =
"TemporalCalibrationWindows";
229 tempCalPlatformName =
"TemporalCalibrationApple";
231 tempCalPlatformName =
"TemporalCalibrationLinux";
233 QDomNode node = rtSourceNode.namedItem(tempCalPlatformName);
239 if(rtsource.compare(
"Digital")!=0)
241 QDomElement sizeNode = findElement(rtSourceNode,
"ImageSize");
242 readTextNode(&retval.
mImageWidth, sizeNode,
"Width");
247 QList<QDomNode> currentConfigNodeList = this->
getConfigNodes(scanner, probe, rtsource, configId);
248 if(currentConfigNodeList.isEmpty())
250 cx::reportWarning(QString(
"No nodes found in config [%1/%2/%3/%4]").arg(scanner).arg(probe).arg(rtsource).arg(configId));
253 QDomNode configNode = currentConfigNodeList.first();
255 readTextNode(&retval.
mName, configNode,
"Name");
256 if(rtsource.compare(
"Digital")!=0)
258 readTextNode(&retval.
mWidthDeg, configNode,
"WidthDeg");
261 readTextNode(&retval.
mDepth, configNode,
"Depth");
262 readTextNode(&retval.
mOffset, configNode,
"Offset");
264 QDomElement originElement = findElement(configNode,
"Origin");
265 readTextNode(&retval.
mOriginCol, originElement,
"Col");
266 readTextNode(&retval.
mOriginRow, originElement,
"Row");
268 QDomElement edgesElement = findElement(configNode,
"CroppingEdges");
269 readTextNode(&retval.
mLeftEdge, edgesElement,
"Left");
270 readTextNode(&retval.
mRightEdge, edgesElement,
"Right");
271 readTextNode(&retval.
mTopEdge, edgesElement,
"Top");
272 readTextNode(&retval.
mBottomEdge, edgesElement,
"Bottom");
274 QDomElement pixelSizeElement = findElement(configNode,
"PixelSize");
275 readTextNode(&retval.
mPixelWidth, pixelSizeElement,
"Width");
276 readTextNode(&retval.
mPixelHeight, pixelSizeElement,
"Height");
286 QList<QDomNode> retval;
297 if(node.firstChildElement(
"Name").text() == scanner)
306 QList<QDomNode> retval;
310 QDomNode scannerNode;
311 foreach(scannerNode, temp)
319 QDomNode scannerNode;
320 foreach(scannerNode, temp)
322 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(scannerNode.toElement().elementsByTagName(
"USProbe"));
324 foreach(probeNode, temp2)
326 if(probeNode.firstChildElement(
"Name").text() == probe)
327 retval.append(probeNode);
336 QList<QDomNode> retval;
337 if(rtSource ==
"ALL")
341 foreach(probeNode, temp)
350 foreach(probeNode, temp)
352 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(probeNode.toElement().elementsByTagName(
"RTSource"));
353 QDomNode rtSourceNode;
354 foreach(rtSourceNode, temp2)
356 if(rtSourceNode.firstChildElement(
"Name").text() == rtSource)
357 retval.append(rtSourceNode);
366 QList<QDomNode> retval;
370 QDomNode rtSourceNode;
371 foreach(rtSourceNode, temp)
379 QDomNode rtSourceNode;
380 foreach(rtSourceNode, temp)
382 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(rtSourceNode.toElement().elementsByTagName(
"Config"));
384 foreach(configNode, temp2)
386 if(configNode.firstChildElement(
"ID").text() == config)
387 retval.append(configNode);
396 QList<QDomNode> retval;
397 for(
int i=0; i < list.count(); ++i)
399 retval.append(list.item(i));
406 QList<QDomNode> configNodes = this->
getConfigNodes(scanner, probe, rtsource, configId);
407 if (configNodes.empty())
410 QString(
"Failed to remove probe config: No such path %1/%2/%3/%4")
417 QDomNode victim = configNodes.first();
419 QDomNode parentNode = victim.parentNode();
420 parentNode.removeChild(victim);
421 victim = QDomElement();
434 while (node.hasChildNodes())
435 node.removeChild(node.firstChild());
449 QDomElement rtSourceNode = rtNodes.first().toElement();
450 if (rtSourceNode.isNull())
454 QDomElement configNode;
455 if (!configNodes.empty())
457 configNode = configNodes.first().toElement();
462 rtSourceNode.appendChild(configNode);
QString qstring_cast(const T &val)
< a easy-to-work-with struct for a specific xml configuration
QList< QDomNode > getConfigNodes(QString scanner, QString probe, QString rtsource, QString config="ALL")
get a list of ALL confignodes for that scanner/probe/rtsource combo, or just the one you are looking ...
void reportError(QString msg)
int mBottomEdge
BottomEdge.
virtual QStringList getConfigIdList(QString scanner, QString probe, QString rtSource)
get a list of config ids for that scanner/probe/rsource combo
virtual QString getFileName()
double mWidthDeg
width in degrees
QList< QDomNode > nodeListToListOfNodes(QDomNodeList list)
converts a QDomNodeList to a QList<QDomNode>
void addTextElement(QDomElement parent, QString element, QString text)
QString mRtSource
realtime source
double mPixelWidth
Pixel width.
double mOriginRow
Origin.Row.
ProbeXmlConfigParserImpl(QString &pathToXml)
opens the file and reads it onto the QDomDocument
virtual QStringList getProbeList(QString scanner)
get a list of all probes for that scanner
QString mNotes
useful information
virtual void saveCurrentConfig(Configuration config)
int mHorizontalOffset
parameter for the grabber
virtual void removeConfig(QString scanner, QString probe, QString rtsource, QString configId)
QList< QDomNode > getRTSourceNodes(QString scanner, QString probe, QString rtSource="ALL")
get a list of ALL rtsourcenodes for that scanner/probe combo, or just the one you are looking for ...
void reportWarning(QString msg)
QString mConfigId
config id
double mPixelHeight
Pixel height.
QDomElement safeGetElement(QDomElement parent, QString childName)
QList< QDomNode > getScannerNodes(QString scanner="ALL")
get a list of ALL scanner nodes or just the one you are looking for
QString mUsScanner
scanner
int mImageWidth
Width of the used image format (x dim)
QDomDocument getDocument()
returns the document
virtual QStringList getRtSourceList(QString scanner, QString probe)
get a list of rt sources for that scanner/probe combo
int mImageHeight
Height of the used image format (y dim)
double mTemporalCalibration
delay in timestamping in grabber source relative to master clock.
QString mName
Name of config set.
virtual QStringList getScannerList()
get a list of all scanner in the xml
void save()
save entire document.
virtual Configuration getConfiguration(QString scanner, QString probe, QString rtsource, QString configId)
get a easy-to-work-with struct of a specific config
QList< QDomNode > getProbeNodes(QString scanner, QString probe="ALL")
get a list of ALL probenodes for that scanner, or just the one you are looking for ...
Helper class for xml files used to store ssc/cx data.
double mOriginCol
Origin.Col.
virtual ~ProbeXmlConfigParserImpl()