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 extern const QString DUMMY_CURVE_NAME;
16 const QString POINT_IDENTIFIER_DELIMITER (
"\t");
18 const double MISSING_ORDINAL_VALUE = 0;
19 const double MISSING_POSGRAPH_VALUE = 0;
26 const QPointF &posScreen) :
27 m_isAxisPoint (curveName == AXIS_CURVE_NAME),
28 m_identifier (uniqueIdentifierGenerator(curveName)),
29 m_posScreen (posScreen),
30 m_hasPosGraph (false),
31 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
33 m_ordinal (MISSING_ORDINAL_VALUE)
35 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
36 <<
" curveName=" << curveName.toLatin1().data()
37 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
38 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data();
40 ENGAUGE_ASSERT (!curveName.isEmpty ());
44 const QPointF &posScreen,
45 const QPointF &posGraph) :
47 m_identifier (uniqueIdentifierGenerator(curveName)),
48 m_posScreen (posScreen),
50 m_posGraph (posGraph),
52 m_ordinal (MISSING_ORDINAL_VALUE)
54 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME ||
55 curveName == DUMMY_CURVE_NAME);
57 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
58 <<
" curveName=" << curveName.toLatin1().data()
59 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
60 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
61 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data();
63 ENGAUGE_ASSERT (!curveName.isEmpty ());
67 const QString &identifier,
68 const QPointF &posScreen,
69 const QPointF &posGraph,
72 m_identifier (identifier),
73 m_posScreen (posScreen),
75 m_posGraph (posGraph),
79 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
81 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
82 <<
" curveName=" << curveName.toLatin1().data()
83 <<
" identifier=" << m_identifier.toLatin1().data()
84 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
85 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
88 ENGAUGE_ASSERT (!curveName.isEmpty ());
92 const QPointF &posScreen,
93 const QPointF &posGraph,
96 m_identifier (uniqueIdentifierGenerator(curveName)),
97 m_posScreen (posScreen),
99 m_posGraph (posGraph),
103 ENGAUGE_ASSERT (curveName == AXIS_CURVE_NAME);
105 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
106 <<
" curveName=" << curveName.toLatin1().data()
107 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
108 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
109 <<
" posGraph=" << QPointFToString (posGraph).toLatin1().data()
112 ENGAUGE_ASSERT (!curveName.isEmpty ());
116 const QString &identifier,
117 const QPointF &posScreen,
119 m_isAxisPoint (false),
120 m_identifier (identifier),
121 m_posScreen (posScreen),
122 m_hasPosGraph (false),
123 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
127 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
129 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point"
130 <<
" curveName=" << curveName.toLatin1().data()
131 <<
" identifier=" << identifier.toLatin1().data()
132 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
135 ENGAUGE_ASSERT (!curveName.isEmpty ());
139 const QPointF &posScreen,
141 m_isAxisPoint (false),
142 m_identifier (uniqueIdentifierGenerator(curveName)),
143 m_posScreen (posScreen),
144 m_hasPosGraph (false),
145 m_posGraph (MISSING_POSGRAPH_VALUE, MISSING_POSGRAPH_VALUE),
149 ENGAUGE_ASSERT (curveName != AXIS_CURVE_NAME);
151 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point(identifier,posScreen,posGraph,ordinal)"
152 <<
" identifierGenerated=" << m_identifier.toLatin1().data()
153 <<
" posScreen=" << QPointFToString (posScreen).toLatin1().data()
164 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::operator="
165 <<
" isAxisPoint=" << (point.
isAxisPoint() ?
"true" :
"false")
166 <<
" identifier=" << point.
identifier ().toLatin1().data()
167 <<
" posScreen=" << QPointFToString (point.
posScreen ()).toLatin1().data()
168 <<
" hasPosGraph=" << (point.
hasPosGraph() ?
"true" :
"false")
169 <<
" posGraph=" << QPointFToString (point.
posGraph (SKIP_HAS_CHECK)).toLatin1().data()
170 <<
" hasOrdinal=" << (point.
hasOrdinal() ?
"true" :
"false")
171 <<
" ordinal=" << point.
ordinal (SKIP_HAS_CHECK);
177 m_posGraph = point.
posGraph (SKIP_HAS_CHECK);
179 m_ordinal = point.
ordinal (SKIP_HAS_CHECK);
186 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::Point(const Point &other)"
187 <<
" isAxisPoint=" << (other.
isAxisPoint() ?
"true" :
"false")
188 <<
" identifier=" << other.
identifier ().toLatin1().data()
189 <<
" posScreen=" << QPointFToString (other.
posScreen ()).toLatin1().data()
190 <<
" hasPosGraph=" << (other.
hasPosGraph() ?
"true" :
"false")
191 <<
" posGraph=" << QPointFToString (other.
posGraph (SKIP_HAS_CHECK)).toLatin1().data()
192 <<
" hasOrdinal=" << (other.
hasOrdinal() ?
"true" :
"false")
193 <<
" ordinal=" << other.
ordinal (SKIP_HAS_CHECK);
199 m_posGraph = other.
posGraph (SKIP_HAS_CHECK);
201 m_ordinal = other.
ordinal (SKIP_HAS_CHECK);
206 QStringList tokens = pointIdentifier.split (POINT_IDENTIFIER_DELIMITER);
207 return tokens.value (0);
217 return m_hasPosGraph;
227 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::identifierIndex"
228 <<
" identifierIndex=" << m_identifierIndex;
230 return m_identifierIndex;
235 return m_isAxisPoint;
238 void Point::loadXml(QXmlStreamReader &reader)
240 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml";
244 QXmlStreamAttributes attributes = reader.attributes();
246 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER) &&
247 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX) &&
248 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT)) {
250 m_hasOrdinal = attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL);
252 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_POINT_ORDINAL).toDouble();
254 m_ordinal = MISSING_ORDINAL_VALUE;
257 QString
isAxisPoint = attributes.value(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT).toString();
259 m_identifier = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER).toString();
260 m_identifierIndex = attributes.value(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX).toInt();
261 m_isAxisPoint = (isAxisPoint == DOCUMENT_SERIALIZE_BOOL_TRUE);
262 m_hasPosGraph =
false;
263 m_posGraph.setX (MISSING_POSGRAPH_VALUE);
264 m_posGraph.setY (MISSING_POSGRAPH_VALUE);
266 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
267 (reader.name () != DOCUMENT_SERIALIZE_POINT)) {
269 loadNextFromReader(reader);
270 if (reader.atEnd()) {
275 if (reader.tokenType () == QXmlStreamReader::StartElement) {
277 if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN) {
279 attributes = reader.attributes();
281 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
282 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
284 m_posScreen.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
285 m_posScreen.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
291 }
else if (reader.name() == DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH) {
293 m_hasPosGraph =
true;
294 attributes = reader.attributes();
296 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_X) &&
297 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_Y)) {
299 m_posGraph.setX (attributes.value(DOCUMENT_SERIALIZE_POINT_X).toDouble());
300 m_posGraph.setY (attributes.value(DOCUMENT_SERIALIZE_POINT_Y).toDouble());
310 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::loadXml"
311 <<
" identifier=" << m_identifier.toLatin1().data()
312 <<
" identifierIndex=" << m_identifierIndex
313 <<
" posScreen=" << QPointFToString (m_posScreen).toLatin1().data()
314 <<
" posGraph=" << QPointFToString (m_posGraph).toLatin1().data()
315 <<
" ordinal=" << m_ordinal;
322 reader.raiseError(
"Cannot read point data");
328 if (applyHasCheck == KEEP_HAS_CHECK) {
329 ENGAUGE_ASSERT (m_hasOrdinal);
337 if (applyHasCheck == KEEP_HAS_CHECK) {
338 ENGAUGE_ASSERT (m_hasPosGraph);
350 QTextStream &str)
const
352 const QString UNDEFINED (
"undefined");
354 str << indentation <<
"Point\n";
356 indentation += INDENTATION_DELTA;
358 str << indentation <<
"identifier=" << m_identifier <<
"\n";
359 str << indentation <<
"posScreen=" << QPointFToString (m_posScreen) <<
"\n";
361 str << indentation <<
"posGraph=" << QPointFToString (m_posGraph) <<
"\n";
363 str << indentation <<
"posGraph=" << UNDEFINED <<
"\n";
366 str << indentation <<
"ordinal=" << m_ordinal <<
"\n";
368 str << indentation <<
"ordinal=" << UNDEFINED <<
"\n";
374 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::saveXml";
376 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT);
377 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER, m_identifier);
379 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_ORDINAL, QString::number (m_ordinal));
381 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IS_AXIS_POINT,
382 m_isAxisPoint ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
386 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_INDEX, QString::number (m_identifierIndex));
388 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_SCREEN);
389 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posScreen.x()));
390 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posScreen.y()));
391 writer.writeEndElement();
394 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_POSITION_GRAPH);
395 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_X, QString::number (m_posGraph.x()));
396 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_Y, QString::number (m_posGraph.y()));
397 writer.writeEndElement();
400 writer.writeEndElement();
405 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::setIdentifierIndex"
413 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setOrdinal"
414 <<
" identifier=" << m_identifier.toLatin1().data()
423 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosGraph"
424 <<
" identifier=" << m_identifier.toLatin1().data()
425 <<
" posGraph=" << QPointFToString(posGraph).toLatin1().data();
429 ENGAUGE_ASSERT (m_isAxisPoint);
431 m_hasPosGraph =
true;
437 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Point::setPosScreen"
438 <<
" identifier=" << m_identifier.toLatin1().data()
439 <<
" posScreen=" << QPointFToString(posScreen).toLatin1().data();
446 return QString (
"%1%2%3")
447 .arg (AXIS_CURVE_NAME)
448 .arg (POINT_IDENTIFIER_DELIMITER)
452 QString Point::uniqueIdentifierGenerator (
const QString &curveName)
454 LOG4CPP_INFO_S ((*mainCat)) <<
"Point::uniqueIdentifierGenerator"
455 <<
" curveName=" << curveName.toLatin1().data()
456 <<
" identifierIndex=" << m_identifierIndex;
458 return QString (
"%1%2point%3%4")
460 .arg (POINT_IDENTIFIER_DELIMITER)
461 .arg (POINT_IDENTIFIER_DELIMITER)
462 .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.