forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerbview_draw_panel_gal.cpp
216 lines (159 loc) · 6.71 KB
/
gerbview_draw_panel_gal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gerbview_draw_panel_gal.h"
#include <view/view.h>
#include <view/wx_view_controls.h>
#include <gerbview_painter.h>
#include <drawing_sheet/ds_proxy_view_item.h>
#include <zoom_defines.h>
#include <gerbview_frame.h>
#include <gal/graphics_abstraction_layer.h>
#include <settings/settings_manager.h>
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
#include <functional>
#include <memory>
using namespace std::placeholders;
GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize,
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
{
m_view = new KIGFX::VIEW( true );
m_view->SetGAL( m_gal );
GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
m_painter = std::make_unique<KIGFX::GERBVIEW_PAINTER>( m_gal );
m_view->SetPainter( m_painter.get() );
// This fixes the zoom in and zoom out limits:
m_view->SetScaleLimits( ZOOM_MAX_LIMIT_GERBVIEW, ZOOM_MIN_LIMIT_GERBVIEW );
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
setDefaultLayerDeps();
// Load display options (such as filled/outline display of items).
auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
if( frame )
{
auto& displ_opts = frame->GetDisplayOptions();
auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
m_view->GetPainter()->GetSettings() );
rs->LoadDisplayOptions( displ_opts );
rs->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
}
}
GERBVIEW_DRAW_PANEL_GAL::~GERBVIEW_DRAW_PANEL_GAL()
{
}
void GERBVIEW_DRAW_PANEL_GAL::SetHighContrastLayer( int aLayer )
{
// Set display settings for high contrast mode
KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
SetTopLayer( aLayer );
rSettings->ClearHighContrastLayers();
rSettings->SetLayerIsHighContrast( aLayer );
rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
m_view->UpdateAllLayersColor();
}
void GERBVIEW_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
std::vector<MSG_PANEL_ITEM>& aList )
{
}
void GERBVIEW_DRAW_PANEL_GAL::OnShow()
{
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
if( frame )
{
SetTopLayer( frame->GetActiveLayer() );
auto& displ_opts = frame->GetDisplayOptions();
static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
}
m_view->RecacheAllItems();
}
bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
{
bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
// The next onPaint event will call m_view->UpdateItems() that is very time consumming
// after switching to opengl. Clearing m_view and rebuild it is much faster
if( aGalType == GAL_TYPE_OPENGL )
{
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
if( frame )
{
m_view->Clear();
for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
{
GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
{
m_view->Add (item );
}
}
}
}
setDefaultLayerDeps();
GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
return rv;
}
void GERBVIEW_DRAW_PANEL_GAL::setDefaultLayerDeps()
{
// caching makes no sense for Cairo and other software renderers
auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
m_view->SetLayerTarget( i, target );
// for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
// m_view->SetLayerDisplayOnly( i );
m_view->SetLayerDisplayOnly( LAYER_DCODES );
m_view->SetLayerDisplayOnly( LAYER_NEGATIVE_OBJECTS );
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_GRID );
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_AXES );
m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_BACKGROUND );
m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
}
void GERBVIEW_DRAW_PANEL_GAL::SetDrawingSheet( DS_PROXY_VIEW_ITEM* aDrawingSheet )
{
m_drawingSheet.reset( aDrawingSheet );
m_view->Add( m_drawingSheet.get() );
}
void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
{
m_view->ClearTopLayers();
for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
{
m_view->SetLayerOrder( GERBER_DCODE_LAYER( GERBER_DRAW_LAYER( i ) ), 2 * i );
m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
}
m_view->SetTopLayer( aLayer );
// Move DCODE layer to the top
m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
m_view->SetTopLayer( LAYER_GP_OVERLAY );
m_view->UpdateAllLayersOrder();
}
BOX2I GERBVIEW_DRAW_PANEL_GAL::GetDefaultViewBBox() const
{
// Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
if( m_drawingSheet && m_view->IsLayerVisible( LAYER_DRAWINGSHEET ) )
return m_drawingSheet->ViewBBox();
return BOX2I();
}