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 (C) 1992-2023, 2024 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
51 while( entry != m_navHistory.end() )
52 {
53 if( std::find( sheets.begin(), sheets.end(), *entry ) != sheets.end() )
54 ++entry;
55 else
56 entry = m_navHistory.erase( entry );
57 }
58}
59
60
61void SCH_NAVIGATE_TOOL::HypertextCommand( const wxString& href )
62{
63 wxString destPage;
64
66 {
68 Back( dummy );
69 }
70 else if( EDA_TEXT::IsGotoPageHref( href, &destPage ) && !destPage.IsEmpty() )
71 {
72 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().Hierarchy() )
73 {
74 if( sheet.GetPageNumber() == destPage )
75 {
76 changeSheet( sheet );
77 return;
78 }
79 }
80
81 m_frame->ShowInfoBarError( wxString::Format( _( "Page '%s' not found." ), destPage ) );
82 }
83 else
84 {
85 wxMenu menu;
86
87 menu.Append( 1, wxString::Format( _( "Open %s" ), href ) );
88
89 if( m_frame->GetPopupMenuSelectionFromUser( menu ) == 1 )
90 GetAssociatedDocument( m_frame, href, &m_frame->Prj(), nullptr, &m_frame->Schematic() );
91 }
92}
93
94
96{
97 // Checks for CanGoUp()
98 LeaveSheet( aEvent );
99 return 0;
100}
101
102
104{
105 if( CanGoForward() )
106 {
107 m_navIndex++;
108
111
114 }
115 else
116 {
117 wxBell();
118 }
119
120 return 0;
121}
122
123
125{
126 if( CanGoBack() )
127 {
128 m_navIndex--;
129
132
135 }
136 else
137 {
138 wxBell();
139 }
140
141 return 0;
142}
143
144
146{
147 if( CanGoPrevious() )
148 {
149 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() - 1;
150 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
151 }
152 else
153 {
154 wxBell();
155 }
156
157 return 0;
158}
159
160
162{
163 if( CanGoNext() )
164 {
165 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() + 1;
166 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
167 }
168 else
169 {
170 wxBell();
171 }
172
173 return 0;
174}
175
176
178{
179 return m_navHistory.size() > 0 && m_navIndex != m_navHistory.begin();
180}
181
182
184{
185 return m_navHistory.size() > 0 && m_navIndex != --m_navHistory.end();
186}
187
188
190{
191 return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
192}
193
194
196{
198}
199
200
202{
204 < (int) m_frame->Schematic().Hierarchy().size();
205}
206
207
209{
211 wxCHECK( path, 0 );
212
213 changeSheet( *path );
214
215 return 0;
216}
217
218
220{
222 const EE_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
223
224 if( selection.GetSize() == 1 )
225 {
227 pushed.push_back( (SCH_SHEET*) selection.Front() );
228
229 changeSheet( pushed );
230 }
231
232 return 0;
233}
234
235
237{
238 if( CanGoUp() )
239 {
241 popped.pop_back();
242
243 changeSheet( popped );
244 }
245 else
246 {
247 wxBell();
248 }
249
250 return 0;
251}
252
253
255{
259
263
266}
267
268
270{
271 if( CanGoForward() )
272 m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
273
274 m_navHistory.push_back( aPath );
275 m_navIndex = --m_navHistory.end();
276}
277
278
280{
283
284 // Store the current zoom level into the current screen before switching
286
287 pushToHistory( aPath );
288
289 m_frame->FocusOnItem( nullptr );
292}
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:1285
static TOOL_ACTION changeSheet
Definition: ee_actions.h:231
static TOOL_ACTION navigateForward
Definition: ee_actions.h:235
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION navigateBack
Definition: ee_actions.h:236
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:233
static TOOL_ACTION enterSheet
Definition: ee_actions.h:232
static TOOL_ACTION navigateNext
Definition: ee_actions.h:238
static TOOL_ACTION navigateUp
Definition: ee_actions.h:234
static TOOL_ACTION navigatePrevious
Definition: ee_actions.h:237
EE_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...
double GetScale() const
Definition: view.h:273
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:161
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:214
SCH_SHEET & Root() const
Definition: schematic.h:125
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)
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:636
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:57
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
Generic, UI-independent tool event.
Definition: tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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
#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