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 <tomasz.wlostowski@cern.ch>
6  * Copyright (C) 2019-2020 KiCad Developers, see CHANGELOG.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 
26 #include <geometry/shape_file_io.h>
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 
41 void process( const BOARD_CONNECTED_ITEM* item, int net )
42 {
43  if( item->GetNetCode() != net )
44  return;
45 
46  SHAPE_POLY_SET pset;
47 
48  item->TransformShapeWithClearanceToPolygon( pset, UNDEFINED_LAYER, 1, ARC_HIGH_DEF,
49  ERROR_OUTSIDE );
50 
51  SHAPE_FILE_IO shapeIo; // default = stdout
52  shapeIo.Write( &pset );
53 }
54 
55 
57 {
59 };
60 
61 
62 int polygon_gererator_main( int argc, char* argv[] )
63 {
64  if( argc < 2 )
66 
67  std::string filename;
68 
69  if( argc > 1 )
70  filename = argv[1];
71 
72  auto brd = KI_TEST::ReadBoardFromFileOrStream( filename );
73 
74  if( !brd )
76 
77  for( unsigned net = 0; net < brd->GetNetCount(); net++ )
78  {
79  for( PCB_TRACK* track : brd->Tracks() )
80  process( track, net );
81 
82  for( FOOTPRINT* fp : brd->Footprints() )
83  {
84  for( PAD* pad : fp->Pads() )
85  process( pad, net );
86  }
87 
88  for( ZONE* zone : brd->Zones() )
89  process( zone, net );
90  }
91 
93 }
94 
95 
97  "polygon_generator",
98  "Dump board geometry as a set of polygons",
100 } );
Tools can define their own statuses from here onwards.
Helper class for saving/loading shapes from a file.
Definition: shape_file_io.h:39
POLY_GEN_RET_CODES
#define OK
The command line was not correct for the tool.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
Represent a set of closed polygons.
int polygon_gererator_main(int argc, char *argv[])
static bool registered
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void Write(const SHAPE *aShape, const std::string &aName="<noname>")
void process(const BOARD_CONNECTED_ITEM *item, int net)
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:156
General utilities for PCB file IO for QA programs.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
Definition: pad.h:57