KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rule_editor_data_base.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) 2024 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef RULE_EDITOR_DATA_BASE_H_
21#define RULE_EDITOR_DATA_BASE_H_
22
23#include <lset.h>
24#include <lseq.h>
25#include <optional>
26
31{
32public:
33 virtual ~ICopyable() = default;
34
35 virtual void CopyFrom( const ICopyable& source ) = 0;
36};
37
42{
43public:
45
46 explicit RULE_EDITOR_DATA_BASE( int aId, int aParentId, wxString aRuleName ) :
47 m_id( aId ), m_parentId( aParentId ), m_ruleName( aRuleName ), m_isNew( false )
48 {
49 }
50
51 virtual ~RULE_EDITOR_DATA_BASE() = default;
52
58 int GetId() { return m_id; }
59
65 void SetId( int aId ) { m_id = aId; }
66
72 int GetParentId() { return m_parentId.value_or( -1 ); }
73
79 void SetParentId( int aParentId ) { m_parentId = aParentId; }
80
86 wxString GetRuleName() { return m_ruleName; }
87
93 void SetRuleName( wxString aRuleName ) { m_ruleName = aRuleName; }
94
100 wxString GetComment() { return m_comment; }
101
107 void SetComment( wxString aComment ) { m_comment = aComment; }
108
114 bool IsNew() { return m_isNew; }
115
121 void SetIsNew( bool aIsNew ) { m_isNew = aIsNew; }
122
128 void CopyFrom( const ICopyable& aSource ) override
129 {
130 const auto& baseSource = dynamic_cast<const RULE_EDITOR_DATA_BASE&>( aSource );
131
132 m_comment = baseSource.m_comment;
133 }
134
135private:
136 int m_id; // Unique ID of the rule.
137 std::optional<int> m_parentId; // Optional parent ID of the rule.
138 wxString m_ruleName;
139 wxString m_comment;
140 bool m_isNew = false;
142};
143
144#endif // RULE_EDITOR_DATA_BASE_H_
Abstract interface class to enable polymorphic copying between objects.
virtual void CopyFrom(const ICopyable &source)=0
virtual ~ICopyable()=default
virtual ~RULE_EDITOR_DATA_BASE()=default
RULE_EDITOR_DATA_BASE()=default
bool m_isNew
Flag indicating if the user is creating a new rule (true) or editing an existing rule (false).
bool IsNew()
Check if the rule is marked as new.
int GetId()
Get the unique ID of the rule.
void SetIsNew(bool aIsNew)
Mark the rule as new or not.
RULE_EDITOR_DATA_BASE(int aId, int aParentId, wxString aRuleName)
void SetId(int aId)
Set the unique ID of the rule.
void SetParentId(int aParentId)
Set the parent ID of the rule.
void CopyFrom(const ICopyable &aSource) override
Implementation of the polymorphic CopyFrom method.
wxString GetComment()
Get the comment associated with the rule.
void SetRuleName(wxString aRuleName)
Set the name of the rule.
void SetComment(wxString aComment)
Set the comment for the rule.
std::optional< int > m_parentId
wxString GetRuleName()
Get the name of the rule.
int GetParentId()
Get the parent ID of the rule.