KiCad PCB EDA Suite
ws_proxy_undo_item.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) 2019 Kicad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <ws_proxy_undo_item.h>
25 #include <ws_data_model.h>
26 #include <eda_draw_frame.h>
27 #include <macros.h>
28 
29 using namespace KIGFX;
30 
33  m_selectedDataItem( INT_MAX ),
34  m_selectedDrawItem( INT_MAX )
35 {
36  if( aFrame )
37  {
38  m_pageInfo = aFrame->GetPageSettings();
39  m_titleBlock = aFrame->GetTitleBlock();
40  }
41 
44 
45  for( size_t ii = 0; ii < model.GetItems().size(); ++ii )
46  {
47  WS_DATA_ITEM* dataItem = model.GetItem( ii );
48 
49  for( size_t jj = 0; jj < dataItem->GetDrawItems().size(); ++jj )
50  {
51  WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ jj ];
52 
53  if( drawItem->IsSelected() )
54  {
55  m_selectedDataItem = ii;
56  m_selectedDrawItem = jj;
57  break;
58  }
59  }
60  }
61 }
62 
63 
65 {
67  {
68  aFrame->SetPageSettings( m_pageInfo );
69  aFrame->SetTitleBlock( m_titleBlock );
70  }
71 
73 
74  if( aView )
75  {
76  aView->Clear();
77 
78  for( int ii = 0; ii < (int)WS_DATA_MODEL::GetTheInstance().GetItems().size(); ++ii )
79  {
81 
82  dataItem->SyncDrawItems( nullptr, aView );
83 
84  if( ii == m_selectedDataItem && m_selectedDrawItem < (int)dataItem->GetDrawItems().size() )
85  {
86  WS_DRAW_ITEM_BASE* drawItem = dataItem->GetDrawItems()[ m_selectedDrawItem ];
87  drawItem->SetSelected();
88  }
89  }
90  }
91 }
92 
void Restore(EDA_DRAW_FRAME *aFrame, KIGFX::VIEW *aView=nullptr)
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
virtual const TITLE_BLOCK & GetTitleBlock() const =0
Work sheet structure type definitions.
Definition: ws_data_item.h:93
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
bool IsSelected() const
Definition: base_struct.h:233
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
WS_DATA_ITEM * GetItem(unsigned aIdx) const
void SetPageLayout(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout, or the default layout, if no custom layout available.
std::vector< WS_DATA_ITEM * > & GetItems()
The base class for create windows for drawing purpose.
This file contains miscellaneous commonly used macros and functions.
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
virtual const PAGE_INFO & GetPageSettings() const =0
WS_PROXY_UNDO_ITEM(const EDA_DRAW_FRAME *aFrame)
void SetSelected()
Definition: base_struct.h:239
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
const std::vector< WS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ws_data_item.h:128
virtual void SyncDrawItems(WS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
Class VIEW.
Definition: view.h:61
void SaveInString(wxString &aOutputString)
Save the description in a buffer.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210