KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
117 m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
118 }
119 else
120 {
121 m_drawingSheet->SetSheetName( "" );
122 m_drawingSheet->SetSheetPath( "" );
123 }
124
125 ResizeSheetWorkingArea( aScreen );
126
127 Add( m_drawingSheet.get() );
128
129 InitPreview();
130}
131
132
134{
135 Clear();
136
137 if( !aSymbol )
138 return;
139
140 // Draw the fields.
141 for( LIB_ITEM& item : aSymbol->GetDrawItems() )
142 {
143 if( item.Type() == LIB_FIELD_T )
144 {
145 LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
146
147 wxCHECK2( field, continue );
148
149 Add( &item );
150 }
151 }
152
153 LIB_SYMBOL* drawnSymbol = aSymbol;
154
155 // Draw the parent items if the symbol is inherited from another symbol.
156 if( aSymbol->IsAlias() )
157 {
158 std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetParent().lock();
159
160 wxCHECK( parent, /* void */ );
161
162 drawnSymbol = parent.get();
163 }
164
165 for( LIB_ITEM& item : drawnSymbol->GetDrawItems() )
166 {
167 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
168 // users may be confused by shown fields that can not be edited.)
169 if( item.Type() == LIB_FIELD_T )
170 continue;
171
172 Add( &item );
173 }
174
175 InitPreview();
176}
177
178
180{
181 for( VIEW_ITEM* item : *m_allItems )
182 Hide( item, false );
183}
184
185
187{
188 // SetVisible( m_drawingSheet.get(), false );
189}
190
191
192}; // 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
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:108
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition: sch_view.cpp:133
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:186
void Cleanup()
Definition: sch_view.cpp:65
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:105
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:179
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:314
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:1116
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1567
void InitPreview()
Definition: view.cpp:1645
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:61
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:99
bool IsAlias() const
Definition: lib_symbol.h:193
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:515
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:127
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:90
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:87
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.
wxString GetFullScreenDesc() const override
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
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:91
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
@ FRAME_SCH
Definition: frame_type.h:34
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:386
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:387
#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:246
#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:198
WX_VIEW_CONTROLS class definition.