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-2018 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 <fctsys.h>
26 #include <gr_basic.h>
27 #include <gr_text.h>
28 #include <gerbview_frame.h>
29 #include <gbr_layout.h>
30 #include <gerber_file_image.h>
31 #include <gerber_file_image_list.h>
32 
35 {
36 }
37 
38 
40 {
41 }
42 
43 // Accessor to the list of gerber files (and drill files) images
45 {
47 }
48 
49 
51 {
52  EDA_RECT bbox;
53  bool first_item = true;
54 
55  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
56  {
57  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
58 
59  if( gerber == NULL ) // Graphic layer not yet used
60  continue;
61 
62  for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
63  {
64  if( first_item )
65  {
66  bbox = item->GetBoundingBox();
67  first_item = false;
68  }
69  else
70  bbox.Merge( item->GetBoundingBox() );
71  }
72  }
73 
74  bbox.Normalize();
75 
76  m_BoundingBox = bbox;
77  return bbox;
78 }
79 
80 
81 SEARCH_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
82 {
83  KICAD_T stype;
85  const KICAD_T* p = scanTypes;
86  bool done = false;
87 
88 #if 0 && defined(DEBUG)
89  std::cout << GetClass().mb_str() << ' ';
90 #endif
91 
92  while( !done )
93  {
94  stype = *p;
95 
96  switch( stype )
97  {
99  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
100  {
101  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
102 
103  if( gerber == NULL ) // Graphic layer not yet used
104  continue;
105 
106  result = gerber->Visit( inspector, testData, p );
107 
108  if( result == SEARCH_QUIT )
109  break;
110  }
111 
112  ++p;
113  break;
114 
115  default: // catch EOT or ANY OTHER type here and return.
116  done = true;
117  break;
118  }
119 
120  if( result == SEARCH_QUIT )
121  break;
122  }
123 
124  return result;
125 }
Class CLASS_GBR_LAYOUT to handle info to draw loaded Gerber images and page frame reference.
wxString GetClass() const override
Function GetClass returns the class name.
Definition: gbr_layout.h:64
EDA_RECT m_BoundingBox
Definition: gbr_layout.h:56
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Class GERBER_FILE_IMAGE holds 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
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:108
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
static GERBER_FILE_IMAGE_LIST & GetImagesList()
EDA_RECT ComputeBoundingBox() const
Function ComputeBoundingBox calculates the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:50
void Normalize()
Function Normalize ensures that the height ant width are positive.
GERBER_DRAW_ITEM * Next() const
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Definition: gbr_layout.cpp:81
SEARCH_RESULT
Definition: base_struct.h:54