KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bezier_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, 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 const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
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 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 BEZIER_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 start = m_constructMan.GetStart();
71
72 KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
73
74 int dashSize = KiROUND( aView->ToWorld( 12 ) );
75
77 {
78 // Draw the first control point control line
79 preview_ctx.DrawLineDashed( start, m_constructMan.GetControlC1(), dashSize, dashSize / 2,
80 false );
81 }
82
84 {
85 const VECTOR2I c2vec = m_constructMan.GetControlC2() - m_constructMan.GetEnd();
86
87 // Draw the second control point control line as a double length line
88 // centered on the end point
89 preview_ctx.DrawLineDashed( m_constructMan.GetEnd() - c2vec, m_constructMan.GetControlC2(),
90 dashSize, dashSize / 2, false );
91 }
92
93 wxArrayString cursorStrings;
94
96 {
97 // Going to need a better way to get a length here
98 // const int length = m_constructMan.GetBezierLength();
99 // Have enough points to report a bezier length
100 // cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "L" ), 12300000,
101 // m_iuScale, m_units ) );
102 }
103
104 if( !cursorStrings.empty() )
105 {
106 // place the text next to cursor, on opposite side from radius
107 DrawTextNextToCursor( aView, m_constructMan.GetLastPoint(),
108 start - m_constructMan.GetLastPoint(), cursorStrings,
109 aLayer == LAYER_SELECT_OVERLAY );
110 }
111}
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
constexpr void SetMaximum()
Definition box2.h:80
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
Abstract interface for drawing on a 2D-surface.
void ResetTextAttributes()
Reset text attributes to default styling.
BEZIER_ASSISTANT(const BEZIER_GEOM_MANAGER &aManager, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
const BEZIER_GEOM_MANAGER & m_constructMan
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the assistance (with reference to the construction manager.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Manage the construction of a bezier through a series of steps.
@ SET_CONTROL2
Waiting to lock in the second control point.
@ SET_END
Waiting to lock in the end point.
@ SET_CONTROL1
Waiting to lock in the first control point.
A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy t...
void DrawLineDashed(const VECTOR2I &aStart, const VECTOR2I &aEn, int aDashStep, int aDashFill, bool aDeEmphasised)
Draw a dashed line 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:66
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:202
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition view.cpp:467
EDA_UNITS
Definition eda_units.h:48
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:279
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const wxArrayString &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695