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 The 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();
51 m_view->SetGAL( m_gal );
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
59 m_painter->GetSettings()->LoadColors( ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME ) );
60
61 m_view->SetPainter( m_painter.get() );
62 // This fixes the zoom in and zoom out limits
64
66
67 m_view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
68 m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, true );
69 m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, false );
70
72}
73
74
78
79
81 std::vector<MSG_PANEL_ITEM>& aList )
82{
83}
84
85
87{
88 PL_SELECTION_TOOL* selTool = m_edaFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
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().GetTypeAsString() );
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++ )
148 m_view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
149
150 m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
151
153 m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
154
156 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
157}
158
159
161{
162 m_view->ClearTopLayers();
163 m_view->SetTopLayer( aLayer );
164
165 m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
166
167 m_view->SetTopLayer( LAYER_GP_OVERLAY );
168
169 m_view->UpdateAllLayersOrder();
170}
171
constexpr EDA_IU_SCALE drawSheetIUScale
Definition base_units.h:113
BOX2< VECTOR2D > BOX2D
Definition box2.h:923
wxString m_ColorTheme
Active color theme name.
Drawing sheet structure type definitions.
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
Return 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...
The base class for create windows for drawing purpose.
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.
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
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:66
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:745
An implementation of class VIEW_CONTROLS for wxWidgets library.
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:98
@ LAYER_DRAWINGSHEET_PAGEn
Sheet Editor previewing pages after first page.
Definition layer_ids.h:326
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:277
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:278
@ LAYER_DRAWINGSHEET_PAGE1
Sheet Editor previewing first page.
Definition layer_ids.h:325
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:279
@ 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
see class PGM_BASE
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
WX_VIEW_CONTROLS class definition.
#define ZOOM_MAX_LIMIT_PLEDITOR
#define ZOOM_MIN_LIMIT_PLEDITOR