Engauge Digitizer 2
Loading...
Searching...
No Matches
CentipedeSegmentConstantREllipse.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2020 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
10#include "DocumentModelCoords.h"
11#include "EnumsToQt.h"
12#include "GraphicsArcItem.h"
14#include "GraphicsScene.h"
15#include "mmsubs.h"
16#include <qdebug.h>
17#include <qmath.h>
18#include <QPen>
19#include "QtToString.h"
20
22 const DocumentModelCoords &modelCoords,
25 const QPointF &posClickScreen) :
29{
30 // Radius through click point
31 QPointF posClickGraph;
32 transformation.transformScreenToRawGraph (posClickScreen,
33 posClickGraph);
34 double rGraph = posClickGraph.y();
35
36 // Compute basis vectors that are used here and when by any callback(s)
37 QPointF posOriginGraph (0, 0);
38 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LOG) {
39 posOriginGraph = QPointF (0, modelCoords.originRadius());
40 }
41
42 QPointF posScreen0, posScreen90;
43 transformation.transformRawGraphToScreen (posOriginGraph,
44 m_posOriginScreen);
45 transformation.transformRawGraphToScreen (QPointF (0, rGraph),
46 posScreen0);
47 transformation.transformRawGraphToScreen (QPointF (90, rGraph),
48 posScreen90);
49
50 // Fit the ellipse
51 CentipedeEndpointsPolar endpointsPolar (modelCoords,
55 m_posOriginScreen);
56
57 QRectF rectBounding;
58 CentipedeDebugPolar debugPolar;
59 double angleRotation;
62 angleRotation,
63 rectBounding,
64 debugPolar);;
65
66 debugPolar.display (scene,
67 modelCoords,
69
70 // Compute position and angle values
71 m_posRadialLow = endpointsPolar.posScreenConstantRForLowT (modelGuideline.creationCircleRadius());
72 m_posRadialHigh = endpointsPolar.posScreenConstantRForHighT (modelGuideline.creationCircleRadius());
73 endpointsPolar.posScreenConstantRHighLow (modelGuideline.creationCircleRadius (),
74 m_posTangentialLow,
75 m_posTangentialHigh);
76
77 // Create graphics item and its relay. As explained in GuidelineEllipse::updateGeometry, the correct sequence
78 // of graphical operations is very tricky, and less successful if setTransformOriginPoint is used (e.g. works for
79 // non-shear cases but not shear cases)
80 m_graphicsItem = new GraphicsArcItem (rectBounding);
81 m_graphicsItem->setSpanAngle (0); // Prevent flicker by display before span angle is changed from all-inclusive default
82 m_graphicsItem->setRotation (qRadiansToDegrees (angleRotation));
83 m_graphicsItem->setPos (m_posOriginScreen);
84 m_graphicsItemRelay = new GraphicsArcItemRelay (this,
85 m_graphicsItem);
86 QColor color (ColorPaletteToQColor (modelGuideline.lineColor()));
87 m_graphicsItem->setPen (QPen (color,
88 modelGuideline.lineWidthActive ()));
89 updateRadius (modelGuideline.creationCircleRadius());
90
91 scene.addItem (m_graphicsItem);
92}
93
95{
96 delete m_graphicsItem;
97 delete m_graphicsItemRelay;
98}
99
101{
102 double distanceLow = magnitude (posScreen - m_posRadialLow);
103 double distanceHigh = magnitude (posScreen - m_posRadialHigh);
104
105 return qMin (distanceLow, distanceHigh);
106}
107
109{
110 // Scale up/down the angles, with them converging to center angle as radius goes to zero
111 double scaling = radius / modelGuideline().creationCircleRadius ();
112
113 emit signalUpdateAngles (m_posTangentialLow - m_posOriginScreen,
114 posClickScreen () - m_posOriginScreen,
115 m_posTangentialHigh - m_posOriginScreen,
116 m_graphicsItem->rect().width () / m_graphicsItem->rect().height(),
117 scaling);
118}
@ COORD_SCALE_LOG
Definition CoordScale.h:14
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
Class for collecting and then displaying debug information computed during constant R ellipse calcula...
void display(QGraphicsScene &scene, const DocumentModelCoords &modelCoords, const Transformation &transformation)
Display member variable values on scene.
Compute endpoints for polar centipedes.
QPointF posScreenConstantRForLowT(double radius) const
Screen point for R value of circle/coordinate intersection in the decreasing T direction.
void ellipseScreenConstantRForTHighLowAngles(const Transformation &transformation, const QPointF &posClickScreen, double &angleRotation, QRectF &rectBounding, CentipedeDebugPolar &DebugPolar)
Ellipse for R value of circle/coordinate intersection. Start/span angles are calculated separately.
void posScreenConstantRHighLow(double radiusAboutClick, QPointF &posLow, QPointF &posHigh) const
Return two points (posLow and posHigh) where circle around posClickScreen intersects constant-radiusA...
QPointF posScreenConstantRForHighT(double radius) const
Screen point for R value of circle/coordinate intersection in the increasing T direction.
QPointF posClickScreen() const
Center of circle in screen coordinates.
CentipedeSegmentAbstract(const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
const DocumentModelGuideline & modelGuideline() const
Settings.
Transformation transformation() const
Transformation which is static through the entire lifetime of the Centipede class instances.
CentipedeSegmentConstantREllipse(GraphicsScene &scene, const DocumentModelCoords &modelCoords, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const
Return distance to closest endpoint.
virtual void updateRadius(double radius)
Update geometry to reflect cursor movement.
void signalUpdateAngles(QPointF posTangentialLow, QPointF posTangentialCenter, QPointF posTangentialHigh, double widthToHeight, double scaling)
Send new geometry for later updating.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
Model for managing the coordinate values corresponding Guidelines.
double creationCircleRadius() const
Get method for creation circle radius in pixels.
Enable postponed geometry changes for GraphicsArcItem, using a signal to trigger this class to update...
Draw an arc as an ellipse but without lines from the center to the start and end points.
Add point and line handling to generic QGraphicsScene.
Affine transformation between screen and graph coordinates, based on digitized axis points.
double magnitude(const QPointF &vec)
Norm of vector.
Definition mmsubs.cpp:193