16 #include <QStringList> 18 #include <qfileinfo.h> 26 if (!QFileInfo(pathToXml).exists())
28 cx::reportError(QString(
"Cannot find probe config file [%1]").arg(pathToXml));
42 foreach(node, scannerNodes)
44 retval << node.firstChildElement(
"Name").text();
59 foreach(node, probeNodes)
61 retval << node.firstChildElement(
"Name").text();
71 foreach(node, rtSourceNodes)
73 retval << node.firstChildElement(
"Name").text();
81 QList<QDomNode> configNodes = this->
getConfigNodes(scanner, probe, rtSource);
83 foreach(node, configNodes)
85 retval << node.firstChildElement(
"ID").text();
92 QDomElement findElement(QDomNode parent, QString name)
94 QDomNode node = parent.namedItem(name);
95 QDomElement element = node.toElement();
97 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
105 template<
class TYPE>
bool readTextNode(TYPE* retval, QDomNode parent, QString name);
108 bool readTextNode<QString>(QString* retval, QDomNode parent, QString name)
110 QDomElement element = parent.namedItem(name).toElement();
111 bool found = !element.isNull() && !element.text().isNull();
113 *retval = element.text();
115 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
119 bool readTextNode<int>(
int* retval, QDomNode parent, QString name)
122 QDomElement element = parent.namedItem(name).toElement();
123 bool found = !element.isNull() && !element.text().isNull();
125 *retval = element.text().toInt(&ok);
128 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
134 cx::reportWarning(QString(
"Cannot convert node %2/%1 to int").arg(name).arg(parent.toElement().tagName()));
139 bool readTextNode<double>(
double* retval, QDomNode parent, QString name)
142 QDomElement element = parent.namedItem(name).toElement();
143 bool found = !element.isNull() && !element.text().isNull();
145 *retval = element.text().toDouble(&ok);
148 cx::reportWarning(QString(
"Cannot find node %2/%1").arg(name).arg(parent.toElement().tagName()));
154 cx::reportWarning(QString(
"Cannot convert node %2/%1 to double").arg(name).arg(parent.toElement().tagName()));
169 retval.
mNotes =
"Found no notes.";
171 QList<QDomNode> currentScannerNodeList = this->
getScannerNodes(scanner);
172 if(currentScannerNodeList.isEmpty())
177 QDomNode scannerNode = currentScannerNodeList.first();
179 QList<QDomNode> probeList = this->
getProbeNodes(scanner, probe);
180 if(probeList.isEmpty())
185 QDomNode probeNode = probeList.first();
191 QList<QDomNode> currentRtSourceNodeList = this->
getRTSourceNodes(scanner, probe, rtsource);
192 if(currentRtSourceNodeList.isEmpty())
194 cx::reportWarning(QString(
"No rtsources found (Missing temporal calibration) [%1/%2/%3]").arg(scanner).arg(probe).arg(rtsource));
197 QDomNode rtSourceNode = currentRtSourceNodeList.first();
203 QString tempCalPlatformName =
"None";
206 tempCalPlatformName =
"TemporalCalibrationWindows";
208 tempCalPlatformName =
"TemporalCalibrationApple";
210 tempCalPlatformName =
"TemporalCalibrationLinux";
212 QDomNode node = rtSourceNode.namedItem(tempCalPlatformName);
218 if(rtsource.compare(
"Digital")!=0)
220 QDomElement sizeNode = findElement(rtSourceNode,
"ImageSize");
221 readTextNode(&retval.
mImageWidth, sizeNode,
"Width");
226 QList<QDomNode> currentConfigNodeList = this->
getConfigNodes(scanner, probe, rtsource, configId);
227 if(currentConfigNodeList.isEmpty())
229 cx::reportWarning(QString(
"No nodes found in config [%1/%2/%3/%4]").arg(scanner).arg(probe).arg(rtsource).arg(configId));
232 QDomNode configNode = currentConfigNodeList.first();
234 readTextNode(&retval.
mName, configNode,
"Name");
235 if(rtsource.compare(
"Digital")!=0)
237 readTextNode(&retval.
mWidthDeg, configNode,
"WidthDeg");
240 readTextNode(&retval.
mDepth, configNode,
"Depth");
241 readTextNode(&retval.
mOffset, configNode,
"Offset");
243 QDomElement originElement = findElement(configNode,
"Origin");
244 readTextNode(&retval.
mOriginCol, originElement,
"Col");
245 readTextNode(&retval.
mOriginRow, originElement,
"Row");
247 QDomElement edgesElement = findElement(configNode,
"CroppingEdges");
248 readTextNode(&retval.
mLeftEdge, edgesElement,
"Left");
249 readTextNode(&retval.
mRightEdge, edgesElement,
"Right");
250 readTextNode(&retval.
mTopEdge, edgesElement,
"Top");
251 readTextNode(&retval.
mBottomEdge, edgesElement,
"Bottom");
253 QDomElement pixelSizeElement = findElement(configNode,
"PixelSize");
254 readTextNode(&retval.
mPixelWidth, pixelSizeElement,
"Width");
255 readTextNode(&retval.
mPixelHeight, pixelSizeElement,
"Height");
265 QList<QDomNode> retval;
276 if(node.firstChildElement(
"Name").text() == scanner)
285 QList<QDomNode> retval;
289 QDomNode scannerNode;
290 foreach(scannerNode, temp)
298 QDomNode scannerNode;
299 foreach(scannerNode, temp)
301 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(scannerNode.toElement().elementsByTagName(
"USProbe"));
303 foreach(probeNode, temp2)
305 if(probeNode.firstChildElement(
"Name").text() == probe)
306 retval.append(probeNode);
315 QList<QDomNode> retval;
316 if(rtSource ==
"ALL")
320 foreach(probeNode, temp)
329 foreach(probeNode, temp)
331 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(probeNode.toElement().elementsByTagName(
"RTSource"));
332 QDomNode rtSourceNode;
333 foreach(rtSourceNode, temp2)
335 if(rtSourceNode.firstChildElement(
"Name").text() == rtSource)
336 retval.append(rtSourceNode);
345 QList<QDomNode> retval;
349 QDomNode rtSourceNode;
350 foreach(rtSourceNode, temp)
358 QDomNode rtSourceNode;
359 foreach(rtSourceNode, temp)
361 QList<QDomNode> temp2 = this->
nodeListToListOfNodes(rtSourceNode.toElement().elementsByTagName(
"Config"));
363 foreach(configNode, temp2)
365 if(configNode.firstChildElement(
"ID").text() == config)
366 retval.append(configNode);
375 QList<QDomNode> retval;
376 for(
int i=0; i < list.count(); ++i)
378 retval.append(list.item(i));
385 QList<QDomNode> configNodes = this->
getConfigNodes(scanner, probe, rtsource, configId);
386 if (configNodes.empty())
389 QString(
"Failed to remove probe config: No such path %1/%2/%3/%4")
396 QDomNode victim = configNodes.first();
398 QDomNode parentNode = victim.parentNode();
399 parentNode.removeChild(victim);
400 victim = QDomElement();
413 while (node.hasChildNodes())
414 node.removeChild(node.firstChild());
428 QDomElement rtSourceNode = rtNodes.first().toElement();
429 if (rtSourceNode.isNull())
433 QDomElement configNode;
434 if (!configNodes.empty())
436 configNode = configNodes.first().toElement();
441 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()