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 (C) 2017-2022 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
28
30#include <view/view.h>
31
32#include <base_units.h>
33#include <trigo.h>
34
35using namespace KIGFX::PREVIEW;
36
38 EDA_UNITS aUnits ) :
40 m_constructMan( aManager ),
41 m_iuScale( aIuScale ),
42 m_units( aUnits )
43{
44}
45
46
48{
49 BOX2I tmp;
50
51 // no bounding box when no graphic shown
53 return tmp;
54
55 // this is an edit-time artefact; no reason to try and be smart with the bounding box
56 // (besides, we can't tell the text extents without a view to know what the scale is)
57 tmp.SetMaximum();
58 return tmp;
59}
60
61
62void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
63{
64 KIGFX::GAL& gal = *aView->GetGAL();
65
66 // not in a position to draw anything
68 return;
69
71
72 const VECTOR2I origin = m_constructMan.GetOrigin();
73
74 KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
75
76 // draw first radius line
78
80 dimFirstLine );
81
82 wxArrayString cursorStrings;
83
85 {
86 // haven't started the angle selection phase yet
87
89
90 // draw the radius guide circle
91 preview_ctx.DrawCircle( origin, m_constructMan.GetRadius(), true );
92
93 initAngle.Normalize720();
94
95 cursorStrings.push_back(
97 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), initAngle.AsDegrees(), m_iuScale,
98 EDA_UNITS::DEGREES ) );
99 }
100 else
101 {
102 preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetEndRadiusEnd(), false );
103
106 EDA_ANGLE normalizedEnd = ( start + subtended ).Normalize180();
107
108 // draw dimmed extender line to cursor
109 preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetLastPoint(), true );
110
111 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "Δθ" ), subtended.AsDegrees(),
112 m_iuScale, EDA_UNITS::DEGREES ) );
113 cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ),
114 normalizedEnd.AsDegrees(), m_iuScale,
115 EDA_UNITS::DEGREES ) );
116 }
117
118 // place the text next to cursor, on opposite side from radius
120 origin - m_constructMan.GetLastPoint(), cursorStrings,
121 aLayer == LAYER_SELECT_OVERLAY );
122}
constexpr void SetMaximum()
Definition: box2.h:80
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Normalize720()
Definition: eda_angle.h:271
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
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.
const ARC_GEOM_MANAGER & m_constructMan
Definition: arc_assistant.h:73
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
Definition: arc_assistant.h:74
Manage the construction of a circular arc though sequential setting of critical points: center,...
VECTOR2I GetOrigin() const
< Get the center point of the arc (valid when state > SET_ORIGIN)
ARC_STEPS GetStep() const
Get the current step the manager is on (useful when drawing something depends on the current state)
EDA_ANGLE GetStartAngle() const
Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE)
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc end point.
VECTOR2I GetEndRadiusEnd() const
Get the radius of the arc (valid if step >= SET_START)
double GetRadius() const
Get the angle of the vector leading to the start point (valid if step >= SET_START)
@ 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...
Definition: draw_context.h:45
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.
VECTOR2I GetLastPoint() const
Get the last point added (locked in or not).
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:203
EDA_UNITS
Definition: eda_units.h:46
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:220
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:79