2019-06-14 18:14:41 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 jp.charras at wanadoo.fr
|
2023-02-08 13:26:54 +00:00
|
|
|
* Copyright (C) 2019, 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-06-14 18:14:41 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file design_inspector.cpp
|
|
|
|
*/
|
|
|
|
|
2021-06-03 22:32:32 +00:00
|
|
|
#include <wx/dc.h>
|
2019-06-14 18:14:41 +00:00
|
|
|
#include <wx/imaglist.h>
|
|
|
|
#include <wx/wupdlock.h>
|
2020-10-02 12:29:17 +00:00
|
|
|
|
2020-10-14 02:46:39 +00:00
|
|
|
#include <eda_item.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
2019-06-14 18:14:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-10-13 05:04:31 +00:00
|
|
|
|
|
|
|
#include "dialogs/dialog_design_inspector_base.h"
|
|
|
|
#include "design_inspector.h"
|
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "properties_frame.h"
|
|
|
|
#include "tools/pl_actions.h"
|
|
|
|
#include "tools/pl_selection_tool.h"
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
|
2019-06-14 18:14:41 +00:00
|
|
|
/* XPM
|
|
|
|
* This bitmap is used to show item types
|
|
|
|
*/
|
|
|
|
static const char* root_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #008080",
|
|
|
|
" xxxx ",
|
|
|
|
" xxx ",
|
|
|
|
" xxx ",
|
|
|
|
" xxx ",
|
|
|
|
"xxxxxxxxxxx ",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xxxxxxxxxxx ",
|
|
|
|
" xxx ",
|
|
|
|
" xxx ",
|
|
|
|
" xxx ",
|
|
|
|
" xxxx ",
|
|
|
|
" "
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* line_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #008080",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xx ",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xxxxxxxxxxxx"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* rect_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #000080",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xxxxxxxxxxxx"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* text_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #800000",
|
|
|
|
" xxxxxxxxxx ",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xx xx xx",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xxxx ",
|
|
|
|
" xxxxxx "
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* poly_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #008000",
|
|
|
|
" xx ",
|
|
|
|
" xxxx ",
|
|
|
|
" xxxxxx ",
|
|
|
|
" xxxxxxxx ",
|
|
|
|
" xxxxxxxxxx ",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
"xxxxxxxxxxxx",
|
|
|
|
" xxxxxxxxxx ",
|
|
|
|
" xxxxxxxx ",
|
|
|
|
" xxxxxx ",
|
|
|
|
" xxxx ",
|
|
|
|
" xx "
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* img_xpm[] =
|
|
|
|
{
|
|
|
|
"12 12 2 1",
|
|
|
|
" c None",
|
|
|
|
"x c #800000",
|
|
|
|
" xx ",
|
|
|
|
" xxxxxx ",
|
|
|
|
" xx xx ",
|
|
|
|
"xx xx",
|
|
|
|
"xx xx",
|
|
|
|
" xx xx ",
|
|
|
|
" xxxxxx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx ",
|
|
|
|
" xx "
|
|
|
|
};
|
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
|
2019-06-14 18:14:41 +00:00
|
|
|
// A helper class to draw these bitmaps into a wxGrid cell:
|
|
|
|
class BitmapGridCellRenderer : public wxGridCellStringRenderer
|
|
|
|
{
|
|
|
|
const char** m_BitmapXPM;
|
|
|
|
public:
|
|
|
|
BitmapGridCellRenderer( const char** aBitmapXPM )
|
|
|
|
{
|
|
|
|
m_BitmapXPM = aBitmapXPM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
|
|
|
|
wxDC& aDc, const wxRect& aRect,
|
|
|
|
int aRow, int aCol, bool aIsSelected) override;
|
|
|
|
};
|
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
|
2019-06-14 18:14:41 +00:00
|
|
|
// Column ids for m_gridListItems
|
2019-06-15 07:58:23 +00:00
|
|
|
enum COL_INDEX
|
|
|
|
{
|
|
|
|
COL_BITMAP,
|
|
|
|
COL_TYPENAME,
|
|
|
|
COL_REPEAT_NUMBER,
|
|
|
|
COL_COMMENT,
|
|
|
|
COL_TEXTSTRING,
|
|
|
|
COL_COUNT //Sentinel
|
|
|
|
};
|
2019-06-14 18:14:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
DIALOG_INSPECTOR::DIALOG_INSPECTOR( PL_EDITOR_FRAME* aParent ) :
|
|
|
|
DIALOG_INSPECTOR_BASE( aParent )
|
|
|
|
{
|
|
|
|
m_editorFrame = aParent;
|
|
|
|
ReCreateDesignList();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2019-06-14 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_INSPECTOR::~DIALOG_INSPECTOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_INSPECTOR::ReCreateDesignList()
|
|
|
|
{
|
|
|
|
wxWindowUpdateLocker dummy( this ); // Avoid flicker when rebuilding the tree
|
2019-06-15 07:58:23 +00:00
|
|
|
const PAGE_INFO& page_info = m_editorFrame->GetPageLayout().GetPageSettings();
|
2019-06-14 18:14:41 +00:00
|
|
|
|
|
|
|
if( m_gridListItems->GetNumberRows() > 1 )
|
|
|
|
m_gridListItems->DeleteRows( 1, m_gridListItems->GetNumberRows() - 1 );
|
|
|
|
|
|
|
|
m_itemsList.clear();
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& drawingSheet = DS_DATA_MODEL::GetTheInstance();
|
2020-11-24 22:16:41 +00:00
|
|
|
wxFileName fn( static_cast<PL_EDITOR_FRAME*>( GetParent() )->GetCurrentFileName() );
|
2019-06-14 18:14:41 +00:00
|
|
|
|
|
|
|
if( fn.GetName().IsEmpty() )
|
2021-05-30 22:56:24 +00:00
|
|
|
SetTitle( "<default drawing sheet>" );
|
2019-06-14 18:14:41 +00:00
|
|
|
else
|
|
|
|
SetTitle( fn.GetName() );
|
|
|
|
|
2019-06-15 07:58:23 +00:00
|
|
|
// The first item is the layout: Display info about the page: fmt, size...
|
2019-06-14 18:14:41 +00:00
|
|
|
int row = 0;
|
2019-06-15 07:58:23 +00:00
|
|
|
GetGridList()->SetCellValue( row, COL_TYPENAME, _( "Layout" ) );
|
2023-02-08 13:26:54 +00:00
|
|
|
|
|
|
|
// Display page format name.
|
|
|
|
GetGridList()->SetCellValue( row, COL_COMMENT, page_info.GetType() );
|
2019-06-15 07:58:23 +00:00
|
|
|
GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER, "-" );
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I page_sizeIU = m_editorFrame->GetPageSizeIU();
|
2023-02-08 13:26:54 +00:00
|
|
|
GetGridList()->SetCellValue( row, COL_TEXTSTRING,
|
|
|
|
wxString::Format( _( "Size: %.1fx%.1fmm" ),
|
2022-09-16 11:33:56 +00:00
|
|
|
drawSheetIUScale.IUTomm( page_sizeIU.x ),
|
|
|
|
drawSheetIUScale.IUTomm( page_sizeIU.y ) ) );
|
2019-06-14 18:14:41 +00:00
|
|
|
GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( root_xpm ) );
|
|
|
|
GetGridList()->SetReadOnly( row, COL_BITMAP );
|
2021-02-22 23:47:17 +00:00
|
|
|
m_itemsList.push_back( nullptr ); // this item is not a DS_DATA_ITEM, just a pseudo item
|
2019-06-14 18:14:41 +00:00
|
|
|
|
|
|
|
// Now adding all current items
|
|
|
|
row++;
|
2023-02-08 13:26:54 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* item : drawingSheet.GetItems() )
|
2019-06-14 18:14:41 +00:00
|
|
|
{
|
|
|
|
const char** img = nullptr;
|
|
|
|
|
|
|
|
switch( item->GetType() )
|
|
|
|
{
|
2023-02-08 13:26:54 +00:00
|
|
|
case DS_DATA_ITEM::DS_SEGMENT:
|
|
|
|
img = line_xpm;
|
|
|
|
break;
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
case DS_DATA_ITEM::DS_RECT:
|
|
|
|
img = rect_xpm;
|
|
|
|
break;
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
case DS_DATA_ITEM::DS_TEXT:
|
|
|
|
img = text_xpm;
|
|
|
|
break;
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
case DS_DATA_ITEM::DS_POLYPOLYGON:
|
|
|
|
img = poly_xpm;
|
|
|
|
break;
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
case DS_DATA_ITEM::DS_BITMAP:
|
|
|
|
img = img_xpm;
|
|
|
|
break;
|
2019-06-14 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetGridList()->AppendRows( 1 );
|
|
|
|
GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( img ) );
|
|
|
|
GetGridList()->SetReadOnly( row, COL_BITMAP );
|
|
|
|
GetGridList()->SetCellValue( row, COL_TYPENAME,item->GetClassName() );
|
2019-06-15 07:58:23 +00:00
|
|
|
GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER,
|
2019-06-14 18:14:41 +00:00
|
|
|
wxString::Format( "%d", item->m_RepeatCount ) );
|
|
|
|
GetGridList()->SetCellValue( row, COL_COMMENT, item->m_Info );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( item->GetType() == DS_DATA_ITEM::DS_TEXT )
|
2019-06-14 18:14:41 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM_TEXT* t_item = static_cast<DS_DATA_ITEM_TEXT*>( item );
|
2019-06-14 18:14:41 +00:00
|
|
|
GetGridList()->SetCellValue( row, COL_TEXTSTRING, t_item->m_TextBase );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_itemsList.push_back( item );
|
|
|
|
row++;
|
|
|
|
}
|
2019-06-15 07:58:23 +00:00
|
|
|
|
|
|
|
// Now resize the columns:
|
|
|
|
int cols_to_resize[] =
|
|
|
|
{
|
|
|
|
COL_BITMAP, COL_TYPENAME, COL_REPEAT_NUMBER, COL_COMMENT, COL_TEXTSTRING, COL_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
int col = cols_to_resize[ii];
|
|
|
|
|
|
|
|
if( col == COL_COUNT )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( col == COL_BITMAP )
|
|
|
|
{
|
|
|
|
#define BITMAP_SIZE 16
|
|
|
|
GetGridList()->SetColMinimalWidth( col, BITMAP_SIZE*2 );
|
|
|
|
GetGridList()->AutoSizeColumn( col, false );
|
|
|
|
}
|
|
|
|
else
|
2023-02-08 13:26:54 +00:00
|
|
|
{
|
2019-06-15 07:58:23 +00:00
|
|
|
GetGridList()->AutoSizeColumn( col );
|
2023-02-08 13:26:54 +00:00
|
|
|
}
|
2019-06-15 07:58:23 +00:00
|
|
|
|
|
|
|
GetGridList()->AutoSizeColLabelSize( col );
|
|
|
|
}
|
2019-06-14 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DIALOG_INSPECTOR::SelectRow( DS_DATA_ITEM* aItem )
|
2019-06-14 18:14:41 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
// m_itemsList[0] is not a true DS_DATA_ITEM
|
2019-06-14 18:14:41 +00:00
|
|
|
for( unsigned row = 1; row < m_itemsList.size(); ++row )
|
|
|
|
{
|
|
|
|
if( m_itemsList[row] == aItem )
|
|
|
|
{
|
|
|
|
GetGridList()->GoToCell( row, COL_TYPENAME );
|
|
|
|
GetGridList()->SelectRow( row );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 13:26:54 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* DIALOG_INSPECTOR::GetDrawingSheetDataItem( int aRow ) const
|
2019-06-14 18:14:41 +00:00
|
|
|
{
|
|
|
|
return ( aRow >= 0 && aRow < (int)m_itemsList.size() ) ? m_itemsList[aRow]: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_INSPECTOR::onCellClicked( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
int row = event.GetRow();
|
|
|
|
GetGridList()->SelectRow( row );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* item = GetDrawingSheetDataItem( row );
|
2019-06-14 18:14:41 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( !item ) // only DS_DATA_ITEM are returned.
|
2019-06-14 18:14:41 +00:00
|
|
|
return;
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
// Select this item in drawing sheet editor, and update the properties panel:
|
2019-06-14 18:14:41 +00:00
|
|
|
PL_SELECTION_TOOL* selectionTool = m_editorFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
selectionTool->ClearSelection();
|
|
|
|
EDA_ITEM* draw_item = item->GetDrawItems()[0];
|
|
|
|
selectionTool->AddItemToSel( draw_item );
|
|
|
|
m_editorFrame->GetCanvas()->Refresh();
|
|
|
|
m_editorFrame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BitmapGridCellRenderer::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
|
|
|
|
wxDC& aDc, const wxRect& aRect,
|
2023-02-08 13:26:54 +00:00
|
|
|
int aRow, int aCol, bool aIsSelected )
|
2019-06-14 18:14:41 +00:00
|
|
|
{
|
2023-02-08 13:26:54 +00:00
|
|
|
wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
|
2019-06-14 18:14:41 +00:00
|
|
|
wxBitmap bm( m_BitmapXPM );
|
2023-02-08 13:26:54 +00:00
|
|
|
aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true );
|
2019-06-14 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_EDITOR_FRAME::ShowDesignInspector()
|
|
|
|
{
|
|
|
|
DIALOG_INSPECTOR dlg( this );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|