KiCad PCB EDA Suite
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 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 <common.h>
33 #include <base_units.h>
34 #include <trigo.h>
35 
36 using namespace KIGFX::PREVIEW;
37 
39  : EDA_ITEM( NOT_USED ), m_constructMan( aManager ), m_units( aUnits )
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 artefact; 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 
65 double getNormDeciDegFromRad( double aRadians )
66 {
67  double degs = RAD2DECIDEG( aRadians );
68 
69  // normalise to +/- 360
70  while( degs < -3600.0 )
71  degs += 3600.0;
72 
73  while( degs > 3600.0 )
74  degs -= 3600.0;
75 
76  return degs;
77 }
78 
79 
80 void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
81 {
82  auto& gal = *aView->GetGAL();
83 
84  // not in a position to draw anything
85  if( m_constructMan.IsReset() )
86  return;
87 
88  gal.ResetTextAttributes();
89 
90  const auto origin = m_constructMan.GetOrigin();
91 
92  KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
93 
94  // draw first radius line
95  bool dimFirstLine = m_constructMan.GetStep() > ARC_GEOM_MANAGER::SET_START;
96 
97  preview_ctx.DrawLineWithAngleHighlight(
98  origin, m_constructMan.GetStartRadiusEnd(), dimFirstLine );
99 
100  std::vector<wxString> cursorStrings;
101 
103  {
104  // haven't started the angle selection phase yet
105 
106  double initAngle = m_constructMan.GetStartAngle();
107 
108  // draw the radius guide circle
109  preview_ctx.DrawCircle( origin, m_constructMan.GetRadius(), true );
110 
111  double degs = getNormDeciDegFromRad( initAngle );
112 
113  cursorStrings.push_back( DimensionLabel( "r", m_constructMan.GetRadius(), m_units ) );
114  cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), degs,
115  EDA_UNITS::DEGREES ) );
116  }
117  else
118  {
119  preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetEndRadiusEnd(), false );
120 
121  double start = m_constructMan.GetStartAngle();
122  double subtended = m_constructMan.GetSubtended();
123  double subtendedDeg = getNormDeciDegFromRad( subtended );
124  double endAngleDeg = getNormDeciDegFromRad( start + subtended );
125 
126  // draw dimmed extender line to cursor
127  preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetLastPoint(), true );
128 
129  cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "Δθ" ), subtendedDeg,
130  EDA_UNITS::DEGREES ) );
131  cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), endAngleDeg,
132  EDA_UNITS::DEGREES ) );
133  }
134 
135  // place the text next to cursor, on opposite side from radius
137  origin - m_constructMan.GetLastPoint(),
138  cursorStrings, aLayer == LAYER_SELECT_OVERLAY );
139 }
EDA_UNITS
Definition: common.h:200
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the assistance (with reference to the contstruction manager.
ARC_ASSISTANT(const ARC_GEOM_MANAGER &aManager, EDA_UNITS aUnits)
VECTOR2I GetEndRadiusEnd() const
Get the coordinates of the arc end point
Implementation of conversion functions that require both schematic and board internal units.
the 3d code uses this value
Definition: typeinfo.h:80
double RAD2DECIDEG(double rad)
Definition: trigo.h:225
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:182
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc start
const ARC_GEOM_MANAGER & m_constructMan
Definition: arc_assistant.h:69
wxString DimensionLabel(const wxString &prefix, double aVal, EDA_UNITS aUnits, bool aIncludeUnits=true)
Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffi...
double GetStartAngle() const
Get the angle of the vector leading to the start point (valid if step >= SET_START)
double GetSubtended() const
Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE)
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 ResetTextAttributes()
Reset text attributes to default styling.
Waiting to lock in origin point
VECTOR2I GetOrigin() const
Get the centre point of the arc (valid when state > SET_ORIGIN)
void SetMaximum()
Definition: box2.h:73
double GetRadius() const
Get the radius of the arc (valid if step >= SET_START)
void DrawCircle(const VECTOR2I &aOrigin, double aRad, bool aDeEmphasised)
Draw a preview circle on the current layer.
A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy t...
Definition: draw_context.h:44
VECTOR2I GetLastPoint() const
Gets the last point added (locked in or not).
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
double getNormDeciDegFromRad(double aRadians)
Get deci-degrees from radians, normalised to +/- 360.
ARC_STEPS GetStep() const
Get the current step the mananger is on (useful when drawing something depends on the current state)
currently selected items overlay
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:147
The common library.
VIEW.
Definition: view.h:63
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const std::vector< wxString > &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.