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_PROJECT_LOCAL_SETTINGS_H
23 #define KICAD_PROJECT_LOCAL_SETTINGS_H
24 
25 #include <layer_ids.h>
26 #include <project/board_project_settings.h>
27 #include <settings/json_settings.h>
28 #include <wildcards_and_files_ext.h>
29 #include <settings/app_settings.h>
30 
31 class PROJECT;
32 
33 struct PROJECT_FILE_STATE
34 {
35     wxString fileName;
36     bool open;
37     struct WINDOW_STATE window;
38 };
39 
40 
41 /**
42  * The project local settings are things that are attached to a particular project, but also might
43  * be particular to a certain user editing that project, or change quickly, and therefore may not
44  * want to be checked in to version control or otherwise distributed with the main project.
45  *
46  * Examples include layer visibility, recently-used design entry settings, and so on.
47  *
48  * The backing store is a JSON file named <project>.kicad_prl
49  *
50  * This file doesn't need to exist for a project to be loaded.  It will be created on-demand if
51  * any of the things stored here are modified by the user.
52  */
53 class PROJECT_LOCAL_SETTINGS : public JSON_SETTINGS
54 {
55 public:
56     PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxString& aFilename );
57 
~PROJECT_LOCAL_SETTINGS()58     virtual ~PROJECT_LOCAL_SETTINGS() {}
59 
60     bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override;
61 
62     bool SaveAs( const wxString& aDirectory, const wxString& aFile );
63 
64     bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
65 
SetProject(PROJECT * aProject)66     void SetProject( PROJECT* aProject )
67     {
68         m_project = aProject;
69     }
70 
71     void SaveFileState( const wxString& aFileName, const WINDOW_SETTINGS* aWindowCfg, bool aOpen );
72 
73     const PROJECT_FILE_STATE* GetFileState( const wxString& aFileName );
74 
75     void ClearFileState();
76 
77 protected:
getFileExt()78     wxString getFileExt() const override
79     {
80         return ProjectLocalSettingsFileExtension;
81     }
82 
getLegacyFileExt()83     wxString getLegacyFileExt() const override
84     {
85         return wxT( "NO_SUCH_FILE_EXTENSION" );
86     }
87 
88 public:
89 
90     /**
91      * Project scope
92      */
93 
94     /// File based state
95     std::vector<PROJECT_FILE_STATE> m_files;
96 
97     /**
98      * Board settings
99      */
100 
101     /// The board layers that are turned on for viewing (@see PCB_LAYER_ID)
102     LSET m_VisibleLayers;
103 
104     /// The GAL layers (aka items) that are turned on for viewing (@see GAL_LAYER_ID)
105     GAL_SET m_VisibleItems;
106 
107     /// The current (active) board layer for editing
108     PCB_LAYER_ID m_ActiveLayer;
109 
110     /// The name of a LAYER_PRESET that is currently activated (or blank if none)
111     wxString m_ActiveLayerPreset;
112 
113     /// The current contrast mode
114     HIGH_CONTRAST_MODE m_ContrastModeDisplay;
115 
116     /// The current net color mode
117     NET_COLOR_MODE m_NetColorMode;
118 
119     /// The current ratsnest draw mode
120     RATSNEST_MODE m_RatsnestMode;
121 
122     /// The current setting for whether to automatically adjust track widths to match
123     bool m_AutoTrackWidth;
124 
125     /// How zones are drawn
126     ZONE_DISPLAY_MODE m_ZoneDisplayMode;
127 
128     double m_TrackOpacity;     ///< Opacity override for all tracks
129     double m_ViaOpacity;       ///< Opacity override for all types of via
130     double m_PadOpacity;       ///< Opacity override for SMD pads and PTH
131     double m_ZoneOpacity;      ///< Opacity override for filled zones
132 
133     /**
134      * A list of netnames that have been manually hidden in the board editor.
135      * Currently, hiding nets means hiding the ratsnest for those nets.
136      */
137     std::vector<wxString> m_HiddenNets;
138 
139     /// State of the selection filter widget
140     SELECTION_FILTER_OPTIONS m_SelectionFilter;
141 
142 private:
143     /// A link to the owning project
144     PROJECT* m_project;
145 };
146 
147 #endif
148