KiCad PCB EDA Suite
Loading...
Searching...
No Matches
multichannel_tool.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef TOOLS_MULTICHANNEL_TOOL_H
21#define TOOLS_MULTICHANNEL_TOOL_H
22
23#include <map>
24#include <memory>
25#include <vector>
26#include <set>
27#include <unordered_map>
28#include <unordered_set>
29
30#include <tools/pcb_tool_base.h>
33
34#include <reporter.h>
35#include <zone_settings.h>
36
37class wxWindow;
38class wxCloseEvent;
39class EDA_ITEM;
41class FOOTPRINT;
42class PCB_GROUP;
43class NETINFO_ITEM;
44
45struct RULE_AREA;
46
48{
49 bool m_isOk = false;
50 bool m_doCopy = false;
51 wxString m_errorMsg;
53 std::vector<wxString> m_mismatchReasons;
55 std::unordered_set<BOARD_ITEM*> m_affectedItems;
57 std::unordered_set<BOARD_ITEM*> m_groupableItems;
59 std::set<FOOTPRINT*> m_unmatched;
60 bool m_searchLimit = false;
61};
62
64{
67 bool m_fromSelection = false;
68 ZONE* m_zone = nullptr;
69 std::set<FOOTPRINT*> m_components;
70 std::unordered_set<EDA_ITEM*> m_designBlockItems;
71 PCB_GROUP* m_group = nullptr;
72 bool m_generateEnabled = false;
73 wxString m_sheetPath;
74 wxString m_sheetName;
75 wxString m_ruleName;
77 wxString m_groupName;
79
82};
83
84
86{
87 bool m_replaceExisting = false;
88 bool m_linkAreas = false;
89 RULE_AREA* m_refRA = nullptr;
91
92 std::vector<RULE_AREA> m_areas;
93 std::unordered_map<RULE_AREA*, RULE_AREA_COMPAT_DATA> m_compatMap;
94
96 bool FromSelection() const { return !m_selectedItems.empty(); }
97
98 std::set<BOARD_ITEM*> m_selectedItems;
99 std::set<FOOTPRINT*> m_selectedFootprints;
100 std::vector<std::unique_ptr<BOARD_ITEM>> m_scratchItems;
101};
102
103
104namespace KIGFX
105{
106class VIEW_OVERLAY;
107}
108
110{
111public:
114
115 int RepeatLayout( const TOOL_EVENT& aEvent, ZONE* aRefZone );
116 int RepeatLayout( const TOOL_EVENT& aEvent, RULE_AREA& aRefArea, RULE_AREA& aTargetArea,
117 REPEAT_LAYOUT_OPTIONS& aOptions, BOARD_COMMIT* aExternalCommit = nullptr,
118 wxString* aErrorOut = nullptr );
119 int AutogenerateRuleAreas( const TOOL_EVENT& aEvent );
120
121 void UpdatePickedPoint( const std::optional<VECTOR2I>& aPoint ) override {};
122 void UpdatePickedItem( const EDA_ITEM* aItem ) override;
123
124 void ShowMismatchDetails( wxWindow* aParent, const wxString& aSummary,
125 const std::vector<wxString>& aReasons ) const;
126
128
131 int CheckRACompatibility( ZONE* aRefZone );
132
137 bool UpdateLinkedLayouts( ZONE* aSource );
138
140 void UnlinkAreas( const std::set<ZONE*>& aZones );
141
143 void StartRepeatFromSelection( const std::vector<EDA_ITEM*>& aItems );
144 void DiscoverRepeatCandidates( bool aLoose );
145
147 static ZONE* ChannelZone( const PCB_GROUP* aGroup );
148
155 std::set<FOOTPRINT*> ExpandToMatchingTopology( const std::set<FOOTPRINT*>& aSeed, bool aLargest );
156
158 void RefreshRepeat();
159 void UpdateRepeatPreview();
160
162 void HighlightRepeatAreas( const RULE_AREA* aArea );
163
165 int ApplyRepeat();
166
167 static wxString JoinReferences( const std::set<FOOTPRINT*>& aFootprints );
168
175 static std::vector<NETINFO_ITEM*> IsolateDesignBlockAutoNets( BOARD* aBoard,
176 const std::set<FOOTPRINT*>& aFootprints,
177 const std::unordered_set<EDA_ITEM*>& aItems );
178
179private:
180 bool Init() override;
181 void Reset( RESET_REASON aReason ) override;
182 void setTransitions() override;
183 int repeatLayout( const TOOL_EVENT& aEvent );
184 int updateLinkedLayouts( const TOOL_EVENT& aEvent );
185 int unlinkLayout( const TOOL_EVENT& aEvent );
186 int expandToMatchingTopology( const TOOL_EVENT& aEvent );
187 int expandToLargestTopology( const TOOL_EVENT& aEvent );
188 int expandSelection( bool aLargest );
189
190 bool routerBusy() const;
191
193 void linkAreas( BOARD_COMMIT& aCommit, ZONE* aRefZone, const std::vector<RULE_AREA*>& aTargets );
194 void detachArea( BOARD_COMMIT& aCommit, ZONE* aZone );
195 void dropLoneLinks( BOARD_COMMIT& aCommit, const std::set<KIID>& aSets );
196
198 std::vector<RULE_AREA_COMPAT_DATA> findMatches( const std::set<FOOTPRINT*>& aSelected, bool aLoose );
199
201 bool updateSelectionCore();
203 void clearRepeatPreview();
204
209 std::set<BOARD_CONNECTED_ITEM*> findRepeatRouting( RULE_AREA* aArea, const std::set<int>& aNets,
210 const REPEAT_LAYOUT_OPTIONS& aOpts );
211 void hideMovedRatsnest();
212 void setPreviewHidden( bool aHide );
213 void closeRepeatDialog();
214 void onRepeatDialogClosed( wxCloseEvent& aEvent );
215 int applyRepeat( BOARD_COMMIT& aCommit );
216
217
218 bool findComponentsInRuleArea( RULE_AREA* aRuleArea, std::set<FOOTPRINT*>& aComponents );
219 bool findOtherItemsInRuleArea( RULE_AREA* aRuleArea, std::set<BOARD_ITEM*>& aItems );
220 int findRoutingInRuleArea( RULE_AREA* aRuleArea, std::set<BOARD_CONNECTED_ITEM*>& aOutput ) const;
221 void copyRuleAreaContents( RULE_AREA* aRefArea, RULE_AREA* aTargetArea,
222 BOARD_COMMIT* aCommit, REPEAT_LAYOUT_OPTIONS aOpts,
223 RULE_AREA_COMPAT_DATA& aCompatData );
224
225 const SHAPE_LINE_CHAIN buildRAOutline( std::set<FOOTPRINT*>& aFootprints, int aMargin );
226 const SHAPE_LINE_CHAIN buildRAOutline( const std::set<BOARD_ITEM*>& aItems, int aMargin );
227
228 std::set<FOOTPRINT*> queryComponentsInSheet( wxString aSheetName ) const;
229 std::set<FOOTPRINT*> queryComponentsInComponentClass( const wxString& aComponentClassName ) const;
230 std::set<FOOTPRINT*> queryComponentsInGroup( const wxString& aGroupName ) const;
231 std::set<BOARD_ITEM*> queryBoardItemsInGroup( const wxString& aGroupName ) const;
232 PCB_GROUP* findPlacementGroup( const wxString& aGroupName ) const;
233
234 bool resolveConnectionTopology( RULE_AREA* aRefArea, RULE_AREA* aTargetArea,
235 RULE_AREA_COMPAT_DATA& aMatches,
236 const TMATCH::ISOMORPHISM_PARAMS& aParams = {},
237 const std::unordered_set<int>& aExtraGlobalNets = {} );
238
245
255 bool resolveTopologies( const wxString& aTitle, const std::vector<TOPOLOGY_JOB>& aJobs );
257 bool aHasMatches,
258 const std::map<int, int>& aNetMap );
259 bool pruneExistingGroups( COMMIT& aCommit, const std::unordered_set<BOARD_ITEM*>& aItemsToCheck );
260
261 std::unique_ptr<REPORTER> m_reporter;
264 std::vector<KIID> m_previewHidden;
265 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_highlight;
266 const RULE_AREA* m_focusArea = nullptr;
267 std::map<FOOTPRINT*, BOX2I> m_previewBoxes;
268 std::vector<SEG> m_previewRatsnest;
269};
270
271
272#endif // TOOLS_MULTICHANNEL_TOOL
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
void setPreviewHidden(bool aHide)
int CheckRACompatibility(ZONE *aRefZone)
void detachArea(BOARD_COMMIT &aCommit, ZONE *aZone)
std::set< FOOTPRINT * > queryComponentsInSheet(wxString aSheetName) const
void fixupNet(BOARD_CONNECTED_ITEM *aRef, BOARD_CONNECTED_ITEM *aTarget, bool aHasMatches, const std::map< int, int > &aNetMap)
Attempts to make sure copied items are assigned the right net.
bool findOtherItemsInRuleArea(RULE_AREA *aRuleArea, std::set< BOARD_ITEM * > &aItems)
void dropLoneLinks(BOARD_COMMIT &aCommit, const std::set< KIID > &aSets)
bool resolveConnectionTopology(RULE_AREA *aRefArea, RULE_AREA *aTargetArea, RULE_AREA_COMPAT_DATA &aMatches, const TMATCH::ISOMORPHISM_PARAMS &aParams={}, const std::unordered_set< int > &aExtraGlobalNets={})
std::unique_ptr< REPORTER > m_reporter
void HighlightRepeatAreas(const RULE_AREA *aArea)
Mark the reference parts, and the parts of aArea if given, on the board while the dialog is open.
std::vector< SEG > m_previewRatsnest
bool resolveTopologies(const wxString &aTitle, const std::vector< TOPOLOGY_JOB > &aJobs)
Resolve the topology of each job in turn on a worker thread.
int repeatLayout(const TOOL_EVENT &aEvent)
bool findComponentsInRuleArea(RULE_AREA *aRuleArea, std::set< FOOTPRINT * > &aComponents)
void UpdatePickedItem(const EDA_ITEM *aItem) override
std::map< FOOTPRINT *, BOX2I > m_previewBoxes
int expandToLargestTopology(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void UnlinkAreas(const std::set< ZONE * > &aZones)
Remove aZones from their link sets, and any area left alone in one, as one undo step.
static wxString JoinReferences(const std::set< FOOTPRINT * > &aFootprints)
bool Init() override
Init() is called once upon a registration of the tool.
void onRepeatDialogClosed(wxCloseEvent &aEvent)
const SHAPE_LINE_CHAIN buildRAOutline(std::set< FOOTPRINT * > &aFootprints, int aMargin)
int findRoutingInRuleArea(RULE_AREA *aRuleArea, std::set< BOARD_CONNECTED_ITEM * > &aOutput) const
int applyRepeat(BOARD_COMMIT &aCommit)
static ZONE * ChannelZone(const PCB_GROUP *aGroup)
The rule area zone that makes aGroup a repeated channel, or null for any other group.
RULE_AREAS_DATA * GetData()
std::vector< RULE_AREA_COMPAT_DATA > findMatches(const std::set< FOOTPRINT * > &aSelected, bool aLoose)
The channels elsewhere on the board that repeat the topology of aSelected.
std::set< FOOTPRINT * > ExpandToMatchingTopology(const std::set< FOOTPRINT * > &aSeed, bool aLargest)
Grow aSeed with the parts next to it, keeping only sets that still have an exact twin elsewhere on th...
bool UpdateLinkedLayouts(ZONE *aSource)
Copy aSource onto the other areas of its link set, as one undo step.
static std::vector< NETINFO_ITEM * > IsolateDesignBlockAutoNets(BOARD *aBoard, const std::set< FOOTPRINT * > &aFootprints, const std::unordered_set< EDA_ITEM * > &aItems)
Remap auto-generated nets (Net-(...), unconnected-...) of a design block that was appended for layout...
void StartRepeatFromSelection(const std::vector< EDA_ITEM * > &aItems)
Use plain selected items as the reference and discover the channels that repeat them.
int expandToMatchingTopology(const TOOL_EVENT &aEvent)
const RULE_AREA * m_focusArea
std::vector< KIID > m_previewHidden
void copyRuleAreaContents(RULE_AREA *aRefArea, RULE_AREA *aTargetArea, BOARD_COMMIT *aCommit, REPEAT_LAYOUT_OPTIONS aOpts, RULE_AREA_COMPAT_DATA &aCompatData)
RULE_AREAS_DATA m_areas
PCB_GROUP * findPlacementGroup(const wxString &aGroupName) const
bool pruneExistingGroups(COMMIT &aCommit, const std::unordered_set< BOARD_ITEM * > &aItemsToCheck)
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_highlight
int updateLinkedLayouts(const TOOL_EVENT &aEvent)
void ShowMismatchDetails(wxWindow *aParent, const wxString &aSummary, const std::vector< wxString > &aReasons) const
void RefreshRepeat()
Re-derive the channels after a tick or the anchor changed, then redraw the preview.
int RepeatLayout(const TOOL_EVENT &aEvent, ZONE *aRefZone)
int AutogenerateRuleAreas(const TOOL_EVENT &aEvent)
int expandSelection(bool aLargest)
void DiscoverRepeatCandidates(bool aLoose)
std::set< BOARD_CONNECTED_ITEM * > findRepeatRouting(RULE_AREA *aArea, const std::set< int > &aNets, const REPEAT_LAYOUT_OPTIONS &aOpts)
The routing of aArea on aNets, the only nets a repeat ever carries.
DIALOG_MULTICHANNEL_REPEAT_LAYOUT * m_dialog
std::set< FOOTPRINT * > queryComponentsInComponentClass(const wxString &aComponentClassName) const
void UpdatePickedPoint(const std::optional< VECTOR2I > &aPoint) override
int ApplyRepeat()
Apply what the Repeat Layout dialog shows.
void linkAreas(BOARD_COMMIT &aCommit, ZONE *aRefZone, const std::vector< RULE_AREA * > &aTargets)
Link aTargets and aRefZone into one set with their own copies of the options.
int unlinkLayout(const TOOL_EVENT &aEvent)
std::set< FOOTPRINT * > queryComponentsInGroup(const wxString &aGroupName) const
std::set< BOARD_ITEM * > queryBoardItemsInGroup(const wxString &aGroupName) const
Handle the data for a net.
Definition netinfo.h:50
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
Interface class for something that receives picked points or items from this tool.
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
std::map< FOOTPRINT *, FOOTPRINT * > COMPONENT_MATCHES
Definition topo_match.h:188
RULE_AREA_COMPAT_DATA * m_compat
Options for copying a placement rule area onto the others linked to it.
std::unordered_map< RULE_AREA *, RULE_AREA_COMPAT_DATA > m_compatMap
REPEAT_LAYOUT_OPTIONS m_options
bool m_linkAreas
Link the ticked targets to the reference.
bool FromSelection() const
A plain selection is the reference, and its channels are created only when applied.
std::vector< std::unique_ptr< BOARD_ITEM > > m_scratchItems
Areas and groups not yet on the board.
std::set< FOOTPRINT * > m_selectedFootprints
std::set< BOARD_ITEM * > m_selectedItems
std::vector< RULE_AREA > m_areas
std::vector< wxString > m_mismatchReasons
TMATCH::COMPONENT_MATCHES m_discovered
Pairing found by discovery.
std::unordered_set< BOARD_ITEM * > m_affectedItems
Filled in by copyRuleAreaContents with items that were affected by the copy operation.
TMATCH::COMPONENT_MATCHES m_matchingComponents
std::set< FOOTPRINT * > m_unmatched
Selected footprints the channel lacks.
std::unordered_set< BOARD_ITEM * > m_groupableItems
Filled in by copyRuleAreaContents with affected items that can be grouped together.
VECTOR2I m_center
bool ScansContents() const
True when the contents are scanned from the area rather than taken from an exact item list.
std::unordered_set< EDA_ITEM * > m_designBlockItems
wxString m_sheetName
bool m_fromSelection
The reference of a plain selection, copied as given with its footprint area deciding what else comes ...
PLACEMENT_SOURCE_T m_sourceType
wxString m_componentClass
std::set< FOOTPRINT * > m_components
wxString m_ruleName
PCB_GROUP * m_group
wxString m_groupName
wxString m_sheetPath
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
Class ZONE_SETTINGS used to handle zones parameters in dialogs.
PLACEMENT_SOURCE_T