KiCad PCB EDA Suite
PARAM_VIEWPORT3D Class Reference

#include <board_project_settings.h>

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

Public Member Functions

 PARAM_VIEWPORT3D (const std::string &aPath, std::vector< VIEWPORT3D > *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< VIEWPORT3D > * m_viewports
 
nlohmann::json m_default
 
std::function< nlohmann::json()> m_getter
 
std::function< void(nlohmann::json)> m_setter
 

Detailed Description

Definition at line 233 of file board_project_settings.h.

Constructor & Destructor Documentation

◆ PARAM_VIEWPORT3D()

PARAM_VIEWPORT3D::PARAM_VIEWPORT3D ( const std::string &  aPath,
std::vector< VIEWPORT3D > *  aViewportList 
)

Definition at line 196 of file board_project_settings.cpp.

197 :
199 std::bind( &PARAM_VIEWPORT3D::viewportsToJson, this ),
200 std::bind( &PARAM_VIEWPORT3D::jsonToViewports, this, _1 ),
201 {} ),
202 m_viewports( aViewportList )
203{
204 wxASSERT( aViewportList );
205}
void jsonToViewports(const nlohmann::json &aJson)
nlohmann::json viewportsToJson()
std::vector< VIEWPORT3D > * m_viewports

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_VIEWPORT3D::jsonToViewports ( const nlohmann::json aJson)
private

Definition at line 241 of file board_project_settings.cpp.

242{
243 if( aJson.empty() || !aJson.is_array() )
244 return;
245
246 m_viewports->clear();
247
248 for( const nlohmann::json& viewport : aJson )
249 {
250 if( viewport.contains( "name" ) )
251 {
252 VIEWPORT3D v( viewport.at( "name" ).get<wxString>() );
253
254 if( viewport.contains( "xx" ) )
255 v.matrix[0].x = viewport.at( "xx" ).get<double>();
256
257 if( viewport.contains( "xy" ) )
258 v.matrix[0].y = viewport.at( "xy" ).get<double>();
259
260 if( viewport.contains( "xz" ) )
261 v.matrix[0].z = viewport.at( "xz" ).get<double>();
262
263 if( viewport.contains( "xw" ) )
264 v.matrix[0].w = viewport.at( "xw" ).get<double>();
265
266 if( viewport.contains( "yx" ) )
267 v.matrix[1].x = viewport.at( "yx" ).get<double>();
268
269 if( viewport.contains( "yy" ) )
270 v.matrix[1].y = viewport.at( "yy" ).get<double>();
271
272 if( viewport.contains( "yz" ) )
273 v.matrix[1].z = viewport.at( "yz" ).get<double>();
274
275 if( viewport.contains( "yw" ) )
276 v.matrix[1].w = viewport.at( "yw" ).get<double>();
277
278 if( viewport.contains( "zx" ) )
279 v.matrix[2].x = viewport.at( "zx" ).get<double>();
280
281 if( viewport.contains( "zy" ) )
282 v.matrix[2].y = viewport.at( "zy" ).get<double>();
283
284 if( viewport.contains( "zz" ) )
285 v.matrix[2].z = viewport.at( "zz" ).get<double>();
286
287 if( viewport.contains( "zw" ) )
288 v.matrix[2].w = viewport.at( "zw" ).get<double>();
289
290 if( viewport.contains( "wx" ) )
291 v.matrix[3].x = viewport.at( "wx" ).get<double>();
292
293 if( viewport.contains( "wy" ) )
294 v.matrix[3].y = viewport.at( "wy" ).get<double>();
295
296 if( viewport.contains( "wz" ) )
297 v.matrix[3].z = viewport.at( "wz" ).get<double>();
298
299 if( viewport.contains( "ww" ) )
300 v.matrix[3].w = viewport.at( "ww" ).get<double>();
301
302 m_viewports->emplace_back( v );
303 }
304 }
305}
nlohmann::json json
Definition: gerbview.cpp:44

References m_viewports, and VIEWPORT3D::matrix.

◆ 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_VIEWPORT3D::viewportsToJson ( )
private

Definition at line 208 of file board_project_settings.cpp.

209{
210 nlohmann::json ret = nlohmann::json::array();
211
212 for( const VIEWPORT3D& viewport : *m_viewports )
213 {
214 nlohmann::json js = {
215 { "name", viewport.name },
216 { "xx", viewport.matrix[0].x },
217 { "xy", viewport.matrix[0].y },
218 { "xz", viewport.matrix[0].z },
219 { "xw", viewport.matrix[0].w },
220 { "yx", viewport.matrix[1].x },
221 { "yy", viewport.matrix[1].y },
222 { "yz", viewport.matrix[1].z },
223 { "yw", viewport.matrix[1].w },
224 { "zx", viewport.matrix[2].x },
225 { "zy", viewport.matrix[2].y },
226 { "zz", viewport.matrix[2].z },
227 { "zw", viewport.matrix[2].w },
228 { "wx", viewport.matrix[3].x },
229 { "wy", viewport.matrix[3].y },
230 { "wz", viewport.matrix[3].z },
231 { "ww", viewport.matrix[3].w }
232 };
233
234 ret.push_back( js );
235 }
236
237 return ret;
238}

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<VIEWPORT3D>* PARAM_VIEWPORT3D::m_viewports
private

Definition at line 243 of file board_project_settings.h.

Referenced by jsonToViewports(), and viewportsToJson().


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