forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_zone_helpers.cpp
228 lines (185 loc) · 7.2 KB
/
edit_zone_helpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, [email protected]
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* Some code comes from FreePCB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <kiface_i.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <pcbnew_settings.h>
#include <board_commit.h>
#include <zone.h>
#include <zones.h>
#include <zones_functions_for_undo_redo.h>
#include <connectivity/connectivity_data.h>
#include <widgets/progress_reporter.h>
#include <zone_filler.h>
void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone )
{
int dialogResult;
ZONE_SETTINGS zoneInfo = GetZoneSettings();
PICKED_ITEMS_LIST pickedList; // zones for undo/redo command
PICKED_ITEMS_LIST deletedList; // zones that have been deleted when combined
BOARD_COMMIT commit( this );
// Save initial zones configuration, for undo/redo, before adding new zone
// note the net name and the layer can be changed, so we must save all zones
deletedList.ClearListAndDeleteItems();
pickedList.ClearListAndDeleteItems();
SaveCopyOfZones( pickedList, GetBoard(), -1, UNDEFINED_LAYER );
if( aZone->GetIsRuleArea() )
{
// edit a rule area on a copper layer
zoneInfo << *aZone;
dialogResult = InvokeRuleAreaEditor( this, &zoneInfo );
}
else if( IsCopperLayer( aZone->GetLayer() ) )
{
// edit a zone on a copper layer
zoneInfo << *aZone;
dialogResult = InvokeCopperZonesEditor( this, &zoneInfo );
}
else
{
zoneInfo << *aZone;
dialogResult = InvokeNonCopperZonesEditor( this, &zoneInfo );
}
if( dialogResult == wxID_CANCEL )
{
deletedList.ClearListAndDeleteItems();
pickedList.ClearListAndDeleteItems();
return;
}
SetZoneSettings( zoneInfo );
OnModify();
if( dialogResult == ZONE_EXPORT_VALUES )
{
UpdateCopyOfZonesList( pickedList, deletedList, GetBoard() );
commit.Stage( pickedList );
commit.Push( _( "Modify zone properties" ) );
pickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
return;
}
wxBusyCursor dummy;
// Undraw old zone outlines
for( ZONE* zone : GetBoard()->Zones() )
GetCanvas()->GetView()->Update( zone );
zoneInfo.ExportSetting( *aZone );
NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
if( net ) // net == NULL should not occur
aZone->SetNetCode( net->GetNetCode() );
// Combine zones if possible
GetBoard()->OnAreaPolygonModified( &deletedList, aZone );
UpdateCopyOfZonesList( pickedList, deletedList, GetBoard() );
// Only auto-refill zones here if in user preferences
if( Settings().m_AutoRefillZones )
{
// refill zones with the new properties applied
std::vector<ZONE*> zones_to_refill;
for( unsigned i = 0; i < pickedList.GetCount(); ++i )
{
ZONE* zone = dyn_cast<ZONE*>( pickedList.GetPickedItem( i ) );
if( zone == nullptr )
{
wxASSERT_MSG( false, "Expected a zone after zone properties edit" );
continue;
}
// aZone won't be filled if the layer set was modified, but it needs to be updated
if( zone->IsFilled() || zone == aZone )
zones_to_refill.push_back( zone );
}
commit.Stage( pickedList );
std::lock_guard<KISPINLOCK> lock( GetBoard()->GetConnectivity()->GetLock() );
if( zones_to_refill.size() )
{
ZONE_FILLER filler( GetBoard(), &commit );
wxString title =
wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() );
filler.InstallNewProgressReporter( this, title, 4 );
if( !filler.Fill( zones_to_refill ) )
{
// User has already OK'ed dialog so we're going to go ahead and commit even if the
// fill was cancelled.
}
}
}
commit.Push( _( "Modify zone properties" ) );
GetBoard()->GetConnectivity()->RecalculateRatsnest();
pickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
}
bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList, ZONE* modified_area )
{
// clip polygon against itself
bool modified = NormalizeAreaPolygon( aModifiedZonesList, modified_area );
// Test for bad areas: all zones must have more than 2 corners:
// Note: should not happen, but just in case.
for( ZONE* zone : m_zones )
{
if( zone->GetNumCorners() < 3 )
{
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::DELETED );
aModifiedZonesList->PushItem( picker );
zone->SetFlags( STRUCT_DELETED );
}
}
return modified;
}
bool BOARD::TestZoneIntersection( ZONE* aZone1, ZONE* aZone2 )
{
// see if areas are on same layer
if( aZone1->GetLayer() != aZone2->GetLayer() )
return false;
SHAPE_POLY_SET* poly1 = aZone1->Outline();
SHAPE_POLY_SET* poly2 = aZone2->Outline();
// test bounding rects
BOX2I b1 = poly1->BBox();
BOX2I b2 = poly2->BBox();
if( ! b1.Intersects( b2 ) )
return false;
// Now test for intersecting segments
for( auto segIterator1 = poly1->IterateSegmentsWithHoles(); segIterator1; segIterator1++ )
{
// Build segment
SEG firstSegment = *segIterator1;
for( auto segIterator2 = poly2->IterateSegmentsWithHoles(); segIterator2; segIterator2++ )
{
// Build second segment
SEG secondSegment = *segIterator2;
// Check whether the two segments built collide
if( firstSegment.Collide( secondSegment, 0 ) )
return true;
}
}
// If a contour is inside another contour, no segments intersects, but the zones
// can be combined if a corner is inside an outline (only one corner is enough)
for( auto iter = poly2->IterateWithHoles(); iter; iter++ )
{
if( poly1->Contains( *iter ) )
return true;
}
for( auto iter = poly1->IterateWithHoles(); iter; iter++ )
{
if( poly2->Contains( *iter ) )
return true;
}
return false;
}