Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineStateDeployedConstantTAbstract.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2019 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 "EngaugeAssert.h"
8#include "GuidelineLine.h"
12#include "Logger.h"
13#include <QGraphicsScene>
14#include "Transformation.h"
15
20
24
26{
27 // Selecting an arbitrary range value is tricky for the constant T case when log scaling is in effect, since
28 // we cannot pick:
29 // - the origin radius since we are creating a second point which will be later combined with the origin
30 // to fully define the Guideline line
31 // - any negative number (log only accepts positive values)
32 // - any value between 0 (exclusive) and the origin radius (exclusive) since there is no corresponding point
33 // in the graph when the log scale is increasing while moving away from the origin
34 // - any value between the origin radius (exclusive) and infinity since there is no corresponding point
35 // in the graph when the log scale is decreasing while moving away from the origin
36 // The strategy is to pick the four corners of the screen and use one of their coordinates
37 const QGraphicsScene &scene = context().guideline().scene();
38 QRectF sceneRect = scene.sceneRect();
39 QPointF posGraphTL, posGraphTR, posGraphBL, posGraphBR;
41 posGraphTL);
43 posGraphTR);
45 posGraphBL);
47 posGraphBR);
48 double arbitraryRange = qMax (posGraphTL.y(), qMax (posGraphTR.y(), qMax (posGraphBL.y(), posGraphBR.y())));
49
50 QPointF posScreen;
51 context().transformation().transformRawGraphToScreen (QPointF (valueGraph,
52 arbitraryRange),
53 posScreen);
54
55 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineStateDeployedConstantTAbstract::convertGraphCoordinateToScreenPoint"
56 << " pos=(" << posScreen.x() << ", " << posScreen.y() << ")";
57
58 return posScreen;
59}
60
62{
63 QPointF posGraph;
65 posGraph);
66
67 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineStateDeployedConstantTAbstract::convertScreenPointToGraphCoordinate"
68 << " pos=(" << posGraph.x() << ", " << posGraph.y() << ")";
69
70 return posGraph.x();
71}
72
74{
75 // pointToLine applies in this state
76 return EllipseParameters();
77}
78
79QLineF GuidelineStateDeployedConstantTAbstract::pointToLine (const QPointF &posScreen) const
80{
82
83 return projector.fromPosScreen (context().transformation(),
84 sceneRect (),
85 posScreen);
86}
87
89{
90 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineStateDeployedConstantTAbstract::updateWithLatestTransformation";
91
92 if (!context().transformation().transformIsDefined()) {
93 // Discard this Guideline immediately if the transformation transitions to undefined
95 } else {
96
98
99 GuidelineLine *line = dynamic_cast<GuidelineLine*> (&context().guideline());
100 line->setLine (projector.fromCoordinateT (context().transformation(),
101 sceneRect (),
102 context().posCursorGraph().x ()));
103 }
104}
@ GUIDELINE_STATE_DISCARDED
log4cpp::Category * mainCat
Definition Logger.cpp:14
Parameters that define an ellipse about the specified center, at the specified angle from alignment w...
QGraphicsScene & scene()
GraphicsScene that owns this class.
Line version of GuidelineAbstract.
Project a point along the radial direction in graph coordinates to produce a curve along the constant...
QLineF fromPosScreen(const Transformation &transformation, const QRectF &sceneRect, const QPointF &posScreen)
Return line through point in screen coordinates.
QLineF fromCoordinateT(const Transformation &transformation, const QRectF &sceneRect, double tGraph)
Return line through theta in graph coordinates.
QRectF sceneRect() const
Scene rectangle in screen coordinates (=pixels)
GuidelineStateContext & context() const
Context in charge of the state classes.
Context class for state machine that belongs to the Guideline class.
Transformation transformation() const
Return copy of transformation owned by MainWindow.
GuidelineAbstract & guideline()
Guideline that owns this context class.
void requestStateTransition(GuidelineState guidelineState)
Request a state transition.
GuidelineStateDeployedAbstract(GuidelineStateContext &context)
Single constructor.
virtual QPointF convertGraphCoordinateToScreenPoint(double valueGraph) const
Convert single graph coordinate into screen point pair.
GuidelineStateDeployedConstantTAbstract(GuidelineStateContext &context)
Single constructor.
virtual double convertScreenPointToGraphCoordinate(const QPointF &posScreen) const
Convert screen point pair into single graph coordinate.
virtual QLineF pointToLine(const QPointF &posScreen) const
Return line parallel to an axis line, that passes through the specified point.
virtual void updateWithLatestTransformation()
Update given Transformation in GuidelineStateContext.
virtual EllipseParameters pointToEllipse(const QPointF &posScreen) const
Return ellipse representing constant range, that passes through the specified point.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20