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 PCB_BASE_FRAME* aFrame,
38 MULTICHANNEL_TOOL *aParentTool ) :
40 m_parentTool( aParentTool )
41{
42 m_board = aFrame->GetBoard();
43 auto data = m_parentTool->GetData();
44 m_refRAName->SetLabelText( data->m_refRA->m_zone->GetZoneName() );
46
47 for( auto& ra : data->m_compatMap )
48 {
49 TABLE_ENTRY ent;
50
51 ent.m_doCopy = ra.second.m_isOk;
52 ent.m_errMsg = ra.second.m_errorMsg;
53 ent.m_isOK = ra.second.m_isOk;
54 ent.m_raName = ra.first->m_ruleName;
55 ent.m_targetRA = ra.first;
56 ent.m_mismatchReasons = ra.second.m_mismatchReasons;
57
58 m_targetRAs.push_back( ent );
59 }
60
61 std::sort( m_targetRAs.begin(), m_targetRAs.end(),
62 [] ( const TABLE_ENTRY&a ,const TABLE_ENTRY& b ) -> int
63 {
64 if ( !a.m_isOK && b.m_isOK )
65 return 0;
66 else if ( a.m_isOK && !b.m_isOK )
67 return 1;
68 else
69 return a.m_raName < b.m_raName;
70 } );
71
72 int i = 0;
73
74 m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_raGrid ) ) );
75 m_raGrid->ClearGrid();
76 m_raGrid->EnableEditing( true );
77 m_raGrid->HideRowLabels();
78 m_raGrid->SetColLabelValue( 0, wxT("Copy") );
79 m_raGrid->SetColLabelValue( 1, wxT("Target Rule Area") );
80 m_raGrid->SetColLabelValue( 2, wxT("Status") );
81 m_raGrid->SetColLabelValue( 3, wxT("Details") );
82 m_raGrid->AutoSizeColumn( 1 );
83 m_raGrid->AppendRows( m_targetRAs.size() - 1 );
84
85 for( TABLE_ENTRY& entry : m_targetRAs)
86 {
87 m_raGrid->SetCellValue( i, 1, entry.m_raName );
88 m_raGrid->SetCellValue( i, 2, entry.m_isOK ? _("OK") : entry.m_errMsg );
89 m_raGrid->SetCellValue( i, 3, wxString() );
90 m_raGrid->SetCellRenderer( i, 0, new wxGridCellBoolRenderer);
91 m_raGrid->SetCellEditor( i, 0, new wxGridCellBoolEditor);
92 m_raGrid->SetCellValue( i, 0, entry.m_doCopy ? wxT("1") : wxT("") );
93
94 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() )
95 {
96 wxGridCellAttr* attr = new wxGridCellAttr;
97 attr->SetRenderer( new GRID_CELL_ICON_RENDERER( m_detailsIcon ) );
98 attr->SetReadOnly();
99 m_raGrid->SetAttr( i, 3, attr );
100 m_raGrid->SetCellValue( i, 3, wxString() );
101 }
102
103 i++;
104 }
105
106 m_raGrid->Bind( wxEVT_GRID_CELL_LEFT_CLICK,
108 m_raGrid->SetMaxSize( wxSize( -1, 400 ) );
109 m_raGrid->Fit();
110
111 wxArrayString refFpNames;
112 refFpNames.push_back( "" );
113
114 for( FOOTPRINT* fp : data->m_refRA->m_components )
115 refFpNames.push_back( fp->GetReference() );
116
117 refFpNames.Sort();
118 m_refAnchorFp->Set( refFpNames );
119 m_refAnchorFp->SetSelection( 0 );
120
121 m_cbCopyPlacement->SetValue( data->m_options.m_copyPlacement );
122 m_cbCopyRouting->SetValue( data->m_options.m_copyRouting );
123 m_cbCopyOnlyConnectedRouting->SetValue( data->m_options.m_connectedRoutingOnly );
124 m_cbGroupItems->SetValue( data->m_options.m_groupItems );
125 m_cbCopyOtherItems->SetValue( data->m_options.m_copyOtherItems );
126 m_cbIncludeLockedComponents->SetValue( data->m_options.m_includeLockedItems );
127
128 Layout();
129 SetupStandardButtons();
130 finishDialogSettings();
131}
132
134{
135 m_raGrid->Unbind( wxEVT_GRID_CELL_LEFT_CLICK,
137 m_raGrid->PopEventHandler( true );
138}
139
141{
142 auto data = m_parentTool->GetData();
143
144 for( size_t i = 0; i < m_targetRAs.size(); i++ )
145 {
146 wxString doCopy = m_raGrid->GetCellValue( i, 0 );
147
148 data->m_compatMap[m_targetRAs[i].m_targetRA].m_doCopy =
149 !doCopy.CompareTo( wxT( "1" ) ) ? true : false;
150 }
151
152 data->m_options.m_copyPlacement = m_cbCopyPlacement->GetValue();
153 data->m_options.m_copyRouting = m_cbCopyRouting->GetValue();
154 data->m_options.m_connectedRoutingOnly = m_cbCopyOnlyConnectedRouting->GetValue();
155 data->m_options.m_copyOtherItems = m_cbCopyOtherItems->GetValue();
156 data->m_options.m_groupItems = m_cbGroupItems->GetValue();
157 data->m_options.m_includeLockedItems = m_cbIncludeLockedComponents->GetValue();
158
159 if( m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) == "" )
160 {
161 data->m_options.m_anchorFp = nullptr;
162 }
163 else
164 {
165 for( FOOTPRINT* fp : m_board->Footprints() )
166 {
167 if( fp->GetReference() == m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) )
168 data->m_options.m_anchorFp = fp;
169 }
170 }
171
172 return true;
173}
174
175
177{
178 // fixme: I have no idea how to use this together with wxGrid so that it resizes correctly...
179
180 //if( !wxDialog::TransferDataToWindow() )
181 //return false;
182
183 return true;
184}
185
186
188{
189 int row = aEvent.GetRow();
190 int col = aEvent.GetCol();
191
192 if( col == 3 && row >= 0 && row < static_cast<int>( m_targetRAs.size() ) )
193 {
194 const TABLE_ENTRY& entry = m_targetRAs[row];
195
196 if( !entry.m_isOK && !entry.m_mismatchReasons.empty() && m_parentTool )
197 {
198 wxString summary = wxString::Format(
199 _( "Rule area topologies do not match: %s" ), entry.m_errMsg );
200
201 m_parentTool->ShowMismatchDetails( this, summary, entry.m_mismatchReasons );
202 }
203 }
204
205 aEvent.Skip();
206}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:104
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)
const wxString & GetReference() const
Definition footprint.h:661
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
#define _(s)
wxString m_errMsg
bool m_isOK
std::vector< wxString > m_mismatchReasons