KiCad PCB EDA Suite
Loading...
Searching...
No Matches
line_ending.h
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
24#pragma once
25
26#include <math/vector2d.h>
27#include <geometry/eda_angle.h>
28#include <stroke_params.h>
29#include <wx/string.h>
30
31class OUTPUTFORMATTER;
32class PLOTTER;
33struct EDA_IU_SCALE;
34
35namespace KIGFX
36{
37class GAL;
39
51
52
62{
63public:
71
72 LINE_ENDING( LINE_ENDING_STYLE aStyle, int aLength = 0, int aWidth = 0,
73 int aStrokeWidth = 0 ) :
74 m_style( aStyle ),
75 m_length( aLength ),
76 m_width( aWidth ),
78 {
79 }
80
82 void SetStyle( LINE_ENDING_STYLE aStyle ) { m_style = aStyle; }
83
84 int GetLength() const { return m_length; }
85 void SetLength( int aLength ) { m_length = aLength; }
86
87 int GetWidth() const { return m_width; }
88 void SetWidth( int aWidth ) { m_width = aWidth; }
89
90 void SetUniformSize( int aSize )
91 {
92 m_length = aSize;
93 m_width = aSize;
94 }
95
100 int GetStrokeWidth() const { return m_stroke.GetWidth(); }
101 void SetStrokeWidth( int aWidth ) { m_stroke.SetWidth( aWidth ); }
102
103 const STROKE_PARAMS& GetStroke() const { return m_stroke; }
104 void SetStroke( const STROKE_PARAMS& aStroke ) { m_stroke = aStroke; }
105
110 VECTOR2I GetEffectiveSize( int aLineWidth ) const;
111
117 int GetShortenDepth( int aLineWidth ) const;
118
126 int GetCurveOrientationDepth( int aLineWidth ) const;
127
134 void GetShapes( const VECTOR2I& aPoint, const EDA_ANGLE& aTangent,
135 int aLineWidth, std::vector<VECTOR2I>& aPolygon ) const;
136
137 bool operator==( const LINE_ENDING& aOther ) const;
138 bool operator!=( const LINE_ENDING& aOther ) const { return !( *this == aOther ); }
139
140 void Draw( KIGFX::GAL& aGal, const VECTOR2I& aPoint, const EDA_ANGLE& aTangent,
141 double aLineWidth, const KIGFX::COLOR4D& aColor ) const;
142
143 void Plot( PLOTTER* aPlotter, const VECTOR2I& aPoint, const EDA_ANGLE& aTangent,
144 int aLineWidth, void* aData = nullptr ) const;
145
146 void Format( OUTPUTFORMATTER* aOut, const EDA_IU_SCALE& aIuScale,
147 const char* aToken ) const;
148
149 static wxString StyleToToken( LINE_ENDING_STYLE aStyle );
150 static LINE_ENDING_STYLE TokenToStyle( const wxString& aToken );
151
152 static constexpr double DEFAULT_RATIO_LENGTH = 5.0;
153 static constexpr double DEFAULT_RATIO_WIDTH = 5.0;
154
160 static const int s_defaultChoiceCount;
161
165 static int StyleToChoiceIndex( LINE_ENDING_STYLE aStyle );
166
167private:
172};
Represent basic circle geometry with utility geometry functions.
Definition circle.h:33
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Abstract interface for drawing on a 2D-surface.
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
Definition line_ending.h:62
int GetLength() const
Along-line size. 0 = auto.
Definition line_ending.h:84
const STROKE_PARAMS & GetStroke() const
static constexpr double DEFAULT_RATIO_LENGTH
int GetWidth() const
Perpendicular size. 0 = auto.
Definition line_ending.h:87
int GetShortenDepth(int aLineWidth) const
Return how far the line should be shortened at this ending.
bool operator==(const LINE_ENDING &aOther) const
void SetStroke(const STROKE_PARAMS &aStroke)
void Draw(KIGFX::GAL &aGal, const VECTOR2I &aPoint, const EDA_ANGLE &aTangent, double aLineWidth, const KIGFX::COLOR4D &aColor) const
static wxString StyleToToken(LINE_ENDING_STYLE aStyle)
void SetLength(int aLength)
Definition line_ending.h:85
void SetUniformSize(int aSize)
Definition line_ending.h:90
void SetStyle(LINE_ENDING_STYLE aStyle)
Definition line_ending.h:82
int GetCurveOrientationDepth(int aLineWidth) const
Return how far along a curved body to look when orienting this ending.
void SetWidth(int aWidth)
Definition line_ending.h:88
LINE_ENDING_STYLE m_style
static const int s_defaultChoiceCount
VECTOR2I GetEffectiveSize(int aLineWidth) const
Return the rendered size per axis, applying auto-sizing when length or width is 0.
static constexpr double DEFAULT_RATIO_WIDTH
void SetStrokeWidth(int aWidth)
static LINE_ENDING_STYLE TokenToStyle(const wxString &aToken)
int m_length
Along-line axis. 0 = auto (ratio * line width).
LINE_ENDING_STYLE GetStyle() const
Definition line_ending.h:81
void GetShapes(const VECTOR2I &aPoint, const EDA_ANGLE &aTangent, int aLineWidth, std::vector< VECTOR2I > &aPolygon) const
Generate ending geometry as polygon vertices at the given point and direction.
bool operator!=(const LINE_ENDING &aOther) const
static const LINE_ENDING_STYLE s_defaultChoiceOrder[]
Dropdown display order for line ending style choosers.
Definition line_ending.h:38
STROKE_PARAMS m_stroke
static int StyleToChoiceIndex(LINE_ENDING_STYLE aStyle)
Return the dropdown index for the given style, or 0 (NONE) if not found.
void Plot(PLOTTER *aPlotter, const VECTOR2I &aPoint, const EDA_ANGLE &aTangent, int aLineWidth, void *aData=nullptr) const
int m_width
Perpendicular axis. 0 = auto.
int GetStrokeWidth() const
Outline stroke width.
LINE_ENDING(LINE_ENDING_STYLE aStyle, int aLength=0, int aWidth=0, int aStrokeWidth=0)
Definition line_ending.h:72
void Format(OUTPUTFORMATTER *aOut, const EDA_IU_SCALE &aIuScale, const char *aToken) const
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
Base plotter engine class.
Definition plotter.h:136
Simple container to manage line stroke parameters.
@ NONE
Definition eda_fill.h:42
LINE_ENDING_STYLE
Line ending styles for graphic lines, arcs, and beziers.
Definition line_ending.h:44
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
LINE_STYLE
Dashed line types.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683