KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_lib_mgr.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 (C) 2022 Mikolaj Wielgus
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <map>
24#include <vector>
25
26#include <sim/sim_library.h>
27#include <sim/sim_model.h>
28#include <sim/sim_model_input.h>
29
30class EMBEDDED_FILES;
31class PROJECT;
32class SCH_SYMBOL;
33
34
36{
37public:
38 SIM_LIB_MGR( const PROJECT* aPrj );
39 virtual ~SIM_LIB_MGR() = default;
40
42
43 void Clear();
44
45 void SetFilesStack( std::vector<EMBEDDED_FILES*> aFilesStack )
46 {
47 m_embeddedFilesStack = std::move( aFilesStack );
48 }
49
50 void SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter );
51
52 SIM_MODEL& CreateModel( SIM_MODEL::TYPE aType, std::span<const wxString> aPins,
53 REPORTER& aReporter );
54
55 SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, std::span<const wxString> aPins,
56 REPORTER& aReporter );
57
58 SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, std::span<const wxString> aPins,
59 const std::vector<SCH_FIELD>& aFields, bool aResolve, int aDepth,
60 REPORTER& aReporter );
61
63 static SIM_MODEL_INPUT CaptureModelInput( const SCH_SHEET_PATH* aSheetPath, const SCH_SYMBOL& aSymbol,
64 int aDepth, const wxString& aVariantName,
65 const wxString& aMergedSimPins = wxEmptyString );
66
68 SIM_LIBRARY::MODEL CreateModel( const SIM_MODEL_INPUT& aInput, bool aAllowRawFallback,
69 REPORTER& aReporter );
70
71 // aMergedSimPins is an optional merged Sim.Pins string from all units of a multi-unit symbol.
72 // If provided (non-empty), it will be used instead of the symbol's Sim.Pins field.
73 SIM_LIBRARY::MODEL CreateModel( const SCH_SHEET_PATH* aSheetPath, const SCH_SYMBOL& aSymbol,
74 bool aResolve, int aDepth, const wxString& aVariantName,
75 REPORTER& aReporter, const wxString& aMergedSimPins = wxEmptyString );
76
77 SIM_LIBRARY::MODEL CreateModel( const std::vector<SCH_FIELD>& aFields, bool aResolve, int aDepth,
78 std::span<const wxString> aPins, REPORTER& aReporter );
79
80 SIM_LIBRARY::MODEL CreateModel( const wxString& aLibraryPath, const std::string& aBaseModelName,
81 const std::vector<SCH_FIELD>& aFields, bool aResolve, int aDepth,
82 std::span<const wxString> aPins, REPORTER& aReporter );
83
84 void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel );
85
86 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> GetLibraries() const;
87 std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
88
89 wxString ResolveLibraryPath( const wxString& aLibraryPath, REPORTER& aReporter );
90 wxString ResolveEmbeddedLibraryPath( const wxString& aLibPath, const wxString& aRelativeLib,
91 REPORTER& aReporter );
92
93private:
94 SIM_LIBRARY::MODEL createModel( const std::vector<SCH_FIELD>& aFields, bool aResolve, int aDepth,
95 std::span<const wxString> aPins, REPORTER& aReporter,
96 bool aAllowRawFallback );
97
98 std::vector<EMBEDDED_FILES*> m_embeddedFilesStack; // no ownership
99 const PROJECT* m_project; // no ownership
101 std::map<wxString, std::unique_ptr<SIM_LIBRARY>> m_libraries;
102 std::vector<std::unique_ptr<SIM_MODEL>> m_models;
103};
104
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:75
void SetModel(int aIndex, std::unique_ptr< SIM_MODEL > aModel)
SIM_LIBRARY::MODEL createModel(const std::vector< SCH_FIELD > &aFields, bool aResolve, int aDepth, std::span< const wxString > aPins, REPORTER &aReporter, bool aAllowRawFallback)
wxString ResolveLibraryPath(const wxString &aLibraryPath, REPORTER &aReporter)
const PROJECT * m_project
Definition sim_lib_mgr.h:99
std::vector< EMBEDDED_FILES * > m_embeddedFilesStack
Definition sim_lib_mgr.h:98
bool m_forceFullParse
SIM_LIB_MGR(const PROJECT *aPrj)
std::vector< std::unique_ptr< SIM_MODEL > > m_models
virtual ~SIM_LIB_MGR()=default
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
std::map< wxString, std::reference_wrapper< const SIM_LIBRARY > > GetLibraries() const
wxString ResolveEmbeddedLibraryPath(const wxString &aLibPath, const wxString &aRelativeLib, REPORTER &aReporter)
std::vector< std::reference_wrapper< SIM_MODEL > > GetModels() const
static SIM_MODEL_INPUT CaptureModelInput(const SCH_SHEET_PATH *aSheetPath, const SCH_SYMBOL &aSymbol, int aDepth, const wxString &aVariantName, const wxString &aMergedSimPins=wxEmptyString)
Resolve instance fields once; editors use the field-based overloads for unresolved input.
void SetLibrary(const wxString &aLibraryPath, REPORTER &aReporter)
void SetForceFullParse()
Definition sim_lib_mgr.h:41
std::map< wxString, std::unique_ptr< SIM_LIBRARY > > m_libraries
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:45