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#include <footprint.h>
35
36
38 MULTICHANNEL_TOOL *aParentTool ) :
40 m_parentTool( aParentTool )
41{
42 m_board = aFrame->GetBoard();
44
45 m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_raGrid ) ) );
46 m_raGrid->ClearGrid();
47 m_raGrid->EnableEditing( true );
48 m_raGrid->AutoSizeColumn( 1 );
49 m_raGrid->SetupColumnAutosizer( 1 );
50
51 m_raGrid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &DIALOG_MULTICHANNEL_REPEAT_LAYOUT::OnGridCellLeftClick, this );
52
53 Layout();
56}
57
63
65{
66 auto data = m_parentTool->GetData();
67
68 for( size_t i = 0; i < m_targetRAs.size(); i++ )
69 {
70 wxString doCopy = m_raGrid->GetCellValue( i, 0 );
71
72 data->m_compatMap[m_targetRAs[i].m_targetRA].m_doCopy = !doCopy.CompareTo( wxT( "1" ) ) ? true : false;
73 }
74
75 data->m_options.m_copyPlacement = m_cbCopyPlacement->GetValue();
76 data->m_options.m_copyRouting = m_cbCopyRouting->GetValue();
77 data->m_options.m_connectedRoutingOnly = m_cbCopyOnlyConnectedRouting->GetValue();
78 data->m_options.m_copyOtherItems = m_cbCopyOtherItems->GetValue();
79 data->m_options.m_groupItems = m_cbGroupItems->GetValue();
80 data->m_options.m_includeLockedItems = m_cbIncludeLockedComponents->GetValue();
81
82 if( m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) == "" )
83 {
84 data->m_options.m_anchorFp = nullptr;
85 }
86 else
87 {
88 for( FOOTPRINT* fp : m_board->Footprints() )
89 {
90 if( fp->GetReference() == m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) )
91 data->m_options.m_anchorFp = fp;
92 }
93 }
94
95 return true;
96}
97
98
100{
101 RULE_AREAS_DATA* data = m_parentTool->GetData();
102
103 for( const auto& [ruleArea, ruleAreaData] : data->m_compatMap )
104 {
105 TABLE_ENTRY ent;
106
107 ent.m_doCopy = ruleAreaData.m_isOk;
108 ent.m_errMsg = ruleAreaData.m_errorMsg;
109 ent.m_isOK = ruleAreaData.m_isOk;
110 ent.m_raName = ruleArea->m_ruleName;
111 ent.m_targetRA = ruleArea;
112 ent.m_mismatchReasons = ruleAreaData.m_mismatchReasons;
113
114 m_targetRAs.push_back( ent );
115 }
116
117 std::sort( m_targetRAs.begin(), m_targetRAs.end(),
118 [] ( const TABLE_ENTRY&a ,const TABLE_ENTRY& b ) -> int
119 {
120 if ( !a.m_isOK && b.m_isOK )
121 return 0;
122 else if ( a.m_isOK && !b.m_isOK )
123 return 1;
124 else
125 return a.m_raName < b.m_raName;
126 } );
127
128 m_raGrid->ClearRows();
129 m_raGrid->AppendRows( m_targetRAs.size() );
130
131 int i = 0;
132
133 for( TABLE_ENTRY& entry : m_targetRAs )
134 {
135 m_raGrid->SetCellValue( i, 1, entry.m_raName );
136 m_raGrid->SetCellValue( i, 2, entry.m_isOK ? _( "OK" ) : entry.m_errMsg );
137 m_raGrid->SetCellValue( i, 3, wxString() );
138 m_raGrid->SetCellRenderer( i, 0, new wxGridCellBoolRenderer);
139 m_raGrid->SetCellEditor( i, 0, new wxGridCellBoolEditor);
140 m_raGrid->SetCellValue( i, 0, entry.m_doCopy ? wxT( "1" ) : wxT( "" ) );
141
142 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() )
143 {
144 wxGridCellAttr* attr = new wxGridCellAttr;
145 attr->SetRenderer( new GRID_CELL_ICON_RENDERER( m_detailsIcon ) );
146 attr->SetReadOnly();
147 m_raGrid->SetAttr( i, 3, attr );
148 m_raGrid->SetCellValue( i, 3, wxString() );
149 }
150
151 i++;
152 }
153
154 m_raGrid->Fit();
155
156 m_refRAName->SetLabelText( data->m_refRA->m_zone->GetZoneName() );
157
158 wxArrayString refFpNames;
159 refFpNames.push_back( "" );
160
161 for( FOOTPRINT* fp : data->m_refRA->m_components )
162 refFpNames.push_back( fp->GetReference() );
163
164 refFpNames.Sort();
165 m_refAnchorFp->Set( refFpNames );
166 m_refAnchorFp->SetSelection( 0 );
167
169 m_cbCopyRouting->SetValue( data->m_options.m_copyRouting );
171 m_cbGroupItems->SetValue( data->m_options.m_groupItems );
174
175 return true;
176}
177
178
180{
181 int row = aEvent.GetRow();
182 int col = aEvent.GetCol();
183
184 if( col == 3 && row >= 0 && row < static_cast<int>( m_targetRAs.size() ) )
185 {
186 const TABLE_ENTRY& entry = m_targetRAs[row];
187
188 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() && m_parentTool )
189 {
190 wxString summary = wxString::Format( _( "Rule area topologies do not match: %s" ), entry.m_errMsg );
191
192 m_parentTool->ShowMismatchDetails( this, summary, entry.m_mismatchReasons );
193 }
194 }
195
196 aEvent.Skip();
197}
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:751
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:163
#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