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-2019 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 "gerbview_actions.h"
27 #include "gerbview_control.h"
29 
30 
31 GERBVIEW_CONTROL::GERBVIEW_CONTROL() : TOOL_INTERACTIVE( "gerbview.Control" ), m_frame( nullptr )
32 {
33 }
34 
35 
37 {
38  m_frame = getEditFrame<GERBVIEW_FRAME>();
39 }
40 
41 
43 {
44  m_frame->LoadGerberFiles( wxEmptyString );
45  // loadListOfGerberAndDrillFiles() refreshes the canvas
46 
47  return 0;
48 }
49 
50 
52 {
53  m_frame->LoadExcellonFiles( wxEmptyString );
55 
56  return 0;
57 }
58 
59 
61 {
62  m_frame->LoadGerberJobFile( wxEmptyString );
64 
65  return 0;
66 }
67 
68 
70 {
71  m_frame->LoadZipArchiveFile( wxEmptyString );
73 
74  return 0;
75 }
76 
77 
79 {
80  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
81  const auto& selection = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
82  GERBER_DRAW_ITEM* item = nullptr;
83 
84  if( selection.Size() == 1 )
85  {
86  item = static_cast<GERBER_DRAW_ITEM*>( selection[0] );
87  }
88 
90  {
91  m_frame->m_SelComponentBox->SetSelection( 0 );
92  m_frame->m_SelNetnameBox->SetSelection( 0 );
93  m_frame->m_SelAperAttributesBox->SetSelection( 0 );
94 
95  settings->m_netHighlightString = "";
96  settings->m_componentHighlightString = "";
97  settings->m_attributeHighlightString = "";
98  }
99  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
100  {
101  auto string = item->GetNetAttributes().m_Netname;
102  settings->m_netHighlightString = string;
103  m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) );
104  }
105  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
106  {
107  auto string = item->GetNetAttributes().m_Cmpref;
108  settings->m_componentHighlightString = string;
109  m_frame->m_SelComponentBox->SetStringSelection( string );
110  }
111  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
112  {
113  D_CODE* apertDescr = item->GetDcodeDescr();
114  if( apertDescr )
115  {
116  auto string = apertDescr->m_AperFunction;
117  settings->m_attributeHighlightString = string;
118  m_frame->m_SelAperAttributesBox->SetStringSelection( string );
119  }
120  }
121 
123  m_frame->GetCanvas()->Refresh();
124 
125  return 0;
126 }
127 
128 
130 {
131  bool state;
132  bool needs_refresh = false;
133  auto options = m_frame->GetDisplayOptions();
134 
136  {
137  options.m_DisplayLinesFill = !options.m_DisplayLinesFill;
138  needs_refresh = true;
139  }
141  {
142  options.m_DisplayFlashedItemsFill = !options.m_DisplayFlashedItemsFill;
143  needs_refresh = true;
144  }
146  {
147  options.m_DisplayPolygonsFill = !options.m_DisplayPolygonsFill;
148  needs_refresh = true;
149  }
151  {
154  }
155  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::dcodeDisplay ) )
156  {
159  }
160  else if( aEvent.IsAction( &ACTIONS::highContrastMode ) )
161  {
162  options.m_HighContrastMode = !options.m_HighContrastMode;
163  needs_refresh = true;
164  }
165  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::toggleDiffMode ) )
166  {
167  options.m_DiffMode = !options.m_DiffMode;
168  needs_refresh = true;
169  }
170  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::flipGerberView ) )
171  {
172  options.m_FlipGerberView = !options.m_FlipGerberView;
173 
174  KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
175  view->SetMirror( options.m_FlipGerberView, false );
176  needs_refresh = true;
177  }
178 
179  if( needs_refresh )
180  m_frame->UpdateDisplayOptions( options );
181 
182  return 0;
183 }
184 
185 
187 {
188  int layer = m_frame->GetActiveLayer();
189 
190  if( layer < GERBER_DRAWLAYERS_COUNT - 1 )
191  m_frame->SetActiveLayer( layer + 1, true );
192 
193  return 0;
194 }
195 
196 
198 {
199  int layer = m_frame->GetActiveLayer();
200 
201  if( layer > 0 )
202  m_frame->SetActiveLayer( layer - 1, true );
203 
204  return 0;
205 }
206 
207 
209 {
211  GERBVIEW_SELECTION& selection = selTool->GetSelection();
212 
213  if( selection.GetSize() == 1 )
214  {
215  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
216 
217  MSG_PANEL_ITEMS msgItems;
218  item->GetMsgPanelInfo( m_frame, msgItems );
219  m_frame->SetMsgPanel( msgItems );
220  }
221  else
222  {
223  m_frame->EraseMsgBox();
224  }
225 
226  return 0;
227 }
228 
229 
231 {
236  Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
237 
242 
245 
254 
258 }
int OpenJobFile(const TOOL_EVENT &aEvent)
int OpenGerber(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
static TOOL_ACTION openDrillFile
GERBVIEW_FRAME * m_frame
static TOOL_ACTION openGerber
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
int OpenZipFile(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1435
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 update the GERBER_LAYER_...
static TOOL_ACTION layerNext
wxString m_Cmpref
the component reference parent of the data
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
static TOOL_ACTION print
Definition: actions.h:60
void SetMirror(bool aMirrorX, bool aMirrorY)
Function SetMirror() Controls the mirroring of the VIEW.
Definition: view.cpp:564
Visibility flag has changed.
Definition: view_item.h:58
int HighlightControl(const TOOL_EVENT &aEvent)
static TOOL_ACTION highlightNet
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
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:67
static TOOL_ACTION toggleDiffMode
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
void setTransitions() override
Sets up handlers for various events.
static TOOL_ACTION flipGerberView
void UpdateDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Updates the display options and refreshes the view as needed.
#define GERBER_DRAWLAYERS_COUNT
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool LoadGerberFiles(const wxString &aFileName)
function LoadGerberFiles Load a photoplot (Gerber) file or many files.
static TOOL_ACTION highlightAttribute
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, 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:295
bool LoadZipArchiveFile(const wxString &aFileName)
function LoadZipArchiveFileLoadZipArchiveFile Load a zipped archive file.
static TOOL_ACTION linesDisplayOutlines
TOOL_EVENT.
Definition: tool_event.h:171
static TOOL_ACTION openJobFile
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
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
static const TOOL_EVENT ClearedEvent
Definition: actions.h:208
const GBR_NETLIST_METADATA & GetNetAttributes() const
GERBVIEW_SELECTION & GetSelection()
Function GetSelection()
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
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
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
GERBVIEW_SELECTION_TOOL.
wxChoice * m_SelAperAttributesBox
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
int LayerNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION highlightClear
int OpenDrillFile(const TOOL_EVENT &aEvent)
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
static TOOL_ACTION polygonsDisplayOutlines
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
wxChoice * m_SelComponentBox
bool LoadExcellonFiles(const wxString &aFileName)
function LoadExcellonFiles Load a drill (EXCELLON) file or many files.
int DisplayControl(const TOOL_EVENT &aEvent)
VIEW.
Definition: view.h:61
static TOOL_ACTION highContrastMode
Definition: actions.h:101
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
static TOOL_ACTION openZipFile
static TOOL_ACTION highlightComponent