23#include <wx/propgrid/propgrid.h>
44 : wxAnyToVariantRegistration( factory )
66 return wxTypeId(a) == wxTypeId(b);
74 new wxAnyValueTypeImpl<std::optional<int>>() );
78 s_wxAnyToSTD_OPTIONAL_INT_VARIANTRegistration(
86 : wxAnyToVariantRegistration( factory )
108 return wxTypeId(a) == wxTypeId(b);
116 new wxAnyValueTypeImpl<std::optional<double>>() );
120 s_wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistration(
128 : wxAnyToVariantRegistration( factory )
150 return wxTypeId(a) == wxTypeId(b);
157wxAnyValueTypeScopedPtr
169 : wxAnyToVariantRegistration( factory )
191 return wxTypeId(a) == wxTypeId(b);
199 new wxAnyValueTypeImpl<KIGFX::COLOR4D>() );
208 wxPGProperty* ret =
nullptr;
252 size_t typeId = aProperty->
TypeHash();
258 ret =
new wxEnumProperty( wxPG_LABEL, wxPG_LABEL,
259 const_cast<wxPGChoices&
>( aProperty->
Choices() ) );
263 ret =
new wxIntProperty();
265 else if( typeId ==
TYPE_HASH(
unsigned int ) || typeId ==
TYPE_HASH(
unsigned long ) )
267 ret =
new wxUIntProperty();
271 ret =
new wxFloatProperty();
277 else if( typeId ==
TYPE_HASH( wxString ) )
287 wxFAIL_MSG( wxString::Format( wxS(
"Property %s not supported by PGPropertyFactory" ),
288 aProperty->
Name() ) );
289 ret =
new wxPropertyCategory();
290 ret->Enable(
false );
299 ret->SetLabel( wxGetTranslation( aProperty->
Name() ) );
300 ret->SetName( aProperty->
Name() );
301 ret->SetHelpString( wxGetTranslation( aProperty->
Name() ) );
302 ret->SetClientData(
const_cast<PROPERTY_BASE*
>( aProperty ) );
311 m_parentFrame( aParentFrame ),
312 m_coordType( aCoordType )
322#if wxCHECK_VERSION( 3, 3, 0 )
324 wxPGPropValFormatFlags aFlags )
const
331 wxCHECK_MSG(
false,
false, wxS(
"PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
335#if wxCHECK_VERSION( 3, 3, 0 )
337 wxPGPropValFormatFlags aFlags )
const
344 if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
348 if( !variantData->Value().has_value() )
349 return wxEmptyString;
351 distanceIU = variantData->
Value().value();
353 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
355 distanceIU = aVariant.GetLong();
359 wxFAIL_MSG( wxT(
"Expected int (or std::optional<int>) value type" ) );
360 return wxEmptyString;
365 distanceIU = transforms.
ToDisplay(
static_cast<long long int>( distanceIU ), m_coordType );
372 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
373 m_parentFrame( aParentFrame )
378#if wxCHECK_VERSION( 3, 3, 0 )
380 wxPGPropValFormatFlags aArgFlags )
const
383 int aArgFlags )
const
387 wxCHECK_MSG(
false,
false, wxS(
"PGPROPERTY_AREA::StringToValue should not be used." ) );
391#if wxCHECK_VERSION( 3, 3, 0 )
393 wxPGPropValFormatFlags aArgFlags )
const
398 wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG, wxEmptyString );
400 wxLongLongNative areaIU = aVariant.GetLongLong();
413 wxUIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
421 if( aValue.GetType() == wxT(
"std::optional<int>" ) )
425 if( !data->Value().has_value() )
426 return wxEmptyString;
428 wxVariant value( data->Value().value() );
429 return wxUIntProperty::ValidateValue( value, aValidationInfo );
432 return wxUIntProperty::ValidateValue( aValue, aValidationInfo );
444 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
457 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 )
465 wxCHECK_MSG( m_customEditor, wxPGEditor_TextCtrl,
466 wxT(
"Make sure to RegisterEditorClass() for PGPROPERTY_RATIO!" ) );
467 return m_customEditor;
471#if wxCHECK_VERSION( 3, 3, 0 )
473 wxPGPropValFormatFlags aArgFlags )
const
476 int aArgFlags )
const
480 wxCHECK_MSG(
false,
false, wxS(
"PGPROPERTY_RATIO::StringToValue should not be used." ) );
484#if wxCHECK_VERSION( 3, 3, 0 )
486 wxPGPropValFormatFlags aArgFlags )
const
493 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
497 if( !variantData->Value().has_value() )
498 return wxEmptyString;
500 value = variantData->
Value().value();
502 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
504 value = aVariant.GetDouble();
508 wxFAIL_MSG( wxT(
"Expected double (or std::optional<double>) value type" ) );
509 return wxEmptyString;
512 return wxString::Format( wxS(
"%g" ), value );
518 if( aValue.GetType() == wxT(
"std::optional<double>" ) )
522 if( !data->Value().has_value() )
523 return wxEmptyString;
525 wxVariant value( data->Value().value() );
526 return wxFloatProperty::ValidateValue( value, aValidationInfo );
529 return wxFloatProperty::ValidateValue( aValue, aValidationInfo );
539#if wxCHECK_VERSION( 3, 3, 0 )
541 wxPGPropValFormatFlags aArgFlags )
const
544 int aArgFlags )
const
549 if( !aText.ToDouble( &value ) )
557 if( aVariant.IsNull() || aVariant.GetDouble() != value )
567#if wxCHECK_VERSION( 3, 3, 0 )
569 wxPGPropValFormatFlags aArgFlags )
const
574 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
578 if( variantData->Value().has_value() )
579 return wxString::Format( wxS(
"%g\u00B0" ), variantData->Value().value() / m_scale );
581 return wxEmptyString;
583 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
585 return wxString::Format( wxS(
"%g\u00B0" ), aVariant.GetDouble() / m_scale );
587 else if( aVariant.GetType() == wxS(
"EDA_ANGLE" ) )
595 wxCHECK_MSG(
false, wxEmptyString, wxS(
"Unexpected variant type in PGPROPERTY_ANGLE" ) );
608 wxSize size( 16, -1 );
610 if( wxPropertyGrid* pg = GetGrid() )
611 size = pg->FromDIP( size );
618 wxPGPaintData& aPaintData )
620 int index = aPaintData.m_choiceItem;
626 if( index < 0 || index >=
static_cast<int>( GetChoices().GetCount() ) )
631 if(
color == wxNullColour )
634 aDC.SetPen( *wxTRANSPARENT_PEN );
635 aDC.SetBrush( wxBrush(
color ) );
636 aDC.DrawRectangle( aRect );
638 aPaintData.m_drawnWidth = aRect.width;
642#if wxCHECK_VERSION( 3, 3, 0 )
644 wxPGPropValFormatFlags aFlags )
const
649 if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
650 return wxEmptyString;
656#if wxCHECK_VERSION( 3, 3, 0 )
658 wxPGPropValFormatFlags aArgFlags )
const
670 wxBoolProperty( aLabel, aName, aValue )
678 wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
679 wxT(
"Make sure to RegisterEditorClass() for PGPROPERTY_BOOL!" ) );
680 return m_customEditor;
686 wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
687 m_backgroundColor( aBackgroundColor )
690#if wxCHECK_VERSION( 3, 3, 0 )
691 SetFlag( wxPGPropertyFlags::NoEditor );
693 SetFlag( wxPG_PROP_NOEDITOR );
698#if wxCHECK_VERSION( 3, 3, 0 )
700 wxPGPropValFormatFlags aArgFlags )
const
711#if wxCHECK_VERSION( 3, 3, 0 )
713 wxPGPropValFormatFlags aFlags )
const
720 if( aValue.IsType( wxS(
"COLOR4D" ) ) )
723 return wxStringProperty::ValueToString( aValue, aFlags );
static wxVariantData * VariantDataFactory(const wxAny &aAny)
static wxVariantData * VariantDataFactory(const wxAny &aAny)
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
A wxEnumProperty that displays a color next to the enum value.
void SetScale(double aScale)
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxValidator * DoGetValidator() const override
Do not perform PG validation; the UX is not what we want.
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
PGPROPERTY_AREA(EDA_DRAW_FRAME *aParentFrame)
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxValidator * DoGetValidator() const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
const wxPGEditor * DoGetEditorClass() const override
PGPROPERTY_BOOL(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, bool aValue=false)
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aFlags=0) const override
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
PGPROPERTY_COLOR4D(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, KIGFX::COLOR4D aValue=KIGFX::COLOR4D::UNSPECIFIED, KIGFX::COLOR4D aBackground=KIGFX::COLOR4D::UNSPECIFIED)
wxColour GetColor(int aValue)
wxSize OnMeasureImage(int aItem=-1) const override
void OnCustomPaint(wxDC &aDC, const wxRect &aRect, wxPGPaintData &aPaintData) override
Customized wxPGProperty class to handle angles.
PGPROPERTY_COORD(EDA_DRAW_FRAME *aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
wxValidator * DoGetValidator() const override
wxString DistanceToString(wxVariant &aVariant, int aArgFlags=0) const
bool StringToDistance(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const
virtual ~PGPROPERTY_DISTANCE()=0
PGPROPERTY_DISTANCE(EDA_DRAW_FRAME *aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
const wxPGEditor * DoGetEditorClass() const override
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
PGPROPERTY_SIZE(EDA_DRAW_FRAME *aParentFrame)
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
bool StringToValue(wxVariant &aVariant, const wxString &aString, int aFlags=0) const override
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
virtual size_t TypeHash() const =0
Return type-id of the property type.
PROPERTY_DISPLAY Display() const
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
const wxString & Name() const
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
std::optional< double > Value() const
static wxVariantData * VariantDataFactory(const wxAny &aAny)
std::optional< int > Value() const
static wxVariantData * VariantDataFactory(const wxAny &aAny)
wxAnyToCOLOR4D_VARIANTRegistrationImpl(wxVariantDataFactory factory)
static wxAnyValueType * GetInstance()
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool IsSameClass(const wxAnyValueType *otherType)
virtual wxAnyValueType * GetAssociatedType() override
static wxAnyValueTypeScopedPtr s_instance
static wxAnyValueTypeScopedPtr s_instance
static bool IsSameClass(const wxAnyValueType *otherType)
virtual wxAnyValueType * GetAssociatedType() override
static wxAnyValueType * GetInstance()
wxAnyToEDA_ANGLE_VARIANTRegistrationImpl(wxVariantDataFactory factory)
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool IsSameClass(const wxAnyValueType *otherType)
static wxAnyValueType * GetInstance()
wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl(wxVariantDataFactory factory)
static wxAnyValueTypeScopedPtr s_instance
virtual wxAnyValueType * GetAssociatedType() override
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static wxAnyValueTypeScopedPtr s_instance
virtual wxAnyValueType * GetAssociatedType() override
static wxAnyValueType * GetInstance()
static bool IsSameClass(const wxAnyValueType *otherType)
wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl(wxVariantDataFactory factory)
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.
PROPERTY_DISPLAY
Common property types.
@ PT_DEGREE
Angle expressed in degrees.
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_DECIDEGREE
Angle expressed in decidegrees.
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
@ PT_DEFAULT
Default property for a given type.
@ PT_SIZE
Size expressed in distance units (mm/inch)
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Custom text control validator definitions.