KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_navigate_tool.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) 2019 CERN
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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <schematic.h>
22#include <eeschema_id.h>
23#include <tools/sch_actions.h>
25#include <common.h>
26#include "eda_doc.h"
27
28
29wxString SCH_NAVIGATE_TOOL::g_BackLink = wxT( "HYPERTEXT_BACK" );
30
31
33{
34 m_navHistory.clear();
35 m_navHistory.push_back( m_frame->GetCurrentSheet() );
36 m_navIndex = m_navHistory.begin();
37}
38
39
41{
42 wxCHECK( m_frame, /* void */ );
43
44 SCH_SHEET_LIST sheets = m_frame->Schematic().Hierarchy();
45
46 wxCHECK( !sheets.empty(), /* void */ );
47
48 // Search through our history, and removing any entries
49 // that the no longer point to a sheet on the schematic
50 auto entry = m_navHistory.begin();
51
52 while( entry != m_navHistory.end() )
53 {
54 if( std::find( sheets.begin(), sheets.end(), *entry ) != sheets.end() )
55 {
56 // Don't allow multiple consecutive instances of the same history.
57 if( ( entry != m_navHistory.begin() ) && ( *entry == *std::prev( entry ) ) )
58 entry = m_navHistory.erase( entry );
59 else
60 ++entry;
61 }
62 else
63 {
64 entry = m_navHistory.erase( entry );
65 }
66 }
67 if( m_navHistory.size() <= 1 )
68 m_navIndex = m_navHistory.begin();
69 else
70 m_navIndex = --m_navHistory.end();
71}
72
73
74void SCH_NAVIGATE_TOOL::HypertextCommand( const wxString& aHref )
75{
76 wxString destPage;
77 wxString href = ResolveUriByEnvVars( aHref, &m_frame->Prj() );
78
80 {
82 Back( dummy );
83 }
84 else if( EDA_TEXT::IsGotoPageHref( href, &destPage ) && !destPage.IsEmpty() )
85 {
86 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().Hierarchy() )
87 {
88 if( sheet.GetPageNumber() == destPage )
89 {
90 changeSheet( sheet );
91 return;
92 }
93 }
94
95 m_frame->ShowInfoBarError( wxString::Format( _( "Page '%s' not found." ), destPage ) );
96 }
97 else
98 {
99 wxMenu menu;
100
101 menu.Append( 1, wxString::Format( _( "Open %s" ), href ) );
102
103 if( m_frame->GetPopupMenuSelectionFromUser( menu ) == 1 )
104 GetAssociatedDocument( m_frame, href, &m_frame->Prj(), nullptr, { &m_frame->Schematic() } );
105 }
106}
107
108
110{
111 // Checks for CanGoUp()
112 LeaveSheet( aEvent );
113 return 0;
114}
115
116
118{
119 if( CanGoForward() )
120 {
121 m_navIndex++;
122
123 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
124 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
125
126 m_frame->SetCurrentSheet( *m_navIndex );
127 m_frame->DisplayCurrentSheet();
128 }
129 else
130 {
131 wxBell();
132 }
133
134 return 0;
135}
136
137
139{
140 if( CanGoBack() )
141 {
142 m_navIndex--;
143
144 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
145 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
146
147 m_frame->SetCurrentSheet( *m_navIndex );
148 m_frame->DisplayCurrentSheet();
149 }
150 else
151 {
152 wxBell();
153 }
154
155 return 0;
156}
157
158
160{
161 if( CanGoPrevious() )
162 {
163 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() - 1;
164 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
165 }
166 else
167 {
168 wxBell();
169 }
170
171 return 0;
172}
173
174
176{
177 if( CanGoNext() )
178 {
179 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() + 1;
180 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
181 }
182 else
183 {
184 wxBell();
185 }
186
187 return 0;
188}
189
190
192{
193 return m_navHistory.size() > 0 && m_navIndex != m_navHistory.begin();
194}
195
196
198{
199 return m_navHistory.size() > 0 && m_navIndex != --m_navHistory.end();
200}
201
202
204{
205 std::vector<SCH_SHEET*> topLevelSheets = m_frame->Schematic().GetTopLevelSheets();
206
207 for( SCH_SHEET* top_sheet : topLevelSheets )
208 {
209 if( m_frame->GetCurrentSheet().Last() == top_sheet )
210 return false;
211 }
212
213 return true;
214}
215
216
218{
219 return m_frame->GetCurrentSheet().GetVirtualPageNumber() > 1;
220}
221
222
224{
225 if( !m_frame->Schematic().IsValid() )
226 return false;
227
228 return m_frame->GetCurrentSheet().GetVirtualPageNumber()
229 < (int) m_frame->Schematic().Hierarchy().size();
230}
231
232
234{
236 wxCHECK( path, 0 );
237
238 changeSheet( *path );
239
240 return 0;
241}
242
243
245{
246 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
247 const SCH_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
248
249 if( selection.GetSize() == 1 )
250 {
251 SCH_SHEET_PATH pushed = m_frame->GetCurrentSheet();
252 pushed.push_back( (SCH_SHEET*) selection.Front() );
253
254 changeSheet( pushed );
255 }
256
257 return 0;
258}
259
260
262{
263 if( CanGoUp() )
264 {
265 SCH_SHEET_PATH popped = m_frame->GetCurrentSheet();
266 popped.pop_back();
267
268 changeSheet( popped );
269 }
270 else
271 {
272 wxBell();
273 }
274
275 return 0;
276}
277
278
292
293
295{
296 if( CanGoForward() )
297 m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
298
299 if( m_navHistory.empty() || ( *(--m_navHistory.end()) != aPath ) )
300 m_navHistory.push_back( aPath );
301
302 m_navIndex = --m_navHistory.end();
303}
304
305
307{
308 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
309 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
310
311 // Store the current zoom level into the current screen before switching
312 m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale();
313
314 pushToHistory( aPath );
315
316 m_frame->ClearFocus();
317 m_frame->Schematic().SetCurrentSheet( aPath );
318 m_frame->DisplayCurrentSheet();
319}
static TOOL_ACTION cancelInteractive
Definition actions.h:68
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
static TOOL_ACTION navigateBack
static TOOL_ACTION leaveSheet
static TOOL_ACTION navigateNext
static TOOL_ACTION navigateForward
static TOOL_ACTION navigatePrevious
static TOOL_ACTION changeSheet
static TOOL_ACTION enterSheet
static TOOL_ACTION navigateUp
void ResetHistory()
Remove deleted pages from history. Must be done when schematic.
void CleanHistory()
Enter sheet provided in aEvent.
int Back(const TOOL_EVENT &aEvent)
Navigate to previous sheet by numeric sheet number.
int Previous(const TOOL_EVENT &aEvent)
Navigate to next sheet by numeric sheet number.
int Next(const TOOL_EVENT &aEvent)
std::list< SCH_SHEET_PATH >::iterator m_navIndex
void changeSheet(const SCH_SHEET_PATH &aPath)
int ChangeSheet(const TOOL_EVENT &aEvent)
Enter selected sheet.
int Forward(const TOOL_EVENT &aEvent)
Navigate back in sheet history.
int EnterSheet(const TOOL_EVENT &aEvent)
Return to parent sheet. Synonymous with Up.
static wxString g_BackLink
void pushToHistory(const SCH_SHEET_PATH &aPath)
Change current sheet to aPath and handle history, zooming, etc.
void HypertextCommand(const wxString &aHref)
int Up(const TOOL_EVENT &aEvent)
Navigate forward in sheet history.
void setTransitions() override
< Set up handlers for various events.
std::list< SCH_SHEET_PATH > m_navHistory
int LeaveSheet(const TOOL_EVENT &aEvent)
Navigate up in sheet hierarchy.
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
Generic, UI-independent tool event.
Definition tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:469
void Go(int(SCH_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
const wxString ResolveUriByEnvVars(const wxString &aUri, const PROJECT *aProject)
Replace any environment and/or text variables in URIs.
Definition common.cpp:717
The common library.
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
Definition eda_doc.cpp:59
This file is part of the common library.
std::vector< FAB_LAYER_COLOR > dummy
std::string path
@ SCH_SHEET_T
Definition typeinfo.h:172