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-2017 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <memory>
27 #include <view/view.h>
28 #include <view/view_group.h>
29 #include <view/view_rtree.h>
30 #include <view/wx_view_controls.h>
31 #include <worksheet_viewitem.h>
33 #include <class_libentry.h>
34 #include <sch_sheet.h>
35 #include <sch_screen.h>
37 
38 #include "sch_view.h"
39 
40 
41 namespace KIGFX {
42 
43 
44 SCH_VIEW::SCH_VIEW( bool aIsDynamic ) :
45  VIEW( aIsDynamic )
46 {
47 }
48 
49 
51 {
52 }
53 
54 
56 {
57 
58  for( auto item = aScreen->GetDrawItems(); item; item = item->Next() )
59  Add( item );
60 
61  m_worksheet.reset( new KIGFX::WORKSHEET_VIEWITEM( 1, &aScreen->GetPageSettings(),
62  &aScreen->GetTitleBlock() ) );
63  m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
64  m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );
65 
67  m_preview.reset( new KIGFX::VIEW_GROUP () );
68 
69  Add( m_worksheet.get() );
70  Add( m_selectionArea.get() );
71  Add( m_preview.get() );
72 }
73 
74 
76 {
77  DisplaySheet( aSheet->GetScreen() );
78 }
79 
80 
82 {
83  Clear();
84 
85  if( !aPart )
86  return;
87 
88  for ( auto &item : aPart->GetDrawItems() )
89  Add( &item );
90 
92  m_preview.reset( new KIGFX::VIEW_GROUP () );
93  Add( m_selectionArea.get() );
94  Add( m_preview.get() );
95 }
96 
97 
99 {
100  m_preview->Clear();
101 
102  for( auto item : m_ownedItems )
103  delete item;
104 
105  m_ownedItems.clear();
106  Update( m_preview.get() );
107 }
108 
109 
110 void SCH_VIEW::AddToPreview( EDA_ITEM *aItem, bool takeOwnership )
111 {
112  Hide( aItem, false );
113  m_preview->Add( aItem );
114 
115  if( takeOwnership )
116  m_ownedItems.push_back( aItem );
117 
118  SetVisible( m_preview.get(), true );
119  Hide( m_preview.get(), false );
120  Update( m_preview.get() );
121 }
122 
123 
124 void SCH_VIEW::ShowSelectionArea( bool aShow )
125 {
126  if( aShow )
127  {
128  // Reset seleciton area so the previous one doesn't flash before the first
129  // mouse move updates it
130  m_selectionArea->SetOrigin( VECTOR2I() );
131  m_selectionArea->SetEnd( VECTOR2I() );
132  }
133 
134  SetVisible( m_selectionArea.get(), aShow );
135 }
136 
137 
138 void SCH_VIEW::ShowPreview( bool aShow )
139 {
140  SetVisible( m_preview.get(), aShow );
141 }
142 
143 
145 {
146  for( auto item : *m_allItems )
147  Hide ( item, false );
148 }
149 
150 
152 {
153 // SetVisible( m_worksheet.get(), false );
154 }
155 
156 
157 };
158 
Definition of the SCH_SHEET class for Eeschema.
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1488
int m_ScreenNumber
Definition: base_screen.h:216
void ClearHiddenFlags()
Definition: sch_view.cpp:144
void DisplayComponent(LIB_PART *aPart)
Definition: sch_view.cpp:81
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
void ShowSelectionArea(bool aShow=true)
Definition: sch_view.cpp:124
void DisplaySheet(SCH_SHEET *aSheet)
Definition: sch_view.cpp:75
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
std::unique_ptr< KIGFX::PREVIEW::SELECTION_AREA > m_selectionArea
Definition: sch_view.h:93
SCH_ITEM * Next() const
WX_VIEW_CONTROLS class definition.
std::vector< EDA_ITEM * > m_ownedItems
Definition: sch_view.h:95
std::shared_ptr< std::vector< VIEW_ITEM * > > m_allItems
Flat list of all items.
Definition: view.h:813
Class that handles properties and drawing of worksheet layout.
void HideWorksheet()
Definition: sch_view.cpp:151
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1099
SCH_VIEW(bool aIsDynamic)
Definition: sch_view.cpp:44
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
void ShowPreview(bool aShow=true)
Definition: sch_view.cpp:138
Class LIB_ITEM definition.
void ClearPreview()
Definition: sch_view.cpp:98
Define a library symbol object.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
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:1521
void AddToPreview(EDA_ITEM *aItem, bool takeOwnership=true)
Definition: sch_view.cpp:110
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:136
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
Definitions for the Eeschema program SCH_SCREEN class.
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
std::unique_ptr< WORKSHEET_VIEWITEM > m_worksheet
Definition: sch_view.h:92
Board layer functions and definitions.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1467
int m_NumberOfScreens
Definition: base_screen.h:217
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:126
Class SELECTION_AREA.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:335
Class VIEW.
Definition: view.h:61
std::unique_ptr< KIGFX::VIEW_GROUP > m_preview
Definition: sch_view.h:94