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 <grid_tricks.h>
28#include <pcb_edit_frame.h>
30#include <zone.h>
31#include <board.h>
32
33
35 PCB_BASE_FRAME* aFrame,
36 MULTICHANNEL_TOOL *aParentTool ) :
38 m_parentTool( aParentTool )
39{
40 m_board = aFrame->GetBoard();
41 auto data = m_parentTool->GetData();
42 m_refRAName->SetLabelText( data->m_refRA->m_area->GetZoneName() );
43
44 for( auto& ra : data->m_compatMap )
45 {
46 TABLE_ENTRY ent;
47
48 ent.m_doCopy = ra.second.m_isOk;
49 ent.m_errMsg = ra.second.m_errorMsg;
50 ent.m_isOK = ra.second.m_isOk;
51 ent.m_raName = ra.first->m_ruleName;
52 ent.m_targetRA = ra.first;
53
54 m_targetRAs.push_back( ent );
55 }
56
57 std::sort( m_targetRAs.begin(), m_targetRAs.end(),
58 [] ( const TABLE_ENTRY&a ,const TABLE_ENTRY& b ) -> int
59 {
60 if ( !a.m_isOK && b.m_isOK )
61 return 0;
62 else if ( a.m_isOK && !b.m_isOK )
63 return 1;
64 else
65 return a.m_raName < b.m_raName;
66 } );
67
68 int i = 0;
69
70 m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_raGrid ) ) );
71 m_raGrid->ClearGrid();
72 m_raGrid->EnableEditing( true );
73 m_raGrid->HideRowLabels();
74 m_raGrid->SetColLabelValue( 0, wxT("Copy") );
75 m_raGrid->SetColLabelValue( 1, wxT("Target Rule Area") );
76 m_raGrid->SetColLabelValue( 2, wxT("Status") );
77 m_raGrid->SetColLabelValue( 3, wxT( "RefFp" ) );
78 m_raGrid->AutoSizeColumn( 1 );
79 m_raGrid->AppendRows( m_targetRAs.size() - 1 );
80
81 for( TABLE_ENTRY& entry : m_targetRAs)
82 {
83 m_raGrid->SetCellValue( i, 1, entry.m_raName );
84 m_raGrid->SetCellValue( i, 2, entry.m_isOK ? _("OK") : entry.m_errMsg );
85 m_raGrid->SetCellRenderer( i, 0, new wxGridCellBoolRenderer);
86 m_raGrid->SetCellEditor( i, 0, new wxGridCellBoolEditor);
87 m_raGrid->SetCellValue( i, 0, entry.m_doCopy ? wxT("1") : wxT("") );
88 i++;
89 }
90
91 m_raGrid->SetMaxSize( wxSize( -1, 400 ) );
92 m_raGrid->Fit();
93
94 wxArrayString refFpNames;
95 refFpNames.push_back( "" );
96
97 for( FOOTPRINT* fp : data->m_refRA->m_raFootprints )
98 refFpNames.push_back( fp->GetReference() );
99
100 refFpNames.Sort();
101 m_refAnchorFp->Set( refFpNames );
102 m_refAnchorFp->SetSelection( 0 );
103
104 m_cbCopyPlacement->SetValue( data->m_options.m_copyPlacement );
105 m_cbCopyRouting->SetValue( data->m_options.m_copyRouting );
106 m_cbCopyOnlyConnectedRouting->SetValue( data->m_options.m_connectedRoutingOnly );
107 m_cbGroupItems->SetValue( data->m_options.m_groupItems );
108 m_cbCopyOtherItems->SetValue( data->m_options.m_copyOtherItems );
109 m_cbIncludeLockedComponents->SetValue( data->m_options.m_includeLockedItems );
110 m_cbIncludeOffRAComponents->SetValue( data->m_options.m_moveOffRAComponents );
111
112 Layout();
115}
116
118{
119 m_raGrid->PopEventHandler( true );
120}
121
123{
124 auto data = m_parentTool->GetData();
125
126 for( size_t i = 0; i < m_targetRAs.size(); i++ )
127 {
128 wxString doCopy = m_raGrid->GetCellValue( i, 0 );
129
130 data->m_compatMap[m_targetRAs[i].m_targetRA].m_doCopy =
131 !doCopy.CompareTo( wxT( "1" ) ) ? true : false;
132 }
133
134 data->m_options.m_copyPlacement = m_cbCopyPlacement->GetValue();
135 data->m_options.m_copyRouting = m_cbCopyRouting->GetValue();
136 data->m_options.m_connectedRoutingOnly = m_cbCopyOnlyConnectedRouting->GetValue();
137 data->m_options.m_copyOtherItems = m_cbCopyOtherItems->GetValue();
138 data->m_options.m_groupItems = m_cbGroupItems->GetValue();
139 data->m_options.m_includeLockedItems = m_cbIncludeLockedComponents->GetValue();
140 data->m_options.m_moveOffRAComponents = m_cbIncludeOffRAComponents->GetValue();
141
142 if( m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) == "" )
143 {
144 data->m_options.m_anchorFp = nullptr;
145 }
146 else
147 {
148 for( FOOTPRINT* fp : m_board->Footprints() )
149 {
150 if( fp->GetReference() == m_refAnchorFp->GetString( m_refAnchorFp->GetSelection() ) )
151 data->m_options.m_anchorFp = fp;
152 }
153 }
154
155 return true;
156}
157
158
160{
161 // fixme: I have no idea how to use this together with wxGrid so that it resizes correctly...
162
163 //if( !wxDialog::TransferDataToWindow() )
164 //return false;
165
166 return true;
167}
const FOOTPRINTS & Footprints() const
Definition: board.h:358
Class DIALOG_MULTICHANNEL_REPEAT_LAYOUT_BASE.
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:627
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
RULE_AREAS_DATA * GetData()
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
#define _(s)
wxString m_errMsg
bool m_isOK
wxString m_raName
RULE_AREA * m_targetRA
bool m_doCopy