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