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 <track.h>
38 
39 
40 void process( const BOARD_CONNECTED_ITEM* item, int net )
41 {
42  if( item->GetNetCode() != net )
43  return;
44 
45  SHAPE_POLY_SET pset;
46 
47  item->TransformShapeWithClearanceToPolygon( pset, UNDEFINED_LAYER, 1, ARC_HIGH_DEF,
48  ERROR_OUTSIDE );
49 
50  SHAPE_FILE_IO shapeIo; // default = stdout
51  shapeIo.Write( &pset );
52 }
53 
54 
56 {
58 };
59 
60 
61 int 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( 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 } );
Tools can define their own statuses from here onwards.
SHAPE_FILE_IO.
Definition: shape_file_io.h:39
int GetNetCode() const
Function GetNetCode.
POLY_GEN_RET_CODES
#define OK
The command line was not correct for the tool.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
SHAPE_POLY_SET.
int polygon_gererator_main(int argc, char *argv[])
static bool registered
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
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
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
Definition: board_item.cpp:129
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:59
Definition: track.h:83