KiCad PCB EDA Suite
gbr_layout.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) 2012-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <gerbview_frame.h>
26 #include <gbr_layout.h>
27 #include <gerber_file_image.h>
28 #include <gerber_file_image_list.h>
29 
31  EDA_ITEM( nullptr, GERBER_LAYOUT_T )
32 {
33 }
34 
35 
37 {
38 }
39 
40 // Accessor to the list of Gerber files (and drill files) images
42 {
44 }
45 
46 
48 {
49  EDA_RECT bbox;
50  bool first_item = true;
51 
52  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
53  {
54  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
55 
56  if( gerber == nullptr ) // Graphic layer not yet used
57  continue;
58 
59  for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
60  {
61  if( first_item )
62  {
63  bbox = item->GetBoundingBox();
64  first_item = false;
65  }
66  else
67  bbox.Merge( item->GetBoundingBox() );
68  }
69  }
70 
71  bbox.Normalize();
72 
73  m_BoundingBox = bbox;
74  return bbox;
75 }
76 
77 
78 SEARCH_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
79 {
80  KICAD_T stype;
82  const KICAD_T* p = scanTypes;
83  bool done = false;
84 
85 #if 0 && defined(DEBUG)
86  std::cout << GetClass().mb_str() << ' ';
87 #endif
88 
89  while( !done )
90  {
91  stype = *p;
92 
93  switch( stype )
94  {
95  case GERBER_LAYOUT_T:
96  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
97  {
98  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
99 
100  if( gerber == nullptr ) // Graphic layer not yet used
101  continue;
102 
103  result = gerber->Visit( inspector, testData, p );
104 
105  if( result == SEARCH_RESULT::QUIT )
106  break;
107  }
108 
109  ++p;
110  break;
111 
112  default: // catch EOT or ANY OTHER type here and return.
113  done = true;
114  break;
115  }
116 
117  if( result == SEARCH_RESULT::QUIT )
118  break;
119  }
120 
121  return result;
122 }
Class CLASS_GBR_LAYOUT to handle info to draw loaded Gerber images and page frame reference.
wxString GetClass() const override
Return the class name.
Definition: gbr_layout.h:51
EDA_RECT m_BoundingBox
Definition: gbr_layout.h:88
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
GERBER_DRAW_ITEMS & GetItems()
Hold the image data and parameters for one gerber file and layer parameters.
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
static GERBER_FILE_IMAGE_LIST & GetImagesList()
EDA_RECT ComputeBoundingBox() const
Calculate the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:47
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
Handle the component boundary box.
Definition: eda_rect.h:42
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:41
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: gbr_layout.cpp:78
SEARCH_RESULT
Definition: eda_item.h:41