7 #include "DocumentSerialize.h" 8 #include "EngaugeAssert.h" 12 #include <QStringList> 13 #include <QTextStream> 14 #include "QtToString.h" 15 #include <QXmlStreamReader> 16 #include <QXmlStreamWriter> 19 unsigned int Point::m_identifierIndex = 0;
21 extern const QString AXIS_CURVE_NAME;
22 extern const QString DUMMY_CURVE_NAME;
23 const QString POINT_IDENTIFIER_DELIMITER_SAFE (
"\t");
24 const QString POINT_IDENTIFIER_DELIMITER_XML (
"_");
26 const double MISSING_ORDINAL_VALUE = 0;
27 const double MISSING_POSGRAPH_VALUE = 0;
35 m_isAxisPoint (curveName == AXIS_CURVE_NAME),
36 m_identifier (uniqueIdentifierGenerator(curveName)),
37 m_posScreen (posScreen),
38 m_hasPosGraph (false),
39 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
41 m_ordinal (MISSING_ORDINAL_VALUE),
44 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point" 45 <<
" curveName=" << curveName.toLatin1().data()
46 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
47 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data();
49 ENGAUGE_ASSERT (!curveName.isEmpty ());
57 m_identifier (uniqueIdentifierGenerator(curveName)),
58 m_posScreen (posScreen),
60 m_posGraph (posGraph),
62 m_ordinal (MISSING_ORDINAL_VALUE),
65 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME ||
66 curveName == DUMMY_CURVE_NAME);
68 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point" 69 <<
" curveName=" << curveName.toLatin1().data()
70 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
71 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
72 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
73 <<
" isXOnly=" << (isXOnly ?
"true" :
"false");
75 ENGAUGE_ASSERT (!curveName.isEmpty ());
85 m_identifier (identifier),
86 m_posScreen (posScreen),
88 m_posGraph (posGraph),
93 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
95 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point" 96 <<
" curveName=" << curveName.toLatin1().data()
97 <<
" identifier=" << m_identifier.toLatin1().data()
98 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
99 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
100 <<
" ordinal=" << ordinal
101 <<
" isXOnly=" << (isXOnly ?
"true" :
"false");
103 ENGAUGE_ASSERT (!curveName.isEmpty ());
111 m_isAxisPoint (true),
112 m_identifier (uniqueIdentifierGenerator(curveName)),
113 m_posScreen (posScreen),
114 m_hasPosGraph (true),
115 m_posGraph (posGraph),
120 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
122 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point" 123 <<
" curveName=" << curveName.toLatin1().data()
124 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
125 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
126 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
127 <<
" ordinal=" << ordinal
128 <<
" isXOnly=" << (isXOnly ?
"true" :
"false");
130 ENGAUGE_ASSERT (!curveName.isEmpty ());
137 m_isAxisPoint (false),
138 m_identifier (identifier),
139 m_posScreen (posScreen),
140 m_hasPosGraph (false),
141 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
146 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
148 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point" 149 <<
" curveName=" << curveName.toLatin1().data()
150 <<
" identifier=" << identifier.toLatin1().data()
151 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
154 ENGAUGE_ASSERT (!curveName.isEmpty ());
160 m_isAxisPoint (false),
161 m_identifier (uniqueIdentifierGenerator(curveName)),
162 m_posScreen (posScreen),
163 m_hasPosGraph (false),
164 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
169 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
171 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point(identifier,posScreen,posGraph,ordinal)" 172 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
173 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
184 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::Point(const Point &other)" 185 <<
" isAxisPoint=" << (other.
isAxisPoint() ?
"true" :
"false")
186 <<
" identifier=" << other.
identifier ().toLatin1().data()
187 <<
" posScreen=" << QPointFToString (other.
posScreen ()).toLatin1().data()
188 <<
" hasPosGraph=" << (other.
hasPosGraph() ?
"true" :
"false")
189 <<
" posGraph=" << QPointFToString (other.
posGraph (SKIP_HAS_CHECK)).toLatin1().data()
190 <<
" hasOrdinal=" << (other.
hasOrdinal() ?
"true" :
"false")
191 <<
" ordinal=" << other.
ordinal (SKIP_HAS_CHECK)
192 <<
" isXOnly=" << other.
isXOnly ();
198 m_posGraph = other.
posGraph (SKIP_HAS_CHECK);
200 m_ordinal = other.
ordinal (SKIP_HAS_CHECK);
206 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::operator=" 207 <<
" isAxisPoint=" << (point.
isAxisPoint() ?
"true" :
"false")
208 <<
" identifier=" << point.
identifier ().toLatin1().data()
209 <<
" posScreen=" << QPointFToString (point.
posScreen ()).toLatin1().data()
210 <<
" hasPosGraph=" << (point.
hasPosGraph() ?
"true" :
"false")
211 <<
" posGraph=" << QPointFToString (point.
posGraph (SKIP_HAS_CHECK)).toLatin1().data()
212 <<
" hasOrdinal=" << (point.
hasOrdinal() ?
"true" :
"false")
213 <<
" ordinal=" << point.
ordinal (SKIP_HAS_CHECK);
219 m_posGraph = point.
posGraph (SKIP_HAS_CHECK);
221 m_ordinal = point.
ordinal (SKIP_HAS_CHECK);
231 if (pointIdentifier.contains (POINT_IDENTIFIER_DELIMITER_SAFE)) {
233 tokens = pointIdentifier.split (POINT_IDENTIFIER_DELIMITER_SAFE);
239 tokens = pointIdentifier.split (POINT_IDENTIFIER_DELIMITER_XML);
243 return tokens.value (0);
253 return m_hasPosGraph;
263 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::identifierIndex" 264 <<
" identifierIndex=" << m_identifierIndex;
266 return m_identifierIndex;
271 return m_isAxisPoint;
279 void Point::loadXml(QXmlStreamReader &reader)
281 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml";
285 QXmlStreamAttributes attributes = reader.attributes();
289 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER) &&
290 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX) &&
291 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT)) {
293 m_hasOrdinal = attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL);
295 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_POINT_ORDINAL).toDouble();
297 m_ordinal = MISSING_ORDINAL_VALUE;
300 QString
isAxisPoint = attributes.value(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT).toString();
302 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_POINT_IS_X_ONLY)) {
303 isXOnly = attributes.value(DOCUMENT_SERIALIZE_POINT_IS_X_ONLY).toString();
306 m_identifier = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER).toString();
307 m_identifierIndex = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX).toInt();
308 m_isAxisPoint = (isAxisPoint == DOCUMENT_SERIALIZE_BOOL_TRUE);
309 m_hasPosGraph =
false;
310 m_posGraph.setX (MISSING_POSGRAPH_VALUE);
311 m_posGraph.setY (MISSING_POSGRAPH_VALUE);
312 m_isXOnly = (isXOnly == DOCUMENT_SERIALIZE_BOOL_TRUE);
314 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
315 (reader.name () != DOCUMENT_SERIALIZE_POINT)) {
317 loadNextFromReader(reader);
318 if (reader.atEnd()) {
323 if (reader.tokenType () == QXmlStreamReader::StartElement) {
325 if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN) {
327 attributes = reader.attributes();
329 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
330 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
332 m_posScreen.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
333 m_posScreen.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
339 }
else if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH) {
341 m_hasPosGraph =
true;
342 attributes = reader.attributes();
344 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
345 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
347 m_posGraph.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
348 m_posGraph.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
358 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml" 359 <<
" identifier=" << m_identifier.toLatin1().data()
360 <<
" identifierIndex=" << m_identifierIndex
361 <<
" posScreen=" << QPointFToString (m_posScreen).toLatin1().data()
362 <<
" posGraph=" << QPointFToString (m_posGraph).toLatin1().data()
363 <<
" ordinal=" << m_ordinal;
370 reader.raiseError(QObject::tr (
"Cannot read point data"));
376 if (applyHasCheck == KEEP_HAS_CHECK) {
377 ENGAUGE_ASSERT (m_hasOrdinal);
385 if (applyHasCheck == KEEP_HAS_CHECK) {
386 ENGAUGE_ASSERT (m_hasPosGraph);
398 QTextStream &str)
const 400 const QString UNDEFINED (
"undefined");
402 str << indentation <<
"Point\n";
404 indentation += INDENTATION_DELTA;
406 str << indentation <<
"identifier=" << m_identifier <<
"\n";
407 str << indentation <<
"posScreen=" << QPointFToString (m_posScreen) <<
"\n";
409 str << indentation <<
"posGraph=" << QPointFToString (m_posGraph) <<
"\n";
411 str << indentation <<
"posGraph=" << UNDEFINED <<
"\n";
414 str << indentation <<
"ordinal=" << m_ordinal <<
"\n";
416 str << indentation <<
"ordinal=" << UNDEFINED <<
"\n";
422 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::saveXml";
424 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT);
425 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER, m_identifier);
427 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL, QString::number (m_ordinal));
429 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT,
430 m_isAxisPoint ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
431 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IS_X_ONLY,
432 m_isXOnly ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
436 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX, QString::number (m_identifierIndex));
438 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN);
439 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posScreen.x()));
440 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posScreen.y()));
441 writer.writeEndElement();
447 const char FORMAT =
'g';
448 const int PRECISION = 16;
450 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH);
451 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posGraph.x(), FORMAT, PRECISION));
452 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posGraph.y(), FORMAT, PRECISION));
453 writer.writeEndElement();
456 writer.writeEndElement();
463 m_identifier = curveNameNew + m_identifier.mid (curveNameOld.length());
468 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::setIdentifierIndex" 476 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setOrdinal" 477 <<
" identifier=" << m_identifier.toLatin1().data()
486 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosGraph" 487 <<
" identifier=" << m_identifier.toLatin1().data()
488 <<
" posGraph=" << QPointFToString(posGraph).toLatin1().data();
492 ENGAUGE_ASSERT (m_isAxisPoint);
494 m_hasPosGraph =
true;
500 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosScreen" 501 <<
" identifier=" << m_identifier.toLatin1().data()
502 <<
" posScreen=" << QPointFToString(posScreen).toLatin1().data();
509 return QString (
"%1%2%3")
510 .arg (AXIS_CURVE_NAME)
511 .arg (POINT_IDENTIFIER_DELIMITER_SAFE)
515 QString Point::uniqueIdentifierGenerator (
const QString &curveName)
517 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::uniqueIdentifierGenerator" 518 <<
" curveName=" << curveName.toLatin1().data()
519 <<
" identifierIndex=" << m_identifierIndex;
521 return QString (
"%1%2point%3%4")
523 .arg (POINT_IDENTIFIER_DELIMITER_SAFE)
524 .arg (POINT_IDENTIFIER_DELIMITER_SAFE)
525 .arg (m_identifierIndex++);
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined...
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
static void setIdentifierIndex(unsigned int identifierIndex)
Reset the current index while performing a Redo.
static unsigned int identifierIndex()
Return the current index for storage in case we need to reset it later while performing a Redo...
bool isAxisPoint() const
True if point is an axis point. This is used only for sanity checks.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
Point & operator=(const Point &point)
Assignment constructor.
void setPosGraph(const QPointF &posGraph)
Set method for position in graph coordinates.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
QString identifier() const
Unique identifier for a specific Point.
bool hasOrdinal() const
True if ordinal is defined.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
bool hasPosGraph() const
True if graph position is defined.
void setPosScreen(const QPointF &posScreen)
Set method for position in screen coordinates.
Point()
Default constructor so this class can be used inside a container.
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setCurveName(const QString &curveName)
Update the point identifer to match the specified curve name.