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