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 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 <class_board.h>
35 #include <class_drawsegment.h>
36 #include <class_module.h>
37 #include <class_pad.h>
38 #include <class_track.h>
39 #include <class_zone.h>
40 
41 
42 void process( const BOARD_CONNECTED_ITEM* item, int net )
43 {
44  if( item->GetNetCode() != net )
45  return;
46 
47  SHAPE_POLY_SET pset;
48 
49  item->TransformShapeWithClearanceToPolygon( pset, 1, ARC_HIGH_DEF );
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 )
65  {
66  printf( "A sample tool for dumping board geometry as a set of polygons.\n" );
67  printf( "Usage : %s board_file.kicad_pcb\n\n", argv[0] );
69  }
70 
71  std::string filename;
72 
73  if( argc > 1 )
74  filename = argv[1];
75 
76  auto brd = KI_TEST::ReadBoardFromFileOrStream( filename );
77 
78  if( !brd )
79  {
81  }
82 
83  for( unsigned net = 0; net < brd->GetNetCount(); net++ )
84  {
85  printf( "net %d\n", net );
86 
87  for( auto track : brd->Tracks() )
88  process( track, net );
89 
90  for( auto mod : brd->Modules() )
91  {
92  for( auto pad : mod->Pads() )
93  process( pad, net );
94  }
95 
96  for( auto zone : brd->Zones() )
97  process( zone, net );
98 
99  printf( "endnet\n" );
100  }
101 
102  return KI_TEST::RET_CODES::OK;
103 }
104 
105 
107  "polygon_generator",
108  "Dump board geometry as a set of polygons",
110 } );
Tools can define their own statuses from here onwards.
SHAPE_FILE_IO.
Definition: shape_file_io.h:39
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError=ARC_LOW_DEF, bool ignoreLineWidth=false) const
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
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...
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
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
Pad object description.
void Write(const SHAPE *aShape, const std::string &aName="<noname>")
Class to handle a graphic segment.
void process(const BOARD_CONNECTED_ITEM *item, int net)
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.