KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
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
129
132 }
133 else
134 {
135 wxBell();
136 }
137
138 return 0;
139}
140
141
143{
144 if( CanGoBack() )
145 {
146 m_navIndex--;
147
150
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{
216}
217
218
220{
222 < (int) m_frame->Schematic().Hierarchy().size();
223}
224
225
227{
229 wxCHECK( path, 0 );
230
231 changeSheet( *path );
232
233 return 0;
234}
235
236
238{
240 const SCH_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
241
242 if( selection.GetSize() == 1 )
243 {
245 pushed.push_back( (SCH_SHEET*) selection.Front() );
246
247 changeSheet( pushed );
248 }
249
250 return 0;
251}
252
253
255{
256 if( CanGoUp() )
257 {
259 popped.pop_back();
260
261 changeSheet( popped );
262 }
263 else
264 {
265 wxBell();
266 }
267
268 return 0;
269}
270
271
273{
277
281
284}
285
286
288{
289 if( CanGoForward() )
290 m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
291
292 if( m_navHistory.empty() || ( *(--m_navHistory.end()) != aPath ) )
293 m_navHistory.push_back( aPath );
294
295 m_navIndex = --m_navHistory.end();
296}
297
298
300{
303
304 // Store the current zoom level into the current screen before switching
306
307 pushToHistory( aPath );
308
309 m_frame->FocusOnItem( nullptr );
312}
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
Definition: eda_text.cpp:1295
double GetScale() const
Definition: view.h:272
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition: schematic.h:153
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:208
SCH_SHEET & Root() const
Definition: schematic.h:117
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: sch_actions.h:57
static TOOL_ACTION navigateBack
Definition: sch_actions.h:235
static TOOL_ACTION leaveSheet
Definition: sch_actions.h:232
static TOOL_ACTION navigateNext
Definition: sch_actions.h:237
static TOOL_ACTION navigateForward
Definition: sch_actions.h:234
static TOOL_ACTION navigatePrevious
Definition: sch_actions.h:236
static TOOL_ACTION changeSheet
Definition: sch_actions.h:230
static TOOL_ACTION enterSheet
Definition: sch_actions.h:231
static TOOL_ACTION navigateUp
Definition: sch_actions.h:233
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void DisplayCurrentSheet()
Draw the current sheet on the display.
void FocusOnItem(SCH_ITEM *aItem)
void pushToHistory(SCH_SHEET_PATH aPath)
Change current sheet to aPath and handle history, zooming, etc.
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
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 changeSheet(SCH_SHEET_PATH aPath)
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.
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:658
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=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...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
int GetVirtualPageNumber() const
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
Generic, UI-independent tool event.
Definition: tool_event.h:168
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:465
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
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
const wxString ResolveUriByEnvVars(const wxString &aUri, const PROJECT *aProject)
Replace any environment and/or text variables in URIs.
Definition: common.cpp:364
The common library.
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, EMBEDDED_FILES *aFiles)
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:174