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.

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