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>
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( 100.0 ), Mils2iu( 100.0 ) ) );
72 
73  SetEvtHandlerEnabled( true );
74  SetFocus();
75  Show( true );
76  Raise();
77  StartDrawing();
78 }
79 
80 
82 {
83 }
84 
85 
87 {
88  //m_view->RecacheAllItems();
89 }
90 
91 
93 {
94  for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
95  {
96  LAYER_NUM layer = SCH_LAYER_ORDER[i];
97  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
98 
99  m_view->SetLayerOrder( layer, i );
100  }
101 }
102 
103 
105 {
106  // An alias's fields don't know how to substitute in their parent's values, so we
107  // don't let them draw themselves. This means no caching.
108  auto target = KIGFX::TARGET_NONCACHED;
109 
110  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
111  m_view->SetLayerTarget( i, target );
112 
115 
118 
121 }
122 
123 
125 {
126  return static_cast<KIGFX::SCH_VIEW*>( m_view );
127 }
128 
129 
130 void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
131 {
132  EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
133 }
134 
135 
136 void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
137 {
138  if( IsShown() )
139  EDA_DRAW_PANEL_GAL::onPaint( aEvent );
140 }
void SetScaleLimits(double aMaximum, double aMinimum)
Function SetScaleLimits() Sets minimum and maximum values for scale.
Definition: view.h:300
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
void OnShow() override
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:645
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.
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:905
void SetMirror(bool aMirrorX, bool aMirrorY)
Function SetMirror() Controls the mirroring of the VIEW.
Definition: view.cpp:546
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:694
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:420
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:408
SCH_PAINTER Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:133
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
This 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:191
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:500