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
48SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
49 VIEW( aIsDynamic )
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( LIB_ITEM& item : aSymbol->GetDrawItems() )
147 {
148 if( item.Type() == LIB_FIELD_T )
149 {
150 LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
151
152 wxCHECK2( field, continue );
153
154 Add( &item );
155 }
156 }
157
158 LIB_SYMBOL* drawnSymbol = aSymbol;
159
160 // Draw the parent items if the symbol is inherited from another symbol.
161 if( aSymbol->IsAlias() )
162 {
163 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
164 drawnSymbol = parent.get();
165 else
166 {
167 wxCHECK( false, /* void */ );
168 }
169 }
170
171 for( LIB_ITEM& item : drawnSymbol->GetDrawItems() )
172 {
173 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
174 // users may be confused by shown fields that can not be edited.)
175 if( 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:203
void SetSize(const Vec &size)
Definition: box2.h:214
bool IsType(FRAME_T aType) const
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:109
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:192
void Cleanup()
Definition: sch_view.cpp:67
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:106
SCH_VIEW(bool aIsDynamic, SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:48
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: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:552
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
The set of layers that are displayed on the top.
Definition: view.h:849
void Clear()
Remove all items from the view.
Definition: view.cpp:1121
void InitPreview()
Definition: view.cpp:1673
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:836
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1584
BOX2D m_boundary
Definition: view.h:858
Field object used in symbol libraries.
Definition: lib_field.h:62
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsAlias() const
Definition: lib_symbol.h:215
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:545
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:527
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:93
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
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:165
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:97
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
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:394
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:395
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:391
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:212
WX_VIEW_CONTROLS class definition.