32#include <wx/settings.h>
33#include <wx/stattext.h>
34#include <wx/propgrid/advprops.h>
38#if !wxCHECK_VERSION( 3, 3, 0 )
45 m_splitter_key_proportion( -1 )
47 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
52 wxPGInitResourceModule();
58 wxPGEditor_TextCtrl =
nullptr;
59 wxPGEditor_Choice =
nullptr;
60 wxPGEditor_ComboBox =
nullptr;
61 wxPGEditor_TextCtrlAndButton =
nullptr;
62 wxPGEditor_CheckBox =
nullptr;
63 wxPGEditor_ChoiceAndButton =
nullptr;
64 wxPGEditor_SpinCtrl =
nullptr;
65 wxPGEditor_DatePickerCtrl =
nullptr;
74 m_caption =
new wxStaticText(
this, wxID_ANY,
_(
"No objects selected" ) );
75 mainSizer->Add(
m_caption, 0, wxALL | wxEXPAND, 5 );
77 m_grid =
new wxPropertyGrid(
this, wxID_ANY, wxDefaultPosition, wxSize( 300, 400 ),
79 m_grid->SetUnspecifiedValueAppearance( wxPGCell( wxT(
"<...>" ) ) );
80 m_grid->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
82#if wxCHECK_VERSION( 3, 3, 0 )
83 m_grid->SetValidationFailureBehavior( wxPGVFBFlags::MarkCell );
85 m_grid->SetValidationFailureBehavior( wxPG_VFB_MARK_CELL );
88 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
89 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
90 m_grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
91 m_grid->AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
92 m_grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_SPACE );
93 m_grid->DedicateKey( WXK_RETURN );
94 m_grid->DedicateKey( WXK_NUMPAD_ENTER );
95 m_grid->DedicateKey( WXK_DOWN );
96 m_grid->DedicateKey( WXK_UP );
97 mainSizer->Add(
m_grid, 1, wxEXPAND, 5 );
99 m_grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
103 m_grid->SetCaptionTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_CAPTIONTEXT ) );
108 SetSizer( mainSizer );
118 Bind( wxEVT_PG_COL_END_DRAG,
119 [&]( wxPropertyGridEvent& )
122 static_cast<float>(
m_grid->GetSplitterPosition() ) /
m_grid->GetSize().x;
126 [&]( wxSizeEvent& aEvent )
148 if(
m_grid->IsEditorFocused() )
149 m_grid->CommitChangesFromEditor();
155 if( aSelection.
Empty() )
157 m_caption->SetLabel(
_(
"No objects selected" ) );
163 std::set<TYPE_ID> types;
168 wxCHECK( !types.empty(), );
174 std::set<PROPERTY_BASE*> commonProps;
176 copy( allProperties.begin(), allProperties.end(), inserter( commonProps, commonProps.begin() ) );
181 std::set<wxString> groups( groupDisplayOrder.begin(), groupDisplayOrder.end() );
183 std::set<PROPERTY_BASE*> availableProps;
186 for(
const TYPE_ID& type : types )
192 copy( itemDisplayOrder.begin(), itemDisplayOrder.end(),
193 inserter( displayOrder, displayOrder.begin() ) );
197 for(
const wxString&
group : itemGroups )
199 if( !groups.count(
group ) )
201 groupDisplayOrder.emplace_back(
group );
202 groups.insert(
group );
206 for(
auto it = commonProps.begin(); it != commonProps.end(); )
208 if( !binary_search( itemProps.begin(), itemProps.end(), *it ) )
209 it = commonProps.erase( it );
221 if( property->IsHiddenFromPropertiesManager() )
224 if( isFootprintEditor && property->IsHiddenFromLibraryEditors() )
228 availableProps.insert( property );
231 bool writeable =
true;
232 std::set<PROPERTY_BASE*> existingProps;
234 for( wxPropertyGridIterator it =
m_grid->GetIterator(); !it.AtEnd(); it.Next() )
236 wxPGProperty* pgProp = it.GetProperty();
246 pgProp->SetValue( commonVal );
247 pgProp->Enable( writeable );
249 existingProps.insert( property );
252 if( existingProps == availableProps )
258 std::map<wxPGProperty*, int> pgPropOrders;
259 std::map<wxString, std::vector<wxPGProperty*>> pgPropGroups;
271 pgProp->SetValue( commonVal );
272 pgProp->Enable( writeable );
275 wxASSERT( displayOrder.count( property ) );
276 pgPropOrders[pgProp] = displayOrder[property];
277 pgPropGroups[
property->Group()].emplace_back( pgProp );
281 if( aSelection.
Size() > 1 )
283 m_caption->SetLabel( wxString::Format(
_(
"%d objects selected" ), aSelection.
Size() ) );
290 const wxString unspecifiedGroupCaption =
_(
"Basic Properties" );
292 for(
const wxString& groupName : groupDisplayOrder )
294 if( !pgPropGroups.count( groupName ) )
297 std::vector<wxPGProperty*>& properties = pgPropGroups[groupName];
298 wxString groupCaption = wxGetTranslation( groupName );
300 auto groupItem =
new wxPropertyCategory( groupName.IsEmpty() ? unspecifiedGroupCaption
303 m_grid->Append( groupItem );
305 std::sort( properties.begin(), properties.end(),
306 [&]( wxPGProperty*& aFirst, wxPGProperty*& aSecond )
308 return pgPropOrders[aFirst] < pgPropOrders[aSecond];
311 for( wxPGProperty* property : properties )
312 m_grid->Append( property );
321 const wxAny& any = aItem->
Get( aProperty );
322 bool converted =
false;
328 converted = any.GetAs<
int>( &tmp );
331 aValue = wxVariant( tmp );
335 converted = any.GetAs( &aValue );
338 wxFAIL_MSG( wxS(
"Could not convert wxAny to wxVariant" ) );
346 wxVariant& aValue,
bool& aWritable )
352 bool different =
false;
371 if( !different && !aValue.IsNull() && value != aValue )
376 else if( !different )
394 if( aEvent.IsShown() )
401 if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ShiftDown() )
403 m_grid->CommitChangesFromEditor();
407 if( aEvent.GetKeyCode() == WXK_SPACE )
409 if( wxPGProperty* prop =
m_grid->GetSelectedProperty() )
411 if( prop->GetValueType() == wxT(
"bool" ) )
413 m_grid->SetPropertyValue( prop, !prop->GetValue().GetBool() );
419 if( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
421 m_grid->CommitChangesFromEditor();
The base frame for deriving all KiCad main window classes.
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
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
Enhanced renderer to work around some limitations in wxWidgets 3.0 capabilities.
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 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)
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
virtual bool Writeable(INSPECTABLE *aObject) const
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
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 ...
void SetTransforms(ORIGIN_TRANSFORMS *aTransforms)
void SetUnits(EDA_UNITS aUnits)
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.
EDA_UNITS GetUserUnits() const
Base window classes and related definitions.
wxFont GetDockedPaneFont(wxWindow *aWindow)
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
std::vector< PROPERTY_BASE * > PROPERTY_LIST
std::map< PROPERTY_BASE *, int > PROPERTY_DISPLAY_ORDER
size_t TYPE_ID
Unique type identifier.