8#include "CurvesGraphs.h"
10#include "DocumentSerialize.h"
11#include "EngaugeAssert.h"
13#include "MigrateToVersion6.h"
15#include "PointComparator.h"
20#include <QXmlStreamReader>
21#include <QXmlStreamWriter>
22#include "Transformation.h"
25const QString AXIS_CURVE_NAME (
"Axes");
26const QString DEFAULT_GRAPH_CURVE_NAME (
"Curve1");
27const QString DUMMY_CURVE_NAME (
"dummy");
28const QString TAB_DELIMITER (
"\t");
30typedef QMap<double, QString> XOrThetaToPointIdentifier;
35 m_curveName (curveName),
36 m_colorFilterSettings (colorFilterSettings),
37 m_curveStyle (curveStyle)
42 m_curveName (curve.curveName ()),
43 m_points (curve.points ()),
44 m_colorFilterSettings (curve.colorFilterSettings ()),
45 m_curveStyle (curve.curveStyle ())
53 qint32 int32, xScreen, yScreen;
54 double xGraph, yGraph;
69 if (m_curveName == AXIS_CURVE_NAME) {
80 for (
int i = 0; i < count; i++) {
86 if (m_curveName == AXIS_CURVE_NAME) {
89 Point point (m_curveName,
90 QPointF (xScreen, yScreen),
91 QPointF (xGraph, yGraph),
99 Point point (m_curveName,
100 QPointF (xScreen, yScreen));
116 m_points = curve.
points ();
125 m_points.push_back (point);
130 return m_colorFilterSettings;
144 const QString &identifier)
147 QList<Point>::iterator itr;
148 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
163 QTextStream &strHtml,
166 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::exportToClipboard"
167 <<
" hashCount=" << selectedHash.count();
172 QList<Point>::const_iterator itr;
173 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
175 const Point &point = *itr;
176 if (selectedHash.contains (point.
identifier ())) {
182 strCsv <<
"X" << TAB_DELIMITER << m_curveName <<
"\n";
183 strHtml <<
"<table>\n"
184 <<
"<tr><th>X</th><th>" << m_curveName <<
"</th></tr>\n";
194 Curve curve(m_curveName,
212 strCsv << pos.x() << TAB_DELIMITER << pos.y() <<
"\n";
213 strHtml <<
"<tr><td>" << pos.x() <<
"</td><td>" << pos.y() <<
"</td></tr>\n";
221 strHtml <<
"</table>\n";
228 Points::const_iterator itr;
229 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
230 const Point &point = *itr;
237 ENGAUGE_ASSERT (
false);
244 QList<Point>::const_iterator itr;
245 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
247 const Point &point = *itr;
261 QList<Point>::const_iterator itr;
262 const Point *pointBefore = 0;
263 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
265 const Point &point = *itr;
267 if (pointBefore != 0) {
277 pointBefore = &point;
281void Curve::loadCurvePoints(QXmlStreamReader &reader)
283 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadCurvePoints";
287 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
288 (reader.name() != DOCUMENT_SERIALIZE_CURVE_POINTS)) {
290 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
292 if (reader.atEnd()) {
297 if (tokenType == QXmlStreamReader::StartElement) {
299 if (reader.name () == DOCUMENT_SERIALIZE_POINT) {
301 Point point (reader);
302 m_points.push_back (point);
308 reader.raiseError(QObject::tr (
"Cannot read curve data"));
312void Curve::loadXml(QXmlStreamReader &reader)
314 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadXml";
318 QXmlStreamAttributes attributes = reader.attributes();
320 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_CURVE_NAME)) {
322 setCurveName (attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString());
325 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
326 (reader.name() != DOCUMENT_SERIALIZE_CURVE)){
328 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
330 if (reader.atEnd()) {
335 if (tokenType == QXmlStreamReader::StartElement) {
337 if (reader.name() == DOCUMENT_SERIALIZE_COLOR_FILTER) {
338 m_colorFilterSettings.
loadXml(reader);
339 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_POINTS) {
340 loadCurvePoints(reader);
341 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_STYLE) {
349 if (reader.hasError()) {
360 reader.raiseError (QObject::tr (
"Cannot read curve data"));
365 const QPointF &deltaScreen)
367 Point *point = pointForPointIdentifier (pointIdentifier);
369 QPointF posScreen = deltaScreen + point->
posScreen ();
375 return m_points.count ();
378Point *Curve::pointForPointIdentifier (
const QString pointIdentifier)
380 Points::iterator itr;
381 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
388 ENGAUGE_ASSERT (
false);
402 Points::const_iterator itr;
403 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
404 const Point &point = *itr;
419 Points::const_iterator itr;
420 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
421 const Point &point = *itr;
432 QTextStream &str)
const
434 str << indentation <<
"Curve=" << m_curveName <<
"\n";
436 indentation += INDENTATION_DELTA;
438 Points::const_iterator itr;
439 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
440 const Point &point = *itr;
454 Points::iterator itr;
455 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
458 m_points.erase (itr);
466 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::saveXml";
468 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE);
469 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
470 m_colorFilterSettings.
saveXml (writer,
476 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE_POINTS);
477 Points::const_iterator itr;
478 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
479 const Point &point = *itr;
482 writer.writeEndElement();
484 writer.writeEndElement();
497 QList<Point>::iterator itr;
498 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
513 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinals"
514 <<
" curve=" << m_curveName.toLatin1().data()
515 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
519 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
520 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
522 updatePointOrdinalsFunctions (transformation);
524 }
else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH ||
525 curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
527 updatePointOrdinalsRelations ();
531 LOG4CPP_ERROR_S ((*mainCat)) <<
"Curve::updatePointOrdinals";
532 ENGAUGE_ASSERT (
false);
536 qSort (m_points.begin(),
541void Curve::updatePointOrdinalsFunctions (
const Transformation &transformation)
545 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsFunctions"
546 <<
" curve=" << m_curveName.toLatin1().data()
547 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
550 XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
551 Points::iterator itr;
552 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
568 xOrThetaToPointIdentifier [posGraph.x()] = point.
identifier();
573 QMap<QString, double> pointIdentifierToOrdinal;
575 XOrThetaToPointIdentifier::const_iterator itrX;
576 for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {
578 QString pointIdentifier = itrX.value();
579 pointIdentifierToOrdinal [pointIdentifier] = ordinal++;
583 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
585 int ordinalNew = pointIdentifierToOrdinal [point.
identifier()];
590void Curve::updatePointOrdinalsRelations ()
594 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsRelations"
595 <<
" curve=" << m_curveName.toLatin1().data()
596 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
599 Points::iterator itr;
601 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
CallbackSearchReturn
Return values for search callback methods.
@ CALLBACK_SEARCH_RETURN_INTERRUPT
Immediately terminate the current search.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Save curve filter to stream.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
Container for LineStyle and PointStyle for one Curve.
void setLineColor(ColorPalette lineColor)
Set method for line color in specified curve.
void setPointRadius(int radius)
Set method for curve point radius.
LineStyle lineStyle() const
Get method for LineStyle.
void setPointLineWidth(int width)
Set method for curve point perimeter line width.
QString loadXml(QXmlStreamReader &reader)
Load from serialized xml. Returns the curve name.
void setLineConnectAs(CurveConnectAs curveConnectAs)
Set method for connect as method for lines in specified curve.
void setLineWidth(int width)
Set method for line width in specified curve.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Serialize to xml.
void setPointColor(ColorPalette curveColor)
Set method curve point color in specified curve.
void setLineStyle(const LineStyle &lineStyle)
Set method for LineStyle.
void setPointShape(PointShape shape)
Set method for curve point shape in specified curve.
Container for one set of digitized Points.
void addPoint(Point point)
Add Point to this Curve.
bool isXOnly(const QString &pointIdentifier) const
Determine if specified point has just x coordinate. Otherwise has just y coordinate,...
void saveXml(QXmlStreamWriter &writer) const
Serialize curve.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
Translate the position of a point by the specified distance vector.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Curve & operator=(const Curve &curve)
Assignment constructor.
CurveStyle curveStyle() const
Return the curve style.
void exportToClipboard(const QHash< QString, bool > &selectedHash, const Transformation &transformation, QTextStream &strCsv, QTextStream &strHtml, CurvesGraphs &curvesGraphs) const
Export points in this Curve found in the specified point list.
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
void updatePointOrdinals(const Transformation &transformation)
See CurveGraphs::updatePointOrdinals.
ColorFilterSettings colorFilterSettings() const
Return the color filter.
void removePoint(const QString &identifier)
Perform the opposite of addPointAtEnd.
const Points points() const
Return a shallow copy of the Points.
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
void setCurveName(const QString &curveName)
Change the curve name.
QString curveName() const
Name of this Curve.
QPointF positionScreen(const QString &pointIdentifier) const
Return the position, in screen coordinates, of the specified Point.
Curve(const QString &curveName, const ColorFilterSettings &colorFilterSettings, const CurveStyle &curveStyle)
Constructor from scratch.
void editPoint(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of an axis point. This method does not apply to a graph point.
void iterateThroughCurvePoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to Points on Curve.
QPointF positionGraph(const QString &pointIdentifier) const
Return the position, in graph coordinates, of the specified Point.
void iterateThroughCurveSegments(const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to successive Points, as line segments, on Curve. This could be a bit slow.
int numPoints() const
Number of points.
Container for all graph curves. The axes point curve is external to this class.
Curve * curveForCurveName(const QString &curveName)
Return the axis or graph curve for the specified curve name.
void addGraphCurveAtEnd(Curve curve)
Append new graph Curve to end of Curve list.
int numCurves() const
Current number of graphs curves.
static LineStyle defaultAxesCurve()
Initial default for axes curve.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Converts old (=pre version 6) enums to new (=version 6) enums, for reading of old document files.
CurveConnectAs curveConnectAs(int preVersion6) const
Line drawn between points.
ColorPalette colorPalette(int preVersion6) const
Color from color palette.
PointShape pointShape(int preVersion6) const
Point shape.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.
void setCurveName(const QString &curveName)
Update the point identifer to match the specified curve name.
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.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
QPointF posScreen() const
Accessor for screen position.
QString identifier() const
Unique identifier for a specific Point.
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
void setPosGraph(const QPointF &posGraph)
Set method for position in graph coordinates.
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined.
Comparator for sorting Point class.