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, see <https://www.gnu.org/licenses/>.
20 */
21
22
23#include <sch_draw_panel.h>
24
25#include <wx/debug.h>
26#include <wx/event.h>
27#include <wx/gdicmn.h>
28#include <wx/window.h>
29#include <wx/windowid.h>
30#include <memory>
31#include <stdexcept>
32
33#include <confirm.h>
34#include <eda_draw_frame.h>
35#include <gal/definitions.h>
37#include <layer_ids.h>
38#include <math/vector2d.h>
39#include <pgm_base.h>
41#include <view/view.h>
42#include <view/view_controls.h>
44
45#include <sch_base_frame.h>
46#include <sch_painter.h>
47#include <zoom_defines.h>
48
49
50SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
51 const wxPoint& aPosition, const wxSize& aSize,
52 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType )
53 : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
54{
55 m_view = new KIGFX::SCH_VIEW( dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) );
56 m_view->SetGAL( m_gal );
57
58 m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
59
60 m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
61
63
64 if( SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) )
65 cs = frame->GetColorSettings();
66
67 wxASSERT( cs );
68 m_painter->GetSettings()->LoadColors( cs );
69
70 m_view->SetPainter( m_painter.get() );
71
72 // This fixes the zoom in and zoom out limits:
74 m_view->SetMirror( false, false );
75
76 // Early initialization of the canvas background color,
77 // before any OnPaint event is fired for the canvas using a wrong bg color
78 auto settings = m_painter->GetSettings();
79 m_gal->SetClearColor( settings->GetBackgroundColor() );
80
83
85
86 // View controls is the first in the event handler chain, so the Tool Framework operates
87 // on updated viewport data.
89
90 SetEvtHandlerEnabled( true );
91 SetFocus();
92 Show( true );
93 Raise();
95}
96
97
101
102
104{
105 GetView()->DisplaySymbol( aSymbol );
106}
107
108
110{
111 GetView()->Clear();
112
113 if( aScreen )
114 GetView()->DisplaySheet( aScreen );
115 else
116 GetView()->Cleanup();
117}
118
119
121{
122 for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
123 {
124 int layer = SCH_LAYER_ORDER[i];
125 wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
126
127 m_view->SetLayerOrder( layer, i );
128 }
129}
130
131
133{
134 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
136 m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
137
138 Refresh();
139
140 return rv;
141}
142
143
145{
146 // caching makes no sense for Cairo and other software renderers
148
149 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
150 m_view->SetLayerTarget( i, target );
151
153 m_view->SetLayerDisplayOnly( LAYER_SCHEMATIC_ANCHOR );
154
155 // Bitmaps are draw on a non cached GAL layer:
157
158 // Some draw layers need specific settings
160 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
161
163 m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
164
166 m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
167
169 m_view->SetLayerDisplayOnly( LAYER_OP_VOLTAGES );
171 m_view->SetLayerDisplayOnly( LAYER_OP_CURRENTS );
172
174 m_view->SetLayerDisplayOnly( LAYER_SELECTION_SHADOWS ) ;
175
176 m_view->SetLayerDisplayOnly( LAYER_NET_COLOR_HIGHLIGHT );
177 m_view->SetLayerDisplayOnly( LAYER_DANGLING );
178}
179
180
182{
183 return static_cast<KIGFX::SCH_VIEW*>( m_view );
184}
185
186
188{
189 SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
190
191 try
192 {
193 // Check if the current rendering backend can be properly initialized
194 m_view->UpdateItems();
195 }
196 catch( const std::runtime_error& e )
197 {
198 DisplayInfoMessage( frame, e.what() );
199
200 // Use fallback if one is available
201 if( GAL_FALLBACK != m_backend )
202 {
204
205 if( frame )
206 frame->ActivateGalCanvas();
207 }
208 }
209}
210
211
212void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
213{
214 // The first wxPaintEvent can be fired at startup before the GAL engine is fully initialized
215 // (depending on platforms). Do nothing in this case
216 if( !m_gal->IsInitialized() || !m_gal->IsVisible() )
217 return;
218
220}
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))
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
@ 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:65
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition sch_view.cpp:213
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition sch_view.cpp:125
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition view.cpp:975
void Clear()
Remove all items from the view.
Definition view.cpp:1218
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:771
An implementation of class VIEW_CONTROLS for wxWidgets library.
Define a library symbol object.
Definition lib_symbol.h:79
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:245
This file is part of the common library.
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:280
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:276
@ LAYER_DANGLING
Definition layer_ids.h:475
@ LAYER_SCHEMATIC_ANCHOR
Definition layer_ids.h:498
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:491
@ 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:34
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:35
see class PGM_BASE
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
static const int SCH_LAYER_ORDER[]
Definition sch_view.h:43
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
WX_VIEW_CONTROLS class definition.
#define ZOOM_MIN_LIMIT_EESCHEMA
#define ZOOM_MAX_LIMIT_EESCHEMA