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 {
49  m_view = new KIGFX::SCH_VIEW( true, nullptr );
50  m_view->SetGAL( m_gal );
51 
53 
54  m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
55  m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
56 
57  m_view->SetPainter( m_painter.get() );
58  m_view->SetScaleLimits( 20000.0, 0.002 );
59  m_view->SetMirror( false, false );
60 
63 
65  // View controls is the first in the event handler chain, so the Tool Framework operates
66  // on updated viewport data.
68 
69  m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
70  m_gal->SetCursorEnabled( false );
71  m_gal->SetGridSize( VECTOR2D( Mils2iu( 50.0 ), Mils2iu( 50.0 ) ) );
72 
73  m_viewControls->SetSnapping( true );
74 
75  SetEvtHandlerEnabled( true );
76  SetFocus();
77  Show( true );
78  Raise();
79  StartDrawing();
80 }
81 
82 
84 {
85 }
86 
87 
89 {
90  //m_view->RecacheAllItems();
91 }
92 
93 
95 {
96  for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
97  {
98  LAYER_NUM layer = SCH_LAYER_ORDER[i];
99  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
100 
101  m_view->SetLayerOrder( layer, i );
102  }
103 }
104 
105 
107 {
108  // An alias's fields don't know how to substitute in their parent's values, so we
109  // don't let them draw themselves. This means no caching.
110  auto target = KIGFX::TARGET_NONCACHED;
111 
112  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
113  m_view->SetLayerTarget( i, target );
114 
117 
120 
123 }
124 
125 
127 {
128  return static_cast<KIGFX::SCH_VIEW*>( m_view );
129 }
130 
131 
132 void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
133 {
134  EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
135 }
136 
137 
138 void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
139 {
140  if( IsShown() )
141  EDA_DRAW_PANEL_GAL::onPaint( aEvent );
142 }
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:104
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:128
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.
SETTINGS_MANAGER * GetSettingsManager()
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