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.

965 lines
31 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
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
14 years ago
18 years ago
18 years ago
14 years ago
14 years ago
18 years ago
14 years ago
18 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
14 years ago
12 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* 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
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
  7. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file zones_by_polygon.cpp
  28. */
  29. #include <fctsys.h>
  30. #include <kiface_i.h>
  31. #include <class_drawpanel.h>
  32. #include <confirm.h>
  33. #include <wxPcbStruct.h>
  34. #include <class_board.h>
  35. #include <class_zone.h>
  36. #include <pcbnew.h>
  37. #include <zones.h>
  38. #include <pcbnew_id.h>
  39. #include <protos.h>
  40. #include <zones_functions_for_undo_redo.h>
  41. #include <drc_stuff.h>
  42. // Outline creation:
  43. static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC );
  44. static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  45. const wxPoint& aPosition, bool aErase );
  46. // Corner moving
  47. static void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC );
  48. static void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel,
  49. wxDC* aDC,
  50. const wxPoint& aPosition,
  51. bool aErase );
  52. // Local variables
  53. static wxPoint s_CornerInitialPosition; // Used to abort a move corner command
  54. static bool s_CornerIsNew; // Used to abort a move corner command (if it is a new corner, it must be deleted)
  55. static bool s_AddCutoutToCurrentZone; // if true, the next outline will be added to s_CurrentZone
  56. static ZONE_CONTAINER* s_CurrentZone; // if != NULL, these ZONE_CONTAINER params will be used for the next zone
  57. static wxPoint s_CursorLastPosition; // in move zone outline, last cursor position. Used to calculate the move vector
  58. static PICKED_ITEMS_LIST s_PickedList; // a picked list to save zones for undo/redo command
  59. static PICKED_ITEMS_LIST s_AuxiliaryList; // a picked list to store zones that are deleted or added when combined
  60. void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* aZone )
  61. {
  62. if( !aZone )
  63. return;
  64. s_AddCutoutToCurrentZone = false;
  65. s_CurrentZone = aZone;
  66. // set zone settings to the current zone
  67. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  68. zoneInfo << *aZone;
  69. SetZoneSettings( zoneInfo );
  70. // Use the general event handler to set others params (like toolbar)
  71. wxCommandEvent evt;
  72. evt.SetId( aZone->GetIsKeepout() ? ID_PCB_KEEPOUT_AREA_BUTT : ID_PCB_ZONES_BUTT );
  73. OnSelectTool( evt );
  74. }
  75. void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* aZone )
  76. {
  77. if( !aZone )
  78. return;
  79. s_AddCutoutToCurrentZone = true;
  80. s_CurrentZone = aZone;
  81. // set zones setup to the current zone
  82. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  83. zoneInfo << *aZone;
  84. SetZoneSettings( zoneInfo );
  85. // Use the general event handle to set others params (like toolbar)
  86. wxCommandEvent evt;
  87. evt.SetId( aZone->GetIsKeepout() ? ID_PCB_KEEPOUT_AREA_BUTT : ID_PCB_ZONES_BUTT );
  88. OnSelectTool( evt );
  89. }
  90. void PCB_EDIT_FRAME::duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone )
  91. {
  92. ZONE_CONTAINER* newZone = new ZONE_CONTAINER( *aZone );
  93. newZone->UnFill();
  94. ZONE_SETTINGS zoneSettings;
  95. zoneSettings << *aZone;
  96. bool success;
  97. if( aZone->GetIsKeepout() )
  98. success = InvokeKeepoutAreaEditor( this, &zoneSettings );
  99. else if( aZone->IsOnCopperLayer() )
  100. success = InvokeCopperZonesEditor( this, &zoneSettings );
  101. else
  102. success = InvokeNonCopperZonesEditor( this, aZone, &zoneSettings );
  103. // If the new zone is on the same layer as the the initial zone,
  104. // do nothing
  105. if( success && ( aZone->GetLayer() == zoneSettings.m_CurrentZone_Layer ) )
  106. {
  107. DisplayError( this,
  108. _( "The duplicated zone cannot be on the same layer as the original zone." ) );
  109. success = false;
  110. }
  111. if( success )
  112. {
  113. zoneSettings.ExportSetting( *newZone );
  114. newZone->Outline()->Hatch();
  115. s_AuxiliaryList.ClearListAndDeleteItems();
  116. s_PickedList.ClearListAndDeleteItems();
  117. SaveCopyOfZones( s_PickedList, GetBoard(), newZone->GetNetCode(), newZone->GetLayer() );
  118. GetBoard()->Add( newZone );
  119. ITEM_PICKER picker( newZone, UR_NEW );
  120. s_PickedList.PushItem( picker );
  121. GetScreen()->SetCurItem( NULL ); // This outline may be deleted when merging outlines
  122. // Combine zones if possible
  123. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, newZone );
  124. // Redraw zones
  125. GetBoard()->RedrawAreasOutlines( m_canvas, aDC, GR_OR, newZone->GetLayer() );
  126. GetBoard()->RedrawFilledAreas( m_canvas, aDC, GR_OR, newZone->GetLayer() );
  127. if( GetBoard()->GetAreaIndex( newZone ) >= 0
  128. && GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( newZone, true ) )
  129. {
  130. DisplayInfoMessage( this, _( "Warning: The new zone fails DRC" ) );
  131. }
  132. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  133. SaveCopyInUndoList( s_PickedList, UR_UNSPECIFIED );
  134. s_PickedList.ClearItemsList();
  135. OnModify();
  136. }
  137. else
  138. delete newZone;
  139. }
  140. int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC )
  141. {
  142. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  143. if( !zone )
  144. return 0;
  145. if( !zone->GetNumCorners() )
  146. return 0;
  147. zone->DrawWhileCreateOutline( m_canvas, DC, GR_XOR );
  148. if( zone->GetNumCorners() > 2 )
  149. {
  150. zone->Outline()->DeleteCorner( zone->GetNumCorners() - 1 );
  151. if( m_canvas->IsMouseCaptured() )
  152. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  153. }
  154. else
  155. {
  156. m_canvas->SetMouseCapture( NULL, NULL );
  157. SetCurItem( NULL );
  158. zone->RemoveAllContours();
  159. zone->ClearFlags();
  160. }
  161. return zone->GetNumCorners();
  162. }
  163. /**
  164. * Function Abort_Zone_Create_Outline
  165. * cancels the Begin_Zone command if at least one EDGE_ZONE was created.
  166. */
  167. static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC )
  168. {
  169. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
  170. ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
  171. if( zone )
  172. {
  173. zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
  174. zone->RemoveAllContours();
  175. if( zone->IsNew() )
  176. {
  177. delete zone;
  178. pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
  179. }
  180. else
  181. zone->ClearFlags();
  182. }
  183. pcbframe->SetCurItem( NULL );
  184. s_AddCutoutToCurrentZone = false;
  185. s_CurrentZone = NULL;
  186. Panel->SetMouseCapture( NULL, NULL );
  187. }
  188. void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* aZone,
  189. int corner_id, bool IsNewCorner )
  190. {
  191. if( aZone->IsOnCopperLayer() ) // Show the Net
  192. {
  193. if( GetBoard()->IsHighLightNetON() && DC )
  194. {
  195. HighLight( DC ); // Remove old highlight selection
  196. }
  197. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  198. zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
  199. SetZoneSettings( zoneInfo );
  200. GetBoard()->SetHighLightNet( aZone->GetNetCode() );
  201. if( DC )
  202. HighLight( DC );
  203. }
  204. // Prepare copy of old zones, for undo/redo.
  205. // if the corner is new, remove it from list, save and insert it in list
  206. int cx = aZone->Outline()->GetX( corner_id );
  207. int cy = aZone->Outline()->GetY( corner_id );
  208. if ( IsNewCorner )
  209. aZone->Outline()->DeleteCorner( corner_id );
  210. s_AuxiliaryList.ClearListAndDeleteItems();
  211. s_PickedList.ClearListAndDeleteItems();
  212. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  213. if ( IsNewCorner )
  214. aZone->Outline()->InsertCorner(corner_id-1, cx, cy );
  215. aZone->SetFlags( IN_EDIT );
  216. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  217. Abort_Zone_Move_Corner_Or_Outlines );
  218. s_CornerInitialPosition = aZone->GetCornerPosition( corner_id );
  219. s_CornerIsNew = IsNewCorner;
  220. s_AddCutoutToCurrentZone = false;
  221. s_CurrentZone = NULL;
  222. }
  223. void PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge( wxDC* DC,
  224. ZONE_CONTAINER* aZone,
  225. int corner_id )
  226. {
  227. aZone->SetFlags( IS_DRAGGED );
  228. aZone->SetSelectedCorner( corner_id );
  229. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  230. Abort_Zone_Move_Corner_Or_Outlines );
  231. s_CursorLastPosition = s_CornerInitialPosition = GetCrossHairPosition();
  232. s_AddCutoutToCurrentZone = false;
  233. s_CurrentZone = NULL;
  234. s_PickedList.ClearListAndDeleteItems();
  235. s_AuxiliaryList.ClearListAndDeleteItems();
  236. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  237. }
  238. void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* aZone )
  239. {
  240. // Show the Net
  241. if( aZone->IsOnCopperLayer() ) // Show the Net
  242. {
  243. if( GetBoard()->IsHighLightNetON() )
  244. {
  245. HighLight( DC ); // Remove old highlight selection
  246. }
  247. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  248. zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
  249. SetZoneSettings( zoneInfo );
  250. GetBoard()->SetHighLightNet( aZone->GetNetCode() );
  251. HighLight( DC );
  252. }
  253. s_PickedList.ClearListAndDeleteItems();
  254. s_AuxiliaryList.ClearListAndDeleteItems();
  255. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  256. aZone->SetFlags( IS_MOVED );
  257. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  258. Abort_Zone_Move_Corner_Or_Outlines );
  259. s_CursorLastPosition = s_CornerInitialPosition = GetCrossHairPosition();
  260. s_CornerIsNew = false;
  261. s_AddCutoutToCurrentZone = false;
  262. s_CurrentZone = NULL;
  263. }
  264. void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* aZone )
  265. {
  266. aZone->ClearFlags();
  267. m_canvas->SetMouseCapture( NULL, NULL );
  268. if( DC )
  269. aZone->Draw( m_canvas, DC, GR_OR );
  270. OnModify();
  271. s_AddCutoutToCurrentZone = false;
  272. s_CurrentZone = NULL;
  273. SetCurItem( NULL ); // This outline can be deleted when merging outlines
  274. // Combine zones if possible
  275. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  276. m_canvas->Refresh();
  277. int ii = GetBoard()->GetAreaIndex( aZone ); // test if aZone exists
  278. if( ii < 0 )
  279. aZone = NULL; // was removed by combining zones
  280. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  281. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  282. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  283. int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( aZone, true );
  284. if( error_count )
  285. {
  286. DisplayError( this, _( "Area: DRC outline error" ) );
  287. }
  288. }
  289. void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* aZone )
  290. {
  291. OnModify();
  292. if( aZone->Outline()->GetCornersCount() <= 3 )
  293. {
  294. m_canvas->RefreshDrawingRect( aZone->GetBoundingBox() );
  295. if( DC )
  296. { // Remove the full zone because this is no more an area
  297. aZone->UnFill();
  298. aZone->DrawFilledArea( m_canvas, DC, GR_XOR );
  299. }
  300. GetBoard()->Delete( aZone );
  301. return;
  302. }
  303. LAYER_ID layer = aZone->GetLayer();
  304. if( DC )
  305. {
  306. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_XOR, layer );
  307. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_XOR, layer );
  308. }
  309. s_AuxiliaryList.ClearListAndDeleteItems();
  310. s_PickedList. ClearListAndDeleteItems();
  311. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  312. aZone->Outline()->DeleteCorner( aZone->GetSelectedCorner() );
  313. // modify zones outlines according to the new aZone shape
  314. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  315. if( DC )
  316. {
  317. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, layer );
  318. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_OR, layer );
  319. }
  320. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  321. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  322. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  323. int ii = GetBoard()->GetAreaIndex( aZone ); // test if aZone exists
  324. if( ii < 0 )
  325. aZone = NULL; // aZone does not exist anymore, after combining zones
  326. int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( aZone, true );
  327. if( error_count )
  328. {
  329. DisplayError( this, _( "Area: DRC outline error" ) );
  330. }
  331. }
  332. /**
  333. * Function Abort_Zone_Move_Corner_Or_Outlines
  334. * cancels the Begin_Zone state if at least one EDGE_ZONE has been created.
  335. */
  336. void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC )
  337. {
  338. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
  339. ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
  340. if( zone->IsMoving() )
  341. {
  342. wxPoint offset;
  343. offset = s_CornerInitialPosition - s_CursorLastPosition;
  344. zone->Move( offset );
  345. }
  346. else if( zone->IsDragging() )
  347. {
  348. wxPoint offset = s_CornerInitialPosition - s_CursorLastPosition;
  349. int selection = zone->GetSelectedCorner();
  350. zone->MoveEdge( offset, selection );
  351. }
  352. else
  353. {
  354. if( s_CornerIsNew )
  355. {
  356. zone->Outline()->DeleteCorner( zone->GetSelectedCorner() );
  357. }
  358. else
  359. {
  360. wxPoint pos = s_CornerInitialPosition;
  361. zone->Outline()->MoveCorner( zone->GetSelectedCorner(), pos.x, pos.y );
  362. }
  363. }
  364. Panel->SetMouseCapture( NULL, NULL );
  365. s_AuxiliaryList.ClearListAndDeleteItems();
  366. s_PickedList. ClearListAndDeleteItems();
  367. Panel->Refresh();
  368. pcbframe->SetCurItem( NULL );
  369. zone->ClearFlags();
  370. s_AddCutoutToCurrentZone = false;
  371. s_CurrentZone = NULL;
  372. }
  373. /// Redraws the zone outline when moving a corner according to the cursor position
  374. void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  375. const wxPoint& aPosition, bool aErase )
  376. {
  377. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
  378. ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
  379. if( aErase ) // Undraw edge in old position
  380. {
  381. zone->Draw( aPanel, aDC, GR_XOR );
  382. }
  383. wxPoint pos = pcbframe->GetCrossHairPosition();
  384. if( zone->IsMoving() )
  385. {
  386. wxPoint offset;
  387. offset = pos - s_CursorLastPosition;
  388. zone->Move( offset );
  389. s_CursorLastPosition = pos;
  390. }
  391. else if( zone->IsDragging() )
  392. {
  393. wxPoint offset = pos - s_CursorLastPosition;
  394. int selection = zone->GetSelectedCorner();
  395. zone->MoveEdge( offset, selection );
  396. s_CursorLastPosition = pos;
  397. }
  398. else
  399. {
  400. zone->Outline()->MoveCorner( zone->GetSelectedCorner(), pos.x, pos.y );
  401. }
  402. zone->Draw( aPanel, aDC, GR_XOR );
  403. }
  404. int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC )
  405. {
  406. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  407. // verify if s_CurrentZone exists (could be deleted since last selection) :
  408. int ii;
  409. for( ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
  410. {
  411. if( s_CurrentZone == GetBoard()->GetArea( ii ) )
  412. break;
  413. }
  414. if( ii >= GetBoard()->GetAreaCount() ) // Not found: could be deleted since last selection
  415. {
  416. s_AddCutoutToCurrentZone = false;
  417. s_CurrentZone = NULL;
  418. }
  419. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  420. // Verify if a new zone is allowed on this layer:
  421. if( zone == NULL )
  422. {
  423. if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT && !IsCopperLayer( GetActiveLayer() ) )
  424. {
  425. DisplayError( this,
  426. _( "Error: a keepout area is allowed only on copper layers" ) );
  427. return 0;
  428. }
  429. }
  430. // If no zone contour in progress, a new zone is being created,
  431. if( zone == NULL )
  432. {
  433. zone = GetBoard()->m_CurrentZoneContour = new ZONE_CONTAINER( GetBoard() );
  434. zone->SetFlags( IS_NEW );
  435. zone->SetTimeStamp( GetNewTimeStamp() );
  436. }
  437. if( zone->GetNumCorners() == 0 ) // Start a new contour: init zone params (net, layer ...)
  438. {
  439. if( !s_CurrentZone ) // A new outline is created, from scratch
  440. {
  441. ZONE_EDIT_T edited;
  442. // Init zone params to reasonable values
  443. zone->SetLayer( GetActiveLayer() );
  444. // Prompt user for parameters:
  445. m_canvas->SetIgnoreMouseEvents( true );
  446. if( zone->IsOnCopperLayer() )
  447. {
  448. // Put a zone on a copper layer
  449. if( GetBoard()->GetHighLightNetCode() > 0 )
  450. {
  451. zoneInfo.m_NetcodeSelection = GetBoard()->GetHighLightNetCode();
  452. zone->SetNetCode( zoneInfo.m_NetcodeSelection );
  453. }
  454. double tmp = ZONE_THERMAL_RELIEF_GAP_MIL;
  455. wxConfigBase* cfg = Kiface().KifaceSettings();
  456. cfg->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, &tmp );
  457. zoneInfo.m_ThermalReliefGap = KiROUND( tmp * IU_PER_MILS);
  458. tmp = ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL;
  459. cfg->Read( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, &tmp );
  460. zoneInfo.m_ThermalReliefCopperBridge = KiROUND( tmp * IU_PER_MILS );
  461. tmp = ZONE_CLEARANCE_MIL;
  462. cfg->Read( ZONE_CLEARANCE_WIDTH_STRING_KEY, &tmp );
  463. zoneInfo.m_ZoneClearance = KiROUND( tmp * IU_PER_MILS );
  464. tmp = ZONE_THICKNESS_MIL;
  465. cfg->Read( ZONE_MIN_THICKNESS_WIDTH_STRING_KEY, &tmp );
  466. zoneInfo.m_ZoneMinThickness = KiROUND( tmp * IU_PER_MILS );
  467. zoneInfo.m_CurrentZone_Layer = zone->GetLayer();
  468. if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT )
  469. {
  470. zoneInfo.SetIsKeepout( true );
  471. // Netcode, netname and some other settings are irrelevant,
  472. // so ensure they are cleared
  473. zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
  474. zoneInfo.SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_NONE );
  475. zoneInfo.SetCornerRadius( 0 );
  476. edited = InvokeKeepoutAreaEditor( this, &zoneInfo );
  477. }
  478. else
  479. {
  480. zoneInfo.SetIsKeepout( false );
  481. edited = InvokeCopperZonesEditor( this, &zoneInfo );
  482. }
  483. }
  484. else // Put a zone on a non copper layer (technical layer)
  485. {
  486. zoneInfo.SetIsKeepout( false );
  487. zoneInfo.m_NetcodeSelection = 0; // No net for non copper zones
  488. edited = InvokeNonCopperZonesEditor( this, zone, &zoneInfo );
  489. }
  490. m_canvas->MoveCursorToCrossHair();
  491. m_canvas->SetIgnoreMouseEvents( false );
  492. if( edited == ZONE_ABORT )
  493. {
  494. GetBoard()->m_CurrentZoneContour = NULL;
  495. delete zone;
  496. return 0;
  497. }
  498. // Switch active layer to the selected zone layer
  499. SetActiveLayer( zoneInfo.m_CurrentZone_Layer );
  500. SetZoneSettings( zoneInfo );
  501. }
  502. else
  503. {
  504. // Start a new contour: init zone params (net and layer) from an existing
  505. // zone (add cutout or similar zone)
  506. zoneInfo.m_CurrentZone_Layer = s_CurrentZone->GetLayer();
  507. SetActiveLayer( s_CurrentZone->GetLayer() );
  508. zoneInfo << *s_CurrentZone;
  509. SetZoneSettings( zoneInfo );
  510. }
  511. // Show the Net for zones on copper layers
  512. if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) &&
  513. !zoneInfo.GetIsKeepout() )
  514. {
  515. if( s_CurrentZone )
  516. {
  517. zoneInfo.m_NetcodeSelection = s_CurrentZone->GetNetCode();
  518. GetBoard()->SetZoneSettings( zoneInfo );
  519. }
  520. if( GetBoard()->IsHighLightNetON() )
  521. {
  522. HighLight( DC ); // Remove old highlight selection
  523. }
  524. GetBoard()->SetHighLightNet( zoneInfo.m_NetcodeSelection );
  525. HighLight( DC );
  526. }
  527. if( !s_AddCutoutToCurrentZone )
  528. s_CurrentZone = NULL; // the zone is used only once ("add similar zone" command)
  529. }
  530. // if first segment
  531. if( zone->GetNumCorners() == 0 )
  532. {
  533. zoneInfo.ExportSetting( *zone );
  534. zone->Outline()->Start( zoneInfo.m_CurrentZone_Layer,
  535. GetCrossHairPosition().x,
  536. GetCrossHairPosition().y,
  537. zone->GetHatchStyle() );
  538. zone->AppendCorner( GetCrossHairPosition() );
  539. if( g_Drc_On && (m_drc->Drc( zone, 0 ) == BAD_DRC) && zone->IsOnCopperLayer() )
  540. {
  541. zone->ClearFlags();
  542. zone->RemoveAllContours();
  543. // use the form of SetCurItem() which does not write to the msg panel,
  544. // SCREEN::SetCurItem(), so the DRC error remains on screen.
  545. // PCB_EDIT_FRAME::SetCurItem() calls DisplayInfo().
  546. GetScreen()->SetCurItem( NULL );
  547. DisplayError( this,
  548. _( "DRC error: this start point is inside or too close an other area" ) );
  549. return 0;
  550. }
  551. SetCurItem( zone );
  552. m_canvas->SetMouseCapture( Show_New_Edge_While_Move_Mouse, Abort_Zone_Create_Outline );
  553. }
  554. else // edge in progress:
  555. {
  556. ii = zone->GetNumCorners() - 1;
  557. // edge in progress : the current corner coordinate was set
  558. // by Show_New_Edge_While_Move_Mouse
  559. if( zone->GetCornerPosition( ii - 1 ) != zone->GetCornerPosition( ii ) )
  560. {
  561. if( !g_Drc_On || !zone->IsOnCopperLayer() || ( m_drc->Drc( zone, ii - 1 ) == OK_DRC ) )
  562. {
  563. // Ok, we can add a new corner
  564. if( m_canvas->IsMouseCaptured() )
  565. m_canvas->CallMouseCapture( DC, wxPoint(0,0), false );
  566. zone->AppendCorner( GetCrossHairPosition() );
  567. SetCurItem( zone ); // calls DisplayInfo().
  568. if( m_canvas->IsMouseCaptured() )
  569. m_canvas->CallMouseCapture( DC, wxPoint(0,0), false );
  570. }
  571. }
  572. }
  573. return zone->GetNumCorners();
  574. }
  575. bool PCB_EDIT_FRAME::End_Zone( wxDC* DC )
  576. {
  577. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  578. if( !zone )
  579. return true;
  580. // Validate the current outline:
  581. if( zone->GetNumCorners() <= 2 ) // An outline must have 3 corners or more
  582. {
  583. Abort_Zone_Create_Outline( m_canvas, DC );
  584. return true;
  585. }
  586. // Remove the last corner if is is at the same location as the prevoius corner
  587. zone->Outline()->RemoveNullSegments();
  588. // Validate the current edge:
  589. int icorner = zone->GetNumCorners() - 1;
  590. if( zone->IsOnCopperLayer() )
  591. {
  592. if( g_Drc_On && m_drc->Drc( zone, icorner - 1 ) == BAD_DRC ) // we can't validate last edge
  593. return false;
  594. if( g_Drc_On && m_drc->Drc( zone, icorner ) == BAD_DRC ) // we can't validate the closing edge
  595. {
  596. DisplayError( this,
  597. _( "DRC error: closing this area creates a DRC error with an other area" ) );
  598. m_canvas->MoveCursorToCrossHair();
  599. return false;
  600. }
  601. }
  602. zone->ClearFlags();
  603. zone->DrawWhileCreateOutline( m_canvas, DC, GR_XOR );
  604. m_canvas->SetMouseCapture( NULL, NULL );
  605. // Undraw old drawings, because they can have important changes
  606. LAYER_ID layer = zone->GetLayer();
  607. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_XOR, layer );
  608. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_XOR, layer );
  609. // Save initial zones configuration, for undo/redo, before adding new zone
  610. s_AuxiliaryList.ClearListAndDeleteItems();
  611. s_PickedList.ClearListAndDeleteItems();
  612. SaveCopyOfZones(s_PickedList, GetBoard(), zone->GetNetCode(), zone->GetLayer() );
  613. // Put new zone in list
  614. if( !s_CurrentZone )
  615. {
  616. zone->Outline()->CloseLastContour(); // Close the current corner list
  617. GetBoard()->Add( zone );
  618. GetBoard()->m_CurrentZoneContour = NULL;
  619. // Add this zone in picked list, as new item
  620. ITEM_PICKER picker( zone, UR_NEW );
  621. s_PickedList.PushItem( picker );
  622. }
  623. else // Append this outline as a cutout to an existing zone
  624. {
  625. for( int ii = 0; ii < zone->GetNumCorners(); ii++ )
  626. {
  627. s_CurrentZone->AppendCorner( zone->GetCornerPosition( ii ) );
  628. }
  629. s_CurrentZone->Outline()->CloseLastContour(); // Close the current corner list
  630. zone->RemoveAllContours(); // All corners are copied in s_CurrentZone. Free corner list.
  631. zone = s_CurrentZone;
  632. }
  633. s_AddCutoutToCurrentZone = false;
  634. s_CurrentZone = NULL;
  635. GetScreen()->SetCurItem( NULL ); // This outline can be deleted when merging outlines
  636. // Combine zones if possible :
  637. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, zone );
  638. // Redraw the real edge zone :
  639. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, layer );
  640. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_OR, layer );
  641. int ii = GetBoard()->GetAreaIndex( zone ); // test if zone exists
  642. if( ii < 0 )
  643. zone = NULL; // was removed by combining zones
  644. int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( zone, true );
  645. if( error_count )
  646. {
  647. DisplayError( this, _( "Area: DRC outline error" ) );
  648. }
  649. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  650. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  651. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  652. OnModify();
  653. return true;
  654. }
  655. /* Redraws the zone outlines when moving mouse
  656. */
  657. static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  658. const wxPoint& aPosition, bool aErase )
  659. {
  660. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
  661. wxPoint c_pos = pcbframe->GetCrossHairPosition();
  662. ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
  663. if( !zone )
  664. return;
  665. int icorner = zone->GetNumCorners() - 1;
  666. if( icorner < 1 )
  667. return; // We must have 2 (or more) corners
  668. if( aErase ) // Undraw edge in old position
  669. {
  670. zone->DrawWhileCreateOutline( aPanel, aDC );
  671. }
  672. // Redraw the current edge in its new position
  673. if( pcbframe->GetZoneSettings().m_Zone_45_Only )
  674. {
  675. // calculate the new position as allowed
  676. wxPoint StartPoint = zone->GetCornerPosition( icorner - 1 );
  677. CalculateSegmentEndPoint( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y );
  678. }
  679. zone->SetCornerPosition( icorner, c_pos );
  680. zone->DrawWhileCreateOutline( aPanel, aDC );
  681. }
  682. void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* aZone )
  683. {
  684. ZONE_EDIT_T edited;
  685. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  686. m_canvas->SetIgnoreMouseEvents( true );
  687. // Save initial zones configuration, for undo/redo, before adding new zone
  688. // note the net name and the layer can be changed, so we must save all zones
  689. s_AuxiliaryList.ClearListAndDeleteItems();
  690. s_PickedList.ClearListAndDeleteItems();
  691. SaveCopyOfZones(s_PickedList, GetBoard(), -1, UNDEFINED_LAYER );
  692. if( aZone->GetIsKeepout() )
  693. {
  694. // edit a keepout area on a copper layer
  695. zoneInfo << *aZone;
  696. edited = InvokeKeepoutAreaEditor( this, &zoneInfo );
  697. }
  698. else if( IsCopperLayer( aZone->GetLayer() ) )
  699. {
  700. // edit a zone on a copper layer
  701. zoneInfo << *aZone;
  702. edited = InvokeCopperZonesEditor( this, &zoneInfo );
  703. }
  704. else
  705. {
  706. edited = InvokeNonCopperZonesEditor( this, aZone, &zoneInfo );
  707. }
  708. m_canvas->MoveCursorToCrossHair();
  709. m_canvas->SetIgnoreMouseEvents( false );
  710. if( edited == ZONE_ABORT )
  711. {
  712. s_AuxiliaryList.ClearListAndDeleteItems();
  713. s_PickedList.ClearListAndDeleteItems();
  714. return;
  715. }
  716. SetZoneSettings( zoneInfo );
  717. if( edited == ZONE_EXPORT_VALUES )
  718. {
  719. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  720. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  721. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  722. return;
  723. }
  724. // Undraw old zone outlines
  725. for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
  726. {
  727. ZONE_CONTAINER* edge_zone = GetBoard()->GetArea( ii );
  728. edge_zone->Draw( m_canvas, DC, GR_XOR );
  729. }
  730. zoneInfo.ExportSetting( *aZone );
  731. NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
  732. if( net ) // net == NULL should not occur
  733. aZone->SetNetCode( net->GetNet() );
  734. // Combine zones if possible
  735. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  736. // Redraw the real new zone outlines
  737. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, UNDEFINED_LAYER );
  738. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  739. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  740. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
  741. OnModify();
  742. }
  743. void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* aZone )
  744. {
  745. int ncont = aZone->Outline()->GetContour( aZone->GetSelectedCorner() );
  746. EDA_RECT dirty = aZone->GetBoundingBox();
  747. // For compatibility with old boards: remove old SEGZONE fill segments
  748. Delete_OldZone_Fill( NULL, aZone->GetTimeStamp() );
  749. // Remove current filling:
  750. aZone->UnFill();
  751. if( ncont == 0 ) // This is the main outline: remove all
  752. {
  753. SaveCopyInUndoList( aZone, UR_DELETED );
  754. GetBoard()->Remove( aZone );
  755. }
  756. else
  757. {
  758. SaveCopyInUndoList( aZone, UR_CHANGED );
  759. aZone->Outline()->RemoveContour( ncont );
  760. }
  761. m_canvas->RefreshDrawingRect( dirty );
  762. OnModify();
  763. }