KiCad PCB EDA Suite
treeprojectfiles.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 
31 #include <bitmaps.h>
32 
33 #include "treeproject_item.h"
34 #include "tree_project_frame.h"
35 #include "treeprojectfiles.h"
36 #include "kicad_id.h"
37 
38 
39 IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl )
40 
41 
43  : wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
44  wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator, wxT( "EDATreeCtrl" ) )
45 {
46  m_Parent = parent;
47 
48  // icons size is not know (depending on they are built)
49  // so get it:
50  wxSize iconsize;
51  wxBitmap dummy = KiBitmap( eeschema_xpm );
52  iconsize.x = dummy.GetWidth();
53  iconsize.y = dummy.GetHeight();
54 
55  // Make an image list containing small icons
56  m_ImageList = new wxImageList( iconsize.x, iconsize.y, true, TREE_MAX );
57 
58  m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_LEGACY_PROJECT
59  m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_JSON_PROJECT
60  m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC
61  m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC
62  m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB
63  m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_SEXPR_PCB
64  m_ImageList->Add( KiBitmap( icon_gerbview_small_xpm ) ); // TREE_GERBER
65  m_ImageList->Add( KiBitmap( gerber_job_file_xpm ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
66  m_ImageList->Add( KiBitmap( html_xpm ) ); // TREE_HTML
67  m_ImageList->Add( KiBitmap( datasheet_xpm ) ); // TREE_PDF
68  m_ImageList->Add( KiBitmap( editor_xpm ) ); // TREE_TXT
69  m_ImageList->Add( KiBitmap( netlist_xpm ) ); // TREE_NET
70  m_ImageList->Add( KiBitmap( unknown_xpm ) ); // TREE_UNKNOWN
71  m_ImageList->Add( KiBitmap( directory_xpm ) ); // TREE_DIRECTORY
72  m_ImageList->Add( KiBitmap( icon_cvpcb_small_xpm ) ); // TREE_CMP_LINK
73  m_ImageList->Add( KiBitmap( tools_xpm ) ); // TREE_REPORT
74  m_ImageList->Add( KiBitmap( post_compo_xpm ) ); // TREE_POS
75  m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL
76  m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_NC (similar TREE_DRILL)
77  m_ImageList->Add( KiBitmap( post_drill_xpm ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
78  m_ImageList->Add( KiBitmap( svg_file_xpm ) ); // TREE_SVG
79  m_ImageList->Add( KiBitmap( pagelayout_load_xpm ) ); // TREE_PAGE_LAYOUT_DESCR
80  m_ImageList->Add( KiBitmap( module_xpm ) ); // TREE_FOOTPRINT_FILE
81  m_ImageList->Add( KiBitmap( library_xpm ) ); // TREE_SCHEMATIC_LIBFILE
82  m_ImageList->Add( KiBitmap( library_xpm ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
83 
84  SetImageList( m_ImageList );
85 }
86 
87 
89 {
90  delete m_ImageList;
91 }
92 
93 
94 int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
95 {
96  TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 );
97  TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 );
98 
99  if( !myitem1 || !myitem2 )
100  return 0;
101 
102  if( myitem1->GetType() == TREE_DIRECTORY && myitem2->GetType() != TREE_DIRECTORY )
103  return -1;
104 
105  if( myitem2->GetType() == TREE_DIRECTORY && myitem1->GetType() != TREE_DIRECTORY )
106  return 1;
107 
108  if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
109  return -1;
110 
111  if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
112  return 1;
113 
114  return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
115 }
bool IsRootFile() const
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
IDs used in KiCad main frame foe menuitems and tools.
const BITMAP_OPAQUE module_xpm[1]
Definition: module.cpp:29
const BITMAP_OPAQUE icon_cvpcb_small_xpm[1]
const BITMAP_OPAQUE editor_xpm[1]
Definition: editor.cpp:83
TREEPROJECTFILES This is the class to show (as a tree) the files in the project directory.
const BITMAP_OPAQUE new_project_xpm[1]
Definition: new_project.cpp:32
wxImageList * m_ImageList
const BITMAP_OPAQUE pagelayout_load_xpm[1]
TreeFileType GetType() const
const BITMAP_OPAQUE gerber_job_file_xpm[1]
const BITMAP_OPAQUE svg_file_xpm[1]
Definition: svg_file.cpp:68
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE datasheet_xpm[1]
Definition: datasheet.cpp:76
const BITMAP_OPAQUE library_xpm[1]
Definition: library.cpp:71
TREE_PROJECT_FRAME Window to display the tree files.
const BITMAP_OPAQUE html_xpm[1]
Definition: html.cpp:65
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
const BITMAP_OPAQUE pcbnew_xpm[1]
const BITMAP_OPAQUE tools_xpm[1]
Definition: tools.cpp:113
const BITMAP_OPAQUE directory_xpm[1]
Definition: directory.cpp:30
const BITMAP_OPAQUE unknown_xpm[1]
Definition: unknown.cpp:60
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
const BITMAP_OPAQUE netlist_xpm[1]
const BITMAP_OPAQUE eeschema_xpm[1]
const BITMAP_OPAQUE post_drill_xpm[1]
Definition: post_drill.cpp:61
const wxString & GetFileName() const
const BITMAP_OPAQUE icon_gerbview_small_xpm[1]
const BITMAP_OPAQUE post_compo_xpm[1]
Definition: post_compo.cpp:96