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>
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
42using namespace std::placeholders;
43
44
45PL_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 );
52
53 GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.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();
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 model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), drawSheetIUScale.IU_PER_MILS );
97
98 // To show the formatted texts instead of raw texts in drawing sheet editor, we need
99 // a dummy DS_DRAW_ITEM_LIST.
101 dummy.SetPaperFormat( &m_edaFrame->GetPageSettings().GetType() );
102 dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
103 dummy.SetProject( &m_edaFrame->Prj() );
104 dummy.SetMilsToIUfactor( drawSheetIUScale.IU_PER_MILS );
105
106 for( DS_DATA_ITEM* dataItem : model.GetItems() )
107 dataItem->SyncDrawItems( &dummy, m_view );
108
109 // Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
110 // of the selected corner for coord origin of new items
111 // Not also this item has no peer in DS_DATA_MODEL list.
112 const int penWidth = 0; // This value is to use the default thickness line
113 constexpr double markerSize = drawSheetIUScale.mmToIU( 5 );
114 m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
115 m_view->Add( m_pageDrawItem.get() );
116
117 selTool->RebuildSelection();
118
119 // Gives a reasonable boundary to the view area
120 // Otherwise scroll bars are not usable
121 // A full size = 2 * page size allows a margin around the drawing sheet.
122 // (Note: no need to have a large working area: nothing can be drawn outside th page size).
123 double size_x = m_edaFrame->GetPageSizeIU().x;
124 double size_y = m_edaFrame->GetPageSizeIU().y;
125 BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
126 m_view->SetBoundary( boundary );
127
128 m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
129 VECTOR2I originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
130 m_pageDrawItem->SetMarkerPos( originCoord );
131}
132
133
135{
136 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
137
139
140 GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
141
142 return rv;
143}
144
145
147{
148 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
150
152
155
158}
159
160
162{
164 m_view->SetTopLayer( aLayer );
165
167
169
171}
172
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:110
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:187
Drawing sheet structure type definitions.
Definition: ds_data_item.h:96
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:39
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:383
The base class for create windows for drawing purpose.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
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...
virtual const PAGE_INFO & GetPageSettings() const =0
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:889
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Set a layer display-only (ie: to be rendered but not returned by hit test queries).
Definition: view.h:457
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:203
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:279
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:489
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:469
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:393
void Clear()
Remove all items from the view.
Definition: view.cpp:1096
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:874
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:720
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:822
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:309
An implementation of class VIEW_CONTROLS for wxWidgets library.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
const wxString & GetType() const
Definition: page_info.h:94
std::unique_ptr< DS_DRAW_ITEM_PAGE > m_pageDrawItem
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
virtual void SetTopLayer(int aLayer) override
Move the selected layer to the top, so it is displayed above all others.
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)
void DisplayDrawingSheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
void setDefaultLayerDeps()
< Set rendering targets & dependencies for layers.
bool SwitchBackend(GAL_TYPE aGalType) override
Move the selected layer to the top, so it is displayed above all others.
The main window used in the drawing sheet editor.
PL_SELECTION & GetSelection()
Return the set of currently selected items.
void RebuildSelection()
Rebuild the selection from the flags in the view items.
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:90
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
@ LAYER_DRAWINGSHEET_PAGEn
for drawingsheetEditor previewing
Definition: layer_ids.h:247
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:217
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:218
@ LAYER_DRAWINGSHEET_PAGE1
for drawingsheetEditor previewing
Definition: layer_ids.h:246
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:219
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
see class PGM_BASE
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
const double IU_PER_MM
Definition: base_units.h:77
const double IU_PER_MILS
Definition: base_units.h:78
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
WX_VIEW_CONTROLS class definition.
#define ZOOM_MAX_LIMIT_PLEDITOR
Definition: zoom_defines.h:54
#define ZOOM_MIN_LIMIT_PLEDITOR
Definition: zoom_defines.h:55