2 #include "CurvesGraphs.h"
3 #include "CurveStyle.h"
4 #include "DocumentSerialize.h"
5 #include "EngaugeAssert.h"
7 #include "MigrateToVersion6.h"
9 #include "PointComparator.h"
10 #include <QDataStream>
13 #include <QTextStream>
14 #include <QXmlStreamReader>
15 #include <QXmlStreamWriter>
16 #include "Transformation.h"
19 const QString AXIS_CURVE_NAME (
"Axes");
20 const int AXIS_CURVE_ORDINAL = 0;
21 const QString DEFAULT_GRAPH_CURVE_NAME (
"Curve1");
22 const QString DUMMY_CURVE_NAME (
"dummy");
23 const QString TAB_DELIMITER (
"\t");
25 typedef QMap<double, QString> XOrThetaToPointIdentifier;
30 m_curveName (curveName),
31 m_colorFilterSettings (colorFilterSettings),
32 m_curveStyle (curveStyle)
37 m_curveName (curve.curveName ()),
38 m_points (curve.points ()),
39 m_colorFilterSettings (curve.colorFilterSettings ()),
40 m_curveStyle (curve.curveStyle ())
48 qint32 int32, xScreen, yScreen;
49 double xGraph, yGraph;
64 if (m_curveName == AXIS_CURVE_NAME) {
75 for (
int i = 0; i < count; i++) {
81 if (m_curveName == AXIS_CURVE_NAME) {
84 Point point (m_curveName,
85 QPointF (xScreen, yScreen),
86 QPointF (xGraph, yGraph),
93 Point point (m_curveName,
94 QPointF (xScreen, yScreen));
110 m_points = curve.
points ();
119 m_points.push_back (point);
124 return m_colorFilterSettings;
138 const QString &identifier)
141 QList<Point>::iterator itr;
142 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
157 QTextStream &strHtml,
160 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::exportToClipboard"
161 <<
" hashCount=" << selectedHash.count();
166 QList<Point>::const_iterator itr;
167 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
169 const Point &point = *itr;
170 if (selectedHash.contains (point.
identifier ())) {
176 strCsv <<
"X" << TAB_DELIMITER << m_curveName <<
"\n";
177 strHtml <<
"<table>\n"
178 <<
"<tr><th>X</th><th>" << m_curveName <<
"</th></tr>\n";
188 Curve curve(m_curveName,
206 strCsv << pos.x() << TAB_DELIMITER << pos.y() <<
"\n";
207 strHtml <<
"<tr><td>" << pos.x() <<
"</td><td>" << pos.y() <<
"</td></tr>\n";
215 strHtml <<
"</table>\n";
221 QList<Point>::const_iterator itr;
222 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
224 const Point &point = *itr;
238 QList<Point>::const_iterator itr;
239 const Point *pointBefore = 0;
240 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
242 const Point &point = *itr;
244 if (pointBefore != 0) {
254 pointBefore = &point;
258 void Curve::loadCurvePoints(QXmlStreamReader &reader)
260 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadCurvePoints";
264 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
265 (reader.name() != DOCUMENT_SERIALIZE_CURVE_POINTS)) {
267 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
269 if (reader.atEnd()) {
274 if (tokenType == QXmlStreamReader::StartElement) {
276 if (reader.name () == DOCUMENT_SERIALIZE_POINT) {
278 Point point (reader);
279 m_points.push_back (point);
285 reader.raiseError(
"Cannot read curve data");
289 void Curve::loadXml(QXmlStreamReader &reader)
291 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadXml";
295 QXmlStreamAttributes attributes = reader.attributes();
297 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_CURVE_NAME)) {
299 setCurveName (attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString());
302 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
303 (reader.name() != DOCUMENT_SERIALIZE_CURVE)){
305 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
307 if (reader.atEnd()) {
312 if (tokenType == QXmlStreamReader::StartElement) {
314 if (reader.name() == DOCUMENT_SERIALIZE_COLOR_FILTER) {
315 m_colorFilterSettings.
loadXml(reader);
316 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_POINTS) {
317 loadCurvePoints(reader);
318 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_STYLE) {
326 if (reader.hasError()) {
337 reader.raiseError (
"Cannot read curve data");
342 const QPointF &deltaScreen)
344 Point *point = pointForPointIdentifier (pointIdentifier);
346 QPointF posScreen = deltaScreen + point->
posScreen ();
352 return m_points.count ();
355 Point *Curve::pointForPointIdentifier (
const QString pointIdentifier)
357 Points::iterator itr;
358 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
365 ENGAUGE_ASSERT (
false);
379 Points::const_iterator itr;
380 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
381 const Point &point = *itr;
396 Points::const_iterator itr;
397 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
398 const Point &point = *itr;
409 QTextStream &str)
const
411 str << indentation <<
"Curve=" << m_curveName <<
"\n";
413 indentation += INDENTATION_DELTA;
415 Points::const_iterator itr;
416 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
417 const Point &point = *itr;
431 Points::iterator itr;
432 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
435 m_points.erase (itr);
443 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::saveXml";
445 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE);
446 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
447 m_colorFilterSettings.
saveXml (writer);
452 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE_POINTS);
453 Points::const_iterator itr;
454 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
455 const Point &point = *itr;
458 writer.writeEndElement();
460 writer.writeEndElement();
482 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinals"
483 <<
" curve=" << m_curveName.toLatin1().data()
484 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
488 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
489 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
491 updatePointOrdinalsFunctions (transformation);
493 }
else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH ||
494 curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
496 updatePointOrdinalsRelations ();
500 LOG4CPP_ERROR_S ((*mainCat)) <<
"Curve::updatePointOrdinals";
501 ENGAUGE_ASSERT (
false);
505 qSort (m_points.begin(),
510 void Curve::updatePointOrdinalsFunctions (
const Transformation &transformation)
514 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsFunctions"
515 <<
" curve=" << m_curveName.toLatin1().data()
516 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
519 XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
520 Points::iterator itr;
521 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
537 xOrThetaToPointIdentifier [posGraph.x()] = point.
identifier();
542 QMap<QString, double> pointIdentifierToOrdinal;
544 XOrThetaToPointIdentifier::const_iterator itrX;
545 for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {
547 QString pointIdentifier = itrX.value();
548 pointIdentifierToOrdinal [pointIdentifier] = ordinal++;
552 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
554 int ordinalNew = pointIdentifierToOrdinal [point.
identifier()];
559 void Curve::updatePointOrdinalsRelations ()
563 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsRelations"
564 <<
" curve=" << m_curveName.toLatin1().data()
565 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
568 Points::iterator itr;
570 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
void removePoint(const QString &identifier)
Perform the opposite of addPointAtEnd.
QPointF positionScreen(const QString &pointIdentifier) const
Return the position, in screen coordinates, of the specified Point.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Comparator for sorting Point class.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Serialize to xml.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
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.
const Points points() const
Return a shallow copy of the Points.
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void addPoint(Point point)
Add Point to this Curve.
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
Curve * curveForCurveName(const QString &curveName)
Return the axis or graph curve for the specified curve name.
int numCurves() const
Current number of graphs curves.
int numPoints() const
Number of points.
void updatePointOrdinals(const Transformation &transformation)
See CurveGraphs::updatePointOrdinals.
LineStyle lineStyle() const
Get method for LineStyle.
void setPointShape(PointShape shape)
Set method for curve point shape in specified curve.
void addGraphCurveAtEnd(Curve curve)
Append new graph Curve to end of Curve list.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
static LineStyle defaultAxesCurve()
Initial default for axes curve.
QPointF posScreen() const
Accessor for screen position.
void setLineConnectAs(CurveConnectAs curveConnectAs)
Set method for connect as method for lines in specified curve.
QPointF positionGraph(const QString &pointIdentifier) const
Return the position, in graph coordinates, of the specified Point.
void setLineStyle(const LineStyle &lineStyle)
Set method for LineStyle.
Curve(const QString &curveName, const ColorFilterSettings &colorFilterSettings, const CurveStyle &curveStyle)
Constructor from scratch.
void setPosGraph(const QPointF &posGraph)
Set method for position in graph coordinates.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
ColorPalette colorPalette(int preVersion6) const
Color from color palette.
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...
Curve & operator=(const Curve &curve)
Assignment constructor.
CallbackSearchReturn
Return values for search callback methods.
QString identifier() const
Unique identifier for a specific Point.
Converts old (=pre version 6) enums to new (=version 6) enums, for reading of old document files...
PointShape pointShape(int preVersion6) const
Point shape.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
Translate the position of a point by the specified distance vector.
void setPointRadius(int radius)
Set method for curve point radius.
void setPointLineWidth(int width)
Set method for curve point perimeter line width.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
QString loadXml(QXmlStreamReader &reader)
Load from serialized xml. Returns the curve name.
Container for all graph curves. The axes point curve is external to this class.
void saveXml(QXmlStreamWriter &writer) const
Save curve filter to stream.
void iterateThroughCurvePoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to Points on 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 setCurveName(const QString &curveName)
Change the curve name.
Container for LineStyle and PointStyle for one Curve.
void setPosScreen(const QPointF &posScreen)
Set method for position in screen coordinates.
Container for one set of digitized Points.
void setLineColor(ColorPalette lineColor)
Set method for line color in specified curve.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
void setPointColor(ColorPalette curveColor)
Set method curve point color in specified curve.
Immediately terminate the current search.
CurveStyle curveStyle() const
Return the curve style.
CurveConnectAs curveConnectAs() const
Get method for connect type.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setLineWidth(int width)
Set method for line width in specified curve.
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
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...
void saveXml(QXmlStreamWriter &writer) const
Serialize curve.
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
CurveConnectAs curveConnectAs(int preVersion6) const
Line drawn between points.
ColorFilterSettings colorFilterSettings() const
Return the color filter.
QString curveName() const
Name of this Curve.