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 The 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
54
56{
57}
58
59
60void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
61{
62 if( aItem->IsSCH_ITEM() )
63 {
64 // The equivalent function in PCB_VIEW doesn't need to do this, but
65 // that's only because RunOnChildren's constness is misleading in the PCB editor;
66 // it doesn't modify target item, but our uses of it modify its children.
67 SCH_ITEM* schItem = const_cast<SCH_ITEM*>( static_cast<const SCH_ITEM*>( aItem ) );
68
69 if( schItem->Type() == SCH_TABLECELL_T )
70 {
71 VIEW::Update( schItem->GetParent() );
72 }
73 else
74 {
75 schItem->RunOnChildren(
76 [this, aUpdateFlags]( SCH_ITEM* child )
77 {
78 VIEW::Update( child, aUpdateFlags );
79 },
80 RECURSE_MODE::NO_RECURSE );
81 }
82 }
83
84 VIEW::Update( aItem, aUpdateFlags );
85}
86
87
88void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
89{
91}
92
93
95{
96 Clear();
97 m_drawingSheet.reset();
98 m_preview.reset();
99}
100
101
102void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
103{
104 VIEW::SetScale( aScale, aAnchor );
105
106 // Redraw items whose rendering is dependent on zoom
107 if( m_frame )
109}
110
111
112void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
113{
114 for( SCH_ITEM* item : aScreen->Items() )
115 Add( item );
116
118 &aScreen->Schematic()->Project(),
119 &aScreen->GetTitleBlock(),
120 aScreen->Schematic()->GetProperties() ) );
121 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
122 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
123 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
125 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
126 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
127
128 if( m_frame && m_frame->IsType( FRAME_SCH ) )
129 {
130 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
131
132 wxCHECK( editFrame, /* void */ );
133
134 m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
135 m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
136 }
137 else
138 {
139 m_drawingSheet->SetSheetName( "" );
140 m_drawingSheet->SetSheetPath( "" );
141 }
142
143 Add( m_drawingSheet.get() );
144
145 InitPreview();
146
147 // Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
148 if( m_frame && m_frame->GetToolManager() )
150}
151
152
154{
155 Clear();
156
157 if( !aSymbol )
158 return;
159
160 // Draw the fields.
161 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
162 {
163 if( item.Type() == SCH_FIELD_T )
164 Add( &item );
165 }
166
167 LIB_SYMBOL* drawnSymbol = aSymbol;
168
169 // Draw the parent items if the symbol is inherited from another symbol.
170 if( aSymbol->IsDerived() )
171 {
172 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
173 drawnSymbol = parent.get();
174 else
175 {
176 wxCHECK( false, /* void */ );
177 }
178 }
179
180 for( SCH_ITEM& item : drawnSymbol->GetDrawItems() )
181 {
182 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
183 // users may be confused by shown fields that can not be edited.)
184 if( item.Type() == SCH_FIELD_T )
185 continue;
186
187 Add( &item );
188 }
189
190 InitPreview();
191}
192
193
195{
196 for( VIEW_ITEM* item : *m_allItems )
197 {
198 if( !item )
199 continue;
200
201 Hide( item, false );
202 }
203}
204
205
207{
208 // SetVisible( m_drawingSheet.get(), false );
209}
210
211
212}; // namespace KIGFX
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
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
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
EDA_ITEM * GetParent() const
Definition: eda_item.h:112
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition: sch_view.h:126
void Update(const KIGFX::VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: sch_view.cpp:60
SCH_VIEW(SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:48
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition: sch_view.cpp:153
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition: sch_view.cpp:112
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:102
void HideDrawingSheet()
Definition: sch_view.cpp:206
void Cleanup()
Definition: sch_view.cpp:94
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:123
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:194
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
bool IsSCH_ITEM() const
Definition: view_item.h:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:570
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:298
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:871
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1685
void Clear()
Remove all items from the view.
Definition: view.cpp:1143
void InitPreview()
Definition: view.cpp:1722
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:1633
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:269
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:103
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:106
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:168
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition: sch_item.h:602
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:139
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition: sch_screen.h:117
const wxString & GetFileName() const
Definition: sch_screen.h:152
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:105
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:163
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:485
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition: layer_ids.h:486
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:33
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:59
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:429
@ SCH_TABLECELL_T
Definition: typeinfo.h:167
@ SCH_FIELD_T
Definition: typeinfo.h:151
WX_VIEW_CONTROLS class definition.