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 (C) 2018-2022 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
27
29
30#include <sch_preview_panel.h>
31#include <sch_view.h>
32#include <sch_painter.h>
33#include <sch_edit_frame.h>
36#include <zoom_defines.h>
37
38#include <functional>
39
40#include <sch_sheet.h>
41#include <pgm_base.h>
42
43using namespace std::placeholders;
44
45SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
46 const wxPoint& aPosition, const wxSize& aSize,
47 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
48 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
49{
50 m_view = new KIGFX::SCH_VIEW( true, nullptr );
52
54
55 m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
56
57 SCH_RENDER_SETTINGS* renderSettings = GetRenderSettings();
58 renderSettings->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
59 renderSettings->m_ShowPinsElectricalType = false;
60 renderSettings->m_ShowPinNumbers = false;
61 renderSettings->m_TextOffsetRatio = 0.35;
62
63 m_view->SetPainter( m_painter.get() );
64 // This fixes the zoom in and zoom out limits:
66 m_view->SetMirror( false, false );
67
70
72 // View controls is the first in the event handler chain, so the Tool Framework operates
73 // on updated viewport data.
75
76 m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
77 m_gal->SetCursorEnabled( false );
79
80 SetEvtHandlerEnabled( true );
81 SetFocus();
82 Show( true );
83 Raise();
85}
86
87
89{
90}
91
92
94{
95 return static_cast<SCH_RENDER_SETTINGS*>( m_painter->GetSettings() );
96}
97
98
100{
101 //m_view->RecacheAllItems();
102}
103
104
106{
107 for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
108 {
109 int layer = SCH_LAYER_ORDER[i];
110 wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
111
112 m_view->SetLayerOrder( layer, i );
113 }
114}
115
116
118{
119 // An alias's fields don't know how to substitute in their parent's values, so we
120 // don't let them draw themselves. This means no caching.
121 auto target = KIGFX::TARGET_NONCACHED;
122
123 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
124 m_view->SetLayerTarget( i, target );
125
128
131
134}
135
136
138{
139 return static_cast<KIGFX::SCH_VIEW*>( m_view );
140}
141
142
143void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
144{
145 EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
146}
147
148
149void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
150{
151 if( IsShownOnScreen() )
153}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
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.
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.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:68
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition: view.cpp:539
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:897
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Set a layer display-only (ie: to be rendered but not returned by hit test queries).
Definition: view.h:459
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:205
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:493
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:471
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:729
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:311
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
Definition: view.cpp:638
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
drawingsheet frame and titleblock
Definition: layer_ids.h:221
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:222
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:223
@ LAYER_SCHEMATIC_GRID
Definition: layer_ids.h:387
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
static const int SCH_LAYER_ORDER[]
Definition: sch_view.h:45
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
WX_VIEW_CONTROLS class definition.
#define ZOOM_MAX_LIMIT_EESCHEMA_PREVIEW
Definition: zoom_defines.h:53
#define ZOOM_MIN_LIMIT_EESCHEMA_PREVIEW
Definition: zoom_defines.h:54