1 #include "DocumentSerialize.h"
2 #include "EngaugeAssert.h"
7 #include "QtToString.h"
8 #include <QXmlStreamReader>
9 #include <QXmlStreamWriter>
12 unsigned int Point::m_identifierIndex = 0;
14 extern const QString AXIS_CURVE_NAME;
15 const QString POINT_IDENTIFIER_DELIMITER (
"_");
17 const double MISSING_ORDINAL_VALUE = 0;
18 const double MISSING_POSGRAPH_VALUE = 0;
25 const QPointF &posScreen) :
26 m_isAxisPoint (curveName == AXIS_CURVE_NAME),
27 m_identifier (uniqueIdentifierGenerator(curveName)),
28 m_posScreen (posScreen),
29 m_hasPosGraph (false),
30 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
32 m_ordinal (MISSING_ORDINAL_VALUE)
34 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
35 <<
" curveName=" << curveName.toLatin1().data()
36 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
37 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data();
39 ENGAUGE_ASSERT (!curveName.isEmpty ());
43 const QPointF &posScreen,
44 const QPointF &posGraph) :
46 m_identifier (uniqueIdentifierGenerator(curveName)),
47 m_posScreen (posScreen),
49 m_posGraph (posGraph),
51 m_ordinal (MISSING_ORDINAL_VALUE)
53 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
55 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
56 <<
" curveName=" << curveName.toLatin1().data()
57 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
58 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
59 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data();
61 ENGAUGE_ASSERT (!curveName.isEmpty ());
65 const QString &identifier,
66 const QPointF &posScreen,
67 const QPointF &posGraph,
70 m_identifier (identifier),
71 m_posScreen (posScreen),
73 m_posGraph (posGraph),
77 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
79 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
80 <<
" curveName=" << curveName.toLatin1().data()
81 <<
" identifier=" << m_identifier.toLatin1().data()
82 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
83 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
86 ENGAUGE_ASSERT (!curveName.isEmpty ());
90 const QPointF &posScreen,
91 const QPointF &posGraph,
94 m_identifier (uniqueIdentifierGenerator(curveName)),
95 m_posScreen (posScreen),
97 m_posGraph (posGraph),
101 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
103 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
104 <<
" curveName=" << curveName.toLatin1().data()
105 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
106 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
107 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
110 ENGAUGE_ASSERT (!curveName.isEmpty ());
114 const QString &identifier,
115 const QPointF &posScreen,
117 m_isAxisPoint (false),
118 m_identifier (identifier),
119 m_posScreen (posScreen),
120 m_hasPosGraph (false),
121 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
125 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
127 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
128 <<
" curveName=" << curveName.toLatin1().data()
129 <<
" identifier=" << identifier.toLatin1().data()
130 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
133 ENGAUGE_ASSERT (!curveName.isEmpty ());
137 const QPointF &posScreen,
139 m_isAxisPoint (false),
140 m_identifier (uniqueIdentifierGenerator(curveName)),
141 m_posScreen (posScreen),
142 m_hasPosGraph (false),
143 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
147 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
149 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point(identifier,posScreen,posGraph,ordinal)"
150 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
151 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
162 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::operator="
163 <<
" isAxisPoint=" << (point.
isAxisPoint() ?
"true" :
"false")
164 <<
" identifier=" << point.
identifier ().toLatin1().data()
165 <<
" posScreen=" << QPointFToString (point.
posScreen ()).toLatin1().data()
166 <<
" hasPosGraph=" << (point.
hasPosGraph() ?
"true" :
"false")
167 <<
" posGraph=" << QPointFToString (point.
posGraph (SKIP_HAS_CHECK)).toLatin1().data()
168 <<
" hasOrdinal=" << (point.
hasOrdinal() ?
"true" :
"false")
169 <<
" ordinal=" << point.
ordinal (SKIP_HAS_CHECK);
175 m_posGraph = point.
posGraph (SKIP_HAS_CHECK);
177 m_ordinal = point.
ordinal (SKIP_HAS_CHECK);
184 LOG4CPP_INFO_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);
197 m_posGraph = other.
posGraph (SKIP_HAS_CHECK);
199 m_ordinal = other.
ordinal (SKIP_HAS_CHECK);
204 QStringList tokens = pointIdentifier.split (POINT_IDENTIFIER_DELIMITER);
205 return tokens.value (0);
215 return m_hasPosGraph;
225 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::identifierIndex"
226 <<
" identifierIndex=" << m_identifierIndex;
228 return m_identifierIndex;
233 return m_isAxisPoint;
236 void Point::loadXml(QXmlStreamReader &reader)
238 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml";
242 QXmlStreamAttributes attributes = reader.attributes();
244 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER) &&
245 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX) &&
246 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT)) {
248 m_hasOrdinal = attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL);
250 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_POINT_ORDINAL).toDouble();
252 m_ordinal = MISSING_ORDINAL_VALUE;
255 QString
isAxisPoint = attributes.value(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT).toString();
257 m_identifier = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER).toString();
258 m_identifierIndex = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX).toInt();
259 m_isAxisPoint = (isAxisPoint == DOCUMENT_SERIALIZE_BOOL_TRUE);
260 m_hasPosGraph =
false;
261 m_posGraph.setX (MISSING_POSGRAPH_VALUE);
262 m_posGraph.setY (MISSING_POSGRAPH_VALUE);
264 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
265 (reader.name () != DOCUMENT_SERIALIZE_POINT)) {
267 loadNextFromReader(reader);
268 if (reader.atEnd()) {
273 if (reader.tokenType () == QXmlStreamReader::StartElement) {
275 if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN) {
277 attributes = reader.attributes();
279 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
280 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
282 m_posScreen.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
283 m_posScreen.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
289 }
else if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH) {
291 m_hasPosGraph =
true;
292 attributes = reader.attributes();
294 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
295 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
297 m_posGraph.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
298 m_posGraph.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
308 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml"
309 <<
" identifier=" << m_identifier.toLatin1().data()
310 <<
" identifierIndex=" << m_identifierIndex
311 <<
" posScreen=" << QPointFToString (m_posScreen).toLatin1().data()
312 <<
" posGraph=" << QPointFToString (m_posGraph).toLatin1().data()
313 <<
" ordinal=" << m_ordinal;
320 reader.raiseError(
"Cannot read point data");
326 if (applyHasCheck == KEEP_HAS_CHECK) {
327 ENGAUGE_ASSERT (m_hasOrdinal);
335 if (applyHasCheck == KEEP_HAS_CHECK) {
336 ENGAUGE_ASSERT (m_hasPosGraph);
348 QTextStream &str)
const
350 const QString UNDEFINED (
"undefined");
352 str << indentation <<
"Point\n";
354 indentation += INDENTATION_DELTA;
356 str << indentation <<
"identifier=" << m_identifier <<
"\n";
357 str << indentation <<
"posScreen=" << QPointFToString (m_posScreen) <<
"\n";
359 str << indentation <<
"posGraph=" << QPointFToString (m_posGraph) <<
"\n";
361 str << indentation <<
"posGraph=" << UNDEFINED <<
"\n";
364 str << indentation <<
"ordinal=" << m_ordinal <<
"\n";
366 str << indentation <<
"ordinal=" << UNDEFINED <<
"\n";
372 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::saveXml";
374 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT);
375 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER, m_identifier);
377 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL, QString::number (m_ordinal));
379 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT,
380 m_isAxisPoint ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
384 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX, QString::number (m_identifierIndex));
386 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN);
387 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posScreen.x()));
388 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posScreen.y()));
389 writer.writeEndElement();
392 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH);
393 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posGraph.x()));
394 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posGraph.y()));
395 writer.writeEndElement();
398 writer.writeEndElement();
403 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::setIdentifierIndex"
411 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setOrdinal"
412 <<
" identifier=" << m_identifier.toLatin1().data()
421 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosGraph"
422 <<
" identifier=" << m_identifier.toLatin1().data()
423 <<
" posGraph=" << QPointFToString(posGraph).toLatin1().data();
427 ENGAUGE_ASSERT (m_isAxisPoint);
429 m_hasPosGraph =
true;
435 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosScreen"
436 <<
" identifier=" << m_identifier.toLatin1().data()
437 <<
" posScreen=" << QPointFToString(posScreen).toLatin1().data();
444 return QString (
"%1%2%3")
445 .arg (AXIS_CURVE_NAME)
446 .arg (POINT_IDENTIFIER_DELIMITER)
450 QString Point::uniqueIdentifierGenerator (
const QString &curveName)
452 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::uniqueIdentifierGenerator"
453 <<
" curveName=" << curveName.toLatin1().data()
454 <<
" identifierIndex=" << m_identifierIndex;
456 return QString (
"%1%2point%3%4")
458 .arg (POINT_IDENTIFIER_DELIMITER)
459 .arg (POINT_IDENTIFIER_DELIMITER)
460 .arg (m_identifierIndex++);
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
bool isAxisPoint() const
True if point is an axis point. This is used only for sanity checks.
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...
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
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.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
QString identifier() const
Unique identifier for a specific Point.
bool hasPosGraph() const
True if graph position is defined.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setPosScreen(const QPointF &posScreen)
Set method for position in screen coordinates.
Point()
Default constructor so this class can be used inside a container.
bool hasOrdinal() const
True if ordinal is defined.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.