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 */
45static 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
64static 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
83static 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
102static 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
121static 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
140static 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:
160class BitmapGridCellRenderer : public wxGridCellStringRenderer
161{
162 const char** m_BitmapXPM;
163public:
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
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
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 drawSheetIUScale.IUTomm( page_sizeIU.x ),
229 drawSheetIUScale.IUTomm( page_sizeIU.y ) ) );
230 GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( root_xpm ) );
231 GetGridList()->SetReadOnly( row, COL_BITMAP );
232 m_itemsList.push_back( nullptr ); // this item is not a DS_DATA_ITEM, just a pseudo item
233
234 // Now adding all current items
235 row++;
236 for( DS_DATA_ITEM* item : drawingSheet.GetItems() )
237 {
238 const char** img = nullptr;
239
240 switch( item->GetType() )
241 {
243 img = line_xpm;
244 break;
245
247 img = rect_xpm;
248 break;
249
251 img = text_xpm;
252 break;
253
255 img = poly_xpm;
256 break;
257
259 img = img_xpm;
260 break;
261 }
262
263 GetGridList()->AppendRows( 1 );
264 GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( img ) );
265 GetGridList()->SetReadOnly( row, COL_BITMAP );
266 GetGridList()->SetCellValue( row, COL_TYPENAME,item->GetClassName() );
267 GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER,
268 wxString::Format( "%d", item->m_RepeatCount ) );
269 GetGridList()->SetCellValue( row, COL_COMMENT, item->m_Info );
270
271 if( item->GetType() == DS_DATA_ITEM::DS_TEXT )
272 {
273 DS_DATA_ITEM_TEXT* t_item = static_cast<DS_DATA_ITEM_TEXT*>( item );
274 GetGridList()->SetCellValue( row, COL_TEXTSTRING, t_item->m_TextBase );
275 }
276
277 m_itemsList.push_back( item );
278 row++;
279 }
280
281 // Now resize the columns:
282 int cols_to_resize[] =
283 {
285 };
286
287 for( int ii = 0; ; ii++ )
288 {
289 int col = cols_to_resize[ii];
290
291 if( col == COL_COUNT )
292 break;
293
294 if( col == COL_BITMAP )
295 {
296 #define BITMAP_SIZE 16
297 GetGridList()->SetColMinimalWidth( col, BITMAP_SIZE*2 );
298 GetGridList()->AutoSizeColumn( col, false );
299 }
300 else
301 GetGridList()->AutoSizeColumn( col );
302
303 GetGridList()->AutoSizeColLabelSize( col );
304 }
305}
306
307
308// Select the row corresponding to the DS_DATA_ITEM aItem
310{
311 // m_itemsList[0] is not a true DS_DATA_ITEM
312 for( unsigned row = 1; row < m_itemsList.size(); ++row )
313 {
314 if( m_itemsList[row] == aItem )
315 {
316 GetGridList()->GoToCell( row, COL_TYPENAME );
317 GetGridList()->SelectRow( row );
318 break;
319 }
320 }
321}
322
323//return the drawing sheet item managed by the cell
325{
326 return ( aRow >= 0 && aRow < (int)m_itemsList.size() ) ? m_itemsList[aRow]: nullptr;
327}
328
329
330void DIALOG_INSPECTOR::onCellClicked( wxGridEvent& event )
331{
332 int row = event.GetRow();
333 GetGridList()->SelectRow( row );
334
336
337 if( !item ) // only DS_DATA_ITEM are returned.
338 return;
339
340 // Select this item in drawing sheet editor, and update the properties panel:
342 selectionTool->ClearSelection();
343 EDA_ITEM* draw_item = item->GetDrawItems()[0];
344 selectionTool->AddItemToSel( draw_item );
347}
348
349
350void BitmapGridCellRenderer::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
351 wxDC& aDc, const wxRect& aRect,
352 int aRow, int aCol, bool aIsSelected)
353{
354 wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected);
355 wxBitmap bm( m_BitmapXPM );
356 aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true);
357}
358
359
361{
362 DIALOG_INSPECTOR dlg( this );
363
364 dlg.ShowModal();
365}
constexpr EDA_IU_SCALE drawSheetIUScale
Definition: base_units.h:110
BitmapGridCellRenderer(const char **aBitmapXPM)
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDc, const wxRect &aRect, int aRow, int aCol, bool aIsSelected) override
Class DIALOG_INSPECTOR_BASE.
DESIGN_INSPECTOR is the left window showing the list of items.
void onCellClicked(wxGridEvent &event) override
DS_DATA_ITEM * GetDrawingSheetDataItem(int aRow) const
wxGrid * GetGridList() const
void SelectRow(DS_DATA_ITEM *aItem)
DIALOG_INSPECTOR(PL_EDITOR_FRAME *aParent)
PL_EDITOR_FRAME * m_editorFrame
std::vector< DS_DATA_ITEM * > m_itemsList
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Drawing sheet structure type definitions.
Definition: ds_data_item.h:96
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ds_data_item.h:110
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:39
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
std::vector< DS_DATA_ITEM * > & GetItems()
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:85
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
const wxString & GetType() const
Definition: page_info.h:94
The main window used in the drawing sheet editor.
void ShowDesignInspector()
Show the dialog displaying the list of DS_DATA_ITEM items in the page layout.
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PROPERTIES_FRAME * GetPropertiesFrame()
const PL_EDITOR_LAYOUT & GetPageLayout() const
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PAGE_INFO & GetPageSettings()
int ClearSelection(const TOOL_EVENT &aEvent)
void CopyPrmsFromItemToPanel(DS_DATA_ITEM *aItem)
int AddItemToSel(const TOOL_EVENT &aEvent)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
static const char * poly_xpm[]
static const char * root_xpm[]
static const char * text_xpm[]
@ COL_COMMENT
@ COL_REPEAT_NUMBER
@ COL_COUNT
@ COL_BITMAP
@ COL_TEXTSTRING
@ COL_TYPENAME
static const char * rect_xpm[]
#define BITMAP_SIZE
static const char * line_xpm[]
static const char * img_xpm[]
#define _(s)
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
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
constexpr double IUTomm(int iu) const
Definition: base_units.h:87