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 
32  TOOL_INTERACTIVE( "gerbview.Control" ),
33  m_frame( nullptr )
34 {
35 }
36 
37 
39 {
40  m_frame = getEditFrame<GERBVIEW_FRAME>();
41 }
42 
43 
45 {
46  m_frame->LoadGerberFiles( wxEmptyString );
47  // loadListOfGerberAndDrillFiles() refreshes the canvas
48 
49  return 0;
50 }
51 
52 
54 {
55  m_frame->LoadExcellonFiles( wxEmptyString );
57 
58  return 0;
59 }
60 
61 
63 {
64  m_frame->LoadGerberJobFile( wxEmptyString );
66 
67  return 0;
68 }
69 
70 
72 {
73  m_frame->LoadZipArchiveFile( wxEmptyString );
75 
76  return 0;
77 }
78 
79 
81 {
82  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
83  const auto& selection = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
84  GERBER_DRAW_ITEM* item = nullptr;
85 
86  if( selection.Size() == 1 )
87  {
88  item = static_cast<GERBER_DRAW_ITEM*>( selection[0] );
89  }
90 
92  {
93  m_frame->m_SelComponentBox->SetSelection( 0 );
94  m_frame->m_SelNetnameBox->SetSelection( 0 );
95  m_frame->m_SelAperAttributesBox->SetSelection( 0 );
96 
97  settings->m_netHighlightString = "";
98  settings->m_componentHighlightString = "";
99  settings->m_attributeHighlightString = "";
100  }
101  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
102  {
103  auto string = item->GetNetAttributes().m_Netname;
104  settings->m_netHighlightString = string;
105  m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) );
106  }
107  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
108  {
109  auto string = item->GetNetAttributes().m_Cmpref;
110  settings->m_componentHighlightString = string;
111  m_frame->m_SelComponentBox->SetStringSelection( string );
112  }
113  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
114  {
115  D_CODE* apertDescr = item->GetDcodeDescr();
116  if( apertDescr )
117  {
118  auto string = apertDescr->m_AperFunction;
119  settings->m_attributeHighlightString = string;
120  m_frame->m_SelAperAttributesBox->SetStringSelection( string );
121  }
122  }
123 
125  m_frame->GetCanvas()->Refresh();
126 
127  return 0;
128 }
129 
130 
132 {
133  bool state;
134  bool needs_refresh = false;
135  auto options = m_frame->GetDisplayOptions();
136 
138  {
139  options.m_DisplayLinesFill = !options.m_DisplayLinesFill;
140  needs_refresh = true;
141  }
143  {
144  options.m_DisplayFlashedItemsFill = !options.m_DisplayFlashedItemsFill;
145  needs_refresh = true;
146  }
148  {
149  options.m_DisplayPolygonsFill = !options.m_DisplayPolygonsFill;
150  needs_refresh = true;
151  }
153  {
156  }
157  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::dcodeDisplay ) )
158  {
161  }
162  else if( aEvent.IsAction( &ACTIONS::highContrastMode ) )
163  {
164  options.m_HighContrastMode = !options.m_HighContrastMode;
165  needs_refresh = true;
166  }
167  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::toggleDiffMode ) )
168  {
169  options.m_DiffMode = !options.m_DiffMode;
170  needs_refresh = true;
171  }
172 
173  if( needs_refresh )
174  m_frame->UpdateDisplayOptions( options );
175 
176  return 0;
177 }
178 
179 
181 {
182  int layer = m_frame->GetActiveLayer();
183 
184  if( layer < GERBER_DRAWLAYERS_COUNT - 1 )
185  m_frame->SetActiveLayer( layer + 1, true );
186 
187  return 0;
188 }
189 
190 
192 {
193  int layer = m_frame->GetActiveLayer();
194 
195  if( layer > 0 )
196  m_frame->SetActiveLayer( layer - 1, true );
197 
198  return 0;
199 }
200 
201 
203 {
205  GERBVIEW_SELECTION& selection = selTool->GetSelection();
206 
207  if( selection.GetSize() == 1 )
208  {
209  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
210 
211  MSG_PANEL_ITEMS msgItems;
212  item->GetMsgPanelInfo( m_frame, msgItems );
213  m_frame->SetMsgPanel( msgItems );
214  }
215  else
216  {
217  m_frame->EraseMsgBox();
218  }
219 
220  return 0;
221 }
222 
223 
225 {
230  Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
231 
236 
239 
247 
251 }
int OpenJobFile(const TOOL_EVENT &aEvent)
int OpenGerber(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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:203
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:1444
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
Visibility flag has changed.
Definition: view_item.h:56
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.
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:204
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:131
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)
static TOOL_ACTION highContrastMode
Definition: actions.h:99
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
static TOOL_ACTION openZipFile
static TOOL_ACTION highlightComponent