KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_preview_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20
23
25
26#include <sch_preview_panel.h>
27#include <sch_view.h>
28#include <sch_painter.h>
29#include <sch_edit_frame.h>
32#include <zoom_defines.h>
33
34#include <functional>
35
36#include <sch_sheet.h>
37#include <pgm_base.h>
38
39using namespace std::placeholders;
40
41SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
42 const wxPoint& aPosition, const wxSize& aSize,
43 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
44 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
45{
46 m_view = new KIGFX::SCH_VIEW( nullptr );
47 m_view->SetGAL( m_gal );
48
49 m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
50
51 m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
52
53 SCH_RENDER_SETTINGS* renderSettings = GetRenderSettings();
54 renderSettings->LoadColors( ::GetColorSettings( DEFAULT_THEME ) );
55 renderSettings->m_ShowPinsElectricalType = false;
56 renderSettings->m_ShowPinNumbers = false;
57 renderSettings->m_TextOffsetRatio = 0.35;
58
59 m_view->SetPainter( m_painter.get() );
60 // This fixes the zoom in and zoom out limits:
62 m_view->SetMirror( false, false );
63
66
68 // View controls is the first in the event handler chain, so the Tool Framework operates
69 // on updated viewport data.
71
72 m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
73 m_gal->SetCursorEnabled( false );
74 m_gal->SetGridSize( VECTOR2D( schIUScale.MilsToIU( 100.0 ), schIUScale.MilsToIU( 100.0 ) ) );
75
76 SetEvtHandlerEnabled( true );
77 SetFocus();
78 Show( true );
79 Raise();
81}
82
83
87
88
90{
91 return static_cast<SCH_RENDER_SETTINGS*>( m_painter->GetSettings() );
92}
93
94
96{
97 //m_view->RecacheAllItems();
98}
99
100
102{
103 for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
104 {
105 int layer = SCH_LAYER_ORDER[i];
106 wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
107
108 m_view->SetLayerOrder( layer, i );
109 }
110}
111
112
114{
115 // An alias's fields don't know how to substitute in their parent's values, so we
116 // don't let them draw themselves. This means no caching.
117 auto target = KIGFX::TARGET_NONCACHED;
118
119 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
120 m_view->SetLayerTarget( i, target );
121
122 m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
123 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
124
126 m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
127
129 m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
130}
131
132
134{
135 return static_cast<KIGFX::SCH_VIEW*>( m_view );
136}
137
138
139void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
140{
141 EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
142}
143
144
145void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
146{
147 if( IsShownOnScreen() )
149}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
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
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
void StartDrawing()
Begin drawing if it was stopped previously.
Contains methods for drawing schematic-specific items.
Definition sch_painter.h:65
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition view.cpp:975
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.
void setDefaultLayerOrder()
Set rendering targets & dependencies for layers.
void OnShow() override
Called when the window is shown for the first time.
KIGFX::SCH_VIEW * view() const
Reassign layer order to the initial settings.
void Refresh(bool aEraseBackground, const wxRect *aRect) override
SCH_PREVIEW_PANEL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
~SCH_PREVIEW_PANEL() override
Called when the window is shown for the first time.
void onPaint(wxPaintEvent &WXUNUSED(aEvent)) override
SCH_RENDER_SETTINGS * GetRenderSettings() const
void LoadColors(const COLOR_SETTINGS *aSettings) override
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:276
@ LAYER_SCHEMATIC_GRID
Definition layer_ids.h:484
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
@ 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)
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
WX_VIEW_CONTROLS class definition.
#define ZOOM_MAX_LIMIT_EESCHEMA_PREVIEW
#define ZOOM_MIN_LIMIT_EESCHEMA_PREVIEW