KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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();
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
58 PL_EDITOR_SETTINGS* cfg = mgr.GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
59
60 m_painter->GetSettings()->LoadColors( mgr.GetColorSettings( cfg->m_ColorTheme ) );
61
62 m_view->SetPainter( m_painter.get() );
63 // This fixes the zoom in and zoom out limits
65
67
71
73}
74
75
77{
78}
79
80
82 std::vector<MSG_PANEL_ITEM>& aList )
83{
84}
85
86
88{
91
92 selTool->GetSelection().Clear();
93 m_view->Clear();
94
95 m_pageDrawItem.reset();
96
97 model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), drawSheetIUScale.IU_PER_MILS );
98
99 // To show the formatted texts instead of raw texts in drawing sheet editor, we need
100 // a dummy DS_DRAW_ITEM_LIST.
102 dummy.SetPaperFormat( m_edaFrame->GetPageSettings().GetType() );
103 dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
104 dummy.SetProject( &m_edaFrame->Prj() );
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:109
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:197
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:401
The base class for create windows for drawing purpose.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual const PAGE_INFO & GetPageSettings() const =0
virtual const VECTOR2I GetPageSizeIU() const =0
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
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:68
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:896
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:478
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:299
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:283
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:503
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:494
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:397
void Clear()
Remove all items from the view.
Definition: view.cpp:1127
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:881
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:742
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:829
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:313
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:99
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
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:93
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
@ LAYER_DRAWINGSHEET_PAGEn
for drawingsheetEditor previewing
Definition: layer_ids.h:251
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:218
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:219
@ LAYER_DRAWINGSHEET_PAGE1
for drawingsheetEditor previewing
Definition: layer_ids.h:250
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:220
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:38
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:39
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
const double IU_PER_MM
Definition: base_units.h:76
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690
WX_VIEW_CONTROLS class definition.
#define ZOOM_MAX_LIMIT_PLEDITOR
Definition: zoom_defines.h:57
#define ZOOM_MIN_LIMIT_PLEDITOR
Definition: zoom_defines.h:58