KiCad PCB EDA Suite
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-2019 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 
25 #include <view/wx_view_controls.h>
26 #include <ws_proxy_view_item.h>
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 
37 #include <functional>
38 
39 #include <sch_sheet.h>
40 #include <pgm_base.h>
41 
42 using namespace std::placeholders;
43 
44 SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
45  const wxPoint& aPosition, const wxSize& aSize,
46  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
47  EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ),
48  m_parent( aParentWindow )
49 {
50  m_view = new KIGFX::SCH_VIEW( true, nullptr );
51  m_view->SetGAL( m_gal );
52 
54 
55  m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
56  m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
57 
58  m_view->SetPainter( m_painter.get() );
59  m_view->SetScaleLimits( 20000.0, 0.002 );
60  m_view->SetMirror( false, false );
61 
64 
66  // View controls is the first in the event handler chain, so the Tool Framework operates
67  // on updated viewport data.
69 
71  m_gal->SetCursorEnabled( false );
72  m_gal->SetGridSize( VECTOR2D( Mils2iu( 50.0 ), Mils2iu( 50.0 ) ) );
73 
74  m_viewControls->SetSnapping( true );
75 
76  SetEvtHandlerEnabled( true );
77  SetFocus();
78  Show( true );
79  Raise();
80  StartDrawing();
81 }
82 
83 
85 {
86 }
87 
88 
90 {
91  //m_view->RecacheAllItems();
92 }
93 
94 
96 {
97  for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
98  {
99  LAYER_NUM layer = SCH_LAYER_ORDER[i];
100  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
101 
102  m_view->SetLayerOrder( layer, i );
103  }
104 }
105 
106 
108 {
109  // An alias's fields don't know how to substitute in their parent's values, so we
110  // don't let them draw themselves. This means no caching.
111  auto target = KIGFX::TARGET_NONCACHED;
112 
113  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
114  m_view->SetLayerTarget( i, target );
115 
118 
121 
124 }
125 
126 
128 {
129  return static_cast<KIGFX::SCH_VIEW*>( m_view );
130 }
131 
132 
133 void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
134 {
135  EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
136 }
137 
138 
139 void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
140 {
141  if( IsShown() )
142  EDA_DRAW_PANEL_GAL::onPaint( aEvent );
143 }
void SetScaleLimits(double aMaximum, double aMinimum)
Function SetScaleLimits() Sets minimum and maximum values for scale.
Definition: view.h:298
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
void OnShow() override
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:664
KIGFX::SCH_VIEW * view() const
WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:927
void SetMirror(bool aMirrorX, bool aMirrorY)
Function SetMirror() Controls the mirroring of the VIEW.
Definition: view.cpp:565
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static const LAYER_NUM SCH_LAYER_ORDER[]
Definition: sch_view.h:44
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:434
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
void setDefaultLayerOrder()
Reassigns layer order to the initial settings.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
SCH_PREVIEW_PANEL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
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:422
SCH_PAINTER Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:117
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
void onPaint(wxPaintEvent &WXUNUSED(aEvent)) override
virtual void SetFocus() override
~SCH_PREVIEW_PANEL() override
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
void StartDrawing()
Function StartDrawing() Begins drawing if it was stopped previously.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
see class PGM_BASE
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
currently selected items overlay
void SetPainter(PAINTER *aPainter)
Function SetPainter() Sets the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:189
void Refresh(bool aEraseBackground, const wxRect *aRect) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:519