Kill off a few more g_UserUnit references.

(cherry picked from commit 452b1a7)
This commit is contained in:
Jeff Young 2018-06-13 17:05:43 +01:00
parent cae249bbb8
commit 5ce0f8ba54
11 changed files with 53 additions and 39 deletions

View File

@ -121,6 +121,12 @@ double To_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils )
* could truncate the actual value * could truncate the actual value
*/ */
// JEY TODO: retire this in favour of MessageTextFromValue()....
wxString CoordinateToString( int aValue, bool aUseMils )
{
return MessageTextFromValue( g_UserUnit, aValue, aUseMils );
}
// A lower-precision (for readability) version of StringFromValue() // A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils ) wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils )
@ -384,6 +390,16 @@ int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue, bool aUseMi
} }
// JEY TODO: remove
int ValueFromString( const wxString& aTextValue )
{
int value;
value = ValueFromString( g_UserUnit, aTextValue);
return value;
}
// JEY TODO: remove; use a UNIT_BINDER instead // JEY TODO: remove; use a UNIT_BINDER instead
int ValueFromTextCtrl( const wxTextCtrl& aTextCtr ) int ValueFromTextCtrl( const wxTextCtrl& aTextCtr )
{ {

View File

@ -180,11 +180,12 @@ int ValueFromTextCtrl( const wxTextCtrl& aTextCtr );
/** /**
* Returns the units symbol. * Returns the units symbol.
* *
* @param aUnits - Units type, default is current units setting. * @param aUnits - Units requested.
* @param aFormatString - A formatting string to embed the units symbol into. Note: * @param aFormatString - A formatting string to embed the units symbol into. Note:
* the format string must contain the %s format specifier. * the format string must contain the %s format specifier.
* @return The formatted units symbol. * @return The formatted units symbol.
*/ */
// TODO: remove default value for aUnits
wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit, wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit,
const wxString& aFormatString = " (%s):" ); const wxString& aFormatString = " (%s):" );
@ -194,12 +195,14 @@ wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit,
* The strings returned are full text name and not abbreviations or symbolic * The strings returned are full text name and not abbreviations or symbolic
* representations of the units. Use ReturnUnitSymbol() for that. * representations of the units. Use ReturnUnitSymbol() for that.
* *
* @param aUnits - The units text to return. * @param aUnits - The units requested.
* @return The human readable units string. * @return The human readable units string.
*/ */
wxString GetUnitsLabel( EDA_UNITS_T aUnits, bool aUseMils = false ); wxString GetUnitsLabel( EDA_UNITS_T aUnits, bool aUseMils = false );
// TODO: remove default value for aUnits
wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit, bool aUseMils = false ); wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit, bool aUseMils = false );
// TODO: remove (units should either be in textControl or handled by UNIT_BINDER)
void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit ); void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit );
#endif // _BASE_UNITS_H_ #endif // _BASE_UNITS_H_

View File

@ -206,7 +206,7 @@ void DIMENSION::UpdateHeight()
} }
void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) void DIMENSION::AdjustDimensionDetails( EDA_UNITS_T aUnits )
{ {
const int arrowz = Mils2iu( 50 ); // size of arrows const int arrowz = Mils2iu( 50 ); // size of arrows
int ii; int ii;
@ -216,6 +216,9 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
int hx, hy; // dimension line interval int hx, hy; // dimension line interval
double angle, angle_f; double angle, angle_f;
if( aUnits != UNSCALED_UNITS )
m_Unit = aUnits;
// Init layer : // Init layer :
m_Text.SetLayer( GetLayer() ); m_Text.SetLayer( GetLayer() );
@ -313,11 +316,8 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
m_Text.SetTextAngle( newAngle ); m_Text.SetTextAngle( newAngle );
if( !aDoNotChangeText ) m_Value = measure;
{ SetText( MessageTextFromValue( m_Unit, m_Value ) );
m_Value = measure;
SetText( MessageTextFromValue( g_UserUnit, m_Value ) );
}
} }

View File

@ -173,9 +173,9 @@ public:
/** /**
* Function AdjustDimensionDetails * Function AdjustDimensionDetails
* Calculate coordinates of segments used to draw the dimension. * Calculate coordinates of segments used to draw the dimension.
* @param aDoNotChangeText (bool) if false, the dimension text is initialized * @param aUnits the units for the dimension text, or UNSCALED_UNITS to leave unchanged
*/ */
void AdjustDimensionDetails( bool aDoNotChangeText = false ); void AdjustDimensionDetails( EDA_UNITS_T aUnits = UNSCALED_UNITS );
void SetText( const wxString& NewText ); void SetText( const wxString& NewText );
const wxString GetText() const; const wxString GetText() const;

View File

@ -283,7 +283,7 @@ DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC )
aDimension->Text().SetThickness( width ); aDimension->Text().SetThickness( width );
aDimension->SetWidth( width ); aDimension->SetWidth( width );
aDimension->AdjustDimensionDetails(); aDimension->AdjustDimensionDetails( GetUserUnits() );
aDimension->Draw( m_canvas, aDC, GR_XOR ); aDimension->Draw( m_canvas, aDC, GR_XOR );
m_canvas->SetMouseCapture( BuildDimension, AbortBuildDimension ); m_canvas->SetMouseCapture( BuildDimension, AbortBuildDimension );
@ -335,7 +335,7 @@ static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
{ {
Dimension->m_featureLineDO = pos; Dimension->m_featureLineDO = pos;
Dimension->m_crossBarF = Dimension->m_featureLineDO; Dimension->m_crossBarF = Dimension->m_featureLineDO;
Dimension->AdjustDimensionDetails( ); Dimension->AdjustDimensionDetails();
} }
else else
{ {

View File

@ -772,7 +772,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
else else
dimension->SetHeight( kicad_y( d.y3 - d.y1 ) ); dimension->SetHeight( kicad_y( d.y3 - d.y1 ) );
dimension->AdjustDimensionDetails(); dimension->AdjustDimensionDetails( MILLIMETRES );
} }
} }

View File

@ -139,7 +139,7 @@ BOARD_ITEM* FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay( int aHotKeyCode )
{ {
item = (*m_Collector)[ii]; item = (*m_Collector)[ii];
wxString text = item->GetSelectMenuText( g_UserUnit ); wxString text = item->GetSelectMenuText( GetUserUnits() );
BITMAP_DEF xpm = item->GetMenuImage(); BITMAP_DEF xpm = item->GetMenuImage();
AddMenuItem( &itemMenu, AddMenuItem( &itemMenu,

View File

@ -49,7 +49,7 @@
#include <menus_helpers.h> #include <menus_helpers.h>
static wxMenu* Append_Track_Width_List( BOARD* aBoard ); static wxMenu* Append_Track_Width_List( BOARD* aBoard, EDA_UNITS_T aUnits );
bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu )
@ -360,7 +360,7 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu )
AddMenuItem( aPopMenu, ID_POPUP_PCB_BEGIN_TRACK, AddMenuItem( aPopMenu, ID_POPUP_PCB_BEGIN_TRACK,
msg, KiBitmap( add_tracks_xpm ) ); msg, KiBitmap( add_tracks_xpm ) );
AddMenuItem( aPopMenu, Append_Track_Width_List( GetBoard() ), AddMenuItem( aPopMenu, Append_Track_Width_List( GetBoard(), GetUserUnits() ),
ID_POPUP_PCB_SELECT_WIDTH, _( "Select Track Width" ), ID_POPUP_PCB_SELECT_WIDTH, _( "Select Track Width" ),
KiBitmap( width_track_xpm ) ); KiBitmap( width_track_xpm ) );
@ -410,7 +410,7 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu )
msg = AddHotkeyName( _( "Begin Track" ), g_Board_Editor_Hotkeys_Descr, HK_ADD_NEW_TRACK ); msg = AddHotkeyName( _( "Begin Track" ), g_Board_Editor_Hotkeys_Descr, HK_ADD_NEW_TRACK );
AddMenuItem( aPopMenu, ID_POPUP_PCB_BEGIN_TRACK, msg, KiBitmap( add_tracks_xpm ) ); AddMenuItem( aPopMenu, ID_POPUP_PCB_BEGIN_TRACK, msg, KiBitmap( add_tracks_xpm ) );
AddMenuItem( aPopMenu, Append_Track_Width_List( GetBoard() ), AddMenuItem( aPopMenu, Append_Track_Width_List( GetBoard(), GetUserUnits() ),
ID_POPUP_PCB_SELECT_WIDTH, _( "Select Track Width" ), ID_POPUP_PCB_SELECT_WIDTH, _( "Select Track Width" ),
KiBitmap( width_track_xpm ) ); KiBitmap( width_track_xpm ) );
@ -579,7 +579,8 @@ void PCB_EDIT_FRAME::createPopupMenuForTracks( TRACK* Track, wxMenu* PopMenu )
} }
// Allows switching to another track/via size when routing // Allows switching to another track/via size when routing
AddMenuItem( PopMenu, Append_Track_Width_List( GetBoard() ), ID_POPUP_PCB_SELECT_WIDTH, AddMenuItem( PopMenu, Append_Track_Width_List( GetBoard(), GetUserUnits() ),
ID_POPUP_PCB_SELECT_WIDTH,
_( "Select Track Width" ), KiBitmap( width_track_xpm ) ); _( "Select Track Width" ), KiBitmap( width_track_xpm ) );
// Delete control: // Delete control:
@ -988,11 +989,11 @@ void PCB_EDIT_FRAME::createPopUpMenuForMarkers( MARKER_PCB* aMarker, wxMenu* aPo
* creates a wxMenu * which shows the last used track widths and via diameters * creates a wxMenu * which shows the last used track widths and via diameters
* @return a pointer to the menu * @return a pointer to the menu
*/ */
static wxMenu* Append_Track_Width_List( BOARD* aBoard ) static wxMenu* Append_Track_Width_List( BOARD* aBoard, EDA_UNITS_T aUnits )
{ {
wxString msg; wxString msg;
wxMenu* trackwidth_menu; wxMenu* trackwidth_menu;
wxString value; BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
trackwidth_menu = new wxMenu; trackwidth_menu = new wxMenu;
@ -1000,20 +1001,18 @@ static wxMenu* Append_Track_Width_List( BOARD* aBoard )
_( "Use the track width when starting on a track, otherwise the current track width" ), _( "Use the track width when starting on a track, otherwise the current track width" ),
true ); true );
if( aBoard->GetDesignSettings().m_UseConnectedTrackWidth ) if( bds.m_UseConnectedTrackWidth )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, true ); trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, true );
if( aBoard->GetDesignSettings().GetViaSizeIndex() != 0 if( bds.GetViaSizeIndex() != 0 || bds.GetTrackWidthIndex() != 0 || bds.m_UseConnectedTrackWidth )
|| aBoard->GetDesignSettings().GetTrackWidthIndex() != 0
|| aBoard->GetDesignSettings().m_UseConnectedTrackWidth )
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, trackwidth_menu->Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES,
_( "Use Netclass Values" ), _( "Use Netclass Values" ),
_( "Use track and via sizes from their Netclass values" ), _( "Use track and via sizes from their Netclass values" ),
true ); true );
for( unsigned ii = 0; ii < aBoard->GetDesignSettings().m_TrackWidthList.size(); ii++ ) for( unsigned ii = 0; ii < bds.m_TrackWidthList.size(); ii++ )
{ {
value = StringFromValue( g_UserUnit, aBoard->GetDesignSettings().m_TrackWidthList[ii], true ); wxString value = StringFromValue( aUnits, bds.m_TrackWidthList[ii], true );
msg.Printf( _( "Track %s" ), GetChars( value ) ); msg.Printf( _( "Track %s" ), GetChars( value ) );
if( ii == 0 ) if( ii == 0 )
@ -1024,16 +1023,12 @@ static wxMenu* Append_Track_Width_List( BOARD* aBoard )
trackwidth_menu->AppendSeparator(); trackwidth_menu->AppendSeparator();
for( unsigned ii = 0; ii < aBoard->GetDesignSettings().m_ViasDimensionsList.size(); ii++ ) for( unsigned ii = 0; ii < bds.m_ViasDimensionsList.size(); ii++ )
{ {
value = StringFromValue( g_UserUnit, wxString value = StringFromValue( aUnits, bds.m_ViasDimensionsList[ii].m_Diameter, true );
aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter, wxString drill = StringFromValue( aUnits, bds.m_ViasDimensionsList[ii].m_Drill, true );
true );
wxString drill = StringFromValue( g_UserUnit,
aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill,
true );
if( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill <= 0 ) if( bds.m_ViasDimensionsList[ii].m_Drill <= 0 )
{ {
msg.Printf( _( "Via %s" ), GetChars( value ) ); msg.Printf( _( "Via %s" ), GetChars( value ) );
} }

View File

@ -247,7 +247,7 @@ void PCB_EDIT_FRAME::SyncMenusAndToolbars( wxEvent& aEvent )
m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_MM, false ); m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_MM, false );
m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, false ); m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, false );
if( g_UserUnit == INCHES ) if( GetUserUnits() == INCHES )
{ {
menuBar->FindItem( ID_TB_OPTIONS_SELECT_UNIT_INCH )->Check( true ); menuBar->FindItem( ID_TB_OPTIONS_SELECT_UNIT_INCH )->Check( true );
m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, true ); m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, true );

View File

@ -584,7 +584,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
dimension->Text().SetThickness( width ); dimension->Text().SetThickness( width );
dimension->SetWidth( width ); dimension->SetWidth( width );
dimension->AdjustDimensionDetails(); dimension->AdjustDimensionDetails( m_frame->GetUserUnits() );
preview.Add( dimension ); preview.Add( dimension );
frame()->SetMsgPanel( dimension ); frame()->SetMsgPanel( dimension );

View File

@ -780,7 +780,7 @@ int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent )
// TODO should not it be refactored to pcb_frame member function? // TODO should not it be refactored to pcb_frame member function?
wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
if( g_UserUnit == INCHES ) if( m_frame->GetUserUnits() == INCHES )
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM ); evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM );
else else
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH ); evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );