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>
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 #include <zoom_defines.h>
41 
42 using namespace std::placeholders;
43 
44 
45 PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
46  const wxPoint& aPosition, const wxSize& aSize,
47  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
48  EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
49 {
50  m_view = new KIGFX::VIEW( true );
51  m_view->SetGAL( m_gal );
52 
53  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
54 
55  m_painter = std::make_unique<KIGFX::DS_PAINTER>( m_gal );
56 
57  SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
58  PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
59  m_painter->GetSettings()->LoadColors( settingsManager.GetColorSettings( cfg->m_ColorTheme ) );
60 
61  m_view->SetPainter( m_painter.get() );
62  // This fixes the zoom in and zoom out limits
64 
66 
70 
72 }
73 
74 
76 {
77 }
78 
79 
81  std::vector<MSG_PANEL_ITEM>& aList )
82 {
83 }
84 
85 
87 {
90 
91  selTool->GetSelection().Clear();
92  m_view->Clear();
93 
94  m_pageDrawItem.reset();
95 
96  // Obviously, always show the page limit:
98  auto painter = m_view->GetPainter();
99  auto settings = painter->GetSettings();
100  settings->SetShowPageLimits( true );
101 
102  model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), IU_PER_MILS );
103 
104  // To show the formatted texts instead of raw texts in drawing sheet editor, we need
105  // a dummy DS_DRAW_ITEM_LIST.
107  dummy.SetPaperFormat( &m_edaFrame->GetPageSettings().GetType() );
108  dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
109  dummy.SetProject( &m_edaFrame->Prj() );
110  dummy.SetMilsToIUfactor( IU_PER_MILS );
111 
112  for( DS_DATA_ITEM* dataItem : model.GetItems() )
113  dataItem->SyncDrawItems( &dummy, m_view );
114 
115  // Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
116  // of the selected corner for coord origin of new items
117  // Not also this item has no peer in DS_DATA_MODEL list.
118  const int penWidth = 0; // This value is to use the default thickness line
119  constexpr double markerSize = Millimeter2iu( 5 );
120  m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
121  m_view->Add( m_pageDrawItem.get() );
122 
123  selTool->RebuildSelection();
124 
125  // Gives a reasonable boundary to the view area
126  // Otherwise scroll bars are not usable
127  // A full size = 2 * page size allows a margin around the drawing sheet.
128  // (Note: no need to have a large working area: nothing can be drawn outside th page size).
129  double size_x = m_edaFrame->GetPageSizeIU().x;
130  double size_y = m_edaFrame->GetPageSizeIU().y;
131  BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ),
132  VECTOR2D( size_x * 1.5, size_y * 1.5) );
133  m_view->SetBoundary( boundary );
134 
135  m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
136  wxPoint originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
137  m_pageDrawItem->SetMarkerPos( originCoord );
138 }
139 
140 
142 {
143  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
144 
146 
147  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
148 
149  return rv;
150 }
151 
152 
154 {
155  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
157 
159 
162 
165 }
166 
167 
169 {
171  m_view->SetTopLayer( aLayer );
172 
174 
176 
178 }
179 
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:303
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
for drawingsheetEditor previewing
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:38
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:82
void RebuildSelection()
Rebuild the selection from the flags in the view items.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
Definition: view.cpp:837
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)
An implementation of class VIEW_CONTROLS for wxWidgets library.
#define ZOOM_MAX_LIMIT_PLEDITOR
Definition: zoom_defines.h:54
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
bool SwitchBackend(GAL_TYPE aGalType) override
Move the selected layer to the top, so it is displayed above all others.
const wxString & GetType() const
Definition: page_info.h:94
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:904
void DisplayDrawingSheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
The base class for create windows for drawing purpose.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
PL_SELECTION & GetSelection()
Return the set of currently selected items.
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
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:680
Auxiliary rendering target (noncached)
Definition: definitions.h:49
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:424
virtual const PAGE_INFO & GetPageSettings() const =0
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
std::unique_ptr< DS_DRAW_ITEM_PAGE > m_pageDrawItem
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void Clear()
Remove all items from the view.
Definition: view.cpp:1091
PROJECT & Prj() const
Return 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.
for drawingsheetEditor previewing
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:412
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::GAL * GetGAL() const
Return 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)
Control the visibility of a particular layer.
Definition: view.h:387
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:889
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
see class PGM_BASE
void setDefaultLayerDeps()
< Set rendering targets & dependencies for layers.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
Drawing sheet structure type definitions.
Definition: ds_data_item.h:95
currently selected items overlay
#define IU_PER_MILS
Definition: plotter.cpp:137
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:197
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:376
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:321
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
drawingsheet frame and titleblock
void SetShowPageLimits(bool aShow)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:273
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:494
virtual void SetTopLayer(int aLayer) override
Move the selected layer to the top, so it is displayed above all others.
static constexpr int Millimeter2iu(double mm)
void SetShowPageLimits(bool aDraw)
#define ZOOM_MIN_LIMIT_PLEDITOR
Definition: zoom_defines.h:55
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184