KiCad PCB EDA Suite
ws_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-2019 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <ws_proxy_view_item.h>
26 #include <ws_draw_item.h>
27 #include <ws_data_item.h>
29 #include <painter.h>
31 #include <page_info.h>
32 #include <view/view.h>
33 #include <ws_painter.h>
34 
35 using namespace KIGFX;
36 
37 WS_PROXY_VIEW_ITEM::WS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo,
38  const TITLE_BLOCK* aTitleBlock ) :
39  EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
40  m_mils2IUscalefactor( aMils2IUscalefactor ),
41  m_titleBlock( aTitleBlock ),
42  m_pageInfo( aPageInfo ),
43  m_sheetNumber( 1 ),
44  m_sheetCount( 1 )
45 {
46 }
47 
48 
50 {
51  m_pageInfo = aPageInfo;
52 }
53 
54 
56 {
57  m_titleBlock = aTitleBlock;
58 }
59 
60 
62 {
63  BOX2I bbox;
64 
65  if( m_pageInfo != NULL )
66  {
67  bbox.SetOrigin( VECTOR2I( 0, 0 ) );
70  }
71  else
72  {
73  bbox.SetMaximum();
74  }
75 
76  return bbox;
77 }
78 
79 
80 void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
81 {
82  auto gal = aView->GetGAL();
83  auto settings = aView->GetPainter()->GetSettings();
84  wxString fileName( m_fileName.c_str(), wxConvUTF8 );
85  wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
86  WS_DRAW_ITEM_LIST drawList;
87 
88  drawList.SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
89  // Adjust the scaling factor for worksheet items:
90  // worksheet items coordinates and sizes are stored in mils,
91  // and must be scaled to the same units as the caller
92  drawList.SetMilsToIUfactor( m_mils2IUscalefactor );
93  drawList.SetSheetNumber( m_sheetNumber );
94  drawList.SetSheetCount( m_sheetCount );
95  drawList.SetFileName( fileName );
96  drawList.SetSheetName( sheetName );
97 
98  drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock );
99 
100  // Draw the title block normally even if the view is flipped
101  bool flipped = gal->IsFlippedX();
102 
103  if( flipped )
104  {
105  gal->Save();
106  gal->Translate( VECTOR2D( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor, 0 ) );
107  gal->Scale( VECTOR2D( -1.0, 1.0 ) );
108  }
109 
110  WS_PAINTER ws_painter( gal );
111  WS_RENDER_SETTINGS* ws_settings =static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
112 
113  ws_settings->SetNormalColor( settings->GetLayerColor( LAYER_WORKSHEET ) );
114  ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
115  ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
116 
117  // Draw all the components that make the page layout
118  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
119  ws_painter.Draw( item, LAYER_WORKSHEET );
120 
121  // Draw gray line that outlines the sheet size
122  if( settings->GetShowPageLimits() )
124 
125  if( flipped )
126  gal->Restore();
127 }
128 
129 
130 void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
131 {
132  aCount = 1;
133  aLayers[0] = LAYER_WORKSHEET;
134 }
135 
136 
Class WS_RENDER_SETTINGS Stores page-layout-specific render settings.
Definition: ws_painter.h:46
void SetNormalColor(const COLOR4D &aColor)
Definition: ws_painter.h:65
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:425
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
const TITLE_BLOCK * m_titleBlock
Title block that contains properties of the title block displayed in the worksheet.
int GetHeightMils() const
Definition: page_info.h:140
void SetTitleBlock(const TITLE_BLOCK *aTitleBlock)
Function SetTitleBlock() Changes the TITLE_BLOCK object used to draw the worksheet.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
the 3d code uses this value
Definition: typeinfo.h:80
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
std::string m_sheetName
Sheet name displayed in the title block.
std::string m_fileName
File name displayed in the title block.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
WS_PROXY_VIEW_ITEM(int aScaleFactor, const PAGE_INFO *aPageInfo, const TITLE_BLOCK *aTitleBlock)
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:363
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
void SetMaximum()
Definition: box2.h:71
int m_sheetCount
Sheets count number displayed in the title block.
Class WS_PAINTER Contains methods for drawing worksheet items.
Definition: ws_painter.h:95
void ViewDraw(int aLayer, VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:223
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Board layer functions and definitions.
int m_mils2IUscalefactor
the factor between mils (units used in worksheet and internal units) it is the value IU_PER_MILS used...
void SetOrigin(const Vec &pos)
Definition: box2.h:208
currently selected items overlay
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
void SetSelectedColor(const COLOR4D &aColor)
Definition: ws_painter.h:66
const PAGE_INFO * m_pageInfo
Worksheet page information.
Class VIEW.
Definition: view.h:61
void SetBrightenedColor(const COLOR4D &aColor)
Definition: ws_painter.h:67
void SetPageInfo(const PAGE_INFO *aPageInfo)
Function SetPageInfo() Changes the PAGE_INFO object used to draw the worksheet.
int m_sheetNumber
Sheet number displayed in the title block.
virtual bool Draw(const VIEW_ITEM *, int) override
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
Definition: ws_painter.cpp:244
virtual RENDER_SETTINGS * GetSettings() override
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Definition: ws_painter.h:114
int GetWidthMils() const
Definition: page_info.h:137