KiCad PCB EDA Suite
design_inspector.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) 2019 jp.charras at wanadoo.fr
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <wx/imaglist.h>
26 #include <wx/wupdlock.h>
27 
28 #include <eda_item.h>
32 #include <tool/tool_manager.h>
33 
35 #include "design_inspector.h"
36 #include "pl_editor_frame.h"
37 #include "properties_frame.h"
38 #include "tools/pl_actions.h"
40 
41 /* XPM
42  * This bitmap is used to show item types
43  */
44 static const char* root_xpm[] =
45 {
46  "12 12 2 1",
47  " c None",
48  "x c #008080",
49  " xxxx ",
50  " xxx ",
51  " xxx ",
52  " xxx ",
53  "xxxxxxxxxxx ",
54  "xxxxxxxxxxxx",
55  "xxxxxxxxxxx ",
56  " xxx ",
57  " xxx ",
58  " xxx ",
59  " xxxx ",
60  " "
61 };
62 
63 static const char* line_xpm[] =
64 {
65  "12 12 2 1",
66  " c None",
67  "x c #008080",
68  "xx ",
69  "xx ",
70  "xx ",
71  "xx ",
72  "xx ",
73  "xx ",
74  "xx ",
75  "xx ",
76  "xx ",
77  "xx ",
78  "xxxxxxxxxxxx",
79  "xxxxxxxxxxxx"
80 };
81 
82 static const char* rect_xpm[] =
83 {
84  "12 12 2 1",
85  " c None",
86  "x c #000080",
87  "xxxxxxxxxxxx",
88  "xxxxxxxxxxxx",
89  "xx xx",
90  "xx xx",
91  "xx xx",
92  "xx xx",
93  "xx xx",
94  "xx xx",
95  "xx xx",
96  "xx xx",
97  "xxxxxxxxxxxx",
98  "xxxxxxxxxxxx"
99 };
100 
101 static const char* text_xpm[] =
102 {
103  "12 12 2 1",
104  " c None",
105  "x c #800000",
106  " xxxxxxxxxx ",
107  "xxxxxxxxxxxx",
108  "xx xx xx",
109  " xx ",
110  " xx ",
111  " xx ",
112  " xx ",
113  " xx ",
114  " xx ",
115  " xx ",
116  " xxxx ",
117  " xxxxxx "
118 };
119 
120 static const char* poly_xpm[] =
121 {
122  "12 12 2 1",
123  " c None",
124  "x c #008000",
125  " xx ",
126  " xxxx ",
127  " xxxxxx ",
128  " xxxxxxxx ",
129  " xxxxxxxxxx ",
130  "xxxxxxxxxxxx",
131  "xxxxxxxxxxxx",
132  " xxxxxxxxxx ",
133  " xxxxxxxx ",
134  " xxxxxx ",
135  " xxxx ",
136  " xx "
137 };
138 
139 static const char* img_xpm[] =
140 {
141  "12 12 2 1",
142  " c None",
143  "x c #800000",
144  " xx ",
145  " xxxxxx ",
146  " xx xx ",
147  "xx xx",
148  "xx xx",
149  " xx xx ",
150  " xxxxxx ",
151  " xx ",
152  " xx ",
153  " xx ",
154  " xx ",
155  " xx "
156 };
157 
158 // A helper class to draw these bitmaps into a wxGrid cell:
159 class BitmapGridCellRenderer : public wxGridCellStringRenderer
160 {
161  const char** m_BitmapXPM;
162 public:
163  BitmapGridCellRenderer( const char** aBitmapXPM )
164  {
165  m_BitmapXPM = aBitmapXPM;
166  }
167 
168  void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
169  wxDC& aDc, const wxRect& aRect,
170  int aRow, int aCol, bool aIsSelected) override;
171 };
172 
173 // Column ids for m_gridListItems
175 {
181  COL_COUNT //Sentinel
182 };
183 
184 
186  DIALOG_INSPECTOR_BASE( aParent )
187 {
188  m_editorFrame = aParent;
190 
191  // Now all widgets have the size fixed, call FinishDialogSettings
193 }
194 
195 
197 {
198 }
199 
200 
201 
203 {
204  wxWindowUpdateLocker dummy( this ); // Avoid flicker when rebuilding the tree
205  const PAGE_INFO& page_info = m_editorFrame->GetPageLayout().GetPageSettings();
206 
207  if( m_gridListItems->GetNumberRows() > 1 )
208  m_gridListItems->DeleteRows( 1, m_gridListItems->GetNumberRows() - 1 );
209 
210  m_itemsList.clear();
211 
213  wxFileName fn( static_cast<PL_EDITOR_FRAME*>( GetParent() )->GetCurrentFileName() );
214 
215  if( fn.GetName().IsEmpty() )
216  SetTitle( "<default page layout>" );
217  else
218  SetTitle( fn.GetName() );
219 
220  // The first item is the layout: Display info about the page: fmt, size...
221  int row = 0;
222  GetGridList()->SetCellValue( row, COL_TYPENAME, _( "Layout" ) );
223  GetGridList()->SetCellValue( row, COL_COMMENT, page_info.GetType() ); // Display page format name
224  GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER, "-" );
225  wxSize page_sizeIU = m_editorFrame->GetPageSizeIU();
226  GetGridList()->SetCellValue( row, COL_TEXTSTRING, wxString::Format( _( "Size: %.1fx%.1fmm" ),
227  Iu2Millimeter( page_sizeIU.x ), Iu2Millimeter( page_sizeIU.y ) ) );
228  GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( root_xpm ) );
229  GetGridList()->SetReadOnly( row, COL_BITMAP );
230  m_itemsList.push_back( nullptr ); // this item is not a DS_DATA_ITEM, just a pseudo item
231 
232  // Now adding all current items
233  row++;
234  for( DS_DATA_ITEM* item : drawingSheet.GetItems() )
235  {
236  const char** img = nullptr;
237 
238  switch( item->GetType() )
239  {
241  img = line_xpm;
242  break;
243 
245  img = rect_xpm;
246  break;
247 
249  img = text_xpm;
250  break;
251 
253  img = poly_xpm;
254  break;
255 
257  img = img_xpm;
258  break;
259  }
260 
261  GetGridList()->AppendRows( 1 );
262  GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( img ) );
263  GetGridList()->SetReadOnly( row, COL_BITMAP );
264  GetGridList()->SetCellValue( row, COL_TYPENAME,item->GetClassName() );
265  GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER,
266  wxString::Format( "%d", item->m_RepeatCount ) );
267  GetGridList()->SetCellValue( row, COL_COMMENT, item->m_Info );
268 
269  if( item->GetType() == DS_DATA_ITEM::DS_TEXT )
270  {
271  DS_DATA_ITEM_TEXT* t_item = static_cast<DS_DATA_ITEM_TEXT*>( item );
272  GetGridList()->SetCellValue( row, COL_TEXTSTRING, t_item->m_TextBase );
273  }
274 
275  m_itemsList.push_back( item );
276  row++;
277  }
278 
279  // Now resize the columns:
280  int cols_to_resize[] =
281  {
283  };
284 
285  for( int ii = 0; ; ii++ )
286  {
287  int col = cols_to_resize[ii];
288 
289  if( col == COL_COUNT )
290  break;
291 
292  if( col == COL_BITMAP )
293  {
294  #define BITMAP_SIZE 16
295  GetGridList()->SetColMinimalWidth( col, BITMAP_SIZE*2 );
296  GetGridList()->AutoSizeColumn( col, false );
297  }
298  else
299  GetGridList()->AutoSizeColumn( col );
300 
301  GetGridList()->AutoSizeColLabelSize( col );
302  }
303 }
304 
305 
306 // Select the row corresponding to the DS_DATA_ITEM aItem
308 {
309  // m_itemsList[0] is not a true DS_DATA_ITEM
310  for( unsigned row = 1; row < m_itemsList.size(); ++row )
311  {
312  if( m_itemsList[row] == aItem )
313  {
314  GetGridList()->GoToCell( row, COL_TYPENAME );
315  GetGridList()->SelectRow( row );
316  break;
317  }
318  }
319 }
320 
321 //return the page layout item managed by the cell
323 {
324  return ( aRow >= 0 && aRow < (int)m_itemsList.size() ) ? m_itemsList[aRow]: nullptr;
325 }
326 
327 
328 void DIALOG_INSPECTOR::onCellClicked( wxGridEvent& event )
329 {
330  int row = event.GetRow();
331  GetGridList()->SelectRow( row );
332 
333  DS_DATA_ITEM* item = GetDrawingSheetDataItem( row );
334 
335  if( !item ) // only DS_DATA_ITEM are returned.
336  return;
337 
338  // Select this item in drawing sheet editor, and update the properties panel:
340  selectionTool->ClearSelection();
341  EDA_ITEM* draw_item = item->GetDrawItems()[0];
342  selectionTool->AddItemToSel( draw_item );
345 }
346 
347 
348 void BitmapGridCellRenderer::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
349  wxDC& aDc, const wxRect& aRect,
350  int aRow, int aCol, bool aIsSelected)
351 {
352  wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected);
353  wxBitmap bm( m_BitmapXPM );
354  aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true);
355 }
356 
357 
359 {
360  DIALOG_INSPECTOR dlg( this );
361 
362  dlg.ShowModal();
363 }
DIALOG_INSPECTOR(PL_EDITOR_FRAME *aParent)
PROPERTIES_FRAME * GetPropertiesFrame()
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:38
Class DIALOG_INSPECTOR_BASE.
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PL_EDITOR_FRAME is the main window used in the drawing sheet editor.
static const char * line_xpm[]
int ClearSelection(const TOOL_EVENT &aEvent)
std::vector< DS_DATA_ITEM * > & GetItems()
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
const wxString & GetType() const
Definition: page_info.h:94
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void onCellClicked(wxGridEvent &event) override
int AddItemToSel(const TOOL_EVENT &aEvent)
PAGE_INFO & GetPageSettings()
static const char * img_xpm[]
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
DS_DATA_ITEM * GetDrawingSheetDataItem(int aRow) const
void ShowDesignInspector()
Show the dialog displaying the list of DS_DATA_ITEM items in the page layout.
std::vector< DS_DATA_ITEM * > m_itemsList
#define BITMAP_SIZE
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ds_data_item.h:111
static const char * rect_xpm[]
static const char * root_xpm[]
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SelectRow(DS_DATA_ITEM *aItem)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
PL_EDITOR_FRAME * m_editorFrame
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
BitmapGridCellRenderer(const char **aBitmapXPM)
wxGrid * GetGridList() const
Drawing sheet structure type definitions.
Definition: ds_data_item.h:95
#define _(s)
Definition: 3d_actions.cpp:33
static const char * poly_xpm[]
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
DESIGN_INSPECTOR is the left window showing the list of items.
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDc, const wxRect &aRect, int aRow, int aCol, bool aIsSelected) override
void CopyPrmsFromItemToPanel(DS_DATA_ITEM *aItem)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
const PL_EDITOR_LAYOUT & GetPageLayout() const
static const char * text_xpm[]