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( 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
105 for( DS_DATA_ITEM* dataItem : model.GetItems() )
106 dataItem->SyncDrawItems( &dummy, m_view );
107
108 // Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
109 // of the selected corner for coord origin of new items
110 // Not also this item has no peer in DS_DATA_MODEL list.
111 const int penWidth = 0; // This value is to use the default thickness line
112 constexpr double markerSize = drawSheetIUScale.mmToIU( 5 );
113 m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
114 m_view->Add( m_pageDrawItem.get() );
115
116 selTool->RebuildSelection();
117
118 // Gives a reasonable boundary to the view area
119 // Otherwise scroll bars are not usable
120 // A full size = 2 * page size allows a margin around the drawing sheet.
121 // (Note: no need to have a large working area: nothing can be drawn outside th page size).
122 double size_x = m_edaFrame->GetPageSizeIU().x;
123 double size_y = m_edaFrame->GetPageSizeIU().y;
124 BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
125 m_view->SetBoundary( boundary );
126
127 m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
128 VECTOR2I originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
129 m_pageDrawItem->SetMarkerPos( originCoord );
130}
131
132
134{
135 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
136
138
139 GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
140
141 return rv;
142}
143
144
146{
147 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
149
151
154
157}
158
159
161{
163 m_view->SetTopLayer( aLayer );
164
166
168
170}
171
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:110
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:173
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:894
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:459
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:205
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:281
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:493
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:471
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:395
void Clear()
Remove all items from the view.
Definition: view.cpp:1121
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:879
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:729
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:827
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:311
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
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:92
T * GetAppSettings()
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:55
@ LAYER_DRAWINGSHEET_PAGEn
for drawingsheetEditor previewing
Definition: layer_ids.h:250
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:220
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:221
@ LAYER_DRAWINGSHEET_PAGE1
for drawingsheetEditor previewing
Definition: layer_ids.h:249
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:222
@ 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
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
std::vector< FAB_LAYER_COLOR > dummy
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:587
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