33#include <wx/settings.h>
34#include <wx/stattext.h>
35#include <wx/propgrid/advprops.h>
39#if !wxCHECK_VERSION( 3, 3, 0 )
45 m_SuppressGridChangeEvents( 0 ),
47 m_splitter_key_proportion( -1 )
49 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
54 wxPGInitResourceModule();
60 wxPGEditor_TextCtrl =
nullptr;
61 wxPGEditor_Choice =
nullptr;
62 wxPGEditor_ComboBox =
nullptr;
63 wxPGEditor_TextCtrlAndButton =
nullptr;
64 wxPGEditor_CheckBox =
nullptr;
65 wxPGEditor_ChoiceAndButton =
nullptr;
66 wxPGEditor_SpinCtrl =
nullptr;
67 wxPGEditor_DatePickerCtrl =
nullptr;
70 if( !
Pgm().m_PropertyGridInitialized )
77 m_caption =
new wxStaticText(
this, wxID_ANY,
_(
"No objects selected" ) );
78 mainSizer->Add(
m_caption, 0, wxALL | wxEXPAND, 5 );
80 m_grid =
new wxPropertyGrid(
this );
81 m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT(
"<...>" ) ) );
82 m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
84#if wxCHECK_VERSION( 3, 3, 0 )
85 m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
87 m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
90#if wxCHECK_VERSION( 3, 3, 0 )
91 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
92 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
93 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
94 m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
95 m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
97 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
98 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
99 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
100 m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
101 m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
104 m_grid->DedicateKey( WXK_RETURN );
105 m_grid->DedicateKey( WXK_NUMPAD_ENTER );
106 m_grid->DedicateKey( WXK_DOWN );
107 m_grid->DedicateKey( WXK_UP );
108 mainSizer->Add(
m_grid, 1, wxEXPAND, 5 );
110 m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
114 m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
119 SetSizer( mainSizer );
129 Bind( wxEVT_PG_COL_END_DRAG,
130 [&]( wxPropertyGridEvent& )
136 [&]( wxSizeEvent& aEvent )
157 if(
m_grid->IsEditorFocused() )
158 m_grid->CommitChangesFromEditor();
195 if(
m_grid->IsEditorFocused() )
196 m_grid->CommitChangesFromEditor();
202 if( aSelection.
Empty() )
204 m_caption->SetLabel(
_(
"No objects selected" ) );
208 else if( aSelection.
Size() == 1 )
214 m_caption->SetLabel( wxString::Format(
_(
"%d objects selected" ), aSelection.
Size() ) );
218 std::set<TYPE_ID> types;
223 wxCHECK( !types.empty(), );
226 std::set<PROPERTY_BASE*> commonProps;
227 const std::vector<PROPERTY_BASE*>& allProperties = propMgr.
GetProperties( *types.begin() );
229 copy( allProperties.begin(), allProperties.end(), inserter( commonProps, commonProps.begin() ) );
231 std::map<PROPERTY_BASE*, int> displayOrder = propMgr.
GetDisplayOrder( *types.begin() );
233 std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
235 std::set<PROPERTY_BASE*> availableProps;
238 for(
const TYPE_ID& type : types )
240 const std::vector<PROPERTY_BASE*>& itemProps = propMgr.
GetProperties( type );
241 const std::map<PROPERTY_BASE*, int>& itemDisplayOrder = propMgr.
GetDisplayOrder( type );
243 copy( itemDisplayOrder.begin(), itemDisplayOrder.end(), inserter( displayOrder, displayOrder.begin() ) );
247 if( !groups.count(
group ) )
249 groupDisplayOrder.emplace_back(
group );
250 groups.insert(
group );
254 for(
auto it = commonProps.begin(); it != commonProps.end(); )
256 if( !binary_search( itemProps.begin(), itemProps.end(), *it ) )
257 it = commonProps.erase( it );
274 if( property->IsHiddenFromPropertiesManager() )
277 if( isLibraryEditor && property->IsHiddenFromLibraryEditors() )
280 if( isDesignEditor && property->IsHiddenFromDesignEditors() )
284 availableProps.insert( property );
287 bool writeable =
true;
288 std::set<PROPERTY_BASE*> existingProps;
290 for( wxPropertyGridIterator it =
m_grid->GetIterator(); !it.AtEnd(); it.Next() )
292 wxPGProperty* pgProp = it.GetProperty();
303 pgProp->SetValue( commonVal );
304 pgProp->Enable( writeable );
306 existingProps.insert( property );
309 if( !existingProps.empty() && existingProps == availableProps )
315 std::map<wxPGProperty*, int> pgPropOrders;
316 std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
329 if( choices.GetCount() )
330 pgProp->SetChoices( choices );
332 pgProp->SetValue( commonVal );
333 pgProp->Enable( writeable );
336 wxASSERT( displayOrder.count( property ) );
337 pgPropOrders[pgProp] = displayOrder[property];
338 pgPropGroups[
property->Group()].emplace_back( pgProp );
342 const wxString unspecifiedGroupCaption =
_(
"Basic Properties" );
344 for(
const wxString& groupName : groupDisplayOrder )
346 if( !pgPropGroups.count( groupName ) )
349 std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
350 wxString groupCaption = wxGetTranslation( groupName );
352 auto groupItem =
new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
355 m_grid->Append( groupItem );
357 std::sort( properties.begin(), properties.end(),
358 [&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
360 return pgPropOrders[aFirst] < pgPropOrders[aSecond];
363 for( wxPGProperty* property : properties )
364 m_grid->Append( property );
373 const wxAny& any = aItem->
Get( aProperty );
374 bool converted =
false;
380 converted = any.GetAs<
int>( &tmp );
383 aValue = wxVariant( tmp );
387 converted = any.GetAs( &aValue );
391 wxString propName = aProperty->
Name();
392 propName.Replace(
' ',
'_' );
393 wxFAIL_MSG( wxString::Format( wxS(
"Could not convert wxAny to wxVariant for %s::%s" ),
403 wxVariant& aValue,
bool& aWritable, wxPGChoices& aChoices )
406 bool different =
false;
419 wxPGChoices choices = aProperty->
GetChoices( item );
428 wxArrayString labels = choices.GetLabels();
429 wxArrayInt values = choices.GetValuesForStrings( labels );
431 if( labels != aChoices.GetLabels() || values != aChoices.GetValuesForStrings( labels ) )
444 if( !different && !aValue.IsNull() && value != aValue )
449 else if( !different )
467 if( aEvent.IsShown() )
477 if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() )
481 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
482 oldValue = prop->GetValue();
484 m_grid->CommitChangesFromEditor();
487 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
489 if( prop->GetValue() == oldValue )
496 if( aEvent.GetKeyCode() == WXK_SPACE )
498 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
500 if( prop->GetValueType() == wxT(
"bool" ) )
502 m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
508 if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER
509 || aEvent.GetKeyCode() == WXK_DOWN || aEvent.GetKeyCode() == WXK_UP )
511 m_grid->CommitChangesFromEditor();
515 m_grid->SelectProperty(
m_grid->GetSelectedProperty(),
true );
The base frame for deriving all KiCad main window classes.
bool IsType(FRAME_T aType) const
A base class for most all the KiCad significant classes used in schematics and boards.
virtual wxString GetFriendlyName() const
wxAny Get(PROPERTY_BASE *aProperty) const
virtual wxString GetClass() const =0
Return the class name.
bool m_PropertyGridInitialized
Enhanced renderer to work around some limitations in wxWidgets 3.0 capabilities.
virtual ~PROPERTIES_PANEL()
float m_splitter_key_proportion
Proportion of the grid column splitter that is used for the key column (0.0 - 1.0)
PROPERTIES_PANEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
virtual void valueChanging(wxPropertyGridEvent &aEvent)
void RecalculateSplitterPos()
bool extractValueAndWritability(const SELECTION &aSelection, PROPERTY_BASE *aProperty, wxVariant &aValue, bool &aWritable, wxPGChoices &aChoices)
Processes a selection and determines whether the given property should be available or not and what t...
void SetSplitterProportion(float aProportion)
std::vector< PROPERTY_BASE * > m_displayed
int m_SuppressGridChangeEvents
virtual void OnLanguageChanged(wxCommandEvent &aEvent)
virtual void UpdateData()=0
virtual void valueChanged(wxPropertyGridEvent &aEvent)
bool getItemValue(EDA_ITEM *aItem, PROPERTY_BASE *aProperty, wxVariant &aValue)
Utility to fetch a property value and convert to wxVariant Precondition: aItem is known to have prope...
virtual void rebuildProperties(const SELECTION &aSelection)
Generates the property grid for a given selection of items.
void onCharHook(wxKeyEvent &aEvent)
virtual wxPGProperty * createPGProperty(const PROPERTY_BASE *aProperty) const =0
void onShow(wxShowEvent &aEvent)
bool IsHiddenFromPropertiesManager() const
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
wxPGChoices GetChoices(INSPECTABLE *aObject) const
const wxString & Name() const
Provide class metadata.Helper macro to map type hashes to names.
const std::vector< PROPERTY_BASE * > & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
bool IsWriteableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
bool IsAvailableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
const std::map< PROPERTY_BASE *, int > & GetDisplayOrder(TYPE_ID aType) const
const std::vector< wxString > & GetGroupDisplayOrder(TYPE_ID aType) const
int Size() const
Returns the number of selected parts.
bool Empty() const
Checks if there is anything selected.
SUPPRESS_GRID_CHANGED_EVENTS(PROPERTIES_PANEL *aPanel)
~SUPPRESS_GRID_CHANGED_EVENTS()
PROPERTIES_PANEL * m_panel
Base window classes and related definitions.
@ FRAME_SCH_SYMBOL_EDITOR
KICOMMON_API wxFont GetDockedPaneFont(wxWindow *aWindow)
PGM_BASE & Pgm()
The global program "get" accessor.
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
size_t TYPE_ID
Unique type identifier.