KiCad PCB EDA Suite
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 (C) 1992-2022 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/ee_actions.h>
29#include "eda_doc.h"
30
31
32wxString SCH_NAVIGATE_TOOL::g_BackLink = wxT( "HYPERTEXT_BACK" );
33
34
36{
37 m_navHistory.clear();
38 m_navHistory.push_back( m_frame->GetCurrentSheet() );
39 m_navIndex = m_navHistory.begin();
40}
41
42
44{
46
47 // Search through our history, and removing any entries
48 // that the no longer point to a sheet on the schematic
49 auto entry = m_navHistory.begin();
50 while( entry != m_navHistory.end() )
51 {
52 if( std::find( sheets.begin(), sheets.end(), *entry ) != sheets.end() )
53 ++entry;
54 else
55 entry = m_navHistory.erase( entry );
56 }
57}
58
59
60void SCH_NAVIGATE_TOOL::HypertextCommand( const wxString& href )
61{
62 wxString destPage;
63
65 {
67 Back( dummy );
68 }
69 else if( EDA_TEXT::IsGotoPageHref( href, &destPage ) && !destPage.IsEmpty() )
70 {
71 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
72 {
73 if( sheet.GetPageNumber() == destPage )
74 {
75 changeSheet( sheet );
76 return;
77 }
78 }
79
80 m_frame->ShowInfoBarError( wxString::Format( _( "Page '%d' not found." ), destPage ) );
81 }
82 else
83 {
84 wxMenu menu;
85
86 menu.Append( 1, wxString::Format( _( "Open %s" ), href ) );
87
88 if( m_frame->GetPopupMenuSelectionFromUser( menu ) == 1 )
90 }
91}
92
93
95{
96 // Checks for CanGoUp()
97 LeaveSheet( aEvent );
98 return 0;
99}
100
101
103{
104 if( CanGoForward() )
105 {
106 m_navIndex++;
107
110
113 }
114
115 return 0;
116}
117
118
120{
121 if( CanGoBack() )
122 {
123 m_navIndex--;
124
127
130 }
131
132 return 0;
133}
134
135
137{
138 if( CanGoPrevious() )
141
142 return 0;
143}
144
145
147{
148 if( CanGoNext() )
151
152 return 0;
153}
154
155
157{
158 return m_navHistory.size() > 0 && m_navIndex != m_navHistory.begin();
159}
160
161
163{
164 return m_navHistory.size() > 0 && m_navIndex != --m_navHistory.end();
165}
166
167
169{
170 return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
171}
172
173
175{
177}
178
179
181{
183 < (int) m_frame->Schematic().GetSheets().size();
184}
185
186
188{
190 wxCHECK( path, 0 );
191
192 changeSheet( *path );
193
194 return 0;
195}
196
197
199{
201 const EE_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
202
203 if( selection.GetSize() == 1 )
204 {
206 pushed.push_back( (SCH_SHEET*) selection.Front() );
207
208 changeSheet( pushed );
209 }
210
211 return 0;
212}
213
214
216{
217 if( CanGoUp() )
218 {
220 popped.pop_back();
221
222 changeSheet( popped );
223 }
224
225 return 0;
226}
227
228
230{
234
238
241}
242
243
245{
246 if( CanGoForward() )
248
249 m_navHistory.push_back( aPath );
250 m_navIndex = --m_navHistory.end();
251}
252
253
255{
258
259 // Store the current zoom level into the current screen before switching
261
262 pushToHistory( aPath );
263
264 m_frame->SetCurrentSheet( aPath );
266}
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
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:998
static TOOL_ACTION changeSheet
Definition: ee_actions.h:200
static TOOL_ACTION navigateForward
Definition: ee_actions.h:204
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION navigateBack
Definition: ee_actions.h:205
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:202
static TOOL_ACTION enterSheet
Definition: ee_actions.h:201
static TOOL_ACTION navigateNext
Definition: ee_actions.h:207
static TOOL_ACTION navigateUp
Definition: ee_actions.h:203
static TOOL_ACTION navigatePrevious
Definition: ee_actions.h:206
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
double GetScale() const
Definition: view.h:269
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:86
SCH_SHEET & Root() const
Definition: schematic.h:91
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 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)
int Up(const TOOL_EVENT &aEvent)
Navigate forward in sheet history.
void HypertextCommand(const wxString &href)
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:543
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:55
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
Generic, UI-independent tool event.
Definition: tool_event.h:156
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:442
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, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
This file is part of the common library.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
CITER next(CITER it)
Definition: ptree.cpp:126
std::vector< FAB_LAYER_COLOR > dummy
@ SCH_SHEET_T
Definition: typeinfo.h:158