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.

259 lines
7.2 KiB

Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.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. #include <pybind11/pybind11.h>
  26. #include <wx/debug.h>
  27. #include <wx/msgdlg.h>
  28. #include <i18n_utility.h>
  29. #include <macros.h>
  30. #include <board.h>
  31. #include <board_design_settings.h>
  32. #include <pcb_group.h>
  33. const BOARD* BOARD_ITEM::GetBoard() const
  34. {
  35. if( Type() == PCB_T )
  36. return static_cast<const BOARD*>( this );
  37. BOARD_ITEM* parent = GetParent();
  38. if( parent )
  39. return parent->GetBoard();
  40. return nullptr;
  41. }
  42. BOARD* BOARD_ITEM::GetBoard()
  43. {
  44. if( Type() == PCB_T )
  45. return static_cast<BOARD*>( this );
  46. BOARD_ITEM* parent = GetParent();
  47. if( parent )
  48. return parent->GetBoard();
  49. return nullptr;
  50. }
  51. bool BOARD_ITEM::IsLocked() const
  52. {
  53. if( GetParentGroup() )
  54. return GetParentGroup()->IsLocked();
  55. const BOARD* board = GetBoard();
  56. return board && board->GetBoardUse() != BOARD_USE::FPHOLDER && m_isLocked;
  57. }
  58. STROKE_PARAMS BOARD_ITEM::GetStroke() const
  59. {
  60. wxCHECK( false, STROKE_PARAMS( Millimeter2iu( DEFAULT_LINE_WIDTH ) ) );
  61. }
  62. void BOARD_ITEM::SetStroke( const STROKE_PARAMS& aStroke )
  63. {
  64. wxCHECK( false, /* void */ );
  65. }
  66. wxString BOARD_ITEM::GetLayerName() const
  67. {
  68. const BOARD* board = GetBoard();
  69. if( board )
  70. return board->GetLayerName( m_layer );
  71. // If no parent, return standard name
  72. return BOARD::GetStandardLayerName( m_layer );
  73. }
  74. wxString BOARD_ITEM::layerMaskDescribe() const
  75. {
  76. const BOARD* board = GetBoard();
  77. LSET layers = GetLayerSet();
  78. // Try to be smart and useful. Check all copper first.
  79. if( layers[F_Cu] && layers[B_Cu] )
  80. return _( "all copper layers" );
  81. LSET copperLayers = layers & board->GetEnabledLayers().AllCuMask();
  82. LSET techLayers = layers & board->GetEnabledLayers().AllTechMask();
  83. for( LSET testLayers : { copperLayers, techLayers, layers } )
  84. {
  85. for( int bit = PCBNEW_LAYER_ID_START; bit < PCB_LAYER_ID_COUNT; ++bit )
  86. {
  87. if( testLayers[ bit ] )
  88. {
  89. wxString layerInfo = board->GetLayerName( static_cast<PCB_LAYER_ID>( bit ) );
  90. if( testLayers.count() > 1 )
  91. layerInfo << wxS( " " ) + _( "and others" );
  92. return layerInfo;
  93. }
  94. }
  95. }
  96. // No copper, no technicals: no layer
  97. return _( "no layers" );
  98. }
  99. void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  100. {
  101. // Basic fallback
  102. aCount = 1;
  103. aLayers[0] = m_layer;
  104. if( IsLocked() )
  105. aLayers[aCount++] = LAYER_LOCKED_ITEM_SHADOW;
  106. }
  107. void BOARD_ITEM::DeleteStructure()
  108. {
  109. BOARD_ITEM_CONTAINER* parent = GetParent();
  110. if( parent )
  111. parent->Remove( this );
  112. delete this;
  113. }
  114. void BOARD_ITEM::SwapData( BOARD_ITEM* aImage )
  115. {
  116. }
  117. BOARD_ITEM* BOARD_ITEM::Duplicate() const
  118. {
  119. BOARD_ITEM* dupe = static_cast<BOARD_ITEM*>( Clone() );
  120. const_cast<KIID&>( dupe->m_Uuid ) = KIID();
  121. if( dupe->GetParentGroup() )
  122. dupe->GetParentGroup()->AddItem( dupe );
  123. return static_cast<BOARD_ITEM*>( dupe );
  124. }
  125. void BOARD_ITEM::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  126. PCB_LAYER_ID aLayer, int aClearanceValue,
  127. int aError, ERROR_LOC aErrorLoc,
  128. bool ignoreLineWidth ) const
  129. {
  130. wxASSERT_MSG( false, wxT( "Called TransformShapeWithClearanceToPolygon() on unsupported "
  131. "BOARD_ITEM." ) );
  132. };
  133. bool BOARD_ITEM::ptr_cmp::operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const
  134. {
  135. if( a->Type() != b->Type() )
  136. return a->Type() < b->Type();
  137. if( a->GetLayerSet() != b->GetLayerSet() )
  138. return a->GetLayerSet().Seq() < b->GetLayerSet().Seq();
  139. if( a->m_Uuid != b->m_Uuid ) // UUIDs *should* always be unique (for valid boards anyway)
  140. return a->m_Uuid < b->m_Uuid;
  141. return a < b; // But just in case; ptrs are guaranteed to be different
  142. }
  143. std::shared_ptr<SHAPE> BOARD_ITEM::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
  144. {
  145. std::shared_ptr<SHAPE> shape;
  146. UNIMPLEMENTED_FOR( GetClass() );
  147. return shape;
  148. }
  149. BOARD_ITEM_CONTAINER* BOARD_ITEM::GetParentFootprint() const
  150. {
  151. BOARD_ITEM_CONTAINER* ancestor = GetParent();
  152. while( ancestor && ancestor->Type() == PCB_GROUP_T )
  153. ancestor = ancestor->GetParent();
  154. return ( ancestor && ancestor->Type() == PCB_FOOTPRINT_T ) ? ancestor : nullptr;
  155. }
  156. void BOARD_ITEM::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  157. {
  158. wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
  159. }
  160. void BOARD_ITEM::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  161. {
  162. wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
  163. }
  164. static struct BOARD_ITEM_DESC
  165. {
  166. BOARD_ITEM_DESC()
  167. {
  168. ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
  169. if( layerEnum.Choices().GetCount() == 0 )
  170. {
  171. layerEnum.Undefined( UNDEFINED_LAYER );
  172. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  173. layerEnum.Map( *seq, LSET::Name( *seq ) );
  174. }
  175. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  176. REGISTER_TYPE( BOARD_ITEM );
  177. propMgr.InheritsAfter( TYPE_HASH( BOARD_ITEM ), TYPE_HASH( EDA_ITEM ) );
  178. propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _HKI( "Position X" ),
  179. &BOARD_ITEM::SetX, &BOARD_ITEM::GetX, PROPERTY_DISPLAY::DISTANCE ) );
  180. propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _HKI( "Position Y" ),
  181. &BOARD_ITEM::SetY, &BOARD_ITEM::GetY, PROPERTY_DISPLAY::DISTANCE ) );
  182. propMgr.AddProperty( new PROPERTY_ENUM<BOARD_ITEM, PCB_LAYER_ID>( _HKI( "Layer" ),
  183. &BOARD_ITEM::SetLayer, &BOARD_ITEM::GetLayer ) );
  184. propMgr.AddProperty( new PROPERTY<BOARD_ITEM, bool>( _HKI( "Locked" ),
  185. &BOARD_ITEM::SetLocked, &BOARD_ITEM::IsLocked ) );
  186. }
  187. } _BOARD_ITEM_DESC;
  188. IMPLEMENT_ENUM_TO_WXANY( PCB_LAYER_ID )