2 #include "CurvesGraphs.h"
3 #include "DocumentSerialize.h"
4 #include "EngaugeAssert.h"
7 #include "PointComparator.h"
10 #include <QTextStream>
11 #include <QXmlStreamReader>
12 #include <QXmlStreamWriter>
13 #include "Transformation.h"
16 const QString AXIS_CURVE_NAME (
"Axes");
17 const int AXIS_CURVE_ORDINAL = 0;
18 const QString DEFAULT_GRAPH_CURVE_NAME (
"Curve1");
19 const QString TAB_DELIMITER (
"\t");
21 typedef QMap<double, QString> XOrThetaToPointIdentifier;
26 m_curveName (curveName),
27 m_colorFilterSettings (colorFilterSettings),
28 m_curveStyle (curveStyle)
33 m_curveName (curve.curveName ()),
34 m_points (curve.points ()),
35 m_colorFilterSettings (curve.colorFilterSettings ()),
36 m_curveStyle (curve.curveStyle ())
48 m_points = curve.
points ();
57 m_points.push_back (point);
62 return m_colorFilterSettings;
76 const QString &identifier)
79 QList<Point>::iterator itr;
80 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
98 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::exportToClipboard"
99 <<
" hashCount=" << selectedHash.count();
104 QList<Point>::const_iterator itr;
105 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
107 const Point &point = *itr;
108 if (selectedHash.contains (point.
identifier ())) {
114 strCsv <<
"X" << TAB_DELIMITER << m_curveName <<
"\n";
115 strHtml <<
"<table>\n"
116 <<
"<tr><th>X</th><th>" << m_curveName <<
"</th></tr>\n";
126 Curve curve(m_curveName,
144 strCsv << pos.x() << TAB_DELIMITER << pos.y() <<
"\n";
145 strHtml <<
"<tr><td>" << pos.x() <<
"</td><td>" << pos.y() <<
"</td></tr>\n";
153 strHtml <<
"</table>\n";
159 QList<Point>::const_iterator itr;
160 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
162 const Point &point = *itr;
176 QList<Point>::const_iterator itr;
177 const Point *pointBefore = 0;
178 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
180 const Point &point = *itr;
182 if (pointBefore != 0) {
192 pointBefore = &point;
196 void Curve::loadCurvePoints(QXmlStreamReader &reader)
198 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadCurvePoints";
202 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
203 (reader.name() != DOCUMENT_SERIALIZE_CURVE_POINTS)) {
205 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
207 if (reader.atEnd()) {
212 if (tokenType == QXmlStreamReader::StartElement) {
214 if (reader.name () == DOCUMENT_SERIALIZE_POINT) {
216 Point point (reader);
217 m_points.push_back (point);
223 reader.raiseError(
"Cannot read curve data");
227 void Curve::loadXml(QXmlStreamReader &reader)
229 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadXml";
233 QXmlStreamAttributes attributes = reader.attributes();
235 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_CURVE_NAME)) {
237 setCurveName (attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString());
240 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
241 (reader.name() != DOCUMENT_SERIALIZE_CURVE)){
243 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
245 if (reader.atEnd()) {
250 if (tokenType == QXmlStreamReader::StartElement) {
252 if (reader.name() == DOCUMENT_SERIALIZE_COLOR_FILTER) {
253 m_colorFilterSettings.
loadXml(reader);
254 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_POINTS) {
255 loadCurvePoints(reader);
256 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_STYLE) {
264 if (reader.hasError()) {
275 reader.raiseError (
"Cannot read curve data");
280 const QPointF &deltaScreen)
282 Point *point = pointForPointIdentifier (pointIdentifier);
284 QPointF posScreen = deltaScreen + point->
posScreen ();
290 return m_points.count ();
293 Point *Curve::pointForPointIdentifier (
const QString pointIdentifier)
295 Points::iterator itr;
296 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
303 ENGAUGE_ASSERT (
false);
317 Points::const_iterator itr;
318 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
319 const Point &point = *itr;
334 Points::const_iterator itr;
335 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
336 const Point &point = *itr;
347 QTextStream &str)
const
349 str << indentation <<
"Curve=" << m_curveName <<
"\n";
351 indentation += INDENTATION_DELTA;
353 Points::const_iterator itr;
354 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
355 const Point &point = *itr;
369 Points::iterator itr;
370 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
373 m_points.erase (itr);
381 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::saveXml";
383 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE);
384 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
385 m_colorFilterSettings.
saveXml (writer);
390 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE_POINTS);
391 Points::const_iterator itr;
392 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
393 const Point &point = *itr;
396 writer.writeEndElement();
398 writer.writeEndElement();
420 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinals"
421 <<
" curve=" << m_curveName.toLatin1().data()
422 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
426 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
427 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
429 updatePointOrdinalsFunctions (transformation);
431 }
else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH ||
432 curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
434 updatePointOrdinalsRelations ();
438 LOG4CPP_ERROR_S ((*mainCat)) <<
"Curve::updatePointOrdinals";
439 ENGAUGE_ASSERT (
false);
443 qSort (m_points.begin(),
448 void Curve::updatePointOrdinalsFunctions (
const Transformation &transformation)
452 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsFunctions"
453 <<
" curve=" << m_curveName.toLatin1().data()
454 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
457 XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
458 Points::iterator itr;
459 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
475 xOrThetaToPointIdentifier [posGraph.x()] = point.
identifier();
480 QMap<QString, double> pointIdentifierToOrdinal;
482 XOrThetaToPointIdentifier::const_iterator itrX;
483 for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {
485 QString pointIdentifier = itrX.value();
486 pointIdentifierToOrdinal [pointIdentifier] = ordinal++;
490 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
492 int ordinalNew = pointIdentifierToOrdinal [point.
identifier()];
497 void Curve::updatePointOrdinalsRelations ()
501 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsRelations"
502 <<
" curve=" << m_curveName.toLatin1().data()
503 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
506 Points::iterator itr;
508 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 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.
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(...
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.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
Translate the position of a point by the specified distance vector.
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 loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
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 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.
ColorFilterSettings colorFilterSettings() const
Return the color filter.
QString curveName() const
Name of this Curve.