KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ds_proxy_view_item.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) 2013-2020 CERN
5 * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <layer_ids.h>
27#include <page_info.h>
33#include <project.h>
34#include <view/view.h>
35
36using namespace KIGFX;
37
39 const PROJECT* aProject, const TITLE_BLOCK* aTitleBlock,
40 const std::map<wxString, wxString>* aProperties ) :
41 EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
42 m_iuScale( aIuScale ),
43 m_titleBlock( aTitleBlock ),
44 m_pageInfo( aPageInfo ),
45 m_pageNumber( "1" ),
46 m_sheetCount( 1 ),
47 m_isFirstPage( false ),
48 m_project( aProject ),
49 m_properties( aProperties ),
50 m_colorLayer( LAYER_DRAWINGSHEET ),
51 m_pageBorderColorLayer( LAYER_PAGE_LIMITS )
52{
53}
54
55
57{
58 BOX2I bbox;
59
60 if( m_pageInfo )
61 {
62 bbox.SetOrigin( VECTOR2I( 0, 0 ) );
65 }
66 else
67 {
68 bbox.SetMaximum();
69 }
70
71 return bbox;
72}
73
74
76 const std::map<wxString, wxString>* aProperties,
77 DS_DRAW_ITEM_LIST* aDrawList ) const
78{
79 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
80 wxString fileName( m_fileName.c_str(), wxConvUTF8 );
81 wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
82 wxString sheetPath( m_sheetPath.c_str(), wxConvUTF8 );
83
84 aDrawList->SetDefaultPenSize( (int) settings->GetDrawingSheetLineWidth() );
85 aDrawList->SetIsFirstPage( m_isFirstPage );
86 aDrawList->SetPageNumber( m_pageNumber );
87 aDrawList->SetSheetCount( m_sheetCount );
88 aDrawList->SetFileName( fileName );
89 aDrawList->SetSheetName( sheetName );
90 aDrawList->SetSheetPath( sheetPath );
91 aDrawList->SetSheetLayer( settings->GetLayerName() );
92 aDrawList->SetProject( m_project );
93 aDrawList->SetProperties( aProperties );
94
96}
97
98
99void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
100{
101 GAL* gal = aView->GetGAL();
102 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
103 DS_DRAW_ITEM_LIST drawList( m_iuScale );
104
105 buildDrawList( aView, m_properties, &drawList );
106
107 BOX2I viewport = BOX2ISafe( aView->GetViewport() );
108
109 // Draw the title block normally even if the view is flipped
110 bool flipped = gal->IsFlippedX();
111
112 if( flipped )
113 {
114 int pageWidth = m_iuScale.MilsToIU( m_pageInfo->GetWidthMils() );
115
116 gal->Save();
117 gal->Translate( VECTOR2D( pageWidth, 0 ) );
118 gal->Scale( VECTOR2D( -1.0, 1.0 ) );
119
120 int right = pageWidth - viewport.GetLeft();
121 int left = right - viewport.GetWidth();
122 viewport.SetOrigin( left, viewport.GetTop() );
123 }
124
125 DS_PAINTER ws_painter( gal );
126 auto ws_settings = static_cast<DS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
127
128 ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
129 ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
130 ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
131 ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
132 ws_settings->SetDefaultFont( settings->GetDefaultFont() );
133
134 // Draw all the components that make the drawing sheet
135 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
136 {
137 if( viewport.Intersects( item->GetApproxBBox() ) )
138 ws_painter.Draw( item, LAYER_DRAWINGSHEET );
139 }
140
141 // Draw gray line that outlines the sheet size
142 if( settings->GetShowPageLimits() )
144
145 if( flipped )
146 gal->Restore();
147}
148
149
150void DS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
151{
152 aCount = 1;
153 aLayers[0] = LAYER_DRAWINGSHEET;
154}
155
156
158{
159 int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
160 DS_DRAW_ITEM_LIST drawList( m_iuScale );
161
162 buildDrawList( aView, m_properties, &drawList );
163
164 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
165 {
166 if( item->HitTest( aPosition, accuracy ) )
167 return true;
168 }
169
170 return false;
171}
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
Definition: box2.h:929
constexpr void SetMaximum()
Definition: box2.h:80
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr coord_type GetLeft() const
Definition: box2.h:228
constexpr void SetEnd(coord_type x, coord_type y)
Definition: box2.h:297
constexpr coord_type GetTop() const
Definition: box2.h:229
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
Base class to handle basic graphic items.
Definition: ds_draw_item.h:59
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
DS_DRAW_ITEM_BASE * GetFirst()
Definition: ds_draw_item.h:511
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetSheetPath(const wxString &aSheetPath)
Set the sheet path to draw/plot.
Definition: ds_draw_item.h:454
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:444
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:461
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:449
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:493
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:434
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:459
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:498
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:488
DS_DRAW_ITEM_BASE * GetNext()
Definition: ds_draw_item.h:521
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:424
const PROJECT * m_project
int m_colorLayer
Layer that is used for drawing sheet color (LAYER_DRAWINGSHEET is always used for visibility)
const BOX2I ViewBBox() const override
const TITLE_BLOCK * m_titleBlock
const EDA_IU_SCALE & m_iuScale
const std::map< wxString, wxString > * m_properties
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const VECTOR2I &aPosition)
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
DS_PROXY_VIEW_ITEM(const EDA_IU_SCALE &aIuScale, const PAGE_INFO *aPageInfo, const PROJECT *aProject, const TITLE_BLOCK *aTitleBlock, const std::map< wxString, wxString > *aProperties)
void buildDrawList(KIGFX::VIEW *aView, const std::map< wxString, wxString > *aProperties, DS_DRAW_ITEM_LIST *aDrawList) const
const PAGE_INFO * m_pageInfo
void ViewGetLayers(int aLayers[], int &aCount) const override
int m_pageBorderColorLayer
Layer that is used for page border color.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
Methods for painting drawing sheet items.
Definition: ds_painter.h:98
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ds_painter.cpp:371
virtual RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: ds_painter.h:110
virtual bool Draw(const VIEW_ITEM *, int) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
Definition: ds_painter.cpp:217
Store page-layout-specific render settings.
Definition: ds_painter.h:46
void SetNormalColor(const COLOR4D &aColor)
Definition: ds_painter.h:66
Abstract interface for drawing on a 2D-surface.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void Restore()
Restore the context.
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void Save()
Save the context.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
float GetDrawingSheetLineWidth() const
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
const wxString & GetLayerName() const
virtual bool GetShowPageLimits() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:547
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:203
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:484
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:221
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
double GetHeightMils() const
Definition: page_info.h:141
double GetWidthMils() const
Definition: page_info.h:136
Container for project specific data.
Definition: project.h:64
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
@ LAYER_PAGE_LIMITS
color for drawing the page extents (visibility stored in PCBNEW_SETTINGS::m_ShowPageLimits)
Definition: layer_ids.h:253
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:218
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:220
@ LAYER_BRIGHTENED
Definition: layer_ids.h:394
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690