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.

319 lines
12 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
13 years ago
13 years ago
  1. /**
  2. * @file zones_functions_for_undo_redo.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 <jp.charras@wanadoo.fr>
  8. * Copyright (C) 2007-2015 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. /* These functions are relative to undo redo function, when zones are involved.
  28. *
  29. * When a zone outline is modified (or created) this zone, or others zones on the same layer
  30. * and with the same netcode can change or can be deleted due to the fact overlapping zones are
  31. * merged. Also, when a zone outline is modified by adding a cutout area, this zone can be
  32. * converted to more than one area, if the outline is break to 2 or more outlines and therefore
  33. * new zones are created
  34. *
  35. * Due to the complexity of potential changes, and the fact there are only few zones in a board,
  36. * and a zone has only few segments outlines, the more easy way to undo redo changes is to make
  37. * a copy of all zones that can be changed and see after zone editing or creation what zones that
  38. * are really modified, and ones they are modified (changes, deletion or addition)
  39. */
  40. #include <pgm_base.h>
  41. #include <pcb_edit_frame.h>
  42. #include <board.h>
  43. #include <zone.h>
  44. #include <pcbnew.h>
  45. #include <zones.h>
  46. #include <zones_functions_for_undo_redo.h>
  47. /**
  48. * Function IsSame
  49. * test is 2 zones are equivalent:
  50. * 2 zones are equivalent if they have same parameters and same outlines
  51. * info relative to filling is not take in account
  52. * @param aZoneToCompare = zone to compare with "this"
  53. */
  54. bool ZONE::IsSame( const ZONE& aZoneToCompare )
  55. {
  56. // compare basic parameters:
  57. if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
  58. return false;
  59. if( GetNetCode() != aZoneToCompare.GetNetCode() )
  60. return false;
  61. if( GetPriority() != aZoneToCompare.GetPriority() )
  62. return false;
  63. // Compare zone specific parameters
  64. if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
  65. return false;
  66. if( GetIsRuleArea() )
  67. {
  68. if( GetDoNotAllowCopperPour() != aZoneToCompare.GetDoNotAllowCopperPour() )
  69. return false;
  70. if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
  71. return false;
  72. if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
  73. return false;
  74. if( GetDoNotAllowPads() != aZoneToCompare.GetDoNotAllowPads() )
  75. return false;
  76. if( GetDoNotAllowFootprints() != aZoneToCompare.GetDoNotAllowFootprints() )
  77. return false;
  78. }
  79. if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
  80. return false;
  81. if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
  82. return false;
  83. if( m_fillMode != aZoneToCompare.GetFillMode() )
  84. return false;
  85. if( m_PadConnection != aZoneToCompare.m_PadConnection )
  86. return false;
  87. if( m_thermalReliefGap != aZoneToCompare.m_thermalReliefGap )
  88. return false;
  89. if( m_thermalReliefSpokeWidth != aZoneToCompare.m_thermalReliefSpokeWidth )
  90. return false;
  91. if( m_zoneName != aZoneToCompare.m_zoneName )
  92. return false;
  93. if( m_islandRemovalMode != aZoneToCompare.m_islandRemovalMode )
  94. return false;
  95. if( m_minIslandArea != aZoneToCompare.m_minIslandArea )
  96. return false;
  97. // Compare outlines
  98. wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
  99. wxASSERT( aZoneToCompare.Outline() );
  100. if( Outline() != aZoneToCompare.Outline() ) // Compare vector
  101. return false;
  102. return true;
  103. }
  104. /**
  105. * Function SaveCopyOfZones
  106. * creates a copy of zones having a given netcode on a given layer,
  107. * and fill a pick list with pickers to handle these copies
  108. * the UndoRedo status is set to CHANGED for all items in list
  109. * Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing
  110. * @param aPickList = the pick list
  111. * @param aPcb = the Board
  112. * @param aNetCode = the reference netcode. if aNetCode < 0 all netcodes are used
  113. * @param aLayer = the layer of zones. if aLayer < 0, all layers are used
  114. * @return the count of saved copies
  115. */
  116. int SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb, int aNetCode, LAYER_NUM aLayer )
  117. {
  118. int copyCount = 0;
  119. for( unsigned ii = 0; ; ii++ )
  120. {
  121. ZONE* zone = aPcb->GetArea( ii );
  122. if( zone == nullptr ) // End of list
  123. break;
  124. if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
  125. continue;
  126. if( aLayer >= 0 && !zone->GetLayerSet().test( aLayer ) )
  127. continue;
  128. ZONE* zoneDup = new ZONE( *zone );
  129. zoneDup->SetParent( aPcb );
  130. ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
  131. picker.SetLink( zoneDup );
  132. aPickList.PushItem( picker );
  133. copyCount++;
  134. }
  135. return copyCount;
  136. }
  137. /**
  138. * Function UpdateCopyOfZonesList
  139. * Check a pick list to remove zones identical to their copies and set the type of operation in
  140. * picker (DELETED, CHANGED). If an item is deleted, the initial values are retrievered,
  141. * because they can have changed during editing.
  142. * @param aPickList = the main pick list
  143. * @param aAuxiliaryList = the list of deleted or added (new created) items after calculations
  144. * @param aPcb = the Board
  145. *
  146. * aAuxiliaryList is a list of pickers updated by zone algorithms:
  147. * This list contains zones which were added or deleted during the zones combine process
  148. * aPickList :is a list of zones that can be modified (changed or deleted, or not modified)
  149. * Typically, this is the list of existing zones on the layer of the edited zone,
  150. * before any change.
  151. * >> if the picked zone is not changed, it is removed from list
  152. * >> if the picked zone was deleted (i.e. not found in board list), the picker is modified:
  153. * its status becomes DELETED
  154. * the aAuxiliaryList corresponding picker is removed (if not found : set an error)
  155. * >> if the picked zone was flagged as NEWITEM, and was after deleted ,
  156. * perhaps combined with another zone (i.e. not found in board list):
  157. * the picker is removed
  158. * the zone itself if really deleted
  159. * the aAuxiliaryList corresponding picker is removed (if not found : set an error)
  160. * After aPickList is cleaned, the aAuxiliaryList is read
  161. * All pickers flagged NEWITEM are moved to aPickList
  162. * (the corresponding zones are zone that were created by the zone normalize and combine process,
  163. * mainly when adding cutout areas, or creating self intersecting contours)
  164. * All pickers flagged DELETED are removed, and the coresponding zones actually deleted
  165. * (the corresponding zones are new zone that were created by the zone normalize process,
  166. * when creating self intersecting contours, and after combined with an existing zone.
  167. * At the end of the update process the aAuxiliaryList must be void,
  168. * because all pickers created by the combine process
  169. * must have been removed (removed for new and deleted zones, or moved in aPickList.)
  170. * If not an error is set.
  171. */
  172. void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList,
  173. PICKED_ITEMS_LIST& aAuxiliaryList,
  174. BOARD* aPcb )
  175. {
  176. for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
  177. {
  178. UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
  179. ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
  180. for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
  181. {
  182. ZONE* zone = aPcb->GetArea( ii );
  183. if( zone == nullptr )
  184. {
  185. /* End of list: the stored item is not found:
  186. * it must be in aDeletedList:
  187. * search it and restore initial values
  188. * or
  189. * if flagged NEWITEM: remove it definitively
  190. */
  191. if( status == UNDO_REDO::NEWITEM )
  192. {
  193. delete ref;
  194. ref = nullptr;
  195. aPickList.RemovePicker( kk );
  196. kk--;
  197. }
  198. else
  199. {
  200. ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
  201. aPickList.SetPickedItemStatus( UNDO_REDO::DELETED, kk );
  202. wxASSERT_MSG( zcopy != nullptr,
  203. wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
  204. *ref = *zcopy;
  205. // the copy was deleted; the link does not exists now.
  206. aPickList.SetPickedItemLink( nullptr, kk );
  207. delete zcopy;
  208. }
  209. // Remove this item from aAuxiliaryList, mainly for tests purpose
  210. bool notfound = true;
  211. for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
  212. {
  213. if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
  214. {
  215. aAuxiliaryList.RemovePicker( nn );
  216. notfound = false;
  217. break;
  218. }
  219. }
  220. if( notfound ) // happens when the new zone overlaps an existing zone
  221. // and these zones are combined
  222. {
  223. #if defined(DEBUG)
  224. printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
  225. "combined with another zone\n" );
  226. fflush(nullptr);
  227. #endif
  228. }
  229. break;
  230. }
  231. if( zone == ref ) // picked zone found
  232. {
  233. if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
  234. {
  235. ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
  236. if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
  237. {
  238. delete zcopy; // Delete copy
  239. aPickList.RemovePicker( kk );
  240. kk--;
  241. }
  242. }
  243. break;
  244. }
  245. }
  246. }
  247. // Add new zones in main pick list, and remove pickers from Auxiliary List
  248. for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
  249. {
  250. if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
  251. {
  252. ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
  253. aPickList.PushItem( picker );
  254. aAuxiliaryList.RemovePicker( ii );
  255. }
  256. else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::DELETED )
  257. {
  258. delete aAuxiliaryList.GetPickedItemLink( ii );
  259. aAuxiliaryList.RemovePicker( ii );
  260. }
  261. else
  262. ii++;
  263. }
  264. // Should not occur:
  265. wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
  266. wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
  267. }