Engauge Digitizer  2
GraphicsLinesForCurves.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "Curve.h"
8 #include "CurveStyles.h"
9 #include "DataKey.h"
10 #include "EngaugeAssert.h"
11 #include "GraphicsLinesForCurve.h"
12 #include "GraphicsLinesForCurves.h"
13 #include "GraphicsPoint.h"
14 #include "GraphicsPointAbstractBase.h"
15 #include "GraphicsScene.h"
16 #include <iostream>
17 #include "Logger.h"
18 #include "Point.h"
19 #include <QGraphicsItem>
20 #include <QTextStream>
21 #include "QtToString.h"
22 #include "Transformation.h"
23 
25 {
26 }
27 
28 void GraphicsLinesForCurves::addPoint (const QString &curveName,
29  const QString &pointIdentifier,
30  double ordinal,
31  GraphicsPoint &point)
32 {
33  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::addPoint"
34  << " curve=" << curveName.toLatin1().data()
35  << " identifier=" << pointIdentifier.toLatin1().data()
36  << " ordinal=" << ordinal
37  << " pos=" << QPointFToString (point.pos()).toLatin1().data();
38 
39  m_graphicsLinesForCurve [curveName]->addPoint (pointIdentifier,
40  ordinal,
41  point);
42 }
43 
45  const QStringList &curveNames)
46 {
47  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::addRemoveCurves"
48  << " curveCount=" << m_graphicsLinesForCurve.count();
49 
50  // Add new curves
51  QStringList::const_iterator itrC;
52  for (itrC = curveNames.begin (); itrC != curveNames.end (); itrC++) {
53 
54  QString curveName = *itrC;
55 
56  if (!m_graphicsLinesForCurve.contains (curveName)) {
57 
58  GraphicsLinesForCurve *item = new GraphicsLinesForCurve(curveName);
59  scene.addItem (item);
60 
61  m_graphicsLinesForCurve [curveName] = item;
62  }
63  }
64 
65  // Remove expired curves
66  GraphicsLinesContainer::const_iterator itrG, itrGNext;
67  for (itrG = m_graphicsLinesForCurve.begin (); itrG != m_graphicsLinesForCurve.end (); itrG = itrGNext) {
68 
69  const QString curveName = itrG.key ();
70  GraphicsLinesForCurve *graphicsLines = itrG.value();
71 
72  itrGNext = itrG;
73  itrGNext++;
74 
75  if (!curveNames.contains (curveName)) {
76 
77  delete graphicsLines;
78  m_graphicsLinesForCurve.remove (curveName);
79  }
80  }
81 }
82 
84 {
85  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::lineMembershipPurge";
86 
87  GraphicsLinesContainer::const_iterator itr;
88  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
89 
90  const QString curveName = itr.key ();
91  GraphicsLinesForCurve *graphicsLines = itr.value();
92 
93  graphicsLines->lineMembershipPurge (curveStyles.lineStyle (curveName));
94  }
95 }
96 
98 {
99  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::lineMembershipReset";
100 
101  GraphicsLinesContainer::const_iterator itr;
102  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
103 
104  GraphicsLinesForCurve *graphicsLines = itr.value();
105 
106  graphicsLines->lineMembershipReset ();
107  }
108 }
109 
111 {
112  QString text;
113  QTextStream str (&text);
114 
115  printStream ("", str);
116  std::cerr << text.toLatin1().data();
117 }
118 
119 void GraphicsLinesForCurves::printStream (QString indentation,
120  QTextStream &str) const
121 {
122  str << indentation << "GraphicsLinesForCurves\n";
123 
124  indentation += INDENTATION_DELTA;
125 
126  GraphicsLinesContainer::const_iterator itr;
127  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
128 
129  const GraphicsLinesForCurve *graphicsLines = itr.value();
130 
131  graphicsLines->printStream (indentation,
132  str);
133  }
134 }
135 
136 void GraphicsLinesForCurves::removePoint(const QString &identifier)
137 {
138  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::removePoint"
139  << " point=" << identifier.toLatin1().data ()
140  << " curveCount=" << m_graphicsLinesForCurve.count();
141 
142  QString curveName = Point::curveNameFromPointIdentifier(identifier);
143 
144  ENGAUGE_ASSERT (m_graphicsLinesForCurve.contains (curveName));
145  double ordinal = m_graphicsLinesForCurve [curveName]->identifierToOrdinal (identifier);
146  m_graphicsLinesForCurve [curveName]->removePoint(ordinal);
147 }
148 
150 {
151  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::removeTemporaryPointIfExists";
152 
154 
155  ENGAUGE_ASSERT (m_graphicsLinesForCurve.contains (curveName));
156  m_graphicsLinesForCurve [curveName]->removeTemporaryPointIfExists ();
157 }
158 
160 {
161  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::resetOnLoad";
162 
163  GraphicsLinesContainer::iterator itr;
164  for (itr = m_graphicsLinesForCurve.begin(); itr != m_graphicsLinesForCurve.end(); itr++) {
165  GraphicsLinesForCurve *curve = itr.value();
166  delete curve;
167  }
168 
169  m_graphicsLinesForCurve.clear();
170 }
171 
173  const CurveStyles &curveStyles,
174  const QString &curveName,
175  const Point &point,
176  GeometryWindow *geometryWindow)
177 {
178  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsLinesForCurves::updateAfterCommand"
179  << " point=" << point.identifier().toLatin1().data()
180  << " curveCount=" << m_graphicsLinesForCurve.count();
181 
182  ENGAUGE_ASSERT (m_graphicsLinesForCurve.contains (curveName));
183  m_graphicsLinesForCurve [curveName]->updateAfterCommand (scene,
184  curveStyles.pointStyle(curveName),
185  point,
186  geometryWindow);
187 }
188 
190 {
191  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::updateCurveStyles";
192 
193  GraphicsLinesContainer::const_iterator itr;
194  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
195 
196  QString curveName = itr.key();
197 
198  m_graphicsLinesForCurve [curveName]->updateCurveStyle (modelCurveStyles.curveStyle (curveName));
199  }
200 }
201 
203 {
204  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::updateGraphicsLinesToMatchGraphicsPoints";
205 
206  GraphicsLinesContainer::const_iterator itr;
207  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
208 
209  QString curveName = itr.key();
210 
211  // This is where we add lines for non-axes curves
212  if (curveName != AXIS_CURVE_NAME) {
213 
214  m_graphicsLinesForCurve [curveName]->updateGraphicsLinesToMatchGraphicsPoints(curveStyles.lineStyle (curveName));
215  }
216  }
217 }
218 
220 {
221  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::updateHighlightOpacity"
222  << " highlightOpacity=" << highlightOpacity;
223 
224  GraphicsLinesContainer::const_iterator itr;
225  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
226 
227  QString curveName = itr.key();
228 
229  m_graphicsLinesForCurve [curveName]->updateHighlightOpacity (highlightOpacity);
230  }
231 }
232 
234  const Transformation &transformation)
235 {
236  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::updatePointOrdinalsAfterDrag";
237 
238  GraphicsLinesContainer::const_iterator itr;
239  for (itr = m_graphicsLinesForCurve.begin (); itr != m_graphicsLinesForCurve.end (); itr++) {
240 
241  QString curveName = itr.key();
242  GraphicsLinesForCurve *graphicsLines = itr.value();
243 
244  graphicsLines->updatePointOrdinalsAfterDrag (curveStyles.lineStyle (curveName),
245  transformation);
246  }
247 }
void lineMembershipPurge(const CurveStyles &curveStyles)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
void removePoint(const QString &identifier)
Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScen...
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
Definition: CurveStyles.cpp:79
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
Definition: Point.cpp:227
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
QPointF pos() const
Proxy method for QGraphicsItem::pos.
GraphicsLinesForCurves()
Single constructor.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:22
void addPoint(const QString &curveName, const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new point.
void lineMembershipReset()
Mark points as unwanted. Afterwards, lineMembershipPurge gets called.
const PointStyle pointStyle(const QString &curveName) const
Get method for copying one point style. Cannot return just a reference or else there is a warning abo...
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:23
Window that displays the geometry information, as a table, for the current curve. ...
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition: Point.cpp:507
void updateAfterCommand(GraphicsScene &scene, const CurveStyles &curveStyles, const QString &curveName, const Point &point, GeometryWindow *geometryWindow)
Update the GraphicsScene with the specified Point from the Document. If it does not exist yet in the ...
void updatePointOrdinalsAfterDrag(const CurveStyles &curveStyles, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag.
void updatePointOrdinalsAfterDrag(const LineStyle &lineStyle, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag. Pretty much the same steps as Curve::updatePointOrdinals...
This class stores the GraphicsLine objects for one Curve.
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &curveStyles)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
QString identifier() const
Unique identifier for a specific Point.
Definition: Point.cpp:256
void print() const
Debugging method for printing directly from symbolic debugger.
Affine transformation between screen and graph coordinates, based on digitized axis points...
const LineStyle lineStyle(const QString &curveName) const
Get method for copying one line style in one step.
Definition: CurveStyles.cpp:97
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
void updateCurveStyles(const CurveStyles &modelCurveStyles)
Update the curve style for every curve.
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:33
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
void lineMembershipPurge(const LineStyle &lineStyle)
Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines...
void addRemoveCurves(GraphicsScene &scene, const QStringList &curveNames)
Add new curves and remove expired curves to match the specified list.
void updateHighlightOpacity(double highlightOpacity)
Update the highlight opacity value. This may or may not affect the current display immediately depend...