KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 The 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_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
54
56{
57}
58
59
61{
62 Clear();
63 m_drawingSheet.reset();
64 m_preview.reset();
65}
66
67
68void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
69{
70 VIEW::SetScale( aScale, aAnchor );
71
72 // Redraw items whose rendering is dependent on zoom
73 if( m_frame )
75}
76
77
78void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
79{
80 for( SCH_ITEM* item : aScreen->Items() )
81 Add( item );
82
84 &aScreen->Schematic()->Prj(),
85 &aScreen->GetTitleBlock(),
86 aScreen->Schematic()->GetProperties() ) );
87 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
88 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
89 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
91 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
92 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
93
94 if( m_frame && m_frame->IsType( FRAME_SCH ) )
95 {
96 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
97
98 wxCHECK( editFrame, /* void */ );
99
100 m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
101 m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
102 }
103 else
104 {
105 m_drawingSheet->SetSheetName( "" );
106 m_drawingSheet->SetSheetPath( "" );
107 }
108
109 Add( m_drawingSheet.get() );
110
111 InitPreview();
112
113 // Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
114 if( m_frame && m_frame->GetToolManager() )
116}
117
118
120{
121 Clear();
122
123 if( !aSymbol )
124 return;
125
126 // Draw the fields.
127 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
128 {
129 if( item.Type() == SCH_FIELD_T )
130 Add( &item );
131 }
132
133 LIB_SYMBOL* drawnSymbol = aSymbol;
134
135 // Draw the parent items if the symbol is inherited from another symbol.
136 if( aSymbol->IsDerived() )
137 {
138 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
139 drawnSymbol = parent.get();
140 else
141 {
142 wxCHECK( false, /* void */ );
143 }
144 }
145
146 for( SCH_ITEM& item : drawnSymbol->GetDrawItems() )
147 {
148 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
149 // users may be confused by shown fields that can not be edited.)
150 if( item.Type() == SCH_FIELD_T )
151 continue;
152
153 Add( &item );
154 }
155
156 InitPreview();
157}
158
159
161{
162 for( VIEW_ITEM* item : *m_allItems )
163 {
164 if( !item )
165 continue;
166
167 Hide( item, false );
168 }
169}
170
171
173{
174 // SetVisible( m_drawingSheet.get(), false );
175}
176
177
178}; // 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
bool IsType(FRAME_T aType) const
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:123
SCH_VIEW(SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:48
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition: sch_view.cpp:119
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:78
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:68
void HideDrawingSheet()
Definition: sch_view.cpp:172
void Cleanup()
Definition: sch_view.cpp:60
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:120
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:160
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:560
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:297
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:871
void Clear()
Remove all items from the view.
Definition: view.cpp:1131
void InitPreview()
Definition: view.cpp:1710
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: view.h:858
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1621
Define a library symbol object.
Definition: lib_symbol.h:85
bool IsDerived() const
Definition: lib_symbol.h:207
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:519
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:277
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:84
const std::map< wxString, wxString > * GetProperties()
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:167
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:134
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition: sch_screen.h:112
const wxString & GetFileName() const
Definition: sch_screen.h:147
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:102
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:158
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:484
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:485
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:32
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:408
@ SCH_FIELD_T
Definition: typeinfo.h:150
WX_VIEW_CONTROLS class definition.