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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <widgets/wx_grid.h>
27#include <bitmaps.h>
28#include <grid_tricks.h>
29#include <pcb_edit_frame.h>
32#include <zone.h>
33#include <board.h>
34
35
37 MULTICHANNEL_TOOL *aParentTool ) :
39 m_parentTool( aParentTool )
40{
41 m_board = aFrame->GetBoard();
43
44 m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_raGrid ) ) );
45 m_raGrid->ClearGrid();
46 m_raGrid->EnableEditing( true );
47 m_raGrid->AutoSizeColumn( 1 );
48 m_raGrid->SetupColumnAutosizer( 1 );
49
50 m_raGrid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &DIALOG_MULTICHANNEL_REPEAT_LAYOUT::OnGridCellLeftClick, this );
51
52 Layout();
55}
56
62
64{
65 auto data = m_parentTool->GetData();
66
67 for( size_t i = 0; i < m_targetRAs.size(); i++ )
68 {
69 wxString doCopy = m_raGrid->GetCellValue( i, 0 );
70
71 data->m_compatMap[m_targetRAs[i].m_targetRA].m_doCopy = !doCopy.CompareTo( wxT( "1" ) ) ? true : false;
72 }
73
74 data->m_options.m_copyPlacement = m_cbCopyPlacement->GetValue();
75 data->m_options.m_copyRouting = m_cbCopyRouting->GetValue();
76 data->m_options.m_connectedRoutingOnly = m_cbCopyOnlyConnectedRouting->GetValue();
77 data->m_options.m_copyOtherItems = m_cbCopyOtherItems->GetValue();
78 data->m_options.m_groupItems = m_cbGroupItems->GetValue();
79 data->m_options.m_includeLockedItems = m_cbIncludeLockedComponents->GetValue();
80
81 if( m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) == "" )
82 {
83 data->m_options.m_anchorFp = nullptr;
84 }
85 else
86 {
87 for( FOOTPRINT* fp : m_board->Footprints() )
88 {
89 if( fp->GetReference() == m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) )
90 data->m_options.m_anchorFp = fp;
91 }
92 }
93
94 return true;
95}
96
97
99{
100 RULE_AREAS_DATA* data = m_parentTool->GetData();
101
102 for( const auto& [ruleArea, ruleAreaData] : data->m_compatMap )
103 {
104 TABLE_ENTRY ent;
105
106 ent.m_doCopy = ruleAreaData.m_isOk;
107 ent.m_errMsg = ruleAreaData.m_errorMsg;
108 ent.m_isOK = ruleAreaData.m_isOk;
109 ent.m_raName = ruleArea->m_ruleName;
110 ent.m_targetRA = ruleArea;
111 ent.m_mismatchReasons = ruleAreaData.m_mismatchReasons;
112
113 m_targetRAs.push_back( ent );
114 }
115
116 std::sort( m_targetRAs.begin(), m_targetRAs.end(),
117 [] ( const TABLE_ENTRY&a ,const TABLE_ENTRY& b ) -> int
118 {
119 if ( !a.m_isOK && b.m_isOK )
120 return 0;
121 else if ( a.m_isOK && !b.m_isOK )
122 return 1;
123 else
124 return a.m_raName < b.m_raName;
125 } );
126
127 m_raGrid->ClearRows();
128 m_raGrid->AppendRows( m_targetRAs.size() );
129
130 int i = 0;
131
132 for( TABLE_ENTRY& entry : m_targetRAs )
133 {
134 m_raGrid->SetCellValue( i, 1, entry.m_raName );
135 m_raGrid->SetCellValue( i, 2, entry.m_isOK ? _( "OK" ) : entry.m_errMsg );
136 m_raGrid->SetCellValue( i, 3, wxString() );
137 m_raGrid->SetCellRenderer( i, 0, new wxGridCellBoolRenderer);
138 m_raGrid->SetCellEditor( i, 0, new wxGridCellBoolEditor);
139 m_raGrid->SetCellValue( i, 0, entry.m_doCopy ? wxT( "1" ) : wxT( "" ) );
140
141 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() )
142 {
143 wxGridCellAttr* attr = new wxGridCellAttr;
144 attr->SetRenderer( new GRID_CELL_ICON_RENDERER( m_detailsIcon ) );
145 attr->SetReadOnly();
146 m_raGrid->SetAttr( i, 3, attr );
147 m_raGrid->SetCellValue( i, 3, wxString() );
148 }
149
150 i++;
151 }
152
153 m_raGrid->Fit();
154
155 m_refRAName->SetLabelText( data->m_refRA->m_zone->GetZoneName() );
156
157 wxArrayString refFpNames;
158 refFpNames.push_back( "" );
159
160 for( FOOTPRINT* fp : data->m_refRA->m_components )
161 refFpNames.push_back( fp->GetReference() );
162
163 refFpNames.Sort();
164 m_refAnchorFp->Set( refFpNames );
165 m_refAnchorFp->SetSelection( 0 );
166
168 m_cbCopyRouting->SetValue( data->m_options.m_copyRouting );
170 m_cbGroupItems->SetValue( data->m_options.m_groupItems );
173
174 return true;
175}
176
177
179{
180 int row = aEvent.GetRow();
181 int col = aEvent.GetCol();
182
183 if( col == 3 && row >= 0 && row < static_cast<int>( m_targetRAs.size() ) )
184 {
185 const TABLE_ENTRY& entry = m_targetRAs[row];
186
187 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() && m_parentTool )
188 {
189 wxString summary = wxString::Format( _( "Rule area topologies do not match: %s" ), entry.m_errMsg );
190
191 m_parentTool->ShowMismatchDetails( this, summary, entry.m_mismatchReasons );
192 }
193 }
194
195 aEvent.Skip();
196}
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:116
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:741
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
const wxString & GetZoneName() const
Definition zone.h:159
#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