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.

187 lines
6.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: zones_by_polygon_fill_functions.cpp
  3. /////////////////////////////////////////////////////////////////////////////
  4. /*
  5. * This program source code file is part of KICAD, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2009 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
  8. * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <wx/progdlg.h>
  28. #include "fctsys.h"
  29. #include "appl_wxstruct.h"
  30. #include "common.h"
  31. #include "class_drawpanel.h"
  32. #include "pcbnew.h"
  33. #include "wxPcbStruct.h"
  34. #include "zones.h"
  35. /**
  36. * Function Delete_Zone_Fill
  37. * Remove the zone fillig which include the segment aZone, or the zone which have the given time stamp.
  38. * A zone is a group of segments which have the same TimeStamp
  39. * @param aZone = zone segment within the zone to delete. Can be NULL
  40. * @param aTimestamp = Timestamp for the zone to delete, used if aZone == NULL
  41. */
  42. void PCB_EDIT_FRAME::Delete_Zone_Fill( SEGZONE* aZone, long aTimestamp )
  43. {
  44. bool modify = false;
  45. unsigned long TimeStamp;
  46. if( aZone == NULL )
  47. TimeStamp = aTimestamp;
  48. else
  49. TimeStamp = aZone->m_TimeStamp; // Save reference time stamp (aZone will be deleted)
  50. SEGZONE* next;
  51. for( SEGZONE* zone = GetBoard()->m_Zone; zone != NULL; zone = next )
  52. {
  53. next = zone->Next();
  54. if( zone->m_TimeStamp == TimeStamp )
  55. {
  56. modify = TRUE;
  57. /* remove item from linked list and free memory */
  58. zone->DeleteStructure();
  59. }
  60. }
  61. // Now delete the outlines of the corresponding copper areas (deprecated)
  62. for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
  63. {
  64. ZONE_CONTAINER* zone = GetBoard()->GetArea( ii );
  65. if( zone->m_TimeStamp == TimeStamp )
  66. {
  67. modify = TRUE;
  68. zone->m_FilledPolysList.clear();
  69. zone->m_FillSegmList.clear();
  70. zone->m_IsFilled = false;
  71. }
  72. }
  73. if( modify )
  74. {
  75. OnModify();
  76. DrawPanel->Refresh();
  77. }
  78. }
  79. /***************************************************************************************/
  80. int PCB_EDIT_FRAME::Fill_Zone( ZONE_CONTAINER* zone_container, bool verbose )
  81. /***************************************************************************************/
  82. /**
  83. * Function Fill_Zone
  84. * Calculate the zone filling for the outline zone_container
  85. * The zone outline is a frontier, and can be complex (with holes)
  86. * The filling starts from starting points like pads, tracks.
  87. * If exists, the old filling is removed
  88. * @param zone_container = zone to fill
  89. * @param verbose = true to show error messages
  90. * @return error level (0 = no error)
  91. */
  92. {
  93. wxString msg;
  94. MsgPanel->EraseMsgBox();
  95. if( GetBoard()->ComputeBoundingBox() == false )
  96. {
  97. if( verbose )
  98. wxMessageBox( wxT( "Board is empty!" ) );
  99. return -1;
  100. }
  101. // Shows the net
  102. g_Zone_Default_Setting.m_NetcodeSelection = zone_container->GetNet();
  103. msg = zone_container->GetNetName();
  104. if( msg.IsEmpty() )
  105. msg = wxT( "No net" );
  106. Affiche_1_Parametre( this, 22, _( "NetName" ), msg, RED );
  107. wxBusyCursor dummy; // Shows an hourglass cursor (removed by its destructor)
  108. zone_container->m_FilledPolysList.clear();
  109. Delete_Zone_Fill( NULL, zone_container->m_TimeStamp );
  110. zone_container->BuildFilledPolysListData( GetBoard() );
  111. OnModify();
  112. return 0;
  113. }
  114. int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose )
  115. /**
  116. * Function Fill_All_Zones
  117. * Fill all zones on the board
  118. * The old fillings are removed
  119. * @param verbose = true to show error messages
  120. * @return error level (0 = no error)
  121. */
  122. {
  123. int errorLevel = 0;
  124. int areaCount = GetBoard()->GetAreaCount();
  125. wxBusyCursor dummyCursor;
  126. wxString msg;
  127. #define FORMAT_STRING _( "Filling zone %d out of %d (net %s)..." )
  128. // Create a message with a long net name, and build a wxProgressDialog
  129. // with a correct size to show this long net name
  130. msg.Printf( FORMAT_STRING,
  131. 000, 999, wxT("XXXXXXXXXXXXXXXXX" ) );
  132. wxProgressDialog progressDialog( _( "Fill All Zones" ), msg,
  133. areaCount+2, this,
  134. wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT );
  135. // Display the actual message
  136. progressDialog.Update( 0, _( "Starting zone fill..." ) );
  137. // Remove segment zones
  138. GetBoard()->m_Zone.DeleteAll();
  139. int ii;
  140. for( ii = 0; ii < areaCount; ii++ )
  141. {
  142. ZONE_CONTAINER* zoneContainer = GetBoard()->GetArea( ii );
  143. msg.Printf( FORMAT_STRING,
  144. ii+1, areaCount, GetChars( zoneContainer->GetNetName() ) );
  145. if( !progressDialog.Update( ii+1, msg ) )
  146. break;
  147. errorLevel = Fill_Zone( zoneContainer, verbose );
  148. if( errorLevel && !verbose )
  149. break;
  150. }
  151. progressDialog.Update( ii+2, _( "Updating ratsnest..." ) );
  152. test_connexions( NULL );
  153. // Recalculate the active ratsnest, i.e. the unconnected links
  154. Tst_Ratsnest( NULL, 0 );
  155. DrawPanel->Refresh( true );
  156. return errorLevel;
  157. }