KiCad PCB EDA Suite
Loading...
Searching...
No Matches
arc_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
21
24
26#include <view/view.h>
27
28#include <base_units.h>
29#include <trigo.h>
30
31using namespace KIGFX::PREVIEW;
32
34 EDA_UNITS aUnits ) :
36 m_constructMan( aManager ),
37 m_iuScale( aIuScale ),
38 m_units( aUnits ),
39 m_drawArc( false )
40{
41}
42
43
45{
46 BOX2I tmp;
47
48 // no bounding box when no graphic shown
49 if( m_constructMan.IsReset() )
50 return tmp;
51
52 // this is an edit-time artifact; no reason to try and be smart with the bounding box
53 // (besides, we can't tell the text extents without a view to know what the scale is)
54 tmp.SetMaximum();
55 return tmp;
56}
57
58
59void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
60{
61 KIGFX::GAL& gal = *aView->GetGAL();
62
63 // not in a position to draw anything
64 if( m_constructMan.IsReset() )
65 return;
66
68
69 const VECTOR2I origin = m_constructMan.GetOrigin();
70
71 KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
72
73 // draw first radius line
74 bool dimFirstLine = m_constructMan.GetStep() > ARC_GEOM_MANAGER::SET_START;
75
76 preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetStartRadiusEnd(),
77 dimFirstLine );
78
79 wxArrayString cursorStrings;
80
82 {
83 // haven't started the angle selection phase yet
84
85 EDA_ANGLE initAngle = m_constructMan.GetStartAngle();
86
87 // Draw the radius guide circle if wanted
88 if( m_drawArc )
89 {
90 preview_ctx.DrawCircle( origin, m_constructMan.GetRadius(), true );
91 }
92
93 initAngle.Normalize720();
94
95 cursorStrings.push_back(
96 DimensionLabel( "r", m_constructMan.GetRadius(), m_iuScale, m_units ) );
97 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ),
98 initAngle.AsDegrees(), m_iuScale,
100 }
101 else
102 {
103 preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetEndRadiusEnd(), false );
104
105 EDA_ANGLE start = m_constructMan.GetStartAngle();
106 EDA_ANGLE subtended = m_constructMan.GetSubtended();
107 EDA_ANGLE normalizedEnd = ( start + subtended ).Normalize180();
108
109 // draw dimmed extender line to cursor
110 preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetLastPoint(), true );
111
112 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "Δθ" ), subtended.AsDegrees(),
114 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ),
115 normalizedEnd.AsDegrees(), m_iuScale,
117 }
118
119 // place the text next to cursor, on opposite side from radius
120 DrawTextNextToCursor( aView, m_constructMan.GetLastPoint(),
121 origin - m_constructMan.GetLastPoint(), cursorStrings,
122 aLayer == LAYER_SELECT_OVERLAY );
123}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr void SetMaximum()
Definition box2.h:76
double AsDegrees() const
Definition eda_angle.h:116
EDA_ANGLE Normalize720()
Definition eda_angle.h:279
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.
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the assistance (with reference to the construction manager.
bool m_drawArc
Draw the arc segment (or just the radius lines).
const ARC_GEOM_MANAGER & m_constructMan
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
ARC_ASSISTANT(const ARC_GEOM_MANAGER &aManager, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
const EDA_IU_SCALE & m_iuScale
Manage the construction of a circular arc though sequential setting of critical points: center,...
@ SET_START
Waiting to lock in the arc start point.
A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy t...
void DrawLineWithAngleHighlight(const VECTOR2I &aStart, const VECTOR2I &aEnd, bool aDeEmphasised)
Draw a straight line on the current layer, with a special highlight when the line angle is a multiple...
void DrawCircle(const VECTOR2I &aOrigin, double aRad, bool aDeEmphasised)
Draw a preview circle on the current layer.
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
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...
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:72
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683