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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <schematic.h>
26#include <eeschema_id.h>
27#include <tools/sch_actions.h>
29#include <common.h>
30#include "eda_doc.h"
31
32
33wxString SCH_NAVIGATE_TOOL::g_BackLink = wxT( "HYPERTEXT_BACK" );
34
35
37{
38 m_navHistory.clear();
39 m_navHistory.push_back( m_frame->GetCurrentSheet() );
40 m_navIndex = m_navHistory.begin();
41}
42
43
45{
46 wxCHECK( m_frame, /* void */ );
47
48 SCH_SHEET_LIST sheets = m_frame->Schematic().Hierarchy();
49
50 wxCHECK( !sheets.empty(), /* void */ );
51
52 // Search through our history, and removing any entries
53 // that the no longer point to a sheet on the schematic
54 auto entry = m_navHistory.begin();
55
56 while( entry != m_navHistory.end() )
57 {
58 if( std::find( sheets.begin(), sheets.end(), *entry ) != sheets.end() )
59 {
60 // Don't allow multiple consecutive instances of the same history.
61 if( ( entry != m_navHistory.begin() ) && ( *entry == *std::prev( entry ) ) )
62 entry = m_navHistory.erase( entry );
63 else
64 ++entry;
65 }
66 else
67 {
68 entry = m_navHistory.erase( entry );
69 }
70 }
71 if( m_navHistory.size() <= 1 )
72 m_navIndex = m_navHistory.begin();
73 else
74 m_navIndex = --m_navHistory.end();
75}
76
77
78void SCH_NAVIGATE_TOOL::HypertextCommand( const wxString& aHref )
79{
80 wxString destPage;
81 wxString href = ResolveUriByEnvVars( aHref, &m_frame->Prj() );
82
84 {
86 Back( dummy );
87 }
88 else if( EDA_TEXT::IsGotoPageHref( href, &destPage ) && !destPage.IsEmpty() )
89 {
90 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().Hierarchy() )
91 {
92 if( sheet.GetPageNumber() == destPage )
93 {
94 changeSheet( sheet );
95 return;
96 }
97 }
98
99 m_frame->ShowInfoBarError( wxString::Format( _( "Page '%s' not found." ), destPage ) );
100 }
101 else
102 {
103 wxMenu menu;
104
105 menu.Append( 1, wxString::Format( _( "Open %s" ), href ) );
106
107 if( m_frame->GetPopupMenuSelectionFromUser( menu ) == 1 )
108 GetAssociatedDocument( m_frame, href, &m_frame->Prj(), nullptr, { &m_frame->Schematic() } );
109 }
110}
111
112
114{
115 // Checks for CanGoUp()
116 LeaveSheet( aEvent );
117 return 0;
118}
119
120
122{
123 if( CanGoForward() )
124 {
125 m_navIndex++;
126
127 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
128 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
129
130 m_frame->SetCurrentSheet( *m_navIndex );
131 m_frame->DisplayCurrentSheet();
132 }
133 else
134 {
135 wxBell();
136 }
137
138 return 0;
139}
140
141
143{
144 if( CanGoBack() )
145 {
146 m_navIndex--;
147
148 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
149 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
150
151 m_frame->SetCurrentSheet( *m_navIndex );
152 m_frame->DisplayCurrentSheet();
153 }
154 else
155 {
156 wxBell();
157 }
158
159 return 0;
160}
161
162
164{
165 if( CanGoPrevious() )
166 {
167 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() - 1;
168 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
169 }
170 else
171 {
172 wxBell();
173 }
174
175 return 0;
176}
177
178
180{
181 if( CanGoNext() )
182 {
183 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() + 1;
184 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
185 }
186 else
187 {
188 wxBell();
189 }
190
191 return 0;
192}
193
194
196{
197 return m_navHistory.size() > 0 && m_navIndex != m_navHistory.begin();
198}
199
200
202{
203 return m_navHistory.size() > 0 && m_navIndex != --m_navHistory.end();
204}
205
206
208{
209 return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
210}
211
212
214{
215 return m_frame->GetCurrentSheet().GetVirtualPageNumber() > 1;
216}
217
218
220{
221 if( !m_frame->Schematic().IsValid() )
222 return false;
223
224 return m_frame->GetCurrentSheet().GetVirtualPageNumber()
225 < (int) m_frame->Schematic().Hierarchy().size();
226}
227
228
230{
232 wxCHECK( path, 0 );
233
234 changeSheet( *path );
235
236 return 0;
237}
238
239
241{
242 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
243 const SCH_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
244
245 if( selection.GetSize() == 1 )
246 {
247 SCH_SHEET_PATH pushed = m_frame->GetCurrentSheet();
248 pushed.push_back( (SCH_SHEET*) selection.Front() );
249
250 changeSheet( pushed );
251 }
252
253 return 0;
254}
255
256
258{
259 if( CanGoUp() )
260 {
261 SCH_SHEET_PATH popped = m_frame->GetCurrentSheet();
262 popped.pop_back();
263
264 changeSheet( popped );
265 }
266 else
267 {
268 wxBell();
269 }
270
271 return 0;
272}
273
274
288
289
291{
292 if( CanGoForward() )
293 m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
294
295 if( m_navHistory.empty() || ( *(--m_navHistory.end()) != aPath ) )
296 m_navHistory.push_back( aPath );
297
298 m_navIndex = --m_navHistory.end();
299}
300
301
303{
304 m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
305 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
306
307 // Store the current zoom level into the current screen before switching
308 m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale();
309
310 pushToHistory( aPath );
311
312 m_frame->ClearFocus();
313 m_frame->Schematic().SetCurrentSheet( aPath );
314 m_frame->DisplayCurrentSheet();
315}
static TOOL_ACTION cancelInteractive
Definition actions.h:72
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
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:47
Generic, UI-independent tool event.
Definition tool_event.h:171
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:473
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:368
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:62
This file is part of the common library.
std::vector< FAB_LAYER_COLOR > dummy
@ SCH_SHEET_T
Definition typeinfo.h:177