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> 22 #include <QTextStream> 23 #include "QtToString.h" 25 #include "Transformation.h" 30 typedef QMap<double, double> XOrThetaToOrdinal;
33 m_curveName (curveName)
35 setZValue (Z_VALUE_CURVE);
36 setData (DATA_KEY_GRAPHICS_ITEM_TYPE,
37 GRAPHICS_ITEM_TYPE_LINE);
38 setData (DATA_KEY_IDENTIFIER,
39 QVariant (m_curveName));
42 GraphicsLinesForCurve::~GraphicsLinesForCurve()
44 OrdinalToGraphicsPoint::iterator itr;
45 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
50 m_graphicsPoints.clear();
57 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::addPoint" 58 <<
" curve=" << m_curveName.toLatin1().data()
59 <<
" identifier=" << pointIdentifier.toLatin1().data()
60 <<
" ordinal=" << ordinal
61 <<
" pos=" << QPointFToString (graphicsPoint.
pos()).toLatin1().data()
62 <<
" newPointCount=" << (m_graphicsPoints.count() + 1);
64 m_graphicsPoints [ordinal] = &graphicsPoint;
67 QPainterPath GraphicsLinesForCurve::drawLinesSmooth ()
69 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesSmooth" 70 <<
" curve=" << m_curveName.toLatin1().data();
76 vector<SplinePair> xy;
77 OrdinalToGraphicsPoint::const_iterator itr;
78 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
80 double ordinal = itr.key();
83 t.push_back (ordinal);
95 int segmentEndingAtPointI = 0;
99 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
105 path.moveTo (point->
pos());
108 QPointF p1 (spline.
p1 (segmentEndingAtPointI).
x(),
109 spline.
p1 (segmentEndingAtPointI).
y());
110 QPointF p2 (spline.
p2 (segmentEndingAtPointI).
x(),
111 spline.
p2 (segmentEndingAtPointI).
y());
117 ++segmentEndingAtPointI;
125 QPainterPath GraphicsLinesForCurve::drawLinesStraight ()
127 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::drawLinesStraight" 128 <<
" curve=" << m_curveName.toLatin1().data();
134 OrdinalToGraphicsPoint::const_iterator itr;
135 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
141 path.moveTo (point->
pos ());
143 path.lineTo (point->
pos ());
152 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::identifierToOrdinal" 153 <<
" identifier=" << identifier.toLatin1().data();
155 OrdinalToGraphicsPoint::const_iterator itr;
156 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
160 if (point->
data (DATA_KEY_IDENTIFIER) == identifier) {
165 ENGAUGE_ASSERT (
false);
172 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipPurge" 173 <<
" curve=" << m_curveName.toLatin1().data();
175 OrdinalToGraphicsPoint::iterator itr, itrNext;
176 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
185 double ordinal = itr.key ();
188 m_graphicsPoints.remove (ordinal);
194 if (lineStyle.
paletteColor() == COLOR_PALETTE_TRANSPARENT) {
196 pen = QPen (Qt::NoPen);
200 pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
212 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::lineMembershipReset" 213 <<
" curve=" << m_curveName.toLatin1().data();
215 OrdinalToGraphicsPoint::iterator itr;
216 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
224 bool GraphicsLinesForCurve::needOrdinalRenumbering ()
const 227 bool needRenumbering =
false;
228 for (
int ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
230 double ordinalKeyGot = m_graphicsPoints.keys().at (ordinalKeyWanted);
235 if (ordinalKeyWanted != ordinalKeyGot) {
236 needRenumbering =
true;
241 return needRenumbering;
245 QTextStream &str)
const 247 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
249 str << indentation <<
"GraphicsLinesForCurve=" << m_curveName
250 <<
" dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
251 <<
" dataType=" << dataKeyToString (type).toLatin1().data() <<
"\n";
253 indentation += INDENTATION_DELTA;
255 OrdinalToGraphicsPoint::const_iterator itr;
256 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
258 double ordinalKey = itr.key();
269 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removePoint" 270 <<
" point=" << ordinal
271 <<
" pointCount=" << m_graphicsPoints.count();
273 ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
276 m_graphicsPoints.remove (ordinal);
278 delete graphicsPoint;
283 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::removeTemporaryPointIfExists";
285 OrdinalToGraphicsPoint::iterator itr;
286 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
290 m_graphicsPoints.remove (itr.key());
292 delete graphicsPoint;
298 void GraphicsLinesForCurve::renumberOrdinals ()
300 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::renumberOrdinals";
302 int ordinalKeyWanted;
306 QList<GraphicsPoint*> points;
307 for (ordinalKeyWanted = 0; ordinalKeyWanted < m_graphicsPoints.count(); ordinalKeyWanted++) {
309 GraphicsPoint *graphicsPoint = m_graphicsPoints.values().at (ordinalKeyWanted);
310 points << graphicsPoint;
313 m_graphicsPoints.clear ();
315 for (ordinalKeyWanted = 0; ordinalKeyWanted < points.count(); ordinalKeyWanted++) {
318 m_graphicsPoints [ordinalKeyWanted] = graphicsPoint;
327 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateAfterCommand" 328 <<
" curve=" << m_curveName.toLatin1().data()
329 <<
" pointCount=" << m_graphicsPoints.count();
332 if (m_graphicsPoints.contains (point.
ordinal())) {
334 graphicsPoint = m_graphicsPoints [point.
ordinal()];
350 m_graphicsPoints [point.
ordinal ()] = graphicsPoint;
355 ENGAUGE_CHECK_PTR (graphicsPoint);
361 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle";
363 OrdinalToGraphicsPoint::const_iterator itr;
364 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
373 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateCurveStyle" 374 <<
" curve=" << m_curveName.toLatin1().data()
375 <<
" highlightOpacity=" << highlightOpacity;
377 OrdinalToGraphicsPoint::const_iterator itr;
378 for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
389 bool needRenumbering = needOrdinalRenumbering ();
390 if (needRenumbering) {
396 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints" 397 <<
" numberPoints=" << m_graphicsPoints.count()
398 <<
" ordinalRenumbering=" << (needRenumbering ?
"true" :
"false");
407 m_graphicsPoints.count () < 3) {
409 path = drawLinesStraight ();
411 path = drawLinesSmooth ();
423 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints" 424 <<
" curve=" << m_curveName.toLatin1().data()
425 <<
" curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
427 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
428 curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
433 XOrThetaToOrdinal xOrThetaToOrdinal;
434 OrdinalToGraphicsPoint::iterator itrP;
435 for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
437 double ordinal = itrP.key();
445 xOrThetaToOrdinal [pointGraph.x()] = ordinal;
449 OrdinalToGraphicsPoint temporaryList;
451 XOrThetaToOrdinal::const_iterator itrX;
452 for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
454 double ordinalOld = *itrX;
457 temporaryList [ordinalNew++] = point;
461 m_graphicsPoints.clear();
462 for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
464 double ordinal = itrP.key();
467 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.
double y() const
Get method for y.
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 updateGraphicsLinesToMatchGraphicsPoints(const LineStyle &lineStyle)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
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.
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.
SplinePair p2(unsigned int i) const
Bezier p2 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
SplinePair p1(unsigned int i) const
Bezier p1 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
void addPoint(const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new line.
Add point and line handling to generic QGraphicsScene.
double x() const
Get method for x.
void lineMembershipPurge(const LineStyle &lineStyle)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
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.