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.

314 lines
8.9 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 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) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file tracepcb.cpp
  28. * @brief Functions to redraw the current board.
  29. */
  30. #include <fctsys.h>
  31. #include <class_drawpanel.h>
  32. #include <wxPcbStruct.h>
  33. #include <base_units.h>
  34. #include <class_board.h>
  35. #include <class_module.h>
  36. #include <class_track.h>
  37. #include <class_zone.h>
  38. #include <class_marker_pcb.h>
  39. #include <pcbnew.h>
  40. #include <module_editor_frame.h>
  41. #include <pcbplot.h>
  42. #include <wx/overlay.h>
  43. // Local functions:
  44. /* Trace the pads of a module in sketch mode.
  45. * Used to display pads when when the module visibility is set to not visible
  46. * and we want to see pad through.
  47. * The pads must appear on the layers selected in LayerMask
  48. */
  49. static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module,
  50. int ox, int oy, LSET LayerMask, GR_DRAWMODE draw_mode );
  51. void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  52. {
  53. PCB_SCREEN* screen = GetScreen();
  54. if( !GetBoard() || !screen )
  55. return;
  56. GRSetDrawMode( DC, GR_COPY );
  57. m_canvas->DrawBackGround( DC );
  58. DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString );
  59. // Redraw the footprints
  60. for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
  61. module->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST );
  62. #ifdef USE_WX_OVERLAY
  63. if( IsShown() )
  64. {
  65. m_overlay.Reset();
  66. wxDCOverlay overlaydc( m_overlay, (wxWindowDC*) DC );
  67. overlaydc.Clear();
  68. }
  69. #endif
  70. if( m_canvas->IsMouseCaptured() )
  71. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  72. // Redraw the cursor
  73. m_canvas->DrawCrossHair( DC );
  74. }
  75. /* Draw the BOARD, and others elements : axis, grid ..
  76. */
  77. void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  78. {
  79. PCB_SCREEN* screen = GetScreen();
  80. if( !GetBoard() || !screen )
  81. return;
  82. GRSetDrawMode( DC, GR_COPY );
  83. m_canvas->DrawBackGround( DC );
  84. DrawWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness,
  85. IU_PER_MILS, GetBoard()->GetFileName() );
  86. GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST );
  87. DrawGeneralRatsnest( DC );
  88. #ifdef USE_WX_OVERLAY
  89. if( IsShown() )
  90. {
  91. m_overlay.Reset();
  92. wxDCOverlay overlaydc( m_overlay, (wxWindowDC*) DC );
  93. overlaydc.Clear();
  94. }
  95. #endif
  96. if( m_canvas->IsMouseCaptured() )
  97. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  98. // Redraw the cursor
  99. m_canvas->DrawCrossHair( DC );
  100. }
  101. // Redraw the BOARD items but not cursors, axis or grid
  102. void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
  103. {
  104. /* The order of drawing is flexible on some systems and not on others. For
  105. * OSes which use OR to draw, the order is not important except for the
  106. * effect of the highlight and its relationship to markers. See comment
  107. * below.
  108. * This order independence comes from the fact that a binary OR operation is
  109. * commutative in nature.
  110. * However on the OSX, the OR operation is not used, and so this sequence
  111. * below is chosen to give MODULEs the highest visible priority.
  112. */
  113. /* Draw all tracks and zones. As long as dark colors are used for the
  114. * tracks, Then the OR draw mode should show tracks underneath other
  115. * tracks. But a white track will cover any other color since it has
  116. * more bits to OR in.
  117. */
  118. for( TRACK* track = m_Track; track; track = track->Next() )
  119. {
  120. if( track->IsMoving() )
  121. continue;
  122. track->Draw( aPanel, DC, aDrawMode );
  123. }
  124. // SEGZONE is outdated, only her for compatibility with
  125. // very old designs
  126. for( SEGZONE* zone = m_Zone; zone; zone = zone->Next() )
  127. {
  128. if( zone->IsMoving() )
  129. continue;
  130. zone->Draw( aPanel, DC, aDrawMode );
  131. }
  132. // Draw the graphic items
  133. for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
  134. {
  135. if( item->IsMoving() )
  136. continue;
  137. switch( item->Type() )
  138. {
  139. case PCB_DIMENSION_T:
  140. case PCB_TEXT_T:
  141. case PCB_TARGET_T:
  142. case PCB_LINE_T:
  143. item->Draw( aPanel, DC, aDrawMode );
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149. // Draw areas (i.e. zones)
  150. for( int ii = 0; ii < GetAreaCount(); ii++ )
  151. {
  152. ZONE_CONTAINER* zone = GetArea( ii );
  153. // Areas must be drawn here only if not moved or dragged,
  154. // because these areas are drawn by ManageCursor() in a specific manner
  155. if( ( zone->GetFlags() & (IN_EDIT | IS_DRAGGED | IS_MOVED) ) == 0 )
  156. {
  157. zone->Draw( aPanel, DC, aDrawMode );
  158. zone->DrawFilledArea( aPanel, DC, aDrawMode );
  159. }
  160. }
  161. LSET all_cu = LSET::AllCuMask();
  162. for( MODULE* module = m_Modules; module; module = module->Next() )
  163. {
  164. bool display = true;
  165. LSET layerMask = all_cu;
  166. if( module->IsMoving() )
  167. continue;
  168. if( !IsElementVisible( PCB_VISIBLE( MOD_FR_VISIBLE ) ) )
  169. {
  170. if( module->GetLayer() == F_Cu )
  171. display = false;
  172. layerMask.set( F_Cu, false );
  173. }
  174. if( !IsElementVisible( PCB_VISIBLE( MOD_BK_VISIBLE ) ) )
  175. {
  176. if( module->GetLayer() == B_Cu )
  177. display = false;
  178. layerMask.set( B_Cu, false );
  179. }
  180. if( display )
  181. module->Draw( aPanel, DC, aDrawMode );
  182. else
  183. Trace_Pads_Only( aPanel, DC, module, 0, 0, layerMask, aDrawMode );
  184. }
  185. if( IsHighLightNetON() )
  186. DrawHighLight( aPanel, DC, GetHighLightNetCode() );
  187. // draw the BOARD's markers last, otherwise the high light will erase any marker on a pad
  188. for( unsigned i = 0; i < m_markers.size(); ++i )
  189. {
  190. m_markers[i]->Draw( aPanel, DC, aDrawMode );
  191. }
  192. }
  193. void BOARD::DrawHighLight( EDA_DRAW_PANEL* am_canvas, wxDC* DC, int aNetCode )
  194. {
  195. GR_DRAWMODE draw_mode;
  196. if( IsHighLightNetON() )
  197. draw_mode = GR_HIGHLIGHT | GR_OR;
  198. else
  199. draw_mode = GR_AND | GR_HIGHLIGHT;
  200. // Redraw zones
  201. for( int ii = 0; ii < GetAreaCount(); ii++ )
  202. {
  203. ZONE_CONTAINER* zone = GetArea( ii );
  204. if( zone->GetNetCode() == aNetCode )
  205. {
  206. zone->Draw( am_canvas, DC, draw_mode );
  207. }
  208. }
  209. // Redraw any pads that have aNetCode
  210. for( MODULE* module = m_Modules; module; module = module->Next() )
  211. {
  212. for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
  213. {
  214. if( pad->GetNetCode() == aNetCode )
  215. {
  216. pad->Draw( am_canvas, DC, draw_mode );
  217. }
  218. }
  219. }
  220. // Redraw track and vias that have aNetCode
  221. for( TRACK* seg = m_Track; seg; seg = seg->Next() )
  222. {
  223. if( seg->GetNetCode() == aNetCode )
  224. {
  225. seg->Draw( am_canvas, DC, draw_mode );
  226. }
  227. }
  228. }
  229. /* Trace the pads of a module in sketch mode.
  230. * Used to display pads when when the module visibility is set to not visible
  231. * and we want to see pad through.
  232. * The pads must appear on the layers selected in LayerMask
  233. */
  234. static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* aModule,
  235. int ox, int oy, LSET aLayerMask, GR_DRAWMODE draw_mode )
  236. {
  237. DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
  238. int tmp = displ_opts->m_DisplayPadFill;
  239. displ_opts->m_DisplayPadFill = false;
  240. // Draw pads.
  241. for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
  242. {
  243. if( (pad->GetLayerSet() & aLayerMask) == 0 )
  244. continue;
  245. pad->Draw( panel, DC, draw_mode, wxPoint( ox, oy ) );
  246. }
  247. displ_opts->m_DisplayPadFill = tmp;
  248. }