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
|
2023-03-24 15:57:52 +00:00
|
|
|
* Copyright (C) 2023 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PG_PROPERTIES_H
|
|
|
|
#define PG_PROPERTIES_H
|
|
|
|
|
|
|
|
#include <wx/propgrid/propgrid.h>
|
|
|
|
#include <wx/propgrid/property.h>
|
|
|
|
#include <wx/propgrid/props.h>
|
2023-06-21 01:57:20 +00:00
|
|
|
#include <wx/propgrid/advprops.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <common.h>
|
2023-06-25 20:13:07 +00:00
|
|
|
#include <gal/color4d.h>
|
2022-10-31 01:09:59 +00:00
|
|
|
#include <origin_transforms.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
class PROPERTY_BASE;
|
|
|
|
class REGEX_VALIDATOR;
|
2023-02-16 03:16:49 +00:00
|
|
|
class EDA_DRAW_FRAME;
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-02-16 03:16:49 +00:00
|
|
|
wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty, EDA_DRAW_FRAME* aFrame );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-03-24 15:57:52 +00:00
|
|
|
///< Customized abstract wxPGProperty class to handle coordinate/size units
|
2020-02-04 08:40:25 +00:00
|
|
|
class PGPROPERTY_DISTANCE
|
|
|
|
{
|
|
|
|
public:
|
2024-02-04 23:01:16 +00:00
|
|
|
PGPROPERTY_DISTANCE( EDA_DRAW_FRAME* aParentFrame,
|
2023-11-10 18:36:02 +00:00
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType );
|
2020-02-04 08:40:25 +00:00
|
|
|
virtual ~PGPROPERTY_DISTANCE() = 0;
|
|
|
|
|
2022-11-03 02:50:49 +00:00
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const { return m_coordType; }
|
2022-10-31 01:09:59 +00:00
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
protected:
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToDistance( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
|
|
|
|
wxString DistanceToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const;
|
|
|
|
#else
|
2020-02-04 08:40:25 +00:00
|
|
|
bool StringToDistance( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) const;
|
|
|
|
wxString DistanceToString( wxVariant& aVariant, int aArgFlags = 0 ) const;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
protected:
|
|
|
|
EDA_DRAW_FRAME* m_parentFrame;
|
2022-10-31 01:09:59 +00:00
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType;
|
2020-02-04 08:40:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-02-04 23:01:16 +00:00
|
|
|
class PGPROPERTY_AREA : public wxIntProperty
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PGPROPERTY_AREA( EDA_DRAW_FRAME* aParentFrame );
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
virtual ~PGPROPERTY_AREA() = default;
|
|
|
|
|
2024-02-04 23:01:16 +00:00
|
|
|
protected:
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
#else
|
2024-02-04 23:01:16 +00:00
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags = 0 ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-02-04 23:01:16 +00:00
|
|
|
|
|
|
|
wxValidator* DoGetValidator() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EDA_DRAW_FRAME* m_parentFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
class PGPROPERTY_SIZE : public wxUIntProperty, public PGPROPERTY_DISTANCE
|
|
|
|
{
|
|
|
|
public:
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_SIZE( EDA_DRAW_FRAME* aParentFrame );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
virtual ~PGPROPERTY_SIZE() = default;
|
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
|
|
|
|
{
|
|
|
|
return StringToDistance( aVariant, aText, aFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
|
|
|
|
{
|
|
|
|
return DistanceToString( aVariant, aFlags );
|
|
|
|
}
|
|
|
|
#else
|
2023-03-24 15:57:52 +00:00
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags = 0 ) const override
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
return StringToDistance( aVariant, aText, aArgFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
|
|
|
|
{
|
|
|
|
return DistanceToString( aVariant, aArgFlags );
|
|
|
|
}
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
wxValidator* DoGetValidator() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PGPROPERTY_COORD : public wxIntProperty, public PGPROPERTY_DISTANCE
|
|
|
|
{
|
|
|
|
public:
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_COORD( EDA_DRAW_FRAME* aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType );
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
virtual ~PGPROPERTY_COORD() = default;
|
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
|
|
|
|
{
|
|
|
|
return StringToDistance( aVariant, aText, aFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override
|
|
|
|
{
|
|
|
|
return DistanceToString( aVariant, aFlags );
|
|
|
|
}
|
|
|
|
#else
|
2023-03-24 15:57:52 +00:00
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags = 0 ) const override
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
return StringToDistance( aVariant, aText, aArgFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override
|
|
|
|
{
|
|
|
|
return DistanceToString( aVariant, aArgFlags );
|
|
|
|
}
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
wxValidator* DoGetValidator() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-03-24 15:57:52 +00:00
|
|
|
///< Customized wxPGProperty class to handle angles
|
2020-02-04 08:40:25 +00:00
|
|
|
class PGPROPERTY_ANGLE : public wxFloatProperty
|
|
|
|
{
|
|
|
|
public:
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_ANGLE() :
|
|
|
|
wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
|
|
|
|
m_scale( 1.0 )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
virtual ~PGPROPERTY_ANGLE() = default;
|
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
#else
|
2023-03-24 15:57:52 +00:00
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags = 0 ) const override;
|
2020-02-04 08:40:25 +00:00
|
|
|
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
|
|
|
|
void SetScale( double aScale )
|
|
|
|
{
|
|
|
|
m_scale = aScale;
|
|
|
|
}
|
|
|
|
|
2022-12-03 02:25:42 +00:00
|
|
|
wxValidator* DoGetValidator() const override;
|
|
|
|
|
2023-03-24 15:57:52 +00:00
|
|
|
///< Do not perform PG validation; the UX is not what we want.
|
2022-12-09 03:24:13 +00:00
|
|
|
bool ValidateValue( wxVariant&, wxPGValidationInfo& ) const override { return true; }
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
protected:
|
2023-03-24 15:57:52 +00:00
|
|
|
///< Scale factor to convert between raw and displayed value
|
2020-02-04 08:40:25 +00:00
|
|
|
double m_scale;
|
|
|
|
};
|
|
|
|
|
2021-08-22 15:59:02 +00:00
|
|
|
|
2023-03-24 15:57:52 +00:00
|
|
|
///< A wxEnumProperty that displays a color next to the enum value
|
2021-08-22 15:59:02 +00:00
|
|
|
class PGPROPERTY_COLORENUM : public wxEnumProperty
|
|
|
|
{
|
|
|
|
public:
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_COLORENUM( wxPGChoices* aChoices ) :
|
|
|
|
wxEnumProperty( wxPG_LABEL, wxPG_LABEL, *aChoices, 0 ),
|
2023-01-24 15:42:09 +00:00
|
|
|
m_colorFunc( []( int aDummy ) { return wxNullColour; } )
|
2021-08-22 15:59:02 +00:00
|
|
|
{
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
SetFlag( wxPGPropertyFlags::CustomImage );
|
|
|
|
#else
|
2022-11-29 23:37:29 +00:00
|
|
|
SetFlag( wxPG_PROP_CUSTOMIMAGE );
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2021-08-22 15:59:02 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
virtual ~PGPROPERTY_COLORENUM() = default;
|
|
|
|
|
2021-08-22 15:59:02 +00:00
|
|
|
wxSize OnMeasureImage( int aItem = -1 ) const override;
|
|
|
|
|
|
|
|
void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
|
|
|
|
|
2023-01-22 17:17:39 +00:00
|
|
|
void SetColorFunc( std::function<wxColour( int aValue )> aFunc )
|
2021-08-22 15:59:02 +00:00
|
|
|
{
|
|
|
|
m_colorFunc = aFunc;
|
|
|
|
}
|
|
|
|
|
2023-01-22 17:17:39 +00:00
|
|
|
wxColour GetColor( int aValue )
|
2021-08-22 15:59:02 +00:00
|
|
|
{
|
2023-01-22 17:17:39 +00:00
|
|
|
return m_colorFunc( aValue );
|
2021-08-22 15:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2023-01-22 17:17:39 +00:00
|
|
|
std::function<wxColour( int aValue )> m_colorFunc;
|
2021-08-22 15:59:02 +00:00
|
|
|
};
|
|
|
|
|
2022-11-25 18:15:46 +00:00
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
class PGPROPERTY_RATIO : public wxFloatProperty
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PGPROPERTY_RATIO();
|
|
|
|
|
|
|
|
const wxPGEditor* DoGetEditorClass() const override;
|
|
|
|
|
|
|
|
virtual ~PGPROPERTY_RATIO() = default;
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
#else
|
2024-01-10 00:25:05 +00:00
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags = 0 ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant, int aArgFlags = 0 ) const override;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-01-10 00:25:05 +00:00
|
|
|
|
|
|
|
bool ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const override;
|
|
|
|
|
|
|
|
wxValidator* DoGetValidator() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-25 18:15:46 +00:00
|
|
|
class PGPROPERTY_STRING : public wxStringProperty
|
|
|
|
{
|
|
|
|
public:
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_STRING() :
|
|
|
|
wxStringProperty( wxPG_LABEL, wxPG_LABEL, wxEmptyString )
|
2022-11-25 18:15:46 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~PGPROPERTY_STRING() = default;
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
#else
|
2022-11-25 18:15:46 +00:00
|
|
|
wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
|
|
|
|
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aString,
|
|
|
|
int aFlags = 0 ) const override;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2022-11-25 18:15:46 +00:00
|
|
|
};
|
|
|
|
|
2023-01-22 17:10:36 +00:00
|
|
|
|
|
|
|
class PGPROPERTY_BOOL : public wxBoolProperty
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
|
|
|
bool aValue = false );
|
|
|
|
|
|
|
|
virtual ~PGPROPERTY_BOOL() = default;
|
|
|
|
|
|
|
|
const wxPGEditor* DoGetEditorClass() const override;
|
|
|
|
};
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2023-06-29 03:54:27 +00:00
|
|
|
class PGPROPERTY_COLOR4D : public wxStringProperty
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
2023-06-30 02:53:06 +00:00
|
|
|
KIGFX::COLOR4D aValue = KIGFX::COLOR4D::UNSPECIFIED,
|
|
|
|
KIGFX::COLOR4D aBackground = KIGFX::COLOR4D::UNSPECIFIED );
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
virtual ~PGPROPERTY_COLOR4D() = default;
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
|
|
|
|
wxString ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags = wxPGPropValFormatFlags::Null ) const override;
|
|
|
|
#else
|
2023-06-21 01:57:20 +00:00
|
|
|
wxString ValueToString( wxVariant& aValue, int aFlags = 0 ) const override;
|
|
|
|
|
|
|
|
bool StringToValue( wxVariant &aVariant, const wxString &aText,
|
|
|
|
int aFlags = 0 ) const override;
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2023-06-30 02:53:06 +00:00
|
|
|
|
|
|
|
void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) { m_backgroundColor = aColor; }
|
|
|
|
const KIGFX::COLOR4D& GetBackgroundColor() const { return m_backgroundColor; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Used for rendering colors with opacity
|
|
|
|
KIGFX::COLOR4D m_backgroundColor;
|
2023-06-21 01:57:20 +00:00
|
|
|
};
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
#endif /* PG_PROPERTIES_H */
|