KiCad PCB EDA Suite
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-2022 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>
32#include <project.h>
33#include <view/view.h>
34
35using namespace KIGFX;
36
37DS_PROXY_VIEW_ITEM::DS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo,
38 const PROJECT* aProject, const TITLE_BLOCK* aTitleBlock,
39 const std::map<wxString, wxString>* aProperties ) :
40 EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
41 m_mils2IUscalefactor( aMils2IUscalefactor ),
42 m_titleBlock( aTitleBlock ),
43 m_pageInfo( aPageInfo ),
44 m_pageNumber( "1" ),
45 m_sheetCount( 1 ),
46 m_isFirstPage( false ),
47 m_project( aProject ),
48 m_properties( aProperties ),
49 m_colorLayer( LAYER_DRAWINGSHEET ),
50 m_pageBorderColorLayer( LAYER_PAGE_LIMITS )
51{
52}
53
54
56{
57 BOX2I bbox;
58
59 if( m_pageInfo != NULL )
60 {
61 bbox.SetOrigin( VECTOR2I( 0, 0 ) );
64 }
65 else
66 {
67 bbox.SetMaximum();
68 }
69
70 return bbox;
71}
72
73
75 const std::map<wxString, wxString>* aProperties,
76 DS_DRAW_ITEM_LIST* aDrawList ) const
77{
78 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
79 wxString fileName( m_fileName.c_str(), wxConvUTF8 );
80 wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
81 wxString sheetPath( m_sheetPath.c_str(), wxConvUTF8 );
82
83 aDrawList->SetDefaultPenSize( (int) settings->GetDrawingSheetLineWidth() );
84 // Adjust the scaling factor: drawing sheet item coordinates and sizes are stored in mils,
85 // and must be scaled to the same units as the caller
87 aDrawList->SetIsFirstPage( m_isFirstPage );
88 aDrawList->SetPageNumber( m_pageNumber );
89 aDrawList->SetSheetCount( m_sheetCount );
90 aDrawList->SetFileName( fileName );
91 aDrawList->SetSheetName( sheetName );
92 aDrawList->SetSheetPath( sheetPath );
93 aDrawList->SetSheetLayer( settings->GetLayerName() );
94 aDrawList->SetProject( m_project );
95 aDrawList->SetProperties( aProperties );
96
98}
99
100
101void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
102{
103 GAL* gal = aView->GetGAL();
104 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
105 DS_DRAW_ITEM_LIST drawList;
106
107 buildDrawList( aView, m_properties, &drawList );
108
109 // Draw the title block normally even if the view is flipped
110 bool flipped = gal->IsFlippedX();
111
112 if( flipped )
113 {
114 gal->Save();
116 gal->Scale( VECTOR2D( -1.0, 1.0 ) );
117 }
118
119 DS_PAINTER ws_painter( gal );
120 auto ws_settings = static_cast<DS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
121
122 ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
123 ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
124 ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
125 ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
126 ws_settings->SetDefaultFont( settings->GetDefaultFont() );
127
128 // Draw all the components that make the drawing sheet
129 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
130 ws_painter.Draw( item, LAYER_DRAWINGSHEET );
131
132 // Draw gray line that outlines the sheet size
133 if( settings->GetShowPageLimits() )
135
136 if( flipped )
137 gal->Restore();
138}
139
140
141void DS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
142{
143 aCount = 1;
144 aLayers[0] = LAYER_DRAWINGSHEET;
145}
146
147
149{
150 int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
151 DS_DRAW_ITEM_LIST drawList;
152
153 buildDrawList( aView, m_properties, &drawList );
154
155 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
156 {
157 if( item->HitTest( aPosition, accuracy ) )
158 return true;
159 }
160
161 return false;
162}
void SetOrigin(const Vec &pos)
Definition: box2.h:202
void SetMaximum()
Definition: box2.h:63
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:255
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:385
DS_DRAW_ITEM_BASE * GetFirst()
Definition: ds_draw_item.h:485
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:439
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:429
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:446
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:434
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:467
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:419
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:444
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:472
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:462
DS_DRAW_ITEM_BASE * GetNext()
Definition: ds_draw_item.h:495
void SetMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ds_draw_item.h:452
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:409
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 std::map< wxString, wxString > * m_properties
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const VECTOR2I &aPosition)
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
int m_mils2IUscalefactor
the factor between mils (units used in drawing sheet and internal units) it is the value IU_PER_MILS ...
void buildDrawList(KIGFX::VIEW *aView, const std::map< wxString, wxString > *aProperties, DS_DRAW_ITEM_LIST *aDrawList) const
DS_PROXY_VIEW_ITEM(int aScaleFactor, const PAGE_INFO *aPageInfo, const PROJECT *aProject, const TITLE_BLOCK *aTitleBlock, const std::map< wxString, wxString > *aProperties)
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:85
Methods for painting drawing sheet items.
Definition: ds_painter.h:98
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ds_painter.cpp:338
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:192
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:69
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
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:445
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
int GetHeightMils() const
Definition: page_info.h:133
int GetWidthMils() const
Definition: page_info.h:130
Container for project specific data.
Definition: project.h:63
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:249
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:217
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:219
@ LAYER_BRIGHTENED
Definition: layer_ids.h:379
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618