WIP: Implement new dimension properties

This commit is contained in:
Jon Evans 2020-09-10 22:38:30 -04:00
parent ae7877c6cb
commit f1b7903a7d
8 changed files with 173 additions and 67 deletions

View File

@ -38,6 +38,7 @@
DIMENSION::DIMENSION( BOARD_ITEM* aParent ) DIMENSION::DIMENSION( BOARD_ITEM* aParent )
: BOARD_ITEM( aParent, PCB_DIMENSION_T ), : BOARD_ITEM( aParent, PCB_DIMENSION_T ),
m_overrideValue( false ),
m_units( EDA_UNITS::INCHES ), m_units( EDA_UNITS::INCHES ),
m_useMils( false ), m_useMils( false ),
m_autoUnits( false ), m_autoUnits( false ),

View File

@ -111,10 +111,10 @@ public:
int GetMeasuredValue() const { return m_measuredValue; } int GetMeasuredValue() const { return m_measuredValue; }
wxString GetDisplayedValue() const /**
{ * @return the text that should be shown, including any prefix and suffix
return m_text.GetText(); */
} wxString GetDisplayedText() const;
wxString GetPrefix() const { return m_prefix; } wxString GetPrefix() const { return m_prefix; }
void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; } void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; }
@ -226,6 +226,7 @@ protected:
// Value format // Value format
bool m_overrideValue; ///< Manually specify the displayed measurement value bool m_overrideValue; ///< Manually specify the displayed measurement value
wxString m_overrideText; ///< The shown value if m_overrideValue is true
wxString m_prefix; ///< String prepended to the value wxString m_prefix; ///< String prepended to the value
wxString m_suffix; ///< String appended to the value wxString m_suffix; ///< String appended to the value
EDA_UNITS m_units; ///< 0 = inches, 1 = mm EDA_UNITS m_units; ///< 0 = inches, 1 = mm

View File

@ -75,6 +75,33 @@ DIALOG_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES( PCB_BASE_EDIT_FRAME* a
m_sdbSizerOK->SetDefault(); m_sdbSizerOK->SetDefault();
m_cbOverrideValue->Bind( wxEVT_CHECKBOX,
[&]( wxCommandEvent& evt )
{
m_txtValue->Enable( m_cbOverrideValue->GetValue() );
if( !m_cbOverrideValue->GetValue() )
m_txtValue->SetValue( getValueText() );
} );
auto updateEventHandler =
[&]( wxCommandEvent& evt )
{
if( !m_cbOverrideValue->GetValue() )
m_txtValue->ChangeValue( getValueText() );
updatePreviewText();
};
m_txtValue->Bind( wxEVT_TEXT, updateEventHandler );
m_txtPrefix->Bind( wxEVT_TEXT, updateEventHandler );
m_txtSuffix->Bind( wxEVT_TEXT, updateEventHandler );
m_cbUnits->Bind( wxEVT_CHOICE, updateEventHandler );
m_cbUnitsFormat->Bind( wxEVT_CHOICE, updateEventHandler );
m_cbPrecision->Bind( wxEVT_CHOICE, updateEventHandler );
m_cbSuppressZeroes->Bind( wxEVT_CHECKBOX, updateEventHandler );
FinishDialogSettings(); FinishDialogSettings();
} }
@ -86,13 +113,16 @@ DIALOG_DIMENSION_PROPERTIES::~DIALOG_DIMENSION_PROPERTIES()
bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow() bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow()
{ {
m_txtValue->SetValue( m_dimension->GetText() ); m_txtValue->Enable( m_dimension->GetOverrideValue() );
m_cbOverrideValue->SetValue( m_dimension->GetOverrideValue() );
EDA_UNITS units; EDA_UNITS units;
bool useMils; bool useMils;
m_dimension->GetUnits( units, useMils ); m_dimension->GetUnits( units, useMils );
m_cbUnits->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : useMils ? 1 : 0 ); m_cbUnits->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : useMils ? 1 : 0 );
m_cbUnitsFormat->SetSelection( static_cast<int>( m_dimension->GetUnitsFormat() ) );
m_cbPrecision->SetSelection( static_cast<int>( m_dimension->GetPrecision() ) );
m_txtPrefix->SetValue( m_dimension->GetPrefix() ); m_txtPrefix->SetValue( m_dimension->GetPrefix() );
m_txtSuffix->SetValue( m_dimension->GetSuffix() ); m_txtSuffix->SetValue( m_dimension->GetSuffix() );
@ -104,6 +134,8 @@ bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow()
m_cbLayer->SetSelection( 0 ); m_cbLayer->SetSelection( 0 );
} }
m_cbSuppressZeroes->SetValue( m_dimension->GetSuppressZeroes() );
TEXTE_PCB& text = m_dimension->Text(); TEXTE_PCB& text = m_dimension->Text();
m_textWidth.SetValue( text.GetTextSize().x ); m_textWidth.SetValue( text.GetTextSize().x );
@ -111,14 +143,19 @@ bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow()
m_textThickness.SetValue( text.GetTextThickness() ); m_textThickness.SetValue( text.GetTextThickness() );
m_textPosX.SetValue( text.GetTextPos().x ); m_textPosX.SetValue( text.GetTextPos().x );
m_textPosY.SetValue( text.GetTextPos().y ); m_textPosY.SetValue( text.GetTextPos().y );
m_orientValue = text.GetTextAngleDegrees();
m_cbKeepAligned->SetValue( m_dimension->GetKeepTextAligned() );
m_cbItalic->SetValue( text.IsItalic() ); m_cbItalic->SetValue( text.IsItalic() );
m_cbMirrored->SetValue( text.IsMirrored() );
EDA_TEXT_HJUSTIFY_T hJustify = text.GetHorizJustify(); EDA_TEXT_HJUSTIFY_T hJustify = text.GetHorizJustify();
m_cbJustification->SetSelection( (int) hJustify + 1 ); m_cbJustification->SetSelection( (int) hJustify + 1 );
m_orientValue = text.GetTextAngleDegrees();
m_cbMirrored->SetValue( text.IsMirrored() );
m_lineThickness.SetValue( m_dimension->GetLineThickness() ); m_lineThickness.SetValue( m_dimension->GetLineThickness() );
m_arrowLength.SetValue( m_dimension->GetArrowLength() );
// Do this last; it depends on the other settings
m_txtValue->SetValue( getValueText() );
return DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataToWindow(); return DIALOG_DIMENSION_PROPERTIES_BASE::TransferDataToWindow();
} }
@ -126,64 +163,122 @@ bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow()
bool DIALOG_DIMENSION_PROPERTIES::TransferDataFromWindow() bool DIALOG_DIMENSION_PROPERTIES::TransferDataFromWindow()
{ {
#if 0 m_dimension->SetOverrideValue( m_cbOverrideValue->GetValue() );
switch( m_DimensionUnitsOpt->GetSelection() )
{ if( m_cbOverrideValue->GetValue() )
case 0: m_dimension->SetText( m_txtValue->GetValue() );
dimension->SetUnits( EDA_UNITS::INCHES, false );
break; m_dimension->SetPrefix( m_txtPrefix->GetValue() );
case 1: m_dimension->SetSuffix( m_txtSuffix->GetValue() );
dimension->SetUnits( EDA_UNITS::INCHES, true ); m_dimension->SetLayer( static_cast<PCB_LAYER_ID>( m_cbLayer->GetLayerSelection() ) );
break;
case 2: m_dimension->SetUnitsMode( static_cast<DIM_UNITS_MODE>( m_cbUnits->GetSelection() ) );
dimension->SetUnits( EDA_UNITS::MILLIMETRES, false ); m_dimension->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
break; m_dimension->SetPrecision( m_cbPrecision->GetSelection() );
default: break; m_dimension->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );
}
#endif TEXTE_PCB& text = m_dimension->Text();
// TODO(JE) text positioning modes
wxPoint pos( m_textPosX.GetValue(), m_textPosY.GetValue() );
text.SetPosition( pos );
text.SetTextAngle( KiROUND( m_orientValue * 10.0 ) );
text.SetTextWidth( m_textWidth.GetValue() );
text.SetTextHeight( m_textHeight.GetValue() );
text.SetTextThickness( m_textThickness.GetValue() );
text.SetItalic( m_cbItalic->GetValue() );
text.SetMirrored( m_cbMirrored->GetValue() );
int justification = m_cbJustification->GetSelection() - 1;
text.SetHorizJustify( static_cast<EDA_TEXT_HJUSTIFY_T>( justification ) );
m_dimension->SetKeepTextAligned( m_cbKeepAligned->GetValue() );
m_dimension->SetLineThickness( m_lineThickness.GetValue() );
m_dimension->SetArrowLength( m_arrowLength.GetValue() );
return true; return true;
} }
#if 0
void DIALOG_TEXT_PROPERTIES::OnDimensionTextChange( wxCommandEvent& event ) void DIALOG_DIMENSION_PROPERTIES::getUnitsSelection( EDA_UNITS& aUnits, bool& aUseMils )
{ {
EDA_UNITS units = EDA_UNITS::UNSCALED; aUseMils = false;
bool useMils;
FetchUnitsFromString( m_DimensionText->GetValue(), units, useMils ); switch( m_cbUnits->GetSelection() )
{
case 0: // inches
aUnits = EDA_UNITS::INCHES;
break;
if( units != EDA_UNITS::UNSCALED ) case 1: // mils
m_DimensionUnitsOpt->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : useMils ? 1 : 0 ); aUnits = EDA_UNITS::INCHES;
aUseMils = true;
break;
case 2: // mm
aUnits = EDA_UNITS::MILLIMETRES;
break;
case 3: // auto
aUnits = m_frame->GetUserUnits();
break;
default:
break;
}
} }
void DIALOG_TEXT_PROPERTIES::OnDimensionUnitsChange( wxCommandEvent& event )
wxString DIALOG_DIMENSION_PROPERTIES::getValueText()
{ {
DIMENSION* dimension = (DIMENSION*) m_item; int val = m_dimension->GetMeasuredValue();
EDA_UNITS units; int precision = m_cbPrecision->GetSelection();
EDA_UNITS units;
bool useMils; bool useMils;
getUnitsSelection( units, useMils );
// Get default units in case dimension text doesn't contain units. wxString text;
dimension->GetUnits( units, useMils ); wxString format = wxT( "%." ) + wxString::Format( "%i", precision ) + wxT( "f" );
double value = ValueFromString( units, m_DimensionText->GetValue(), useMils ); text.Printf( format, To_User_Unit( units, val, useMils ) );
switch( event.GetSelection() ) if( m_cbSuppressZeroes->GetValue() )
{ {
case 0: while( text[text.Length() - 1] == '0' || text[text.Length() - 1] == '.' )
units = EDA_UNITS::INCHES; text.Remove( text.Length() - 1 );
useMils = false;
break;
case 1:
units = EDA_UNITS::INCHES;
useMils = true;
break;
case 2:
units = EDA_UNITS::MILLIMETRES;
useMils = false;
break;
default: break;
} }
m_DimensionText->SetValue( StringFromValue( units, value, true, useMils ) ); return text;
}
void DIALOG_DIMENSION_PROPERTIES::updatePreviewText()
{
wxString text = m_cbOverrideValue->GetValue() ? m_txtValue->GetValue() : getValueText();
EDA_UNITS units;
bool useMils;
getUnitsSelection( units, useMils );
switch( m_cbUnitsFormat->GetSelection() )
{
case 0: // no units
break;
case 1: // normal
text += " ";
text += GetAbbreviatedUnitsLabel( units, useMils );
break;
case 2: // parenthetical
text += " (";
text += GetAbbreviatedUnitsLabel( units, useMils );
text += ")";
break;
}
text.Prepend( m_txtPrefix->GetValue() );
text.Append( m_txtSuffix->GetValue() );
m_staticTextPreview->SetLabel( text );
} }
#endif

View File

@ -39,6 +39,11 @@ public:
~DIALOG_DIMENSION_PROPERTIES(); ~DIALOG_DIMENSION_PROPERTIES();
protected:
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private: private:
PCB_BASE_EDIT_FRAME* m_frame; PCB_BASE_EDIT_FRAME* m_frame;
@ -57,9 +62,11 @@ private:
UNIT_BINDER m_lineThickness; UNIT_BINDER m_lineThickness;
UNIT_BINDER m_arrowLength; UNIT_BINDER m_arrowLength;
bool TransferDataToWindow() override; void getUnitsSelection( EDA_UNITS& aUnits, bool& aUseMils );
bool TransferDataFromWindow() override; wxString getValueText();
void updatePreviewText();
}; };

View File

@ -341,7 +341,6 @@ DIALOG_DIMENSION_PROPERTIES_BASE::DIALOG_DIMENSION_PROPERTIES_BASE( wxWindow* pa
// Connect Events // Connect Events
this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnInitDlg ) ); this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnInitDlg ) );
m_txtValue->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionTextChange ), NULL, this );
m_cbUnits->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this ); m_cbUnits->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this );
m_txtTextWidth->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_txtTextWidth->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_txtTextPosX->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_txtTextPosX->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this );
@ -357,7 +356,6 @@ DIALOG_DIMENSION_PROPERTIES_BASE::~DIALOG_DIMENSION_PROPERTIES_BASE()
{ {
// Disconnect Events // Disconnect Events
this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnInitDlg ) ); this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnInitDlg ) );
m_txtValue->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionTextChange ), NULL, this );
m_cbUnits->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this ); m_cbUnits->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnDimensionUnitsChange ), NULL, this );
m_txtTextWidth->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_txtTextWidth->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_txtTextPosX->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this ); m_txtTextPosX->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_DIMENSION_PROPERTIES_BASE::OnOkClick ), NULL, this );

View File

@ -215,7 +215,6 @@
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnText">OnDimensionTextChange</event>
</object> </object>
</object> </object>
<object class="gbsizeritem" expanded="0"> <object class="gbsizeritem" expanded="0">

View File

@ -95,7 +95,6 @@ class DIALOG_DIMENSION_PROPERTIES_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); }
virtual void OnDimensionTextChange( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDimensionUnitsChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnDimensionUnitsChange( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); }

View File

@ -2361,23 +2361,26 @@ DIMENSION* PCB_PARSER::parseDIMENSION()
token = NextTok(); token = NextTok();
bool isLegacyDimension = false;
// Old format // Old format
if( token == T_width ) if( token == T_width )
{ {
isLegacyDimension = true;
dimension->SetLineThickness( parseBoardUnits( "dimension width value" ) ); dimension->SetLineThickness( parseBoardUnits( "dimension width value" ) );
NeedRIGHT(); NeedRIGHT();
} }
else if( token != T_type ) else if( token != T_type )
{ {
Expecting( T_type ); Expecting( T_type );
// This function only parses aligned dimensions for now
if( NextTok() != T_aligned )
Expecting( T_aligned );
NeedRIGHT();
} }
// This function only parses aligned dimensions for now
if( NextTok() != T_aligned )
Expecting( T_aligned );
NeedRIGHT();
for( token = NextTok(); token != T_RIGHT; token = NextTok() ) for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{ {
if( token != T_LEFT ) if( token != T_LEFT )
@ -2409,10 +2412,13 @@ DIMENSION* PCB_PARSER::parseDIMENSION()
// Fetch other dimension properties out of the text item // Fetch other dimension properties out of the text item
dimension->SetPosition( text->GetTextPos() ); dimension->SetPosition( text->GetTextPos() );
EDA_UNITS units = EDA_UNITS::INCHES; if( isLegacyDimension )
bool useMils = false; {
FetchUnitsFromString( text->GetText(), units, useMils ); EDA_UNITS units = EDA_UNITS::INCHES;
dimension->SetUnits( units, useMils ); bool useMils = false;
FetchUnitsFromString( text->GetText(), units, useMils );
dimension->SetUnits( units, useMils );
}
delete text; delete text;
break; break;