You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.4 KiB

  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. #include <fctsys.h>
  25. #include <gr_basic.h>
  26. #include <gr_text.h>
  27. #include <gerbview_frame.h>
  28. #include <gbr_layout.h>
  29. #include <gerber_file_image.h>
  30. #include <gerber_file_image_list.h>
  31. GBR_LAYOUT::GBR_LAYOUT() :
  32. EDA_ITEM( (EDA_ITEM*)NULL, GERBER_LAYOUT_T )
  33. {
  34. }
  35. GBR_LAYOUT::~GBR_LAYOUT()
  36. {
  37. }
  38. // Accessor to the list of gerber files (and drill files) images
  39. GERBER_FILE_IMAGE_LIST* GBR_LAYOUT::GetImagesList() const
  40. {
  41. return &GERBER_FILE_IMAGE_LIST::GetImagesList();
  42. }
  43. EDA_RECT GBR_LAYOUT::ComputeBoundingBox() const
  44. {
  45. EDA_RECT bbox;
  46. bool first_item = true;
  47. for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
  48. {
  49. GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
  50. if( gerber == NULL ) // Graphic layer not yet used
  51. continue;
  52. for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
  53. {
  54. if( first_item )
  55. {
  56. bbox = item->GetBoundingBox();
  57. first_item = false;
  58. }
  59. else
  60. bbox.Merge( item->GetBoundingBox() );
  61. }
  62. }
  63. bbox.Normalize();
  64. m_BoundingBox = bbox;
  65. return bbox;
  66. }
  67. SEARCH_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
  68. {
  69. KICAD_T stype;
  70. SEARCH_RESULT result = SEARCH_CONTINUE;
  71. const KICAD_T* p = scanTypes;
  72. bool done = false;
  73. #if 0 && defined(DEBUG)
  74. std::cout << GetClass().mb_str() << ' ';
  75. #endif
  76. while( !done )
  77. {
  78. stype = *p;
  79. switch( stype )
  80. {
  81. case GERBER_IMAGE_LIST_T:
  82. for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
  83. {
  84. GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
  85. if( gerber == NULL ) // Graphic layer not yet used
  86. continue;
  87. result = gerber->Visit( inspector, testData, p );
  88. if( result == SEARCH_QUIT )
  89. break;
  90. }
  91. ++p;
  92. break;
  93. default: // catch EOT or ANY OTHER type here and return.
  94. done = true;
  95. break;
  96. }
  97. if( result == SEARCH_QUIT )
  98. break;
  99. }
  100. return result;
  101. }