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.

1029 lines
34 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
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
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-2017 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 <pcb_edit_frame.h>
  34. #include <board_commit.h>
  35. #include <view/view.h>
  36. #include <class_board.h>
  37. #include <class_zone.h>
  38. #include <pcbnew.h>
  39. #include <zones.h>
  40. #include <pcbnew_id.h>
  41. #include <protos.h>
  42. #include <zones_functions_for_undo_redo.h>
  43. #include <drc.h>
  44. #include <connectivity_data.h>
  45. #include <widgets/progress_reporter.h>
  46. #include <zone_filler.h>
  47. // Outline creation:
  48. static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC );
  49. static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  50. const wxPoint& aPosition, bool aErase );
  51. // Corner moving
  52. static void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC );
  53. static void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel,
  54. wxDC* aDC,
  55. const wxPoint& aPosition,
  56. bool aErase );
  57. // Local variables
  58. static wxPoint s_CornerInitialPosition; // Used to abort a move corner command
  59. static bool s_CornerIsNew; // Used to abort a move corner command (if it is a new corner, it must be deleted)
  60. static bool s_AddCutoutToCurrentZone; // if true, the next outline will be added to s_CurrentZone
  61. static ZONE_CONTAINER* s_CurrentZone; // if != NULL, these ZONE_CONTAINER params will be used for the next zone
  62. static wxPoint s_CursorLastPosition; // in move zone outline, last cursor position. Used to calculate the move vector
  63. static PICKED_ITEMS_LIST s_PickedList; // a picked list to save zones for undo/redo command
  64. static PICKED_ITEMS_LIST s_AuxiliaryList; // a picked list to store zones that are deleted or added when combined
  65. void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* aZone )
  66. {
  67. if( !aZone )
  68. return;
  69. s_AddCutoutToCurrentZone = false;
  70. s_CurrentZone = aZone;
  71. // set zone settings to the current zone
  72. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  73. zoneInfo << *aZone;
  74. SetZoneSettings( zoneInfo );
  75. // Use the general event handler to set others params (like toolbar)
  76. wxCommandEvent evt;
  77. evt.SetId( aZone->GetIsKeepout() ? ID_PCB_KEEPOUT_AREA_BUTT : ID_PCB_ZONES_BUTT );
  78. OnSelectTool( evt );
  79. }
  80. void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* aZone )
  81. {
  82. if( !aZone )
  83. return;
  84. s_AddCutoutToCurrentZone = true;
  85. s_CurrentZone = aZone;
  86. // set zones setup to the current zone
  87. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  88. zoneInfo << *aZone;
  89. SetZoneSettings( zoneInfo );
  90. // Use the general event handle to set others params (like toolbar)
  91. wxCommandEvent evt;
  92. evt.SetId( aZone->GetIsKeepout() ? ID_PCB_KEEPOUT_AREA_BUTT : ID_PCB_ZONES_BUTT );
  93. OnSelectTool( evt );
  94. }
  95. void PCB_EDIT_FRAME::duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone )
  96. {
  97. ZONE_CONTAINER* newZone = new ZONE_CONTAINER( *aZone );
  98. newZone->UnFill();
  99. ZONE_SETTINGS zoneSettings;
  100. zoneSettings << *aZone;
  101. bool success;
  102. if( aZone->GetIsKeepout() )
  103. success = InvokeKeepoutAreaEditor( this, &zoneSettings );
  104. else if( aZone->IsOnCopperLayer() )
  105. success = InvokeCopperZonesEditor( this, &zoneSettings );
  106. else
  107. success = InvokeNonCopperZonesEditor( this, aZone, &zoneSettings );
  108. // If the new zone is on the same layer as the the initial zone,
  109. // do nothing
  110. if( success )
  111. {
  112. if( aZone->GetIsKeepout() && ( aZone->GetLayerSet() == zoneSettings.m_Layers ) )
  113. {
  114. DisplayErrorMessage(
  115. this, _( "The duplicated zone cannot be on the same layers as the original zone." ) );
  116. success = false;
  117. }
  118. else if( !aZone->GetIsKeepout() && ( aZone->GetLayer() == zoneSettings.m_CurrentZone_Layer ) )
  119. {
  120. DisplayErrorMessage(
  121. this, _( "The duplicated zone cannot be on the same layer as the original zone." ) );
  122. success = false;
  123. }
  124. }
  125. if( success )
  126. {
  127. zoneSettings.ExportSetting( *newZone );
  128. newZone->Hatch();
  129. s_AuxiliaryList.ClearListAndDeleteItems();
  130. s_PickedList.ClearListAndDeleteItems();
  131. SaveCopyOfZones( s_PickedList, GetBoard(), newZone->GetNetCode(), newZone->GetLayer() );
  132. GetBoard()->Add( newZone );
  133. ITEM_PICKER picker( newZone, UR_NEW );
  134. s_PickedList.PushItem( picker );
  135. GetScreen()->SetCurItem( NULL ); // This outline may be deleted when merging outlines
  136. // Combine zones if possible
  137. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, newZone );
  138. // Redraw zones
  139. GetBoard()->RedrawAreasOutlines( m_canvas, aDC, GR_OR, newZone->GetLayer() );
  140. GetBoard()->RedrawFilledAreas( m_canvas, aDC, GR_OR, newZone->GetLayer() );
  141. DRC drc( this );
  142. if( GetBoard()->GetAreaIndex( newZone ) >= 0
  143. && drc.TestZoneToZoneOutline( newZone, true ) )
  144. {
  145. DisplayInfoMessage( this, _( "Warning: The new zone fails DRC" ) );
  146. }
  147. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  148. SaveCopyInUndoList( s_PickedList, UR_UNSPECIFIED );
  149. s_PickedList.ClearItemsList();
  150. OnModify();
  151. }
  152. else
  153. delete newZone;
  154. }
  155. int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC )
  156. {
  157. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  158. if( !zone )
  159. return 0;
  160. if( !zone->GetNumCorners() )
  161. return 0;
  162. zone->DrawWhileCreateOutline( m_canvas, DC, GR_XOR );
  163. if( zone->GetNumCorners() > 2 )
  164. {
  165. zone->Outline()->RemoveVertex( zone->GetNumCorners() - 1 );
  166. if( m_canvas->IsMouseCaptured() )
  167. m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
  168. }
  169. else
  170. {
  171. m_canvas->SetMouseCapture( NULL, NULL );
  172. SetCurItem( NULL );
  173. zone->RemoveAllContours();
  174. zone->ClearFlags();
  175. }
  176. return zone->GetNumCorners();
  177. }
  178. /**
  179. * Function Abort_Zone_Create_Outline
  180. * cancels the Begin_Zone command if at least one EDGE_ZONE was created.
  181. */
  182. static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC )
  183. {
  184. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
  185. ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
  186. if( zone )
  187. {
  188. zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
  189. zone->RemoveAllContours();
  190. if( zone->IsNew() )
  191. {
  192. delete zone;
  193. pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
  194. }
  195. else
  196. zone->ClearFlags();
  197. }
  198. pcbframe->SetCurItem( NULL );
  199. s_AddCutoutToCurrentZone = false;
  200. s_CurrentZone = NULL;
  201. Panel->SetMouseCapture( NULL, NULL );
  202. }
  203. void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* aZone,
  204. int corner_id, bool IsNewCorner )
  205. {
  206. if( aZone->IsOnCopperLayer() ) // Show the Net
  207. {
  208. if( GetBoard()->IsHighLightNetON() && DC )
  209. {
  210. HighLight( DC ); // Remove old highlight selection
  211. }
  212. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  213. zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
  214. SetZoneSettings( zoneInfo );
  215. GetBoard()->SetHighLightNet( aZone->GetNetCode() );
  216. if( DC )
  217. HighLight( DC );
  218. }
  219. // Prepare copy of old zones, for undo/redo.
  220. // if the corner is new, remove it from list, save and insert it in list
  221. VECTOR2I corner = aZone->Outline()->Vertex( corner_id );
  222. if ( IsNewCorner )
  223. aZone->Outline()->RemoveVertex( corner_id );
  224. s_AuxiliaryList.ClearListAndDeleteItems();
  225. s_PickedList.ClearListAndDeleteItems();
  226. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  227. if ( IsNewCorner )
  228. aZone->Outline()->InsertVertex(corner_id-1, corner );
  229. aZone->SetFlags( IN_EDIT );
  230. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  231. Abort_Zone_Move_Corner_Or_Outlines );
  232. s_CornerInitialPosition = static_cast<wxPoint>( aZone->GetCornerPosition( corner_id ) );
  233. s_CornerIsNew = IsNewCorner;
  234. s_AddCutoutToCurrentZone = false;
  235. s_CurrentZone = NULL;
  236. }
  237. void PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge( wxDC* DC,
  238. ZONE_CONTAINER* aZone,
  239. int corner_id )
  240. {
  241. aZone->SetFlags( IS_DRAGGED );
  242. aZone->SetSelectedCorner( corner_id );
  243. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  244. Abort_Zone_Move_Corner_Or_Outlines );
  245. s_CursorLastPosition = s_CornerInitialPosition = GetCrossHairPosition();
  246. s_AddCutoutToCurrentZone = false;
  247. s_CurrentZone = NULL;
  248. s_PickedList.ClearListAndDeleteItems();
  249. s_AuxiliaryList.ClearListAndDeleteItems();
  250. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  251. }
  252. void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* aZone )
  253. {
  254. // Show the Net
  255. if( aZone->IsOnCopperLayer() ) // Show the Net
  256. {
  257. if( GetBoard()->IsHighLightNetON() )
  258. {
  259. HighLight( DC ); // Remove old highlight selection
  260. }
  261. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  262. zoneInfo.m_NetcodeSelection = aZone->GetNetCode();
  263. SetZoneSettings( zoneInfo );
  264. GetBoard()->SetHighLightNet( aZone->GetNetCode() );
  265. HighLight( DC );
  266. }
  267. s_PickedList.ClearListAndDeleteItems();
  268. s_AuxiliaryList.ClearListAndDeleteItems();
  269. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  270. aZone->SetFlags( IS_MOVED );
  271. m_canvas->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse,
  272. Abort_Zone_Move_Corner_Or_Outlines );
  273. s_CursorLastPosition = s_CornerInitialPosition = GetCrossHairPosition();
  274. s_CornerIsNew = false;
  275. s_AddCutoutToCurrentZone = false;
  276. s_CurrentZone = NULL;
  277. }
  278. void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* aZone )
  279. {
  280. aZone->ClearFlags();
  281. m_canvas->SetMouseCapture( NULL, NULL );
  282. if( DC )
  283. aZone->Draw( m_canvas, DC, GR_OR );
  284. OnModify();
  285. s_AddCutoutToCurrentZone = false;
  286. s_CurrentZone = NULL;
  287. SetCurItem( NULL ); // This outline can be deleted when merging outlines
  288. // Combine zones if possible
  289. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  290. m_canvas->Refresh();
  291. int ii = GetBoard()->GetAreaIndex( aZone ); // test if aZone exists
  292. if( ii < 0 )
  293. aZone = NULL; // was removed by combining zones
  294. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  295. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  296. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  297. DRC drc( this );
  298. int error_count = drc.TestZoneToZoneOutline( aZone, true );
  299. if( error_count )
  300. {
  301. DisplayErrorMessage( this, _( "Area: DRC outline error" ) );
  302. }
  303. }
  304. void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* aZone )
  305. {
  306. OnModify();
  307. if( aZone->Outline()->TotalVertices() <= 3 )
  308. {
  309. m_canvas->RefreshDrawingRect( aZone->GetBoundingBox() );
  310. if( DC )
  311. { // Remove the full zone because this is no more an area
  312. aZone->UnFill();
  313. aZone->DrawFilledArea( m_canvas, DC, GR_XOR );
  314. }
  315. GetBoard()->Delete( aZone );
  316. return;
  317. }
  318. PCB_LAYER_ID layer = aZone->GetLayer();
  319. if( DC )
  320. {
  321. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_XOR, layer );
  322. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_XOR, layer );
  323. }
  324. s_AuxiliaryList.ClearListAndDeleteItems();
  325. s_PickedList. ClearListAndDeleteItems();
  326. SaveCopyOfZones( s_PickedList, GetBoard(), aZone->GetNetCode(), aZone->GetLayer() );
  327. aZone->Outline()->RemoveVertex( aZone->GetSelectedCorner() );
  328. // modify zones outlines according to the new aZone shape
  329. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  330. if( DC )
  331. {
  332. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, layer );
  333. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_OR, layer );
  334. }
  335. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  336. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  337. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  338. int ii = GetBoard()->GetAreaIndex( aZone ); // test if aZone exists
  339. if( ii < 0 )
  340. aZone = NULL; // aZone does not exist anymore, after combining zones
  341. DRC drc( this );
  342. int error_count = drc.TestZoneToZoneOutline( aZone, true );
  343. if( error_count )
  344. {
  345. DisplayErrorMessage( this, _( "Area: DRC outline error" ) );
  346. }
  347. }
  348. /**
  349. * Function Abort_Zone_Move_Corner_Or_Outlines
  350. * cancels the Begin_Zone state if at least one EDGE_ZONE has been created.
  351. */
  352. void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC )
  353. {
  354. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
  355. ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
  356. if( zone->IsMoving() )
  357. {
  358. wxPoint offset;
  359. offset = s_CornerInitialPosition - s_CursorLastPosition;
  360. zone->Move( offset );
  361. }
  362. else if( zone->IsDragging() )
  363. {
  364. wxPoint offset = s_CornerInitialPosition - s_CursorLastPosition;
  365. int selection = zone->GetSelectedCorner();
  366. zone->MoveEdge( offset, selection );
  367. }
  368. else
  369. {
  370. if( s_CornerIsNew )
  371. {
  372. zone->Outline()->RemoveVertex( zone->GetSelectedCorner() );
  373. }
  374. else
  375. {
  376. wxPoint pos = s_CornerInitialPosition;
  377. zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
  378. }
  379. }
  380. Panel->SetMouseCapture( NULL, NULL );
  381. s_AuxiliaryList.ClearListAndDeleteItems();
  382. s_PickedList. ClearListAndDeleteItems();
  383. Panel->Refresh();
  384. pcbframe->SetCurItem( NULL );
  385. zone->ClearFlags();
  386. s_AddCutoutToCurrentZone = false;
  387. s_CurrentZone = NULL;
  388. }
  389. /// Redraws the zone outline when moving a corner according to the cursor position
  390. void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  391. const wxPoint& aPosition, bool aErase )
  392. {
  393. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
  394. ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
  395. if( aErase ) // Undraw edge in old position
  396. {
  397. zone->Draw( aPanel, aDC, GR_XOR );
  398. }
  399. wxPoint pos = pcbframe->GetCrossHairPosition();
  400. if( zone->IsMoving() )
  401. {
  402. wxPoint offset;
  403. offset = pos - s_CursorLastPosition;
  404. zone->Move( offset );
  405. s_CursorLastPosition = pos;
  406. }
  407. else if( zone->IsDragging() )
  408. {
  409. wxPoint offset = pos - s_CursorLastPosition;
  410. int selection = zone->GetSelectedCorner();
  411. zone->MoveEdge( offset, selection );
  412. s_CursorLastPosition = pos;
  413. }
  414. else
  415. {
  416. zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
  417. }
  418. zone->Draw( aPanel, aDC, GR_XOR );
  419. }
  420. int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC )
  421. {
  422. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  423. // verify if s_CurrentZone exists (could be deleted since last selection) :
  424. int ii;
  425. for( ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
  426. {
  427. if( s_CurrentZone == GetBoard()->GetArea( ii ) )
  428. break;
  429. }
  430. if( ii >= GetBoard()->GetAreaCount() ) // Not found: could be deleted since last selection
  431. {
  432. s_AddCutoutToCurrentZone = false;
  433. s_CurrentZone = NULL;
  434. }
  435. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  436. // Verify if a new zone is allowed on this layer:
  437. if( zone == NULL )
  438. {
  439. if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT && !IsCopperLayer( GetActiveLayer() ) )
  440. {
  441. DisplayErrorMessage( this,
  442. _( "Error: a keepout area is allowed only on copper layers" ) );
  443. return 0;
  444. }
  445. }
  446. // If no zone contour in progress, a new zone is being created,
  447. if( zone == NULL )
  448. {
  449. zone = GetBoard()->m_CurrentZoneContour = new ZONE_CONTAINER( GetBoard() );
  450. zone->SetFlags( IS_NEW );
  451. zone->SetTimeStamp( GetNewTimeStamp() );
  452. }
  453. if( zone->GetNumCorners() == 0 ) // Start a new contour: init zone params (net, layer ...)
  454. {
  455. if( !s_CurrentZone ) // A new outline is created, from scratch
  456. {
  457. ZONE_EDIT_T edited;
  458. // Prompt user for parameters:
  459. m_canvas->SetIgnoreMouseEvents( true );
  460. if( IsCopperLayer( GetActiveLayer() ) )
  461. {
  462. // Put a zone on a copper layer
  463. if( GetBoard()->GetHighLightNetCode() > 0 )
  464. {
  465. zoneInfo.m_NetcodeSelection = GetBoard()->GetHighLightNetCode();
  466. zone->SetNetCode( zoneInfo.m_NetcodeSelection );
  467. }
  468. double tmp = ZONE_THERMAL_RELIEF_GAP_MIL;
  469. wxConfigBase* cfg = Kiface().KifaceSettings();
  470. cfg->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, &tmp );
  471. zoneInfo.m_ThermalReliefGap = KiROUND( tmp * IU_PER_MILS);
  472. tmp = ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL;
  473. cfg->Read( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, &tmp );
  474. zoneInfo.m_ThermalReliefCopperBridge = KiROUND( tmp * IU_PER_MILS );
  475. tmp = ZONE_CLEARANCE_MIL;
  476. cfg->Read( ZONE_CLEARANCE_WIDTH_STRING_KEY, &tmp );
  477. zoneInfo.m_ZoneClearance = KiROUND( tmp * IU_PER_MILS );
  478. tmp = ZONE_THICKNESS_MIL;
  479. cfg->Read( ZONE_MIN_THICKNESS_WIDTH_STRING_KEY, &tmp );
  480. zoneInfo.m_ZoneMinThickness = KiROUND( tmp * IU_PER_MILS );
  481. if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT )
  482. {
  483. zoneInfo.SetIsKeepout( true );
  484. // Netcode, netname and some other settings are irrelevant,
  485. // so ensure they are cleared
  486. zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
  487. zoneInfo.SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_NONE );
  488. zoneInfo.SetCornerRadius( 0 );
  489. edited = InvokeKeepoutAreaEditor( this, &zoneInfo );
  490. }
  491. else
  492. {
  493. zoneInfo.m_CurrentZone_Layer = GetActiveLayer(); // Preselect a layer
  494. zoneInfo.SetIsKeepout( false );
  495. edited = InvokeCopperZonesEditor( this, &zoneInfo );
  496. }
  497. }
  498. else // Put a zone on a non copper layer (technical layer)
  499. {
  500. zone->SetLayer( GetActiveLayer() ); // Preselect a layer
  501. zoneInfo.SetIsKeepout( false );
  502. zoneInfo.m_NetcodeSelection = 0; // No net for non copper zones
  503. edited = InvokeNonCopperZonesEditor( this, zone, &zoneInfo );
  504. }
  505. m_canvas->MoveCursorToCrossHair();
  506. m_canvas->SetIgnoreMouseEvents( false );
  507. if( edited == ZONE_ABORT )
  508. {
  509. GetBoard()->m_CurrentZoneContour = NULL;
  510. delete zone;
  511. return 0;
  512. }
  513. // Switch active layer to the selected zone layer
  514. SetActiveLayer( zoneInfo.m_CurrentZone_Layer );
  515. SetZoneSettings( zoneInfo );
  516. OnModify();
  517. }
  518. else
  519. {
  520. // Start a new contour: init zone params (net and layer) from an existing
  521. // zone (add cutout or similar zone)
  522. zoneInfo.m_CurrentZone_Layer = s_CurrentZone->GetLayer();
  523. SetActiveLayer( s_CurrentZone->GetLayer() );
  524. zoneInfo << *s_CurrentZone;
  525. SetZoneSettings( zoneInfo );
  526. OnModify();
  527. }
  528. // Show the Net for zones on copper layers
  529. if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) &&
  530. !zoneInfo.GetIsKeepout() )
  531. {
  532. if( s_CurrentZone )
  533. {
  534. zoneInfo.m_NetcodeSelection = s_CurrentZone->GetNetCode();
  535. GetBoard()->SetZoneSettings( zoneInfo );
  536. }
  537. if( GetBoard()->IsHighLightNetON() )
  538. {
  539. HighLight( DC ); // Remove old highlight selection
  540. }
  541. GetBoard()->SetHighLightNet( zoneInfo.m_NetcodeSelection );
  542. HighLight( DC );
  543. }
  544. if( !s_AddCutoutToCurrentZone )
  545. s_CurrentZone = NULL; // the zone is used only once ("add similar zone" command)
  546. }
  547. // if first segment
  548. if( zone->GetNumCorners() == 0 )
  549. {
  550. zoneInfo.ExportSetting( *zone );
  551. // A duplicated corner is needed; null segments are removed when the zone is finished.
  552. zone->AppendCorner( GetCrossHairPosition(), -1 );
  553. // Add the duplicate corner:
  554. zone->AppendCorner( GetCrossHairPosition(), -1, true );
  555. if( Settings().m_legacyDrcOn && (m_drc->Drc( zone, 0 ) == BAD_DRC) && zone->IsOnCopperLayer() )
  556. {
  557. zone->ClearFlags();
  558. zone->RemoveAllContours();
  559. // use the form of SetCurItem() which does not write to the msg panel,
  560. // SCREEN::SetCurItem(), so the DRC error remains on screen.
  561. // PCB_EDIT_FRAME::SetCurItem() calls DisplayInfo().
  562. GetScreen()->SetCurItem( NULL );
  563. DisplayErrorMessage( this,
  564. _( "DRC error: this start point is inside or too close an other area" ) );
  565. return 0;
  566. }
  567. SetCurItem( zone );
  568. m_canvas->SetMouseCapture( Show_New_Edge_While_Move_Mouse, Abort_Zone_Create_Outline );
  569. }
  570. else // edge in progress:
  571. {
  572. ii = zone->GetNumCorners() - 1;
  573. // edge in progress : the current corner coordinate was set
  574. // by Show_New_Edge_While_Move_Mouse
  575. if( zone->GetCornerPosition( ii - 1 ) != zone->GetCornerPosition( ii ) )
  576. {
  577. if( !Settings().m_legacyDrcOn || !zone->IsOnCopperLayer() || ( m_drc->Drc( zone, ii - 1 ) == OK_DRC ) )
  578. {
  579. // Ok, we can add a new corner
  580. if( m_canvas->IsMouseCaptured() )
  581. m_canvas->CallMouseCapture( DC, wxPoint(0,0), false );
  582. // It is necessary to allow duplication of the points, as we have to handle the
  583. // continuous drawing while creating the zone at the same time as we build it. Null
  584. // segments are removed when the zone is finished, in End_Zone.
  585. zone->AppendCorner( GetCrossHairPosition(), -1, true );
  586. SetCurItem( zone ); // calls DisplayInfo().
  587. if( m_canvas->IsMouseCaptured() )
  588. m_canvas->CallMouseCapture( DC, wxPoint(0,0), false );
  589. }
  590. }
  591. }
  592. return zone->GetNumCorners();
  593. }
  594. bool PCB_EDIT_FRAME::End_Zone( wxDC* DC )
  595. {
  596. ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour;
  597. if( !zone )
  598. return true;
  599. // Validate the current outline:
  600. if( zone->GetNumCorners() <= 2 ) // An outline must have 3 corners or more
  601. {
  602. Abort_Zone_Create_Outline( m_canvas, DC );
  603. return true;
  604. }
  605. // Remove the last corner if is is at the same location as the prevoius corner
  606. zone->Outline()->RemoveNullSegments();
  607. // Validate the current edge:
  608. int icorner = zone->GetNumCorners() - 1;
  609. if( zone->IsOnCopperLayer() )
  610. {
  611. if( Settings().m_legacyDrcOn && m_drc->Drc( zone, icorner - 1 ) == BAD_DRC ) // we can't validate last edge
  612. return false;
  613. if( Settings().m_legacyDrcOn && m_drc->Drc( zone, icorner ) == BAD_DRC ) // we can't validate the closing edge
  614. {
  615. DisplayErrorMessage( this,
  616. _( "DRC error: closing this area creates a DRC error with an other area" ) );
  617. m_canvas->MoveCursorToCrossHair();
  618. return false;
  619. }
  620. }
  621. zone->ClearFlags();
  622. zone->DrawWhileCreateOutline( m_canvas, DC, GR_XOR );
  623. m_canvas->SetMouseCapture( NULL, NULL );
  624. // Undraw old drawings, because they can have important changes
  625. PCB_LAYER_ID layer = zone->GetLayer();
  626. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_XOR, layer );
  627. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_XOR, layer );
  628. // Save initial zones configuration, for undo/redo, before adding new zone
  629. s_AuxiliaryList.ClearListAndDeleteItems();
  630. s_PickedList.ClearListAndDeleteItems();
  631. SaveCopyOfZones(s_PickedList, GetBoard(), zone->GetNetCode(), zone->GetLayer() );
  632. // Put new zone in list
  633. if( !s_CurrentZone )
  634. {
  635. GetBoard()->Add( zone );
  636. // Add this zone in picked list, as new item
  637. ITEM_PICKER picker( zone, UR_NEW );
  638. s_PickedList.PushItem( picker );
  639. }
  640. else // Append this outline as a cutout to an existing zone
  641. {
  642. s_CurrentZone->Outline()->AddHole( zone->Outline()->Outline( 0 ) );
  643. zone->RemoveAllContours(); // All corners are copied in s_CurrentZone. Free corner list.
  644. zone = s_CurrentZone;
  645. }
  646. s_AddCutoutToCurrentZone = false;
  647. s_CurrentZone = NULL;
  648. GetBoard()->m_CurrentZoneContour = NULL;
  649. GetScreen()->SetCurItem( NULL ); // This outline can be deleted when merging outlines
  650. // Combine zones if possible :
  651. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, zone );
  652. // Redraw the real edge zone :
  653. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, layer );
  654. GetBoard()->RedrawFilledAreas( m_canvas, DC, GR_OR, layer );
  655. int ii = GetBoard()->GetAreaIndex( zone ); // test if zone exists
  656. if( ii < 0 )
  657. zone = NULL; // was removed by combining zones
  658. DRC drc( this );
  659. int error_count = drc.TestZoneToZoneOutline( zone, true );
  660. if( error_count )
  661. {
  662. DisplayErrorMessage( this, _( "Area: DRC outline error" ) );
  663. }
  664. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  665. SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
  666. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  667. OnModify();
  668. return true;
  669. }
  670. /* Redraws the zone outlines when moving mouse
  671. */
  672. static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  673. const wxPoint& aPosition, bool aErase )
  674. {
  675. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
  676. wxPoint c_pos = pcbframe->GetCrossHairPosition();
  677. ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
  678. if( !zone )
  679. return;
  680. int icorner = zone->GetNumCorners() - 1;
  681. if( icorner < 1 )
  682. return; // We must have 2 (or more) corners
  683. if( aErase ) // Undraw edge in old position
  684. {
  685. zone->DrawWhileCreateOutline( aPanel, aDC );
  686. }
  687. // Redraw the current edge in its new position
  688. if( pcbframe->GetZoneSettings().m_Zone_45_Only )
  689. {
  690. // calculate the new position as allowed
  691. wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
  692. c_pos = CalculateSegmentEndPoint( c_pos, StartPoint );
  693. }
  694. zone->SetCornerPosition( icorner, c_pos );
  695. zone->DrawWhileCreateOutline( aPanel, aDC );
  696. }
  697. void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* aZone )
  698. {
  699. ZONE_EDIT_T edited;
  700. ZONE_SETTINGS zoneInfo = GetZoneSettings();
  701. BOARD_COMMIT commit( this );
  702. m_canvas->SetIgnoreMouseEvents( true );
  703. // Save initial zones configuration, for undo/redo, before adding new zone
  704. // note the net name and the layer can be changed, so we must save all zones
  705. s_AuxiliaryList.ClearListAndDeleteItems();
  706. s_PickedList.ClearListAndDeleteItems();
  707. SaveCopyOfZones( s_PickedList, GetBoard(), -1, UNDEFINED_LAYER );
  708. if( aZone->GetIsKeepout() )
  709. {
  710. // edit a keepout area on a copper layer
  711. zoneInfo << *aZone;
  712. edited = InvokeKeepoutAreaEditor( this, &zoneInfo );
  713. }
  714. else if( IsCopperLayer( aZone->GetLayer() ) )
  715. {
  716. // edit a zone on a copper layer
  717. zoneInfo << *aZone;
  718. edited = InvokeCopperZonesEditor( this, &zoneInfo );
  719. }
  720. else
  721. {
  722. zoneInfo << *aZone;
  723. edited = InvokeNonCopperZonesEditor( this, aZone, &zoneInfo );
  724. }
  725. m_canvas->MoveCursorToCrossHair();
  726. m_canvas->SetIgnoreMouseEvents( false );
  727. if( edited == ZONE_ABORT )
  728. {
  729. s_AuxiliaryList.ClearListAndDeleteItems();
  730. s_PickedList.ClearListAndDeleteItems();
  731. return;
  732. }
  733. SetZoneSettings( zoneInfo );
  734. OnModify();
  735. if( edited == ZONE_EXPORT_VALUES )
  736. {
  737. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  738. commit.Stage( s_PickedList );
  739. commit.Push( _( "Modify zone properties" ) );
  740. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
  741. return;
  742. }
  743. wxBusyCursor dummy;
  744. // Undraw old zone outlines
  745. for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
  746. {
  747. ZONE_CONTAINER* edge_zone = GetBoard()->GetArea( ii );
  748. edge_zone->Draw( m_canvas, DC, GR_XOR );
  749. if( IsGalCanvasActive() )
  750. {
  751. GetGalCanvas()->GetView()->Update( edge_zone );
  752. }
  753. }
  754. zoneInfo.ExportSetting( *aZone );
  755. NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
  756. if( net ) // net == NULL should not occur
  757. aZone->SetNetCode( net->GetNet() );
  758. // Combine zones if possible
  759. GetBoard()->OnAreaPolygonModified( &s_AuxiliaryList, aZone );
  760. // Redraw the real new zone outlines
  761. GetBoard()->RedrawAreasOutlines( m_canvas, DC, GR_OR, UNDEFINED_LAYER );
  762. UpdateCopyOfZonesList( s_PickedList, s_AuxiliaryList, GetBoard() );
  763. // refill zones with the new properties applied
  764. std::vector<ZONE_CONTAINER*> zones_to_refill;
  765. for( unsigned i = 0; i < s_PickedList.GetCount(); ++i )
  766. {
  767. ZONE_CONTAINER* zone = dyn_cast<ZONE_CONTAINER*>( s_PickedList.GetPickedItem( i ) );
  768. if( zone == nullptr )
  769. {
  770. wxASSERT_MSG( false, "Expected a zone after zone properties edit" );
  771. continue;
  772. }
  773. if( zone->IsFilled() )
  774. zones_to_refill.push_back( zone );
  775. }
  776. if( zones_to_refill.size() )
  777. {
  778. ZONE_FILLER filler ( GetBoard() );
  779. wxString title;
  780. title.Printf( _( "Refill %d Zones" ), (int)zones_to_refill.size() );
  781. std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
  782. new WX_PROGRESS_REPORTER( this, title, 3 ) );
  783. filler.SetProgressReporter( progressReporter.get() );
  784. filler.Fill( zones_to_refill );
  785. }
  786. commit.Stage( s_PickedList );
  787. commit.Push( _( "Modify zone properties" ) );
  788. GetBoard()->GetConnectivity()->RecalculateRatsnest();
  789. s_PickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
  790. if( !IsGalCanvasActive() )
  791. m_canvas->Refresh();
  792. }
  793. void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* aZone )
  794. {
  795. // Get contour in which the selected corner is
  796. SHAPE_POLY_SET::VERTEX_INDEX indices;
  797. // If the selected corner does not exist, abort
  798. if( !aZone->Outline()->GetRelativeIndices( aZone->GetSelectedCorner(), &indices ) )
  799. throw( std::out_of_range( "Zone selected corner does not exist" ) );
  800. EDA_RECT dirty = aZone->GetBoundingBox();
  801. // For compatibility with old boards: remove old SEGZONE fill segments
  802. Delete_OldZone_Fill( NULL, aZone->GetTimeStamp() );
  803. // Remove current filling:
  804. aZone->UnFill();
  805. if( indices.m_contour == 0 ) // This is the main outline: remove all
  806. {
  807. SaveCopyInUndoList( aZone, UR_DELETED );
  808. GetBoard()->Remove( aZone );
  809. }
  810. else
  811. {
  812. SaveCopyInUndoList( aZone, UR_CHANGED );
  813. aZone->Outline()->RemoveContour( indices.m_contour, indices.m_polygon );
  814. }
  815. m_canvas->RefreshDrawingRect( dirty );
  816. OnModify();
  817. }