KiCad PCB EDA Suite
Loading...
Searching...
No Matches
doc_property_helpers.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 The 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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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 KICAD_DIFF_DOC_PROPERTY_HELPERS_H
25#define KICAD_DIFF_DOC_PROPERTY_HELPERS_H
26
28#include <title_block.h>
29
30#include <page_info.h>
31
32#include <utility>
33#include <vector>
34
35
36namespace KICAD_DIFF
37{
38
52inline void AppendPaperDeltas( std::vector<PROPERTY_DELTA>& aDeltas, const PAGE_INFO& aBefore,
53 const PAGE_INFO& aAfter )
54{
55 if( aBefore.GetType() != aAfter.GetType() )
56 {
59 d.before = DIFF_VALUE::FromEnum( static_cast<int>( aBefore.GetType() ),
60 aBefore.GetTypeAsString().ToStdString() );
61 d.after = DIFF_VALUE::FromEnum( static_cast<int>( aAfter.GetType() ),
62 aAfter.GetTypeAsString().ToStdString() );
63 aDeltas.push_back( std::move( d ) );
64 }
65
66 if( aBefore.IsPortrait() != aAfter.IsPortrait() )
67 {
70 d.before = DIFF_VALUE::FromBool( aBefore.IsPortrait() );
72 aDeltas.push_back( std::move( d ) );
73 }
74}
75
76
81inline void AppendTitleBlockDeltas( std::vector<PROPERTY_DELTA>& aDeltas, const TITLE_BLOCK& aBefore,
82 const TITLE_BLOCK& aAfter )
83{
84 auto append = [&aDeltas]( const wxString& aName, const wxString& aBeforeValue, const wxString& aAfterValue )
85 {
86 if( aBeforeValue == aAfterValue )
87 return;
88
90 d.name = aName;
91 d.before = DIFF_VALUE::FromString( aBeforeValue );
92 d.after = DIFF_VALUE::FromString( aAfterValue );
93 aDeltas.push_back( std::move( d ) );
94 };
95
96 append( DOC_PROP_TITLE, aBefore.GetTitle(), aAfter.GetTitle() );
97 append( DOC_PROP_DATE, aBefore.GetDate(), aAfter.GetDate() );
98 append( DOC_PROP_REVISION, aBefore.GetRevision(), aAfter.GetRevision() );
99 append( DOC_PROP_COMPANY, aBefore.GetCompany(), aAfter.GetCompany() );
100
101 for( int ii = 0; ii < DOC_TITLE_BLOCK_COMMENTS; ii++ )
102 append( DocPropComment( ii ), aBefore.GetComment( ii ), aAfter.GetComment( ii ) );
103}
104
105
111inline bool ApplyTitleBlockProperty( TITLE_BLOCK& aTarget, const wxString& aName, const TITLE_BLOCK& aSource )
112{
113 if( aName == DOC_PROP_TITLE )
114 aTarget.SetTitle( aSource.GetTitle() );
115 else if( aName == DOC_PROP_DATE )
116 aTarget.SetDate( aSource.GetDate() );
117 else if( aName == DOC_PROP_REVISION )
118 aTarget.SetRevision( aSource.GetRevision() );
119 else if( aName == DOC_PROP_COMPANY )
120 aTarget.SetCompany( aSource.GetCompany() );
121 else
122 {
123 for( int ii = 0; ii < DOC_TITLE_BLOCK_COMMENTS; ii++ )
124 {
125 if( aName == DocPropComment( ii ) )
126 {
127 aTarget.SetComment( ii, aSource.GetComment( ii ) );
128 return true;
129 }
130 }
131
132 return false;
133 }
134
135 return true;
136}
137
138} // namespace KICAD_DIFF
139
140#endif // KICAD_DIFF_DOC_PROPERTY_HELPERS_H
static DIFF_VALUE FromEnum(int aValue, const std::string &aLabel)
static DIFF_VALUE FromBool(bool aValue)
static DIFF_VALUE FromString(const wxString &aValue)
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
wxString GetTypeAsString() const
bool IsPortrait() const
Definition page_info.h:123
const PAGE_SIZE_TYPE & GetType() const
Definition page_info.h:97
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:38
const wxString & GetCompany() const
Definition title_block.h:93
void SetRevision(const wxString &aRevision)
Definition title_block.h:78
void SetComment(int aIdx, const wxString &aComment)
Definition title_block.h:98
const wxString & GetRevision() const
Definition title_block.h:83
void SetTitle(const wxString &aTitle)
Definition title_block.h:55
const wxString & GetDate() const
Definition title_block.h:73
const wxString & GetComment(int aIdx) const
void SetCompany(const wxString &aCompany)
Definition title_block.h:88
const wxString & GetTitle() const
Definition title_block.h:60
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition title_block.h:68
wxString DocPropComment(int aIndex)
bool ApplyTitleBlockProperty(TITLE_BLOCK &aTarget, const wxString &aName, const TITLE_BLOCK &aSource)
Copy the title block field named by a document property from aSource into aTarget.
const wxString DOC_PROP_DATE
const wxString DOC_PROP_PAGE_FORMAT
Property-name keys for the synthetic document-level ITEM_CHANGE (empty KIID_PATH).
constexpr int DOC_TITLE_BLOCK_COMMENTS
Matches the count TITLE_BLOCK::Format writes, which is all a file can hold.
const wxString DOC_PROP_REVISION
void AppendTitleBlockDeltas(std::vector< PROPERTY_DELTA > &aDeltas, const TITLE_BLOCK &aBefore, const TITLE_BLOCK &aAfter)
Append a delta for every title block field that differs between the two documents,...
const wxString DOC_PROP_PAGE_ORIENTATION
const wxString DOC_PROP_COMPANY
void AppendPaperDeltas(std::vector< PROPERTY_DELTA > &aDeltas, const PAGE_INFO &aBefore, const PAGE_INFO &aAfter)
Append DOC_PROP_PAGE_FORMAT and/or DOC_PROP_PAGE_ORIENTATION deltas to aDeltas when the two PAGE_INFO...
const wxString DOC_PROP_TITLE
Title block fields. The comments are numbered from one, as the page settings dialog shows them.
Single (name, before, after) triple for one mutated property on an item.