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.

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