KiCad PCB EDA Suite
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  * @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 <layer_ids.h>
26 #include <page_info.h>
31 #include <project.h>
32 #include <view/view.h>
33 
34 using namespace KIGFX;
35 
36 DS_PROXY_VIEW_ITEM::DS_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_DRAWINGSHEET ),
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->GetDrawingSheetLineWidth() );
78  // Adjust the scaling factor: drawing sheet item coordinates and sizes are stored in mils,
79  // and must be scaled to the same units as the caller
81  aDrawList->SetIsFirstPage( m_isFirstPage );
82  aDrawList->SetPageNumber( m_pageNumber );
83  aDrawList->SetSheetCount( m_sheetCount );
84  aDrawList->SetFileName( fileName );
85  aDrawList->SetSheetName( sheetName );
86  aDrawList->SetProject( m_project );
87 
89 }
90 
91 
92 void DS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
93 {
94  GAL* gal = aView->GetGAL();
95  RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
96  DS_DRAW_ITEM_LIST drawList;
97 
98  buildDrawList( aView, &drawList );
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();
107  gal->Scale( VECTOR2D( -1.0, 1.0 ) );
108  }
109 
110  DS_PAINTER ws_painter( gal );
111  auto ws_settings = static_cast<DS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
112 
113  ws_settings->SetNormalColor( settings->GetLayerColor( m_colorLayer ) );
114  ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
115  ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
116  ws_settings->SetPageBorderColor( settings->GetLayerColor( m_pageBorderColorLayer ) );
117 
118  // Draw all the components that make the drawing sheet
119  for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
120  ws_painter.Draw( item, LAYER_DRAWINGSHEET );
121 
122  // Draw gray line that outlines the sheet size
123  if( settings->GetShowPageLimits() )
125 
126  if( flipped )
127  gal->Restore();
128 }
129 
130 
131 void DS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
132 {
133  aCount = 1;
134  aLayers[0] = LAYER_DRAWINGSHEET;
135 }
136 
137 
138 bool DS_PROXY_VIEW_ITEM::HitTestDrawingSheetItems( VIEW* aView, const wxPoint& aPosition )
139 {
140  int accuracy = (int) aView->ToWorld( 5.0 ); // five pixels at current zoom
141  DS_DRAW_ITEM_LIST drawList;
142 
143  buildDrawList( aView, &drawList );
144 
145  for( DS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
146  {
147  if( item->HitTest( aPosition, accuracy ) )
148  return true;
149  }
150 
151  return false;
152 }
int m_pageBorderColorLayer
Layer that is used for page border color.
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:463
currently selected items overlay
Definition: layer_ids.h:214
Container for project specific data.
Definition: project.h:62
void SetMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ds_draw_item.h:442
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:191
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
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:450
int GetHeightMils() const
Definition: page_info.h:133
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:436
bool IsFlippedX() const
Return true if flip flag for the X axis is set.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:415
the 3d code uses this value
Definition: typeinfo.h:79
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ds_painter.cpp:315
void ViewGetLayers(int aLayers[], int &aCount) const override
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool GetShowPageLimits() const
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const wxPoint &aPosition)
float GetDrawingSheetLineWidth() const
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
DS_PROXY_VIEW_ITEM(int aScaleFactor, const PAGE_INFO *aPageInfo, const PROJECT *aProject, const TITLE_BLOCK *aTitleBlock)
Base class to handle basic graphic items.
Definition: ds_draw_item.h:58
int m_colorLayer
Layer that is used for drawing sheet color (LAYER_DRAWINGSHEET is always used for visibility)
DS_DRAW_ITEM_BASE * GetNext()
Definition: ds_draw_item.h:494
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
int m_mils2IUscalefactor
the factor between mils (units used in drawing sheet and internal units) it is the value IU_PER_MILS ...
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:455
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
void SetMaximum()
Definition: box2.h:57
void buildDrawList(KIGFX::VIEW *aView, DS_DRAW_ITEM_LIST *aDrawList) const
drawingsheet frame and titleblock
Definition: layer_ids.h:212
const TITLE_BLOCK * m_titleBlock
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:423
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
const PAGE_INFO * m_pageInfo
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:207
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
virtual void Restore()
Restore the context.
const BOX2I ViewBBox() const override
void SetOrigin(const Vec &pos)
Definition: box2.h:193
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:400
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:468
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:376
virtual RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: ds_painter.h:111
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.
Definition: ds_painter.cpp:173
Methods for painting drawing sheet items.
Definition: ds_painter.h:98
virtual void Save()
Save the context.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
DS_DRAW_ITEM_BASE * GetFirst()
Definition: ds_draw_item.h:484
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
int GetWidthMils() const
Definition: page_info.h:130
const PROJECT * m_project
Abstract interface for drawing on a 2D-surface.