KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sheet_synchronization_model.h
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) 2023 Ethan Chien <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef SHEET_SYNCHRONIZATION_MODEL_H
26#define SHEET_SYNCHRONIZATION_MODEL_H
27
28#include <sch_sheet_path.h>
29#include <memory>
30#include <optional>
31#include <list>
32#include <wx/dataview.h>
33#include <wx/string.h>
34
36using SHEET_SYNCHRONIZATION_ITE_PTR = std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM>;
37using SHEET_SYNCHRONIZATION_ITEM_LIST = std::vector<SHEET_SYNCHRONIZATION_ITE_PTR>;
38
41class SCH_SHEET;
42class SCH_SHEET_PATH;
43
44class SHEET_SYNCHRONIZATION_MODEL : public wxDataViewVirtualListModel
45{
46public:
48 {
52 };
53
54 enum
55 {
60 };
61
62 static wxString GetColName( int col )
63 {
64 switch( col )
65 {
66 case NAME: return _( "Name" );
67 case SHAPE: return _( "Shape" );
68 default: return {};
69 }
70 }
71
72
74 SCH_SHEET_PATH& aPath );
76
77 void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override;
78
79 bool SetValueByRow( const wxVariant& variant, unsigned row, unsigned col ) override;
80
81 bool GetAttrByRow( unsigned row, unsigned int col, wxDataViewItemAttr& attr ) const override;
82
83 void RemoveItems( wxDataViewItemArray const& aItems );
84
88 bool AppendNewItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
89
93 bool AppendItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
94
95 SHEET_SYNCHRONIZATION_ITEM_LIST TakeItems( wxDataViewItemArray const& aItems );
96
97 SHEET_SYNCHRONIZATION_ITE_PTR TakeItem( wxDataViewItem const& aItem );
98
100
101 void OnRowSelected( std::optional<unsigned> aRow );
102
104
105 void AddNotifier( std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER> aNotifier );
106
107 void DoNotify();
108
109 bool HasSelectedIndex() const { return m_selectedIndex.has_value(); }
110
111 std::optional<unsigned int> GetSelectedIndex() const { return m_selectedIndex; }
112
113private:
115 std::optional<unsigned> m_selectedIndex;
116 std::list<std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER>> m_notifiers;
120};
121
122#endif
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Agent for all the modifications while syncing the sheet pin and hierarchical label.
~SHEET_SYNCHRONIZATION_MODEL() override
std::list< std::shared_ptr< SHEET_SYNCHRONIZATION_NOTIFIER > > m_notifiers
std::optional< unsigned > m_selectedIndex
bool GetAttrByRow(unsigned row, unsigned int col, wxDataViewItemAttr &attr) const override
bool SetValueByRow(const wxVariant &variant, unsigned row, unsigned col) override
SHEET_SYNCHRONIZATION_ITE_PTR TakeItem(wxDataViewItem const &aItem)
SHEET_SYNCHRONIZATION_ITEM_LIST TakeItems(wxDataViewItemArray const &aItems)
SHEET_SYNCHRONIZATION_ITE_PTR GetSynchronizationItem(unsigned aIndex) const
void AddNotifier(std::shared_ptr< SHEET_SYNCHRONIZATION_NOTIFIER > aNotifier)
void GetValueByRow(wxVariant &variant, unsigned row, unsigned col) const override
bool AppendItem(std::shared_ptr< SHEET_SYNCHRONIZATION_ITEM > aItem)
Just append item to the list, the notifiers are not notified.
void UpdateItems(SHEET_SYNCHRONIZATION_ITEM_LIST aItems)
SHEET_SYNCHRONIZATION_AGENT & m_agent
SHEET_SYNCHRONIZATION_ITEM_LIST m_items
void RemoveItems(wxDataViewItemArray const &aItems)
std::optional< unsigned int > GetSelectedIndex() const
bool AppendNewItem(std::shared_ptr< SHEET_SYNCHRONIZATION_ITEM > aItem)
Add a new item, the notifiers are notified.
void OnRowSelected(std::optional< unsigned > aRow)
#define _(s)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< SHEET_SYNCHRONIZATION_ITE_PTR > SHEET_SYNCHRONIZATION_ITEM_LIST
std::shared_ptr< SHEET_SYNCHRONIZATION_ITEM > SHEET_SYNCHRONIZATION_ITE_PTR