KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_multichannel_repeat_layout.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) 2014 John Beard, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <widgets/wx_grid.h>
23#include <bitmaps.h>
24#include <grid_tricks.h>
25#include <pcb_edit_frame.h>
28#include <zone.h>
29#include <board.h>
30#include <footprint.h>
31
32
34 MULTICHANNEL_TOOL *aParentTool ) :
36 m_parentTool( aParentTool )
37{
38 m_board = aFrame->GetBoard();
40
41 m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_raGrid ) ) );
42 m_raGrid->ClearGrid();
43 m_raGrid->EnableEditing( true );
44 m_raGrid->AutoSizeColumn( 1 );
45 m_raGrid->SetupColumnAutosizer( 1 );
46
47 m_raGrid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &DIALOG_MULTICHANNEL_REPEAT_LAYOUT::OnGridCellLeftClick, this );
48
49 Layout();
52}
53
59
61{
62 auto data = m_parentTool->GetData();
63
64 for( size_t i = 0; i < m_targetRAs.size(); i++ )
65 {
66 wxString doCopy = m_raGrid->GetCellValue( i, 0 );
67
68 data->m_compatMap[m_targetRAs[i].m_targetRA].m_doCopy = !doCopy.CompareTo( wxT( "1" ) ) ? true : false;
69 }
70
71 data->m_options.m_copyPlacement = m_cbCopyPlacement->GetValue();
72 data->m_options.m_copyRouting = m_cbCopyRouting->GetValue();
73 data->m_options.m_connectedRoutingOnly = m_cbCopyOnlyConnectedRouting->GetValue();
74 data->m_options.m_copyOtherItems = m_cbCopyOtherItems->GetValue();
75 data->m_options.m_groupItems = m_cbGroupItems->GetValue();
76 data->m_options.m_includeLockedItems = m_cbIncludeLockedComponents->GetValue();
77
78 if( m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) == "" )
79 {
80 data->m_options.m_anchorFp = nullptr;
81 }
82 else
83 {
84 for( FOOTPRINT* fp : m_board->Footprints() )
85 {
86 if( fp->GetReference() == m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) )
87 data->m_options.m_anchorFp = fp;
88 }
89 }
90
91 return true;
92}
93
94
96{
97 RULE_AREAS_DATA* data = m_parentTool->GetData();
98
99 for( const auto& [ruleArea, ruleAreaData] : data->m_compatMap )
100 {
101 TABLE_ENTRY ent;
102
103 ent.m_doCopy = ruleAreaData.m_isOk;
104 ent.m_errMsg = ruleAreaData.m_errorMsg;
105 ent.m_isOK = ruleAreaData.m_isOk;
106 ent.m_raName = ruleArea->m_ruleName;
107 ent.m_targetRA = ruleArea;
108 ent.m_mismatchReasons = ruleAreaData.m_mismatchReasons;
109
110 m_targetRAs.push_back( ent );
111 }
112
113 std::sort( m_targetRAs.begin(), m_targetRAs.end(),
114 [] ( const TABLE_ENTRY&a ,const TABLE_ENTRY& b ) -> int
115 {
116 if ( !a.m_isOK && b.m_isOK )
117 return 0;
118 else if ( a.m_isOK && !b.m_isOK )
119 return 1;
120 else
121 return a.m_raName < b.m_raName;
122 } );
123
124 m_raGrid->ClearRows();
125 m_raGrid->AppendRows( m_targetRAs.size() );
126
127 int i = 0;
128
129 for( TABLE_ENTRY& entry : m_targetRAs )
130 {
131 m_raGrid->SetCellValue( i, 1, entry.m_raName );
132 m_raGrid->SetCellValue( i, 2, entry.m_isOK ? _( "OK" ) : entry.m_errMsg );
133 m_raGrid->SetCellValue( i, 3, wxString() );
134 m_raGrid->SetCellRenderer( i, 0, new wxGridCellBoolRenderer);
135 m_raGrid->SetCellEditor( i, 0, new wxGridCellBoolEditor);
136 m_raGrid->SetCellValue( i, 0, entry.m_doCopy ? wxT( "1" ) : wxT( "" ) );
137
138 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() )
139 {
140 wxGridCellAttr* attr = new wxGridCellAttr;
141 attr->SetRenderer( new GRID_CELL_ICON_RENDERER( m_detailsIcon ) );
142 attr->SetReadOnly();
143 m_raGrid->SetAttr( i, 3, attr );
144 m_raGrid->SetCellValue( i, 3, wxString() );
145 }
146
147 i++;
148 }
149
150 m_raGrid->Fit();
151
152 m_refRAName->SetLabelText( data->m_refRA->m_zone->GetZoneName() );
153
154 wxArrayString refFpNames;
155 refFpNames.push_back( "" );
156
157 for( FOOTPRINT* fp : data->m_refRA->m_components )
158 refFpNames.push_back( fp->GetReference() );
159
160 refFpNames.Sort();
161 m_refAnchorFp->Set( refFpNames );
162 m_refAnchorFp->SetSelection( 0 );
163
165 m_cbCopyRouting->SetValue( data->m_options.m_copyRouting );
167 m_cbGroupItems->SetValue( data->m_options.m_groupItems );
170
171 return true;
172}
173
174
176{
177 int row = aEvent.GetRow();
178 int col = aEvent.GetCol();
179
180 if( col == 3 && row >= 0 && row < static_cast<int>( m_targetRAs.size() ) )
181 {
182 const TABLE_ENTRY& entry = m_targetRAs[row];
183
184 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() && m_parentTool )
185 {
186 wxString summary = wxString::Format( _( "Rule area topologies do not match: %s" ), entry.m_errMsg );
187
188 m_parentTool->ShowMismatchDetails( this, summary, entry.m_mismatchReasons );
189 }
190 }
191
192 aEvent.Skip();
193}
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Constructs and returns a bitmap bundle for the given icon ID, with the default bitmap size being aDef...
Definition bitmap.cpp:112
DIALOG_MULTICHANNEL_REPEAT_LAYOUT_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Repeat Multichannel Layout"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_MULTICHANNEL_REPEAT_LAYOUT(PCB_BASE_FRAME *aFrame, MULTICHANNEL_TOOL *aParentTool)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const wxString & GetReference() const
Definition footprint.h:841
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:57
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
const wxString & GetZoneName() const
Definition zone.h:160
#define _(s)
wxString m_errMsg
bool m_isOK
wxString m_raName
RULE_AREA * m_targetRA
std::vector< wxString > m_mismatchReasons
bool m_doCopy
std::unordered_map< RULE_AREA *, RULE_AREA_COMPAT_DATA > m_compatMap
REPEAT_LAYOUT_OPTIONS m_options
std::set< FOOTPRINT * > m_components