2020-02-04 08:40:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2023-11-11 15:29:34 +00:00
|
|
|
* Copyright (C) 2020-2023 CERN
|
2023-10-06 17:04:00 +00:00
|
|
|
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-02-04 08:40:25 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcb_properties_panel.h"
|
|
|
|
|
2023-11-01 00:38:43 +00:00
|
|
|
#include <font/fontconfig.h>
|
|
|
|
#include <font/kicad_font_name.h>
|
|
|
|
#include <pgm_base.h>
|
2023-02-16 03:16:49 +00:00
|
|
|
#include <pcb_base_edit_frame.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2023-10-06 17:04:00 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2022-11-03 02:50:49 +00:00
|
|
|
#include <properties/property_mgr.h>
|
|
|
|
#include <properties/pg_editors.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <board_commit.h>
|
|
|
|
#include <board_connected_item.h>
|
2022-11-03 02:50:49 +00:00
|
|
|
#include <properties/pg_properties.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <pcb_shape.h>
|
2022-11-25 01:34:40 +00:00
|
|
|
#include <pcb_text.h>
|
2022-05-12 18:16:11 +00:00
|
|
|
#include <pcb_track.h>
|
2023-10-06 17:04:00 +00:00
|
|
|
#include <pcb_generator.h>
|
2023-03-27 15:42:45 +00:00
|
|
|
#include <pad.h>
|
2021-08-22 15:59:02 +00:00
|
|
|
#include <settings/color_settings.h>
|
2022-11-25 18:15:46 +00:00
|
|
|
#include <string_utils.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
|
2023-02-16 03:16:49 +00:00
|
|
|
PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_BASE_EDIT_FRAME* aFrame ) :
|
2022-12-05 02:07:45 +00:00
|
|
|
PROPERTIES_PANEL( aParent, aFrame ),
|
|
|
|
m_frame( aFrame ),
|
|
|
|
m_propMgr( PROPERTY_MANAGER::Instance() )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
m_propMgr.Rebuild();
|
2022-11-29 16:31:00 +00:00
|
|
|
bool found = false;
|
|
|
|
|
2022-12-08 12:55:57 +00:00
|
|
|
wxASSERT( wxPGGlobalVars );
|
|
|
|
|
2023-02-16 03:16:49 +00:00
|
|
|
wxString editorKey = PG_UNIT_EDITOR::BuildEditorName( m_frame );
|
|
|
|
|
|
|
|
auto it = wxPGGlobalVars->m_mapEditorClasses.find( editorKey );
|
2022-12-08 12:55:57 +00:00
|
|
|
|
|
|
|
if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
|
2022-11-29 16:31:00 +00:00
|
|
|
{
|
2023-01-22 17:10:36 +00:00
|
|
|
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( it->second );
|
|
|
|
m_unitEditorInstance->UpdateFrame( m_frame );
|
2022-12-08 12:55:57 +00:00
|
|
|
found = true;
|
2022-11-29 16:31:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 18:25:57 +00:00
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame );
|
2023-01-22 17:10:36 +00:00
|
|
|
m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME );
|
|
|
|
|
|
|
|
if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
|
|
|
|
{
|
|
|
|
PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR();
|
|
|
|
m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( wxPropertyGrid::RegisterEditorClass( cbEditor ) );
|
2022-12-04 18:25:57 +00:00
|
|
|
}
|
2023-01-23 03:44:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( it->second );
|
|
|
|
}
|
2024-01-10 00:25:05 +00:00
|
|
|
|
|
|
|
it = wxPGGlobalVars->m_mapEditorClasses.find( PG_RATIO_EDITOR::EDITOR_NAME );
|
|
|
|
|
|
|
|
if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
|
|
|
|
{
|
|
|
|
PG_RATIO_EDITOR* ratioEditor = new PG_RATIO_EDITOR();
|
|
|
|
m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( wxPropertyGrid::RegisterEditorClass( ratioEditor ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( it->second );
|
|
|
|
}
|
2022-11-22 00:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PCB_PROPERTIES_PANEL::~PCB_PROPERTIES_PANEL()
|
|
|
|
{
|
2023-01-22 17:10:36 +00:00
|
|
|
m_unitEditorInstance->UpdateFrame( nullptr );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-30 15:27:17 +00:00
|
|
|
void PCB_PROPERTIES_PANEL::UpdateData()
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
// TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD?
|
|
|
|
updateLists( static_cast<PCB_EDIT_FRAME*>( m_frame )->GetBoard() );
|
2023-01-22 16:32:38 +00:00
|
|
|
|
|
|
|
// Will actually just be updatePropertyValues() if selection hasn't changed
|
|
|
|
rebuildProperties( selection );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-09 03:24:13 +00:00
|
|
|
void PCB_PROPERTIES_PANEL::AfterCommit()
|
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
2023-01-22 16:32:38 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
rebuildProperties( selection );
|
2023-01-22 16:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
|
|
|
|
{
|
2021-08-22 15:59:02 +00:00
|
|
|
if( aProperty->TypeHash() == TYPE_HASH( PCB_LAYER_ID ) )
|
|
|
|
{
|
|
|
|
wxASSERT( aProperty->HasChoices() );
|
|
|
|
|
2023-01-22 15:47:02 +00:00
|
|
|
const wxPGChoices& canonicalLayers = aProperty->Choices();
|
|
|
|
wxArrayString boardLayerNames;
|
|
|
|
wxArrayInt boardLayerIDs;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) aProperty->Choices().GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
int layer = canonicalLayers.GetValue( ii );
|
|
|
|
|
|
|
|
boardLayerNames.push_back( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) );
|
|
|
|
boardLayerIDs.push_back( canonicalLayers.GetValue( ii ) );
|
|
|
|
}
|
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
auto ret = new PGPROPERTY_COLORENUM( new wxPGChoices( boardLayerNames, boardLayerIDs ) );
|
2021-08-22 15:59:02 +00:00
|
|
|
|
|
|
|
ret->SetColorFunc(
|
2023-01-22 17:17:39 +00:00
|
|
|
[&]( int aValue ) -> wxColour
|
2021-08-22 15:59:02 +00:00
|
|
|
{
|
2023-01-22 17:17:39 +00:00
|
|
|
return m_frame->GetColorSettings()->GetColor( ToLAYER_ID( aValue ) ).ToColour();
|
2021-08-22 15:59:02 +00:00
|
|
|
} );
|
|
|
|
|
2022-12-21 23:03:15 +00:00
|
|
|
ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
|
2021-08-22 15:59:02 +00:00
|
|
|
ret->SetName( aProperty->Name() );
|
2022-12-22 22:44:14 +00:00
|
|
|
ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
|
2021-08-22 15:59:02 +00:00
|
|
|
ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-16 03:16:49 +00:00
|
|
|
return PGPropertyFactory( aProperty, m_frame );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-10 04:38:51 +00:00
|
|
|
PROPERTY_BASE* PCB_PROPERTIES_PANEL::getPropertyFromEvent( const wxPropertyGridEvent& aEvent ) const
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( selection.Front() );
|
2023-01-06 01:32:35 +00:00
|
|
|
|
2023-02-10 04:38:51 +00:00
|
|
|
wxCHECK_MSG( firstItem, nullptr,
|
|
|
|
wxT( "getPropertyFromEvent for a property with nothing selected!") );
|
2023-01-06 01:32:35 +00:00
|
|
|
|
2022-11-25 21:29:56 +00:00
|
|
|
PROPERTY_BASE* property = m_propMgr.GetProperty( TYPE_HASH( *firstItem ),
|
|
|
|
aEvent.GetPropertyName() );
|
2023-02-10 04:38:51 +00:00
|
|
|
wxCHECK_MSG( property, nullptr,
|
|
|
|
wxT( "getPropertyFromEvent for a property not found on the selected item!" ) );
|
|
|
|
|
|
|
|
return property;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_PROPERTIES_PANEL::valueChanging( wxPropertyGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
EDA_ITEM* item = selection.Front();
|
|
|
|
|
|
|
|
PROPERTY_BASE* property = getPropertyFromEvent( aEvent );
|
|
|
|
wxCHECK( property, /* void */ );
|
|
|
|
wxCHECK( item, /* void */ );
|
|
|
|
|
|
|
|
wxVariant newValue = aEvent.GetPropertyValue();
|
|
|
|
|
|
|
|
if( VALIDATOR_RESULT validationFailure = property->Validate( newValue.GetAny(), item ) )
|
|
|
|
{
|
|
|
|
wxString errorMsg = wxString::Format( wxS( "%s: %s" ), wxGetTranslation( property->Name() ),
|
|
|
|
validationFailure->get()->Format( m_frame ) );
|
|
|
|
m_frame->ShowInfoBarError( errorMsg );
|
|
|
|
aEvent.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
PROPERTY_BASE* property = getPropertyFromEvent( aEvent );
|
|
|
|
wxCHECK( property, /* void */ );
|
2023-01-21 22:36:39 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
wxVariant newValue = aEvent.GetPropertyValue();
|
|
|
|
BOARD_COMMIT changes( m_frame );
|
|
|
|
|
2023-12-15 21:04:33 +00:00
|
|
|
PROPERTY_COMMIT_HANDLER handler( &changes );
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
for( EDA_ITEM* edaItem : selection )
|
|
|
|
{
|
2023-12-15 21:04:33 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( edaItem );
|
2020-02-04 08:40:25 +00:00
|
|
|
changes.Modify( item );
|
|
|
|
item->Set( property, newValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
changes.Push( _( "Change property" ) );
|
2023-10-06 17:04:00 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
m_frame->Refresh();
|
2022-12-09 03:24:13 +00:00
|
|
|
|
|
|
|
// Perform grid updates as necessary based on value change
|
|
|
|
AfterCommit();
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard )
|
|
|
|
{
|
2023-11-01 00:38:43 +00:00
|
|
|
wxPGChoices layersAll;
|
|
|
|
wxPGChoices layersCu;
|
|
|
|
wxPGChoices nets;
|
|
|
|
wxPGChoices fonts;
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
// Regenerate all layers
|
2022-05-12 18:16:11 +00:00
|
|
|
for( LSEQ seq = aBoard->GetEnabledLayers().UIOrder(); seq; ++seq )
|
|
|
|
layersAll.Add( LSET::Name( *seq ), *seq );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2022-05-12 18:16:11 +00:00
|
|
|
for( LSEQ seq = LSET( aBoard->GetEnabledLayers() & LSET::AllCuMask() ).UIOrder(); seq; ++seq )
|
|
|
|
layersCu.Add( LSET::Name( *seq ), *seq );
|
2022-05-05 18:48:58 +00:00
|
|
|
|
2022-05-12 18:16:11 +00:00
|
|
|
m_propMgr.GetProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) )->SetChoices( layersAll );
|
|
|
|
m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) )->SetChoices( layersAll );
|
2022-05-05 18:48:58 +00:00
|
|
|
|
2022-05-12 18:16:11 +00:00
|
|
|
// Copper only properties
|
2022-11-25 21:29:56 +00:00
|
|
|
m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
|
|
|
_HKI( "Layer" ) )->SetChoices( layersCu );
|
2022-05-12 18:16:11 +00:00
|
|
|
m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Top" ) )->SetChoices( layersCu );
|
|
|
|
m_propMgr.GetProperty( TYPE_HASH( PCB_VIA ), _HKI( "Layer Bottom" ) )->SetChoices( layersCu );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
// Regenerate nets
|
2024-03-28 20:02:53 +00:00
|
|
|
|
|
|
|
std::vector<std::pair<wxString, int>> netNames;
|
|
|
|
netNames.reserve( aBoard->GetNetInfo().NetsByNetcode().size() );
|
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
for( const auto& [ netCode, netInfo ] : aBoard->GetNetInfo().NetsByNetcode() )
|
2024-03-28 20:02:53 +00:00
|
|
|
netNames.emplace_back( UnescapeString( netInfo->GetNetname() ), netCode );
|
|
|
|
|
|
|
|
std::sort( netNames.begin(), netNames.end(), []( const auto& a, const auto& b )
|
|
|
|
{
|
|
|
|
return a.first.CmpNoCase( b.first ) < 0;
|
|
|
|
} );
|
|
|
|
|
|
|
|
for( const auto& [ netName, netCode ] : netNames )
|
|
|
|
nets.Add( netName, netCode );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
auto netProperty = m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Net" ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
netProperty->SetChoices( nets );
|
2023-11-01 00:38:43 +00:00
|
|
|
|
|
|
|
// Regnerate font names
|
|
|
|
std::vector<std::string> fontNames;
|
|
|
|
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
|
|
|
|
|
|
|
|
fonts.Add( KICAD_FONT_NAME, -1 );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) fontNames.size(); ++ii )
|
|
|
|
fonts.Add( wxString( fontNames[ii] ), ii );
|
|
|
|
|
|
|
|
auto fontProperty = m_propMgr.GetProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Font" ) );
|
|
|
|
fontProperty->SetChoices( fonts );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|