KiCad PCB EDA Suite
gerbview_draw_panel_gal.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) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21 #include <view/view.h>
22 #include <view/wx_view_controls.h>
23 #include <gerbview_painter.h>
25 #include <zoom_defines.h>
26 
27 #include <gerbview_frame.h>
30 
31 #include <gerber_file_image.h>
32 #include <gerber_file_image_list.h>
33 
34 #include <functional>
35 #include <memory>
36 
37 using namespace std::placeholders;
38 
39 
40 GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
41  const wxPoint& aPosition, const wxSize& aSize,
42  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
43 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
44 {
45  m_view = new KIGFX::VIEW( true );
46  m_view->SetGAL( m_gal );
47  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
48 
49  m_painter = std::make_unique<KIGFX::GERBVIEW_PAINTER>( m_gal );
50  m_view->SetPainter( m_painter.get() );
51  // This fixes the zoom in and zoom out limits:
53 
55 
57 
58  // Load display options (such as filled/outline display of items).
59  auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
60 
61  if( frame )
62  {
63  auto& displ_opts = frame->GetDisplayOptions();
64  auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
66 
67  rs->LoadDisplayOptions( displ_opts );
68  rs->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
69  }
70 }
71 
72 
74 {
75 }
76 
77 
79 {
80  // Set display settings for high contrast mode
82 
83  SetTopLayer( aLayer );
84 
85  rSettings->ClearHighContrastLayers();
86  rSettings->SetLayerIsHighContrast( aLayer );
87  rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
88 
90 }
91 
92 
94  std::vector<MSG_PANEL_ITEM>& aList )
95 {
96 
97 }
98 
99 
101 {
102  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
103 
104  if( frame )
105  {
106  SetTopLayer( frame->GetActiveLayer() );
107  auto& displ_opts = frame->GetDisplayOptions();
108  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
109  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
110  }
111 
113 }
114 
115 
117 {
118  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
119 
120  // The next onPaint event will call m_view->UpdateItems() that is very time consumming
121  // after switching to opengl. Clearing m_view and rebuild it is much faster
122  if( aGalType == GAL_TYPE_OPENGL )
123  {
124  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
125 
126  if( frame )
127  {
128  m_view->Clear();
129 
130  for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
131  {
132  GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
133 
134  if( gerber == NULL ) // Graphic layer not yet used
135  continue;
136 
137  for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
138  {
139  m_view->Add (item );
140  }
141  }
142  }
143  }
144 
146 
147  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
148 
149  return rv;
150 }
151 
152 
154 {
155  // caching makes no sense for Cairo and other software renderers
157 
158  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
159  m_view->SetLayerTarget( i, target );
160 
161  // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
162  // m_view->SetLayerDisplayOnly( i );
163 
170 
173 
176 }
177 
178 
180 {
181  m_drawingSheet.reset( aDrawingSheet );
182  m_view->Add( m_drawingSheet.get() );
183 }
184 
185 
187 {
189 
190  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
191  {
193  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
194  }
195 
196  m_view->SetTopLayer( aLayer );
197 
198  // Move DCODE layer to the top
199  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
200 
202 
204 
206 }
207 
208 
210 {
211  // Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
213  return m_drawingSheet->ViewBBox();
214 
215  return BOX2I();
216 }
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:303
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
virtual void SetHighContrastLayer(int aLayer) override
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
Definition: view.cpp:640
GAL_TYPE m_backend
Currently used GAL.
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
Definition: view.cpp:837
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
GERBER_DRAW_ITEMS & GetItems()
An implementation of class VIEW_CONTROLS for wxWidgets library.
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
BOX2I GetDefaultViewBBox() const override
Return the bounding box of the view that should be used if model is not valid.
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1380
Hold the image data and parameters for one gerber file and layer parameters.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Called when the window is shown for the first time.
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:904
GERBVIEW_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
The base class for create windows for drawing purpose.
void setDefaultLayerDeps()
< Set rendering targets & dependencies for layers.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:700
Auxiliary rendering target (noncached)
Definition: definitions.h:49
#define ZOOM_MAX_LIMIT_GERBVIEW
Definition: zoom_defines.h:58
#define GERBER_DCODE_LAYER(x)
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:426
#define ZOOM_MIN_LIMIT_GERBVIEW
Definition: zoom_defines.h:59
#define NULL
#define GERBER_DRAWLAYERS_COUNT
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
void Clear()
Remove all items from the view.
Definition: view.cpp:1091
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:414
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
SETTINGS_MANAGER * GetSettingsManager()
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:889
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void OnShow() override
Called when the window is shown for the first time.
int GetActiveLayer() const
Return the active layer.
bool SwitchBackend(GAL_TYPE aGalType) override
Move the selected layer to the top, so it is displayed above all others.
virtual ~GERBVIEW_DRAW_PANEL_GAL()
Take care of display settings for the given layer to be displayed in high contrast mode.
Main rendering target (cached)
Definition: definitions.h:48
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
void SetDrawingSheet(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Set or update the drawing-sheet (borders and title block) used by the draw panel.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
virtual void SetTopLayer(int aLayer) override
Return the bounding box of the view that should be used if model is not valid.
currently selected items overlay
void ClearHighContrastLayers()
Clear the list of active layers.
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:197
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:322
drawingsheet frame and titleblock
#define GERBER_DRAW_LAYER(x)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:773
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:495
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:404