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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <bitmaps.h>
24#include <wx/settings.h>
25#include <wx/dcmemory.h>
26
27#include "project_tree_item.h"
28#include "project_tree_pane.h"
29#include "project_tree.h"
30#include "kicad_id.h"
31
32
33IMPLEMENT_ABSTRACT_CLASS( PROJECT_TREE, wxTreeCtrl )
34
35
36#ifdef __WXMSW__
37#define PLATFORM_STYLE wxTR_LINES_AT_ROOT
38#else
39#define PLATFORM_STYLE wxTR_NO_LINES
40#endif
41
43 wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
44 PLATFORM_STYLE | wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator,
45 wxT( "EDATreeCtrl" ) ),
46 m_statusImageList( nullptr )
47{
48 m_projectTreePane = parent;
49
50 // Make sure the GUI font scales properly on GTK
51 SetFont( KIUI::GetControlFont( this ) );
52
53 LoadIcons();
54}
55
56
58{
59 // We pass ownership of these to wxWidgets in SetImageList() and SetStateImageList()
60 //delete m_statusImageList;
61}
62
63
65{
66#ifdef __WXMAC__
67 const int c_fileDefSize = 18;
68 const int c_gitDefSize = 16;
69#else
70 const int c_fileDefSize = 22;
71 const int c_gitDefSize = 16;
72#endif
73
74 auto getBundle = [&]( BITMAPS aBmp, int aDefSize )
75 {
76#ifdef __WXMSW__
77 // Add padding to bitmaps because MSW is the only platform that doesn't get it automatically
78 const int c_padding = 1;
79 wxVector<wxBitmap> bmps;
80
81 for( double scale : { 1.0, 1.25, 1.5, 1.75, 2.0, 3.0 } )
82 {
83 int size = aDefSize * scale;
84 int paddedSize = size + c_padding * 2 * scale;
85 wxBitmapBundle scaled = KiBitmapBundleDef( aBmp, size );
86 wxBitmap bmp = scaled.GetBitmap( wxDefaultSize );
87 wxBitmap padded( paddedSize, paddedSize, 32 );
88
89 {
90 padded.UseAlpha();
91 wxMemoryDC dc( padded );
92 dc.DrawBitmap( bmp, c_padding * scale, c_padding * scale );
93 }
94
95 bmps.push_back( padded );
96 }
97
98 return wxBitmapBundle::FromBitmaps( bmps );
99#else
100 return KiBitmapBundleDef( aBmp, aDefSize );
101#endif
102 };
103
104 wxVector<wxBitmapBundle> images;
105 images.push_back( getBundle( BITMAPS::project, c_fileDefSize ) ); // TREE_LEGACY_PROJECT
106 images.push_back( getBundle( BITMAPS::project_kicad, c_fileDefSize ) ); // TREE_JSON_PROJECT
107 images.push_back( getBundle( BITMAPS::icon_eeschema_24, c_fileDefSize ) ); // TREE_LEGACY_SCHEMATIC
108 images.push_back( getBundle( BITMAPS::icon_eeschema_24, c_fileDefSize ) ); // TREE_SEXPR_SCHEMATIC
109 images.push_back( getBundle( BITMAPS::icon_pcbnew_24, c_fileDefSize ) ); // TREE_LEGACY_PCB
110 images.push_back( getBundle( BITMAPS::icon_pcbnew_24, c_fileDefSize ) ); // TREE_SEXPR_PCB
111 images.push_back( getBundle( BITMAPS::icon_gerbview_24, c_fileDefSize ) ); // TREE_GERBER
112 images.push_back( getBundle( BITMAPS::file_gerber_job, c_fileDefSize ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
113 images.push_back( getBundle( BITMAPS::file_html, c_fileDefSize ) ); // TREE_HTML
114 images.push_back( getBundle( BITMAPS::file_pdf, c_fileDefSize ) ); // TREE_PDF
115 images.push_back( getBundle( BITMAPS::editor, c_fileDefSize ) ); // TREE_TXT
116 images.push_back( getBundle( BITMAPS::editor, c_fileDefSize ) ); // TREE_MD
117 images.push_back( getBundle( BITMAPS::netlist, c_fileDefSize ) ); // TREE_NET
118 images.push_back( getBundle( BITMAPS::file_cir, c_fileDefSize ) ); // TREE_NET_SPICE
119 images.push_back( getBundle( BITMAPS::unknown, c_fileDefSize ) ); // TREE_UNKNOWN
120 images.push_back( getBundle( BITMAPS::directory, c_fileDefSize ) ); // TREE_DIRECTORY
121 images.push_back( getBundle( BITMAPS::icon_cvpcb_24, c_fileDefSize ) ); // TREE_CMP_LINK
122 images.push_back( getBundle( BITMAPS::tools, c_fileDefSize ) ); // TREE_REPORT
123 images.push_back( getBundle( BITMAPS::file_pos, c_fileDefSize ) ); // TREE_POS
124 images.push_back( getBundle( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL
125 images.push_back( getBundle( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL_NC (similar TREE_DRILL)
126 images.push_back( getBundle( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
127 images.push_back( getBundle( BITMAPS::file_svg, c_fileDefSize ) ); // TREE_SVG
128 images.push_back( getBundle( BITMAPS::file_csv, c_fileDefSize ) ); // TREE_CSV
129 images.push_back( getBundle( BITMAPS::icon_pagelayout_editor_24, c_fileDefSize ) ); // TREE_PAGE_LAYOUT_DESCR
130 images.push_back( getBundle( BITMAPS::module, c_fileDefSize ) ); // TREE_FOOTPRINT_FILE
131 images.push_back( getBundle( BITMAPS::library, c_fileDefSize ) ); // TREE_SCHEMATIC_LIBFILE
132 images.push_back( getBundle( BITMAPS::library, c_fileDefSize ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
133 images.push_back( getBundle( BITMAPS::editor, c_fileDefSize ) ); // DESIGN_RULES
134 images.push_back( getBundle( BITMAPS::zip, c_fileDefSize ) ); // ZIP_ARCHIVE
135 images.push_back( getBundle( BITMAPS::editor, c_fileDefSize ) ); // JOBSET_FILE
136
137 SetImages( images );
138
139 // KiCad for macOS currently has backported SetStateImages for this control
140 // that is otherwise available since wxWidgets 3.3 on other platforms.
141#if wxCHECK_VERSION( 3, 3, 0 ) || defined( __WXMAC__ )
142 wxVector<wxBitmapBundle> stateImages;
143 stateImages.push_back( wxBitmapBundle( wxBitmap( c_gitDefSize, c_gitDefSize ) ) ); // GIT_STATUS_UNTRACKED
144 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_good_check, c_gitDefSize ) ); // GIT_STATUS_CURRENT
145 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_modified, c_gitDefSize ) ); // GIT_STATUS_MODIFIED
146 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_add, c_gitDefSize ) ); // GIT_STATUS_ADDED
147 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_delete, c_gitDefSize ) ); // GIT_STATUS_DELETED
148 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_out_of_date, c_gitDefSize ) ); // GIT_STATUS_BEHIND
149 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_changed_ahead, c_gitDefSize ) ); // GIT_STATUS_AHEAD
150 stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_conflict, c_gitDefSize ) ); // GIT_STATUS_CONFLICTED
151 stateImages.push_back( wxBitmapBundle( wxBitmap( c_gitDefSize, c_gitDefSize ) ) ); // GIT_STATUS_IGNORED
152
153 SetStateImages( stateImages );
154#else
155 // Make an image list containing small icons
156 wxBitmap blank_bitmap( c_gitDefSize, c_gitDefSize );
157
158 delete m_statusImageList;
159 m_statusImageList = new wxImageList( c_gitDefSize, c_gitDefSize, true,
160 static_cast<int>( KIGIT_COMMON::GIT_STATUS::GIT_STATUS_LAST ) );
161
162 m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
163 m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, c_gitDefSize ) ); // GIT_STATUS_CURRENT
164 m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, c_gitDefSize ) ); // GIT_STATUS_MODIFIED
165 m_statusImageList->Add( KiBitmap( BITMAPS::git_add, c_gitDefSize ) ); // GIT_STATUS_ADDED
166 m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, c_gitDefSize ) ); // GIT_STATUS_DELETED
167 m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, c_gitDefSize ) ); // GIT_STATUS_BEHIND
168 m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, c_gitDefSize ) ); // GIT_STATUS_AHEAD
169 m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, c_gitDefSize ) ); // GIT_STATUS_CONFLICTED
170 m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_IGNORED
171
172 SetStateImageList( m_statusImageList );
173#endif
174
175}
176
177
178void PROJECT_TREE::GetItemsRecursively( const wxTreeItemId& aParentId, std::vector<wxTreeItemId>& aItems )
179{
180 wxTreeItemIdValue cookie;
181 wxTreeItemId child = GetFirstChild( aParentId, cookie );
182
183 while( child.IsOk() )
184 {
185 aItems.push_back( child );
186 GetItemsRecursively( child, aItems );
187 child = GetNextChild( aParentId, cookie );
188 }
189}
190
191
192int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
193{
194 PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
195 PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
196
197 if( !myitem1 || !myitem2 )
198 return 0;
199
200 if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
201 && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
202 return -1;
203
204 if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
205 && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
206 return 1;
207
208 if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
209 return -1;
210
211 if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
212 return 1;
213
214 return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
215}
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Construct and return a bitmap bundle for the given icon ID, with the default bitmap size being aDefHe...
Definition bitmap.cpp:112
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:100
BITMAPS
A list of all bitmap identifiers.
@ git_out_of_date
@ icon_eeschema_24
@ icon_pagelayout_editor_24
@ file_gerber_job
@ git_changed_ahead
@ icon_gerbview_24
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
Window to display the tree files.
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
PROJECT_TREE_PANE * m_projectTreePane
void GetItemsRecursively(const wxTreeItemId &aParentId, std::vector< wxTreeItemId > &aItems)
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
wxImageList * m_statusImageList
PROJECT_TREE(PROJECT_TREE_PANE *parent)
@ ID_PROJECT_TREE
Definition kicad_id.h:32
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
#define PLATFORM_STYLE
const int scale