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 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 <worksheet_viewitem.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>
35 
36 #include <functional>
37 
38 #include <sch_sheet.h>
39 #include <pgm_base.h>
40 
41 using namespace std::placeholders;
42 
43 SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
44  const wxPoint& aPosition, const wxSize& aSize,
45  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
46  EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ),
47  m_parent( aParentWindow )
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 
56  m_view->SetPainter( m_painter.get() );
57  m_view->SetScaleLimits( 20000.0, 0.002 );
58  m_view->SetMirror( false, false );
59 
62 
64  // View controls is the first in the event handler chain, so the Tool Framework operates
65  // on updated viewport data.
67 
70  m_gal->SetGridSize( VECTOR2D( 50.0, 50.0 ) );
71 
72  m_viewControls->SetSnapping( true );
73 
74  SetEvtHandlerEnabled( true );
75  SetFocus();
76  Show( true );
77  Raise();
78  StartDrawing();
79 }
80 
81 
83 {
84 }
85 
86 
88 {
89  //m_view->RecacheAllItems();
90 }
91 
92 
94 {
95  for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
96  {
97  LAYER_NUM layer = SCH_LAYER_ORDER[i];
98  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
99 
100  m_view->SetLayerOrder( layer, i );
101  }
102 }
103 
104 
106 {
107  // An alias's fields don't know how to substitute in their parent's values, so we
108  // don't let them draw themselves. This means no caching.
109  auto target = KIGFX::TARGET_NONCACHED;
110 
111  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
112  m_view->SetLayerTarget( i, target );
113 
116 
119 
122 }
123 
124 
126 {
127  return static_cast<KIGFX::SCH_VIEW*>( m_view );
128 }
129 
130 
131 void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
132 {
133  EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
134 }
135 
136 
137 void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
138 {
139  if( m_painter )
140  static_cast<KIGFX::SCH_PAINTER*>(m_painter.get())->GetSettings()->ImportLegacyColors( nullptr );
141 
142  if( IsShown() )
143  EDA_DRAW_PANEL_GAL::onPaint( aEvent );
144 }
Definition of the SCH_SHEET class for Eeschema.
void SetScaleLimits(double aMaximum, double aMinimum)
Function SetScaleLimits() Sets minimum and maximum values for scale.
Definition: view.h:309
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:661
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library...
constexpr double SCH_WORLD_UNIT
Definition: sch_view.h:41
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:924
void SetMirror(bool aMirrorX, bool aMirrorY)
Function SetMirror() Controls the mirroring of the VIEW.
Definition: view.cpp:563
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:699
Auxiliary rendering target (noncached)
Definition: definitions.h:42
static const LAYER_NUM SCH_LAYER_ORDER[]
Definition: sch_view.h:43
Class that handles properties and drawing of worksheet layout.
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:445
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:586
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:433
Class SCH_PAINTER Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:112
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
void onPaint(wxPaintEvent &WXUNUSED(aEvent)) override
virtual void SetFocus() override
general purpose overlay
~SCH_PREVIEW_PANEL() override
void SetCursorColor(const COLOR4D &aCursorColor)
Set the cursor color.
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
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
size_t i
Definition: json11.cpp:597
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:517
KIGFX::SCH_VIEW * view() const