KiCad PCB EDA Suite
pl_draw_panel_gal.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 modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "pl_draw_panel_gal.h"
21 #include <view/view.h>
22 #include <tool/tool_manager.h>
23 #include <tools/pl_actions.h>
24 #include <view/wx_view_controls.h>
25 #include <ws_proxy_view_item.h>
26 #include <ws_data_model.h>
27 #include <ws_painter.h>
28 #include <colors_design_settings.h>
29 #include <pl_editor_frame.h>
31 
32 #include <functional>
34 
35 using namespace std::placeholders;
36 
37 
38 PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
39  const wxPoint& aPosition, const wxSize& aSize,
40  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
41  EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
42 {
43  m_view = new KIGFX::VIEW( true );
44  m_view->SetGAL( m_gal );
45 
46  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
47 
48  m_painter.reset( new KIGFX::WS_PAINTER( m_gal ) );
49  m_view->SetPainter( m_painter.get() );
50  m_view->SetScaleLimits( 20.0, 0.05 ); // This fixes the zoom in and zoom out limits
51 
53 
57 
59 }
60 
61 
63 {
64 }
65 
66 
67 void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector<MSG_PANEL_ITEM>& aList )
68 {
69 }
70 
71 
73 {
76 
77  selTool->GetSelection().Clear();
78  m_view->Clear();
79 
80  // Obviously, always show the page limit:
82  auto painter = m_view->GetPainter();
83  auto settings = painter->GetSettings();
84  settings->SetShowPageLimits( true );
85 
86  model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), Mils2iu( 1 ) );
87 
88  // To show the formatted texts instead of raw texts in page layout editor, we need
89  // a dummy WS_DRAW_ITEM_LIST.
91  dummy.SetPaperFormat( &m_edaFrame->GetPageSettings().GetType() );
92  dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
93 
94  for( WS_DATA_ITEM* dataItem : model.GetItems() )
95  dataItem->SyncDrawItems( &dummy, m_view );
96 
97  // Build and add a WS_DRAW_ITEM_PAGE to show the page limits and the corner position
98  // of the selected corner for coord origin of new items
99  // Not also this item has no peer in WS_DATA_MODEL list.
100  const int penWidth = 0; // This value is to use the default thickness line
101  constexpr double markerSize = Millimeter2iu( 5 );
102  WS_DRAW_ITEM_PAGE* pageDrawing = new WS_DRAW_ITEM_PAGE( penWidth, markerSize );
103  m_view->Add( pageDrawing );
104 
105  selTool->RebuildSelection();
106 
107  // Gives a reasonable boundary to the view area
108  // Otherwise scroll bars are not usable
109  // A full size = 2 * page size allows a margin around the worksheet.
110  // (Note: no need to have a large working area: nothing can be drawn outside th page size).
111  double size_x = m_edaFrame->GetPageSizeIU().x;
112  double size_y = m_edaFrame->GetPageSizeIU().y;
113  BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ),
114  VECTOR2D( size_x * 1.5, size_y * 1.5) );
115  m_view->SetBoundary( boundary );
116 
117  pageDrawing->SetPageSize( m_edaFrame->GetPageSizeIU() );
118  wxPoint originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
119  pageDrawing->SetMarkerPos( originCoord );
120 }
121 
122 
124 {
125  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
126 
127  // The next onPaint event will call m_view->UpdateItems() that is very time consumming
128  // after switching to opengl. Clearing m_view and rebuild it is much faster
129  if( aGalType == GAL_TYPE_OPENGL )
130  m_view->Clear();
131 
133 
134  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
135 
136  return rv;
137 }
138 
139 
141 {
142  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
144 
146 
149 
152 }
153 
154 
156 {
158  m_view->SetTopLayer( aLayer );
159 
161 
163 
165 }
166 
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
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.
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
void RebuildSelection()
Rebuild the selection from the flags in the view items.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
for pageLayout editor previewing
virtual const TITLE_BLOCK & GetTitleBlock() const =0
Work sheet structure type definitions.
Definition: ws_data_item.h:93
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Function SetTopLayer() Sets given layer to be displayed on the top or sets back the default order of ...
Definition: view.cpp:860
PL_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Handle colors used to draw all items or layers.
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
bool SwitchBackend(GAL_TYPE aGalType) override
const wxString & GetType() const
Definition: page_info.h:97
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:927
void DisplayWorksheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
PL_SELECTION & GetSelection()
Function GetSelection()
virtual const wxSize GetPageSizeIU() const =0
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
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 WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void SetMarkerPos(wxPoint aPos)
Definition: ws_draw_item.h:252
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:434
virtual const PAGE_INFO & GetPageSettings() const =0
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
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
Class WS_PAINTER Contains methods for drawing worksheet items.
Definition: ws_painter.h:95
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:399
EDA_DRAW_FRAME * m_edaFrame
Pointer to the parent window.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void ClearTopLayers()
Function ClearTopLayers() Removes all layers from the on-the-top set (they are no longer displayed ov...
Definition: view.cpp:912
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
void SetPageSize(wxSize aSize)
Definition: ws_draw_item.h:249
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
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
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void SetShowPageLimits(bool aShow)
Class VIEW.
Definition: view.h:61
void SetBoundary(const BOX2D &aBoundary)
Function SetBoundary() Sets limits for view area.
Definition: view.h:267
for pageLayout editor previewing
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:519
virtual void SetTopLayer(int aLayer) override
EDA_UNITS_T
Definition: common.h:154
void SetShowPageLimits(bool aDraw)
Definition: painter.h:188