diff --git a/common/base_units.cpp b/common/base_units.cpp index 78a3f274e3..c6fec919c4 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -121,6 +121,12 @@ double To_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils ) * 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() 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 int ValueFromTextCtrl( const wxTextCtrl& aTextCtr ) { diff --git a/include/base_units.h b/include/base_units.h index 6bd913c707..39897b9eac 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -180,11 +180,12 @@ int ValueFromTextCtrl( const wxTextCtrl& aTextCtr ); /** * 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: * the format string must contain the %s format specifier. * @return The formatted units symbol. */ +// TODO: remove default value for aUnits wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit, 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 * 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. */ 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 ); +// TODO: remove (units should either be in textControl or handled by UNIT_BINDER) void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit ); #endif // _BASE_UNITS_H_ diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index a7b1eb9c42..c848e5f191 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -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 int ii; @@ -216,6 +216,9 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) int hx, hy; // dimension line interval double angle, angle_f; + if( aUnits != UNSCALED_UNITS ) + m_Unit = aUnits; + // Init layer : m_Text.SetLayer( GetLayer() ); @@ -313,11 +316,8 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) m_Text.SetTextAngle( newAngle ); - if( !aDoNotChangeText ) - { - m_Value = measure; - SetText( MessageTextFromValue( g_UserUnit, m_Value ) ); - } + m_Value = measure; + SetText( MessageTextFromValue( m_Unit, m_Value ) ); } diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index 877633555c..c4aa354c11 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -173,9 +173,9 @@ public: /** * Function AdjustDimensionDetails * 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 ); const wxString GetText() const; diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 2178bf74ee..0059b29c5f 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -283,7 +283,7 @@ DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC ) aDimension->Text().SetThickness( width ); aDimension->SetWidth( width ); - aDimension->AdjustDimensionDetails(); + aDimension->AdjustDimensionDetails( GetUserUnits() ); aDimension->Draw( m_canvas, aDC, GR_XOR ); m_canvas->SetMouseCapture( BuildDimension, AbortBuildDimension ); @@ -335,7 +335,7 @@ static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC, { Dimension->m_featureLineDO = pos; Dimension->m_crossBarF = Dimension->m_featureLineDO; - Dimension->AdjustDimensionDetails( ); + Dimension->AdjustDimensionDetails(); } else { diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index 67f4392fdc..c4365f1e6e 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -772,7 +772,7 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics ) else dimension->SetHeight( kicad_y( d.y3 - d.y1 ) ); - dimension->AdjustDimensionDetails(); + dimension->AdjustDimensionDetails( MILLIMETRES ); } } diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index abd4a83bdd..47d2a378f9 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -139,7 +139,7 @@ BOARD_ITEM* FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay( int aHotKeyCode ) { item = (*m_Collector)[ii]; - wxString text = item->GetSelectMenuText( g_UserUnit ); + wxString text = item->GetSelectMenuText( GetUserUnits() ); BITMAP_DEF xpm = item->GetMenuImage(); AddMenuItem( &itemMenu, diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp index 6466b87430..cd088b79bb 100644 --- a/pcbnew/onrightclick.cpp +++ b/pcbnew/onrightclick.cpp @@ -49,7 +49,7 @@ #include -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 ) @@ -360,7 +360,7 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) 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" ), 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 ); 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" ), 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 - 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 ) ); // 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 * @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; - wxMenu* trackwidth_menu; - wxString value; + wxString msg; + wxMenu* trackwidth_menu; + BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); 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" ), true ); - if( aBoard->GetDesignSettings().m_UseConnectedTrackWidth ) + if( bds.m_UseConnectedTrackWidth ) trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, true ); - if( aBoard->GetDesignSettings().GetViaSizeIndex() != 0 - || aBoard->GetDesignSettings().GetTrackWidthIndex() != 0 - || aBoard->GetDesignSettings().m_UseConnectedTrackWidth ) + if( bds.GetViaSizeIndex() != 0 || bds.GetTrackWidthIndex() != 0 || bds.m_UseConnectedTrackWidth ) trackwidth_menu->Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use Netclass Values" ), _( "Use track and via sizes from their Netclass values" ), 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 ) ); if( ii == 0 ) @@ -1024,16 +1023,12 @@ static wxMenu* Append_Track_Width_List( BOARD* aBoard ) 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, - aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter, - true ); - wxString drill = StringFromValue( g_UserUnit, - aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill, - true ); + wxString value = StringFromValue( aUnits, bds.m_ViasDimensionsList[ii].m_Diameter, true ); + wxString drill = StringFromValue( aUnits, bds.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 ) ); } diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp index 8b59ac70c0..a64896ad06 100644 --- a/pcbnew/toolbars_update_user_interface.cpp +++ b/pcbnew/toolbars_update_user_interface.cpp @@ -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_INCH, false ); - if( g_UserUnit == INCHES ) + if( GetUserUnits() == INCHES ) { menuBar->FindItem( ID_TB_OPTIONS_SELECT_UNIT_INCH )->Check( true ); m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, true ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 115485adbb..d8cf74c3c2 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -584,7 +584,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) dimension->Text().SetThickness( width ); dimension->SetWidth( width ); - dimension->AdjustDimensionDetails(); + dimension->AdjustDimensionDetails( m_frame->GetUserUnits() ); preview.Add( dimension ); frame()->SetMsgPanel( dimension ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 3b0d5e64cf..0f9ea629e6 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -780,7 +780,7 @@ int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent ) // TODO should not it be refactored to pcb_frame member function? wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); - if( g_UserUnit == INCHES ) + if( m_frame->GetUserUnits() == INCHES ) evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM ); else evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );