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 <functional>
21 #include <memory>
22 
23 #include <view/view.h>
24 #include <tool/tool_manager.h>
25 #include <view/wx_view_controls.h>
29 #include <page_layout/ws_painter.h>
30 #include <pgm_base.h>
31 #include <kiway.h>
34 
35 #include "pl_draw_panel_gal.h"
36 #include "pl_editor_frame.h"
37 #include "pl_editor_settings.h"
38 #include "tools/pl_actions.h"
40 
41 using namespace std::placeholders;
42 
43 
44 PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( 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::VIEW( true );
50  m_view->SetGAL( m_gal );
51 
52  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
53 
54  m_painter = std::make_unique<KIGFX::WS_PAINTER>( m_gal );
55 
56  SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
57  PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
58  m_painter->GetSettings()->LoadColors( settingsManager.GetColorSettings( cfg->m_ColorTheme ) );
59 
60  m_view->SetPainter( m_painter.get() );
61  m_view->SetScaleLimits( 20.0, 0.05 ); // This fixes the zoom in and zoom out limits
62 
64 
68 
70 }
71 
72 
74 {
75 }
76 
77 
79  std::vector<MSG_PANEL_ITEM>& aList )
80 {
81 }
82 
83 
85 {
88 
89  selTool->GetSelection().Clear();
90  m_view->Clear();
91 
92  m_pageDrawItem.reset();
93 
94  // Obviously, always show the page limit:
96  auto painter = m_view->GetPainter();
97  auto settings = painter->GetSettings();
98  settings->SetShowPageLimits( true );
99 
100  model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), Mils2iu( 1 ) );
101 
102  // To show the formatted texts instead of raw texts in page layout editor, we need
103  // a dummy WS_DRAW_ITEM_LIST.
105  dummy.SetPaperFormat( &m_edaFrame->GetPageSettings().GetType() );
106  dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
107  dummy.SetProject( &m_edaFrame->Prj() );
108 
109  for( WS_DATA_ITEM* dataItem : model.GetItems() )
110  dataItem->SyncDrawItems( &dummy, m_view );
111 
112  // Build and add a WS_DRAW_ITEM_PAGE to show the page limits and the corner position
113  // of the selected corner for coord origin of new items
114  // Not also this item has no peer in WS_DATA_MODEL list.
115  const int penWidth = 0; // This value is to use the default thickness line
116  constexpr double markerSize = Millimeter2iu( 5 );
117  m_pageDrawItem = std::make_unique<WS_DRAW_ITEM_PAGE>( penWidth, markerSize );
118  m_view->Add( m_pageDrawItem.get() );
119 
120  selTool->RebuildSelection();
121 
122  // Gives a reasonable boundary to the view area
123  // Otherwise scroll bars are not usable
124  // A full size = 2 * page size allows a margin around the worksheet.
125  // (Note: no need to have a large working area: nothing can be drawn outside th page size).
126  double size_x = m_edaFrame->GetPageSizeIU().x;
127  double size_y = m_edaFrame->GetPageSizeIU().y;
128  BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ),
129  VECTOR2D( size_x * 1.5, size_y * 1.5) );
130  m_view->SetBoundary( boundary );
131 
132  m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
133  wxPoint originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
134  m_pageDrawItem->SetMarkerPos( originCoord );
135 }
136 
137 
139 {
140  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
141 
142  // The next onPaint event will call m_view->UpdateItems() that is very time consumming
143  // after switching to opengl. Clearing m_view and rebuild it is much faster
144  if( aGalType == GAL_TYPE_OPENGL )
145  m_view->Clear();
146 
148 
149  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
150 
151  return rv;
152 }
153 
154 
156 {
157  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
159 
161 
164 
167 }
168 
169 
171 {
173  m_view->SetTopLayer( aLayer );
174 
176 
178 
180 }
181 
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:38
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.
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:95
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:97
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:838
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)
WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
bool SwitchBackend(GAL_TYPE aGalType) override
std::unique_ptr< WS_DRAW_ITEM_PAGE > m_pageDrawItem
const wxString & GetType() const
Definition: page_info.h:98
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:905
The base class for create windows for drawing purpose.
void DisplayWorksheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
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:201
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 WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:420
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ws_draw_item.h:359
virtual const PAGE_INFO & GetPageSettings() const =0
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1089
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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
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.
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:385
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
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:890
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
see class PGM_BASE
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.
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
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
void SetShowPageLimits(bool aShow)
VIEW.
Definition: view.h:63
void SetBoundary(const BOX2D &aBoundary)
Function SetBoundary() Sets limits for view area.
Definition: view.h:269
for pageLayout editor previewing
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:500
virtual void SetTopLayer(int aLayer) override
static constexpr int Millimeter2iu(double mm)
void SetShowPageLimits(bool aDraw)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:176