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.

981 lines
28 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
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) 1992-2012 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. /**
  26. * @file class_zone.cpp
  27. * @brief Implementation of class to handle copper zones.
  28. */
  29. #include <fctsys.h>
  30. #include <wxstruct.h>
  31. #include <trigo.h>
  32. #include <class_pcb_screen.h>
  33. #include <class_drawpanel.h>
  34. #include <kicad_string.h>
  35. #include <pcbcommon.h>
  36. #include <colors_selection.h>
  37. #include <richio.h>
  38. #include <macros.h>
  39. #include <wxBasePcbFrame.h>
  40. #include <msgpanel.h>
  41. #include <protos.h>
  42. #include <class_board.h>
  43. #include <class_zone.h>
  44. #include <pcbnew.h>
  45. #include <zones.h>
  46. #include <math_for_graphics.h>
  47. #include <polygon_test_point_inside.h>
  48. ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
  49. BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T )
  50. {
  51. SetNet( -1 ); // Net number for fast comparisons
  52. m_CornerSelection = -1;
  53. m_IsFilled = false; // fill status : true when the zone is filled
  54. m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments
  55. m_priority = 0;
  56. m_smoothedPoly = NULL;
  57. m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
  58. SetIsKeepout( false );
  59. SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
  60. SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
  61. SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
  62. m_cornerRadius = 0;
  63. SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
  64. m_Poly = new CPolyLine(); // Outlines
  65. aBoard->GetZoneSettings().ExportSetting( *this );
  66. }
  67. ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) :
  68. BOARD_CONNECTED_ITEM( aZone )
  69. {
  70. // Should the copy be on the same net?
  71. SetNet( aZone.GetNet() );
  72. m_Poly = new CPolyLine( *aZone.m_Poly );
  73. // For corner moving, corner index to drag, or -1 if no selection
  74. m_CornerSelection = -1;
  75. m_IsFilled = aZone.m_IsFilled;
  76. m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
  77. m_ZoneMinThickness = aZone.m_ZoneMinThickness;
  78. m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
  79. m_priority = aZone.m_priority;
  80. m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount;
  81. m_PadConnection = aZone.m_PadConnection;
  82. m_ThermalReliefGap = aZone.m_ThermalReliefGap;
  83. m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge;
  84. m_FilledPolysList = aZone.m_FilledPolysList;
  85. m_FillSegmList = aZone.m_FillSegmList;
  86. m_isKeepout = aZone.m_isKeepout;
  87. m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
  88. m_doNotAllowVias = aZone.m_doNotAllowVias;
  89. m_doNotAllowTracks = aZone.m_doNotAllowTracks;
  90. m_cornerSmoothingType = aZone.m_cornerSmoothingType;
  91. m_cornerRadius = aZone.m_cornerRadius;
  92. SetLocalFlags( aZone.GetLocalFlags() );
  93. }
  94. ZONE_CONTAINER::~ZONE_CONTAINER()
  95. {
  96. delete m_Poly;
  97. m_Poly = NULL;
  98. }
  99. EDA_ITEM* ZONE_CONTAINER::Clone() const
  100. {
  101. return new ZONE_CONTAINER( *this );
  102. }
  103. bool ZONE_CONTAINER::UnFill()
  104. {
  105. bool change = ( m_FilledPolysList.size() > 0 ) || ( m_FillSegmList.size() > 0 );
  106. m_FilledPolysList.clear();
  107. m_FillSegmList.clear();
  108. m_IsFilled = false;
  109. return change;
  110. }
  111. const wxPoint& ZONE_CONTAINER::GetPosition() const
  112. {
  113. static const wxPoint dummy;
  114. return m_Poly ? GetCornerPosition( 0 ) : dummy;
  115. }
  116. void ZONE_CONTAINER::SetNet( int aNetCode )
  117. {
  118. BOARD_CONNECTED_ITEM::SetNet( aNetCode );
  119. if( aNetCode < 0 )
  120. return;
  121. BOARD* board = GetBoard();
  122. if( board )
  123. {
  124. NETINFO_ITEM* net = board->FindNet( aNetCode );
  125. if( net )
  126. m_Netname = net->GetNetname();
  127. else
  128. m_Netname.Empty();
  129. }
  130. else
  131. {
  132. m_Netname.Empty();
  133. }
  134. }
  135. void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
  136. const wxPoint& offset )
  137. {
  138. if( DC == NULL )
  139. return;
  140. wxPoint seg_start, seg_end;
  141. LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  142. BOARD* brd = GetBoard();
  143. EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
  144. if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG )
  145. return;
  146. GRSetDrawMode( DC, aDrawMode );
  147. if( DisplayOpt.ContrastModeDisplay )
  148. {
  149. if( !IsOnLayer( curr_layer ) )
  150. ColorTurnToDarkDarkGray( &color );
  151. }
  152. if( aDrawMode & GR_HIGHLIGHT )
  153. ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) );
  154. ColorApplyHighlightFlag( &color );
  155. SetAlpha( &color, 150 );
  156. // draw the lines
  157. int i_start_contour = 0;
  158. std::vector<wxPoint> lines;
  159. lines.reserve( (GetNumCorners() * 2) + 2 );
  160. for( int ic = 0; ic < GetNumCorners(); ic++ )
  161. {
  162. seg_start = GetCornerPosition( ic ) + offset;
  163. if( m_Poly->m_CornersList[ic].end_contour == false && ic < GetNumCorners() - 1 )
  164. {
  165. seg_end = GetCornerPosition( ic + 1 ) + offset;
  166. }
  167. else
  168. {
  169. seg_end = GetCornerPosition( i_start_contour ) + offset;
  170. i_start_contour = ic + 1;
  171. }
  172. lines.push_back( seg_start );
  173. lines.push_back( seg_end );
  174. }
  175. GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
  176. // draw hatches
  177. lines.clear();
  178. lines.reserve( (m_Poly->m_HatchLines.size() * 2) + 2 );
  179. for( unsigned ic = 0; ic < m_Poly->m_HatchLines.size(); ic++ )
  180. {
  181. seg_start = m_Poly->m_HatchLines[ic].m_Start + offset;
  182. seg_end = m_Poly->m_HatchLines[ic].m_End + offset;
  183. lines.push_back( seg_start );
  184. lines.push_back( seg_end );
  185. }
  186. GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
  187. }
  188. void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
  189. wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
  190. {
  191. static std::vector <char> CornersTypeBuffer;
  192. static std::vector <wxPoint> CornersBuffer;
  193. // outline_mode is false to show filled polys,
  194. // and true to show polygons outlines only (test and debug purposes)
  195. bool outline_mode = DisplayOpt.DisplayZonesMode == 2 ? true : false;
  196. if( DC == NULL )
  197. return;
  198. if( DisplayOpt.DisplayZonesMode == 1 ) // Do not show filled areas
  199. return;
  200. if( m_FilledPolysList.size() == 0 ) // Nothing to draw
  201. return;
  202. BOARD* brd = GetBoard();
  203. LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  204. EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
  205. if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG )
  206. return;
  207. GRSetDrawMode( DC, aDrawMode );
  208. if( DisplayOpt.ContrastModeDisplay )
  209. {
  210. if( !IsOnLayer( curr_layer ) )
  211. ColorTurnToDarkDarkGray( &color );
  212. }
  213. if( aDrawMode & GR_HIGHLIGHT )
  214. ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) );
  215. ColorApplyHighlightFlag( &color );
  216. SetAlpha( &color, 150 );
  217. CornersTypeBuffer.clear();
  218. CornersBuffer.clear();
  219. // Draw all filled areas
  220. int imax = m_FilledPolysList.size() - 1;
  221. for( int ic = 0; ic <= imax; ic++ )
  222. {
  223. CPolyPt* corner = &m_FilledPolysList[ic];
  224. wxPoint coord( corner->x + offset.x, corner->y + offset.y );
  225. CornersBuffer.push_back( coord );
  226. CornersTypeBuffer.push_back( (char) corner->m_utility );
  227. // the last corner of a filled area is found: draw it
  228. if( (corner->end_contour) || (ic == imax) )
  229. {
  230. /* Draw the current filled area: draw segments outline first
  231. * Curiously, draw segments outline first and after draw filled polygons
  232. * with outlines thickness = 0 is a faster than
  233. * just draw filled polygons but with outlines thickness = m_ZoneMinThickness
  234. * So DO NOT use draw filled polygons with outlines having a thickness > 0
  235. * Note: Extra segments ( added to joint holes with external outline) flagged by
  236. * m_utility != 0 are not drawn
  237. * Note not all polygon libraries provide a flag for these extra-segments, therefore
  238. * the m_utility member can be always 0
  239. */
  240. {
  241. // Draw outlines:
  242. if( (m_ZoneMinThickness > 1) || outline_mode )
  243. {
  244. int ilim = CornersBuffer.size() - 1;
  245. for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
  246. {
  247. int x0 = CornersBuffer[is].x;
  248. int y0 = CornersBuffer[is].y;
  249. int x1 = CornersBuffer[ie].x;
  250. int y1 = CornersBuffer[ie].y;
  251. // Draw only basic outlines, not extra segments.
  252. if( CornersTypeBuffer[ie] == 0 )
  253. {
  254. if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
  255. GRCSegm( panel->GetClipBox(), DC,
  256. x0, y0, x1, y1,
  257. m_ZoneMinThickness, color );
  258. else
  259. GRFillCSegm( panel->GetClipBox(), DC,
  260. x0, y0, x1, y1,
  261. m_ZoneMinThickness, color );
  262. }
  263. }
  264. }
  265. // Draw areas:
  266. if( m_FillMode==0 && !outline_mode )
  267. GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
  268. true, 0, color, color );
  269. }
  270. CornersTypeBuffer.clear();
  271. CornersBuffer.clear();
  272. }
  273. }
  274. if( m_FillMode == 1 && !outline_mode ) // filled with segments
  275. {
  276. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  277. {
  278. wxPoint start = m_FillSegmList[ic].m_Start + offset;
  279. wxPoint end = m_FillSegmList[ic].m_End + offset;
  280. if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
  281. GRCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
  282. m_ZoneMinThickness, color );
  283. else
  284. GRFillCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
  285. m_ZoneMinThickness, color );
  286. }
  287. }
  288. }
  289. EDA_RECT ZONE_CONTAINER::GetBoundingBox() const
  290. {
  291. const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
  292. int ymax = -PRELOAD;
  293. int ymin = PRELOAD;
  294. int xmin = PRELOAD;
  295. int xmax = -PRELOAD;
  296. int count = GetNumCorners();
  297. for( int i = 0; i<count; ++i )
  298. {
  299. wxPoint corner = GetCornerPosition( i );
  300. ymax = std::max( ymax, corner.y );
  301. xmax = std::max( xmax, corner.x );
  302. ymin = std::min( ymin, corner.y );
  303. xmin = std::min( xmin, corner.x );
  304. }
  305. EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
  306. return ret;
  307. }
  308. void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC,
  309. GR_DRAWMODE draw_mode )
  310. {
  311. GR_DRAWMODE current_gr_mode = draw_mode;
  312. bool is_close_segment = false;
  313. wxPoint seg_start, seg_end;
  314. if( DC == NULL )
  315. return;
  316. LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
  317. BOARD* brd = GetBoard();
  318. EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
  319. if( DisplayOpt.ContrastModeDisplay )
  320. {
  321. if( !IsOnLayer( curr_layer ) )
  322. ColorTurnToDarkDarkGray( &color );
  323. }
  324. // draw the lines
  325. wxPoint start_contour_pos = GetCornerPosition( 0 );
  326. int icmax = GetNumCorners() - 1;
  327. for( int ic = 0; ic <= icmax; ic++ )
  328. {
  329. int xi = GetCornerPosition( ic ).x;
  330. int yi = GetCornerPosition( ic ).y;
  331. int xf, yf;
  332. if( m_Poly->m_CornersList[ic].end_contour == false && ic < icmax )
  333. {
  334. is_close_segment = false;
  335. xf = GetCornerPosition( ic + 1 ).x;
  336. yf = GetCornerPosition( ic + 1 ).y;
  337. if( (m_Poly->m_CornersList[ic + 1].end_contour) || (ic == icmax - 1) )
  338. current_gr_mode = GR_XOR;
  339. else
  340. current_gr_mode = draw_mode;
  341. }
  342. else // Draw the line from last corner to the first corner of the current contour
  343. {
  344. is_close_segment = true;
  345. current_gr_mode = GR_XOR;
  346. xf = start_contour_pos.x;
  347. yf = start_contour_pos.y;
  348. // Prepare the next contour for drawing, if exists
  349. if( ic < icmax )
  350. start_contour_pos = GetCornerPosition( ic + 1 );
  351. }
  352. GRSetDrawMode( DC, current_gr_mode );
  353. if( is_close_segment )
  354. GRLine( panel->GetClipBox(), DC, xi, yi, xf, yf, 0, WHITE );
  355. else
  356. GRLine( panel->GetClipBox(), DC, xi, yi, xf, yf, 0, color );
  357. }
  358. }
  359. int ZONE_CONTAINER::GetThermalReliefGap( D_PAD* aPad ) const
  360. {
  361. if( aPad == NULL || aPad->GetThermalGap() == 0 )
  362. return m_ThermalReliefGap;
  363. else
  364. return aPad->GetThermalGap();
  365. }
  366. int ZONE_CONTAINER::GetThermalReliefCopperBridge( D_PAD* aPad ) const
  367. {
  368. if( aPad == NULL || aPad->GetThermalWidth() == 0 )
  369. return m_ThermalReliefCopperBridge;
  370. else
  371. return aPad->GetThermalWidth();
  372. }
  373. bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition )
  374. {
  375. if( HitTestForCorner( aPosition ) )
  376. return true;
  377. if( HitTestForEdge( aPosition ) )
  378. return true;
  379. return false;
  380. }
  381. // Zones outlines have no thickness, so it Hit Test functions
  382. // we must have a default distance between the test point
  383. // and a corner or a zone edge:
  384. #define MIN_DIST_IN_MILS 10
  385. bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
  386. {
  387. m_CornerSelection = -1; // Set to not found
  388. // distance (in internal units) to detect a corner in a zone outline.
  389. int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;
  390. wxPoint delta;
  391. unsigned lim = m_Poly->m_CornersList.size();
  392. for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
  393. {
  394. delta.x = refPos.x - m_Poly->m_CornersList[item_pos].x;
  395. delta.y = refPos.y - m_Poly->m_CornersList[item_pos].y;
  396. // Calculate a distance:
  397. int dist = std::max( abs( delta.x ), abs( delta.y ) );
  398. if( dist < min_dist ) // this corner is a candidate:
  399. {
  400. m_CornerSelection = item_pos;
  401. min_dist = dist;
  402. }
  403. }
  404. return m_CornerSelection >= 0;
  405. }
  406. bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
  407. {
  408. unsigned lim = m_Poly->m_CornersList.size();
  409. m_CornerSelection = -1; // Set to not found
  410. // distance (in internal units) to detect a zone outline
  411. int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;
  412. unsigned first_corner_pos = 0;
  413. for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
  414. {
  415. unsigned end_segm = item_pos + 1;
  416. /* the last corner of the current outline is tested
  417. * the last segment of the current outline starts at current corner, and ends
  418. * at the first corner of the outline
  419. */
  420. if( m_Poly->m_CornersList[item_pos].end_contour || end_segm >= lim )
  421. {
  422. unsigned tmp = first_corner_pos;
  423. first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline
  424. end_segm = tmp; // end_segm is the beginning of the current outline
  425. }
  426. /* test the dist between segment and ref point */
  427. int dist = (int) GetPointToLineSegmentDistance( refPos.x,
  428. refPos.y,
  429. m_Poly->m_CornersList[item_pos].x,
  430. m_Poly->m_CornersList[item_pos].y,
  431. m_Poly->m_CornersList[end_segm].x,
  432. m_Poly->m_CornersList[end_segm].y );
  433. if( dist < min_dist )
  434. {
  435. m_CornerSelection = item_pos;
  436. min_dist = dist;
  437. }
  438. }
  439. return m_CornerSelection >= 0;
  440. }
  441. bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect ) const
  442. {
  443. bool is_out_of_box = false;
  444. CRect rect = m_Poly->GetCornerBounds();
  445. if( rect.left < aRect.GetX() )
  446. is_out_of_box = true;
  447. if( rect.top < aRect.GetY() )
  448. is_out_of_box = true;
  449. if( rect.right > aRect.GetRight() )
  450. is_out_of_box = true;
  451. if( rect.bottom > aRect.GetBottom() )
  452. is_out_of_box = true;
  453. return is_out_of_box ? false : true;
  454. }
  455. int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
  456. {
  457. int myClearance = m_ZoneClearance;
  458. #if 0 // Maybe the netclass clearance should not come into play for a zone?
  459. // At least the policy decision can be controlled by the zone
  460. // itself, i.e. here. On reasons of insufficient documentation,
  461. // the user will be less bewildered if we simply respect the
  462. // "zone clearance" setting in the zone properties dialog. (At least
  463. // until there is a UI boolean for this.)
  464. NETCLASS* myClass = GetNetClass();
  465. if( myClass )
  466. myClearance = std::max( myClearance, myClass->GetClearance() );
  467. #endif
  468. if( aItem )
  469. {
  470. int hisClearance = aItem->GetClearance( NULL );
  471. myClearance = std::max( hisClearance, myClearance );
  472. }
  473. return myClearance;
  474. }
  475. bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
  476. {
  477. unsigned indexstart = 0, indexend;
  478. bool inside = false;
  479. for( indexend = 0; indexend < m_FilledPolysList.size(); indexend++ )
  480. {
  481. if( m_FilledPolysList[indexend].end_contour ) // end of a filled sub-area found
  482. {
  483. if( TestPointInsidePolygon( m_FilledPolysList, indexstart, indexend, aRefPos.x,
  484. aRefPos.y ) )
  485. {
  486. inside = true;
  487. break;
  488. }
  489. // Prepare test of next area which starts after the current index end (if exists)
  490. indexstart = indexend + 1;
  491. }
  492. }
  493. return inside;
  494. }
  495. void ZONE_CONTAINER::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  496. {
  497. wxString msg;
  498. BOARD* board = (BOARD*) m_Parent;
  499. wxASSERT( board );
  500. msg = _( "Zone Outline" );
  501. // Display Cutout instead of Outline for holes inside a zone
  502. // i.e. when num contour !=0
  503. int ncont = m_Poly->GetContour( m_CornerSelection );
  504. if( ncont )
  505. msg << wxT( " " ) << _( "(Cutout)" );
  506. aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
  507. if( GetIsKeepout() )
  508. {
  509. msg.Empty();
  510. if( GetDoNotAllowVias() )
  511. msg = _("No via");
  512. if( GetDoNotAllowTracks() )
  513. {
  514. if( !msg.IsEmpty() )
  515. msg += wxT(", ");
  516. msg += _("No track");
  517. }
  518. if( GetDoNotAllowCopperPour() )
  519. {
  520. if( !msg.IsEmpty() )
  521. msg += wxT(", ");
  522. msg += _("No copper pour");
  523. }
  524. aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
  525. }
  526. else if( IsOnCopperLayer() )
  527. {
  528. if( GetNet() >= 0 )
  529. {
  530. NETINFO_ITEM* equipot = board->FindNet( GetNet() );
  531. if( equipot )
  532. msg = equipot->GetNetname();
  533. else
  534. msg = wxT( "<noname>" );
  535. }
  536. else // a netcode < 0 is an error
  537. {
  538. msg = wxT( " [" );
  539. msg << m_Netname + wxT( "]" );
  540. msg << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
  541. }
  542. aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
  543. #if 1
  544. // Display net code : (useful in test or debug)
  545. msg.Printf( wxT( "%d" ), GetNet() );
  546. aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
  547. #endif
  548. // Display priority level
  549. msg.Printf( wxT( "%d" ), GetPriority() );
  550. aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
  551. }
  552. else
  553. {
  554. aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
  555. }
  556. msg = board->GetLayerName( m_Layer );
  557. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), msg, BROWN ) );
  558. msg.Printf( wxT( "%d" ), (int) m_Poly->m_CornersList.size() );
  559. aList.push_back( MSG_PANEL_ITEM( _( "Corners" ), msg, BLUE ) );
  560. if( m_FillMode )
  561. msg = _( "Segments" );
  562. else
  563. msg = _( "Polygons" );
  564. aList.push_back( MSG_PANEL_ITEM( _( "Fill mode" ), msg, BROWN ) );
  565. // Useful for statistics :
  566. msg.Printf( wxT( "%d" ), (int) m_Poly->m_HatchLines.size() );
  567. aList.push_back( MSG_PANEL_ITEM( _( "Hatch lines" ), msg, BLUE ) );
  568. if( m_FilledPolysList.size() )
  569. {
  570. msg.Printf( wxT( "%d" ), (int) m_FilledPolysList.size() );
  571. aList.push_back( MSG_PANEL_ITEM( _( "Corners in DrawList" ), msg, BLUE ) );
  572. }
  573. }
  574. /* Geometric transforms: */
  575. void ZONE_CONTAINER::Move( const wxPoint& offset )
  576. {
  577. /* move outlines */
  578. for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
  579. {
  580. SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
  581. }
  582. m_Poly->Hatch();
  583. /* move filled areas: */
  584. for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
  585. {
  586. CPolyPt* corner = &m_FilledPolysList[ic];
  587. corner->x += offset.x;
  588. corner->y += offset.y;
  589. }
  590. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  591. {
  592. m_FillSegmList[ic].m_Start += offset;
  593. m_FillSegmList[ic].m_End += offset;
  594. }
  595. }
  596. void ZONE_CONTAINER::MoveEdge( const wxPoint& offset )
  597. {
  598. int ii = m_CornerSelection;
  599. // Move the start point of the selected edge:
  600. SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
  601. // Move the end point of the selected edge:
  602. if( m_Poly->m_CornersList[ii].end_contour || ii == GetNumCorners() - 1 )
  603. {
  604. int icont = m_Poly->GetContour( ii );
  605. ii = m_Poly->GetContourStart( icont );
  606. }
  607. else
  608. {
  609. ii++;
  610. }
  611. SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
  612. m_Poly->Hatch();
  613. }
  614. void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
  615. {
  616. wxPoint pos;
  617. for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
  618. {
  619. pos.x = m_Poly->m_CornersList[ii].x;
  620. pos.y = m_Poly->m_CornersList[ii].y;
  621. RotatePoint( &pos, centre, angle );
  622. m_Poly->m_CornersList[ii].x = pos.x;
  623. m_Poly->m_CornersList[ii].y = pos.y;
  624. }
  625. m_Poly->Hatch();
  626. /* rotate filled areas: */
  627. for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
  628. {
  629. CPolyPt* corner = &m_FilledPolysList[ic];
  630. pos.x = corner->x;
  631. pos.y = corner->y;
  632. RotatePoint( &pos, centre, angle );
  633. corner->x = pos.x;
  634. corner->y = pos.y;
  635. }
  636. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  637. {
  638. RotatePoint( &m_FillSegmList[ic].m_Start, centre, angle );
  639. RotatePoint( &m_FillSegmList[ic].m_End, centre, angle );
  640. }
  641. }
  642. void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
  643. {
  644. Mirror( aCentre );
  645. SetLayer( FlipLayer( GetLayer() ) );
  646. }
  647. void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
  648. {
  649. for( unsigned ii = 0; ii < m_Poly->m_CornersList.size(); ii++ )
  650. {
  651. m_Poly->m_CornersList[ii].y -= mirror_ref.y;
  652. NEGATE( m_Poly->m_CornersList[ii].y );
  653. m_Poly->m_CornersList[ii].y += mirror_ref.y;
  654. }
  655. m_Poly->Hatch();
  656. /* mirror filled areas: */
  657. for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
  658. {
  659. CPolyPt* corner = &m_FilledPolysList[ic];
  660. corner->y -= mirror_ref.y;
  661. NEGATE( corner->y );
  662. corner->y += mirror_ref.y;
  663. }
  664. for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
  665. {
  666. m_FillSegmList[ic].m_Start.y -= mirror_ref.y;
  667. NEGATE( m_FillSegmList[ic].m_Start.y );
  668. m_FillSegmList[ic].m_Start.y += mirror_ref.y;
  669. m_FillSegmList[ic].m_End.y -= mirror_ref.y;
  670. NEGATE( m_FillSegmList[ic].m_End.y );
  671. m_FillSegmList[ic].m_End.y += mirror_ref.y;
  672. }
  673. }
  674. void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src )
  675. {
  676. m_Parent = src->m_Parent;
  677. m_Layer = src->m_Layer;
  678. SetNet( src->GetNet() );
  679. SetTimeStamp( src->m_TimeStamp );
  680. m_Poly->RemoveAllContours();
  681. m_Poly->Copy( src->m_Poly ); // copy outlines
  682. m_CornerSelection = -1; // For corner moving, corner index to drag, or -1 if no selection
  683. m_ZoneClearance = src->m_ZoneClearance; // clearance value
  684. m_ZoneMinThickness = src->m_ZoneMinThickness;
  685. m_FillMode = src->m_FillMode; // Filling mode (segments/polygons)
  686. m_ArcToSegmentsCount = src->m_ArcToSegmentsCount;
  687. m_PadConnection = src->m_PadConnection;
  688. m_ThermalReliefGap = src->m_ThermalReliefGap;
  689. m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge;
  690. m_Poly->SetHatchStyle( src->m_Poly->GetHatchStyle() );
  691. m_Poly->SetHatchPitch( src->m_Poly->GetHatchPitch() );
  692. m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector <CSegment>
  693. m_FilledPolysList.clear();
  694. m_FilledPolysList = src->m_FilledPolysList;
  695. m_FillSegmList.clear();
  696. m_FillSegmList = src->m_FillSegmList;
  697. }
  698. bool ZONE_CONTAINER::SetNetNameFromNetCode( void )
  699. {
  700. NETINFO_ITEM* net;
  701. if( m_Parent && ( net = ( (BOARD*) m_Parent )->FindNet( GetNet() ) ) )
  702. {
  703. m_Netname = net->GetNetname();
  704. return true;
  705. }
  706. return false;
  707. }
  708. ZoneConnection ZONE_CONTAINER::GetPadConnection( D_PAD* aPad ) const
  709. {
  710. if( aPad == NULL || aPad->GetZoneConnection() == UNDEFINED_CONNECTION )
  711. return m_PadConnection;
  712. else
  713. return aPad->GetZoneConnection();
  714. }
  715. void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
  716. {
  717. if( aPolygon.empty() )
  718. return;
  719. for( unsigned i = 0; i < aPolygon.size(); i++ )
  720. {
  721. if( i == 0 )
  722. m_Poly->Start( GetLayer(), aPolygon[i].x, aPolygon[i].y, GetHatchStyle() );
  723. else
  724. AppendCorner( aPolygon[i] );
  725. }
  726. m_Poly->CloseLastContour();
  727. }
  728. wxString ZONE_CONTAINER::GetSelectMenuText() const
  729. {
  730. wxString text;
  731. NETINFO_ITEM* net;
  732. BOARD* board = GetBoard();
  733. text = _( "Zone Outline" );
  734. int ncont = m_Poly->GetContour( m_CornerSelection );
  735. if( ncont )
  736. text << wxT( " " ) << _( "(Cutout)" );
  737. if( GetIsKeepout() )
  738. text << wxT( " " ) << _( "(Keepout)" );
  739. text << wxT( " " );
  740. text << wxString::Format( wxT( "(%08lX)" ), m_TimeStamp );
  741. // Display net name for copper zones
  742. if( !GetIsKeepout() )
  743. {
  744. if( GetNet() >= 0 )
  745. {
  746. if( board )
  747. {
  748. net = board->FindNet( GetNet() );
  749. if( net )
  750. {
  751. text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
  752. }
  753. }
  754. else
  755. {
  756. text << _( "** NO BOARD DEFINED **" );
  757. }
  758. }
  759. else
  760. { // A netcode < 0 is an error:
  761. // Netname not found or area not initialised
  762. text << wxT( " [" ) << m_Netname << wxT( "]" );
  763. text << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
  764. }
  765. }
  766. text << _( " on layer " ) << GetLayerName();
  767. return text;
  768. }