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-2023 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 <tool/tool_manager.h>
35#include <layer_ids.h>
36#include <sch_screen.h>
37#include <schematic.h>
38#include <sch_base_frame.h>
39#include <sch_edit_frame.h>
40#include <string_utils.h>
41
42#include "sch_view.h"
43
44
45namespace KIGFX {
46
47
49 VIEW()
50{
51 m_frame = aFrame;
52
53 // Set m_boundary to define the max working area size. The default value is acceptable for
54 // Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
55 // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
56 double max_size = schIUScale.MilsToIU( MAX_PAGE_SIZE_EESCHEMA_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_drawingSheet.reset();
71 m_preview.reset();
72}
73
74
75void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
76{
77 VIEW::SetScale( aScale, aAnchor );
78
79 // Redraw items whose rendering 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( schIUScale.IU_PER_MILS ) * 3.0;
89 double max_size_y = page_info.GetHeightIU( schIUScale.IU_PER_MILS ) * 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
95void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
96{
97 for( SCH_ITEM* item : aScreen->Items() )
98 Add( item );
99
101 &aScreen->Schematic()->Prj(),
102 &aScreen->GetTitleBlock(),
103 aScreen->Schematic()->GetProperties() ) );
104 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
105 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
106 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
108 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
109 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
110
111 if( m_frame && m_frame->IsType( FRAME_SCH ) )
112 {
113 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
114
115 wxCHECK( editFrame, /* void */ );
116
117 m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
118 m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
119 }
120 else
121 {
122 m_drawingSheet->SetSheetName( "" );
123 m_drawingSheet->SetSheetPath( "" );
124 }
125
126 ResizeSheetWorkingArea( aScreen );
127
128 Add( m_drawingSheet.get() );
129
130 InitPreview();
131
132 // Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
133 if( m_frame && m_frame->GetToolManager() )
135}
136
137
139{
140 Clear();
141
142 if( !aSymbol )
143 return;
144
145 // Draw the fields.
146 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
147 {
148 if( item.Type() == SCH_FIELD_T )
149 Add( &item );
150 }
151
152 LIB_SYMBOL* drawnSymbol = aSymbol;
153
154 // Draw the parent items if the symbol is inherited from another symbol.
155 if( aSymbol->IsAlias() )
156 {
157 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
158 drawnSymbol = parent.get();
159 else
160 {
161 wxCHECK( false, /* void */ );
162 }
163 }
164
165 for( SCH_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() == SCH_FIELD_T )
170 continue;
171
172 Add( &item );
173 }
174
175 InitPreview();
176}
177
178
180{
181 for( VIEW_ITEM* item : *m_allItems )
182 {
183 if( !item )
184 continue;
185
186 Hide( item, false );
187 }
188}
189
190
192{
193 // SetVisible( m_drawingSheet.get(), false );
194}
195
196
197}; // namespace KIGFX
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
int GetPageCount() const
Definition: base_screen.h:72
int GetVirtualPageNumber() const
Definition: base_screen.h:75
const wxString & GetPageNumber() const
Definition: base_screen.cpp:70
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr void SetSize(const SizeVec &size)
Definition: box2.h:248
bool IsType(FRAME_T aType) const
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:109
SCH_VIEW(SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:48
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition: sch_view.cpp:138
void ResizeSheetWorkingArea(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:85
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:95
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:75
void HideDrawingSheet()
Definition: sch_view.cpp:191
void Cleanup()
Definition: sch_view.cpp:67
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:106
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:84
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:562
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:299
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
Definition: view.h:867
void Clear()
Remove all items from the view.
Definition: view.cpp:1117
void InitPreview()
Definition: view.cpp:1696
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:854
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1607
BOX2D m_boundary
Definition: view.h:876
Define a library symbol object.
Definition: lib_symbol.h:78
bool IsAlias() const
Definition: lib_symbol.h:195
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:499
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:236
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition: page_info.h:162
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition: page_info.h:153
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:95
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:92
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:166
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:130
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
const wxString & GetFileName() const
Definition: sch_screen.h:143
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:100
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:154
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
@ REDRAW
Full drawing refresh.
Definition: tool_base.h:83
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
@ FRAME_SCH
Definition: frame_type.h:34
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:398
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:399
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:40
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
@ SCH_FIELD_T
Definition: typeinfo.h:150
WX_VIEW_CONTROLS class definition.