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"
30 #include "selection_tool.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::switchUnits( "gerbview.Control.switchUnits",
86  "", "" );
87 
88 TOOL_ACTION GERBVIEW_ACTIONS::resetCoords( "gerbview.Control.resetCoords",
90  "", "" );
91 
92 TOOL_ACTION GERBVIEW_ACTIONS::showHelp( "gerbview.Control.showHelp",
94  "", "" );
95 
97  TOOL_INTERACTIVE( "gerbview.Control" ), m_frame( NULL )
98 {
99 }
100 
101 
103 {
104 }
105 
106 
108 {
109  m_frame = getEditFrame<GERBVIEW_FRAME>();
110 }
111 
112 
114 {
115  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
116  const auto& selection = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
117  GERBER_DRAW_ITEM* item = NULL;
118 
119  if( selection.Size() == 1 )
120  {
121  item = static_cast<GERBER_DRAW_ITEM*>( selection[0] );
122  }
123 
125  {
126  m_frame->m_SelComponentBox->SetSelection( 0 );
127  m_frame->m_SelNetnameBox->SetSelection( 0 );
128  m_frame->m_SelAperAttributesBox->SetSelection( 0 );
129 
130  settings->m_netHighlightString = "";
131  settings->m_componentHighlightString = "";
132  settings->m_attributeHighlightString = "";
133  }
134  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
135  {
136  auto string = item->GetNetAttributes().m_Netname;
137  settings->m_netHighlightString = string;
138  m_frame->m_SelNetnameBox->SetStringSelection( string );
139  }
140  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
141  {
142  auto string = item->GetNetAttributes().m_Cmpref;
143  settings->m_componentHighlightString = string;
144  m_frame->m_SelComponentBox->SetStringSelection( string );
145  }
146  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
147  {
148  D_CODE* apertDescr = item->GetDcodeDescr();
149  if( apertDescr )
150  {
151  auto string = apertDescr->m_AperFunction;
152  settings->m_attributeHighlightString = string;
153  m_frame->m_SelAperAttributesBox->SetStringSelection( string );
154  }
155  }
156 
159 
160  return 0;
161 }
162 
163 
165 {
166  bool state;
167  bool needs_refresh = false;
169 
171  {
172  options.m_DisplayLinesFill = !options.m_DisplayLinesFill;
173  needs_refresh = true;
174  }
176  {
178  needs_refresh = true;
179  }
181  {
182  options.m_DisplayPolygonsFill = !options.m_DisplayPolygonsFill;
183  needs_refresh = true;
184  }
186  {
189  }
190  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::dcodeDisplay ) )
191  {
194  }
195 
196  if( needs_refresh )
197  m_frame->UpdateDisplayOptions( options );
198 
199  return 0;
200 }
201 
202 
204 {
205  int layer = m_frame->GetActiveLayer();
206 
207  if( layer < GERBER_DRAWLAYERS_COUNT - 1 )
208  m_frame->SetActiveLayer( layer + 1, true );
209 
210  return 0;
211 }
212 
213 
215 {
216  int layer = m_frame->GetActiveLayer();
217 
218  if( layer > 0 )
219  m_frame->SetActiveLayer( layer - 1, true );
220 
221  return 0;
222 }
223 
224 
226 {
227  VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
228 
229  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
231 
232  return 0;
233 }
234 
235 
237 {
238  // TODO: Refactor to share with pcbnew
239  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
240 
241  if( m_frame->GetUserUnits() == INCHES )
242  evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM );
243  else
244  evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );
245 
246  m_frame->ProcessEvent( evt );
247 
248  return 0;
249 }
250 
251 
253 {
255 
256  return 0;
257 }
258 
259 
261 {
266 
269 
275 
279 }
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
static TOOL_ACTION resetCoords
int ResetCoords(const TOOL_EVENT &aEvent)
static TOOL_ACTION layerChanged
GERBVIEW_FRAME * m_frame
void UpdateStatusBar() override
Update the status bar information.
static TOOL_ACTION showHelp
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1434
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:152
EDA_HOTKEY_CONFIG * GetHotkeyConfig() const
Return a structure containing currently used hotkey mapping.
Definition: draw_frame.h:431
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:174
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
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
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)
void setTransitions() override
Sets up handlers for various events.
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
static TOOL_ACTION selectionTool
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:397
void UpdateDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Updates the display options and refreshes the view as needed.
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
#define GERBER_DRAWLAYERS_COUNT
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
static TOOL_ACTION highlightAttribute
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
Definition: common.h:160
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
static TOOL_ACTION linesDisplayOutlines
GBR_DISPLAY_OPTIONS m_DisplayOptions
Class TOOL_EVENT.
Definition: tool_event.h:168
int SwitchUnits(const TOOL_EVENT &aEvent)
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
wxString m_Netname
for items associated to a net: the netname
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
All active tools
Definition: tool_event.h:144
TOOL_SETTINGS & GetSettings()
Definition: tool_base.cpp:77
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...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
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
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
const GBR_NETLIST_METADATA & GetNetAttributes() const
Class GERBVIEW_SELECTION_TOOL.
static TOOL_ACTION switchUnits
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
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
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
int DisplayControl(const TOOL_EVENT &aEvent)
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
static TOOL_ACTION highlightComponent