KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_tree.cpp
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) 2004-2012 Jean-Pierre Charras
5 * Copyright (C) 2004-2022 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 2
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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <bitmaps.h>
28#include <wx/settings.h>
29
30#include "project_tree_item.h"
31#include "project_tree_pane.h"
32#include "project_tree.h"
33#include "kicad_id.h"
34
35
36IMPLEMENT_ABSTRACT_CLASS( PROJECT_TREE, wxTreeCtrl )
37
38
39#ifdef __WXMSW__
40#define PLATFORM_STYLE wxTR_LINES_AT_ROOT
41#else
42#define PLATFORM_STYLE wxTR_NO_LINES
43#endif
44
46 wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
47 PLATFORM_STYLE | wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator,
48 wxT( "EDATreeCtrl" ) ),
49 m_imageList( nullptr ),
50 m_statusImageList( nullptr )
51{
52 m_projectTreePane = parent;
53 m_gitCommon = std::make_unique<KIGIT_COMMON>( nullptr );
54
55 // Make sure the GUI font scales properly on GTK
56 SetFont( KIUI::GetControlFont( this ) );
57
58 LoadIcons();
59}
60
61
63{
64 delete m_imageList;
65 delete m_statusImageList;
66}
67
68
70{
71 // KiCad for macOS currently has backported high-DPI support for this control
72 // that is not in a released version of wxWidgets 3.2 yet. This can become the
73 // main codepath once wxWidgets 3.4 is released.
74#ifdef __WXMAC__
75 wxVector<wxBitmapBundle> images;
76 images.push_back( KiBitmapBundle( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
77 images.push_back( KiBitmapBundle( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
78 images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
79 images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
80 images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
81 images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
82 images.push_back( KiBitmapBundle( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
83 images.push_back( KiBitmapBundle( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
84 images.push_back( KiBitmapBundle( BITMAPS::file_html ) ); // TREE_HTML
85 images.push_back( KiBitmapBundle( BITMAPS::file_pdf ) ); // TREE_PDF
86 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_TXT
87 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_MD
88 images.push_back( KiBitmapBundle( BITMAPS::netlist ) ); // TREE_NET
89 images.push_back( KiBitmapBundle( BITMAPS::file_cir ) ); // TREE_NET_SPICE
90 images.push_back( KiBitmapBundle( BITMAPS::unknown ) ); // TREE_UNKNOWN
91 images.push_back( KiBitmapBundle( BITMAPS::directory ) ); // TREE_DIRECTORY
92 images.push_back( KiBitmapBundle( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
93 images.push_back( KiBitmapBundle( BITMAPS::tools ) ); // TREE_REPORT
94 images.push_back( KiBitmapBundle( BITMAPS::file_pos ) ); // TREE_POS
95 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL
96 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
97 images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
98 images.push_back( KiBitmapBundle( BITMAPS::file_svg ) ); // TREE_SVG
99 images.push_back( KiBitmapBundle( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
100 images.push_back( KiBitmapBundle( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
101 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
102 images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
103 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // DESIGN_RULES
104 images.push_back( KiBitmapBundle( BITMAPS::zip ) ); // ZIP_ARCHIVE
105 images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // JOBSET_FILE
106 SetImages( images );
107
108 wxVector<wxBitmapBundle> stateImages;
109 stateImages.push_back( wxBitmapBundle() ); // GIT_STATUS_UNTRACKED
110 stateImages.push_back( KiBitmapBundle( BITMAPS::git_good_check ) ); // GIT_STATUS_CURRENT
111 stateImages.push_back( KiBitmapBundle( BITMAPS::git_modified ) ); // GIT_STATUS_MODIFIED
112 stateImages.push_back( KiBitmapBundle( BITMAPS::git_add ) ); // GIT_STATUS_ADDED
113 stateImages.push_back( KiBitmapBundle( BITMAPS::git_delete ) ); // GIT_STATUS_DELETED
114 stateImages.push_back( KiBitmapBundle( BITMAPS::git_out_of_date ) ); // GIT_STATUS_BEHIND
115 stateImages.push_back( KiBitmapBundle( BITMAPS::git_changed_ahead ) ); // GIT_STATUS_AHEAD
116 stateImages.push_back( KiBitmapBundle( BITMAPS::git_conflict ) ); // GIT_STATUS_CONFLICTED
117
118 SetStateImages( stateImages );
119#else
120 delete m_imageList;
121
122 // Make an image list containing small icons
123 int logicSize = 24 * GetDPIScaleFactor() / GetContentScaleFactor(); // Cross-platform way
124 int physSize = ToPhys( logicSize ); // aka *GetContentScaleFactor()
125
126 if( physSize >= 64 )
127 physSize = 64;
128 else if( physSize >= 48 )
129 physSize = 48;
130 else if( physSize >= 32 )
131 physSize = 32;
132 else
133 physSize = 24;
134
135 logicSize = std::min( logicSize, physSize );
136 int bmpsf = std::max( 1, physSize / logicSize );
137
138 logicSize = physSize / bmpsf;
139
140 auto toBitmap = [&]( BITMAPS aBmps )
141 {
142 wxBitmap bmp = KiBitmap( aBmps, physSize );
143 bmp.SetScaleFactor( bmpsf );
144 wxASSERT(bmp.IsOk());
145 return bmp;
146 };
147
148 m_imageList = new wxImageList( logicSize, logicSize, true,
149 static_cast<int>( TREE_FILE_TYPE::MAX ) );
150
151 m_imageList->Add( toBitmap( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
152 m_imageList->Add( toBitmap( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
153 m_imageList->Add( toBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
154 m_imageList->Add( toBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
155 m_imageList->Add( toBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
156 m_imageList->Add( toBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
157 m_imageList->Add( toBitmap( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
158 m_imageList->Add( toBitmap( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
159 m_imageList->Add( toBitmap( BITMAPS::file_html ) ); // TREE_HTML
160 m_imageList->Add( toBitmap( BITMAPS::file_pdf ) ); // TREE_PDF
161 m_imageList->Add( toBitmap( BITMAPS::editor ) ); // TREE_TXT
162 m_imageList->Add( toBitmap( BITMAPS::editor ) ); // TREE_MD
163 m_imageList->Add( toBitmap( BITMAPS::netlist ) ); // TREE_NET
164 m_imageList->Add( toBitmap( BITMAPS::file_cir ) ); // TREE_NET_SPICE
165 m_imageList->Add( toBitmap( BITMAPS::unknown ) ); // TREE_UNKNOWN
166 m_imageList->Add( toBitmap( BITMAPS::directory ) ); // TREE_DIRECTORY
167 m_imageList->Add( toBitmap( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
168 m_imageList->Add( toBitmap( BITMAPS::tools ) ); // TREE_REPORT
169 m_imageList->Add( toBitmap( BITMAPS::file_pos ) ); // TREE_POS
170 m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL
171 m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
172 m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
173 m_imageList->Add( toBitmap( BITMAPS::file_svg ) ); // TREE_SVG
174 m_imageList->Add( toBitmap( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
175 m_imageList->Add( toBitmap( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
176 m_imageList->Add( toBitmap( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
177 m_imageList->Add( toBitmap( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
178 m_imageList->Add( toBitmap( BITMAPS::editor ) ); // DESIGN_RULES
179 m_imageList->Add( toBitmap( BITMAPS::zip ) ); // ZIP_ARCHIVE
180 m_imageList->Add( toBitmap( BITMAPS::editor ) ); // JOBSET_FILE
181
182 SetImageList( m_imageList );
183
184 // Make an image list containing small icons
185 int size = 16;
186
187 wxBitmap blank_bitmap( size, size );
188
189 delete m_statusImageList;
190 m_statusImageList = new wxImageList( size, size, true,
191 static_cast<int>( KIGIT_COMMON::GIT_STATUS::GIT_STATUS_LAST ) );
192
193 m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
194 m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, size ) ); // GIT_STATUS_CURRENT
195 m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, size ) ); // GIT_STATUS_MODIFIED
196 m_statusImageList->Add( KiBitmap( BITMAPS::git_add, size ) ); // GIT_STATUS_ADDED
197 m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, size ) ); // GIT_STATUS_DELETED
198 m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, size ) ); // GIT_STATUS_BEHIND
199 m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, size ) ); // GIT_STATUS_AHEAD
200 m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, size ) ); // GIT_STATUS_CONFLICTED
201
202 SetStateImageList( m_statusImageList );
203#endif
204
205}
206
207
208int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
209{
210 PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
211 PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
212
213 if( !myitem1 || !myitem2 )
214 return 0;
215
216 if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
217 && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
218 return -1;
219
220 if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
221 && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
222 return 1;
223
224 if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
225 return -1;
226
227 if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
228 return 1;
229
230 return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
231}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
Handle one item (a file or a directory name) for the tree file.
const wxString & GetFileName() const
TREE_FILE_TYPE GetType() const
bool IsRootFile() const
PROJECT_TREE_PANE Window to display the tree files.
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
Definition: project_tree.h:43
PROJECT_TREE_PANE * m_projectTreePane
Definition: project_tree.h:47
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
wxImageList * m_statusImageList
Definition: project_tree.h:49
PROJECT_TREE(PROJECT_TREE_PANE *parent)
std::unique_ptr< KIGIT_COMMON > m_gitCommon
Definition: project_tree.h:50
void LoadIcons()
wxImageList * m_imageList
Definition: project_tree.h:48
IDs used in KiCad main frame foe menuitems and tools.
@ ID_PROJECT_TREE
Definition: kicad_id.h:58
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:160
#define PLATFORM_STYLE