KiCad PCB EDA Suite
PARAM_VIEWPORT Class Reference

#include <board_project_settings.h>

Inheritance diagram for PARAM_VIEWPORT:
PARAM_LAMBDA< nlohmann::json > PARAM_BASE

Public Member Functions

 PARAM_VIEWPORT (const std::string &aPath, std::vector< VIEWPORT > *aViewportList)
 
void Load (JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
 Loads the value of this parameter from JSON to the underlying storage. More...
 
void Store (JSON_SETTINGS *aSettings) const override
 Stores the value of this parameter to the given JSON_SETTINGS object. More...
 
nlohmann::json GetDefault () const
 
void SetDefault () override
 
bool MatchesFile (JSON_SETTINGS *aSettings) const override
 Checks whether the parameter in memory matches the one in a given JSON file. More...
 
const std::string & GetJsonPath () const
 

Protected Attributes

std::string m_path
 the string used to store the param in json files More...
 
bool m_readOnly
 ! True if the parameter pointer should never be overwritten More...
 

Private Member Functions

nlohmann::json viewportsToJson ()
 
void jsonToViewports (const nlohmann::json &aJson)
 

Private Attributes

std::vector< VIEWPORT > * m_viewports
 
nlohmann::json m_default
 
std::function< nlohmann::json()> m_getter
 
std::function< void(nlohmann::json)> m_setter
 

Detailed Description

Definition at line 203 of file board_project_settings.h.

Constructor & Destructor Documentation

◆ PARAM_VIEWPORT()

PARAM_VIEWPORT::PARAM_VIEWPORT ( const std::string &  aPath,
std::vector< VIEWPORT > *  aViewportList 
)

Definition at line 133 of file board_project_settings.cpp.

133 :
135 std::bind( &PARAM_VIEWPORT::viewportsToJson, this ),
136 std::bind( &PARAM_VIEWPORT::jsonToViewports, this, _1 ),
137 {} ),
138 m_viewports( aViewportList )
139{
140 wxASSERT( aViewportList );
141}
std::vector< VIEWPORT > * m_viewports
nlohmann::json viewportsToJson()
void jsonToViewports(const nlohmann::json &aJson)

Member Function Documentation

◆ GetDefault()

nlohmann::json PARAM_LAMBDA< nlohmann::json >::GetDefault ( ) const
inlineinherited

Definition at line 306 of file parameters.h.

307 {
308 return m_default;
309 }

◆ GetJsonPath()

const std::string & PARAM_BASE::GetJsonPath ( ) const
inlineinherited
Returns
the path name of the parameter used to store it in the json file mainly useful in error messages

Definition at line 69 of file parameters.h.

69{ return m_path; }
std::string m_path
the string used to store the param in json files
Definition: parameters.h:75

References PARAM_BASE::m_path.

◆ jsonToViewports()

void PARAM_VIEWPORT::jsonToViewports ( const nlohmann::json aJson)
private

Definition at line 165 of file board_project_settings.cpp.

166{
167 if( aJson.empty() || !aJson.is_array() )
168 return;
169
170 m_viewports->clear();
171
172 for( const nlohmann::json& viewport : aJson )
173 {
174 if( viewport.contains( "name" ) )
175 {
176 VIEWPORT v( viewport.at( "name" ).get<wxString>() );
177
178 if( viewport.contains( "x" ) )
179 v.rect.SetX( viewport.at( "x" ).get<double>() );
180
181 if( viewport.contains( "y" ) )
182 v.rect.SetY( viewport.at( "y" ).get<double>() );
183
184 if( viewport.contains( "w" ) )
185 v.rect.SetWidth( viewport.at( "w" ).get<double>() );
186
187 if( viewport.contains( "h" ) )
188 v.rect.SetHeight( viewport.at( "h" ).get<double>() );
189
190 m_viewports->emplace_back( v );
191 }
192 }
193}
nlohmann::json json
Definition: gerbview.cpp:44

References m_viewports, VIEWPORT::rect, BOX2< Vec >::SetHeight(), BOX2< Vec >::SetWidth(), BOX2< Vec >::SetX(), and BOX2< Vec >::SetY().

◆ Load()

void PARAM_LAMBDA< nlohmann::json >::Load ( JSON_SETTINGS aSettings,
bool  aResetIfMissing = true 
) const
overridevirtualinherited

Loads the value of this parameter from JSON to the underlying storage.

Parameters
aSettingsis the JSON_SETTINGS object to load from.
aResetIfMissingif true will set the parameter to its default value if load fails

Implements PARAM_BASE.

Definition at line 293 of file parameters.cpp.

32{
33 if( m_readOnly )
34 return;
35
36 if( std::is_same<ValueType, nlohmann::json>::value )
37 {
38 if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
39 m_setter( *optval );
40 else
42 }
43 else
44 {
45 if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
46 m_setter( *optval );
47 else
49 }
50}
std::optional< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
bool m_readOnly
! True if the parameter pointer should never be overwritten
Definition: parameters.h:78
std::function< void(nlohmann::json)> m_setter
Definition: parameters.h:323

◆ MatchesFile()

bool PARAM_LAMBDA< nlohmann::json >::MatchesFile ( JSON_SETTINGS aSettings) const
overridevirtualinherited

Checks whether the parameter in memory matches the one in a given JSON file.

Parameters
aSettingsis a JSON_SETTINGS to check the JSON file contents of
Returns
true if the parameter in memory matches its value in the file

Implements PARAM_BASE.

Definition at line 316 of file parameters.cpp.

55{
56 if( std::is_same<ValueType, nlohmann::json>::value )
57 {
58 if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
59 return *optval == m_getter();
60 }
61 else
62 {
63 if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
64 return *optval == m_getter();
65 }
66
67 // Not in file
68 return false;
69}
std::function< nlohmann::json()> m_getter
Definition: parameters.h:321

◆ SetDefault()

void PARAM_LAMBDA< nlohmann::json >::SetDefault ( )
inlineoverridevirtualinherited

Implements PARAM_BASE.

Definition at line 311 of file parameters.h.

312 {
314 }

◆ Store()

void PARAM_LAMBDA< nlohmann::json >::Store ( JSON_SETTINGS aSettings) const
inlineoverridevirtualinherited

Stores the value of this parameter to the given JSON_SETTINGS object.

Parameters
aSettingsis the JSON_SETTINGS object to store into.

Implements PARAM_BASE.

Definition at line 295 of file parameters.h.

296 {
297 try
298 {
299 aSettings->Set<ValueType>( m_path, m_getter() );
300 }
301 catch( ... )
302 {
303 }
304 }
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...

◆ viewportsToJson()

nlohmann::json PARAM_VIEWPORT::viewportsToJson ( )
private

Definition at line 144 of file board_project_settings.cpp.

145{
146 nlohmann::json ret = nlohmann::json::array();
147
148 for( const VIEWPORT& viewport : *m_viewports )
149 {
150 nlohmann::json js = {
151 { "name", viewport.name },
152 { "x", viewport.rect.GetX() },
153 { "y", viewport.rect.GetY() },
154 { "w", viewport.rect.GetWidth() },
155 { "h", viewport.rect.GetHeight() }
156 };
157
158 ret.push_back( js );
159 }
160
161 return ret;
162}

References m_viewports.

Member Data Documentation

◆ m_default

nlohmann::json PARAM_LAMBDA< nlohmann::json >::m_default
privateinherited

Definition at line 319 of file parameters.h.

◆ m_getter

std::function<nlohmann::json ()> PARAM_LAMBDA< nlohmann::json >::m_getter
privateinherited

Definition at line 321 of file parameters.h.

◆ m_path

◆ m_readOnly

bool PARAM_BASE::m_readOnly
protectedinherited

◆ m_setter

std::function<void( nlohmann::json )> PARAM_LAMBDA< nlohmann::json >::m_setter
privateinherited

Definition at line 323 of file parameters.h.

◆ m_viewports

std::vector<VIEWPORT>* PARAM_VIEWPORT::m_viewports
private

Definition at line 213 of file board_project_settings.h.

Referenced by jsonToViewports(), and viewportsToJson().


The documentation for this class was generated from the following files: