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_items.clear();
79
80 for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
81 {
83
84 status.subgraph = subgraph;
85 status.approved = false;
86
87 std::vector<SCH_ITEM*> labels = subgraph->GetVectorBusLabels();
88 wxASSERT( labels.size() > 1 );
89
90 for( SCH_ITEM* label : labels )
91 status.labels.push_back( static_cast<SCH_LABEL_BASE*>( label )->GetText() );
92
93 status.possible_labels = getProposedLabels( status.labels );
94 m_items.push_back( status );
95 }
96}
97
98
100{
101 m_migration_list->DeleteAllItems();
102
103 m_migration_list->InsertColumn( 0, _( "Sheet" ) );
104 m_migration_list->InsertColumn( 1, _( "Conflicting Labels" ) );
105 m_migration_list->InsertColumn( 2, _( "New Label" ) );
106 m_migration_list->InsertColumn( 3, _( "Status" ) );
107
108 for( auto& item : m_items )
109 {
110 wxString old = item.labels[0];
111 for( unsigned j = 1; j < item.labels.size(); j++ )
112 old << ", " << item.labels[j];
113
114 auto i = m_migration_list->InsertItem( m_migration_list->GetItemCount(), wxEmptyString );
115
116 m_migration_list->SetItem( i, 0, item.subgraph->GetSheet().PathHumanReadable() );
117 m_migration_list->SetItem( i, 1, old );
118 m_migration_list->SetItem( i, 2, item.possible_labels[0] );
119 m_migration_list->SetItem( i, 3, "" );
120 }
121
122 m_migration_list->Select( 0 );
123 m_migration_list->SetColumnWidth( 1, -1 );
124}
125
126
128 const std::vector<wxString>& aLabelList )
129{
130 int lowest_start = INT_MAX;
131 int highest_end = -1;
132 int widest_bus = -1;
133
135
136 for( const wxString& label : aLabelList )
137 {
138 conn.ConfigureFromLabel( label );
139
140 int start = conn.VectorStart();
141 int end = conn.VectorEnd();
142
143 if( start < lowest_start )
144 lowest_start = start;
145
146 if( end > highest_end )
147 highest_end = end;
148
149 if( end - start + 1 > widest_bus )
150 widest_bus = end - start + 1;
151 }
152
153 std::vector<wxString> proposals;
154
155 for( const wxString& label : aLabelList )
156 {
157 conn.ConfigureFromLabel( label );
158 wxString proposal = conn.VectorPrefix();
159 proposal << "[" << highest_end << ".." << lowest_start << "]";
160 proposals.push_back( proposal );
161 }
162
163 return proposals;
164}
165
166
167void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
168{
169 unsigned sel = aEvent.GetIndex();
170 wxASSERT( sel < m_items.size() );
171
172 m_selected_index = sel;
173
174 const CONNECTION_SUBGRAPH* subgraph = m_items[sel].subgraph;
175 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
176 const SCH_ITEM* driver = subgraph->GetDriver();
177
178 if( sheet != m_frame->GetCurrentSheet() )
179 {
183 }
184
185 VECTOR2I pos = driver->GetPosition();
186
188 m_frame->RedrawScreen( pos, false );
189
190 m_cb_new_name->Clear();
191
192 for( const wxString& option : m_items[sel].possible_labels )
193 m_cb_new_name->Append( option );
194
195 m_cb_new_name->Select( 0 );
196}
197
198
199void DIALOG_MIGRATE_BUSES::onAcceptClicked( wxCommandEvent& aEvent )
200{
201 wxASSERT( m_selected_index < m_items.size() );
202
203 unsigned sel = m_selected_index;
204
205 m_items[sel].approved_label = m_cb_new_name->GetStringSelection();
206 m_items[sel].approved = true;
207
208 std::vector<SCH_ITEM*> labels = m_items[sel].subgraph->GetVectorBusLabels();
209
210 for( SCH_ITEM* label : labels )
211 static_cast<SCH_LABEL_BASE*>( label )->SetText( m_items[sel].approved_label );
212
213 m_migration_list->SetItem( sel, 2, m_items[sel].approved_label );
214 m_migration_list->SetItem( sel, 3, _( "Updated" ) );
215
216 if( sel < m_items.size() - 1 )
217 m_migration_list->Select( sel + 1 );
218
220}
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
std::vector< const CONNECTION_SUBGRAPH * > GetBusesNeedingMigration()
Determines 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:232
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:143
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:138
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:147
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:54
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
#define _(s)
std::vector< wxString > possible_labels
const CONNECTION_SUBGRAPH * subgraph
std::vector< wxString > labels