KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gerbview_layer_widget.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) 2004-2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/checkbox.h>
27#include <wx/filedlg.h>
29#include <bitmaps.h>
30#include <gerbview.h>
32#include <gerbview_frame.h>
34#include <core/arraydim.h>
35#include <lset.h>
36#include <view/view.h>
37#include <gerbview_painter.h>
40#include <tool/tool_manager.h>
42
43#include "layer_widget.h"
46#include "dcode_selection_box.h"
47
48
49GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFocusOwner ) :
50 LAYER_WIDGET( aParent, aFocusOwner ),
51 m_frame( aParent )
52{
54
56
57 // Update default tabs labels for GerbView
59
60 // handle the popup menu over the layer window.
61 m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN,
62 wxMouseEventHandler( GERBER_LAYER_WIDGET::onRightDownLayers ),
63 nullptr, this );
64
65 // since Popupmenu() calls this->ProcessEvent() we must call this->Connect()
66 // and not m_LayerScrolledWindow->Connect()
67 Connect( ID_LAYER_MANAGER_START, ID_LAYER_MANAGER_END, wxEVT_COMMAND_MENU_SELECTED,
68 wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), nullptr, this );
69}
70
71
76
77
79{
80 m_notebook->SetPageText( 0, _( "Layers" ) );
81 m_notebook->SetPageText( 1, _( "Items" ) );
82}
83
84
86{
87 std::vector<int>render_layers{ LAYER_DCODES, LAYER_NEGATIVE_OBJECTS, LAYER_GERBVIEW_GRID,
90
91 for( int layer: render_layers )
92 {
93 int row = findRenderRow( layer );
94
95 if( row < 0 )
96 continue;
97
98 COLOR4D color = GetRenderColor( row );
99
100 if( color != COLOR4D::UNSPECIFIED )
101 aColorSettings->SetColor( layer, color );
102 }
103
104 for( int layer = GERBVIEW_LAYER_ID_START; layer < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; layer++ )
105 {
106 int row = findLayerRow( layer - GERBVIEW_LAYER_ID_START );
107
108 if( row < 0 ) // Not existing in layer list
109 continue;
110
111 COLOR4D color = GetLayerColor( row );
112
113 if( color != COLOR4D::UNSPECIFIED )
114 aColorSettings->SetColor( layer, color );
115 }
116}
117
118
120{
122
123 // Fixed "Rendering" tab rows within the LAYER_WIDGET, only the initial color
124 // is changed before appending to the LAYER_WIDGET. This is an automatic variable
125 // not a static variable, change the color & state after copying from code to renderRows
126 // on the stack.
127 LAYER_WIDGET::ROW renderRows[7] = {
128
129#define RR LAYER_WIDGET::ROW // Render Row abbreviation to reduce source width
130
131 RR( _( "DCodes" ), LAYER_DCODES, WHITE,
132 _( "Show DCodes identification" ) ),
133 RR( _( "Negative Objects" ), LAYER_NEGATIVE_OBJECTS, DARKGRAY,
134 _( "Show negative objects in this color" ) ),
135 RR(),
136 RR( _( "Grid" ), LAYER_GERBVIEW_GRID, WHITE,
137 _( "Show the (x,y) grid dots" ) ),
138 RR( _( "Drawing Sheet" ), LAYER_GERBVIEW_DRAWINGSHEET, DARKRED,
139 _( "Show drawing sheet border and title block") ),
140 RR( _( "Page Limits" ), LAYER_GERBVIEW_PAGE_LIMITS, WHITE,
141 _( "Show drawing sheet page limits" ) ),
142 RR( _( "Background" ), LAYER_GERBVIEW_BACKGROUND, BLACK,
143 _( "PCB Background" ), true, false )
144 };
145
146 for( unsigned row = 0; row < arrayDim( renderRows ); ++row )
147 {
148 if( renderRows[row].color != COLOR4D::UNSPECIFIED ) // does this row show a color?
149 renderRows[row].color = m_frame->GetVisibleElementColor( renderRows[row].id );
150
151 if( renderRows[row].id ) // if not the separator
152 renderRows[row].state = m_frame->IsElementVisible( renderRows[row].id );
153 }
154
155 AppendRenderRows( renderRows, arrayDim(renderRows) );
156}
157
158
160{
161 // Remember: menu text is capitalized (see our rules_for_capitalization_in_Kicad_UI.txt)
162 KIUI::AddMenuItem( aMenu, ID_SHOW_ALL_LAYERS, _( "Show All Layers" ),
164
165 KIUI::AddMenuItem( aMenu, ID_SHOW_NO_LAYERS_BUT_ACTIVE, _( "Hide All Layers But Active" ),
167
169 _( "Always Hide All Layers But Active" ),
171
172 KIUI::AddMenuItem( aMenu, ID_SHOW_NO_LAYERS, _( "Hide All Layers" ),
174
175 aMenu->AppendSeparator();
176
177 KIUI::AddMenuItem( aMenu, ID_SORT_GBR_LAYERS_X2, _( "Sort Layers if X2 Mode" ),
179
180 KIUI::AddMenuItem( aMenu, ID_SORT_GBR_LAYERS_FILE_EXT, _( "Sort Layers by File Extension" ),
182
183 aMenu->AppendSeparator();
184
186 _( "Layers Display Parameters: Offset and Rotation" ),
188
189 aMenu->AppendSeparator();
190
191 KIUI::AddMenuItem( aMenu, ID_LAYER_MOVE_UP, _( "Move Current Layer Up" ),
193
194 KIUI::AddMenuItem( aMenu, ID_LAYER_MOVE_DOWN, _( "Move Current Layer Down" ),
196
197 KIUI::AddMenuItem( aMenu, ID_LAYER_DELETE, _( "Clear Current Layer..." ),
199}
200
201
202void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
203{
204 wxMenu menu;
205
206 AddRightClickMenuItems( &menu );
207 PopupMenu( &menu );
208
209 passOnFocus();
210}
211
212
213void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
214{
215 int layer;
216 int rowCount;
217 int menuId = event.GetId();
218 bool visible = (menuId == ID_SHOW_ALL_LAYERS) ? true : false;
219 LSET visibleLayers;
220 bool force_active_layer_visible;
221
222 switch( menuId )
223 {
228 // Set the display layers options. Sorting layers has no effect to these options
230 force_active_layer_visible = ( menuId == ID_SHOW_NO_LAYERS_BUT_ACTIVE ||
232
233 // Update icons and check boxes
234 rowCount = GetLayerRowCount();
235
236 for( int row = 0; row < rowCount; ++row )
237 {
238 wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
239 layer = getDecodedId( cb->GetId() );
240 bool loc_visible = visible;
241
242 if( force_active_layer_visible && (layer == m_frame->GetActiveLayer() ) )
243 loc_visible = true;
244
245 cb->SetValue( loc_visible );
246 visibleLayers[ layer ] = loc_visible;
247 }
248
249 m_frame->SetVisibleLayers( visibleLayers );
250 m_frame->GetCanvas()->Refresh();
251 break;
252
254 m_frame->SortLayersByX2Attributes();
255 break;
256
258 m_frame->SortLayersByFileExtension();
259 break;
260
262 m_frame->SetLayerDrawPrms();
263 break;
264
265 case ID_LAYER_MOVE_UP:
266 m_frame->GetToolManager()->RunAction( GERBVIEW_ACTIONS::moveLayerUp );
267 break;
268
270 m_frame->GetToolManager()->RunAction( GERBVIEW_ACTIONS::moveLayerDown );
271 break;
272
273 case ID_LAYER_DELETE:
274 m_frame->Erase_Current_DrawLayer( false );
275
276 break;
277 }
278}
279
281{
283 return false;
284
285 // postprocess after active layer selection ensure active layer visible
286 wxCommandEvent event;
288 onPopupSelection( event );
289 return true;
290}
291
292
294{
296
297 Freeze();
298
299 for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
300 {
301 // Don't show inactive layers
302 if ( GetImagesList()->GetGbrImage(layer) == nullptr )
303 continue;
304
305 int aRow = findLayerRow( layer );
306 bool visible = true;
307 COLOR4D color = m_frame->GetLayerColor( GERBER_DRAW_LAYER( layer ) );
308 wxString msg = GetImagesList()->GetDisplayName( layer,
309 /* include layer number */ false,
310 /* Get the full name */ true );
311
312 if( m_frame->GetCanvas() )
313 visible = m_frame->GetCanvas()->GetView()->IsLayerVisible( GERBER_DRAW_LAYER( layer ) );
314 else
315 visible = m_frame->IsLayerVisible( layer );
316
317 if( aRow >= 0 )
318 {
319 updateLayerRow( findLayerRow( layer ), msg );
320 SetLayerVisible( layer, visible );
321 }
322 else
323 {
324 AppendLayerRow( LAYER_WIDGET::ROW( msg, layer, color, wxEmptyString, visible, true ) );
325 }
326 }
327
329 Thaw();
330}
331
332
334{
335 AddRightClickMenuItems( &aMenu );
336}
337
338
339void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, const COLOR4D& aColor )
340{
341 // NOTE: Active layer in GerbView is stored as 0-indexed, but layer color is
342 // stored according to the GERBER_DRAW_LAYER() offset.
343 m_frame->SetLayerColor( GERBER_DRAW_LAYER( aLayer ), aColor );
344
345 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
346 COLOR_SETTINGS* color_settings = m_frame->GetColorSettings();
347 color_settings->SetColor( aLayer, aColor );
348
349 view->GetPainter()->GetSettings()->LoadColors( color_settings );
350 view->UpdateLayerColor( GERBER_DRAW_LAYER( aLayer ) );
351
352 m_frame->GetCanvas()->Refresh();
353}
354
355
357{
358 // the layer change from the GERBER_LAYER_WIDGET can be denied by returning
359 // false from this function.
360 int layer = m_frame->GetActiveLayer();
361
362 m_frame->SetActiveLayer( aLayer, false );
363 m_frame->syncLayerBox();
364
365 if( layer != m_frame->GetActiveLayer() )
366 {
367 if( ! OnLayerSelected() )
368 {
369 auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>
370 ( m_frame->GetCanvas()->GetView()->GetPainter() )->GetSettings();
371 int dcodeSelected = m_frame->m_DCodeSelector->GetSelectedDCodeId();
372 settings->m_dcodeHighlightValue = dcodeSelected;
373 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
374 m_frame->GetCanvas()->Refresh();
375 }
376 }
377
378 return true;
379}
380
381
382void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFinal )
383{
384 LSET visibleLayers = m_frame->GetVisibleLayers();
385
386 visibleLayers[ aLayer ] = isVisible;
387
388 m_frame->SetVisibleLayers( visibleLayers );
389
390 if( isFinal )
391 m_frame->GetCanvas()->Refresh();
392}
393
394
396{
397 m_frame->SetVisibleElementColor( aId, aColor );
398
399 auto view = m_frame->GetCanvas()->GetView();
400
401 COLOR_SETTINGS* color_settings = m_frame->GetColorSettings();
402 color_settings->SetColor( aId, aColor );
403
404 view->GetPainter()->GetSettings()->LoadColors( color_settings );
405 view->UpdateLayerColor( aId );
406 view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
407 view->UpdateAllItems( KIGFX::COLOR );
408 m_frame->GetCanvas()->Refresh();
409}
410
411
412void GERBER_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
413{
414 m_frame->SetElementVisibility( aId, isEnabled );
415
416 if( m_frame->GetCanvas() )
417 {
418 if( aId == LAYER_GERBVIEW_GRID )
419 {
420 m_frame->GetCanvas()->GetGAL()->SetGridVisibility( m_frame->IsGridVisible() );
421 m_frame->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
422 }
423 else
424 {
425 m_frame->GetCanvas()->GetView()->SetLayerVisible( aId, isEnabled );
426 }
427 }
428
429 m_frame->GetCanvas()->Refresh();
430}
#define RR
Render Row abbreviation to reduce source width.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition arraydim.h:31
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:104
@ show_all_layers
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetColor(int aLayer, const COLOR4D &aColor)
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
static GERBER_FILE_IMAGE_LIST & GetImagesList()
const wxString GetDisplayName(int aIdx, bool aNameOnly=false, bool aFullName=false)
Get the display name for the layer at aIdx.
GERBER_FILE_IMAGE_LIST * GetImagesList()
void OnRenderEnable(int aId, bool isEnabled) override
Notify client code whenever the user changes an rendering enable in one of the rendering checkboxes.
void onPopupSelection(wxCommandEvent &event)
bool OnLayerSelect(int aLayer) override
Notify client code whenever the user selects a different layer.
void OnLayerRightClick(wxMenu &aMenu) override
Notify client code about a layer being right-clicked.
void onRightDownLayers(wxMouseEvent &event)
Put up a popup menu for the layer panel.
void OnLayerVisible(int aLayer, bool isVisible, bool isFinal) override
Notify client code about a layer visibility change.
void CollectCurrentColorSettings(COLOR_SETTINGS *aColorSettings)
Collect the current color settings and put it in aColorSettings.
void SetLayersManagerTabsText()
Update the layer manager tabs labels.
void AddRightClickMenuItems(wxMenu *aMenu)
Add menu items to a menu that should be shown when right-clicking the Gerber layer widget.
bool OnLayerSelected()
Ensure the active layer is visible, and other layers not visible when m_alwaysShowActiveLayer is true...
GERBER_LAYER_WIDGET(GERBVIEW_FRAME *aParent, wxWindow *aFocusOwner)
void OnLayerColorChange(int aLayer, const COLOR4D &aColor) override
Notify client code about a layer color change.
void OnRenderColorChange(int aId, const COLOR4D &aColor) override
Notify client code whenever the user changes a rendering color.
void ReFillRender()
Rebuild Render for instance after the config is read.
void ReFill()
Rebuild Render for instance after the config is read.
static TOOL_ACTION moveLayerUp
static TOOL_ACTION moveLayerDown
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
Methods for drawing GerbView specific items.
virtual GERBVIEW_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:67
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
Definition view.cpp:759
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:221
static int getDecodedId(int aControlId)
Decode aControlId to original un-encoded value.
void AppendRenderRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the render portion of the widget.
LAYER_WIDGET(wxWindow *aParent, wxWindow *aFocusOwner, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
int GetLayerRowCount() const
Return the number of rows in the layer tab.
void passOnFocus()
Give away the keyboard focus up to the main parent window.
COLOR4D GetRenderColor(int aRow) const
Return the color of the Render ROW in position aRow.
void updateLayerRow(int aRow, const wxString &aName)
int findLayerRow(int aLayer) const
Return the row index that aLayer resides in, or -1 if not found.
int findRenderRow(int aId) const
void SetLayerVisible(int aLayer, bool isVisible)
Set aLayer visible or not.
void ClearLayerRows()
Empty out the layer rows.
wxWindow * getLayerComp(int aRow, int aColumn) const
Return the component within the m_LayersFlexGridSizer at aRow and aCol or NULL if these parameters ar...
void AppendLayerRow(const ROW &aRow)
Append a new row in the layer portion of the widget.
void ClearRenderRows()
Empty out the render rows.
COLOR4D GetLayerColor(int aLayer) const
Return the color of the layer ROW associated with aLayer id.
wxNotebook * m_notebook
wxScrolledWindow * m_LayerScrolledWindow
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
@ WHITE
Definition color4d.h:48
@ DARKGRAY
Definition color4d.h:46
@ DARKRED
Definition color4d.h:53
@ BLACK
Definition color4d.h:44
#define _(s)
@ LAYER_GERBVIEW_DRAWINGSHEET
Definition layer_ids.h:534
@ GERBVIEW_LAYER_ID_START
Definition layer_ids.h:524
@ LAYER_GERBVIEW_BACKGROUND
Definition layer_ids.h:533
@ LAYER_DCODES
Definition layer_ids.h:529
@ LAYER_NEGATIVE_OBJECTS
Definition layer_ids.h:530
@ LAYER_GERBVIEW_PAGE_LIMITS
Definition layer_ids.h:535
@ LAYER_GERBVIEW_GRID
Definition layer_ids.h:531
#define GERBER_DRAWLAYERS_COUNT
Number of draw layers in Gerbview.
Definition layer_ids.h:519
#define GERBER_DRAW_LAYER(x)
Definition layer_ids.h:540
#define COLUMN_COLOR_LYR_CB
@ COLOR
Color has changed.
Definition view_item.h:54
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:38
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
Provide all the data needed to add a row to a LAYER_WIDGET.
COLOR4D color
COLOR4D::UNSPECIFIED if none.
bool state
initial wxCheckBox state