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/dc.h>
26 #include <wx/imaglist.h>
27 #include <wx/wupdlock.h>
28 
29 #include <eda_item.h>
33 #include <tool/tool_manager.h>
34 
36 #include "design_inspector.h"
37 #include "pl_editor_frame.h"
38 #include "properties_frame.h"
39 #include "tools/pl_actions.h"
41 
42 /* XPM
43  * This bitmap is used to show item types
44  */
45 static const char* root_xpm[] =
46 {
47  "12 12 2 1",
48  " c None",
49  "x c #008080",
50  " xxxx ",
51  " xxx ",
52  " xxx ",
53  " xxx ",
54  "xxxxxxxxxxx ",
55  "xxxxxxxxxxxx",
56  "xxxxxxxxxxx ",
57  " xxx ",
58  " xxx ",
59  " xxx ",
60  " xxxx ",
61  " "
62 };
63 
64 static const char* line_xpm[] =
65 {
66  "12 12 2 1",
67  " c None",
68  "x c #008080",
69  "xx ",
70  "xx ",
71  "xx ",
72  "xx ",
73  "xx ",
74  "xx ",
75  "xx ",
76  "xx ",
77  "xx ",
78  "xx ",
79  "xxxxxxxxxxxx",
80  "xxxxxxxxxxxx"
81 };
82 
83 static const char* rect_xpm[] =
84 {
85  "12 12 2 1",
86  " c None",
87  "x c #000080",
88  "xxxxxxxxxxxx",
89  "xxxxxxxxxxxx",
90  "xx xx",
91  "xx xx",
92  "xx xx",
93  "xx xx",
94  "xx xx",
95  "xx xx",
96  "xx xx",
97  "xx xx",
98  "xxxxxxxxxxxx",
99  "xxxxxxxxxxxx"
100 };
101 
102 static const char* text_xpm[] =
103 {
104  "12 12 2 1",
105  " c None",
106  "x c #800000",
107  " xxxxxxxxxx ",
108  "xxxxxxxxxxxx",
109  "xx xx xx",
110  " xx ",
111  " xx ",
112  " xx ",
113  " xx ",
114  " xx ",
115  " xx ",
116  " xx ",
117  " xxxx ",
118  " xxxxxx "
119 };
120 
121 static const char* poly_xpm[] =
122 {
123  "12 12 2 1",
124  " c None",
125  "x c #008000",
126  " xx ",
127  " xxxx ",
128  " xxxxxx ",
129  " xxxxxxxx ",
130  " xxxxxxxxxx ",
131  "xxxxxxxxxxxx",
132  "xxxxxxxxxxxx",
133  " xxxxxxxxxx ",
134  " xxxxxxxx ",
135  " xxxxxx ",
136  " xxxx ",
137  " xx "
138 };
139 
140 static const char* img_xpm[] =
141 {
142  "12 12 2 1",
143  " c None",
144  "x c #800000",
145  " xx ",
146  " xxxxxx ",
147  " xx xx ",
148  "xx xx",
149  "xx xx",
150  " xx xx ",
151  " xxxxxx ",
152  " xx ",
153  " xx ",
154  " xx ",
155  " xx ",
156  " xx "
157 };
158 
159 // A helper class to draw these bitmaps into a wxGrid cell:
160 class BitmapGridCellRenderer : public wxGridCellStringRenderer
161 {
162  const char** m_BitmapXPM;
163 public:
164  BitmapGridCellRenderer( const char** aBitmapXPM )
165  {
166  m_BitmapXPM = aBitmapXPM;
167  }
168 
169  void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
170  wxDC& aDc, const wxRect& aRect,
171  int aRow, int aCol, bool aIsSelected) override;
172 };
173 
174 // Column ids for m_gridListItems
176 {
182  COL_COUNT //Sentinel
183 };
184 
185 
187  DIALOG_INSPECTOR_BASE( aParent )
188 {
189  m_editorFrame = aParent;
191 
192  // Now all widgets have the size fixed, call FinishDialogSettings
194 }
195 
196 
198 {
199 }
200 
201 
202 
204 {
205  wxWindowUpdateLocker dummy( this ); // Avoid flicker when rebuilding the tree
206  const PAGE_INFO& page_info = m_editorFrame->GetPageLayout().GetPageSettings();
207 
208  if( m_gridListItems->GetNumberRows() > 1 )
209  m_gridListItems->DeleteRows( 1, m_gridListItems->GetNumberRows() - 1 );
210 
211  m_itemsList.clear();
212 
214  wxFileName fn( static_cast<PL_EDITOR_FRAME*>( GetParent() )->GetCurrentFileName() );
215 
216  if( fn.GetName().IsEmpty() )
217  SetTitle( "<default drawing sheet>" );
218  else
219  SetTitle( fn.GetName() );
220 
221  // The first item is the layout: Display info about the page: fmt, size...
222  int row = 0;
223  GetGridList()->SetCellValue( row, COL_TYPENAME, _( "Layout" ) );
224  GetGridList()->SetCellValue( row, COL_COMMENT, page_info.GetType() ); // Display page format name
225  GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER, "-" );
226  wxSize page_sizeIU = m_editorFrame->GetPageSizeIU();
227  GetGridList()->SetCellValue( row, COL_TEXTSTRING, wxString::Format( _( "Size: %.1fx%.1fmm" ),
228  Iu2Millimeter( page_sizeIU.x ), Iu2Millimeter( page_sizeIU.y ) ) );
229  GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( root_xpm ) );
230  GetGridList()->SetReadOnly( row, COL_BITMAP );
231  m_itemsList.push_back( nullptr ); // this item is not a DS_DATA_ITEM, just a pseudo item
232 
233  // Now adding all current items
234  row++;
235  for( DS_DATA_ITEM* item : drawingSheet.GetItems() )
236  {
237  const char** img = nullptr;
238 
239  switch( item->GetType() )
240  {
242  img = line_xpm;
243  break;
244 
246  img = rect_xpm;
247  break;
248 
250  img = text_xpm;
251  break;
252 
254  img = poly_xpm;
255  break;
256 
258  img = img_xpm;
259  break;
260  }
261 
262  GetGridList()->AppendRows( 1 );
263  GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( img ) );
264  GetGridList()->SetReadOnly( row, COL_BITMAP );
265  GetGridList()->SetCellValue( row, COL_TYPENAME,item->GetClassName() );
266  GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER,
267  wxString::Format( "%d", item->m_RepeatCount ) );
268  GetGridList()->SetCellValue( row, COL_COMMENT, item->m_Info );
269 
270  if( item->GetType() == DS_DATA_ITEM::DS_TEXT )
271  {
272  DS_DATA_ITEM_TEXT* t_item = static_cast<DS_DATA_ITEM_TEXT*>( item );
273  GetGridList()->SetCellValue( row, COL_TEXTSTRING, t_item->m_TextBase );
274  }
275 
276  m_itemsList.push_back( item );
277  row++;
278  }
279 
280  // Now resize the columns:
281  int cols_to_resize[] =
282  {
284  };
285 
286  for( int ii = 0; ; ii++ )
287  {
288  int col = cols_to_resize[ii];
289 
290  if( col == COL_COUNT )
291  break;
292 
293  if( col == COL_BITMAP )
294  {
295  #define BITMAP_SIZE 16
296  GetGridList()->SetColMinimalWidth( col, BITMAP_SIZE*2 );
297  GetGridList()->AutoSizeColumn( col, false );
298  }
299  else
300  GetGridList()->AutoSizeColumn( col );
301 
302  GetGridList()->AutoSizeColLabelSize( col );
303  }
304 }
305 
306 
307 // Select the row corresponding to the DS_DATA_ITEM aItem
309 {
310  // m_itemsList[0] is not a true DS_DATA_ITEM
311  for( unsigned row = 1; row < m_itemsList.size(); ++row )
312  {
313  if( m_itemsList[row] == aItem )
314  {
315  GetGridList()->GoToCell( row, COL_TYPENAME );
316  GetGridList()->SelectRow( row );
317  break;
318  }
319  }
320 }
321 
322 //return the drawing sheet item managed by the cell
324 {
325  return ( aRow >= 0 && aRow < (int)m_itemsList.size() ) ? m_itemsList[aRow]: nullptr;
326 }
327 
328 
329 void DIALOG_INSPECTOR::onCellClicked( wxGridEvent& event )
330 {
331  int row = event.GetRow();
332  GetGridList()->SelectRow( row );
333 
334  DS_DATA_ITEM* item = GetDrawingSheetDataItem( row );
335 
336  if( !item ) // only DS_DATA_ITEM are returned.
337  return;
338 
339  // Select this item in drawing sheet editor, and update the properties panel:
341  selectionTool->ClearSelection();
342  EDA_ITEM* draw_item = item->GetDrawItems()[0];
343  selectionTool->AddItemToSel( draw_item );
346 }
347 
348 
349 void BitmapGridCellRenderer::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
350  wxDC& aDc, const wxRect& aRect,
351  int aRow, int aCol, bool aIsSelected)
352 {
353  wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected);
354  wxBitmap bm( m_BitmapXPM );
355  aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true);
356 }
357 
358 
360 {
361  DIALOG_INSPECTOR dlg( this );
362 
363  dlg.ShowModal();
364 }
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.
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()
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 LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
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
#define _(s)
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ds_data_item.h:110
static const char * rect_xpm[]
static const char * root_xpm[]
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
static const char * poly_xpm[]
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
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:54
const PL_EDITOR_LAYOUT & GetPageLayout() const
static const char * text_xpm[]