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, 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#ifndef RULE_EDITOR_DATA_BASE_H_
25#define RULE_EDITOR_DATA_BASE_H_
26
27#include <lset.h>
28#include <lseq.h>
29#include <optional>
30
35{
36public:
37 virtual ~ICopyable() = default;
38
39 virtual void CopyFrom( const ICopyable& source ) = 0;
40};
41
46{
47public:
49
50 explicit RULE_EDITOR_DATA_BASE( int aId, int aParentId, wxString aRuleName ) :
51 m_id( aId ), m_parentId( aParentId ), m_ruleName( aRuleName ), m_isNew( false )
52 {
53 }
54
55 virtual ~RULE_EDITOR_DATA_BASE() = default;
56
62 int GetId() { return m_id; }
63
69 void SetId( int aId ) { m_id = aId; }
70
76 int GetParentId() { return m_parentId.value_or( -1 ); }
77
83 void SetParentId( int aParentId ) { m_parentId = aParentId; }
84
90 wxString GetRuleName() { return m_ruleName; }
91
97 void SetRuleName( wxString aRuleName ) { m_ruleName = aRuleName; }
98
104 wxString GetComment() { return m_comment; }
105
111 void SetComment( wxString aComment ) { m_comment = aComment; }
112
118 bool IsNew() { return m_isNew; }
119
125 void SetIsNew( bool aIsNew ) { m_isNew = aIsNew; }
126
132 void CopyFrom( const ICopyable& aSource ) override
133 {
134 const auto& baseSource = dynamic_cast<const RULE_EDITOR_DATA_BASE&>( aSource );
135
136 m_comment = baseSource.m_comment;
137 }
138
139private:
140 int m_id; // Unique ID of the rule.
141 std::optional<int> m_parentId; // Optional parent ID of the rule.
142 wxString m_ruleName;
143 wxString m_comment;
144 bool m_isNew;
146};
147
148#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.