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.

303 lines
11 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 <fctsys.h>
  41. #include <pgm_base.h>
  42. #include <pcb_edit_frame.h>
  43. #include <class_board.h>
  44. #include <class_zone.h>
  45. #include <pcbnew.h>
  46. #include <zones.h>
  47. #include <zones_functions_for_undo_redo.h>
  48. /**
  49. * Function IsSame
  50. * test is 2 zones are equivalent:
  51. * 2 zones are equivalent if they have same parameters and same outlines
  52. * info relative to filling is not take in account
  53. * @param aZoneToCompare = zone to compare with "this"
  54. */
  55. bool ZONE_CONTAINER::IsSame( const ZONE_CONTAINER& aZoneToCompare )
  56. {
  57. // compare basic parameters:
  58. if( GetLayer() != aZoneToCompare.GetLayer() )
  59. return false;
  60. if( GetNetCode() != aZoneToCompare.GetNetCode() )
  61. return false;
  62. if( GetPriority() != aZoneToCompare.GetPriority() )
  63. return false;
  64. // Compare zone specific parameters
  65. if( GetIsKeepout() != aZoneToCompare.GetIsKeepout() )
  66. return false;
  67. if( GetIsKeepout() )
  68. {
  69. if( GetDoNotAllowCopperPour() != aZoneToCompare.GetDoNotAllowCopperPour() )
  70. return false;
  71. if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
  72. return false;
  73. if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
  74. return false;
  75. }
  76. if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
  77. return false;
  78. if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
  79. return false;
  80. if( m_FillMode != aZoneToCompare.GetFillMode() )
  81. return false;
  82. if( m_PadConnection != aZoneToCompare.m_PadConnection )
  83. return false;
  84. if( m_ThermalReliefGap != aZoneToCompare.m_ThermalReliefGap )
  85. return false;
  86. if( m_ThermalReliefCopperBridge != aZoneToCompare.m_ThermalReliefCopperBridge )
  87. return false;
  88. // Compare outlines
  89. wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
  90. wxASSERT( aZoneToCompare.Outline() );
  91. if( Outline() != aZoneToCompare.Outline() ) // Compare vector
  92. return false;
  93. return true;
  94. }
  95. /**
  96. * Function SaveCopyOfZones
  97. * creates a copy of zones having a given netcode on a given layer,
  98. * and fill a pick list with pickers to handle these copies
  99. * the UndoRedo status is set to UR_CHANGED for all items in list
  100. * Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing
  101. * @param aPickList = the pick list
  102. * @param aPcb = the Board
  103. * @param aNetCode = the reference netcode. if aNetCode < 0 all netcodes are used
  104. * @param aLayer = the layer of zones. if aLayer < 0, all layers are used
  105. * @return the count of saved copies
  106. */
  107. int SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb, int aNetCode, LAYER_NUM aLayer )
  108. {
  109. int copyCount = 0;
  110. for( unsigned ii = 0; ; ii++ )
  111. {
  112. ZONE_CONTAINER* zone = aPcb->GetArea( ii );
  113. if( zone == NULL ) // End of list
  114. break;
  115. if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
  116. continue;
  117. if( aLayer >= 0 && aLayer != zone->GetLayer() )
  118. continue;
  119. ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
  120. zoneDup->SetParent( aPcb );
  121. ITEM_PICKER picker( zone, UR_CHANGED );
  122. picker.SetLink( zoneDup );
  123. aPickList.PushItem( picker );
  124. copyCount++;
  125. }
  126. return copyCount;
  127. }
  128. /**
  129. * Function UpdateCopyOfZonesList
  130. * Check a pick list to remove zones identical to their copies and set the type of operation in
  131. * picker (UR_DELETED, UR_CHANGED). If an item is deleted, the initial values are retrievered,
  132. * because they can have changed during editing.
  133. * @param aPickList = the main pick list
  134. * @param aAuxiliaryList = the list of deleted or added (new created) items after calculations
  135. * @param aPcb = the Board
  136. *
  137. * aAuxiliaryList is a list of pickers updated by zone algorithms:
  138. * This list contains zones which were added or deleted during the zones combine process
  139. * aPickList :is a list of zones that can be modified (changed or deleted, or not modified)
  140. * Typically, this is the list of existing zones on the layer of the edited zone,
  141. * before any change.
  142. * >> if the picked zone is not changed, it is removed from list
  143. * >> if the picked zone was deleted (i.e. not found in board list), the picker is modified:
  144. * its status becomes UR_DELETED
  145. * the aAuxiliaryList corresponding picker is removed (if not found : set an error)
  146. * >> if the picked zone was flagged as UR_NEW, and was after deleted ,
  147. * perhaps combined with another zone (i.e. not found in board list):
  148. * the picker is removed
  149. * the zone itself if really deleted
  150. * the aAuxiliaryList corresponding picker is removed (if not found : set an error)
  151. * After aPickList is cleaned, the aAuxiliaryList is read
  152. * All pickers flagged UR_NEW are moved to aPickList
  153. * (the corresponding zones are zone that were created by the zone normalize and combine process,
  154. * mainly when adding cutout areas, or creating self intersecting contours)
  155. * All pickers flagged UR_DELETED are removed, and the coresponding zones actually deleted
  156. * (the corresponding zones are new zone that were created by the zone normalize process,
  157. * when creating self intersecting contours, and after combined with an existing zone.
  158. * At the end of the update process the aAuxiliaryList must be void,
  159. * because all pickers created by the combine process
  160. * must have been removed (removed for new and deleted zones, or moved in aPickList.)
  161. * If not an error is set.
  162. */
  163. void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList,
  164. PICKED_ITEMS_LIST& aAuxiliaryList,
  165. BOARD* aPcb )
  166. {
  167. for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
  168. {
  169. UNDO_REDO_T status = aPickList.GetPickedItemStatus( kk );
  170. ZONE_CONTAINER* ref = (ZONE_CONTAINER*) aPickList.GetPickedItem( kk );
  171. for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
  172. {
  173. ZONE_CONTAINER* zone = aPcb->GetArea( ii );
  174. if( zone == NULL )
  175. {
  176. /* End of list: the stored item is not found:
  177. * it must be in aDeletedList:
  178. * search it and restore initial values
  179. * or
  180. * if flagged UR_NEW: remove it definitively
  181. */
  182. if( status == UR_NEW )
  183. {
  184. delete ref;
  185. ref = NULL;
  186. aPickList.RemovePicker( kk );
  187. kk--;
  188. }
  189. else
  190. {
  191. ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
  192. aPickList.SetPickedItemStatus( UR_DELETED, kk );
  193. wxASSERT_MSG( zcopy != NULL,
  194. wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
  195. *ref = *zcopy;
  196. // the copy was deleted; the link does not exists now.
  197. aPickList.SetPickedItemLink( NULL, kk );
  198. delete zcopy;
  199. }
  200. // Remove this item from aAuxiliaryList, mainly for tests purpose
  201. bool notfound = true;
  202. for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
  203. {
  204. if( ref != NULL && aAuxiliaryList.GetPickedItem( nn ) == ref )
  205. {
  206. aAuxiliaryList.RemovePicker( nn );
  207. notfound = false;
  208. break;
  209. }
  210. }
  211. if( notfound ) // happens when the new zone overlaps an existing zone
  212. // and these zones are combined
  213. {
  214. DBG( printf(
  215. "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
  216. "combined with another zone\n" ) );
  217. }
  218. break;
  219. }
  220. if( zone == ref ) // picked zone found
  221. {
  222. if( aPickList.GetPickedItemStatus( kk ) != UR_NEW )
  223. {
  224. ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
  225. if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
  226. {
  227. delete zcopy; // Delete copy
  228. aPickList.RemovePicker( kk );
  229. kk--;
  230. }
  231. }
  232. break;
  233. }
  234. }
  235. }
  236. // Add new zones in main pick list, and remove pickers from Auxiliary List
  237. for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
  238. {
  239. if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_NEW )
  240. {
  241. ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
  242. aPickList.PushItem( picker );
  243. aAuxiliaryList.RemovePicker( ii );
  244. }
  245. else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_DELETED )
  246. {
  247. delete aAuxiliaryList.GetPickedItemLink( ii );
  248. aAuxiliaryList.RemovePicker( ii );
  249. }
  250. else
  251. ii++;
  252. }
  253. // Should not occur:
  254. wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
  255. wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
  256. }