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-2020 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 
35 IMPLEMENT_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::netlist ) ); // TREE_NET
92  m_imageList->Add( KiBitmap( BITMAPS::unknown ) ); // TREE_UNKNOWN
93  m_imageList->Add( KiBitmap( BITMAPS::directory ) ); // TREE_DIRECTORY
94  m_imageList->Add( KiBitmap( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
95  m_imageList->Add( KiBitmap( BITMAPS::tools ) ); // TREE_REPORT
96  m_imageList->Add( KiBitmap( BITMAPS::file_pos ) ); // TREE_POS
97  m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL
98  m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
99  m_imageList->Add( KiBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
100  m_imageList->Add( KiBitmap( BITMAPS::file_svg ) ); // TREE_SVG
101  m_imageList->Add( KiBitmap( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
102  m_imageList->Add( KiBitmap( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
103  m_imageList->Add( KiBitmap( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
104  m_imageList->Add( KiBitmap( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
105  m_imageList->Add( KiBitmap( BITMAPS::editor ) ); // DESIGN_RULES
106 
107  SetImageList( m_imageList );
108 }
109 
110 
111 int PROJECT_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
112 {
113  PROJECT_TREE_ITEM* myitem1 = (PROJECT_TREE_ITEM*) GetItemData( item1 );
114  PROJECT_TREE_ITEM* myitem2 = (PROJECT_TREE_ITEM*) GetItemData( item2 );
115 
116  if( !myitem1 || !myitem2 )
117  return 0;
118 
119  if( myitem1->GetType() == TREE_FILE_TYPE::DIRECTORY
120  && myitem2->GetType() != TREE_FILE_TYPE::DIRECTORY )
121  return -1;
122 
123  if( myitem2->GetType() == TREE_FILE_TYPE::DIRECTORY
124  && myitem1->GetType() != TREE_FILE_TYPE::DIRECTORY )
125  return 1;
126 
127  if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
128  return -1;
129 
130  if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
131  return 1;
132 
133  return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
134 }
const wxString & GetFileName() const
IDs used in KiCad main frame foe menuitems and tools.
wxImageList * m_imageList
Definition: project_tree.h:44
TREE_FILE_TYPE GetType() const
PROJECT_TREE_PANE * m_projectTreePane
Definition: project_tree.h:43
bool IsRootFile() const
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:150
PROJECT_TREE_PANE Window to display the tree files.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
#define PLATFORM_STYLE
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:105
void LoadIcons()
PROJECT_TREE(PROJECT_TREE_PANE *parent)
Handle one item (a file or a directory name) for the tree file.
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
Definition: project_tree.h:38