1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 CERN
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Jon Evans <jon@craftyjon.com>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef KICAD_NET_SETTINGS_H
23 #define KICAD_NET_SETTINGS_H
24 
25 #include <netclass.h>
26 #include <settings/nested_settings.h>
27 
28 /**
29  * NET_SETTINGS stores various net-related settings in a project context.  These settings are
30  * accessible and editable from both the schematic and PCB editors.
31  */
32 class NET_SETTINGS : public NESTED_SETTINGS
33 {
34 public:
35     NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath );
36 
37     virtual ~NET_SETTINGS();
38 
39 public:
40     NETCLASSES m_NetClasses;
41 
42     // Runtime map of label to netclass-name for quick lookup.  Includes both composite labels
43     // (buses) and atomic net names (including individual bus members).
44     std::map<wxString, wxString> m_NetClassAssignments;
45 
46     /**
47      * A map of fully-qualified net names to colors used in the board context.
48      * Since these color overrides are for the board, buses are not included here.
49      * Only nets that the user has assigned custom colors to will be in this list.
50      * Nets that no longer exist will be deleted during a netlist read in Pcbnew.
51      */
52     std::map<wxString, KIGFX::COLOR4D> m_PcbNetColors;
53 
54 public:
55     const wxString& GetNetclassName( const wxString& aNetName ) const;
56 
57     /**
58      * Parse a bus vector (e.g. A[7..0]) into name, begin, and end.
59      *
60      * Ensure that begin and end are positive and that end > begin.
61      *
62      * @param aBus is a bus vector label string
63      * @param aName out is the bus name, e.g. "A"
64      * @param aMemberList is a list of member strings, e.g. "A7", "A6", and so on
65      * @return true if aBus was successfully parsed
66      */
67     static bool ParseBusVector( const wxString& aBus, wxString* aName,
68                                 std::vector<wxString>* aMemberList );
69 
70     /**
71      * Parse a bus group label into the name and a list of components.
72      *
73      * @param aGroup is the input label, e.g. "USB{DP DM}"
74      * @param name is the output group name, e.g. "USB"
75      * @param aMemberList is a list of member strings, e.g. "DP", "DM"
76      * @return true if aGroup was successfully parsed
77      */
78     static bool ParseBusGroup( const wxString& aGroup, wxString* name,
79                                std::vector<wxString>* aMemberList );
80 
81     /**
82      * Rebuild netclass assignments from the netclass membership lists.
83      */
84     void RebuildNetClassAssignments();
85 
86 private:
87     bool migrateSchema0to1();
88 
89     // TODO: Add diff pairs, bus information, etc.
90 };
91 
92 #endif // KICAD_NET_SETTINGS_H
93