KiCad PCB EDA Suite
gerbview_control.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) 2017 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <view/view.h>
22 #include <gerbview_painter.h>
23 #include <gerbview_frame.h>
24 #include <tool/tool_manager.h>
25 #include <menus_helpers.h>
26 #include <hotkeys.h>
27 
28 #include "gerbview_actions.h"
29 #include "gerbview_control.h"
31 
32 TOOL_ACTION GERBVIEW_ACTIONS::selectionTool( "gerbview.Control.selectionTool",
33  AS_GLOBAL, 0,
34  "", "", NULL, AF_ACTIVATE );
35 
36 TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged",
37  AS_GLOBAL, 0,
38  "", "", NULL, AF_NOTIFY );
39 
40 TOOL_ACTION GERBVIEW_ACTIONS::highlightClear( "gerbview.Control.highlightClear",
41  AS_GLOBAL, 0,
42  _( "Clear Highlight" ), "", highlight_remove_xpm );
43 
44 TOOL_ACTION GERBVIEW_ACTIONS::highlightNet( "gerbview.Control.highlightNet",
45  AS_GLOBAL, 0,
46  _( "Highlight Net" ), "", general_ratsnest_xpm );
47 
48 TOOL_ACTION GERBVIEW_ACTIONS::highlightComponent( "gerbview.Control.highlightComponent",
49  AS_GLOBAL, 0,
50  _( "Highlight Component" ), "", file_footprint_xpm );
51 
52 TOOL_ACTION GERBVIEW_ACTIONS::highlightAttribute( "gerbview.Control.highlightAttribute",
53  AS_GLOBAL, 0,
54  _( "Highlight Attribute" ), "", flag_xpm );
55 
56 TOOL_ACTION GERBVIEW_ACTIONS::layerNext( "gerbview.Control.layerNext",
58  "", "" );
59 
60 TOOL_ACTION GERBVIEW_ACTIONS::layerPrev( "gerbview.Control.layerPrev",
62  "", "" );
63 
64 TOOL_ACTION GERBVIEW_ACTIONS::linesDisplayOutlines( "gerbview.Control.linesDisplayOutlines",
66  "", "" );
67 
68 TOOL_ACTION GERBVIEW_ACTIONS::flashedDisplayOutlines( "gerbview.Control.flashedDisplayOutlines",
70  "", "" );
71 
72 TOOL_ACTION GERBVIEW_ACTIONS::polygonsDisplayOutlines( "gerbview.Control.polygonsDisplayOutlines",
74  "", "" );
75 
76 TOOL_ACTION GERBVIEW_ACTIONS::negativeObjectDisplay( "gerbview.Control.negativeObjectDisplay",
78  "", "" );
79 
80 TOOL_ACTION GERBVIEW_ACTIONS::dcodeDisplay( "gerbview.Control.dcodeDisplay",
82  "", "" );
83 
84 TOOL_ACTION GERBVIEW_ACTIONS::resetCoords( "gerbview.Control.resetCoords",
86  "", "" );
87 
88 TOOL_ACTION GERBVIEW_ACTIONS::showHelp( "gerbview.Control.showHelp",
90  "", "" );
91 
93  TOOL_INTERACTIVE( "gerbview.Control" ), m_frame( NULL )
94 {
95 }
96 
97 
99 {
100 }
101 
102 
104 {
105  m_frame = getEditFrame<GERBVIEW_FRAME>();
106 }
107 
108 
110 {
111  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
112  const auto& selection = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
113  GERBER_DRAW_ITEM* item = NULL;
114 
115  if( selection.Size() == 1 )
116  {
117  item = static_cast<GERBER_DRAW_ITEM*>( selection[0] );
118  }
119 
121  {
122  m_frame->m_SelComponentBox->SetSelection( 0 );
123  m_frame->m_SelNetnameBox->SetSelection( 0 );
124  m_frame->m_SelAperAttributesBox->SetSelection( 0 );
125 
126  settings->m_netHighlightString = "";
127  settings->m_componentHighlightString = "";
128  settings->m_attributeHighlightString = "";
129  }
130  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
131  {
132  auto string = item->GetNetAttributes().m_Netname;
133  settings->m_netHighlightString = string;
134  m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) );
135  }
136  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
137  {
138  auto string = item->GetNetAttributes().m_Cmpref;
139  settings->m_componentHighlightString = string;
140  m_frame->m_SelComponentBox->SetStringSelection( string );
141  }
142  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
143  {
144  D_CODE* apertDescr = item->GetDcodeDescr();
145  if( apertDescr )
146  {
147  auto string = apertDescr->m_AperFunction;
148  settings->m_attributeHighlightString = string;
149  m_frame->m_SelAperAttributesBox->SetStringSelection( string );
150  }
151  }
152 
155 
156  return 0;
157 }
158 
159 
161 {
162  bool state;
163  bool needs_refresh = false;
165 
167  {
168  options.m_DisplayLinesFill = !options.m_DisplayLinesFill;
169  needs_refresh = true;
170  }
172  {
174  needs_refresh = true;
175  }
177  {
178  options.m_DisplayPolygonsFill = !options.m_DisplayPolygonsFill;
179  needs_refresh = true;
180  }
182  {
185  }
186  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::dcodeDisplay ) )
187  {
190  }
191 
192  if( needs_refresh )
193  m_frame->UpdateDisplayOptions( options );
194 
195  return 0;
196 }
197 
198 
200 {
201  int layer = m_frame->GetActiveLayer();
202 
203  if( layer < GERBER_DRAWLAYERS_COUNT - 1 )
204  m_frame->SetActiveLayer( layer + 1, true );
205 
206  return 0;
207 }
208 
209 
211 {
212  int layer = m_frame->GetActiveLayer();
213 
214  if( layer > 0 )
215  m_frame->SetActiveLayer( layer - 1, true );
216 
217  return 0;
218 }
219 
220 
222 {
223  VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
224 
225  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
227 
228  return 0;
229 }
230 
231 
233 {
235  return 0;
236 }
237 
238 
240 {
242 
243  return 0;
244 }
245 
246 
248 {
253 
256 
262 
265 }
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
static TOOL_ACTION resetCoords
int ResetCoords(const TOOL_EVENT &aEvent)
static TOOL_ACTION layerChanged
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
GERBVIEW_FRAME * m_frame
void UpdateStatusBar() override
Update the status bar information.
static TOOL_ACTION showHelp
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1443
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
int LayerPrev(const TOOL_EVENT &aEvent)
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function SetActiveLayer will change the currently active layer to aLayer and also update the GERBER_L...
static TOOL_ACTION layerNext
Action activates a tool
Definition: tool_event.h:151
wxString m_Cmpref
the component reference parent of the data
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
Visibility flag has changed.
Definition: view_item.h:56
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
int HighlightControl(const TOOL_EVENT &aEvent)
static TOOL_ACTION highlightNet
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION layerPrev
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
wxChoice * m_SelNetnameBox
int ShowHelp(const TOOL_EVENT &aEvent)
Pcbnew hotkeys.
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:54
void setTransitions() override
Sets up handlers for various events.
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
static TOOL_ACTION selectionTool
void ChangeUserUnits(EDA_UNITS_T aUnits)
Definition: draw_frame.h:292
void UpdateDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Updates the display options and refreshes the view as needed.
EDA_HOTKEY_CONFIG * GetHotkeyConfig() const
Return a structure containing currently used hotkey mapping.
Definition: draw_frame.h:442
#define GERBER_DRAWLAYERS_COUNT
static TOOL_ACTION highlightAttribute
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
Definition: common.h:158
static TOOL_ACTION linesDisplayOutlines
GBR_DISPLAY_OPTIONS m_DisplayOptions
Class TOOL_EVENT.
Definition: tool_event.h:167
int SwitchUnits(const TOOL_EVENT &aEvent)
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
wxString m_Netname
for items associated to a net: the netname
const GBR_NETLIST_METADATA & GetNetAttributes() const
All active tools
Definition: tool_event.h:143
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE
Definition: dcode.h:105
static TOOL_ACTION flashedDisplayOutlines
Class GERBVIEW_SELECTION_TOOL.
wxChoice * m_SelAperAttributesBox
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
int LayerNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION highlightClear
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:123
static TOOL_ACTION polygonsDisplayOutlines
Class TOOL_ACTION.
Definition: tool_action.h:46
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
wxChoice * m_SelComponentBox
int DisplayControl(const TOOL_EVENT &aEvent)
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:408
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
static TOOL_ACTION highlightComponent