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 
25 #include <ws_proxy_view_item.h>
26 #include <ws_draw_item.h>
27 #include <ws_data_item.h>
29 #include <page_info.h>
30 #include <view/view.h>
31 #include <ws_painter.h>
32 
33 using namespace KIGFX;
34 
35 WS_PROXY_VIEW_ITEM::WS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo,
36  const PROJECT* aProject, const TITLE_BLOCK* aTitleBlock ) :
37  EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
38  m_mils2IUscalefactor( aMils2IUscalefactor ),
39  m_titleBlock( aTitleBlock ),
40  m_pageInfo( aPageInfo ),
41  m_sheetNumber( 1 ),
42  m_sheetCount( 1 ),
43  m_project( aProject ),
44  m_colorLayer( LAYER_WORKSHEET ),
45  m_pageBorderColorLayer( LAYER_GRID )
46 {
47 }
48 
49 
51 {
52  BOX2I bbox;
53 
54  if( m_pageInfo != NULL )
55  {
56  bbox.SetOrigin( VECTOR2I( 0, 0 ) );
59  }
60  else
61  {
62  bbox.SetMaximum();
63  }
64 
65  return bbox;
66 }
67 
68 
70 {
71  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
72  wxString fileName( m_fileName.c_str(), wxConvUTF8 );
73  wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
74 
75  aDrawList->SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
76  // Adjust the scaling factor for worksheet items:
77  // worksheet items coordinates and sizes are stored in mils,
78  // and must be scaled to the same units as the caller
80  aDrawList->SetSheetNumber( m_sheetNumber );
81  aDrawList->SetSheetCount( m_sheetCount );
82  aDrawList->SetFileName( fileName );
83  aDrawList->SetSheetName( sheetName );
84  aDrawList->SetProject( m_project );
85 
87 }
88 
89 
90 void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
91 {
92  GAL* gal = aView->GetGAL();
93  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
94  WS_DRAW_ITEM_LIST drawList;
95 
96  buildDrawList( aView, &drawList );
97 
98  // Draw the title block normally even if the view is flipped
99  bool flipped = gal->IsFlippedX();
100 
101  if( flipped )
102  {
103  gal->Save();
105  gal->Scale( VECTOR2D( -1.0, 1.0 ) );
106  }
107 
108  WS_PAINTER ws_painter( gal );
109  auto ws_settings = static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
110 
111  ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
112  ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
113  ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
114  ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
115 
116  // Draw all the components that make the page layout
117  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
118  ws_painter.Draw( item, LAYER_WORKSHEET );
119 
120  // Draw gray line that outlines the sheet size
121  if( settings->GetShowPageLimits() )
123 
124  if( flipped )
125  gal->Restore();
126 }
127 
128 
129 void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
130 {
131  aCount = 1;
132  aLayers[0] = LAYER_WORKSHEET;
133 }
134 
135 
137 {
138  int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
139  WS_DRAW_ITEM_LIST drawList;
140 
141  buildDrawList( aView, &drawList );
142 
143  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
144  {
145  if( item->HitTest( aPosition, accuracy ) )
146  return true;
147  }
148 
149  return false;
150 }
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:429
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:408
PROJECT holds project specific data.
Definition: project.h:61
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:479
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:480
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:416
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:180
WS_DRAW_ITEM_BASE * GetFirst()
Definition: ws_draw_item.h:470
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:199
bool HitTestWorksheetItems(VIEW *aView, const wxPoint &aPosition)
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)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:355
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:454
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)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:436
WS_PAINTER Contains methods for drawing worksheet items.
Definition: ws_painter.h:100
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...
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
Definition: ws_draw_item.h:445
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: base_struct.h:159
virtual void Save()
Save the context.
VIEW.
Definition: view.h:61
void SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:393
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:218
virtual RENDER_SETTINGS * GetSettings() override
Definition: ws_painter.h:119
int GetWidthMils() const
Definition: page_info.h:138
Class GAL is the abstract interface for drawing on a 2D-surface.