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-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
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_rtree.h>
34#include <layer_ids.h>
35#include <sch_screen.h>
36#include <schematic.h>
37#include <sch_base_frame.h>
38#include <sch_edit_frame.h>
39
40#include "sch_view.h"
41
42
43namespace KIGFX {
44
45
46SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
47 VIEW( aIsDynamic )
48{
49 m_frame = aFrame;
50
51 // Set m_boundary to define the max working area size. The default value is acceptable for
52 // Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
53 // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
54 double max_size = schIUScale.MilsToIU( MAX_PAGE_SIZE_EESCHEMA_MILS ) * 3.0;
55 m_boundary.SetOrigin( -max_size/4, -max_size/4 );
56 m_boundary.SetSize( max_size, max_size );
57}
58
59
61{
62}
63
64
66{
67 Clear();
68 m_drawingSheet.reset();
69 m_preview.reset();
70}
71
72
73void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
74{
75 VIEW::SetScale( aScale, aAnchor );
76
77 // Redraw items whose rendering is dependent on zoom
78 if( m_frame )
80}
81
82
84{
85 const PAGE_INFO& page_info = aScreen->GetPageSettings();
86 double max_size_x = page_info.GetWidthIU( schIUScale.IU_PER_MILS ) * 3.0;
87 double max_size_y = page_info.GetHeightIU( schIUScale.IU_PER_MILS ) * 3.0;
88 m_boundary.SetOrigin( -max_size_x / 4, -max_size_y / 4 );
89 m_boundary.SetSize( max_size_x, max_size_y );
90}
91
92
93void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
94{
95 for( SCH_ITEM* item : aScreen->Items() )
96 Add( item );
97
98 m_drawingSheet.reset( new DS_PROXY_VIEW_ITEM( static_cast<int>( schIUScale.IU_PER_MILS ),
99 &aScreen->GetPageSettings(),
100 &aScreen->Schematic()->Prj(),
101 &aScreen->GetTitleBlock(),
102 aScreen->Schematic()->GetProperties() ) );
103 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
104 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
105 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
107 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
108 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
109
110 if( m_frame && m_frame->IsType( FRAME_SCH ) )
111 {
112 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
113
114 wxCHECK( editFrame, /* void */ );
115
116 wxString sheetName = editFrame->GetCurrentSheet().Last()->GetName();
117 wxString sheetPath = editFrame->GetCurrentSheet().PathHumanReadable();
118 m_drawingSheet->SetSheetName( TO_UTF8( sheetName ) );
119 m_drawingSheet->SetSheetPath( TO_UTF8( sheetPath ) );
120 }
121 else
122 {
123 m_drawingSheet->SetSheetName( "" );
124 m_drawingSheet->SetSheetPath( "" );
125 }
126
127 ResizeSheetWorkingArea( aScreen );
128
129 Add( m_drawingSheet.get() );
130
131 InitPreview();
132}
133
134
136{
137 Clear();
138
139 if( !aSymbol )
140 return;
141
142 std::shared_ptr< LIB_SYMBOL > parent;
143 LIB_SYMBOL* drawnSymbol = aSymbol;
144
145 // Draw the mandatory fields for aliases and parent symbols.
146 for( LIB_ITEM& item : aSymbol->GetDrawItems() )
147 {
148 if( item.Type() != LIB_FIELD_T )
149 continue;
150
151 LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
152
153 wxCHECK2( field, continue );
154
155 if( field->GetText().IsEmpty() )
156 continue;
157
158 Add( &item );
159 }
160
161 // Draw the parent items if the symbol is inherited from another symbol.
162 if( aSymbol->IsAlias() )
163 {
164 parent = aSymbol->GetParent().lock();
165
166 wxCHECK( parent, /* void */ );
167
168 drawnSymbol = parent.get();
169 }
170
171 for( LIB_ITEM& item : drawnSymbol->GetDrawItems() )
172 {
173 // Don't show parent symbol fields. Users may be confused by shown fields that can not
174 // be edited.
175 if( aSymbol->IsAlias() && item.Type() == LIB_FIELD_T )
176 continue;
177
178 Add( &item );
179 }
180
181 InitPreview();
182}
183
184
186{
187 for( VIEW_ITEM* item : *m_allItems )
188 Hide( item, false );
189}
190
191
193{
194 // SetVisible( m_drawingSheet.get(), false );
195}
196
197
198}; // namespace KIGFX
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
int GetPageCount() const
Definition: base_screen.h:72
int GetVirtualPageNumber() const
Definition: base_screen.h:75
const wxString & GetPageNumber() const
Definition: base_screen.cpp:71
void SetOrigin(const Vec &pos)
Definition: box2.h:202
void SetSize(const Vec &size)
Definition: box2.h:213
bool IsType(FRAME_T aType) const
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:106
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition: sch_view.cpp:135
void ResizeSheetWorkingArea(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:83
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:93
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:73
void HideDrawingSheet()
Definition: sch_view.cpp:192
void Cleanup()
Definition: sch_view.cpp:65
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:103
SCH_VIEW(bool aIsDynamic, SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:46
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:185
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:548
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
Definition: view.h:847
void Clear()
Remove all items from the view.
Definition: view.cpp:1096
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1545
void InitPreview()
Definition: view.cpp:1623
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:834
BOX2D m_boundary
Definition: view.h:856
Field object used in symbol libraries.
Definition: lib_field.h:60
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
Define a library symbol object.
Definition: lib_symbol.h:98
bool IsAlias() const
Definition: lib_symbol.h:183
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:519
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:125
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition: page_info.h:153
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition: page_info.h:144
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:79
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:76
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
void RefreshZoomDependentItems()
Mark selected items for refresh.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:92
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
wxString GetName() const
Definition: sch_sheet.h:101
@ FRAME_SCH
Definition: frame_type.h:34
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:382
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:383
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:41
const double IU_PER_MILS
Definition: base_units.h:78
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ LIB_FIELD_T
Definition: typeinfo.h:208
WX_VIEW_CONTROLS class definition.