33#include <wx/settings.h>
34#include <wx/stattext.h>
35#include <wx/propgrid/advprops.h>
39#if !wxCHECK_VERSION( 3, 3, 0 )
46 m_splitter_key_proportion( -1 )
48 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
53 wxPGInitResourceModule();
59 wxPGEditor_TextCtrl =
nullptr;
60 wxPGEditor_Choice =
nullptr;
61 wxPGEditor_ComboBox =
nullptr;
62 wxPGEditor_TextCtrlAndButton =
nullptr;
63 wxPGEditor_CheckBox =
nullptr;
64 wxPGEditor_ChoiceAndButton =
nullptr;
65 wxPGEditor_SpinCtrl =
nullptr;
66 wxPGEditor_DatePickerCtrl =
nullptr;
69 if( !
Pgm().m_PropertyGridInitialized )
76 m_caption =
new wxStaticText(
this, wxID_ANY,
_(
"No objects selected" ) );
77 mainSizer->Add(
m_caption, 0, wxALL | wxEXPAND, 5 );
79 m_grid =
new wxPropertyGrid(
this );
80 m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT(
"<...>" ) ) );
81 m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
83#if wxCHECK_VERSION( 3, 3, 0 )
84 m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
86 m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
89#if wxCHECK_VERSION( 3, 3, 0 )
90 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
91 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
92 m_grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_DOWN );
93 m_grid->AddActionTrigger( wxPGKeyboardAction::PrevProperty, WXK_UP );
94 m_grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_SPACE );
96 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
97 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
98 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
99 m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
100 m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
103 m_grid->DedicateKey( WXK_RETURN );
104 m_grid->DedicateKey( WXK_NUMPAD_ENTER );
105 m_grid->DedicateKey( WXK_DOWN );
106 m_grid->DedicateKey( WXK_UP );
107 mainSizer->Add(
m_grid, 1, wxEXPAND, 5 );
109 m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
113 m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
118 SetSizer( mainSizer );
128 Bind( wxEVT_PG_COL_END_DRAG,
129 [&]( wxPropertyGridEvent& )
132 static_cast<float>(
m_grid->GetSplitterPosition() ) /
m_grid->GetSize().x;
136 [&]( wxSizeEvent& aEvent )
157 if(
m_grid->IsEditorFocused() )
158 m_grid->CommitChangesFromEditor();
174 if(
m_grid->IsEditorFocused() )
175 m_grid->CommitChangesFromEditor();
181 if( aSelection.
Empty() )
183 m_caption->SetLabel(
_(
"No objects selected" ) );
187 else if( aSelection.
Size() == 1 )
193 m_caption->SetLabel( wxString::Format(
_(
"%d objects selected" ), aSelection.
Size() ) );
197 std::set<TYPE_ID> types;
202 wxCHECK( !types.empty(), );
205 std::set<PROPERTY_BASE*> commonProps;
208 copy( allProperties.begin(), allProperties.end(), inserter( commonProps, commonProps.begin() ) );
213 std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
215 std::set<PROPERTY_BASE*> availableProps;
218 for(
const TYPE_ID& type : types )
224 copy( itemDisplayOrder.begin(), itemDisplayOrder.end(),
225 inserter( displayOrder, displayOrder.begin() ) );
229 for(
const wxString&
group : itemGroups )
231 if( !groups.count(
group ) )
233 groupDisplayOrder.emplace_back(
group );
234 groups.insert(
group );
238 for(
auto it = commonProps.begin(); it != commonProps.end(); )
240 if( !binary_search( itemProps.begin(), itemProps.end(), *it ) )
241 it = commonProps.erase( it );
258 if( property->IsHiddenFromPropertiesManager() )
261 if( isLibraryEditor && property->IsHiddenFromLibraryEditors() )
264 if( isDesignEditor && property->IsHiddenFromDesignEditors() )
268 availableProps.insert( property );
271 bool writeable =
true;
272 std::set<PROPERTY_BASE*> existingProps;
274 for( wxPropertyGridIterator it =
m_grid->GetIterator(); !it.AtEnd(); it.Next() )
276 wxPGProperty* pgProp = it.GetProperty();
286 pgProp->SetValue( commonVal );
287 pgProp->Enable( writeable );
289 existingProps.insert( property );
292 if( !existingProps.empty() && existingProps == availableProps )
298 std::map<wxPGProperty*, int> pgPropOrders;
299 std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
311 pgProp->SetValue( commonVal );
312 pgProp->Enable( writeable );
315 wxASSERT( displayOrder.count( property ) );
316 pgPropOrders[pgProp] = displayOrder[property];
317 pgPropGroups[
property->Group()].emplace_back( pgProp );
321 const wxString unspecifiedGroupCaption =
_(
"Basic Properties" );
323 for(
const wxString& groupName : groupDisplayOrder )
325 if( !pgPropGroups.count( groupName ) )
328 std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
329 wxString groupCaption = wxGetTranslation( groupName );
331 auto groupItem =
new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
334 m_grid->Append( groupItem );
336 std::sort( properties.begin(), properties.end(),
337 [&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
339 return pgPropOrders[aFirst] < pgPropOrders[aSecond];
342 for( wxPGProperty* property : properties )
343 m_grid->Append( property );
352 const wxAny& any = aItem->
Get( aProperty );
353 bool converted =
false;
359 converted = any.GetAs<
int>( &tmp );
362 aValue = wxVariant( tmp );
366 converted = any.GetAs( &aValue );
369 wxFAIL_MSG( wxS(
"Could not convert wxAny to wxVariant" ) );
377 wxVariant& aValue,
bool& aWritable )
380 bool different =
false;
402 if( !different && !aValue.IsNull() && value != aValue )
407 else if( !different )
425 if( aEvent.IsShown() )
434 if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() &&
m_grid->IsAnyModified() )
436 m_grid->CommitChangesFromEditor();
443 if( aEvent.GetKeyCode() == WXK_SPACE )
445 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
447 if( prop->GetValueType() == wxT(
"bool" ) )
449 m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
455 if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
457 m_grid->CommitChangesFromEditor();
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
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)
bool extractValueAndWritability(const SELECTION &aSelection, PROPERTY_BASE *aProperty, wxVariant &aValue, bool &aWritable)
Processes a selection and determines whether the given property should be available or not and what t...
void RecalculateSplitterPos()
void SetSplitterProportion(float aProportion)
std::vector< PROPERTY_BASE * > m_displayed
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.
Provide class metadata.Helper macro to map type hashes to names.
const PROPERTY_LIST & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
const PROPERTY_DISPLAY_ORDER & GetDisplayOrder(TYPE_ID aType) const
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::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.
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
std::vector< PROPERTY_BASE * > PROPERTY_LIST
std::map< PROPERTY_BASE *, int > PROPERTY_DISPLAY_ORDER
size_t TYPE_ID
Unique type identifier.