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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SHEET_SYNCHRONIZATION_MODEL_H
22#define SHEET_SYNCHRONIZATION_MODEL_H
23
24#include <sch_sheet_path.h>
25#include <memory>
26#include <optional>
27#include <list>
28#include <wx/dataview.h>
29#include <wx/string.h>
30
32using SHEET_SYNCHRONIZATION_ITE_PTR = std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM>;
33using SHEET_SYNCHRONIZATION_ITEM_LIST = std::vector<SHEET_SYNCHRONIZATION_ITE_PTR>;
34
37class SCH_SHEET;
38class SCH_SHEET_PATH;
39
40class SHEET_SYNCHRONIZATION_MODEL : public wxDataViewVirtualListModel
41{
42public:
49
50 enum
51 {
56 };
57
58 static wxString GetColName( int col )
59 {
60 switch( col )
61 {
62 case NAME: return _( "Name" );
63 case SHAPE: return _( "Shape" );
64 default: return {};
65 }
66 }
67
68
70 const SCH_SHEET_PATH& aPath );
72
73 void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override;
74
75 bool SetValueByRow( const wxVariant& variant, unsigned row, unsigned col ) override;
76
77 bool GetAttrByRow( unsigned row, unsigned int col, wxDataViewItemAttr& attr ) const override;
78
79 void RemoveItems( wxDataViewItemArray const& aItems );
80
84 bool AppendNewItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
85
89 bool AppendItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
90
91 SHEET_SYNCHRONIZATION_ITEM_LIST TakeItems( wxDataViewItemArray const& aItems );
92
93 SHEET_SYNCHRONIZATION_ITE_PTR TakeItem( wxDataViewItem const& aItem );
94
96
97 SHEET_SYNCHRONIZATION_ITE_PTR GetSynchronizationItem( wxDataViewItem const& aItem ) const;
98
99 void OnRowSelected( std::optional<unsigned> aRow );
100
102
103 void AddNotifier( std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER> aNotifier );
104
105 void DoNotify();
106
107 bool HasSelectedIndex() const { return m_selectedIndex.has_value(); }
108
109 std::optional<unsigned int> GetSelectedIndex() const { return m_selectedIndex; }
110
111 unsigned int GetCount() const override;
112
113
114private:
116 std::optional<unsigned> m_selectedIndex;
117 std::list<std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER>> m_notifiers;
121};
122
123#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:44
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)
unsigned int GetCount() const override
SHEET_SYNCHRONIZATION_ITEM_LIST TakeItems(wxDataViewItemArray const &aItems)
SHEET_SYNCHRONIZATION_MODEL(SHEET_SYNCHRONIZATION_AGENT &aAgent, SCH_SHEET *aSheet, const SCH_SHEET_PATH &aPath)
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