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 (C) 2019-2022 KiCad Developers, see change_log.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
60 : DIALOG_MIGRATE_BUSES_BASE( aParent ), m_frame( aParent ), m_selected_index( 0 )
61{
62 m_migration_list->Bind( wxEVT_LIST_ITEM_SELECTED,
64
65 m_btn_accept->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
67
69 updateUi();
70
72}
73
74
76{
77 m_migration_list->Unbind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_MIGRATE_BUSES::onItemSelected,
78 this );
79
80 m_btn_accept->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MIGRATE_BUSES::onAcceptClicked,
81 this );
82}
83
84
86{
87 m_items.clear();
89
90 for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
91 {
93
94 status.subgraph = subgraph;
95 status.approved = false;
96
97 std::vector<SCH_ITEM*> labels = subgraph->GetVectorBusLabels();
98 wxASSERT( labels.size() > 1 );
99
100 for( SCH_ITEM* label : labels )
101 status.labels.push_back( static_cast<SCH_LABEL_BASE*>( label )->GetText() );
102
103 status.possible_labels = getProposedLabels( status.labels );
104 m_items.push_back( status );
105 }
106}
107
108
110{
111 m_migration_list->DeleteAllItems();
112
113 m_migration_list->InsertColumn( 0, _( "Sheet" ) );
114 m_migration_list->InsertColumn( 1, _( "Conflicting Labels" ) );
115 m_migration_list->InsertColumn( 2, _( "New Label" ) );
116 m_migration_list->InsertColumn( 3, _( "Status" ) );
117
118 for( auto& item : m_items )
119 {
120 wxString old = item.labels[0];
121 for( unsigned j = 1; j < item.labels.size(); j++ )
122 old << ", " << item.labels[j];
123
124 auto i = m_migration_list->InsertItem( m_migration_list->GetItemCount(), wxEmptyString );
125
126 m_migration_list->SetItem( i, 0, item.subgraph->GetSheet().PathHumanReadable() );
127 m_migration_list->SetItem( i, 1, old );
128 m_migration_list->SetItem( i, 2, item.possible_labels[0] );
129 m_migration_list->SetItem( i, 3, "" );
130 }
131
132 m_migration_list->Select( 0 );
133 m_migration_list->SetColumnWidth( 1, -1 );
134}
135
136
138 const std::vector<wxString>& aLabelList )
139{
140 int lowest_start = INT_MAX;
141 int highest_end = -1;
142 int widest_bus = -1;
143
145
146 for( const wxString& label : aLabelList )
147 {
148 conn.ConfigureFromLabel( label );
149
150 int start = conn.VectorStart();
151 int end = conn.VectorEnd();
152
153 if( start < lowest_start )
154 lowest_start = start;
155
156 if( end > highest_end )
157 highest_end = end;
158
159 if( end - start + 1 > widest_bus )
160 widest_bus = end - start + 1;
161 }
162
163 std::vector<wxString> proposals;
164
165 for( const wxString& label : aLabelList )
166 {
167 conn.ConfigureFromLabel( label );
168 wxString proposal = conn.VectorPrefix();
169 proposal << "[" << highest_end << ".." << lowest_start << "]";
170 proposals.push_back( proposal );
171 }
172
173 return proposals;
174}
175
176
177void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
178{
179 unsigned sel = aEvent.GetIndex();
180 wxASSERT( sel < m_items.size() );
181
182 m_selected_index = sel;
183
184 const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph;
185 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
186 const SCH_ITEM* driver = subgraph->GetDriver();
187
188 if( sheet != m_frame->GetCurrentSheet() )
189 {
193 }
194
195 VECTOR2I pos = driver->GetPosition();
196
198 m_frame->RedrawScreen( pos, false );
199
200 m_cb_new_name->Clear();
201
202 for( const wxString& option : m_items[sel].possible_labels )
203 m_cb_new_name->Append( option );
204
205 m_cb_new_name->Select( 0 );
206}
207
208
209void DIALOG_MIGRATE_BUSES::onAcceptClicked( wxCommandEvent& aEvent )
210{
211 wxASSERT( m_selected_index < m_items.size() );
212
213 unsigned sel = m_selected_index;
214
215 m_items[sel].approved_label = m_cb_new_name->GetStringSelection();
216 m_items[sel].approved = true;
217
218 std::vector<SCH_ITEM*> labels = m_items[sel].subgraph->GetVectorBusLabels();
219
220 for( SCH_ITEM* label : labels )
221 static_cast<SCH_LABEL_BASE*>( label )->SetText( m_items[sel].approved_label );
222
223 m_migration_list->SetItem( sel, 2, m_items[sel].approved_label );
224 m_migration_list->SetItem( sel, 3, _( "Updated" ) );
225
226 if( sel < m_items.size() - 1 )
227 m_migration_list->Select( sel + 1 );
228
230}
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
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.
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:239
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:146
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:141
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:165
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:145
#define _(s)
std::vector< wxString > possible_labels
const CONNECTION_SUBGRAPH * subgraph
std::vector< wxString > labels