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-2020 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 
26 #include <page_info.h>
30 #include <page_layout/ws_painter.h>
31 #include <project.h>
32 #include <view/view.h>
33 
34 using namespace KIGFX;
35 
36 WS_PROXY_VIEW_ITEM::WS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo,
37  const PROJECT* aProject, const TITLE_BLOCK* aTitleBlock ) :
38  EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
39  m_mils2IUscalefactor( aMils2IUscalefactor ),
40  m_titleBlock( aTitleBlock ),
41  m_pageInfo( aPageInfo ),
42  m_pageNumber( "1" ),
43  m_sheetCount( 1 ),
44  m_isFirstPage( false ),
45  m_project( aProject ),
46  m_colorLayer( LAYER_WORKSHEET ),
47  m_pageBorderColorLayer( LAYER_GRID )
48 {
49 }
50 
51 
53 {
54  BOX2I bbox;
55 
56  if( m_pageInfo != NULL )
57  {
58  bbox.SetOrigin( VECTOR2I( 0, 0 ) );
61  }
62  else
63  {
64  bbox.SetMaximum();
65  }
66 
67  return bbox;
68 }
69 
70 
72 {
73  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
74  wxString fileName( m_fileName.c_str(), wxConvUTF8 );
75  wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
76 
77  aDrawList->SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
78  // Adjust the scaling factor for worksheet items:
79  // worksheet items coordinates and sizes are stored in mils,
80  // and must be scaled to the same units as the caller
82  aDrawList->SetIsFirstPage( m_isFirstPage );
83  aDrawList->SetPageNumber( m_pageNumber );
84  aDrawList->SetSheetCount( m_sheetCount );
85  aDrawList->SetFileName( fileName );
86  aDrawList->SetSheetName( sheetName );
87  aDrawList->SetProject( m_project );
88 
90 }
91 
92 
93 void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
94 {
95  GAL* gal = aView->GetGAL();
96  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
97  WS_DRAW_ITEM_LIST drawList;
98 
99  buildDrawList( aView, &drawList );
100 
101  // Draw the title block normally even if the view is flipped
102  bool flipped = gal->IsFlippedX();
103 
104  if( flipped )
105  {
106  gal->Save();
108  gal->Scale( VECTOR2D( -1.0, 1.0 ) );
109  }
110 
111  WS_PAINTER ws_painter( gal );
112  auto ws_settings = static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
113 
114  ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
115  ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
116  ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
117  ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
118 
119  // Draw all the components that make the page layout
120  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
121  ws_painter.Draw( item, LAYER_WORKSHEET );
122 
123  // Draw gray line that outlines the sheet size
124  if( settings->GetShowPageLimits() )
126 
127  if( flipped )
128  gal->Restore();
129 }
130 
131 
132 void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
133 {
134  aCount = 1;
135  aLayers[0] = LAYER_WORKSHEET;
136 }
137 
138 
139 bool WS_PROXY_VIEW_ITEM::HitTestWorksheetItems( VIEW* aView, const wxPoint& aPosition )
140 {
141  int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
142  WS_DRAW_ITEM_LIST drawList;
143 
144  buildDrawList( aView, &drawList );
145 
146  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
147  {
148  if( item->HitTest( aPosition, accuracy ) )
149  return true;
150  }
151 
152  return false;
153 }
WS_PROXY_VIEW_ITEM(int aScaleFactor, const PAGE_INFO *aPageInfo, const PROJECT *aProject, const TITLE_BLOCK *aTitleBlock)
void SetDefaultPenSize(int aPenSize)
Definition: ws_draw_item.h:437
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:416
PROJECT holds project specific data.
Definition: project.h:63
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
const TITLE_BLOCK * m_titleBlock
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:456
int GetHeightMils() const
Definition: page_info.h:141
bool IsFlippedX() const
Return true if flip flag for the X axis is set.
WS_DRAW_ITEM_BASE * GetNext()
Definition: ws_draw_item.h:490
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
void buildDrawList(VIEW *aView, WS_DRAW_ITEM_LIST *aDrawList) const
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ws_draw_item.h:424
int m_pageBorderColorLayer
Layer that is used for page border color.
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
bool GetShowPageLimits() const
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:182
WS_DRAW_ITEM_BASE * GetFirst()
Definition: ws_draw_item.h:480
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ws_draw_item.h:451
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
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:201
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ws_draw_item.h:359
bool HitTestWorksheetItems(VIEW *aView, const wxPoint &aPosition)
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ws_draw_item.h:459
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
#define NULL
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the page layout.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:360
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:464
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void SetMaximum()
Definition: box2.h:73
void SetMilsToIUfactor(double aScale)
Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:443
Methods for drawing worksheet items.
Definition: ws_painter.h:98
void ViewDraw(int aLayer, VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:225
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
virtual void Restore()
Restore the context.
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...
float GetWorksheetLineWidth() const
void SetOrigin(const Vec &pos)
Definition: box2.h:210
currently selected items overlay
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
Helper classes to handle basic graphic items used to draw/plot title blocks and frame references segm...
Definition: ws_draw_item.h:56
virtual void Save()
Save the context.
VIEW.
Definition: view.h:63
void SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:401
int m_colorLayer
Layer that is used for worksheet color (LAYER_WORKSHEET is always used for visibility)
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
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:220
virtual RENDER_SETTINGS * GetSettings() override
Definition: ws_painter.h:117
int GetWidthMils() const
Definition: page_info.h:138
Class GAL is the abstract interface for drawing on a 2D-surface.