File: database_lib_settings.h

package info (click to toggle)
kicad 9.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 771,448 kB
  • sloc: cpp: 969,355; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 228; javascript: 167; perl: 10
file content (123 lines) | stat: -rw-r--r-- 4,373 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2022 Jon Evans <jon@craftyjon.com>
 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef KICAD_DATABASE_LIB_SETTINGS_H
#define KICAD_DATABASE_LIB_SETTINGS_H

#include <settings/json_settings.h>
#include <wx/string.h>


enum class DATABASE_SOURCE_TYPE
{
    ODBC,
    INVALID
};


struct KICOMMON_API DATABASE_SOURCE
{
    DATABASE_SOURCE_TYPE type;
    std::string          dsn;
    std::string          username;
    std::string          password;
    int                  timeout;
    std::string          connection_string;
};


struct KICOMMON_API DATABASE_FIELD_MAPPING
{
    std::string column;             ///< Database column name
    std::string name;               ///< KiCad field name
    wxString    name_wx;            ///< KiCad field name (converted)
    bool        visible_on_add;     ///< Whether to show the field when placing the symbol
    bool        visible_in_chooser; ///< Whether the column is shown by default in the chooser
    bool        show_name;   ///< Whether or not to show the field name as well as its value
    bool        inherit_properties; ///< Whether or not to inherit properties from symbol field

    explicit DATABASE_FIELD_MAPPING( std::string aColumn, std::string aName, bool aVisibleOnAdd,
                                     bool aVisibleInChooser, bool aShowName,
                                     bool aInheritProperties );
};


struct KICOMMON_API MAPPABLE_SYMBOL_PROPERTIES
{
    std::string description;
    std::string footprint_filters;
    std::string keywords;
    std::string exclude_from_sim;
    std::string exclude_from_bom;
    std::string exclude_from_board;
};


/**
 * A database library table will be mapped to a sub-library provided by the database library entry
 * in the KiCad symbol/footprint library table.  A single database library config file (managed by
 * this class) may contain more than one table mapping, and each will have its own nickname.
 *
 * The LIB_ID for parts placed from this library will be constructed from the nickname of the
 * database library itself, plus the nickname of the particular sub-library and the value of the
 * key column for the placed part.
 *
 * For example, if a database library is configured with the nickname "PartsDB" and it provides a
 * table called "Capacitors", with `key_col` set to "Part Number", the LIB_ID for a capacitor placed
 * from this table will look something like `PartsDB-Capacitors:CAP-001`
 */
struct KICOMMON_API DATABASE_LIB_TABLE
{
    std::string name;              ///< KiCad library nickname (will form part of the LIB_ID)
    std::string table;             ///< Database table to pull content from
    std::string key_col;           ///< Unique key column name (will form part of the LIB_ID)
    std::string symbols_col;       ///< Column name containing KiCad symbol refs
    std::string footprints_col;    ///< Column name containing KiCad footprint refs

    MAPPABLE_SYMBOL_PROPERTIES properties;
    std::vector<DATABASE_FIELD_MAPPING> fields;
};


struct KICOMMON_API DATABASE_CACHE_SETTINGS
{
    int max_size;    ///< Maximum number of single-row results to cache
    int max_age;     ///< Max age of cached rows before they expire, in seconds
};


class KICOMMON_API DATABASE_LIB_SETTINGS : public JSON_SETTINGS
{
public:
    DATABASE_LIB_SETTINGS( const std::string& aFilename );

    virtual ~DATABASE_LIB_SETTINGS() {}

    DATABASE_SOURCE m_Source;

    std::vector<DATABASE_LIB_TABLE> m_Tables;

    DATABASE_CACHE_SETTINGS m_Cache;

protected:
    wxString getFileExt() const override;
};

#endif //KICAD_DATABASE_LIB_SETTINGS_H