KiCad PCB EDA Suite
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 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 <memory>
29 #include <view/view.h>
30 #include <view/view_group.h>
31 #include <view/view_rtree.h>
32 #include <view/wx_view_controls.h>
33 #include <ws_proxy_view_item.h>
35 #include <class_libentry.h>
36 #include <sch_sheet.h>
37 #include <sch_screen.h>
38 #include <sch_component.h>
39 #include <schematic.h>
40 #include <lib_pin.h>
42 #include <sch_edit_frame.h>
43 
44 #include "sch_view.h"
45 
46 
47 namespace KIGFX {
48 
49 
50 SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
51  VIEW( aIsDynamic )
52 {
53  m_frame = aFrame;
54  // Set m_boundary to define the max working area size. The default value
55  // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to
56  // very different internal units.
57  // So we have to use a smaller value.
58  // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin
59  // around the worksheet.
60  double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
61  m_boundary.SetOrigin( -max_size/4, -max_size/4 );
62  m_boundary.SetSize( max_size, max_size );
63 
65  m_preview.reset( new KIGFX::VIEW_GROUP() );
66 }
67 
68 
70 {
71 }
72 
73 
74 void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
75 {
76  VIEW::SetScale( aScale, aAnchor );
77 
78  //Redraw selection halos since their width is dependent on zoom
79  if( m_frame )
81 }
82 
83 
85 {
86  const PAGE_INFO& page_info = aScreen->GetPageSettings();
87  double max_size_x = page_info.GetWidthIU() * 3.0;
88  double max_size_y = page_info.GetHeightIU() * 3.0;
89  m_boundary.SetOrigin( -max_size_x/4, -max_size_y/4 );
90  m_boundary.SetSize( max_size_x, max_size_y );
91 }
92 
93 
95 {
96  for( auto item : aScreen->Items() )
97  Add( item );
98 
99  m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
100  &aScreen->GetPageSettings(),
101  &aScreen->Schematic()->Prj(),
102  &aScreen->GetTitleBlock() ) );
103  m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
104  m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );
105  m_worksheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
106  m_worksheet->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
107 
108  if( m_frame && m_frame->IsType( FRAME_SCH ) )
109  m_worksheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
110  else
111  m_worksheet->SetSheetName( "" );
112 
113  ResizeSheetWorkingArea( aScreen );
114 
116  m_preview.reset( new KIGFX::VIEW_GROUP() );
117 
118  Add( m_worksheet.get() );
119  Add( m_selectionArea.get() );
120  Add( m_preview.get() );
121 }
122 
123 
125 {
126  DisplaySheet( aSheet->GetScreen() );
127 }
128 
129 
131 {
132  Clear();
133 
134  if( !aPart )
135  return;
136 
137  std::shared_ptr< LIB_PART > parent;
138  LIB_PART* drawnPart = aPart;
139 
140  // Draw the mandatory fields for aliases and parent symbols.
141  for( auto& item : aPart->GetDrawItems() )
142  {
143  if( item.Type() != LIB_FIELD_T )
144  continue;
145 
146  LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
147 
148  wxCHECK2( field, continue );
149 
150  if( field->GetText().IsEmpty() )
151  continue;
152 
153  Add( &item );
154  }
155 
156  // Draw the parent items if the symbol is inherited from another symbol.
157  if( aPart->IsAlias() )
158  {
159  parent = aPart->GetParent().lock();
160 
161  wxCHECK( parent, /* void */ );
162 
163  drawnPart = parent.get();
164  }
165 
166  for( auto& item : drawnPart->GetDrawItems() )
167  {
168  // Don't show parent symbol fields. Users may be confused by shown fields that can not
169  // be edited.
170  if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
171  continue;
172 
173  Add( &item );
174  }
175 
177  m_preview.reset( new KIGFX::VIEW_GROUP() );
178  Add( m_selectionArea.get() );
179  Add( m_preview.get() );
180 }
181 
182 
184 {
185  m_preview->Clear();
186 
187  for( auto item : m_ownedItems )
188  delete item;
189 
190  m_ownedItems.clear();
191  Update( m_preview.get() );
192 }
193 
194 
195 void SCH_VIEW::AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership )
196 {
197  Hide( aItem, false );
198  m_preview->Add( aItem );
199 
200  if( aTakeOwnership )
201  m_ownedItems.push_back( aItem );
202 
203  SetVisible( m_preview.get(), true );
204  Hide( m_preview.get(), false );
205  Update( m_preview.get() );
206 }
207 
208 
209 void SCH_VIEW::ShowPreview( bool aShow )
210 {
211  SetVisible( m_preview.get(), aShow );
212 }
213 
214 
216 {
217  for( auto item : *m_allItems )
218  Hide( item, false );
219 }
220 
221 
223 {
224  // SetVisible( m_worksheet.get(), false );
225 }
226 
227 
228 }; // namespace KIGFX
void RefreshSelection()
Mark selected items for refresh.
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1507
const wxString & GetFileName() const
Definition: sch_screen.h:189
int m_ScreenNumber
Definition: base_screen.h:85
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:215
void AddToPreview(EDA_ITEM *aItem, bool aTakeOwnership=true)
Definition: sch_view.cpp:195
void DisplayComponent(LIB_PART *aPart)
Definition: sch_view.cpp:130
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
void ResizeSheetWorkingArea(SCH_SCREEN *aScreen)
Definition: sch_view.cpp:84
Field object used in symbol libraries.
Definition: lib_field.h:59
void DisplaySheet(SCH_SHEET *aSheet)
Definition: sch_view.cpp:124
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:194
void SetSize(const Vec &size)
Definition: box2.h:211
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
std::unique_ptr< KIGFX::PREVIEW::SELECTION_AREA > m_selectionArea
Definition: sch_view.h:108
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:184
WX_VIEW_CONTROLS class definition.
std::vector< EDA_ITEM * > m_ownedItems
Definition: sch_view.h:110
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:815
void HideWorksheet()
Definition: sch_view.cpp:222
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void ShowPreview(bool aShow=true)
Definition: sch_view.cpp:209
Class LIB_PIN definition.
PART_REF & GetParent()
void ClearPreview()
Definition: sch_view.cpp:183
Define a library symbol object.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
std::unique_ptr< WS_PROXY_VIEW_ITEM > m_worksheet
Definition: sch_view.h:107
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1540
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:74
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:578
Board layer functions and definitions.
bool IsType(FRAME_T aType) const
BOX2D m_boundary
View boundaries.
Definition: view.h:830
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:93
EE_RTREE & Items()
Definition: sch_screen.h:162
bool IsAlias() const
void SetOrigin(const Vec &pos)
Definition: box2.h:209
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
#define IU_PER_MILS
Definition: plotter.cpp:138
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
#define TO_UTF8(wxstring)
SCH_BASE_FRAME * m_frame
Definition: sch_view.h:104
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1486
SCH_VIEW(bool aIsDynamic, SCH_BASE_FRAME *aFrame)
Definition: sch_view.cpp:50
int m_NumberOfScreens
Definition: base_screen.h:86
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
VIEW.
Definition: view.h:61
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: sch_view.h:109
virtual wxString GetScreenDesc() const