Browse Source
Properties: move to custom editor for distances; refactoring
Properties: move to custom editor for distances; refactoring
Also fix display of angle values since EDA_ANGLE was introduced Fixes https://gitlab.com/kicad/code/kicad/-/issues/122907.0
19 changed files with 360 additions and 107 deletions
-
7common/CMakeLists.txt
-
87common/properties/eda_angle_variant.cpp
-
84common/properties/pg_editors.cpp
-
115common/properties/pg_properties.cpp
-
4common/properties/property_mgr.cpp
-
23common/widgets/unit_binder.cpp
-
4include/inspectable.h
-
52include/properties/eda_angle_variant.h
-
51include/properties/pg_editors.h
-
1include/properties/pg_properties.h
-
3include/properties/property.h
-
0include/properties/property_mgr.h
-
16include/widgets/unit_binder.h
-
8pcbnew/dialogs/pcb_properties_panel.cpp
-
2pcbnew/dialogs/pcb_properties_panel.h
-
4pcbnew/pcb_expr_evaluator.h
-
2qa/tools/drc_proto/drc_proto.cpp
-
2qa/tools/drc_proto/drc_proto_test.cpp
-
2qa/unittests/common/test_property.cpp
@ -0,0 +1,87 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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/>.
|
|||
*/ |
|||
|
|||
#include <properties/eda_angle_variant.h>
|
|||
|
|||
|
|||
EDA_ANGLE_VARIANT_DATA::EDA_ANGLE_VARIANT_DATA() : |
|||
wxVariantData() |
|||
{} |
|||
|
|||
|
|||
EDA_ANGLE_VARIANT_DATA::EDA_ANGLE_VARIANT_DATA( double aAngleDegrees ) : |
|||
wxVariantData(), |
|||
m_angle( aAngleDegrees, DEGREES_T ) |
|||
{} |
|||
|
|||
|
|||
EDA_ANGLE_VARIANT_DATA::EDA_ANGLE_VARIANT_DATA( const EDA_ANGLE& aAngle ) : |
|||
wxVariantData(), |
|||
m_angle( aAngle ) |
|||
{} |
|||
|
|||
|
|||
bool EDA_ANGLE_VARIANT_DATA::Eq( wxVariantData& aOther ) const |
|||
{ |
|||
try |
|||
{ |
|||
EDA_ANGLE_VARIANT_DATA& evd = dynamic_cast<EDA_ANGLE_VARIANT_DATA&>( aOther ); |
|||
|
|||
return evd.m_angle == m_angle; |
|||
} |
|||
catch( std::bad_cast& ) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
|
|||
bool EDA_ANGLE_VARIANT_DATA::Read( wxString& aString ) |
|||
{ |
|||
double val; |
|||
|
|||
if( !aString.ToDouble( &val ) ) |
|||
return false; |
|||
|
|||
m_angle = EDA_ANGLE( val, DEGREES_T ); |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool EDA_ANGLE_VARIANT_DATA::Write( wxString& aString ) const |
|||
{ |
|||
aString = wxString::Format( wxT("%g\u00B0"), m_angle.AsDegrees() ); |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool EDA_ANGLE_VARIANT_DATA::GetAsAny( wxAny* aAny ) const |
|||
{ |
|||
*aAny = m_angle.AsDegrees(); |
|||
return true; |
|||
} |
|||
|
|||
|
|||
wxVariantData* EDA_ANGLE_VARIANT_DATA::VariantDataFactory( const wxAny& aAny ) |
|||
{ |
|||
return new EDA_ANGLE_VARIANT_DATA( aAny.As<EDA_ANGLE>() ); |
|||
} |
|||
|
|||
|
|||
REGISTER_WXANY_CONVERSION( EDA_ANGLE, EDA_ANGLE_VARIANT_DATA ) |
|||
@ -0,0 +1,84 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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/>.
|
|||
*/ |
|||
|
|||
#include <properties/pg_editors.h>
|
|||
#include <properties/pg_properties.h>
|
|||
#include <widgets/unit_binder.h>
|
|||
|
|||
#include <wx/log.h>
|
|||
|
|||
|
|||
PG_UNIT_EDITOR::PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ) : |
|||
wxPGTextCtrlEditor(), |
|||
m_frame( aFrame ) |
|||
{ |
|||
m_unitBinder = std::make_unique<PROPERTY_EDITOR_UNIT_BINDER>( m_frame ); |
|||
} |
|||
|
|||
|
|||
PG_UNIT_EDITOR::~PG_UNIT_EDITOR() |
|||
{ |
|||
} |
|||
|
|||
|
|||
wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty, |
|||
const wxPoint& aPos, const wxSize& aSize ) const |
|||
{ |
|||
wxPGWindowList ret = wxPGTextCtrlEditor::CreateControls( aPropGrid, aProperty, aPos, aSize ); |
|||
|
|||
m_unitBinder->SetControl( ret.m_primary ); |
|||
m_unitBinder->RequireEval(); |
|||
|
|||
if( PGPROPERTY_DISTANCE* prop = dynamic_cast<PGPROPERTY_DISTANCE*>( aProperty ) ) |
|||
m_unitBinder->SetCoordType( prop->CoordType() ); |
|||
|
|||
return ret; |
|||
} |
|||
|
|||
|
|||
bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty, |
|||
wxWindow* aCtrl ) const |
|||
{ |
|||
wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( aCtrl ); |
|||
wxCHECK_MSG( textCtrl, false, "PG_UNIT_EDITOR requires a text control!" ); |
|||
wxString textVal = textCtrl->GetValue(); |
|||
|
|||
if( aProperty->UsesAutoUnspecified() && textVal.empty() ) |
|||
{ |
|||
aVariant.MakeNull(); |
|||
return true; |
|||
} |
|||
|
|||
long result = m_unitBinder->GetValue(); |
|||
|
|||
bool changed = ( result != aVariant.GetLong() ); |
|||
|
|||
if( changed ) |
|||
{ |
|||
aVariant = result; |
|||
m_unitBinder->SetValue( result ); |
|||
} |
|||
|
|||
// Changing unspecified always causes event (returning
|
|||
// true here should be enough to trigger it).
|
|||
if( !changed && aVariant.IsNull() ) |
|||
changed = true; |
|||
|
|||
return changed; |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 KICAD_EDA_ANGLE_VARIANT_H |
|||
#define KICAD_EDA_ANGLE_VARIANT_H |
|||
|
|||
#include <geometry/eda_angle.h> |
|||
|
|||
#include <wx/variant.h> |
|||
|
|||
class EDA_ANGLE_VARIANT_DATA : public wxVariantData |
|||
{ |
|||
public: |
|||
EDA_ANGLE_VARIANT_DATA(); |
|||
|
|||
EDA_ANGLE_VARIANT_DATA( double aAngleDegrees ); |
|||
|
|||
EDA_ANGLE_VARIANT_DATA( const EDA_ANGLE& aAngle ); |
|||
|
|||
bool Eq( wxVariantData& aOther ) const override; |
|||
|
|||
wxString GetType() const override { return wxT( "EDA_ANGLE" ); } |
|||
|
|||
bool Read( wxString& aString ) override; |
|||
|
|||
bool Write( wxString& aString ) const override; |
|||
|
|||
bool GetAsAny( wxAny* aAny ) const override; |
|||
|
|||
static wxVariantData* VariantDataFactory( const wxAny& aAny ); |
|||
|
|||
protected: |
|||
EDA_ANGLE m_angle; |
|||
}; |
|||
|
|||
#endif //KICAD_EDA_ANGLE_VARIANT_H |
|||
@ -0,0 +1,51 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 KICAD_PG_EDITORS_H |
|||
#define KICAD_PG_EDITORS_H |
|||
|
|||
#include <memory> |
|||
|
|||
#include <wx/propgrid/propgrid.h> |
|||
#include <wx/propgrid/editors.h> |
|||
|
|||
class EDA_DRAW_FRAME; |
|||
class PROPERTY_EDITOR_UNIT_BINDER; |
|||
|
|||
class PG_UNIT_EDITOR : public wxPGTextCtrlEditor |
|||
{ |
|||
public: |
|||
PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ); |
|||
|
|||
virtual ~PG_UNIT_EDITOR(); |
|||
|
|||
wxString GetName() const override { return wxT( "UnitEditor" ); } |
|||
|
|||
wxPGWindowList CreateControls( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty, |
|||
const wxPoint& aPos, const wxSize& aSize ) const override; |
|||
|
|||
bool GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty, |
|||
wxWindow* aCtrl ) const override; |
|||
protected: |
|||
EDA_DRAW_FRAME* m_frame; |
|||
|
|||
std::unique_ptr<PROPERTY_EDITOR_UNIT_BINDER> m_unitBinder; |
|||
}; |
|||
|
|||
#endif //KICAD_PG_EDITORS_H |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue