KiCad PCB EDA Suite
Loading...
Searching...
No Matches
model_file_preview_request_service.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
24
25#include <memory>
26#include <string>
27#include <string_view>
28#include <utility>
29
30
35
36
41
42
47
48
50{
51 m_state->queue.Cancel();
52}
53
54
56{
57 m_state->queue.Shutdown();
58}
59
60
62{
63 std::weak_ptr<STATE> state = m_state;
64
65 return [state]( wxString aPath, uint64_t aGeneration, PANEL_MODEL_FILE_PREVIEW::COMPLETION aCompletion )
66 {
67 std::shared_ptr<STATE> locked = state.lock();
68
69 if( !locked )
70 return;
71
72 // The panel stamps its own generation, so the queue's is ignored here.
73 locked->queue.Submit( std::string( aPath.utf8_str() ), S3D::PreviewImportOptions(),
74 [aGeneration, completion = std::move( aCompletion )]( std::uint64_t,
75 S3D::MODEL_IMPORT_RESULT aImported )
76 {
77 PANEL_MODEL_FILE_PREVIEW::RESULT result;
78 result.status = aImported.GetError();
79
80 const std::string_view diagnostic = aImported.GetDiagnostic();
81 result.message = wxString::FromUTF8( diagnostic.data(), diagnostic.size() );
82
83 if( result.message.IsEmpty() && !diagnostic.empty() )
84 result.message = wxString::From8BitData( diagnostic.data(), diagnostic.size() );
85
86 if( aImported )
87 {
88 auto owner = std::make_shared<S3D::MODEL_IMPORT_RESULT>( std::move( aImported ) );
89 result.model = owner->GetModel();
90 result.owner = std::move( owner );
91 }
92
93 completion( aGeneration, std::move( result ) );
94 } );
95 };
96}
97
98
100{
101 std::weak_ptr<STATE> state = m_state;
102
103 return [state]
104 {
105 if( std::shared_ptr<STATE> locked = state.lock() )
106 locked->queue.Cancel();
107 };
108}
std::function< void(wxString, uint64_t, COMPLETION)> REQUEST
std::function< void(uint64_t, RESULT)> COMPLETION
Single-slot import queue shared by every native preview front end.
MODEL_IMPORT_OPTIONS PreviewImportOptions() noexcept
Options for previewing a file the user has not opened.
STL namespace.
wxString result
Test unit parsing edge cases and error handling.