Properties: Move angles to UNIT_BINDER
Also add support for unicode degree sign in evaluator
This commit is contained in:
parent
5e352d2a66
commit
2091aaba2f
|
@ -83,10 +83,11 @@ void NUMERIC_EVALUATOR::SetDefaultUnits( EDA_UNITS aUnits )
|
||||||
{
|
{
|
||||||
switch( aUnits )
|
switch( aUnits )
|
||||||
{
|
{
|
||||||
case EDA_UNITS::MILLIMETRES: m_defaultUnits = Unit::MM; break;
|
case EDA_UNITS::MILLIMETRES: m_defaultUnits = Unit::MM; break;
|
||||||
case EDA_UNITS::MILS: m_defaultUnits = Unit::Mil; break;
|
case EDA_UNITS::MILS: m_defaultUnits = Unit::Mil; break;
|
||||||
case EDA_UNITS::INCHES: m_defaultUnits = Unit::Inch; break;
|
case EDA_UNITS::INCHES: m_defaultUnits = Unit::Inch; break;
|
||||||
default: m_defaultUnits = Unit::MM; break;
|
case EDA_UNITS::DEGREES: m_defaultUnits = Unit::Degrees; break;
|
||||||
|
default: m_defaultUnits = Unit::MM; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +138,9 @@ bool NUMERIC_EVALUATOR::Process( const wxString& aString )
|
||||||
m_parseFinished = false;
|
m_parseFinished = false;
|
||||||
Token tok;
|
Token tok;
|
||||||
|
|
||||||
|
FILE* f = fopen( "C:\\Users\\jon\\log.txt", "w" );
|
||||||
|
numEval::ParseTrace( f, "parser: " );
|
||||||
|
|
||||||
if( aString.IsEmpty() )
|
if( aString.IsEmpty() )
|
||||||
{
|
{
|
||||||
m_parseFinished = true;
|
m_parseFinished = true;
|
||||||
|
@ -156,6 +160,8 @@ bool NUMERIC_EVALUATOR::Process( const wxString& aString )
|
||||||
}
|
}
|
||||||
} while( tok.token );
|
} while( tok.token );
|
||||||
|
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
return !m_parseError;
|
return !m_parseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,10 +171,10 @@ void NUMERIC_EVALUATOR::newString( const wxString& aString )
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
m_originalText = aString;
|
m_originalText = aString;
|
||||||
m_token.inputLen = aString.length();
|
m_token.input = aString.mb_str();
|
||||||
|
m_token.inputLen = strlen( m_token.input );
|
||||||
m_token.outputLen = std::max<std::size_t>( 64, m_token.inputLen + 1 );
|
m_token.outputLen = std::max<std::size_t>( 64, m_token.inputLen + 1 );
|
||||||
m_token.pos = 0;
|
m_token.pos = 0;
|
||||||
m_token.input = aString.mb_str();
|
|
||||||
m_token.token = new char[m_token.outputLen]();
|
m_token.token = new char[m_token.outputLen]();
|
||||||
m_token.token[0] = '0';
|
m_token.token[0] = '0';
|
||||||
|
|
||||||
|
@ -249,6 +255,13 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
|
||||||
const char* cptr = &m_token.input[ m_token.pos ];
|
const char* cptr = &m_token.input[ m_token.pos ];
|
||||||
const auto sizeLeft = m_token.inputLen - m_token.pos;
|
const auto sizeLeft = m_token.inputLen - m_token.pos;
|
||||||
|
|
||||||
|
// We should really give this unicode support
|
||||||
|
if( sizeLeft >= 2 && ch == '\xC2' && cptr[1] == '\xB0' )
|
||||||
|
{
|
||||||
|
m_token.pos += 2;
|
||||||
|
return Unit::Degrees;
|
||||||
|
}
|
||||||
|
|
||||||
if( sizeLeft >= 2 && ch == 'm' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) )
|
if( sizeLeft >= 2 && ch == 'm' && cptr[ 1 ] == 'm' && !isalnum( cptr[ 2 ] ) )
|
||||||
{
|
{
|
||||||
m_token.pos += 2;
|
m_token.pos += 2;
|
||||||
|
@ -353,6 +366,10 @@ NUMERIC_EVALUATOR::Token NUMERIC_EVALUATOR::getToken()
|
||||||
case Unit::Invalid: break;
|
case Unit::Invalid: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( m_defaultUnits == Unit::Degrees && convertFrom == Unit::Degrees )
|
||||||
|
{
|
||||||
|
retval.value.dValue = 1.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if( isalpha( ch ) )
|
else if( isalpha( ch ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <eda_draw_frame.h>
|
#include <eda_draw_frame.h>
|
||||||
|
#include <properties/eda_angle_variant.h>
|
||||||
#include <properties/pg_editors.h>
|
#include <properties/pg_editors.h>
|
||||||
#include <properties/pg_properties.h>
|
#include <properties/pg_properties.h>
|
||||||
#include <widgets/unit_binder.h>
|
#include <widgets/unit_binder.h>
|
||||||
|
@ -69,6 +70,8 @@ wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGPr
|
||||||
|
|
||||||
if( PGPROPERTY_DISTANCE* prop = dynamic_cast<PGPROPERTY_DISTANCE*>( aProperty ) )
|
if( PGPROPERTY_DISTANCE* prop = dynamic_cast<PGPROPERTY_DISTANCE*>( aProperty ) )
|
||||||
m_unitBinder->SetCoordType( prop->CoordType() );
|
m_unitBinder->SetCoordType( prop->CoordType() );
|
||||||
|
else if( PGPROPERTY_ANGLE* prop = dynamic_cast<PGPROPERTY_ANGLE*>( aProperty ) )
|
||||||
|
m_unitBinder->SetUnits( EDA_UNITS::DEGREES );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +90,16 @@ bool PG_UNIT_EDITOR::OnEvent( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty
|
||||||
{
|
{
|
||||||
if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( aCtrl ) )
|
if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( aCtrl ) )
|
||||||
{
|
{
|
||||||
textCtrl->SelectAll();
|
if( !textCtrl->HasFocus() )
|
||||||
return false;
|
{
|
||||||
|
textCtrl->SelectAll();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( aEvent.GetEventType() == wxEVT_KILL_FOCUS )
|
||||||
|
wxLogDebug( "test" );
|
||||||
|
|
||||||
return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
|
return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
|
||||||
}
|
}
|
||||||
|
@ -111,15 +120,29 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr
|
||||||
aVariant.MakeNull();
|
aVariant.MakeNull();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
long result = m_unitBinder->GetValue();
|
if( dynamic_cast<PGPROPERTY_ANGLE*>( aProperty ) )
|
||||||
|
|
||||||
bool changed = ( aVariant.IsNull() || result != aVariant.GetLong() );
|
|
||||||
|
|
||||||
if( changed )
|
|
||||||
{
|
{
|
||||||
aVariant = result;
|
double result = m_unitBinder->GetAngleValue().AsDegrees();
|
||||||
m_unitBinder->SetValue( result );
|
changed = ( aVariant.IsNull() || result != aVariant.GetDouble() );
|
||||||
|
|
||||||
|
if( changed )
|
||||||
|
{
|
||||||
|
aVariant = result;
|
||||||
|
m_unitBinder->SetValue( result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long result = m_unitBinder->GetValue();
|
||||||
|
changed = ( aVariant.IsNull() || result != aVariant.GetLong() );
|
||||||
|
|
||||||
|
if( changed )
|
||||||
|
{
|
||||||
|
aVariant = result;
|
||||||
|
m_unitBinder->SetValue( result );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changing unspecified always causes event (returning
|
// Changing unspecified always causes event (returning
|
||||||
|
|
|
@ -105,6 +105,7 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty )
|
||||||
prop->SetScale( 10.0 );
|
prop->SetScale( 10.0 );
|
||||||
|
|
||||||
ret = prop;
|
ret = prop;
|
||||||
|
ret->SetEditor( PG_UNIT_EDITOR::EDITOR_NAME );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,8 +236,7 @@ PGPROPERTY_SIZE::PGPROPERTY_SIZE( const wxString& aLabel, const wxString& aName,
|
||||||
|
|
||||||
wxValidator* PGPROPERTY_SIZE::DoGetValidator() const
|
wxValidator* PGPROPERTY_SIZE::DoGetValidator() const
|
||||||
{
|
{
|
||||||
//return m_regExValidator.get();
|
return nullptr;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,7 +250,6 @@ PGPROPERTY_COORD::PGPROPERTY_COORD( const wxString& aLabel, const wxString& aNam
|
||||||
|
|
||||||
wxValidator* PGPROPERTY_COORD::DoGetValidator() const
|
wxValidator* PGPROPERTY_COORD::DoGetValidator() const
|
||||||
{
|
{
|
||||||
//return m_regExValidator.get();
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +296,12 @@ wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxValidator* PGPROPERTY_ANGLE::DoGetValidator() const
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxSize PGPROPERTY_COLORENUM::OnMeasureImage( int aItem ) const
|
wxSize PGPROPERTY_COLORENUM::OnMeasureImage( int aItem ) const
|
||||||
{
|
{
|
||||||
// TODO(JE) calculate size from window metrics?
|
// TODO(JE) calculate size from window metrics?
|
||||||
|
|
|
@ -346,8 +346,13 @@ void UNIT_BINDER::SetValue( const wxString& aValue )
|
||||||
wxString value = aValue;
|
wxString value = aValue;
|
||||||
|
|
||||||
if( m_unitsInValue )
|
if( m_unitsInValue )
|
||||||
value += wxT( " " ) + EDA_UNIT_UTILS::GetLabel( m_units, m_dataType );
|
{
|
||||||
|
if( !( m_units == EDA_UNITS::DEGREES || m_units == EDA_UNITS::PERCENT ) )
|
||||||
|
value += wxT( " " );
|
||||||
|
|
||||||
|
value += EDA_UNIT_UTILS::GetLabel( m_units, m_dataType );
|
||||||
|
}
|
||||||
|
|
||||||
if( textEntry )
|
if( textEntry )
|
||||||
textEntry->SetValue( value );
|
textEntry->SetValue( value );
|
||||||
else if( staticText )
|
else if( staticText )
|
||||||
|
@ -404,7 +409,12 @@ void UNIT_BINDER::ChangeValue( const wxString& aValue )
|
||||||
wxString value = aValue;
|
wxString value = aValue;
|
||||||
|
|
||||||
if( m_unitsInValue )
|
if( m_unitsInValue )
|
||||||
value += wxT( " " ) + EDA_UNIT_UTILS::GetLabel( m_units, m_dataType );
|
{
|
||||||
|
if( !( m_units == EDA_UNITS::DEGREES || m_units == EDA_UNITS::PERCENT ) )
|
||||||
|
value += wxT( " " );
|
||||||
|
|
||||||
|
value += EDA_UNIT_UTILS::GetLabel( m_units, m_dataType );
|
||||||
|
}
|
||||||
|
|
||||||
if( textEntry )
|
if( textEntry )
|
||||||
textEntry->ChangeValue( value );
|
textEntry->ChangeValue( value );
|
||||||
|
|
|
@ -93,7 +93,7 @@ namespace numEval
|
||||||
|
|
||||||
class NUMERIC_EVALUATOR
|
class NUMERIC_EVALUATOR
|
||||||
{
|
{
|
||||||
enum class Unit { Invalid, MM, CM, Inch, Mil };
|
enum class Unit { Invalid, MM, CM, Inch, Mil, Degrees };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NUMERIC_EVALUATOR( EDA_UNITS aUnits );
|
NUMERIC_EVALUATOR( EDA_UNITS aUnits );
|
||||||
|
|
|
@ -45,6 +45,10 @@ public:
|
||||||
|
|
||||||
static wxVariantData* VariantDataFactory( const wxAny& aAny );
|
static wxVariantData* VariantDataFactory( const wxAny& aAny );
|
||||||
|
|
||||||
|
const EDA_ANGLE& Angle() { return m_angle; }
|
||||||
|
|
||||||
|
void SetAngle( const EDA_ANGLE& aAngle ) { m_angle = aAngle; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EDA_ANGLE m_angle;
|
EDA_ANGLE m_angle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -111,6 +111,8 @@ public:
|
||||||
m_scale = aScale;
|
m_scale = aScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxValidator* DoGetValidator() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///> Scale factor to convert between raw and displayed value
|
///> Scale factor to convert between raw and displayed value
|
||||||
double m_scale;
|
double m_scale;
|
||||||
|
|
Loading…
Reference in New Issue