1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef KICAD_BOARD_PROJECT_SETTINGS_H
22 #define KICAD_BOARD_PROJECT_SETTINGS_H
23 
24 #include <layer_ids.h>
25 #include <settings/parameters.h>
26 
27 // Can be removed by refactoring PARAM_LAYER_PRESET
28 #include <nlohmann/json.hpp>
29 
30 /**
31  * This file contains data structures that are saved in the project file or project local settings
32  * file that are specific to PcbNew.  This is done so that these structures are available in common.
33  */
34 
35 
36 /**
37  * Selection filtering that applies all the time (not the "filter selection" dialog that modifies
38  * the current selection)
39  */
40 struct SELECTION_FILTER_OPTIONS
41 {
42     bool lockedItems;   ///< Allow selecting locked items
43     bool footprints;    ///< Allow selecting entire footprints
44     bool text;          ///< Text (free or attached to a footprint)
45     bool tracks;        ///< Copper tracks
46     bool vias;          ///< Vias (all types>
47     bool pads;          ///< Footprint pads
48     bool graphics;      ///< Graphic lines, shapes, polygons
49     bool zones;         ///< Copper zones
50     bool keepouts;      ///< Keepout zones
51     bool dimensions;    ///< Dimension items
52     bool otherItems;    ///< Anything not fitting one of the above categories
53 
SELECTION_FILTER_OPTIONSSELECTION_FILTER_OPTIONS54     SELECTION_FILTER_OPTIONS()
55     {
56         lockedItems = true;
57         footprints  = true;
58         text        = true;
59         tracks      = true;
60         vias        = true;
61         pads        = true;
62         graphics    = true;
63         zones       = true;
64         keepouts    = true;
65         dimensions  = true;
66         otherItems  = true;
67     }
68 
69     /**
70      * @return true if any of the item types are enabled (excluding "locked items" which is special)
71      */
AnySELECTION_FILTER_OPTIONS72     bool Any()
73     {
74         return ( footprints || text || tracks || vias || pads || graphics || zones
75                  || keepouts || dimensions || otherItems );
76     }
77 
78     /**
79      * @return true if all the item types are enabled (excluding "locked items" which is special)
80      */
AllSELECTION_FILTER_OPTIONS81     bool All()
82     {
83         return ( footprints && text && tracks && vias && pads && graphics && zones
84                  && keepouts && dimensions && otherItems );
85     }
86 };
87 
88 /**
89  * Determine how inactive layers should be displayed.
90  */
91 enum class HIGH_CONTRAST_MODE
92 {
93     NORMAL = 0,     ///< Inactive layers are shown normally (no high-contrast mode)
94     DIMMED,         ///< Inactive layers are dimmed (old high-contrast mode)
95     HIDDEN          ///< Inactive layers are hidden
96 };
97 
98 ///< Determine how zones should be displayed.
99 enum class ZONE_DISPLAY_MODE
100 {
101     SHOW_FILLED,
102     SHOW_ZONE_OUTLINE,
103 
104     // Debug modes
105 
106     SHOW_FRACTURE_BORDERS,
107     SHOW_TRIANGULATION
108 };
109 
110 ///< Determine how net color overrides should be applied.
111 enum class NET_COLOR_MODE
112 {
113     OFF,        ///< Net (and netclass) colors are not shown
114     RATSNEST,   ///< Net/netclass colors are shown on ratsnest lines only
115     ALL         ///< Net/netclass colors are shown on all net copper
116 };
117 
118 ///< Determine how ratsnest lines are drawn.
119 enum class RATSNEST_MODE
120 {
121     ALL,        ///< Ratsnest lines are drawn to items on all layers (default)
122     VISIBLE     ///< Ratsnest lines are drawn to items on visible layers only
123 };
124 
125 /**
126  * A saved set of layers that are visible.
127  */
128 struct LAYER_PRESET
129 {
130     LAYER_PRESET( const wxString& aName = wxEmptyString ) :
nameLAYER_PRESET131             name( aName ),
132             activeLayer( UNSELECTED_LAYER )
133     {
134         layers       = LSET::AllLayersMask();
135         renderLayers = GAL_SET::DefaultVisible();
136         readOnly     = false;
137     }
138 
LAYER_PRESETLAYER_PRESET139     LAYER_PRESET( const wxString& aName, const LSET& aVisibleLayers ) :
140             name( aName ),
141             layers( aVisibleLayers ),
142             activeLayer( UNSELECTED_LAYER )
143     {
144         renderLayers = GAL_SET::DefaultVisible();
145         readOnly     = false;
146     }
147 
LAYER_PRESETLAYER_PRESET148     LAYER_PRESET( const wxString& aName, const LSET& aVisibleLayers, const GAL_SET& aVisibleObjects,
149                   PCB_LAYER_ID aActiveLayer ) :
150             name( aName ),
151             layers( aVisibleLayers ),
152             renderLayers( aVisibleObjects ),
153             activeLayer( aActiveLayer )
154     {
155         readOnly = false;
156     }
157 
LayersMatchLAYER_PRESET158     bool LayersMatch( const LAYER_PRESET& aOther )
159     {
160         return aOther.layers == layers && aOther.renderLayers == renderLayers;
161     }
162 
163     wxString     name;          ///< A name for this layer set
164     LSET         layers;        ///< Board layers that are visible
165     GAL_SET      renderLayers;  ///< Render layers (e.g. object types) that are visible
166     PCB_LAYER_ID activeLayer;   ///< Optional layer to set active when this preset is loaded
167     bool         readOnly;      ///< True if this is a read-only (built-in) preset
168 };
169 
170 
171 class PARAM_LAYER_PRESET : public PARAM_LAMBDA<nlohmann::json>
172 {
173 public:
174     PARAM_LAYER_PRESET( const std::string& aPath, std::vector<LAYER_PRESET>* aPresetList );
175 
176 private:
177     nlohmann::json presetsToJson();
178 
179     void jsonToPresets( const nlohmann::json& aJson );
180 
181     std::vector<LAYER_PRESET>* m_presets;
182 };
183 
184 #endif // KICAD_BOARD_PROJECT_SETTINGS_H
185