KiCad PCB EDA Suite
ee_inspection_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) 2019-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 <sch_symbol.h>
26#include <id.h>
27#include <kiway.h>
28#include <confirm.h>
31#include <tools/ee_actions.h>
34#include <tools/ee_selection.h>
35#include <sim/sim_plot_frame.h>
36#include <sch_edit_frame.h>
37#include <symbol_edit_frame.h>
38#include <symbol_viewer_frame.h>
39#include <eda_doc.h>
40#include <sch_marker.h>
41#include <project.h>
43#include <dialogs/dialog_erc.h>
44#include <math/util.h> // for KiROUND
45
46
48 EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.InspectionTool" ),
49 m_ercDialog( nullptr )
50{
51}
52
53
55{
57
58 // Add inspection actions to the selection tool menu
59 //
61
63
66
67 return true;
68}
69
70
72{
73 EE_TOOL_BASE::Reset( aReason );
74
75 if( aReason == MODEL_RELOAD )
76 {
78 }
79}
80
81
83{
85 return 0;
86}
87
88
90{
91 if( m_frame->IsType( FRAME_SCH ) )
92 {
93 if( m_ercDialog )
94 {
95 // Needed at least on Windows. Raise() is not enough
96 m_ercDialog->Show( true );
97 // Bring it to the top if already open. Dual monitor users need this.
98 m_ercDialog->Raise();
99 }
100 else
101 {
102 // This is a modeless dialog, so new it rather than instantiating on stack.
103 m_ercDialog = new DIALOG_ERC( static_cast<SCH_EDIT_FRAME*>( m_frame ) );
104
105 m_ercDialog->Show( true );
106 }
107 }
108}
109
110
112{
113 if( m_ercDialog )
114 m_ercDialog->Destroy();
115
116 m_ercDialog = nullptr;
117}
118
119
121{
122 if( m_ercDialog )
123 {
124 m_ercDialog->Show( true );
125 m_ercDialog->Raise();
127 }
128 else
129 {
131 }
132
133 return 0;
134}
135
136
138{
139 if( m_ercDialog )
140 {
141 m_ercDialog->Show( true );
142 m_ercDialog->Raise();
144 }
145 else
146 {
148 }
149
150 return 0;
151}
152
153
155{
156 if( m_ercDialog )
157 {
159 EE_SELECTION& selection = selectionTool->GetSelection();
160
161 if( selection.GetSize() == 1 && selection.Front()->Type() == SCH_MARKER_T )
162 {
163 if( !m_ercDialog->IsShown() )
164 m_ercDialog->Show( true );
165
166 m_ercDialog->SelectMarker( static_cast<SCH_MARKER*>( selection.Front() ) );
167 }
168 }
169
170 // Show the item info on a left click on this item
171 UpdateMessagePanel( aEvent );
172
173 return 0;
174}
175
176
178{
180 EE_SELECTION& selection = selTool->GetSelection();
181 SCH_MARKER* marker = nullptr;
182
183 if( selection.GetSize() == 1 && selection.Front()->Type() == SCH_MARKER_T )
184 marker = static_cast<SCH_MARKER*>( selection.Front() );
185
186 if( m_ercDialog )
187 {
188 // Let the ERC dialog handle it since it has more update hassles to worry about
189 // Note that if marker is nullptr the dialog will exclude whichever marker is selected
190 // in the dialog itself
191 m_ercDialog->ExcludeMarker( marker );
192 }
193 else if( marker != nullptr )
194 {
195 marker->SetExcluded( true );
196 m_frame->GetCanvas()->GetView()->Update( marker );
198 m_frame->OnModify();
199 }
200
201 return 0;
202}
203
204
205extern void CheckLibSymbol( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
206 int aGridForPins, EDA_DRAW_FRAME* aUnitsProvider );
207
209{
210 LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
211
212 if( !symbol )
213 return 0;
214
215 std::vector<wxString> messages;
216 const int grid_size = KiROUND( getView()->GetGAL()->GetGridSize().x );
217
218 CheckLibSymbol( symbol, messages, grid_size, m_frame );
219
220 if( messages.empty() )
221 {
222 DisplayInfoMessage( m_frame, _( "No symbol issues found." ) );
223 }
224 else
225 {
226 HTML_MESSAGE_BOX dlg( m_frame, _( "Symbol Warnings" ) );
227
228 for( const wxString& single_msg : messages )
229 dlg.AddHTML_Text( single_msg );
230
231 dlg.ShowModal();
232 }
233
234 return 0;
235}
236
237
239{
240#ifdef KICAD_SPICE
242
243 if( !simFrame )
244 return -1;
245
246 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
247 blocking_win->Close( true );
248
249 simFrame->Show( true );
250
251 // On Windows, Raise() does not bring the window on screen, when iconized
252 if( simFrame->IsIconized() )
253 simFrame->Iconize( false );
254
255 simFrame->Raise();
256#endif /* KICAD_SPICE */
257 return 0;
258}
259
260
262{
263 wxString datasheet;
264
266 {
267 LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
268
269 if( !symbol )
270 return 0;
271
272 datasheet = symbol->GetDatasheetField().GetText();
273 }
275 {
276 LIB_SYMBOL* entry = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame )->GetSelectedSymbol();
277
278 if( !entry )
279 return 0;
280
282 }
283 else if( m_frame->IsType( FRAME_SCH ) )
284 {
286
287 if( selection.Empty() )
288 return 0;
289
290 SCH_SYMBOL* symbol = (SCH_SYMBOL*) selection.Front();
291
292 // Use GetShownText() to resolve any text variables
294 }
295
296 if( datasheet.IsEmpty() || datasheet == wxT( "~" ) )
297 {
298 m_frame->ShowInfoBarError( _( "No datasheet defined." ) );
299 }
300 else
301 {
302 GetAssociatedDocument( m_frame, datasheet, &m_frame->Prj(), m_frame->Prj().SchSearchS() );
303 }
304
305 return 0;
306}
307
308
310{
312 EE_SELECTION& selection = selTool->GetSelection();
313
314 if( selection.GetSize() == 1 )
315 {
316 EDA_ITEM* item = (EDA_ITEM*) selection.Front();
317
318 std::vector<MSG_PANEL_ITEM> msgItems;
319 item->GetMsgPanelInfo( m_frame, msgItems );
320 m_frame->SetMsgPanel( msgItems );
321 }
322 else
323 {
325 }
326
327 if( SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
328 editFrame->UpdateNetHighlightStatus();
329
330 return 0;
331}
332
333
335{
339 // See note 1:
343
346
348
349 // Note 1: tUpdateMessagePanel is called by CrossProbe. So uncomment this line if
350 // call to CrossProbe is modifiied
351 // Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedEvent );
355}
356
357
static TOOL_ACTION excludeMarker
Definition: actions.h:89
static TOOL_ACTION nextMarker
Definition: actions.h:88
static TOOL_ACTION prevMarker
Definition: actions.h:87
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
void ExcludeMarker(SCH_MARKER *aMarker=nullptr)
Exclude aMarker from the ERC list.
Definition: dialog_erc.cpp:823
void SelectMarker(const SCH_MARKER *aMarker)
Definition: dialog_erc.cpp:800
void PrevMarker()
Definition: dialog_erc.cpp:776
void NextMarker()
Definition: dialog_erc.cpp:788
bool Show(bool show) override
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...
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: eda_item.h:211
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
static TOOL_ACTION runERC
Definition: ee_actions.h:153
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:152
static TOOL_ACTION checkSymbol
Definition: ee_actions.h:167
static TOOL_ACTION runSimulation
Definition: ee_actions.h:247
static SELECTION_CONDITION SingleSymbol
static SELECTION_CONDITION SingleNonExcludedMarker
int RunSimulation(const TOOL_EVENT &aEvent)
DIALOG_ERC * m_ercDialog
int NextMarker(const TOOL_EVENT &aEvent)
int PrevMarker(const TOOL_EVENT &aEvent)
int ShowDatasheet(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void setTransitions() override
<
int ExcludeMarker(const TOOL_EVENT &aEvent)
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
Display the selected item info (when clicking on a item)
bool Init() override
Init() is called once upon a registration of the tool.
int RunERC(const TOOL_EVENT &aEvent)
int CheckSymbol(const TOOL_EVENT &aEvent)
int CrossProbe(const TOOL_EVENT &aEvent)
Called when clicking on a item:
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...
EE_SELECTION & GetSelection()
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:50
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: ee_tool_base.h:86
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:184
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:66
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:207
static const TOOL_EVENT SelectedEvent
Definition: actions.h:205
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:210
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:204
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:206
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1574
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:617
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
void SetExcluded(bool aExcluded)
Definition: marker_base.h:98
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Schematic editor (Eeschema) main window.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:169
Schematic symbol object.
Definition: sch_symbol.h:80
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:892
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
EDA_ITEM * Front() const
Definition: selection.h:200
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:107
Implementing SIM_PLOT_FRAME_BASE.
The symbol library editor main window.
Symbol library viewer main window.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ MODEL_RELOAD
Model changes (required full reload)
Definition: tool_base.h:80
Generic, UI-independent tool event.
Definition: tool_event.h:156
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).
TOOL_MENU & GetToolMenu()
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:320
This file is part of the common library.
#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 CheckLibSymbol(LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, int aGridForPins, EDA_DRAW_FRAME *aUnitsProvider)
Check a lib symbol to find incorrect settings Pins not on a valid grid Pins duplicated Conflict with ...
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34
@ FRAME_SCH_VIEWER_MODAL
Definition: frame_type.h:37
@ FRAME_SIMULATOR
Definition: frame_type.h:38
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
@ DATASHEET_FIELD
name of datasheet
@ SCH_SYMBOL_T
Definition: typeinfo.h:155
@ SCH_MARKER_T
Definition: typeinfo.h:140
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80