KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_migrate_buses.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) 2018 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jon Evans <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <sch_connection.h>
23#include <schematic.h>
24#include <connection_graph.h>
25#include <tool/tool_manager.h>
26#include <tool/actions.h>
28#include <sch_label.h>
29#include <view/view_controls.h>
30
61 : DIALOG_MIGRATE_BUSES_BASE( aParent ), m_frame( aParent ), m_selected_index( 0 )
62{
63 OptOut( this ); // No control state save/restore
64
65 m_migration_list->Bind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_MIGRATE_BUSES::onItemSelected, this );
66 m_btn_accept->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MIGRATE_BUSES::onAcceptClicked, this );
67
69 updateUi();
70
72}
73
74
76{
77 m_migration_list->Unbind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_MIGRATE_BUSES::onItemSelected, this );
78 m_btn_accept->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MIGRATE_BUSES::onAcceptClicked, this );
79}
80
81
83{
84 m_items.clear();
86
87 for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
88 {
90
91 status.subgraph = subgraph;
92 status.approved = false;
93
94 std::vector<SCH_ITEM*> labels = subgraph->GetVectorBusLabels();
95 wxASSERT( labels.size() > 1 );
96
97 for( SCH_ITEM* label : labels )
98 status.labels.push_back( static_cast<SCH_LABEL_BASE*>( label )->GetText() );
99
100 status.possible_labels = getProposedLabels( status.labels );
101 m_items.push_back( status );
102 }
103}
104
105
107{
108 m_migration_list->DeleteAllItems();
109
110 m_migration_list->InsertColumn( 0, _( "Sheet" ) );
111 m_migration_list->InsertColumn( 1, _( "Conflicting Labels" ) );
112 m_migration_list->InsertColumn( 2, _( "New Label" ) );
113 m_migration_list->InsertColumn( 3, _( "Status" ) );
114
115 for( auto& item : m_items )
116 {
117 wxString old = item.labels[0];
118
119 for( unsigned j = 1; j < item.labels.size(); j++ )
120 old << ", " << item.labels[j];
121
122 auto i = m_migration_list->InsertItem( m_migration_list->GetItemCount(), wxEmptyString );
123
124 m_migration_list->SetItem( i, 0, item.subgraph->GetSheet().PathHumanReadable() );
125 m_migration_list->SetItem( i, 1, old );
126 m_migration_list->SetItem( i, 2, item.possible_labels[0] );
127 m_migration_list->SetItem( i, 3, "" );
128 }
129
130 m_migration_list->Select( 0 );
131 m_migration_list->SetColumnWidth( 1, -1 );
132}
133
134
135std::vector<wxString> DIALOG_MIGRATE_BUSES::getProposedLabels( const std::vector<wxString>& aLabelList )
136{
137 int lowest_start = INT_MAX;
138 int highest_end = -1;
139 int widest_bus = -1;
140
142
143 for( const wxString& label : aLabelList )
144 {
145 conn.ConfigureFromLabel( label );
146
147 int start = conn.VectorStart();
148 int end = conn.VectorEnd();
149
150 if( start < lowest_start )
151 lowest_start = start;
152
153 if( end > highest_end )
154 highest_end = end;
155
156 if( end - start + 1 > widest_bus )
157 widest_bus = end - start + 1;
158 }
159
160 std::vector<wxString> proposals;
161
162 for( const wxString& label : aLabelList )
163 {
164 conn.ConfigureFromLabel( label );
165 wxString proposal = conn.VectorPrefix();
166 proposal << "[" << highest_end << ".." << lowest_start << "]";
167 proposals.push_back( proposal );
168 }
169
170 return proposals;
171}
172
173
174void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
175{
176 unsigned sel = aEvent.GetIndex();
177 wxASSERT( sel < m_items.size() );
178
179 m_selected_index = sel;
180
181 const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph;
182 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
183 const SCH_ITEM* driver = subgraph->GetDriver();
184
185 if( sheet != m_frame->GetCurrentSheet() )
186 {
190 }
191
192 VECTOR2I pos = driver->GetPosition();
193
195 m_frame->RedrawScreen( pos, false );
196
197 m_cb_new_name->Clear();
198
199 for( const wxString& option : m_items[sel].possible_labels )
200 m_cb_new_name->Append( option );
201
202 m_cb_new_name->Select( 0 );
203}
204
205
206void DIALOG_MIGRATE_BUSES::onAcceptClicked( wxCommandEvent& aEvent )
207{
208 wxASSERT( m_selected_index < m_items.size() );
209
210 unsigned sel = m_selected_index;
211
212 m_items[sel].approved_label = m_cb_new_name->GetStringSelection();
213 m_items[sel].approved = true;
214
215 std::vector<SCH_ITEM*> labels = m_items[sel].subgraph->GetVectorBusLabels();
216
217 for( SCH_ITEM* label : labels )
218 static_cast<SCH_LABEL_BASE*>( label )->SetText( m_items[sel].approved_label );
219
220 m_migration_list->SetItem( sel, 2, m_items[sel].approved_label );
221 m_migration_list->SetItem( sel, 3, _( "Updated" ) );
222
223 if( sel < m_items.size() - 1 )
224 m_migration_list->Select( sel + 1 );
225
227}
static TOOL_ACTION zoomFitScreen
Definition: actions.h:141
std::vector< const CONNECTION_SUBGRAPH * > GetBusesNeedingMigration()
Determine which subgraphs have more than one conflicting bus label.
A subgraph is a set of items that are electrically connected on a single sheet.
const SCH_ITEM * GetDriver() const
const SCH_SHEET_PATH & GetSheet() const
Class DIALOG_MIGRATE_BUSES_BASE.
void onAcceptClicked(wxCommandEvent &aEvent)
void onItemSelected(wxListEvent &aEvent)
SCH_EDIT_FRAME * m_frame
std::vector< wxString > getProposedLabels(const std::vector< wxString > &aLabelList)
std::vector< BUS_MIGRATION_STATUS > m_items
DIALOG_MIGRATE_BUSES(SCH_EDIT_FRAME *aParent)
Migrates buses using legacy multi-label joining behavior.
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:272
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition: schematic.h:176
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:183
virtual void RedrawScreen(const VECTOR2I &aCenterPoint, bool aWarpPointer)
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
long VectorEnd() const
void ConfigureFromLabel(const wxString &aLabel)
Configures the connection given a label.
long VectorStart() const
wxString VectorPrefix() const
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
#define _(s)
std::vector< wxString > possible_labels
const CONNECTION_SUBGRAPH * subgraph
std::vector< wxString > labels
VECTOR2I end