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);
100 m_graphicsPoints.count(),
106 OrdinalToGraphicsPoint::const_iterator itr = m_graphicsPoints.begin();
109 path.moveTo (point->
pos ());
110 pathMultiValued.moveTo (point->
pos ());
114 itr != m_graphicsPoints.end();
121 QPointF p1 (spline.p1 (segment).x(),
122 spline.p1 (segment).y());
123 QPointF p2 (spline.p2 (segment).x(),
124 spline.p2 (segment).y());
127 case SPLINE_DRAWER_ENUM_VISIBLE_DRAW:
136 case SPLINE_DRAWER_ENUM_INVISIBLE_MOVE:
139 path.moveTo (point->
pos ());
142 OrdinalToGraphicsPoint::const_iterator itrBefore = itr - 1;
144 pathMultiValued.moveTo (pointBefore->
pos ());
145 pathMultiValued.cubicTo (p1,
148 lineMultiValued = lineStyle;
154 pathMultiValued.moveTo (point->
pos ());
161 QPainterPath GraphicsLinesForCurve::drawLinesStraight (QPainterPath & )
163 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight" 164 <<
" curve=" << m_curveName.toLatin1().data();
170 OrdinalToGraphicsPoint::const_iterator itr;
171 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
177 path.moveTo (point->
pos ());
179 path.lineTo (point->
pos ());
188 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal" 189 <<
" identifier=" << identifier.toLatin1().data();
191 OrdinalToGraphicsPoint::const_iterator itr;
192 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
196 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
201 ENGAUGE_ASSERT (
false);
208 QPainterPath &pathMultiValued,
211 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge" 212 <<
" curve=" << m_curveName.toLatin1().data();
214 OrdinalToGraphicsPoint::iterator itr, itrNext;
215 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
224 double ordinal = itr.key ();
227 m_graphicsPoints.remove (ordinal);
233 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
235 pen = QPen (Qt::NoPen);
239 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
254 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset" 255 <<
" curve=" << m_curveName.toLatin1().data();
257 OrdinalToGraphicsPoint::iterator itr;
258 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
266 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const 269 bool needRenumbering =
false;
270 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
272 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
277 if (ordinalKeyWanted != ordinalKeyGot) {
278 needRenumbering =
true;
283 return needRenumbering;
287 QTextStream &str)
const 289 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
291 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
292 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
293 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
295 indentation += INDENTATION_DELTA;
297 OrdinalToGraphicsPoint::const_iterator itr;
298 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
300 double ordinalKey = itr.key();
311 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint" 312 <<
" point=" << ordinal
313 <<
" pointCount=" << m_graphicsPoints.count();
315 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
318 m_graphicsPoints.remove (ordinal);
320 delete graphicsPoint;
325 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
327 OrdinalToGraphicsPoint::iterator itr;
328 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
332 m_graphicsPoints.remove (itr.key());
334 delete graphicsPoint;
340 void GraphicsLinesForCurve::renumberOrdinals ()
342 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
344 int ordinalKeyWanted;
348 QList<GraphicsPoint*> points;
349 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
351 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
352 points << graphicsPoint;
355 m_graphicsPoints.clear ();
357 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
360 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
369 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand" 370 <<
" curve=" << m_curveName.toLatin1().data()
371 <<
" pointCount=" << m_graphicsPoints.count();
374 if (m_graphicsPoints.contains (point.
ordinal())) {
376 graphicsPoint = m_graphicsPoints [point.
ordinal()];
392 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
397 ENGAUGE_CHECK_PTR (graphicsPoint);
403 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
405 OrdinalToGraphicsPoint::const_iterator itr;
406 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
415 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle" 416 <<
" curve=" << m_curveName.toLatin1().data()
417 <<
" highlightOpacity=" << highlightOpacity;
419 OrdinalToGraphicsPoint::const_iterator itr;
420 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
429 QPainterPath &pathMultiValued,
434 bool needRenumbering = needOrdinalRenumbering ();
435 if (needRenumbering) {
441 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints" 442 <<
" numberPoints=" << m_graphicsPoints.count()
443 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
452 m_graphicsPoints.count () < 3) {
454 path = drawLinesStraight (pathMultiValued);
456 path = drawLinesSmooth (lineStyle,
471 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updatePointOrdinalsAfterDrag" 472 <<
" curve=" << m_curveName.toLatin1().data()
473 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
475 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
476 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
481 XOrThetaToOrdinal xOrThetaToOrdinal;
482 OrdinalToGraphicsPoint::iterator itrP;
483 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
485 double ordinal = itrP.key();
493 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
497 OrdinalToGraphicsPoint temporaryList;
499 XOrThetaToOrdinal::const_iterator itrX;
500 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
502 double ordinalOld = *itrX;
505 temporaryList [ordinalNew++] = point;
509 m_graphicsPoints.clear();
510 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
512 double ordinal = itrP.key();
515 m_graphicsPoints [ordinal] = point;
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Cubic interpolation given independent and dependent value vectors.
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void updateCurveStyle(const CurveStyle &curveStyle)
Update the curve style for this curve.
unsigned int width() const
Width of line.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
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 setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPos(const QPointF pos)
Update the position.
QPointF posScreen() const
Accessor for screen position.
GraphicsLinesForCurve(const QString &curveName)
Single constructor.
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
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...
QString identifier() const
Unique identifier for a specific Point.
ColorPalette paletteColor() const
Line color.
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 printStream(QString indentation, QTextStream &str, double ordinalKey) const
Debugging method that supports print method of this class and printStream method of some other class(...
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.
bool wanted() const
Identify point as wanted//unwanted.
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.
void bindToSpline(const LineStyle &lineStyle, int numSegments, const Spline &spline)
Analyze each segment in the Spline.
SplineDrawerOperation segmentOperation(int segment) const
Indicate if, and how, segment is to be drawn.
void addPoint(const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new line.
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.
double identifierToOrdinal(const QString &identifier) const
Get ordinal for specified identifier.
void reset()
Mark point as unwanted, and unbind any bound lines.