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
|
2024-01-10 00:25:05 +00:00
|
|
|
* Copyright (C) 2021-2024 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-05-05 18:48:58 +00:00
|
|
|
#include <wx/dc.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <wx/propgrid/propgrid.h>
|
|
|
|
|
2022-08-25 20:37:36 +00:00
|
|
|
#include <macros.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
#include <validators.h>
|
2023-02-16 03:16:49 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2022-09-17 01:07:36 +00:00
|
|
|
#include <eda_units.h>
|
2023-06-21 01:57:20 +00:00
|
|
|
#include <properties/color4d_variant.h>
|
2024-01-10 00:25:05 +00:00
|
|
|
#include <properties/std_optional_variants.h>
|
2022-11-03 02:50:49 +00:00
|
|
|
#include <properties/eda_angle_variant.h>
|
|
|
|
#include <properties/pg_properties.h>
|
2022-11-30 17:09:57 +00:00
|
|
|
#include <properties/pg_editors.h>
|
2022-11-03 02:50:49 +00:00
|
|
|
#include <properties/property_mgr.h>
|
|
|
|
#include <properties/property.h>
|
2022-11-25 18:15:46 +00:00
|
|
|
#include <string_utils.h>
|
2021-08-22 15:59:02 +00:00
|
|
|
#include <widgets/color_swatch.h>
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2022-11-15 15:45:18 +00:00
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
class wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl( wxVariantDataFactory factory )
|
|
|
|
: wxAnyToVariantRegistration( factory )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool IsSameClass(const wxAnyValueType* otherType)
|
|
|
|
{
|
|
|
|
return AreSameClasses( *s_instance.get(), *otherType );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueType* GetInstance()
|
|
|
|
{
|
|
|
|
return s_instance.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxAnyValueType* GetAssociatedType() override
|
|
|
|
{
|
|
|
|
return wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl::GetInstance();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
|
|
|
|
{
|
|
|
|
return wxTypeId(a) == wxTypeId(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueTypeScopedPtr s_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxAnyValueTypeScopedPtr wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<std::optional<int>>() );
|
|
|
|
|
|
|
|
static wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl s_wxAnyToSTD_OPTIONAL_INT_VARIANTRegistration( &STD_OPTIONAL_INT_VARIANT_DATA::VariantDataFactory );
|
|
|
|
|
|
|
|
|
|
|
|
class wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl( wxVariantDataFactory factory )
|
|
|
|
: wxAnyToVariantRegistration( factory )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool IsSameClass(const wxAnyValueType* otherType)
|
|
|
|
{
|
|
|
|
return AreSameClasses( *s_instance.get(), *otherType );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueType* GetInstance()
|
|
|
|
{
|
|
|
|
return s_instance.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxAnyValueType* GetAssociatedType() override
|
|
|
|
{
|
|
|
|
return wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl::GetInstance();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
|
|
|
|
{
|
|
|
|
return wxTypeId(a) == wxTypeId(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueTypeScopedPtr s_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxAnyValueTypeScopedPtr wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<std::optional<double>>() );
|
|
|
|
|
|
|
|
static wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl s_wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistration( &STD_OPTIONAL_DOUBLE_VARIANT_DATA::VariantDataFactory );
|
|
|
|
|
|
|
|
|
2022-11-15 15:45:18 +00:00
|
|
|
class wxAnyToEDA_ANGLE_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToEDA_ANGLE_VARIANTRegistrationImpl( wxVariantDataFactory factory )
|
|
|
|
: wxAnyToVariantRegistration( factory )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool IsSameClass(const wxAnyValueType* otherType)
|
|
|
|
{
|
|
|
|
return AreSameClasses( *s_instance.get(), *otherType );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueType* GetInstance()
|
|
|
|
{
|
|
|
|
return s_instance.get();
|
|
|
|
}
|
|
|
|
|
2022-11-15 18:27:20 +00:00
|
|
|
virtual wxAnyValueType* GetAssociatedType() override
|
2022-11-15 15:45:18 +00:00
|
|
|
{
|
|
|
|
return wxAnyToEDA_ANGLE_VARIANTRegistrationImpl::GetInstance();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
|
|
|
|
{
|
|
|
|
return wxTypeId(a) == wxTypeId(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueTypeScopedPtr s_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxAnyValueTypeScopedPtr wxAnyToEDA_ANGLE_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<EDA_ANGLE>() );
|
|
|
|
|
|
|
|
static wxAnyToEDA_ANGLE_VARIANTRegistrationImpl s_wxAnyToEDA_ANGLE_VARIANTRegistration( &EDA_ANGLE_VARIANT_DATA::VariantDataFactory );
|
|
|
|
|
2022-11-03 02:50:49 +00:00
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
class wxAnyToCOLOR4D_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToCOLOR4D_VARIANTRegistrationImpl( wxVariantDataFactory factory )
|
|
|
|
: wxAnyToVariantRegistration( factory )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool IsSameClass(const wxAnyValueType* otherType)
|
|
|
|
{
|
|
|
|
return AreSameClasses( *s_instance.get(), *otherType );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueType* GetInstance()
|
|
|
|
{
|
|
|
|
return s_instance.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxAnyValueType* GetAssociatedType() override
|
|
|
|
{
|
|
|
|
return wxAnyToCOLOR4D_VARIANTRegistrationImpl::GetInstance();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
|
|
|
|
{
|
|
|
|
return wxTypeId(a) == wxTypeId(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxAnyValueTypeScopedPtr s_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
wxAnyValueTypeScopedPtr wxAnyToCOLOR4D_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<KIGFX::COLOR4D>() );
|
|
|
|
|
|
|
|
static wxAnyToCOLOR4D_VARIANTRegistrationImpl s_wxAnyToCOLOR4D_VARIANTRegistration( &COLOR4D_VARIANT_DATA::VariantDataFactory );
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
wxPGProperty* ret = nullptr;
|
|
|
|
PROPERTY_DISPLAY display = aProperty->Display();
|
|
|
|
|
|
|
|
switch( display )
|
|
|
|
{
|
2020-04-06 16:23:21 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_SIZE:
|
2023-11-10 18:36:02 +00:00
|
|
|
ret = new PGPROPERTY_SIZE( aFrame );
|
2023-02-16 03:16:49 +00:00
|
|
|
ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
break;
|
|
|
|
|
2024-02-04 23:01:16 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_AREA:
|
|
|
|
ret = new PGPROPERTY_AREA( aFrame );
|
|
|
|
ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
|
|
|
|
break;
|
|
|
|
|
2020-04-06 16:23:21 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_COORD:
|
2023-11-10 18:36:02 +00:00
|
|
|
ret = new PGPROPERTY_COORD( aFrame, aProperty->CoordType() );
|
2023-02-16 03:16:49 +00:00
|
|
|
ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
break;
|
|
|
|
|
2020-04-06 16:23:21 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_DECIDEGREE:
|
|
|
|
case PROPERTY_DISPLAY::PT_DEGREE:
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2022-10-16 16:45:10 +00:00
|
|
|
PGPROPERTY_ANGLE* prop = new PGPROPERTY_ANGLE();
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2020-04-06 16:23:21 +00:00
|
|
|
if( display == PROPERTY_DISPLAY::PT_DECIDEGREE )
|
2020-02-04 08:40:25 +00:00
|
|
|
prop->SetScale( 10.0 );
|
|
|
|
|
|
|
|
ret = prop;
|
2023-02-16 03:16:49 +00:00
|
|
|
ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_RATIO:
|
|
|
|
ret = new PGPROPERTY_RATIO();
|
|
|
|
break;
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
default:
|
|
|
|
wxFAIL;
|
2022-08-25 20:37:36 +00:00
|
|
|
KI_FALLTHROUGH;
|
2020-02-04 08:40:25 +00:00
|
|
|
/* fall through */
|
2020-04-06 16:23:21 +00:00
|
|
|
case PROPERTY_DISPLAY::PT_DEFAULT:
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
// Create a corresponding wxPGProperty
|
|
|
|
size_t typeId = aProperty->TypeHash();
|
|
|
|
|
|
|
|
// Enum property
|
|
|
|
if( aProperty->HasChoices() )
|
|
|
|
{
|
|
|
|
// I do not know why enum property takes a non-const reference to wxPGChoices..
|
|
|
|
ret = new wxEnumProperty( wxPG_LABEL, wxPG_LABEL,
|
|
|
|
const_cast<wxPGChoices&>( aProperty->Choices() ) );
|
|
|
|
}
|
|
|
|
else if( typeId == TYPE_HASH( int ) || typeId == TYPE_HASH( long ) )
|
|
|
|
{
|
|
|
|
ret = new wxIntProperty();
|
|
|
|
}
|
|
|
|
else if( typeId == TYPE_HASH( unsigned int ) || typeId == TYPE_HASH( unsigned long ) )
|
|
|
|
{
|
|
|
|
ret = new wxUIntProperty();
|
|
|
|
}
|
|
|
|
else if( typeId == TYPE_HASH( float ) || typeId == TYPE_HASH( double ) )
|
|
|
|
{
|
|
|
|
ret = new wxFloatProperty();
|
|
|
|
}
|
|
|
|
else if( typeId == TYPE_HASH( bool ) )
|
|
|
|
{
|
2023-01-22 17:10:36 +00:00
|
|
|
ret = new PGPROPERTY_BOOL();
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
else if( typeId == TYPE_HASH( wxString ) )
|
|
|
|
{
|
2022-11-25 18:15:46 +00:00
|
|
|
ret = new PGPROPERTY_STRING();
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
else if( typeId == TYPE_HASH( COLOR4D ) )
|
|
|
|
{
|
|
|
|
ret = new PGPROPERTY_COLOR4D();
|
|
|
|
}
|
2020-02-04 08:40:25 +00:00
|
|
|
else
|
|
|
|
{
|
2023-01-22 17:17:39 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxS( "Property %s not supported by PGPropertyFactory" ),
|
|
|
|
aProperty->Name() ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
ret = new wxPropertyCategory();
|
|
|
|
ret->Enable( false );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ret )
|
|
|
|
{
|
2022-12-21 23:03:15 +00:00
|
|
|
ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
ret->SetName( aProperty->Name() );
|
2022-12-22 22:44:14 +00:00
|
|
|
ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-04 23:01:16 +00:00
|
|
|
PGPROPERTY_DISTANCE::PGPROPERTY_DISTANCE( EDA_DRAW_FRAME* aParentFrame,
|
2022-10-31 01:09:59 +00:00
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType ) :
|
2023-11-10 18:36:02 +00:00
|
|
|
m_parentFrame( aParentFrame ),
|
2022-10-31 01:09:59 +00:00
|
|
|
m_coordType( aCoordType )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PGPROPERTY_DISTANCE::~PGPROPERTY_DISTANCE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
2022-10-31 01:09:59 +00:00
|
|
|
bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
|
2024-03-21 01:51:35 +00:00
|
|
|
wxPGPropValFormatFlags aFlags ) const
|
|
|
|
#else
|
|
|
|
bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aFlags ) const
|
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2022-11-03 02:50:49 +00:00
|
|
|
// TODO(JE): Are there actual use cases for this?
|
2023-01-22 17:17:39 +00:00
|
|
|
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aFlags ) const
|
|
|
|
#else
|
|
|
|
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const
|
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2024-01-10 00:25:05 +00:00
|
|
|
long distanceIU;
|
|
|
|
|
|
|
|
if( aVariant.GetType() == wxT( "std::optional<int>" ) )
|
|
|
|
{
|
|
|
|
auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
|
|
|
|
|
|
|
|
if( !variantData->Value().has_value() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
distanceIU = variantData->Value().value();
|
|
|
|
}
|
|
|
|
else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
|
|
|
|
{
|
|
|
|
distanceIU = aVariant.GetLong();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2020-02-04 08:40:25 +00:00
|
|
|
|
2024-02-05 16:52:04 +00:00
|
|
|
ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
|
2022-10-31 01:09:59 +00:00
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
distanceIU = transforms.ToDisplay( static_cast<long long int>( distanceIU ), m_coordType );
|
2022-10-31 01:09:59 +00:00
|
|
|
|
2024-02-05 16:52:04 +00:00
|
|
|
return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-04 23:01:16 +00:00
|
|
|
PGPROPERTY_AREA::PGPROPERTY_AREA( EDA_DRAW_FRAME* aParentFrame ) :
|
|
|
|
wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
|
|
|
|
m_parentFrame( aParentFrame )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2024-02-04 23:01:16 +00:00
|
|
|
bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-02-04 23:01:16 +00:00
|
|
|
{
|
|
|
|
// TODO(JE): Are there actual use cases for this?
|
|
|
|
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_AREA::StringToValue should not be used." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2024-02-04 23:01:16 +00:00
|
|
|
wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, int aArgFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-02-04 23:01:16 +00:00
|
|
|
{
|
|
|
|
wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG, wxEmptyString );
|
|
|
|
|
|
|
|
wxLongLongNative areaIU = aVariant.GetLongLong();
|
|
|
|
|
|
|
|
return m_parentFrame->StringFromValue( areaIU.ToDouble(), true, EDA_DATA_TYPE::AREA );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxValidator* PGPROPERTY_AREA::DoGetValidator() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_SIZE::PGPROPERTY_SIZE( EDA_DRAW_FRAME* aParentFrame ) :
|
|
|
|
wxUIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
|
2024-02-04 23:01:16 +00:00
|
|
|
PGPROPERTY_DISTANCE( aParentFrame, ORIGIN_TRANSFORMS::NOT_A_COORD )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
bool PGPROPERTY_SIZE::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
|
|
|
|
{
|
|
|
|
if( aValue.GetType() == wxT( "std::optional<int>" ) )
|
|
|
|
{
|
|
|
|
auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aValue.GetData() );
|
|
|
|
|
|
|
|
if( !data->Value().has_value() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxVariant value( data->Value().value() );
|
|
|
|
return wxUIntProperty::ValidateValue( value, aValidationInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxUIntProperty::ValidateValue( aValue, aValidationInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-04 08:40:25 +00:00
|
|
|
wxValidator* PGPROPERTY_SIZE::DoGetValidator() const
|
|
|
|
{
|
2022-12-03 02:25:42 +00:00
|
|
|
return nullptr;
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-10 18:36:02 +00:00
|
|
|
PGPROPERTY_COORD::PGPROPERTY_COORD( EDA_DRAW_FRAME* aParentFrame,
|
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType ) :
|
|
|
|
wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
|
2024-02-04 23:01:16 +00:00
|
|
|
PGPROPERTY_DISTANCE( aParentFrame, aCoordType )
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxValidator* PGPROPERTY_COORD::DoGetValidator() const
|
|
|
|
{
|
2022-11-03 02:50:49 +00:00
|
|
|
return nullptr;
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-10 00:25:05 +00:00
|
|
|
PGPROPERTY_RATIO::PGPROPERTY_RATIO() :
|
|
|
|
wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 )
|
|
|
|
{
|
|
|
|
SetEditor( PG_RATIO_EDITOR::EDITOR_NAME );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxPGEditor* PGPROPERTY_RATIO::DoGetEditorClass() const
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( m_customEditor, wxPGEditor_TextCtrl,
|
|
|
|
wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_RATIO!" ) );
|
|
|
|
return m_customEditor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2024-01-10 00:25:05 +00:00
|
|
|
bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-01-10 00:25:05 +00:00
|
|
|
{
|
|
|
|
// TODO(JE): Are there actual use cases for this?
|
|
|
|
wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2024-01-10 00:25:05 +00:00
|
|
|
wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, int aArgFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2024-01-10 00:25:05 +00:00
|
|
|
{
|
|
|
|
double value;
|
|
|
|
|
|
|
|
if( aVariant.GetType() == wxT( "std::optional<double>" ) )
|
|
|
|
{
|
|
|
|
auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
|
|
|
|
|
|
|
|
if( !variantData->Value().has_value() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
value = variantData->Value().value();
|
|
|
|
}
|
|
|
|
else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
|
|
|
|
{
|
|
|
|
value = aVariant.GetDouble();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "Expected double (or std::optional<double>) value type" ) );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxString::Format( wxS( "%g" ), value );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PGPROPERTY_RATIO::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
|
|
|
|
{
|
|
|
|
if( aValue.GetType() == wxT( "std::optional<double>" ) )
|
|
|
|
{
|
|
|
|
auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aValue.GetData() );
|
|
|
|
|
|
|
|
if( !data->Value().has_value() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxVariant value( data->Value().value() );
|
|
|
|
return wxFloatProperty::ValidateValue( value, aValidationInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxFloatProperty::ValidateValue( aValue, aValidationInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxValidator* PGPROPERTY_RATIO::DoGetValidator() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
|
|
|
bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
|
|
|
|
int aArgFlags ) const
|
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
|
|
|
double value = 0.0;
|
|
|
|
|
|
|
|
if( !aText.ToDouble( &value ) )
|
|
|
|
{
|
|
|
|
aVariant.MakeNull();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
value *= m_scale;
|
|
|
|
|
|
|
|
if( aVariant.IsNull() || aVariant.GetDouble() != value )
|
|
|
|
{
|
|
|
|
aVariant = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2020-02-04 08:40:25 +00:00
|
|
|
wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2020-02-04 08:40:25 +00:00
|
|
|
{
|
2022-11-03 02:50:49 +00:00
|
|
|
if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
|
|
|
|
{
|
|
|
|
// TODO(JE) Is this still needed?
|
2023-01-22 17:17:39 +00:00
|
|
|
return wxString::Format( wxS( "%g\u00B0" ), aVariant.GetDouble() / m_scale );
|
2022-11-03 02:50:49 +00:00
|
|
|
}
|
2023-01-22 17:17:39 +00:00
|
|
|
else if( aVariant.GetType() == wxS( "EDA_ANGLE" ) )
|
2022-11-03 02:50:49 +00:00
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-22 17:17:39 +00:00
|
|
|
wxCHECK_MSG( false, wxEmptyString, wxS( "Unexpected variant type in PGPROPERTY_ANGLE" ) );
|
2022-11-03 02:50:49 +00:00
|
|
|
}
|
2020-02-04 08:40:25 +00:00
|
|
|
}
|
2021-08-22 15:59:02 +00:00
|
|
|
|
|
|
|
|
2022-12-03 02:25:42 +00:00
|
|
|
wxValidator* PGPROPERTY_ANGLE::DoGetValidator() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-22 15:59:02 +00:00
|
|
|
wxSize PGPROPERTY_COLORENUM::OnMeasureImage( int aItem ) const
|
|
|
|
{
|
|
|
|
// TODO(JE) calculate size from window metrics?
|
|
|
|
return wxSize( 16, 12 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
|
|
|
|
wxPGPaintData& aPaintData )
|
|
|
|
{
|
|
|
|
int index = aPaintData.m_choiceItem;
|
|
|
|
|
|
|
|
if( index < 0 )
|
|
|
|
index = GetIndex();
|
|
|
|
|
2022-08-22 02:31:06 +00:00
|
|
|
// GetIndex can return -1 when the control hasn't been set up yet
|
|
|
|
if( index < 0 || index >= static_cast<int>( GetChoices().GetCount() ) )
|
|
|
|
return;
|
|
|
|
|
2023-01-22 17:17:39 +00:00
|
|
|
wxColour color = GetColor( GetChoices().GetValue( index ) );
|
2021-08-22 15:59:02 +00:00
|
|
|
|
|
|
|
if( color == wxNullColour )
|
|
|
|
return;
|
|
|
|
|
|
|
|
aDC.SetPen( *wxTRANSPARENT_PEN );
|
|
|
|
aDC.SetBrush( wxBrush( color ) );
|
|
|
|
aDC.DrawRectangle( aRect );
|
2022-08-22 02:31:06 +00:00
|
|
|
|
|
|
|
aPaintData.m_drawnWidth = aRect.width;
|
2021-08-22 15:59:02 +00:00
|
|
|
}
|
2022-11-25 18:15:46 +00:00
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue,
|
|
|
|
wxPGPropValFormatFlags aFlags ) const
|
|
|
|
#else
|
2022-11-25 18:15:46 +00:00
|
|
|
wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2022-11-25 18:15:46 +00:00
|
|
|
{
|
|
|
|
if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
return UnescapeString( aValue.GetString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2022-11-25 18:15:46 +00:00
|
|
|
bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
|
|
|
|
int aFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2022-11-25 18:15:46 +00:00
|
|
|
{
|
|
|
|
aVariant = EscapeString( aString, CTX_QUOTED_STR );
|
|
|
|
return true;
|
|
|
|
}
|
2023-01-22 17:10:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) :
|
|
|
|
wxBoolProperty( aLabel, aName, aValue )
|
|
|
|
{
|
|
|
|
SetEditor( PG_CHECKBOX_EDITOR::EDITOR_NAME );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
|
2024-01-10 00:25:05 +00:00
|
|
|
wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_BOOL!" ) );
|
2023-01-22 17:10:36 +00:00
|
|
|
return m_customEditor;
|
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
|
2023-06-30 02:53:06 +00:00
|
|
|
COLOR4D aValue, COLOR4D aBackgroundColor ) :
|
|
|
|
wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
|
|
|
|
m_backgroundColor( aBackgroundColor )
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
2023-06-29 03:54:27 +00:00
|
|
|
SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
SetFlag( wxPGPropertyFlags::NoEditor );
|
|
|
|
#else
|
2023-06-29 03:54:27 +00:00
|
|
|
SetFlag( wxPG_PROP_NOEDITOR );
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
|
|
|
|
wxPGPropValFormatFlags aArgFlags ) const
|
|
|
|
#else
|
2023-06-21 01:57:20 +00:00
|
|
|
bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
|
|
|
|
int aFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
|
|
|
aVariant.SetData( new COLOR4D_VARIANT_DATA( aString ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 01:51:35 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 3, 0 )
|
|
|
|
wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue,
|
|
|
|
wxPGPropValFormatFlags aFlags ) const
|
|
|
|
#else
|
2023-06-21 01:57:20 +00:00
|
|
|
wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) const
|
2024-03-21 01:51:35 +00:00
|
|
|
#endif
|
2023-06-21 01:57:20 +00:00
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
|
|
|
|
if( aValue.IsType( wxS( "COLOR4D" ) ) )
|
|
|
|
static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
|
|
|
|
else
|
2023-06-29 03:54:27 +00:00
|
|
|
return wxStringProperty::ValueToString( aValue, aFlags );
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|