From 5c646119a7f72a294848101f971ac8b092dbc455 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 21 Jul 2018 13:49:19 +0100 Subject: [PATCH] Allow user-specification of dimension units. Also fixes a units bug when round-tripping a dimension through the file format. Fixes: lp:1782797 * https://bugs.launchpad.net/kicad/+bug/1782797 --- common/base_units.cpp | 75 ++-- include/base_units.h | 12 +- pcbnew/class_dimension.cpp | 14 +- pcbnew/class_dimension.h | 16 +- pcbnew/dialogs/dialog_text_properties.cpp | 122 ++++-- pcbnew/dialogs/dialog_text_properties.h | 2 + .../dialogs/dialog_text_properties_base.cpp | 29 ++ .../dialogs/dialog_text_properties_base.fbp | 363 ++++++++++++++++++ pcbnew/dialogs/dialog_text_properties_base.h | 9 +- pcbnew/dimension.cpp | 2 +- pcbnew/eagle_plugin.cpp | 3 +- pcbnew/pcb_parser.cpp | 7 + pcbnew/tools/drawing_tool.cpp | 3 +- 13 files changed, 591 insertions(+), 66 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 2f6bd7e2cd..10eccf6d15 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -166,7 +166,7 @@ wxString MessageTextFromValue( EDA_UNITS_T aUnits, double aValue, bool aUseMils text.Printf( format, value ); text += " "; - text += GetAbbreviatedUnitsLabel( aUnits ); + text += GetAbbreviatedUnitsLabel( aUnits, aUseMils ); return text; } @@ -367,6 +367,54 @@ double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bo } +void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS_T& aUnits, bool& aUseMils ) +{ + // Acquire the 'right' decimal point separator + const struct lconv* lc = localeconv(); + + wxChar decimal_point = lc->decimal_point[0]; + wxString buf( aTextValue.Strip( wxString::both ) ); + + // Convert the period in decimal point + buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) ); + + // Find the end of the numeric part + unsigned brk_point = 0; + + while( brk_point < buf.Len() ) + { + wxChar ch = buf[brk_point]; + + if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) ) + break; + + ++brk_point; + } + + // Check the unit designator (2 ch significant) + wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() ); + + if( unit == wxT( "in" ) || unit == wxT( "\"" ) ) + { + aUnits = INCHES; + aUseMils = false; + } + else if( unit == wxT( "mm" ) ) + { + aUnits = MILLIMETRES; + } + else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou" + { + aUnits = INCHES; + aUseMils = true; + } + else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad" + { + aUnits = DEGREES; + } +} + + int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMils ) { double value = DoubleValueFromString( aUnits, aTextValue, aUseMils ); @@ -390,31 +438,6 @@ wxString AngleToStringDegrees( double aAngle ) } -wxString GetUnitsLabel( EDA_UNITS_T aUnit, bool aUseMils ) -{ - switch( aUnit ) - { - case INCHES: - if( aUseMils ) - return _( "mils" ); - else - return _( "inches" ); - - case MILLIMETRES: - return _( "millimeters" ); - - case UNSCALED_UNITS: - return _( "units" ); - - case DEGREES: - return _( "degrees" ); - - default: - return wxT( "??" ); - } -} - - wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit, bool aUseMils ) { switch( aUnit ) diff --git a/include/base_units.h b/include/base_units.h index b18b891222..20450115c6 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -163,15 +163,17 @@ double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMils = false ); /** - * Get a human readable units string. - * - * The strings returned are full text name and not abbreviations or symbolic - * representations of the units. Use ReturnUnitSymbol() for that. + * Function FetchUnitsFromString + * writes any unit info found in the string to aUnits and aUseMils. + */ +void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS_T& aUnits, bool& aUseMils ); + +/** + * Get the units string for a given units type. * * @param aUnits - The units requested. * @return The human readable units string. */ -wxString GetUnitsLabel( EDA_UNITS_T aUnits, bool aUseMils = false ); wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit, bool aUseMils = false ); diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index c848e5f191..4fbb5353ee 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -46,7 +46,12 @@ DIMENSION::DIMENSION( BOARD_ITEM* aParent ) : BOARD_ITEM( aParent, PCB_DIMENSION_T ), - m_Width( Millimeter2iu( 0.2 ) ), m_Unit( INCHES ), m_Value( 0 ), m_Height( 0 ), m_Text( this ) + m_Width( Millimeter2iu( 0.2 ) ), + m_Unit( INCHES ), + m_UseMils( false ), + m_Value( 0 ), + m_Height( 0 ), + m_Text( this ) { m_Layer = Dwgs_User; m_Shape = 0; @@ -206,7 +211,7 @@ void DIMENSION::UpdateHeight() } -void DIMENSION::AdjustDimensionDetails( EDA_UNITS_T aUnits ) +void DIMENSION::AdjustDimensionDetails() { const int arrowz = Mils2iu( 50 ); // size of arrows int ii; @@ -216,9 +221,6 @@ void DIMENSION::AdjustDimensionDetails( EDA_UNITS_T aUnits ) int hx, hy; // dimension line interval double angle, angle_f; - if( aUnits != UNSCALED_UNITS ) - m_Unit = aUnits; - // Init layer : m_Text.SetLayer( GetLayer() ); @@ -317,7 +319,7 @@ void DIMENSION::AdjustDimensionDetails( EDA_UNITS_T aUnits ) m_Text.SetTextAngle( newAngle ); m_Value = measure; - SetText( MessageTextFromValue( m_Unit, m_Value ) ); + SetText( MessageTextFromValue( m_Unit, m_Value, m_UseMils ) ); } diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index c4aa354c11..e7bc0a51bf 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -64,6 +64,7 @@ class DIMENSION : public BOARD_ITEM int m_Width; ///< Line width int m_Shape; ///< Currently always 0. EDA_UNITS_T m_Unit; ///< 0 = inches, 1 = mm + bool m_UseMils; ///< If inches, use mils. int m_Value; ///< value of PCB dimensions. int m_Height; ///< length of feature lines TEXTE_PCB m_Text; @@ -173,9 +174,20 @@ public: /** * Function AdjustDimensionDetails * Calculate coordinates of segments used to draw the dimension. - * @param aUnits the units for the dimension text, or UNSCALED_UNITS to leave unchanged */ - void AdjustDimensionDetails( EDA_UNITS_T aUnits = UNSCALED_UNITS ); + void AdjustDimensionDetails(); + + void GetUnits( EDA_UNITS_T& aUnits, bool& aUseMils ) const + { + aUnits = m_Unit; + aUseMils = m_UseMils; + } + + void SetUnits( EDA_UNITS_T aUnits, bool aUseMils ) + { + m_Unit = aUnits; + m_UseMils = aUseMils; + } void SetText( const wxString& NewText ); const wxString GetText() const; diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index d99f91f487..180ec789c6 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -61,8 +61,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_posY( aParent, m_PositionYLabel, m_PositionYCtrl, m_PositionYUnits ), m_OrientValidator( 1, &m_OrientValue ) { - wxString title, label; - bool multiLine = false; + wxString title; if( m_item->Type() == PCB_DIMENSION_T ) { @@ -72,9 +71,12 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_edaText = &dimension->Text(); m_pcbText = &dimension->Text(); - label = _( "Dimension text:" ); + SetInitialFocus( m_DimensionText ); + m_SingleLineSizer->Show( false ); + m_MultiLineSizer->Show( false ); m_KeepUpright->Show( false ); + m_statusLine->Show( false ); } else if( m_item->Type() == PCB_MODULE_TEXT_T ) { @@ -85,10 +87,14 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO switch( m_modText->GetType() ) { - case TEXTE_MODULE::TEXT_is_REFERENCE: label = _( "Reference:" ); break; - case TEXTE_MODULE::TEXT_is_VALUE: label = _( "Value:" ); break; - case TEXTE_MODULE::TEXT_is_DIVERS: label = _( "Text:" ); break; + case TEXTE_MODULE::TEXT_is_REFERENCE: m_TextLabel->SetLabel( _( "Reference:" ) ); break; + case TEXTE_MODULE::TEXT_is_VALUE: m_TextLabel->SetLabel( _( "Value:" ) ); break; + case TEXTE_MODULE::TEXT_is_DIVERS: m_TextLabel->SetLabel( _( "Text:" ) ); break; } + + SetInitialFocus( m_SingleLineText ); + m_MultiLineSizer->Show( false ); + m_DimensionTextSizer->Show( false ); } else { @@ -96,19 +102,18 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_pcbText = (TEXTE_PCB*) aItem; m_edaText = static_cast( m_pcbText ); - multiLine = true; + + SetInitialFocus( m_MultiLineText ); + m_SingleLineSizer->Show( false ); + m_DimensionTextSizer->Show( false ); m_KeepUpright->Show( false ); + m_statusLine->Show( false ); } SetTitle( title ); m_hash_key = title; - m_TextLabel->SetLabel( label ); - m_SingleLineSizer->Show( !multiLine ); - m_MultiLineSizer->Show( multiLine ); - SetInitialFocus( multiLine ? m_MultiLineText : m_SingleLineText ); - // Configure the layers list selector. Note that footprints are built outside the current // board and so we may need to show all layers if the text is on an unactivated layer. if( !m_Parent->GetBoard()->IsLayerEnabled( m_item->GetLayer() ) ) @@ -190,24 +195,70 @@ void DIALOG_TEXT_PROPERTIES::OnCharHook( wxKeyEvent& aEvent ) } +void DIALOG_TEXT_PROPERTIES::OnDimensionTextChange( wxCommandEvent& event ) +{ + EDA_UNITS_T units = UNSCALED_UNITS; + bool useMils; + + FetchUnitsFromString( m_DimensionText->GetValue(), units, useMils ); + + if( units != UNSCALED_UNITS ) + m_DimensionUnitsOpt->SetSelection( units == MILLIMETRES ? 2 : useMils ? 1 : 0 ); +} + + +void DIALOG_TEXT_PROPERTIES::OnDimensionUnitsChange( wxCommandEvent& event ) +{ + DIMENSION* dimension = (DIMENSION*) m_item; + EDA_UNITS_T units; + bool useMils; + + // Get default units in case dimension text doesn't contain units. + dimension->GetUnits( units, useMils ); + + double value = ValueFromString( units, m_DimensionText->GetValue(), useMils ); + + switch( event.GetSelection() ) + { + case 0: units = INCHES; useMils = false; break; + case 1: units = INCHES; useMils = true; break; + case 2: units = MILLIMETRES; useMils = false; break; + default: break; + } + + m_DimensionText->SetValue( StringFromValue( units, value, true, useMils ) ); +} + + bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() { - wxString msg; - if( m_SingleLineText->IsShown() ) { m_SingleLineText->SetValue( m_edaText->GetText() ); m_SingleLineText->SetSelection( -1, -1 ); } - else + else if( m_MultiLineText->IsShown() ) { m_MultiLineText->SetValue( m_edaText->GetText() ); m_MultiLineText->SetSelection( -1, -1 ); } + else if (m_DimensionText->IsShown() ) + { + m_DimensionText->SetValue( m_edaText->GetText() ); + m_DimensionText->SetSelection( -1, -1 ); + + DIMENSION* dimension = (DIMENSION*) m_item; + EDA_UNITS_T units; + bool useMils; + dimension->GetUnits( units, useMils ); + + m_DimensionUnitsOpt->SetSelection( units == MILLIMETRES ? 2 : useMils ? 1 : 0 ); + } if( m_item->Type() == PCB_MODULE_TEXT_T ) { - MODULE* module = dynamic_cast( m_modText->GetParent() ); + MODULE* module = dynamic_cast( m_modText->GetParent() ); + wxString msg; if( module ) { @@ -217,9 +268,13 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() module->IsFlipped() ? _( "back side (mirrored)" ) : _( "front side" ), module->GetOrientation() / 10.0 ); } - } - m_statusLine->SetLabel( msg ); + m_statusLine->SetLabel( msg ); + } + else + { + m_statusLine->Show( false ); + } m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ); @@ -285,10 +340,31 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() #endif // Set the new text content - if( m_SingleLineText->IsShown() && !m_SingleLineText->GetValue().IsEmpty() ) - m_edaText->SetText( m_SingleLineText->GetValue() ); - else if( m_MultiLineText->IsShown() && !m_MultiLineText->GetValue().IsEmpty() ) - m_edaText->SetText( m_MultiLineText->GetValue() ); + if( m_SingleLineText->IsShown() ) + { + if( !m_SingleLineText->GetValue().IsEmpty() ) + m_edaText->SetText( m_SingleLineText->GetValue() ); + } + else if( m_MultiLineText->IsShown() ) + { + if( !m_MultiLineText->GetValue().IsEmpty() ) + m_edaText->SetText( m_MultiLineText->GetValue() ); + } + else if( m_DimensionText->IsShown() ) + { + if( !m_DimensionText->GetValue().IsEmpty() ) + m_edaText->SetText( m_DimensionText->GetValue() ); + + DIMENSION* dimension = (DIMENSION*) m_item; + + switch( m_DimensionUnitsOpt->GetSelection() ) + { + case 0: dimension->SetUnits( INCHES, false ); break; + case 1: dimension->SetUnits( INCHES, true ); break; + case 2: dimension->SetUnits( MILLIMETRES, false ); break; + default: break; + } + } m_item->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) ); @@ -304,7 +380,7 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() if( m_edaText->GetThickness() > maxthickness ) { - DisplayError( NULL, _( "The text thickness is too large for the text size.\n" + DisplayError( this, _( "The text thickness is too large for the text size.\n" "It will be clamped." ) ); m_edaText->SetThickness( maxthickness ); } diff --git a/pcbnew/dialogs/dialog_text_properties.h b/pcbnew/dialogs/dialog_text_properties.h index c55bb264f1..2ec3decb70 100644 --- a/pcbnew/dialogs/dialog_text_properties.h +++ b/pcbnew/dialogs/dialog_text_properties.h @@ -61,6 +61,8 @@ private: bool TransferDataFromWindow() override; void OnCharHook( wxKeyEvent& aEvent ); + void OnDimensionTextChange( wxCommandEvent& event ) override; + void OnDimensionUnitsChange( wxCommandEvent& event ) override; }; diff --git a/pcbnew/dialogs/dialog_text_properties_base.cpp b/pcbnew/dialogs/dialog_text_properties_base.cpp index 363789eae5..2f25e0d81e 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.cpp +++ b/pcbnew/dialogs/dialog_text_properties_base.cpp @@ -46,6 +46,31 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi bMainSizer->Add( m_SingleLineSizer, 0, wxEXPAND|wxALL, 10 ); + m_DimensionTextSizer = new wxFlexGridSizer( 0, 4, 1, 5 ); + m_DimensionTextSizer->AddGrowableCol( 1 ); + m_DimensionTextSizer->SetFlexibleDirection( wxBOTH ); + m_DimensionTextSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + m_DimensionTextLabel = new wxStaticText( this, wxID_ANY, _("Dimension text:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_DimensionTextLabel->Wrap( -1 ); + m_DimensionTextSizer->Add( m_DimensionTextLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); + + m_DimensionText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_DimensionTextSizer->Add( m_DimensionText, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + + m_staticText18 = new wxStaticText( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText18->Wrap( -1 ); + m_DimensionTextSizer->Add( m_staticText18, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); + + wxString m_DimensionUnitsOptChoices[] = { _("Inches"), _("Mils"), _("Millimeters") }; + int m_DimensionUnitsOptNChoices = sizeof( m_DimensionUnitsOptChoices ) / sizeof( wxString ); + m_DimensionUnitsOpt = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_DimensionUnitsOptNChoices, m_DimensionUnitsOptChoices, 0 ); + m_DimensionUnitsOpt->SetSelection( 0 ); + m_DimensionTextSizer->Add( m_DimensionUnitsOpt, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + + + bMainSizer->Add( m_DimensionTextSizer, 0, wxEXPAND|wxALL, 10 ); + wxFlexGridSizer* fgSizerSetup; fgSizerSetup = new wxFlexGridSizer( 0, 5, 4, 0 ); fgSizerSetup->AddGrowableCol( 1 ); @@ -206,6 +231,8 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi // Connect Events this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnInitDlg ) ); m_SingleLineText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_DimensionText->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnDimensionTextChange ), NULL, this ); + m_DimensionUnitsOpt->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this ); m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); @@ -220,6 +247,8 @@ DIALOG_TEXT_PROPERTIES_BASE::~DIALOG_TEXT_PROPERTIES_BASE() // Disconnect Events this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnInitDlg ) ); m_SingleLineText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); + m_DimensionText->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnDimensionTextChange ), NULL, this ); + m_DimensionUnitsOpt->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this ); m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_ThicknessCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_text_properties_base.fbp b/pcbnew/dialogs/dialog_text_properties_base.fbp index a58cf552c4..210ad00dbb 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.fbp +++ b/pcbnew/dialogs/dialog_text_properties_base.fbp @@ -463,6 +463,369 @@ + + 10 + wxEXPAND|wxALL + 0 + + 4 + wxBOTH + 1 + + 5 + + m_DimensionTextSizer + wxFLEX_GROWMODE_SPECIFIED + protected + 0 + 1 + + 5 + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Dimension text: + + 0 + + + 0 + + 1 + m_DimensionTextLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_DimensionText + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + OnDimensionTextChange + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Units: + + 0 + + + 0 + + 1 + m_staticText18 + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Inches" "Mils" "Millimeters" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + -1,-1 + 1 + m_DimensionUnitsOpt + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnDimensionUnitsChange + + + + + + + + + + + + + + + + + + + + + + + + + + 10 wxEXPAND|wxRIGHT|wxLEFT diff --git a/pcbnew/dialogs/dialog_text_properties_base.h b/pcbnew/dialogs/dialog_text_properties_base.h index ca1d0dc0e3..696a4282be 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.h +++ b/pcbnew/dialogs/dialog_text_properties_base.h @@ -22,9 +22,9 @@ class PCB_LAYER_BOX_SELECTOR; #include #include #include +#include #include #include -#include #include #include #include @@ -46,6 +46,11 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM wxBoxSizer* m_SingleLineSizer; wxStaticText* m_TextLabel; wxTextCtrl* m_SingleLineText; + wxFlexGridSizer* m_DimensionTextSizer; + wxStaticText* m_DimensionTextLabel; + wxTextCtrl* m_DimensionText; + wxStaticText* m_staticText18; + wxChoice* m_DimensionUnitsOpt; wxStaticText* m_LayerLabel; PCB_LAYER_BOX_SELECTOR* m_LayerSelectionCtrl; wxCheckBox* m_Visible; @@ -80,6 +85,8 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM // Virtual event handlers, overide them in your derived class virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnDimensionTextChange( wxCommandEvent& event ) { event.Skip(); } + virtual void OnDimensionUnitsChange( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 47cc6325cd..2c74a6d839 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -115,7 +115,7 @@ DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC ) aDimension->Text().SetThickness( boardSettings.GetTextThickness( GetActiveLayer() ) ); aDimension->Text().SetItalic( boardSettings.GetTextItalic( GetActiveLayer() ) ); aDimension->SetWidth( boardSettings.GetLineThickness( GetActiveLayer() ) ); - aDimension->AdjustDimensionDetails( GetUserUnits() ); + aDimension->AdjustDimensionDetails(); aDimension->Draw( m_canvas, aDC, GR_XOR ); m_canvas->SetMouseCapture( BuildDimension, AbortBuildDimension ); diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 9f9b7716f7..89803ceccb 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -756,6 +756,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) dimension->Text().SetTextSize( designSettings.GetTextSize( layer ) ); dimension->Text().SetThickness( designSettings.GetTextThickness( layer ) ); dimension->SetWidth( designSettings.GetLineThickness( layer ) ); + dimension->SetUnits( MILLIMETRES, false ); // check which axis the dimension runs in // because the "height" of the dimension is perpendicular to that axis @@ -766,7 +767,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) else dimension->SetHeight( kicad_y( d.y3 - d.y1 ) ); - dimension->AdjustDimensionDetails( MILLIMETRES ); + dimension->AdjustDimensionDetails(); } } diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 7254bc6682..6bfcf352b6 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1649,12 +1649,19 @@ DIMENSION* PCB_PARSER::parseDIMENSION() case T_gr_text: { TEXTE_PCB* text = parseTEXTE_PCB(); + // This copy (using the copy constructor) rebuild the text timestamp, // that is not what we want. dimension->Text() = *text; // reinitialises the text time stamp to the right value (the dimension time stamp) dimension->Text().SetTimeStamp( dimension->GetTimeStamp() ); dimension->SetPosition( text->GetTextPos() ); + + EDA_UNITS_T units = INCHES; + bool useMils = false; + FetchUnitsFromString( text->GetText(), units, useMils ); + dimension->SetUnits( units, useMils ); + delete text; break; } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 3cf5075651..ef13d6175e 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -581,7 +581,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) dimension->Text().SetThickness( boardSettings.GetTextThickness( layer ) ); dimension->Text().SetItalic( boardSettings.GetTextItalic( layer ) ); dimension->SetWidth( boardSettings.GetLineThickness( layer ) ); - dimension->AdjustDimensionDetails( m_frame->GetUserUnits() ); + dimension->SetUnits( m_frame->GetUserUnits(), false ); + dimension->AdjustDimensionDetails(); preview.Add( dimension ); frame()->SetMsgPanel( dimension );