KiCad PCB EDA Suite
Loading...
Searching...
No Matches
model_preview_manager.cpp
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 as published by
8 * the Free Software Foundation; either version 3 of the License, or (at your option)
9 * 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-3.0.html
19 */
20
22
23#include <algorithm>
24
25#if defined( KICAD_NATIVE_MODEL_PREVIEW ) && defined( __WINDOWS__ )
26#include <confirm.h>
27#include <pgm_base.h>
30#include <trace_helpers.h>
31
32#include <wx/log.h>
33#include <wx/msgdlg.h>
34#endif
35
36namespace
37{
38wxString canonicalRequirement( wxString aRequirement )
39{
40 aRequirement.Trim( true ).Trim( false ).MakeLower();
41 return aRequirement;
42}
43} // namespace
44
45
47 const std::vector<wxString>& aDeclinedRequirements )
48{
51 || !aStatus.canRepairRegistration || aStatus.requirementId.IsEmpty() )
52 {
53 return false;
54 }
55
56 const wxString required = canonicalRequirement( aStatus.requirementId );
57
58 return std::none_of( aDeclinedRequirements.begin(), aDeclinedRequirements.end(),
59 [&]( const wxString& aDeclined )
60 {
61 return canonicalRequirement( aDeclined ) == required;
62 } );
63}
64
65
66void DeclineModelPreviewRequirement( const wxString& aRequirement, std::vector<wxString>& aDeclinedRequirements )
67{
68 const wxString requirement = canonicalRequirement( aRequirement );
69
70 if( requirement.IsEmpty()
71 || std::any_of( aDeclinedRequirements.begin(), aDeclinedRequirements.end(),
72 [&]( const wxString& aDeclined )
73 {
74 return canonicalRequirement( aDeclined ) == requirement;
75 } ) )
76 {
77 return;
78 }
79
80 aDeclinedRequirements.push_back( requirement );
81}
82
83
84#if defined( KICAD_NATIVE_MODEL_PREVIEW ) && defined( __WINDOWS__ )
85void MaybeShowModelPreviewSetupPrompt( wxWindow* aParent )
86{
87 static bool asked = false;
88
89 if( asked )
90 return;
91
92 asked = true;
93
95
96 if( !settings )
97 return;
98
100
102 {
103 wxLogTrace( traceModelPreview, wxS( "No setup prompt: %s" ), status.detail );
104 return;
105 }
106
107 wxMessageDialog dialog( aParent, _( "3D model previews require setup for this KiCad version." ),
108 _( "3D Model Previews" ), wxYES_NO | wxICON_INFORMATION );
109 dialog.SetYesNoLabels( _( "Set Up Previews" ), _( "Skip This Version" ) );
110
111 if( dialog.ShowModal() != wxID_YES )
112 {
114 Pgm().GetSettingsManager().Save( settings );
115 return;
116 }
117
118 wxString error;
119
121 {
122 wxLogTrace( traceModelPreview, wxS( "Registration failed: %s" ), error );
123 DisplayErrorMessage( aParent, _( "Could not set up 3D model previews." ), error );
124 }
125}
126#endif
std::vector< wxString > m_DeclinedModelPreviewRequirements
Preview-component requirements explicitly dismissed by the user.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:546
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
const wxChar *const traceModelPreview
Flag to enable native operating-system model preview debug output.
bool ShouldPromptForModelPreviewSetup(const MODEL_PREVIEW_STATUS &aStatus, const std::vector< wxString > &aDeclinedRequirements)
void DeclineModelPreviewRequirement(const wxString &aRequirement, std::vector< wxString > &aDeclinedRequirements)
bool RepairPlatformModelPreviewRegistration(wxString &aError)
MODEL_PREVIEW_STATUS GetPlatformModelPreviewStatus()
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
MODEL_PREVIEW_ENABLEMENT_STATE enablement
MODEL_PREVIEW_GUIDANCE guidance
wxLogTrace helper definitions.