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
|
2022-12-03 22:34:47 +00:00
|
|
|
* Copyright (C) 2020-2022 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 "properties_panel.h"
|
|
|
|
#include <tool/selection.h>
|
|
|
|
#include <eda_base_frame.h>
|
|
|
|
#include <eda_item.h>
|
2020-10-19 01:57:18 +00:00
|
|
|
#include <import_export.h>
|
2024-02-27 03:10:28 +00:00
|
|
|
#include <pgm_base.h>
|
2022-11-25 17:37:18 +00:00
|
|
|
#include <properties/pg_cell_renderer.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
|
|
|
|
2021-08-22 14:15:49 +00:00
|
|
|
#include <wx/settings.h>
|
|
|
|
#include <wx/stattext.h>
|
2022-12-08 12:55:57 +00:00
|
|
|
#include <wx/propgrid/advprops.h>
|
2021-08-22 14:15:49 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-04-12 17:52:50 +00:00
|
|
|
// This is provided by wx >3.3.0
|
|
|
|
#if !wxCHECK_VERSION( 3, 3, 0 )
|
2020-10-19 01:57:18 +00:00
|
|
|
extern APIIMPORT wxPGGlobalVarsClass* wxPGGlobalVars;
|
2023-04-12 17:52:50 +00:00
|
|
|
#endif
|
2020-04-07 18:13:19 +00:00
|
|
|
|
2022-11-25 14:58:44 +00:00
|
|
|
PROPERTIES_PANEL::PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame ) :
|
|
|
|
wxPanel( aParent ),
|
|
|
|
m_frame( aFrame ),
|
2023-01-21 22:36:39 +00:00
|
|
|
m_splitter_key_proportion( -1 )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2020-04-07 18:13:19 +00:00
|
|
|
// on some platforms wxPGGlobalVars is initialized automatically,
|
|
|
|
// but others need an explicit init
|
|
|
|
if( !wxPGGlobalVars )
|
|
|
|
wxPGInitResourceModule();
|
|
|
|
|
2022-12-08 12:55:57 +00:00
|
|
|
// See https://gitlab.com/kicad/code/kicad/-/issues/12297
|
|
|
|
// and https://github.com/wxWidgets/wxWidgets/issues/11787
|
|
|
|
if( wxPGGlobalVars->m_mapEditorClasses.empty() )
|
|
|
|
{
|
|
|
|
wxPGEditor_TextCtrl = nullptr;
|
|
|
|
wxPGEditor_Choice = nullptr;
|
|
|
|
wxPGEditor_ComboBox = nullptr;
|
|
|
|
wxPGEditor_TextCtrlAndButton = nullptr;
|
|
|
|
wxPGEditor_CheckBox = nullptr;
|
|
|
|
wxPGEditor_ChoiceAndButton = nullptr;
|
|
|
|
wxPGEditor_SpinCtrl = nullptr;
|
|
|
|
wxPGEditor_DatePickerCtrl = nullptr;
|
|
|
|
}
|
|
|
|
|
2024-02-27 03:10:28 +00:00
|
|
|
if( !Pgm().m_PropertyGridInitialized )
|
2023-02-16 03:16:49 +00:00
|
|
|
{
|
|
|
|
delete wxPGGlobalVars->m_defaultRenderer;
|
|
|
|
wxPGGlobalVars->m_defaultRenderer = new PG_CELL_RENDERER();
|
2024-02-27 03:10:28 +00:00
|
|
|
Pgm().m_PropertyGridInitialized = true;
|
2023-02-16 03:16:49 +00:00
|
|
|
}
|
2022-11-25 17:37:18 +00:00
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
m_caption = new wxStaticText( this, wxID_ANY, _( "No objects selected" ) );
|
2021-08-22 14:15:49 +00:00
|
|
|
mainSizer->Add( m_caption, 0, wxALL | wxEXPAND, 5 );
|
|
|
|
|
2023-11-07 13:40:24 +00:00
|
|
|
m_grid = new wxPropertyGrid( this );
|
2020-10-19 01:57:18 +00:00
|
|
|
m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT( "<...>" ) ) );
|
2022-11-25 16:49:21 +00:00
|
|
|
m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
|
2023-04-12 17:52:50 +00:00
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
|
|
|
|
#else
|
2023-02-10 04:38:51 +00:00
|
|
|
m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
|
2023-04-12 17:52:50 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-26 16:04:45 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
2024-03-21 01:51:35 +00:00
|
|
|
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
|
|
|
|
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
|
|
|
|
m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
|
|
|
|
m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
|
|
|
|
m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
|
2023-11-26 16:04:45 +00:00
|
|
|
#else
|
2022-12-03 22:34:47 +00:00
|
|
|
m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
|
2022-12-06 14:10:59 +00:00
|
|
|
m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
|
2022-12-06 13:56:13 +00:00
|
|
|
m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
|
|
|
|
m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
|
|
|
|
m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
|
2023-11-26 16:04:45 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
m_grid->DedicateKey( WXK_RETURN );
|
2022-12-06 14:10:59 +00:00
|
|
|
m_grid->DedicateKey( WXK_NUMPAD_ENTER );
|
2022-12-06 13:56:13 +00:00
|
|
|
m_grid->DedicateKey( WXK_DOWN );
|
|
|
|
m_grid->DedicateKey( WXK_UP );
|
2022-12-13 00:35:08 +00:00
|
|
|
mainSizer->Add( m_grid, 1, wxEXPAND, 5 );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2021-08-22 14:15:49 +00:00
|
|
|
m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
|
2022-12-03 03:43:11 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
// Needed for dark mode, on wx 3.0 at least.
|
|
|
|
m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
|
|
|
|
#endif
|
|
|
|
|
2022-12-13 00:35:08 +00:00
|
|
|
SetFont( KIUI::GetDockedPaneFont( this ) );
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
SetSizer( mainSizer );
|
|
|
|
Layout();
|
|
|
|
|
2021-08-22 14:15:49 +00:00
|
|
|
m_grid->CenterSplitter();
|
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PROPERTIES_PANEL::onCharHook ), nullptr, this );
|
|
|
|
Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanged ), nullptr, this );
|
|
|
|
Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( PROPERTIES_PANEL::valueChanging ), nullptr, this );
|
|
|
|
Connect( wxEVT_SHOW, wxShowEventHandler( PROPERTIES_PANEL::onShow ), nullptr, this );
|
2022-11-25 14:58:44 +00:00
|
|
|
|
|
|
|
Bind( wxEVT_PG_COL_END_DRAG,
|
|
|
|
[&]( wxPropertyGridEvent& )
|
|
|
|
{
|
|
|
|
m_splitter_key_proportion =
|
|
|
|
static_cast<float>( m_grid->GetSplitterPosition() ) / m_grid->GetSize().x;
|
|
|
|
} );
|
|
|
|
|
|
|
|
Bind( wxEVT_SIZE,
|
|
|
|
[&]( wxSizeEvent& aEvent )
|
|
|
|
{
|
2024-02-14 18:15:49 +00:00
|
|
|
CallAfter( [this]()
|
2022-12-06 13:05:28 +00:00
|
|
|
{
|
|
|
|
RecalculateSplitterPos();
|
|
|
|
} );
|
2022-11-25 14:58:44 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
} );
|
2024-03-03 15:57:26 +00:00
|
|
|
|
|
|
|
m_frame->Bind( EDA_LANG_CHANGED, &PROPERTIES_PANEL::OnLanguageChanged, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PROPERTIES_PANEL::~PROPERTIES_PANEL()
|
|
|
|
{
|
|
|
|
m_frame->Unbind( EDA_LANG_CHANGED, &PROPERTIES_PANEL::OnLanguageChanged, this );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-03 15:57:26 +00:00
|
|
|
void PROPERTIES_PANEL::OnLanguageChanged( wxCommandEvent& aEvent )
|
2022-12-21 23:03:15 +00:00
|
|
|
{
|
2024-01-12 17:49:05 +00:00
|
|
|
if( m_grid->IsEditorFocused() )
|
|
|
|
m_grid->CommitChangesFromEditor();
|
|
|
|
|
|
|
|
m_grid->Clear();
|
|
|
|
m_displayed.clear();
|
|
|
|
|
2022-12-21 23:03:15 +00:00
|
|
|
UpdateData();
|
2024-03-03 15:57:26 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
2022-12-21 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-22 16:32:38 +00:00
|
|
|
void PROPERTIES_PANEL::rebuildProperties( const SELECTION& aSelection )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2023-02-11 20:50:43 +00:00
|
|
|
auto reset =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
if( m_grid->IsEditorFocused() )
|
|
|
|
m_grid->CommitChangesFromEditor();
|
2022-11-27 19:28:59 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
m_grid->Clear();
|
|
|
|
m_displayed.clear();
|
|
|
|
};
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
if( aSelection.Empty() )
|
2021-08-22 14:15:49 +00:00
|
|
|
{
|
|
|
|
m_caption->SetLabel( _( "No objects selected" ) );
|
2023-02-11 20:50:43 +00:00
|
|
|
reset();
|
2020-02-04 08:40:25 +00:00
|
|
|
return;
|
2021-08-22 14:15:49 +00:00
|
|
|
}
|
2024-03-15 15:36:47 +00:00
|
|
|
else if( aSelection.Size() == 1 )
|
|
|
|
{
|
|
|
|
m_caption->SetLabel( aSelection.Front()->GetFriendlyName() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_caption->SetLabel( wxString::Format( _( "%d objects selected" ), aSelection.Size() ) );
|
|
|
|
}
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
// Get all the selected types
|
2021-08-22 14:15:49 +00:00
|
|
|
std::set<TYPE_ID> types;
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : aSelection )
|
|
|
|
types.insert( TYPE_HASH( *item ) );
|
|
|
|
|
|
|
|
wxCHECK( !types.empty(), /* void */ );
|
2021-08-22 14:15:49 +00:00
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2021-08-22 14:15:49 +00:00
|
|
|
std::set<PROPERTY_BASE*> commonProps;
|
2023-11-10 18:36:02 +00:00
|
|
|
const PROPERTY_LIST& allProperties = propMgr.GetProperties( *types.begin() );
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
copy( allProperties.begin(), allProperties.end(), inserter( commonProps, commonProps.begin() ) );
|
|
|
|
|
2022-11-28 03:40:14 +00:00
|
|
|
PROPERTY_DISPLAY_ORDER displayOrder = propMgr.GetDisplayOrder( *types.begin() );
|
|
|
|
|
|
|
|
std::vector<wxString> groupDisplayOrder = propMgr.GetGroupDisplayOrder( *types.begin() );
|
|
|
|
std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
|
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
std::set<PROPERTY_BASE*> availableProps;
|
2022-11-28 03:40:14 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
// Get all possible properties
|
2022-12-03 22:34:47 +00:00
|
|
|
for( const TYPE_ID& type : types )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
const PROPERTY_LIST& itemProps = propMgr.GetProperties( type );
|
|
|
|
|
2022-11-28 03:40:14 +00:00
|
|
|
const PROPERTY_DISPLAY_ORDER& itemDisplayOrder = propMgr.GetDisplayOrder( type );
|
|
|
|
|
|
|
|
copy( itemDisplayOrder.begin(), itemDisplayOrder.end(),
|
|
|
|
inserter( displayOrder, displayOrder.begin() ) );
|
|
|
|
|
|
|
|
const std::vector<wxString>& itemGroups = propMgr.GetGroupDisplayOrder( type );
|
|
|
|
|
|
|
|
for( const wxString& group : itemGroups )
|
|
|
|
{
|
|
|
|
if( !groups.count( group ) )
|
|
|
|
{
|
|
|
|
groupDisplayOrder.emplace_back( group );
|
|
|
|
groups.insert( group );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
for( auto it = commonProps.begin(); it != commonProps.end(); /* ++it in the loop */ )
|
|
|
|
{
|
|
|
|
if( !binary_search( itemProps.begin(), itemProps.end(), *it ) )
|
|
|
|
it = commonProps.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
EDA_ITEM* firstItem = aSelection.Front();
|
2024-04-06 13:14:44 +00:00
|
|
|
|
|
|
|
bool isLibraryEditor = m_frame->IsType( FRAME_FOOTPRINT_EDITOR )
|
|
|
|
|| m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR );
|
|
|
|
|
|
|
|
bool isDesignEditor = m_frame->IsType( FRAME_PCB_EDITOR )
|
|
|
|
|| m_frame->IsType( FRAME_SCH );
|
2023-02-11 20:50:43 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
// Find a set of properties that is common to all selected items
|
2022-12-03 22:34:47 +00:00
|
|
|
for( PROPERTY_BASE* property : commonProps )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2023-03-26 23:43:16 +00:00
|
|
|
if( property->IsHiddenFromPropertiesManager() )
|
2022-11-25 16:49:21 +00:00
|
|
|
continue;
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
if( isLibraryEditor && property->IsHiddenFromLibraryEditors() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( isDesignEditor && property->IsHiddenFromDesignEditors() )
|
2023-02-16 03:16:49 +00:00
|
|
|
continue;
|
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
if( propMgr.IsAvailableFor( TYPE_HASH( *firstItem ), property, firstItem ) )
|
|
|
|
availableProps.insert( property );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool writeable = true;
|
|
|
|
std::set<PROPERTY_BASE*> existingProps;
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
for( wxPropertyGridIterator it = m_grid->GetIterator(); !it.AtEnd(); it.Next() )
|
|
|
|
{
|
2023-02-15 02:01:56 +00:00
|
|
|
wxPGProperty* pgProp = it.GetProperty();
|
2023-02-11 20:50:43 +00:00
|
|
|
PROPERTY_BASE* property = propMgr.GetProperty( TYPE_HASH( *firstItem ), pgProp->GetName() );
|
2023-02-15 02:01:56 +00:00
|
|
|
|
|
|
|
// Switching item types? Property may no longer be valid
|
|
|
|
if( !property )
|
|
|
|
continue;
|
|
|
|
|
2023-01-22 16:32:38 +00:00
|
|
|
wxVariant commonVal;
|
2022-12-09 03:24:13 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
extractValueAndWritability( aSelection, property, commonVal, writeable );
|
|
|
|
pgProp->SetValue( commonVal );
|
|
|
|
pgProp->Enable( writeable );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
existingProps.insert( property );
|
|
|
|
}
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
if( !existingProps.empty() && existingProps == availableProps )
|
2023-02-11 20:50:43 +00:00
|
|
|
return;
|
2022-11-28 03:40:14 +00:00
|
|
|
|
2023-02-11 20:50:43 +00:00
|
|
|
// Some difference exists: start from scratch
|
|
|
|
reset();
|
|
|
|
|
|
|
|
std::map<wxPGProperty*, int> pgPropOrders;
|
|
|
|
std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
|
|
|
|
|
|
|
|
for( PROPERTY_BASE* property : availableProps )
|
|
|
|
{
|
|
|
|
wxPGProperty* pgProp = createPGProperty( property );
|
|
|
|
wxVariant commonVal;
|
|
|
|
|
|
|
|
if( !extractValueAndWritability( aSelection, property, commonVal, writeable ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pgProp )
|
|
|
|
{
|
|
|
|
pgProp->SetValue( commonVal );
|
|
|
|
pgProp->Enable( writeable );
|
|
|
|
m_displayed.push_back( property );
|
|
|
|
|
|
|
|
wxASSERT( displayOrder.count( property ) );
|
|
|
|
pgPropOrders[pgProp] = displayOrder[property];
|
|
|
|
pgPropGroups[property->Group()].emplace_back( pgProp );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:40:14 +00:00
|
|
|
const wxString unspecifiedGroupCaption = _( "Basic Properties" );
|
|
|
|
|
|
|
|
for( const wxString& groupName : groupDisplayOrder )
|
|
|
|
{
|
2022-11-29 23:12:28 +00:00
|
|
|
if( !pgPropGroups.count( groupName ) )
|
|
|
|
continue;
|
|
|
|
|
2022-11-28 03:40:14 +00:00
|
|
|
std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
|
2022-12-22 22:44:14 +00:00
|
|
|
wxString groupCaption = wxGetTranslation( groupName );
|
2022-11-28 03:40:14 +00:00
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
auto groupItem = new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
|
2022-12-22 22:44:14 +00:00
|
|
|
: groupCaption );
|
2022-11-28 03:40:14 +00:00
|
|
|
|
|
|
|
m_grid->Append( groupItem );
|
|
|
|
|
|
|
|
std::sort( properties.begin(), properties.end(),
|
|
|
|
[&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
|
|
|
|
{
|
|
|
|
return pgPropOrders[aFirst] < pgPropOrders[aSecond];
|
|
|
|
} );
|
|
|
|
|
|
|
|
for( wxPGProperty* property : properties )
|
|
|
|
m_grid->Append( property );
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:58:44 +00:00
|
|
|
RecalculateSplitterPos();
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
2020-02-06 11:43:32 +00:00
|
|
|
|
|
|
|
|
2023-01-22 16:32:38 +00:00
|
|
|
bool PROPERTIES_PANEL::getItemValue( EDA_ITEM* aItem, PROPERTY_BASE* aProperty, wxVariant& aValue )
|
|
|
|
{
|
|
|
|
const wxAny& any = aItem->Get( aProperty );
|
|
|
|
bool converted = false;
|
|
|
|
|
|
|
|
if( aProperty->HasChoices() )
|
|
|
|
{
|
|
|
|
// handle enums as ints, since there are no default conversion functions for wxAny
|
|
|
|
int tmp;
|
|
|
|
converted = any.GetAs<int>( &tmp );
|
|
|
|
|
|
|
|
if( converted )
|
|
|
|
aValue = wxVariant( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !converted ) // all other types
|
|
|
|
converted = any.GetAs( &aValue );
|
|
|
|
|
|
|
|
if( !converted )
|
|
|
|
wxFAIL_MSG( wxS( "Could not convert wxAny to wxVariant" ) );
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-24 17:08:37 +00:00
|
|
|
bool PROPERTIES_PANEL::extractValueAndWritability( const SELECTION& aSelection,
|
|
|
|
PROPERTY_BASE* aProperty,
|
|
|
|
wxVariant& aValue, bool& aWritable )
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2023-11-10 18:36:02 +00:00
|
|
|
bool different = false;
|
|
|
|
wxVariant commonVal;
|
2023-01-24 17:08:37 +00:00
|
|
|
|
|
|
|
aWritable = true;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : aSelection )
|
|
|
|
{
|
|
|
|
if( !propMgr.IsAvailableFor( TYPE_HASH( *item ), aProperty, item ) )
|
|
|
|
return false;
|
|
|
|
|
2024-02-09 00:15:45 +00:00
|
|
|
if( aProperty->IsHiddenFromPropertiesManager() )
|
|
|
|
return false;
|
|
|
|
|
2023-01-24 17:08:37 +00:00
|
|
|
// If read-only for any of the selection, read-only for the whole selection.
|
2023-07-12 15:02:41 +00:00
|
|
|
if( !propMgr.IsWriteableFor( TYPE_HASH( *item ), aProperty, item ) )
|
2023-01-24 17:08:37 +00:00
|
|
|
aWritable = false;
|
|
|
|
|
|
|
|
wxVariant value;
|
|
|
|
|
|
|
|
if( getItemValue( item, aProperty, value ) )
|
|
|
|
{
|
|
|
|
// Null value indicates different property values between items
|
|
|
|
if( !different && !aValue.IsNull() && value != aValue )
|
|
|
|
{
|
|
|
|
different = true;
|
|
|
|
aValue.MakeNull();
|
|
|
|
}
|
|
|
|
else if( !different )
|
|
|
|
{
|
|
|
|
aValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// getItemValue returned false -- not available for this item
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-06 11:43:32 +00:00
|
|
|
void PROPERTIES_PANEL::onShow( wxShowEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsShown() )
|
2020-03-30 15:27:17 +00:00
|
|
|
UpdateData();
|
2020-02-06 11:43:32 +00:00
|
|
|
}
|
2022-11-25 14:58:44 +00:00
|
|
|
|
|
|
|
|
2022-12-03 22:34:47 +00:00
|
|
|
void PROPERTIES_PANEL::onCharHook( wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() )
|
2022-12-06 13:56:13 +00:00
|
|
|
{
|
2022-12-03 22:34:47 +00:00
|
|
|
m_grid->CommitChangesFromEditor();
|
2022-12-06 13:56:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aEvent.GetKeyCode() == WXK_SPACE )
|
|
|
|
{
|
|
|
|
if( wxPGProperty* prop = m_grid->GetSelectedProperty() )
|
|
|
|
{
|
|
|
|
if( prop->GetValueType() == wxT( "bool" ) )
|
|
|
|
{
|
|
|
|
m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-06 14:10:59 +00:00
|
|
|
|
|
|
|
if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
|
|
|
|
{
|
|
|
|
m_grid->CommitChangesFromEditor();
|
|
|
|
/* don't skip this one; if we're not the last property we'll also go to the next row */
|
|
|
|
}
|
2023-01-17 04:14:38 +00:00
|
|
|
|
2022-12-06 13:56:13 +00:00
|
|
|
aEvent.Skip();
|
2022-12-03 22:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-25 14:58:44 +00:00
|
|
|
void PROPERTIES_PANEL::RecalculateSplitterPos()
|
|
|
|
{
|
|
|
|
if( m_splitter_key_proportion < 0 )
|
|
|
|
m_grid->CenterSplitter();
|
|
|
|
else
|
|
|
|
m_grid->SetSplitterPosition( m_splitter_key_proportion * m_grid->GetSize().x );
|
|
|
|
}
|
2022-12-08 02:38:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PROPERTIES_PANEL::SetSplitterProportion( float aProportion )
|
|
|
|
{
|
|
|
|
m_splitter_key_proportion = aProportion;
|
|
|
|
RecalculateSplitterPos();
|
2022-12-08 12:55:57 +00:00
|
|
|
}
|