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 The 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 ),
52{
53}
54
55
57{
58 BOX2I bbox;
59
60 if( m_pageInfo )
61 {
62 bbox.SetOrigin( VECTOR2I( 0, 0 ) );
63 bbox.SetEnd( VECTOR2I( m_iuScale.MilsToIU( m_pageInfo->GetWidthMils() ),
64 m_iuScale.MilsToIU( m_pageInfo->GetHeightMils() ) ) );
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 wxString variantName( m_variantName.c_str(), wxConvUTF8 );
84 wxString variantDesc( m_variantDesc.c_str(), wxConvUTF8 );
85
86 aDrawList->SetDefaultPenSize( (int) settings->GetDrawingSheetLineWidth() );
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->SetVariantName( variantName );
95 aDrawList->SetVariantDesc( variantDesc );
96 aDrawList->SetProject( m_project );
97 aDrawList->SetProperties( aProperties );
98
100}
101
102
103void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
104{
105 GAL* gal = aView->GetGAL();
106 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
107 DS_DRAW_ITEM_LIST drawList( m_iuScale );
108
109 buildDrawList( aView, m_properties, &drawList );
110
111 BOX2I viewport = BOX2ISafe( aView->GetViewport() );
112
113 // Draw the title block normally even if the view is flipped
114 bool flipped = gal->IsFlippedX();
115
116 if( flipped )
117 {
118 int pageWidth = m_iuScale.MilsToIU( m_pageInfo->GetWidthMils() );
119
120 gal->Save();
121 gal->Translate( VECTOR2D( pageWidth, 0 ) );
122 gal->Scale( VECTOR2D( -1.0, 1.0 ) );
123
124 int right = pageWidth - viewport.GetLeft();
125 int left = right - viewport.GetWidth();
126 viewport.SetOrigin( left, viewport.GetTop() );
127 }
128
129 DS_PAINTER ws_painter( gal );
130 auto ws_settings = static_cast<DS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
131
132 ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
133 ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
134 ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
135 ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
136 ws_settings->SetDefaultFont( settings->GetDefaultFont() );
137
138 // Draw all the components that make the drawing sheet
139 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
140 {
141 if( viewport.Intersects( item->GetApproxBBox() ) )
142 ws_painter.Draw( item, LAYER_DRAWINGSHEET );
143 }
144
145 // Draw gray line that outlines the sheet size
146 if( settings->GetShowPageLimits() )
147 ws_painter.DrawBorder( m_pageInfo, m_iuScale.IU_PER_MILS );
148
149 if( flipped )
150 gal->Restore();
151}
152
153
154std::vector<int> DS_PROXY_VIEW_ITEM::ViewGetLayers() const
155{
156 std::vector<int> layer{ LAYER_DRAWINGSHEET };
157 return layer;
158}
159
160
162{
163 int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
164 DS_DRAW_ITEM_LIST drawList( m_iuScale );
165
166 buildDrawList( aView, m_properties, &drawList );
167
168 for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
169 {
170 if( item->HitTest( aPosition, accuracy ) )
171 return true;
172 }
173
174 return false;
175}
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
Definition box2.h:929
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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.
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
DS_DRAW_ITEM_BASE * GetFirst()
void SetVariantName(const wxString &aVariant)
Set the current variant name and description to draw/plot.
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.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetDefaultPenSize(int aPenSize)
void SetVariantDesc(const wxString &aDesc)
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
DS_DRAW_ITEM_BASE * GetNext()
void SetProject(const PROJECT *aProject)
const PROJECT * m_project
std::vector< int > ViewGetLayers() const override
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
int m_pageBorderColorLayer
Layer that is used for page border color.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
Methods for painting drawing sheet items.
Definition ds_painter.h:98
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
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.
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
friend class VIEW
Definition view_item.h:205
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition view.cpp:598
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:211
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:535
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:229
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
Container for project specific data.
Definition project.h:66
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:329
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:278
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:280
@ LAYER_BRIGHTENED
Definition layer_ids.h:493
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
const int accuracy
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:76
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
VECTOR2< double > VECTOR2D
Definition vector2d.h:686