KiCad PCB EDA Suite
design_tree_frame.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2013 CERN
9  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <wx/imaglist.h>
30 #include <wx/wupdlock.h>
31 #include <fctsys.h>
34 #include <pl_editor_id.h>
35 #include <design_tree_frame.h>
36 
37 /* XPM
38  * This bitmap is used to show item types
39  */
40 static const char* root_xpm[] =
41 {
42  "12 12 2 1",
43  " c None",
44  "x c #008080",
45  " xxxx ",
46  " xxx ",
47  " xxx ",
48  " xxx ",
49  "xxxxxxxxxxx ",
50  "xxxxxxxxxxxx",
51  "xxxxxxxxxxx ",
52  " xxx ",
53  " xxx ",
54  " xxx ",
55  " xxxx ",
56  " "
57 };
58 
59 static const char* line_xpm[] =
60 {
61  "12 12 2 1",
62  " c None",
63  "x c #008080",
64  "xx ",
65  "xx ",
66  "xx ",
67  "xx ",
68  "xx ",
69  "xx ",
70  "xx ",
71  "xx ",
72  "xx ",
73  "xx ",
74  "xxxxxxxxxxxx",
75  "xxxxxxxxxxxx"
76 };
77 
78 static const char* rect_xpm[] =
79 {
80  "12 12 2 1",
81  " c None",
82  "x c #000080",
83  "xxxxxxxxxxxx",
84  "xxxxxxxxxxxx",
85  "xx xx",
86  "xx xx",
87  "xx xx",
88  "xx xx",
89  "xx xx",
90  "xx xx",
91  "xx xx",
92  "xx xx",
93  "xxxxxxxxxxxx",
94  "xxxxxxxxxxxx"
95 };
96 
97 static const char* text_xpm[] =
98 {
99  "12 12 2 1",
100  " c None",
101  "x c #800000",
102  " xxxxxxxxxx ",
103  "xxxxxxxxxxxx",
104  "xx xx xx",
105  " xx ",
106  " xx ",
107  " xx ",
108  " xx ",
109  " xx ",
110  " xx ",
111  " xx ",
112  " xxxx ",
113  " xxxxxx "
114 };
115 
116 static const char* poly_xpm[] =
117 {
118  "12 12 2 1",
119  " c None",
120  "x c #008000",
121  " xx ",
122  " xxxx ",
123  " xxxxxx ",
124  " xxxxxxxx ",
125  " xxxxxxxxxx ",
126  "xxxxxxxxxxxx",
127  "xxxxxxxxxxxx",
128  " xxxxxxxxxx ",
129  " xxxxxxxx ",
130  " xxxxxx ",
131  " xxxx ",
132  " xx "
133 };
134 
135 static const char* img_xpm[] =
136 {
137  "12 12 2 1",
138  " c None",
139  "x c #800000",
140  " xx ",
141  " xxxxxx ",
142  " xx xx ",
143  "xx xx",
144  "xx xx",
145  " xx xx ",
146  " xxxxxx ",
147  " xx ",
148  " xx ",
149  " xx ",
150  " xx ",
151  " xx "
152 };
153 
154 // Event table:
155 
156 
158  wxTreeCtrl( aParent, ID_DESIGN_TREE_FRAME )
159 {
160  // icons size is not know (depending on they are built)
161  // so get it:
162  wxSize iconsize;
163  wxBitmap root_bm( root_xpm );
164 
165  iconsize.x = root_bm.GetWidth();
166  iconsize.y = root_bm.GetHeight();
167 
168  // Make an image list containing small icons
169  m_imageList = new wxImageList( iconsize.x, iconsize.y, true, 6 );
170 
171  m_imageList->Add( root_bm ); // root symbol
172  m_imageList->Add( wxBitmap( line_xpm ) ); // line item
173  m_imageList->Add( wxBitmap( rect_xpm ) ); // rect item
174  m_imageList->Add( wxBitmap( text_xpm ) ); // text item
175  m_imageList->Add( wxBitmap( poly_xpm ) ); // poly item
176  m_imageList->Add( wxBitmap( img_xpm ) ); // bitmap item
177 
178  SetImageList( m_imageList );
179 }
180 
181 
183 {
184  delete m_imageList;
185 }
186 
187 
189 {
190  return wxSize( 100, -1 );
191 }
192 
193 
195 {
196  wxWindowUpdateLocker dummy(this); // Avoid flicker when rebuilding the tree
197 
198  DeleteAllItems();
199 
201 
202  // root tree:
203  wxFileName fn( ((PL_EDITOR_FRAME*) GetParent())->GetCurrFileName() );
204  wxTreeItemId rootitem;
205 
206  if( fn.GetName().IsEmpty() )
207  rootitem = AddRoot( wxT( "<default>" ), 0, 0 );
208  else
209  rootitem = AddRoot( fn.GetName(), 0, 0 );
210 
211  SetItemBold( rootitem, true );
212 
213  // Now adding all current items
214  for( unsigned ii = 0; ii < pglayout.GetCount(); ii++ )
215  {
216  WORKSHEET_DATAITEM* item = pglayout.GetItem( ii );
217  int img = 0;
218  switch( item->GetType() )
219  {
220  case WORKSHEET_DATAITEM::WS_SEGMENT: img = 1; break;
221  case WORKSHEET_DATAITEM::WS_RECT: img = 2; break;
222  case WORKSHEET_DATAITEM::WS_TEXT: img = 3; break;
223  case WORKSHEET_DATAITEM::WS_POLYPOLYGON: img = 4; break;
224  case WORKSHEET_DATAITEM::WS_BITMAP: img = 5; break;
225  }
226  wxTreeItemId cell= AppendItem( rootitem, item->m_Name, img, img );
227  DESIGN_TREE_ITEM_DATA* data = new DESIGN_TREE_ITEM_DATA( item );
228  SetItemData( cell, data );
229  }
230 
231  Expand( rootitem );
232 }
233 
234 
235 // Select the tree item corresponding to the WORKSHEET_DATAITEM aItem
237 {
238  wxTreeItemId rootcell = GetRootItem();
239  wxTreeItemIdValue cookie;
240 
241  wxTreeItemId cell = GetFirstChild( rootcell, cookie );
242 
243  while( cell.IsOk() )
244  {
245  DESIGN_TREE_ITEM_DATA* data = (DESIGN_TREE_ITEM_DATA*) GetItemData( cell );
246 
247  if( data->GetItem() == aItem )
248  {
249  SelectItem( cell );
250  return;
251  }
252 
253  cell = GetNextChild( rootcell, cookie );
254  }
255 }
256 
257 //return the page layout item managed by the cell
259 {
260  DESIGN_TREE_ITEM_DATA* data = (DESIGN_TREE_ITEM_DATA*) GetItemData( aCell );
261  if( data )
262  return data->GetItem();
263  else
264  return NULL;
265 }
266 
267 /* return the page layout item managed by the selected cell (or NULL)
268  */
270 {
271  wxTreeItemId cell;
272  cell = GetSelection();
273 
274  if( cell.IsOk() )
275  return GetPageLayoutItem( cell );
276 
277  return NULL;
278 }
279 
280 /* return the page layout item index managed by the selected cell (or -1)
281  */
283 {
285 
286  if( item == NULL )
287  return -1;
288 
290  return pglayout.GetItemIndex( item );
291 }
static const char * line_xpm[]
static const char * rect_xpm[]
WORKSHEET_DATAITEM * GetPageLayoutItem(wxTreeItemId aCell) const
description of graphic items and texts to build a title block
void SelectCell(WORKSHEET_DATAITEM *aItem)
wxSize GetMinSize() const override
wxImageList * m_imageList
int GetItemIndex(WORKSHEET_DATAITEM *aItem) const
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
DESIGN_TREE_FRAME(PL_EDITOR_FRAME *aParent)
WORKSHEET_DATAITEM * GetItem(unsigned aIdx) const
static const char * poly_xpm[]
class DESIGN_TREE_ITEM Handle one item for the page layoiut design
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
unsigned GetCount() const
static const char * root_xpm[]
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
WS_ItemType GetType() const
classes and function to generate graphics to plt or draw titles blocks and frame references ...
static const char * text_xpm[]
WORKSHEET_DATAITEM * GetItem() const
static const char * img_xpm[]
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const