KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_tool_utils.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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <pcb_shape.h>
24#include <pcb_track.h>
25
26std::optional<int> GetBoardItemWidth( const BOARD_ITEM& aItem )
27{
28 switch( aItem.Type() )
29 {
30 case PCB_SHAPE_T:
31 {
32 const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
33
34 if( shape.GetShape() == SHAPE_T::SEGMENT )
35 return shape.GetWidth();
36
37 if( shape.GetWidth() && !shape.IsSolidFill() )
38 return shape.GetWidth();
39
40 break;
41 }
42
43 case PCB_TRACE_T:
44 case PCB_ARC_T:
45 {
46 const PCB_TRACK& track = static_cast<const PCB_TRACK&>( aItem );
47 return track.GetWidth();
48 }
49
50 default:
51 break;
52 }
53
54 return std::nullopt;
55}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
SHAPE_T GetShape() const
Definition eda_shape.h:185
bool IsSolidFill() const
Definition eda_shape.h:133
int GetWidth() const override
virtual int GetWidth() const
Definition pcb_track.h:87
@ SEGMENT
Definition eda_shape.h:46
std::optional< int > GetBoardItemWidth(const BOARD_ITEM &aItem)
Gets the width of a BOARD_ITEM, for items that have a meaningful width.
Utility functions that can be shared by PCB tools.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89