KiCad PCB EDA Suite
Loading...
Searching...
No Matches
edit_zone_helpers.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 Jean-Pierre Charras, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Some code comes from FreePCB.
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#include <kiface_base.h>
28#include <confirm.h>
29#include <pcb_edit_frame.h>
30#include <pcbnew_settings.h>
31#include <board.h>
32#include <board_commit.h>
34#include <tool/tool_manager.h>
35#include <tool/actions.h>
36#include <zone.h>
37#include <zones.h>
39
40
42{
43 if( aZone->IsCopperThieving() )
44 {
45 SetStatusText( _( "Edit copper-thieving parameters in the Properties panel." ), 0 );
46 return;
47 }
48
49 int dialogResult;
50 ZONE_SETTINGS zoneInfo = m_pcb->GetDesignSettings().GetDefaultZoneSettings();
51 BOARD_COMMIT commit( this );
52
53 if( aZone->GetIsRuleArea() )
54 {
55 // edit a rule area on a copper layer
56 zoneInfo << *aZone;
57 dialogResult = InvokeRuleAreaEditor( this, &zoneInfo, GetBoard() );
58 }
59 else if( IsCopperLayer( aZone->GetFirstLayer() ) )
60 {
61 // edit a zone on a copper layer
62 zoneInfo << *aZone;
63 dialogResult = InvokeCopperZonesEditor( this, aZone, &zoneInfo );
64 }
65 else
66 {
67 zoneInfo << *aZone;
68 dialogResult = InvokeNonCopperZonesEditor( this, &zoneInfo );
69 }
70
71 if( dialogResult == wxID_CANCEL )
72 return;
73
74 wxBusyCursor dummy;
75
76 // Undraw old zone outlines
77 for( ZONE* zone : GetBoard()->Zones() )
78 GetCanvas()->GetView()->Update( zone );
79
80 commit.Modify( aZone );
81
82 zoneInfo.ExportSetting( *aZone );
83
84 if( NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_Netcode ) )
85 aZone->SetNetCode( net->GetNetCode() );
86
87 // restore default net properties
89
90 m_pcb->GetDesignSettings().SetDefaultZoneSettings( zoneInfo );
91
92 commit.Push( _( "Edit Zone Properties" ), SKIP_CONNECTIVITY );
94}
95
96
97bool BOARD::TestZoneIntersection( ZONE* aZone1, ZONE* aZone2 )
98{
99 // see if areas are on same layer
100 if( !( aZone1->GetLayerSet() & aZone2->GetLayerSet() ).any() )
101 return false;
102
103 SHAPE_POLY_SET* poly1 = aZone1->Outline();
104 SHAPE_POLY_SET* poly2 = aZone2->Outline();
105
106 // test bounding rects
107 BOX2I b1 = poly1->BBox();
108 BOX2I b2 = poly2->BBox();
109
110 if( ! b1.Intersects( b2 ) )
111 return false;
112
113 // Now test for intersecting segments
114 for( auto segIterator1 = poly1->IterateSegmentsWithHoles(); segIterator1; segIterator1++ )
115 {
116 // Build segment
117 SEG firstSegment = *segIterator1;
118
119 for( auto segIterator2 = poly2->IterateSegmentsWithHoles(); segIterator2; segIterator2++ )
120 {
121 // Build second segment
122 SEG secondSegment = *segIterator2;
123
124 // Check whether the two segments built collide
125 if( firstSegment.Collide( secondSegment, 0 ) )
126 return true;
127 }
128 }
129
130 // If a contour is inside another contour, no segments intersects, but the zones
131 // can be combined if a corner is inside an outline (only one corner is enough)
132 for( auto iter = poly2->IterateWithHoles(); iter; iter++ )
133 {
134 if( poly1->Contains( *iter ) )
135 return true;
136 }
137
138 for( auto iter = poly1->IterateWithHoles(); iter; iter++ )
139 {
140 if( poly2->Contains( *iter ) )
141 return true;
142 }
143
144 return false;
145}
146
147
148
#define SKIP_CONNECTIVITY
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
bool TestZoneIntersection(ZONE *aZone1, ZONE *aZone2)
Test for intersection of 2 copper areas.
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:91
Handle the data for a net.
Definition netinfo.h:50
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:263
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void Edit_Zone_Params(ZONE *zone_container)
Edit params (layer, clearance, ...) for a zone outline.
Definition seg.h:42
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
Definition seg.cpp:542
Represent a set of closed polygons.
ITERATOR IterateWithHoles(int aOutline)
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
ZONE_SETTINGS handles zones parameters.
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:802
SHAPE_POLY_SET * Outline()
Definition zone.h:422
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
Definition zone.cpp:585
bool IsCopperThieving() const
Definition zone.h:353
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:137
PCB_LAYER_ID GetFirstLayer() const
Definition zone.cpp:558
This file is part of the common library.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE *aZone, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aZoneSettings, BOARD *aBoard, CONVERT_SETTINGS *aConvertSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
#define _(s)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:679
std::vector< FAB_LAYER_COLOR > dummy