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 {
46 }
47 
48 
50 {
51  BOX2I bbox;
52 
53  if( m_pageInfo != NULL )
54  {
55  bbox.SetOrigin( VECTOR2I( 0, 0 ) );
58  }
59  else
60  {
61  bbox.SetMaximum();
62  }
63 
64  return bbox;
65 }
66 
67 
69 {
70  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
71  wxString fileName( m_fileName.c_str(), wxConvUTF8 );
72  wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
73 
74  aDrawList->SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
75  // Adjust the scaling factor for worksheet items:
76  // worksheet items coordinates and sizes are stored in mils,
77  // and must be scaled to the same units as the caller
79  aDrawList->SetSheetNumber( m_sheetNumber );
80  aDrawList->SetSheetCount( m_sheetCount );
81  aDrawList->SetFileName( fileName );
82  aDrawList->SetSheetName( sheetName );
83  aDrawList->SetProject( m_project );
84 
86 }
87 
88 
89 void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
90 {
91  GAL* gal = aView->GetGAL();
92  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
93  WS_DRAW_ITEM_LIST drawList;
94 
95  buildDrawList( aView, &drawList );
96 
97  // Draw the title block normally even if the view is flipped
98  bool flipped = gal->IsFlippedX();
99 
100  if( flipped )
101  {
102  gal->Save();
104  gal->Scale( VECTOR2D( -1.0, 1.0 ) );
105  }
106 
107  WS_PAINTER ws_painter( gal );
108  auto ws_settings = static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
109 
110  ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
111  ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
112  ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
113  ws_settings->SetPageBorderColor( settings->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
114 
115  // Draw all the components that make the page layout
116  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
117  ws_painter.Draw( item, LAYER_WORKSHEET );
118 
119  // Draw gray line that outlines the sheet size
120  if( settings->GetShowPageLimits() )
122 
123  if( flipped )
124  gal->Restore();
125 }
126 
127 
128 void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
129 {
130  aCount = 1;
131  aLayers[0] = LAYER_WORKSHEET;
132 }
133 
134 
136 {
137  int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
138  WS_DRAW_ITEM_LIST drawList;
139 
140  buildDrawList( aView, &drawList );
141 
142  for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
143  {
144  if( item->HitTest( aPosition, accuracy ) )
145  return true;
146  }
147 
148  return false;
149 }
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:426
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ws_draw_item.h:405
PROJECT holds project specific data.
Definition: project.h:59
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:131
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:475
int GetHeightMils() const
Definition: page_info.h:140
bool IsFlippedX() const
Return true if flip flag for the X axis is set.
WS_DRAW_ITEM_BASE * GetNext()
Definition: ws_draw_item.h:477
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:413
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:467
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:400
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
Definition: ws_draw_item.h:451
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:72
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:433
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:224
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:442
float GetWorksheetLineWidth() const
void SetOrigin(const Vec &pos)
Definition: box2.h:209
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:163
virtual void Save()
Save the context.
VIEW.
Definition: view.h:61
void SetProject(const PROJECT *aProject)
Definition: ws_draw_item.h:390
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:263
virtual RENDER_SETTINGS * GetSettings() override
Definition: ws_painter.h:119
int GetWidthMils() const
Definition: page_info.h:137
Class GAL is the abstract interface for drawing on a 2D-surface.