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 (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 const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
39 EDA_ITEM( NOT_USED ), m_constructMan( aManager ), m_iuScale( aIuScale ), m_units( aUnits )
40{
41}
42
43
45{
46 BOX2I tmp;
47
48 // no bounding box when no graphic shown
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
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
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 {
86 // Draw the second control point control line as a double length line
87 // centred on the end point
89 dashSize, dashSize / 2, false );
90 }
91
92 std::vector<wxString> cursorStrings;
93
95 {
96 // Going to need a better way to get a length here
97 // const int length = m_constructMan.GetBezierLength();
98 // Have enough points to report a bezier length
99 // cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "L" ), 12300000,
100 // m_iuScale, m_units ) );
101 }
102
103 if( !cursorStrings.empty() )
104 {
105 // place the text next to cursor, on opposite side from radius
107 start - m_constructMan.GetLastPoint(), cursorStrings,
108 aLayer == LAYER_SELECT_OVERLAY );
109 }
110}
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
constexpr void SetMaximum()
Definition: box2.h:80
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.
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.
VECTOR2I GetControlC2() const
Get the coordinates of the arc end point.
VECTOR2I GetStart() const
< Get the center point of the arc (valid when state > SET_ORIGIN)
@ 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.
BEZIER_STEPS GetStep() const
Get the current step the manager is on (useful when drawing something depends on the current state)
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 DrawLineDashed(const VECTOR2I &aStart, const VECTOR2I &aEn, int aDashStep, int aDashFill, bool aDeEmphasised)
Draw a dashed line 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
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:484
EDA_UNITS
Definition: eda_units.h:46
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:221
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const std::vector< wxString > &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79