8 #include "CurvesGraphs.h" 9 #include "CurveStyle.h" 10 #include "DocumentSerialize.h" 11 #include "EngaugeAssert.h" 13 #include "MigrateToVersion6.h" 15 #include "PointComparator.h" 16 #include <QDataStream> 19 #include <QTextStream> 20 #include <QXmlStreamReader> 21 #include <QXmlStreamWriter> 22 #include "Transformation.h" 25 const QString AXIS_CURVE_NAME (
"Axes");
26 const QString DEFAULT_GRAPH_CURVE_NAME (
"Curve1");
27 const QString DUMMY_CURVE_NAME (
"dummy");
28 const QString TAB_DELIMITER (
"\t");
32 typedef QMultiMap<double, QString> XOrThetaToPointIdentifier;
37 m_curveName (curveName),
38 m_colorFilterSettings (colorFilterSettings),
39 m_curveStyle (curveStyle)
45 m_points (curve.
points ()),
53 const int CONVERT_ENUM_TO_RADIUS = 6;
56 qint32 int32, xScreen, yScreen;
57 double xGraph, yGraph;
72 if (m_curveName == AXIS_CURVE_NAME) {
83 for (
int i = 0; i < count; i++) {
89 if (m_curveName == AXIS_CURVE_NAME) {
92 Point point (m_curveName,
93 QPointF (xScreen, yScreen),
94 QPointF (xGraph, yGraph),
102 Point point (m_curveName,
103 QPointF (xScreen, yScreen));
119 m_points = curve.
points ();
128 m_points.push_back (point);
133 return m_colorFilterSettings;
147 const QString &identifier)
150 QList<Point>::iterator itr;
151 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
167 const QStringList &identifiers,
170 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::editPointGraph" 171 <<
" identifiers=" << identifiers.join(
" ").toLatin1().data();
176 QList<Point>::iterator itr;
177 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
181 if (identifiers.contains (point.
identifier ())) {
215 QTextStream &strHtml,
218 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::exportToClipboard" 219 <<
" hashCount=" << selectedHash.count();
224 QList<Point>::const_iterator itr;
225 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
227 const Point &point = *itr;
228 if (selectedHash.contains (point.
identifier ())) {
234 strCsv <<
"X" << TAB_DELIMITER << m_curveName <<
"\n";
235 strHtml <<
"<table>\n" 236 <<
"<tr><th>X</th><th>" << m_curveName <<
"</th></tr>\n";
246 Curve curve(m_curveName,
264 strCsv << pos.x() << TAB_DELIMITER << pos.y() <<
"\n";
265 strHtml <<
"<tr><td>" << pos.x() <<
"</td><td>" << pos.y() <<
"</td></tr>\n";
273 strHtml <<
"</table>\n";
280 Points::const_iterator itr;
281 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
282 const Point &point = *itr;
289 ENGAUGE_ASSERT (
false);
296 QList<Point>::const_iterator itr;
297 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
299 const Point &point = *itr;
313 QList<Point>::const_iterator itr;
314 const Point *pointBefore = 0;
315 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
317 const Point &point = *itr;
319 if (pointBefore != 0) {
329 pointBefore = &point;
333 void Curve::loadCurvePoints(QXmlStreamReader &reader)
335 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadCurvePoints";
339 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
340 (reader.name() != DOCUMENT_SERIALIZE_CURVE_POINTS)) {
342 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
344 if (reader.atEnd()) {
349 if (tokenType == QXmlStreamReader::StartElement) {
351 if (reader.name () == DOCUMENT_SERIALIZE_POINT) {
353 Point point (reader);
354 m_points.push_back (point);
360 reader.raiseError(QObject::tr (
"Cannot read curve data"));
364 void Curve::loadXml(QXmlStreamReader &reader)
366 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::loadXml";
370 QXmlStreamAttributes attributes = reader.attributes();
372 if (attributes.hasAttribute (DOCUMENT_SERIALIZE_CURVE_NAME)) {
374 setCurveName (attributes.value (DOCUMENT_SERIALIZE_CURVE_NAME).toString());
377 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
378 (reader.name() != DOCUMENT_SERIALIZE_CURVE)){
380 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
382 if (reader.atEnd()) {
387 if (tokenType == QXmlStreamReader::StartElement) {
389 if (reader.name() == DOCUMENT_SERIALIZE_COLOR_FILTER) {
390 m_colorFilterSettings.
loadXml(reader);
391 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_POINTS) {
392 loadCurvePoints(reader);
393 }
else if (reader.name() == DOCUMENT_SERIALIZE_CURVE_STYLE) {
401 if (reader.hasError()) {
412 reader.raiseError (QObject::tr (
"Cannot read curve data"));
417 const QPointF &deltaScreen)
419 Point *point = pointForPointIdentifier (pointIdentifier);
421 QPointF posScreen = deltaScreen + point->
posScreen ();
427 return m_points.count ();
430 Point *Curve::pointForPointIdentifier (
const QString pointIdentifier)
432 Points::iterator itr;
433 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
440 ENGAUGE_ASSERT (
false);
454 Points::const_iterator itr;
455 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
456 const Point &point = *itr;
471 Points::const_iterator itr;
472 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
473 const Point &point = *itr;
484 QTextStream &str)
const 486 str << indentation <<
"Curve=" << m_curveName <<
"\n";
488 indentation += INDENTATION_DELTA;
490 Points::const_iterator itr;
491 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
492 const Point &point = *itr;
506 Points::iterator itr;
507 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
510 m_points.erase (itr);
518 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::saveXml";
520 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE);
521 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
522 m_colorFilterSettings.
saveXml (writer,
528 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVE_POINTS);
529 Points::const_iterator itr;
530 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
531 const Point &point = *itr;
534 writer.writeEndElement();
536 writer.writeEndElement();
549 QList<Point>::iterator itr;
550 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
565 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinals" 566 <<
" curve=" << m_curveName.toLatin1().data()
567 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
571 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
572 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
574 updatePointOrdinalsFunctions (transformation);
576 }
else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH ||
577 curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
579 updatePointOrdinalsRelations ();
583 LOG4CPP_ERROR_S ((*mainCat)) <<
"Curve::updatePointOrdinals";
584 ENGAUGE_ASSERT (
false);
588 qSort (m_points.begin(),
593 void Curve::updatePointOrdinalsFunctions (
const Transformation &transformation)
597 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsFunctions" 598 <<
" curve=" << m_curveName.toLatin1().data()
599 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
604 XOrThetaToPointIdentifier xOrThetaToPointIdentifier;
605 Points::iterator itr;
606 for (itr = m_points.begin (); itr != m_points.end (); itr++) {
622 xOrThetaToPointIdentifier.insert (posGraph.x(),
628 ENGAUGE_ASSERT (xOrThetaToPointIdentifier.count () == m_points.count ());
632 QMap<QString, double> pointIdentifierToOrdinal;
634 XOrThetaToPointIdentifier::const_iterator itrX;
635 for (itrX = xOrThetaToPointIdentifier.begin(); itrX != xOrThetaToPointIdentifier.end(); itrX++) {
637 QString pointIdentifier = itrX.value();
638 pointIdentifierToOrdinal [pointIdentifier] = ordinal++;
642 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
648 ENGAUGE_ASSERT (pointIdentifierToOrdinal.contains (point.
identifier()));
651 int ordinalNew = pointIdentifierToOrdinal [point.
identifier()];
656 void Curve::updatePointOrdinalsRelations ()
660 LOG4CPP_INFO_S ((*mainCat)) <<
"Curve::updatePointOrdinalsRelations" 661 <<
" curve=" << m_curveName.toLatin1().data()
662 <<
" connectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
665 Points::iterator itr;
667 for (itr = m_points.begin(); itr != m_points.end(); itr++) {
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
void removePoint(const QString &identifier)
Perform the opposite of addPointAtEnd.
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined...
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(...
Comparator for sorting Point class.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
ColorFilterSettings colorFilterSettings() const
Return the color filter.
void iterateThroughCurvePoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to Points on Curve.
void addPoint(Point point)
Add Point to this Curve.
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
Curve * curveForCurveName(const QString &curveName)
Return the axis or graph curve for the specified curve name.
QPointF positionScreen(const QString &pointIdentifier) const
Return the position, in screen coordinates, of the specified Point.
void updatePointOrdinals(const Transformation &transformation)
See CurveGraphs::updatePointOrdinals.
void setPointShape(PointShape shape)
Set method for curve point shape in specified curve.
void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of an axis point. This method does not apply to a graph point...
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.
void setLineConnectAs(CurveConnectAs curveConnectAs)
Set method for connect as method for lines in specified curve.
QPointF posScreen() const
Accessor for screen position.
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.
const Points points() const
Return a shallow copy of the Points.
int numPoints() const
Number of points.
Curve & operator=(const Curve &curve)
Assignment constructor.
CallbackSearchReturn
Return values for search callback methods.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Converts old (=pre version 6) enums to new (=version 6) enums, for reading of old document files...
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 identifier() const
Unique identifier for a specific Point.
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 printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
LineStyle lineStyle() const
Get method for LineStyle.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
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 numCurves() const
Current number of graphs curves.
void setCurveName(const QString &curveName)
Change the curve name.
QString curveName() const
Name of this Curve.
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 editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points. This method does not apply to an axis point...
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.
QPointF positionGraph(const QString &pointIdentifier) const
Return the position, in graph coordinates, of the specified Point.
void setLineColor(ColorPalette lineColor)
Set method for line color in specified curve.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Serialize to xml.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
CurveConnectAs curveConnectAs(int preVersion6) const
Line drawn between points.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Save 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.
void saveXml(QXmlStreamWriter &writer) const
Serialize curve.
void setLineWidth(int width)
Set method for line width in specified curve.
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
void setOrdinal(double ordinal)
Set the ordinal used for ordering Points.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
bool isXOnly(const QString &pointIdentifier) const
Determine if specified point has just x coordinate. Otherwise has just y coordinate, or both x and y coordinates.
ColorPalette colorPalette(int preVersion6) const
Color from color palette.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
PointShape pointShape(int preVersion6) const
Point shape.
void setCurveName(const QString &curveName)
Update the point identifer to match the specified curve name.