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/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{
45 wxCHECK( m_frame, /* void */ );
46
48
49 wxCHECK( !sheets.empty(), /* void */ );
50
51 // Search through our history, and removing any entries
52 // that the no longer point to a sheet on the schematic
53 auto entry = m_navHistory.begin();
54
55 while( entry != m_navHistory.end() )
56 {
57 if( std::find( sheets.begin(), sheets.end(), *entry ) != sheets.end() )
58 {
59 // Don't allow multiple consecutive instances of the same history.
60 if( ( entry != m_navHistory.begin() ) && ( *entry == *std::prev( entry ) ) )
61 entry = m_navHistory.erase( entry );
62 else
63 ++entry;
64 }
65 else
66 {
67 entry = m_navHistory.erase( entry );
68 }
69 }
70 if( m_navHistory.size() <= 1 )
71 m_navIndex = m_navHistory.begin();
72 else
73 m_navIndex = --m_navHistory.end();
74}
75
76
77void SCH_NAVIGATE_TOOL::HypertextCommand( const wxString& href )
78{
79 wxString destPage;
80
82 {
84 Back( dummy );
85 }
86 else if( EDA_TEXT::IsGotoPageHref( href, &destPage ) && !destPage.IsEmpty() )
87 {
88 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().Hierarchy() )
89 {
90 if( sheet.GetPageNumber() == destPage )
91 {
92 changeSheet( sheet );
93 return;
94 }
95 }
96
97 m_frame->ShowInfoBarError( wxString::Format( _( "Page '%s' not found." ), destPage ) );
98 }
99 else
100 {
101 wxMenu menu;
102
103 menu.Append( 1, wxString::Format( _( "Open %s" ), href ) );
104
105 if( m_frame->GetPopupMenuSelectionFromUser( menu ) == 1 )
106 GetAssociatedDocument( m_frame, href, &m_frame->Prj(), nullptr, &m_frame->Schematic() );
107 }
108}
109
110
112{
113 // Checks for CanGoUp()
114 LeaveSheet( aEvent );
115 return 0;
116}
117
118
120{
121 if( CanGoForward() )
122 {
123 m_navIndex++;
124
127
130 }
131 else
132 {
133 wxBell();
134 }
135
136 return 0;
137}
138
139
141{
142 if( CanGoBack() )
143 {
144 m_navIndex--;
145
148
151 }
152 else
153 {
154 wxBell();
155 }
156
157 return 0;
158}
159
160
162{
163 if( CanGoPrevious() )
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 if( CanGoNext() )
180 {
181 int targetSheet = m_frame->GetCurrentSheet().GetVirtualPageNumber() + 1;
182 changeSheet( m_frame->Schematic().Hierarchy().at( targetSheet - 1 ) );
183 }
184 else
185 {
186 wxBell();
187 }
188
189 return 0;
190}
191
192
194{
195 return m_navHistory.size() > 0 && m_navIndex != m_navHistory.begin();
196}
197
198
200{
201 return m_navHistory.size() > 0 && m_navIndex != --m_navHistory.end();
202}
203
204
206{
207 return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
208}
209
210
212{
214}
215
216
218{
220 < (int) m_frame->Schematic().Hierarchy().size();
221}
222
223
225{
227 wxCHECK( path, 0 );
228
229 changeSheet( *path );
230
231 return 0;
232}
233
234
236{
238 const EE_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
239
240 if( selection.GetSize() == 1 )
241 {
243 pushed.push_back( (SCH_SHEET*) selection.Front() );
244
245 changeSheet( pushed );
246 }
247
248 return 0;
249}
250
251
253{
254 if( CanGoUp() )
255 {
257 popped.pop_back();
258
259 changeSheet( popped );
260 }
261 else
262 {
263 wxBell();
264 }
265
266 return 0;
267}
268
269
271{
275
279
282}
283
284
286{
287 if( CanGoForward() )
288 m_navHistory.erase( std::next( m_navIndex ), m_navHistory.end() );
289
290 if( m_navHistory.empty() || ( *(--m_navHistory.end()) != aPath ) )
291 m_navHistory.push_back( aPath );
292
293 m_navIndex = --m_navHistory.end();
294}
295
296
298{
301
302 // Store the current zoom level into the current screen before switching
304
305 pushToHistory( aPath );
306
307 m_frame->FocusOnItem( nullptr );
310}
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:1299
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:272
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:166
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:130
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: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
#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