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, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <core/typeinfo.h>
25#include <memory>
26#include <view/view.h>
27#include <view/view_rtree.h>
30#include <tool/tool_manager.h>
31#include <layer_ids.h>
32#include <sch_screen.h>
33#include <schematic.h>
35#include <text_var_dependency.h>
36#include <sch_base_frame.h>
37#include <sch_edit_frame.h>
38#include <string_utils.h>
39
40#include "sch_view.h"
41
42
43namespace KIGFX {
44
45
47 VIEW()
48{
49 m_frame = aFrame;
50}
51
52
57
58
71
72
73void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
74{
75 if( aItem->IsSCH_ITEM() )
76 {
77 // The equivalent function in PCB_VIEW doesn't need to do this, but
78 // that's only because RunOnChildren's constness is misleading in the PCB editor;
79 // it doesn't modify target item, but our uses of it modify its children.
80 SCH_ITEM* schItem = const_cast<SCH_ITEM*>( static_cast<const SCH_ITEM*>( aItem ) );
81
82 if( schItem->Type() == SCH_TABLECELL_T )
83 {
84 VIEW::Update( schItem->GetParent() );
85 }
86 else
87 {
88 schItem->RunOnChildren(
89 [this, aUpdateFlags]( SCH_ITEM* child )
90 {
91 VIEW::Update( child, aUpdateFlags );
92 },
94 }
95 }
96
97 VIEW::Update( aItem, aUpdateFlags );
98}
99
100
101void SCH_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
102{
104}
105
106
108{
109 Clear();
110 m_drawingSheet.reset();
111 m_preview.reset();
112}
113
114
115void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
116{
117 VIEW::SetScale( aScale, aAnchor );
118
119 // Redraw items whose rendering is dependent on zoom
120 if( m_frame )
121 m_frame->RefreshZoomDependentItems();
122}
123
124
125void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
126{
127 for( SCH_ITEM* item : aScreen->Items() )
128 Add( item );
129
131 &aScreen->Schematic()->Project(),
132 &aScreen->GetTitleBlock(),
133 aScreen->Schematic()->GetProperties() ) );
135 m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
136
137 if( m_frame && m_frame->IsType( FRAME_SCH ) )
138 {
139 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
140
141 wxCHECK( editFrame, /* void */ );
142
143 // The title block metadata (sheet name/path, first-page flag) is derived from the
144 // current sheet, so the screen being displayed must be the current sheet's screen.
145 wxCHECK( editFrame->GetCurrentSheet().LastScreen() == aScreen, /* void */ );
146
148 }
149 else
150 {
151 m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
152 m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
153 m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
154 m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
155 m_drawingSheet->SetSheetName( "" );
156 m_drawingSheet->SetSheetPath( "" );
157 m_drawingSheet->SetVariantName( "" );
158 m_drawingSheet->SetVariantDesc( "" );
159 }
160
161 Add( m_drawingSheet.get() );
162
163 // Reactive title-block repaint: register this proxy with the schematic's
164 // text-var tracker. The listener that routes invalidations to VIEW::Update
165 // is installed lazily here too; it outlives individual proxy instances
166 // since it re-reads the current drawing sheet on every fire.
167 if( aScreen->Schematic() )
168 {
169 if( SCHEMATIC_TEXT_VAR_ADAPTER* adapter = aScreen->Schematic()->GetTextVarAdapter() )
170 {
171 m_drawingSheet->AttachToTracker( &adapter->Tracker() );
172
173 TEXT_VAR_TRACKER* tracker = &adapter->Tracker();
174
175 if( m_textVarListenerTracker != tracker
177 {
178 m_textVarListenerTracker->RemoveInvalidateListener( m_textVarListenerHandle );
180 m_textVarListenerTracker = nullptr;
181 }
182
184 {
185 m_textVarListenerTracker = tracker;
187 [this]( EDA_ITEM* aDep, const TEXT_VAR_REF_KEY& )
188 {
189 if( !aDep )
190 return;
191
192 if( m_drawingSheet && aDep == m_drawingSheet.get() )
193 {
195 return;
196 }
197
198 if( aDep->IsSCH_ITEM() )
199 {
200 if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( aDep ) )
201 {
202 text->ClearRenderCache();
203 text->ClearBoundingBoxCache();
204 }
205
207 }
208 } );
209 }
210 }
211 }
212
213 InitPreview();
214
215 // Allow tools to add anything they require to the view (such as the selection VIEW_GROUP)
216 if( m_frame && m_frame->GetToolManager() )
217 m_frame->GetToolManager()->ResetTools( TOOL_BASE::REDRAW );
218}
219
220
222{
223 SCH_SCREEN* screen = aFrame->GetScreen();
224
225 wxCHECK( screen, /* void */ );
226
227 m_drawingSheet->SetPageNumber( TO_UTF8( screen->GetPageNumber() ) );
228 m_drawingSheet->SetSheetCount( screen->GetPageCount() );
229 m_drawingSheet->SetFileName( TO_UTF8( screen->GetFileName() ) );
230
231 // Use the sheet path's virtual page number rather than the screen's, because the screen's
232 // value can be stale after operations like save that temporarily overwrite all screen page
233 // numbers for serialization.
234 m_drawingSheet->SetIsFirstPage( aFrame->GetCurrentSheet().GetVirtualPageNumber() == 1 );
235 m_drawingSheet->SetSheetName( TO_UTF8( aFrame->GetScreenDesc() ) );
236 m_drawingSheet->SetSheetPath( TO_UTF8( aFrame->GetFullScreenDesc() ) );
237
238 wxString currentVariant = aFrame->Schematic().GetCurrentVariant();
239 wxString variantDesc = aFrame->Schematic().GetVariantDescription( currentVariant );
240
241 m_drawingSheet->SetVariantName( TO_UTF8( currentVariant ) );
242 m_drawingSheet->SetVariantDesc( TO_UTF8( variantDesc ) );
243}
244
245
247{
248 if( !m_drawingSheet )
249 return;
250
251 if( m_frame && m_frame->IsType( FRAME_SCH ) )
252 {
253 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
254
255 if( !editFrame )
256 return;
257
260 }
261}
262
263
265{
266 Clear();
267
268 if( !aSymbol )
269 return;
270
271 // Draw the fields.
272 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
273 {
274 if( item.Type() == SCH_FIELD_T )
275 Add( &item );
276 }
277
278 LIB_SYMBOL* drawnSymbol = aSymbol;
279
280 // Draw the parent items if the symbol is inherited from another symbol.
281 if( aSymbol->IsDerived() )
282 {
283 if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
284 drawnSymbol = parent.get();
285 else
286 {
287 wxCHECK( false, /* void */ );
288 }
289 }
290
291 for( SCH_ITEM& item : drawnSymbol->GetDrawItems() )
292 {
293 // Fields already drawn above. (Besides, we don't want to show parent symbol fields as
294 // users may be confused by shown fields that can not be edited.)
295 if( item.Type() == SCH_FIELD_T )
296 continue;
297
298 Add( &item );
299 }
300
301 InitPreview();
302}
303
304
306{
307 for( VIEW_ITEM* item : *m_allItems )
308 {
309 if( !item )
310 continue;
311
312 Hide( item, false );
313 }
314}
315
316
318{
319 // SetVisible( m_drawingSheet.get(), false );
320}
321
322
323}; // namespace KIGFX
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
int GetPageCount() const
Definition base_screen.h:68
int GetVirtualPageNumber() const
Definition base_screen.h:71
const wxString & GetPageNumber() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
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:139
void syncDrawingSheetToCurrentSheet(SCH_EDIT_FRAME *aFrame)
Set the drawing-sheet proxy's page number, count and title-block fields from the frame's current shee...
Definition sch_view.cpp:221
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:73
SCH_VIEW(SCH_BASE_FRAME *aFrame)
Definition sch_view.cpp:46
std::size_t m_textVarListenerHandle
Reactive invalidation listener state.
Definition sch_view.h:152
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Definition sch_view.cpp:264
void DisplaySheet(const SCH_SCREEN *aScreen)
Definition sch_view.cpp:125
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition sch_view.cpp:115
void HideDrawingSheet()
Definition sch_view.cpp:317
void RefreshDrawingSheetPageInfo()
Update the drawing sheet proxy's page number and first-page flag from the current edit frame state.
Definition sch_view.cpp:246
void DetachTextVarTracker()
Drop every cached reference into the currently-attached SCHEMATIC's TEXT_VAR_TRACKER: unregister the ...
Definition sch_view.cpp:59
SCH_BASE_FRAME * m_frame
Definition sch_view.h:136
TEXT_VAR_TRACKER * m_textVarListenerTracker
Definition sch_view.h:153
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition sch_view.cpp:305
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsSCH_ITEM() const
Definition view_item.h:97
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition view.cpp:901
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:365
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition view.h:1082
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:2631
void Clear()
Remove all items from the view.
Definition view.cpp:1774
void InitPreview()
Definition view.cpp:2734
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition view.h:1069
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:2576
friend class VIEW_ITEM
Definition view.h:70
Define a library symbol object.
Definition lib_symbol.h:114
bool IsDerived() const
Definition lib_symbol.h:241
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:843
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:822
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:171
wxString GetCurrentVariant() const
Return the current variant being edited.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:174
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
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:170
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:683
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:144
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
const wxString & GetFileName() const
Definition sch_screen.h:157
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:168
SCH_SCREEN * LastScreen()
int GetVirtualPageNumber() const
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:79
@ RECURSE
Definition eda_item.h:51
@ FRAME_SCH
Definition frame_type.h:30
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition idf_helpers.h:37
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:524
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition layer_ids.h:525
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
Identifies a single resolvable source that a text item's ${...} reference depends on.
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_FIELD_T
Definition typeinfo.h:146
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
WX_VIEW_CONTROLS class definition.