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