KiCad PCB EDA Suite
sch_view.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-2018 CERN
5  * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <core/typeinfo.h>
29 #include <memory>
30 #include <view/view.h>
31 #include <view/view_group.h>
32 #include <view/view_rtree.h>
33 #include <view/wx_view_controls.h>
36 #include <sch_screen.h>
37 #include <schematic.h>
38 #include <sch_base_frame.h>
39 
40 #include "sch_view.h"
41 
42 
43 namespace KIGFX {
44 
45 
46 SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
47  VIEW( aIsDynamic )
48 {
49  m_frame = aFrame;
50  // Set m_boundary to define the max working area size. The default value is acceptable for
51  // Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
52  // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
53  double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
54  m_boundary.SetOrigin( -max_size/4, -max_size/4 );
55  m_boundary.SetSize( max_size, max_size );
56 }
57 
58 
60 {
61 }
62 
63 
65 {
66  Clear();
67  m_drawingSheet.reset();
68  m_preview.reset();
69 }
70 
71 
72 void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
73 {
74  VIEW::SetScale( aScale, aAnchor );
75 
76  //Redraw selection halos since their width is dependent on zoom
77  if( m_frame )
79 }
80 
81 
83 {
84  const PAGE_INFO& page_info = aScreen->GetPageSettings();
85  double max_size_x = page_info.GetWidthIU() * 3.0;
86  double max_size_y = page_info.GetHeightIU() * 3.0;
87  m_boundary.SetOrigin( -max_size_x / 4, -max_size_y / 4 );
88  m_boundary.SetSize( max_size_x, max_size_y );
89 }
90 
91 
92 void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
93 {
94  for( SCH_ITEM* item : aScreen->Items() )
95  Add( item );
96 
97  m_drawingSheet.reset( new DS_PROXY_VIEW_ITEM( static_cast<int>( IU_PER_MILS ),
98  &aScreen->GetPageSettings(),
99  &aScreen->Schematic()->Prj(),
100  &aScreen->GetTitleBlock() ) );
101  m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
102  m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
103  m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
105  m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_GRID );
106  m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
107 
108  if( m_frame && m_frame->IsType( FRAME_SCH ) )
109  m_drawingSheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
110  else
111  m_drawingSheet->SetSheetName( "" );
112 
113  ResizeSheetWorkingArea( aScreen );
114 
115  Add( m_drawingSheet.get() );
116 
117  InitPreview();
118 }
119 
120 
122 {
123  Clear();
124 
125  if( !aPart )
126  return;
127 
128  std::shared_ptr< LIB_PART > parent;
129  LIB_PART* drawnPart = aPart;
130 
131  // Draw the mandatory fields for aliases and parent symbols.
132  for( LIB_ITEM& item : aPart->GetDrawItems() )
133  {
134  if( item.Type() != LIB_FIELD_T )
135  continue;
136 
137  LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
138 
139  wxCHECK2( field, continue );
140 
141  if( field->GetText().IsEmpty() )
142  continue;
143 
144  Add( &item );
145  }
146 
147  // Draw the parent items if the symbol is inherited from another symbol.
148  if( aPart->IsAlias() )
149  {
150  parent = aPart->GetParent().lock();
151 
152  wxCHECK( parent, /* void */ );
153 
154  drawnPart = parent.get();
155  }
156 
157  for( LIB_ITEM& item : drawnPart->GetDrawItems() )
158  {
159  // Don't show parent symbol fields. Users may be confused by shown fields that can not
160  // be edited.
161  if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
162  continue;
163 
164  Add( &item );
165  }
166 
167  InitPreview();
168 }
169 
170 
172 {
173  for( auto item : *m_allItems )
174  Hide( item, false );
175 }
176 
177 
179 {
180  // SetVisible( m_drawingSheet.get(), false );
181 }
182 
183 
184 }; // namespace KIGFX
void RefreshSelection()
Mark selected items for refresh.
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1475
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:104
const wxString & GetFileName() const
Definition: sch_screen.h:192
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:171
void DisplayComponent(LIB_PART *aPart)
Definition: sch_view.cpp:121
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:802
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
void Cleanup()
Definition: sch_view.cpp:64
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetVirtualPageNumber() const
Definition: base_screen.h:79
void InitPreview()
Definition: view.cpp:1545
int GetPageCount() const
Definition: base_screen.h:76
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:197
void SetSize(const Vec &size)
Definition: box2.h:212
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:187
WX_VIEW_CONTROLS class definition.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
Definition: view.h:817
const wxString & GetPageNumber() const
Definition: base_screen.cpp:78
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:92
void Clear()
Remove all items from the view.
Definition: view.cpp:1083
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:467
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
PART_REF & GetParent()
Definition: lib_symbol.h:120
Define a library symbol object.
Definition: lib_symbol.h:93
void ResizeSheetWorkingArea(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:82
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:72
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:99
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:553
void HideDrawingSheet()
Definition: sch_view.cpp:178
Board layer functions and definitions.
bool IsType(FRAME_T aType) const
BOX2D m_boundary
Scale lower limit.
Definition: view.h:829
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:87
EE_RTREE & Items()
Definition: sch_screen.h:162
bool IsAlias() const
Definition: lib_symbol.h:168
void SetOrigin(const Vec &pos)
Definition: box2.h:210
#define IU_PER_MILS
Definition: plotter.cpp:137
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:101
SCH_VIEW(bool aIsDynamic, SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:46
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:321
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
virtual wxString GetScreenDesc() const