KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_draw_panel.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) 2014-2019 CERN
5 * @author Maciej Suminski <[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
27#include <sch_draw_panel.h>
28
29#include <wx/debug.h>
30#include <wx/event.h>
31#include <wx/gdicmn.h>
32#include <wx/window.h>
33#include <wx/windowid.h>
34#include <memory>
35#include <stdexcept>
36
37#include <confirm.h>
38#include <eda_draw_frame.h>
39#include <gal/definitions.h>
41#include <layer_ids.h>
42#include <math/vector2d.h>
43#include <pgm_base.h>
45#include <view/view.h>
46#include <view/view_controls.h>
48
49#include <sch_base_frame.h>
50#include <sch_painter.h>
51#include <zoom_defines.h>
52
53
54SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
55 const wxPoint& aPosition, const wxSize& aSize,
56 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType )
57 : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
58{
59 m_view = new KIGFX::SCH_VIEW( dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) );
60 m_view->SetGAL( m_gal );
61
62 m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
63
64 m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
65
67
68 if( SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) )
69 cs = frame->GetColorSettings();
70
71 wxASSERT( cs );
72 m_painter->GetSettings()->LoadColors( cs );
73
74 m_view->SetPainter( m_painter.get() );
75
76 // This fixes the zoom in and zoom out limits:
78 m_view->SetMirror( false, false );
79
80 // Early initialization of the canvas background color,
81 // before any OnPaint event is fired for the canvas using a wrong bg color
82 auto settings = m_painter->GetSettings();
83 m_gal->SetClearColor( settings->GetBackgroundColor() );
84
87
89
90 // View controls is the first in the event handler chain, so the Tool Framework operates
91 // on updated viewport data.
93
94 SetEvtHandlerEnabled( true );
95 SetFocus();
96 Show( true );
97 Raise();
99}
100
101
105
106
108{
109 GetView()->DisplaySymbol( aSymbol );
110}
111
112
114{
115 GetView()->Clear();
116
117 if( aScreen )
118 GetView()->DisplaySheet( aScreen );
119 else
120 GetView()->Cleanup();
121}
122
123
125{
126 for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
127 {
128 int layer = SCH_LAYER_ORDER[i];
129 wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
130
131 m_view->SetLayerOrder( layer, i );
132 }
133}
134
135
137{
138 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
140 m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
141
142 Refresh();
143
144 return rv;
145}
146
147
149{
150 // caching makes no sense for Cairo and other software renderers
152
153 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
154 m_view->SetLayerTarget( i, target );
155
157 m_view->SetLayerDisplayOnly( LAYER_SCHEMATIC_ANCHOR );
158
159 // Bitmaps are draw on a non cached GAL layer:
161
162 // Some draw layers need specific settings
164 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
165
167 m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
168
170 m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
171
173 m_view->SetLayerDisplayOnly( LAYER_OP_VOLTAGES );
175 m_view->SetLayerDisplayOnly( LAYER_OP_CURRENTS );
176
178 m_view->SetLayerDisplayOnly( LAYER_SELECTION_SHADOWS ) ;
179
180 m_view->SetLayerDisplayOnly( LAYER_NET_COLOR_HIGHLIGHT );
181 m_view->SetLayerDisplayOnly( LAYER_DANGLING );
182}
183
184
186{
187 return static_cast<KIGFX::SCH_VIEW*>( m_view );
188}
189
190
192{
193 SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
194
195 try
196 {
197 // Check if the current rendering backend can be properly initialized
198 m_view->UpdateItems();
199 }
200 catch( const std::runtime_error& e )
201 {
202 DisplayInfoMessage( frame, e.what() );
203
204 // Use fallback if one is available
205 if( GAL_FALLBACK != m_backend )
206 {
208
209 if( frame )
210 frame->ActivateGalCanvas();
211 }
212 }
213}
214
215
216void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
217{
218 // The first wxPaintEvent can be fired at startup before the GAL engine is fully initialized
219 // (depending on platforms). Do nothing in this case
220 if( !m_gal->IsInitialized() || !m_gal->IsVisible() )
221 return;
222
224}
Color settings are a bit different than most of the settings objects in that there can be more than o...
static constexpr GAL_TYPE GAL_FALLBACK
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
@ GAL_TYPE_OPENGL
OpenGL implementation.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetFocus() override
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void StartDrawing()
Begin drawing if it was stopped previously.
GAL_TYPE m_backend
Currently used GAL.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
Contains methods for drawing schematic-specific items.
Definition sch_painter.h:69
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition sch_view.cpp:153
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition sch_view.cpp:112
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition view.cpp:906
void Clear()
Remove all items from the view.
Definition view.cpp:1143
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:745
An implementation of class VIEW_CONTROLS for wxWidgets library.
Define a library symbol object.
Definition lib_symbol.h:85
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
bool SwitchBackend(GAL_TYPE aGalType) override
Switch method of rendering graphics.
void DisplaySymbol(LIB_SYMBOL *aSymbol)
void OnShow() override
Called when the window is shown for the first time.
void DisplaySheet(SCH_SCREEN *aScreen)
void setDefaultLayerOrder()
Reassign layer order to the initial settings.
SCH_DRAW_PANEL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
void setDefaultLayerDeps()
Set rendering targets & dependencies for layers.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent)) override
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:222
This file is part of the common library.
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:277
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:283
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:278
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:279
@ LAYER_DANGLING
Definition layer_ids.h:476
@ LAYER_SCHEMATIC_ANCHOR
Definition layer_ids.h:498
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:492
@ LAYER_OP_CURRENTS
Definition layer_ids.h:500
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:493
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:499
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:38
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:37
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:39
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
see class PGM_BASE
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
static const int SCH_LAYER_ORDER[]
Definition sch_view.h:45
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
WX_VIEW_CONTROLS class definition.
#define ZOOM_MIN_LIMIT_EESCHEMA
#define ZOOM_MAX_LIMIT_EESCHEMA