8 #include "EngaugeAssert.h"
10 #include "GeometryWindow.h"
11 #include "GraphicsItemType.h"
12 #include "GraphicsLinesForCurve.h"
13 #include "GraphicsPoint.h"
14 #include "GraphicsScene.h"
15 #include "LineStyle.h"
18 #include "PointStyle.h"
19 #include <QGraphicsItem>
21 #include <QPainterPath>
23 #include <QTextStream>
24 #include "QtToString.h"
26 #include "SplineDrawer.h"
27 #include "Transformation.h"
32 typedef QMap<double, double> XOrThetaToOrdinal;
35 m_curveName (curveName)
37 setZValue (Z_VALUE_CURVE);
38 setData (DATA_KEY_GRAPHICS_ITEM_TYPE,
39 GRAPHICS_ITEM_TYPE_LINE);
40 setData (DATA_KEY_IDENTIFIER,
41 QVariant (m_curveName));
44 GraphicsLinesForCurve::~GraphicsLinesForCurve()
46 OrdinalToGraphicsPoint::iterator itr;
47 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
52 m_graphicsPoints.clear();
59 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::addPoint"
60 <<
" curve=" << m_curveName.toLatin1().data()
61 <<
" identifier=" << pointIdentifier.toLatin1().data()
62 <<
" ordinal=" << ordinal
63 <<
" pos=" << QPointFToString (graphicsPoint.
pos()).toLatin1().data()
64 <<
" newPointCount=" << (m_graphicsPoints.count() + 1);
66 m_graphicsPoints [ordinal] = &graphicsPoint;
69 QPainterPath GraphicsLinesForCurve::drawLinesSmooth (
const LineStyle &lineStyle,
71 QPainterPath &pathMultiValued,
74 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesSmooth"
75 <<
" curve=" << m_curveName.toLatin1().data();
81 vector<SplinePair> xy;
82 OrdinalToGraphicsPoint::const_iterator itr;
83 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
85 double ordinal = itr.key();
88 t.push_back (ordinal);
105 OrdinalToGraphicsPoint::const_iterator itr = m_graphicsPoints.begin();
108 path.moveTo (point->
pos ());
109 pathMultiValued.moveTo (point->
pos ());
113 itr != m_graphicsPoints.end();
120 QPointF p1 (spline.p1 (segment).x(),
121 spline.p1 (segment).y());
122 QPointF p2 (spline.p2 (segment).x(),
123 spline.p2 (segment).y());
126 case SPLINE_DRAWER_ENUM_VISIBLE_DRAW:
135 case SPLINE_DRAWER_ENUM_INVISIBLE_MOVE:
138 path.moveTo (point->
pos ());
141 OrdinalToGraphicsPoint::const_iterator itrBefore = itr - 1;
143 pathMultiValued.moveTo (pointBefore->
pos ());
144 pathMultiValued.cubicTo (p1,
147 lineMultiValued = lineStyle;
153 pathMultiValued.moveTo (point->
pos ());
160 QPainterPath GraphicsLinesForCurve::drawLinesStraight (QPainterPath & )
162 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight"
163 <<
" curve=" << m_curveName.toLatin1().data();
169 OrdinalToGraphicsPoint::const_iterator itr;
170 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
176 path.moveTo (point->
pos ());
178 path.lineTo (point->
pos ());
187 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal"
188 <<
" identifier=" << identifier.toLatin1().data();
190 OrdinalToGraphicsPoint::const_iterator itr;
191 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
195 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
200 ENGAUGE_ASSERT (
false);
207 QPainterPath &pathMultiValued,
210 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge"
211 <<
" curve=" << m_curveName.toLatin1().data();
213 OrdinalToGraphicsPoint::iterator itr, itrNext;
214 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
223 double ordinal = itr.key ();
226 m_graphicsPoints.remove (ordinal);
232 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
234 pen = QPen (Qt::NoPen);
238 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
253 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset"
254 <<
" curve=" << m_curveName.toLatin1().data();
256 OrdinalToGraphicsPoint::iterator itr;
257 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
265 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const
268 bool needRenumbering =
false;
269 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
271 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
276 if (ordinalKeyWanted != ordinalKeyGot) {
277 needRenumbering =
true;
282 return needRenumbering;
286 QTextStream &str)
const
288 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
290 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
291 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
292 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
294 indentation += INDENTATION_DELTA;
296 OrdinalToGraphicsPoint::const_iterator itr;
297 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
299 double ordinalKey = itr.key();
310 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint"
311 <<
" point=" << ordinal
312 <<
" pointCount=" << m_graphicsPoints.count();
314 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
317 m_graphicsPoints.remove (ordinal);
319 delete graphicsPoint;
324 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
326 OrdinalToGraphicsPoint::iterator itr;
327 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
331 m_graphicsPoints.remove (itr.key());
333 delete graphicsPoint;
339 void GraphicsLinesForCurve::renumberOrdinals ()
341 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
343 int ordinalKeyWanted;
347 QList<GraphicsPoint*> points;
348 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
350 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
351 points << graphicsPoint;
354 m_graphicsPoints.clear ();
356 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
359 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
368 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand"
369 <<
" curve=" << m_curveName.toLatin1().data()
370 <<
" pointCount=" << m_graphicsPoints.count();
373 if (m_graphicsPoints.contains (point.
ordinal())) {
375 graphicsPoint = m_graphicsPoints [point.
ordinal()];
391 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
396 ENGAUGE_CHECK_PTR (graphicsPoint);
402 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
404 OrdinalToGraphicsPoint::const_iterator itr;
405 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
414 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle"
415 <<
" curve=" << m_curveName.toLatin1().data()
416 <<
" highlightOpacity=" << highlightOpacity;
418 OrdinalToGraphicsPoint::const_iterator itr;
419 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
428 QPainterPath &pathMultiValued,
433 bool needRenumbering = needOrdinalRenumbering ();
434 if (needRenumbering) {
440 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
441 <<
" numberPoints=" << m_graphicsPoints.count()
442 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
451 m_graphicsPoints.count () < 3) {
453 path = drawLinesStraight (pathMultiValued);
455 path = drawLinesSmooth (lineStyle,
470 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updatePointOrdinalsAfterDrag"
471 <<
" curve=" << m_curveName.toLatin1().data()
472 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
474 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
475 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
480 XOrThetaToOrdinal xOrThetaToOrdinal;
481 OrdinalToGraphicsPoint::iterator itrP;
482 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
484 double ordinal = itrP.key();
492 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
496 OrdinalToGraphicsPoint temporaryList;
498 XOrThetaToOrdinal::const_iterator itrX;
499 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
501 double ordinalOld = *itrX;
504 temporaryList [ordinalNew++] = point;
508 m_graphicsPoints.clear();
509 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
511 double ordinal = itrP.key();
514 m_graphicsPoints [ordinal] = point;
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
unsigned int width() const
Width of line.
Cubic interpolation given independent and dependent value vectors.
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
void updateCurveStyle(const CurveStyle &curveStyle)
Update the curve style for this curve.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
double identifierToOrdinal(const QString &identifier) const
Get ordinal for specified identifier.
void printStream(QString indentation, QTextStream &str, double ordinalKey) const
Debugging method that supports print method of this class and printStream method of some other class(...
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Window that displays the geometry information, as a table, for the current curve. ...
void bindToSpline(int numSegments, const Spline &spline)
Analyze each segment in the Spline.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
QPointF posScreen() const
Accessor for screen position.
void setPos(const QPointF pos)
Update the position.
SplineDrawerOperation segmentOperation(int segment) const
Indicate if, and how, segment is to be drawn.
bool wanted() const
Identify point as wanted//unwanted.
GraphicsLinesForCurve(const QString &curveName)
Single constructor.
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
QString identifier() const
Unique identifier for a specific Point.
void updatePointOrdinalsAfterDrag(const LineStyle &lineStyle, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag. Pretty much the same steps as Curve::updatePointOrdinals...
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen, GeometryWindow *geometryWindow)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
void lineMembershipPurge(const LineStyle &lineStyle, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
Details for a specific Point.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
static double UNDEFINED_ORDINAL()
Get method for undefined ordinal constant.
void updateHighlightOpacity(double highlightOpacity)
Update the highlight opacity value. This may or may not affect the current display immediately depend...
Container for LineStyle and PointStyle for one Curve.
void updateAfterCommand(GraphicsScene &scene, const PointStyle &pointStyle, const Point &point, GeometryWindow *geometryWindow)
Update the GraphicsScene with the specified Point from the Document. If it does not exist yet in the ...
Details for a specific Line.
Graphics item for drawing a circular or polygonal Point.
ColorPalette paletteColor() const
Line color.
void addPoint(const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new line.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Add point and line handling to generic QGraphicsScene.
This class takes the output from Spline and uses that to draw the curve in the graphics window...
void updateGraphicsLinesToMatchGraphicsPoints(const LineStyle &lineStyle, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
void removePoint(double ordinal)
Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScen...
Single X/Y pair for cubic spline interpolation initialization and calculations.
void reset()
Mark point as unwanted, and unbind any bound lines.