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 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <tools/ee_actions.h>
27 #include <view/view_controls.h>
28 #include <sch_component.h>
29 #include <sch_marker.h>
30 #include <ee_hotkeys.h>
31 #include <confirm.h>
32 #include <tool/conditional_menu.h>
34 #include <tool/selection.h>
35 #include <tool/tool_manager.h>
36 #include <sch_view.h>
37 #include <sch_edit_frame.h>
38 #include <eda_doc.h>
39 
40 
41 TOOL_ACTION EE_ACTIONS::showDatasheet( "eeschema.InspectionTool.showDatasheet",
43  _( "Show Datasheet" ), _( "Opens the datasheet in a browser" ),
44  datasheet_xpm );
45 
46 TOOL_ACTION EE_ACTIONS::showMarkerInfo( "eeschema.InspectionTool.showMarkerInfo",
47  AS_GLOBAL, 0,
48  _( "Show Marker Info" ), _( "Display the marker's info in a dialog" ),
49  info_xpm );
50 
51 
53  : EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.InspectionTool" )
54 {
55 }
56 
57 
59 {
61 
62  auto singleMarkerCondition = SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T )
64 
65  // Add inspection actions to the selection tool menu
66  //
68 
70  selToolMenu.AddItem( EE_ACTIONS::showMarkerInfo, singleMarkerCondition && EE_CONDITIONS::Idle, 400 );
71 
72  return true;
73 }
74 
75 
77 {
79 
80  if( selection.Empty() )
81  return 0;
82 
83  SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front();
84  wxString datasheet = component->GetField( DATASHEET )->GetText();
85 
86  if( !datasheet.IsEmpty() )
87  GetAssociatedDocument( m_frame, datasheet );
88 
89  return 0;
90 }
91 
92 
94 {
95  SELECTION& selection = m_selectionTool->GetSelection();
96 
97  if( selection.Empty() )
98  return 0;
99 
100  SCH_MARKER* marker = dynamic_cast<SCH_MARKER*>( selection.Front() );
101 
102  if( marker )
103  marker->DisplayMarkerInfo( m_frame );
104 
105  return 0;
106 }
107 
108 
110 {
112  SELECTION& selection = selTool->GetSelection();
113 
114  if( selection.GetSize() == 1 )
115  {
116  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
117 
118  MSG_PANEL_ITEMS msgItems;
119  item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems );
120  m_frame->SetMsgPanel( msgItems );
121  }
122  else
123  {
125  }
126 
127  return 0;
128 }
129 
130 
132 {
135 
139 }
140 
141 
SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION showDatasheet
Inspection.
Definition: ee_actions.h:148
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
name of datasheet
static SELECTION_CONDITION SingleSymbol
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
Definition: actions.h:133
TOOL_MENU & GetToolMenu()
This file is part of the common library.
void setTransitions() override
VIEW_CONTROLS class definition.
This file is part of the common library.
const wxString GetText() const override
Function GetText returns the string associated with the text object.
Definition: sch_field.cpp:105
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key.
Definition: tool_action.h:165
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:87
static const KICAD_T ComponentsOnly[]
Definition: ee_collectors.h:44
static SELECTION_CONDITION Idle
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
int ShowMarkerInfo(const TOOL_EVENT &aEvent)
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:69
static TOOL_ACTION showMarkerInfo
Definition: ee_actions.h:149
void DisplayMarkerInfo(EDA_DRAW_FRAME *aFrame)
Function DisplayMarkerInfo displays the full info of this marker, in a HTML window.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
Class TOOL_EVENT.
Definition: tool_event.h:167
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:143
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
Definition: actions.h:134
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: base_struct.h:321
All active tools
Definition: tool_event.h:143
virtual void ClearMsgPanel()
Clear all messages from the message panel.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
Class TOOL_ACTION.
Definition: tool_action.h:46
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
Class EE_TOOL_BASE.
Definition: ee_tool_base.h:49
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
int ShowDatasheet(const TOOL_EVENT &aEvent)
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function RequestSelection()
EDA_ITEM * Front() const
Definition: selection.h:155