KiCad PCB EDA Suite
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>
27#include <wx/settings.h>
28
29#include "project_tree_item.h"
30#include "project_tree_pane.h"
31#include "project_tree.h"
32#include "kicad_id.h"
33
34
35IMPLEMENT_ABSTRACT_CLASS( PROJECT_TREE, wxTreeCtrl )
36
37
38#ifdef __WXMSW__
39#define PLATFORM_STYLE wxTR_LINES_AT_ROOT
40#else
41#define PLATFORM_STYLE wxTR_NO_LINES
42#endif
43
45 wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
46 PLATFORM_STYLE | wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator,
47 wxT( "EDATreeCtrl" ) ),
48 m_imageList( nullptr )
49{
50 m_projectTreePane = parent;
51
52 // Make sure the GUI font scales properly on GTK
53 SetFont( KIUI::GetControlFont( this ) );
54
55 LoadIcons();
56}
57
58
60{
61 delete m_imageList;
62}
63
64
66{
67 delete m_imageList;
68
69 // icons size is not know (depending on they are built)
70 // so get it:
71 wxSize iconsize;
73 iconsize.x = dummy.GetWidth();
74 iconsize.y = dummy.GetHeight();
75
76 // Make an image list containing small icons
77 m_imageList = new wxImageList( iconsize.x, iconsize.y, true,
78 static_cast<int>( TREE_FILE_TYPE::MAX ) );
79
80 m_imageList->Add( KiBitmap( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
81 m_imageList->Add( KiBitmap( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
82 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
83 m_imageList->Add( KiBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
84 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
85 m_imageList->Add( KiBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
86 m_imageList->Add( KiBitmap( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
87 m_imageList->Add( KiBitmap( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
88 m_imageList->Add( KiBitmap( BITMAPS::file_html ) ); // TREE_HTML
89 m_imageList->Add( KiBitmap( BITMAPS::file_pdf ) ); // TREE_PDF
90 m_imageList->Add( KiBitmap( BITMAPS::editor ) ); // TREE_TXT
91 m_imageList->Add( KiBitmap( BITMAPS::editor ) ); // TREE_MD
92 m_imageList->Add( KiBitmap( BITMAPS::netlist ) ); // TREE_NET
93 m_imageList->Add( KiBitmap( BITMAPS::unknown ) ); // TREE_UNKNOWN
94 m_imageList->Add( KiBitmap( BITMAPS::directory ) ); // TREE_DIRECTORY
95 m_imageList->Add( KiBitmap( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
96 m_imageList->Add( KiBitmap( BITMAPS::tools ) ); // TREE_REPORT
97 m_imageList->Add( KiBitmap( BITMAPS::file_pos ) ); // TREE_POS
98 m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL
99 m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
100 m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
101 m_imageList->Add( KiBitmap( BITMAPS::file_svg ) ); // TREE_SVG
102 m_imageList->Add( KiBitmap( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
103 m_imageList->Add( KiBitmap( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
104 m_imageList->Add( KiBitmap( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
105 m_imageList->Add( KiBitmap( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
106 m_imageList->Add( KiBitmap( BITMAPS::editor ) ); // DESIGN_RULES
107 m_imageList->Add( KiBitmap( BITMAPS::zip ) ); // ZIP_ARCHIVE
108
109 SetImageList( m_imageList );
110}
111
112
113int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
114{
115 PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
116 PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
117
118 if( !myitem1 || !myitem2 )
119 return 0;
120
121 if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
122 && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
123 return -1;
124
125 if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
126 && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
127 return 1;
128
129 if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
130 return -1;
131
132 if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
133 return 1;
134
135 return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
136}
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:106
@ icon_pcbnew_24
@ icon_eeschema_24
@ icon_pagelayout_editor_24
@ file_gerber_job
@ project_kicad
@ icon_cvpcb_24
@ 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.
Definition: project_tree.h:39
PROJECT_TREE_PANE * m_projectTreePane
Definition: project_tree.h:43
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
PROJECT_TREE(PROJECT_TREE_PANE *parent)
void LoadIcons()
wxImageList * m_imageList
Definition: project_tree.h:44
IDs used in KiCad main frame foe menuitems and tools.
@ ID_PROJECT_TREE
Definition: kicad_id.h:58
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:162
#define PLATFORM_STYLE
std::vector< FAB_LAYER_COLOR > dummy