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  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
47  const auto& selection = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
48  GERBER_DRAW_ITEM* item = nullptr;
49 
50  if( selection.Size() == 1 )
51  {
52  item = static_cast<GERBER_DRAW_ITEM*>( selection[0] );
53  }
54 
56  {
57  m_frame->m_SelComponentBox->SetSelection( 0 );
58  m_frame->m_SelNetnameBox->SetSelection( 0 );
59  m_frame->m_SelAperAttributesBox->SetSelection( 0 );
60 
61  settings->m_netHighlightString = "";
62  settings->m_componentHighlightString = "";
63  settings->m_attributeHighlightString = "";
64  }
65  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightNet ) )
66  {
67  auto string = item->GetNetAttributes().m_Netname;
68  settings->m_netHighlightString = string;
69  m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) );
70  }
71  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) )
72  {
73  auto string = item->GetNetAttributes().m_Cmpref;
74  settings->m_componentHighlightString = string;
75  m_frame->m_SelComponentBox->SetStringSelection( string );
76  }
77  else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightAttribute ) )
78  {
79  D_CODE* apertDescr = item->GetDcodeDescr();
80  if( apertDescr )
81  {
82  auto string = apertDescr->m_AperFunction;
83  settings->m_attributeHighlightString = string;
84  m_frame->m_SelAperAttributesBox->SetStringSelection( string );
85  }
86  }
87 
90 
91  return 0;
92 }
93 
94 
96 {
97  bool state;
98  bool needs_refresh = false;
99  auto options = m_frame->GetDisplayOptions();
100 
102  {
103  options.m_DisplayLinesFill = !options.m_DisplayLinesFill;
104  needs_refresh = true;
105  }
107  {
108  options.m_DisplayFlashedItemsFill = !options.m_DisplayFlashedItemsFill;
109  needs_refresh = true;
110  }
112  {
113  options.m_DisplayPolygonsFill = !options.m_DisplayPolygonsFill;
114  needs_refresh = true;
115  }
117  {
120  }
121  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::dcodeDisplay ) )
122  {
125  }
126  else if( aEvent.IsAction( &ACTIONS::highContrastMode ) )
127  {
128  options.m_HighContrastMode = !options.m_HighContrastMode;
129  needs_refresh = true;
130  }
131  else if( aEvent.IsAction( &GERBVIEW_ACTIONS::toggleDiffMode ) )
132  {
133  options.m_DiffMode = !options.m_DiffMode;
134  needs_refresh = true;
135  }
136 
137  if( needs_refresh )
138  m_frame->UpdateDisplayOptions( options );
139 
140  return 0;
141 }
142 
143 
145 {
146  int layer = m_frame->GetActiveLayer();
147 
148  if( layer < GERBER_DRAWLAYERS_COUNT - 1 )
149  m_frame->SetActiveLayer( layer + 1, true );
150 
151  return 0;
152 }
153 
154 
156 {
157  int layer = m_frame->GetActiveLayer();
158 
159  if( layer > 0 )
160  m_frame->SetActiveLayer( layer - 1, true );
161 
162  return 0;
163 }
164 
165 
167 {
169  GERBVIEW_SELECTION& selection = selTool->GetSelection();
170 
171  if( selection.GetSize() == 1 )
172  {
173  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
174 
175  MSG_PANEL_ITEMS msgItems;
176  item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems );
177  m_frame->SetMsgPanel( msgItems );
178  }
179  else
180  {
181  m_frame->EraseMsgBox();
182  }
183 
184  return 0;
185 }
186 
187 
189 {
190  Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
191 
196 
199 
207 
211 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:197
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
GERBVIEW_FRAME * m_frame
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:198
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 also update the GERBER_L...
static TOOL_ACTION layerNext
wxString m_Cmpref
the component reference parent of the data
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use.
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
static TOOL_ACTION print
Definition: actions.h:60
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
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
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.
static TOOL_ACTION highlightAttribute
static TOOL_ACTION linesDisplayOutlines
Class TOOL_EVENT.
Definition: tool_event.h:171
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:199
const GBR_NETLIST_METADATA & GetNetAttributes() const
GERBVIEW_SELECTION & GetSelection()
Function GetSelection()
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:328
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
Class GERBVIEW_SELECTION_TOOL.
wxChoice * m_SelAperAttributesBox
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
int LayerNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION highlightClear
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
static TOOL_ACTION polygonsDisplayOutlines
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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
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 highlightComponent