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
51  // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to
52  // very different internal units.
53  // So we have to use a smaller value.
54  // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin
55  // around the worksheet.
56  double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
57  m_boundary.SetOrigin( -max_size/4, -max_size/4 );
58  m_boundary.SetSize( max_size, max_size );
59 }
60 
61 
63 {
64 }
65 
66 
68 {
69  Clear();
70  m_worksheet.reset();
71  m_preview.reset();
72 }
73 
74 
75 void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
76 {
77  VIEW::SetScale( aScale, aAnchor );
78 
79  //Redraw selection halos since their width is dependent on zoom
80  if( m_frame )
82 }
83 
84 
86 {
87  const PAGE_INFO& page_info = aScreen->GetPageSettings();
88  double max_size_x = page_info.GetWidthIU() * 3.0;
89  double max_size_y = page_info.GetHeightIU() * 3.0;
90  m_boundary.SetOrigin( -max_size_x/4, -max_size_y/4 );
91  m_boundary.SetSize( max_size_x, max_size_y );
92 }
93 
94 
96 {
97  for( auto item : aScreen->Items() )
98  Add( item );
99 
100  m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
101  &aScreen->GetPageSettings(),
102  &aScreen->Schematic()->Prj(),
103  &aScreen->GetTitleBlock() ) );
104  m_worksheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
105  m_worksheet->SetSheetCount( aScreen->GetPageCount() );
106  m_worksheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
107  m_worksheet->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
108  m_worksheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_GRID );
109  m_worksheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
110 
111  if( m_frame && m_frame->IsType( FRAME_SCH ) )
112  m_worksheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
113  else
114  m_worksheet->SetSheetName( "" );
115 
116  ResizeSheetWorkingArea( aScreen );
117 
118  Add( m_worksheet.get() );
119 
120  InitPreview();
121 }
122 
123 
125 {
126  DisplaySheet( aSheet->GetScreen() );
127 }
128 
129 
131 {
132  Clear();
133 
134  if( !aPart )
135  return;
136 
137  std::shared_ptr< LIB_PART > parent;
138  LIB_PART* drawnPart = aPart;
139 
140  // Draw the mandatory fields for aliases and parent symbols.
141  for( auto& item : aPart->GetDrawItems() )
142  {
143  if( item.Type() != LIB_FIELD_T )
144  continue;
145 
146  LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
147 
148  wxCHECK2( field, continue );
149 
150  if( field->GetText().IsEmpty() )
151  continue;
152 
153  Add( &item );
154  }
155 
156  // Draw the parent items if the symbol is inherited from another symbol.
157  if( aPart->IsAlias() )
158  {
159  parent = aPart->GetParent().lock();
160 
161  wxCHECK( parent, /* void */ );
162 
163  drawnPart = parent.get();
164  }
165 
166  for( auto& item : drawnPart->GetDrawItems() )
167  {
168  // Don't show parent symbol fields. Users may be confused by shown fields that can not
169  // be edited.
170  if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
171  continue;
172 
173  Add( &item );
174  }
175 
176  InitPreview();
177 }
178 
179 
181 {
182  for( auto item : *m_allItems )
183  Hide( item, false );
184 }
185 
186 
188 {
189  // SetVisible( m_worksheet.get(), false );
190 }
191 
192 
193 }; // namespace KIGFX
void RefreshSelection()
Mark selected items for refresh.
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1480
const wxString & GetFileName() const
Definition: sch_screen.h:186
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:180
void DisplayComponent(LIB_PART *aPart)
Definition: sch_view.cpp:130
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:715
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
void ResizeSheetWorkingArea(SCH_SCREEN *aScreen)
Definition: sch_view.cpp:85
void Cleanup()
Definition: sch_view.cpp:67
Field object used in symbol libraries.
Definition: lib_field.h:59
int GetVirtualPageNumber() const
Definition: base_screen.h:143
void InitPreview()
Definition: view.cpp:1547
int GetPageCount() const
Definition: base_screen.h:140
void DisplaySheet(SCH_SHEET *aSheet)
Definition: sch_view.cpp:124
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:191
void SetSize(const Vec &size)
Definition: box2.h:212
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:287
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:181
WX_VIEW_CONTROLS class definition.
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:807
const wxString & GetPageNumber() const
Definition: base_screen.cpp:79
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
void HideWorksheet()
Definition: sch_view.cpp:187
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1089
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
PART_REF & GetParent()
Define a library symbol object.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
std::unique_ptr< WS_PROXY_VIEW_ITEM > m_worksheet
Definition: sch_view.h:104
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:75
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:559
Board layer functions and definitions.
bool IsType(FRAME_T aType) const
BOX2D m_boundary
View boundaries.
Definition: view.h:819
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:89
EE_RTREE & Items()
Definition: sch_screen.h:159
bool IsAlias() const
void SetOrigin(const Vec &pos)
Definition: box2.h:210
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:79
#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)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
VIEW.
Definition: view.h:63
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
virtual wxString GetScreenDesc() const