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>
39#include <text_var_dependency.h>
40#include <sch_base_frame.h>
41#include <sch_edit_frame.h>
42#include <string_utils.h>
43
44#include "sch_view.h"
45
46
47namespace KIGFX {
48
49
51 VIEW()
52{
53 m_frame = aFrame;
54}
55
56
61
62
75
76
77void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
78{
79 if( aItem->IsSCH_ITEM() )
80 {
81 // The equivalent function in PCB_VIEW doesn't need to do this, but
82 // that's only because RunOnChildren's constness is misleading in the PCB editor;
83 // it doesn't modify target item, but our uses of it modify its children.
84 SCH_ITEM* schItem = const_cast<SCH_ITEM*>( static_cast<const SCH_ITEM*>( aItem ) );
85
86 if( schItem->Type() == SCH_TABLECELL_T )
87 {
88 VIEW::Update( schItem->GetParent() );
89 }
90 else
91 {
92 schItem->RunOnChildren(
93 [this, aUpdateFlags]( SCH_ITEM* child )
94 {
95 VIEW::Update( child, aUpdateFlags );
96 },
98 }
99 }
100
101 VIEW::Update( aItem, aUpdateFlags );
102}
103
104
105void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
106{
108}
109
110
112{
113 Clear();
114 m_drawingSheet.reset();
115 m_preview.reset();
116}
117
118
119void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
120{
121 VIEW::SetScale( aScale, aAnchor );
122
123 // Redraw items whose rendering is dependent on zoom
124 if( m_frame )
125 m_frame->RefreshZoomDependentItems();
126}
127
128
129void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
130{
131 for( SCH_ITEM* item : aScreen->Items() )
132 Add( item );
133
135 &aScreen->Schematic()->Project(),
136 &aScreen->GetTitleBlock(),
137 aScreen->Schematic()->GetProperties() ) );
138 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
139 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
140 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
142 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
143 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
144
145 wxString currentVariant = aScreen->Schematic()->GetCurrentVariant();
146 wxString variantDesc = aScreen->Schematic()->GetVariantDescription( currentVariant );
147 m_drawingSheet->SetVariantName( TO_UTF8( currentVariant ) );
148 m_drawingSheet->SetVariantDesc( TO_UTF8( variantDesc ) );
149
150 if( m_frame && m_frame->IsType( FRAME_SCH ) )
151 {
152 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
153
154 wxCHECK( editFrame, /* void */ );
155
156 m_drawingSheet->SetSheetName( TO_UTF8( editFrame->GetScreenDesc() ) );
157 m_drawingSheet->SetSheetPath( TO_UTF8( editFrame->GetFullScreenDesc() ) );
158 }
159 else
160 {
161 m_drawingSheet->SetSheetName( "" );
162 m_drawingSheet->SetSheetPath( "" );
163 }
164
165 Add( m_drawingSheet.get() );
166
167 // Reactive title-block repaint: register this proxy with the schematic's
168 // text-var tracker. The listener that routes invalidations to VIEW::Update
169 // is installed lazily here too; it outlives individual proxy instances
170 // since it re-reads the current drawing sheet on every fire.
171 if( aScreen->Schematic() )
172 {
173 if( SCHEMATIC_TEXT_VAR_ADAPTER* adapter = aScreen->Schematic()->GetTextVarAdapter() )
174 {
175 m_drawingSheet->AttachToTracker( &adapter->Tracker() );
176
177 TEXT_VAR_TRACKER* tracker = &adapter->Tracker();
178
179 if( m_textVarListenerTracker != tracker
181 {
182 m_textVarListenerTracker->RemoveInvalidateListener( m_textVarListenerHandle );
184 m_textVarListenerTracker = nullptr;
185 }
186
188 {
189 m_textVarListenerTracker = tracker;
191 [this]( EDA_ITEM* aDep, const TEXT_VAR_REF_KEY& )
192 {
193 if( !aDep )
194 return;
195
196 if( m_drawingSheet && aDep == m_drawingSheet.get() )
197 {
199 return;
200 }
201
202 if( aDep->IsSCH_ITEM() )
203 Update( aDep, KIGFX::REPAINT );
204 } );
205 }
206 }
207 }
208
209 InitPreview();
210
211 // Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
212 if( m_frame && m_frame->GetToolManager() )
213 m_frame->GetToolManager()->ResetTools( TOOL_BASE::REDRAW );
214}
215
216
218{
219 Clear();
220
221 if( !aSymbol )
222 return;
223
224 // Draw the fields.
225 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
226 {
227 if( item.Type() == SCH_FIELD_T )
228 Add( &item );
229 }
230
231 LIB_SYMBOL* drawnSymbol = aSymbol;
232
233 // Draw the parent items if the symbol is inherited from another symbol.
234 if( aSymbol->IsDerived() )
235 {
236 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
237 drawnSymbol = parent.get();
238 else
239 {
240 wxCHECK( false, /* void */ );
241 }
242 }
243
244 for( SCH_ITEM& item : drawnSymbol->GetDrawItems() )
245 {
246 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
247 // users may be confused by shown fields that can not be edited.)
248 if( item.Type() == SCH_FIELD_T )
249 continue;
250
251 Add( &item );
252 }
253
254 InitPreview();
255}
256
257
259{
260 for( VIEW_ITEM* item : *m_allItems )
261 {
262 if( !item )
263 continue;
264
265 Hide( item, false );
266 }
267}
268
269
271{
272 // SetVisible( m_drawingSheet.get(), false );
273}
274
275
276}; // namespace KIGFX
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:127
int GetPageCount() const
Definition base_screen.h:72
int GetVirtualPageNumber() const
Definition base_screen.h:75
const wxString & GetPageNumber() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:100
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
EDA_ITEM * GetParent() const
Definition eda_item.h:114
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Definition sch_view.h:135
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:77
SCH_VIEW(SCH_BASE_FRAME *aFrame)
Definition sch_view.cpp:50
std::size_t m_textVarListenerHandle
Reactive invalidation listener state.
Definition sch_view.h:141
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition sch_view.cpp:217
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition sch_view.cpp:129
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition sch_view.cpp:119
void HideDrawingSheet()
Definition sch_view.cpp:270
void DetachTextVarTracker()
Drop every cached reference into the currently-attached SCHEMATIC's TEXT_VAR_TRACKER: unregister the ...
Definition sch_view.cpp:63
SCH_BASE_FRAME * m_frame
Definition sch_view.h:132
TEXT_VAR_TRACKER * m_textVarListenerTracker
Definition sch_view.h:142
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition sch_view.cpp:258
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
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition view.cpp:638
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:301
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition view.h:893
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:1809
void Clear()
Remove all items from the view.
Definition view.cpp:1213
void InitPreview()
Definition view.cpp:1847
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition view.h:880
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:1757
friend class VIEW_ITEM
Definition view.h:69
Define a library symbol object.
Definition lib_symbol.h:83
bool IsDerived() const
Definition lib_symbol.h:200
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:712
std::shared_ptr< LIB_SYMBOL > GetRootSymbol() const
Get the parent symbol that does not have another parent.
Bridges SCHEMATIC's listener stream into the generic TEXT_VAR_TRACKER.
wxString GetVariantDescription(const wxString &aVariantName) const
Return the description for a variant.
class SCHEMATIC_TEXT_VAR_ADAPTER * GetTextVarAdapter() const
Definition schematic.h:633
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:104
wxString GetCurrentVariant() const
Return the current variant being edited.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:107
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
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:634
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:141
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:119
const wxString & GetFileName() const
Definition sch_screen.h:154
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:165
Coordinates the dependency index with change notifications.
ListenerHandle AddInvalidateListener(InvalidateCallback aCallback)
Register a listener that fires for every invalidation.
static constexpr ListenerHandle INVALID_LISTENER
@ REDRAW
Full drawing refresh.
Definition tool_base.h:83
@ RECURSE
Definition eda_item.h:53
@ FRAME_SCH
Definition frame_type.h:34
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:498
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition layer_ids.h:499
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
@ 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.
Identifies a single resolvable source that a text item's ${...} reference depends on.
@ SCH_TABLECELL_T
Definition typeinfo.h:167
@ SCH_FIELD_T
Definition typeinfo.h:151
VECTOR2< double > VECTOR2D
Definition vector2d.h:686
WX_VIEW_CONTROLS class definition.