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