KiCad PCB EDA Suite
polygon_generator.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 CERN
5 * @author Tomasz Wlostowski <[email protected]>
6 * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.TXT for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
29
31
33
34#include <board.h>
35#include <footprint.h>
36#include <pad.h>
37#include <pcb_track.h>
38#include <zone.h>
39
40
41void process( const BOARD_CONNECTED_ITEM* item, int net )
42{
43 if( item->GetNetCode() != net )
44 return;
45
46 SHAPE_POLY_SET pset;
47
49
50 SHAPE_FILE_IO shapeIo; // default = stdout
51 shapeIo.Write( &pset );
52}
53
54
56{
58};
59
60
61int polygon_gererator_main( int argc, char* argv[] )
62{
63 if( argc < 2 )
65
66 std::string filename;
67
68 if( argc > 1 )
69 filename = argv[1];
70
71 auto brd = KI_TEST::ReadBoardFromFileOrStream( filename );
72
73 if( !brd )
75
76 for( unsigned net = 0; net < brd->GetNetCount(); net++ )
77 {
78 for( PCB_TRACK* track : brd->Tracks() )
79 process( track, net );
80
81 for( FOOTPRINT* fp : brd->Footprints() )
82 {
83 for( PAD* pad : fp->Pads() )
84 process( pad, net );
85 }
86
87 for( ZONE* zone : brd->Zones() )
88 process( zone, net );
89 }
90
92}
93
94
96 "polygon_generator",
97 "Dump board geometry as a set of polygons",
99} );
constexpr int ARC_HIGH_DEF
Definition: base_units.h:121
General utilities for PCB file IO for QA programs.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:196
Definition: pad.h:59
Helper class for saving/loading shapes from a file.
Definition: shape_file_io.h:40
void Write(const SHAPE *aShape, const std::string &aName="<noname>")
Represent a set of closed polygons.
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
#define OK
@ ERROR_OUTSIDE
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
@ TOOL_SPECIFIC
Tools can define their own statuses from here onwards.
@ BAD_CMDLINE
The command line was not correct for the tool.
static bool registered
int polygon_gererator_main(int argc, char *argv[])
void process(const BOARD_CONNECTED_ITEM *item, int net)
POLY_GEN_RET_CODES
@ LOAD_FAILED