KiCad PCB EDA Suite
Loading...
Searching...
No Matches
two_point_assistant.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
24#include <view/view.h>
25
26
27using namespace KIGFX::PREVIEW;
28
30 const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
31 GEOM_SHAPE aShape ) :
33 m_constructMan( aManager ),
34 m_units( aUnits ),
35 m_shape( aShape ),
36 m_iuScale( aIuScale )
37{
38}
39
40
42{
43 BOX2I tmp;
44
45 // no bounding box when no graphic shown
46 if( m_constructMan.IsReset() )
47 return tmp;
48
49 // this is an edit-time artefact; no reason to try and be smart with the bounding box
50 // (besides, we can't tell the text extents without a view to know what the scale is)
51 tmp.SetMaximum();
52 return tmp;
53}
54
55
56void TWO_POINT_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
57{
58 KIGFX::GAL& gal = *aView->GetGAL();
59
60 // not in a position to draw anything
61 if( m_constructMan.IsReset() )
62 return;
63
64 const VECTOR2I origin = m_constructMan.GetOrigin();
65 const VECTOR2I end = m_constructMan.GetEnd();
66 const VECTOR2D radVec = end - origin;
67
68 // Ensures that +90° is up and -90° is down in pcbnew
69 const EDA_ANGLE deltaAngle( VECTOR2I( radVec.x, -radVec.y ) );
70
71 if( radVec.x == 0 && radVec.y == 0 )
72 {
73 return; // text next to cursor jumps around a lot in this corner case
74 }
75
77
78 wxArrayString cursorStrings;
79
81 {
82 cursorStrings.push_back(
83 DimensionLabel( "l", radVec.EuclideanNorm(), m_iuScale, m_units ) );
84 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), deltaAngle.AsDegrees(),
86 }
87 else if( m_shape == GEOM_SHAPE::RECT )
88 {
89 cursorStrings.push_back( DimensionLabel( "x", std::abs( radVec.x ), m_iuScale, m_units ) );
90 cursorStrings.push_back( DimensionLabel( "y", std::abs( radVec.y ), m_iuScale, m_units ) );
91 }
92 else if( m_shape == GEOM_SHAPE::CIRCLE )
93 {
94 KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
95 preview_ctx.DrawLine( origin, end, false );
96
97 cursorStrings.push_back(
98 DimensionLabel( "r", radVec.EuclideanNorm(), m_iuScale, m_units ) );
99 }
100
101 // place the text next to cursor, on opposite side from drawing
102 DrawTextNextToCursor( aView, end, origin - end, cursorStrings, aLayer == LAYER_SELECT_OVERLAY );
103}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr void SetMaximum()
Definition box2.h:76
double AsDegrees() const
Definition eda_angle.h:116
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
Abstract interface for drawing on a 2D-surface.
void ResetTextAttributes()
Reset text attributes to default styling.
A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy t...
void DrawLine(const VECTOR2I &aStart, const VECTOR2I &aEnd, bool aDeEmphasised)
Draw a simple line on the current layer.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the assistance (with reference to the construction manager.
const TWO_POINT_GEOMETRY_MANAGER & m_constructMan
TWO_POINT_ASSISTANT(const TWO_POINT_GEOMETRY_MANAGER &aManager, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, GEOM_SHAPE aShape)
Represent a very simple geometry manager for items that have a start and end point.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:207
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:279
EDA_UNITS
Definition eda_units.h:44
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:276
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const wxArrayString &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.
wxString DimensionLabel(const wxString &prefix, double aVal, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, bool aIncludeUnits=true)
Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffi...
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
VECTOR2I end
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:72
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682