7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Nuke base_units from orbit

This commit is contained in:
Mark Roszko 2022-09-16 04:38:10 +00:00
parent 4ae2225b6d
commit b00178adb3
160 changed files with 1708 additions and 1468 deletions
3d-viewer/dialogs
common
cvpcb
eeschema
gerbview
include
pagelayout_editor
pcbnew
CMakeLists.txt
board_stackup_manager
dialogs
drc
footprint_editor_settings.cppfootprint_preview_panel.cppfp_text.cppfp_text_grid_table.cppfp_textbox.cpp
import_gfx
microwave
netinfo_item.cpp
netlist_reader
pad.cpppcb_base_frame.cpppcb_bitmap.cpppcb_dimension.cpppcb_expr_evaluator.cpppcb_target.cpppcb_text.cpppcb_textbox.cpppcb_track.cpppcbnew_settings.cpp
plugins
python/scripting
router
toolbars_pcb_editor.cpp
tools
widgets
zone.cppzone_settings.cpp
qa

View File

@ -49,12 +49,12 @@ void PANEL_3D_RAYTRACING_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg )
m_numSamples_Reflections->SetValue( aCfg->m_Render.raytrace_nrsamples_reflections );
m_numSamples_Refractions->SetValue( aCfg->m_Render.raytrace_nrsamples_refractions );
m_spreadFactor_Shadows->SetValue( StringFromValue( EDA_UNITS::PERCENT,
aCfg->m_Render.raytrace_spread_shadows * 100.0f ) );
m_spreadFactor_Reflections->SetValue( StringFromValue( EDA_UNITS::PERCENT,
aCfg->m_Render.raytrace_spread_reflections * 100.0f ) );
m_spreadFactor_Refractions->SetValue( StringFromValue( EDA_UNITS::PERCENT,
aCfg->m_Render.raytrace_spread_refractions * 100.0f ) );
m_spreadFactor_Shadows->SetValue( EDA_UNIT_UTILS::UI::StringFromValue(
pcbIUScale, EDA_UNITS::PERCENT, aCfg->m_Render.raytrace_spread_shadows * 100.0f ) );
m_spreadFactor_Reflections->SetValue( EDA_UNIT_UTILS::UI::StringFromValue(
pcbIUScale, EDA_UNITS::PERCENT, aCfg->m_Render.raytrace_spread_reflections * 100.0f ) );
m_spreadFactor_Refractions->SetValue( EDA_UNIT_UTILS::UI::StringFromValue(
pcbIUScale, EDA_UNITS::PERCENT, aCfg->m_Render.raytrace_spread_refractions * 100.0f ) );
m_recursiveLevel_Reflections->SetValue( aCfg->m_Render.raytrace_recursivelevel_reflections );
m_recursiveLevel_Refractions->SetValue( aCfg->m_Render.raytrace_recursivelevel_refractions );
@ -70,7 +70,8 @@ void PANEL_3D_RAYTRACING_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg )
auto transfer_value =
[]( wxTextCtrl* aCtrl, int aValue )
{
aCtrl->SetValue( StringFromValue( EDA_UNITS::UNSCALED, aValue ) );
aCtrl->SetValue(
EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, EDA_UNITS::UNSCALED, aValue ) );
};
transfer_color( aCfg->m_Render.raytrace_lightColorCamera, m_colourPickerCameraLight );
@ -136,11 +137,17 @@ bool PANEL_3D_RAYTRACING_OPTIONS::TransferDataFromWindow()
cfg->m_Render.raytrace_nrsamples_refractions = m_numSamples_Refractions->GetValue();
cfg->m_Render.raytrace_spread_shadows =
DoubleValueFromString( EDA_UNITS::PERCENT, m_spreadFactor_Shadows->GetValue() ) / 100.0f;
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::PERCENT,
m_spreadFactor_Shadows->GetValue() )
/ 100.0f;
cfg->m_Render.raytrace_spread_reflections =
DoubleValueFromString( EDA_UNITS::PERCENT, m_spreadFactor_Reflections->GetValue() ) / 100.0f;
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::PERCENT,
m_spreadFactor_Reflections->GetValue() )
/ 100.0f;
cfg->m_Render.raytrace_spread_refractions =
DoubleValueFromString( EDA_UNITS::PERCENT, m_spreadFactor_Refractions->GetValue() ) / 100.0f;
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::PERCENT,
m_spreadFactor_Refractions->GetValue() )
/ 100.0f;
cfg->m_Render.raytrace_recursivelevel_reflections = m_recursiveLevel_Reflections->GetValue();
cfg->m_Render.raytrace_recursivelevel_refractions = m_recursiveLevel_Refractions->GetValue();
@ -161,7 +168,8 @@ bool PANEL_3D_RAYTRACING_OPTIONS::TransferDataFromWindow()
auto get_value =
[]( wxTextCtrl* aCtrl )
{
return DoubleValueFromString( EDA_UNITS::UNSCALED, aCtrl->GetValue() );
return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED,
aCtrl->GetValue() );
};
cfg->m_Render.raytrace_lightElevation[0] = get_value( m_lightElevation1 );

View File

@ -222,7 +222,8 @@ void PANEL_PREVIEW_3D_MODEL::loadSettings()
*/
static double rotationFromString( const wxString& aValue )
{
double rotation = DoubleValueFromString( EDA_UNITS::DEGREES, aValue );
double rotation =
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::DEGREES, aValue );
if( rotation > MAX_ROTATION )
{
@ -319,17 +320,26 @@ void PANEL_PREVIEW_3D_MODEL::updateOrientation( wxCommandEvent &event )
// Write settings back to the parent
FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
modelInfo->m_Scale.x = DoubleValueFromString( EDA_UNITS::UNSCALED, xscale->GetValue() );
modelInfo->m_Scale.y = DoubleValueFromString( EDA_UNITS::UNSCALED, yscale->GetValue() );
modelInfo->m_Scale.z = DoubleValueFromString( EDA_UNITS::UNSCALED, zscale->GetValue() );
modelInfo->m_Scale.x = EDA_UNIT_UTILS::UI::DoubleValueFromString(
pcbIUScale, EDA_UNITS::UNSCALED, xscale->GetValue() );
modelInfo->m_Scale.y = EDA_UNIT_UTILS::UI::DoubleValueFromString(
pcbIUScale, EDA_UNITS::UNSCALED, yscale->GetValue() );
modelInfo->m_Scale.z = EDA_UNIT_UTILS::UI::DoubleValueFromString(
pcbIUScale, EDA_UNITS::UNSCALED, zscale->GetValue() );
modelInfo->m_Rotation.x = rotationFromString( xrot->GetValue() );
modelInfo->m_Rotation.y = rotationFromString( yrot->GetValue() );
modelInfo->m_Rotation.z = rotationFromString( zrot->GetValue() );
modelInfo->m_Offset.x = DoubleValueFromString( m_userUnits, xoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.y = DoubleValueFromString( m_userUnits, yoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.z = DoubleValueFromString( m_userUnits, zoff->GetValue() ) / IU_PER_MM;
modelInfo->m_Offset.x = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
xoff->GetValue() )
/ pcbIUScale.IU_PER_MM;
modelInfo->m_Offset.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
yoff->GetValue() )
/ pcbIUScale.IU_PER_MM;
modelInfo->m_Offset.z = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
zoff->GetValue() )
/ pcbIUScale.IU_PER_MM;
// Update the dummy footprint for the preview
UpdateDummyFootprint( false );
@ -363,7 +373,7 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign
else if( spinCtrl == m_spinZscale )
textCtrl = zscale;
double curr_value = DoubleValueFromString( EDA_UNITS::UNSCALED, textCtrl->GetValue() );
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
curr_value += ( SCALE_INCREMENT * aSign );
curr_value = std::max( 1/MAX_SCALE, curr_value );
@ -383,7 +393,8 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aS
else if( spinCtrl == m_spinZrot )
textCtrl = zrot;
double curr_value = DoubleValueFromString( EDA_UNITS::DEGREES, textCtrl->GetValue() );
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::DEGREES,
textCtrl->GetValue() );
curr_value += ( ROTATION_INCREMENT * aSign );
curr_value = std::max( -MAX_ROTATION, curr_value );
@ -405,7 +416,9 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign
textCtrl = zoff;
double step_mm = OFFSET_INCREMENT_MM;
double curr_value_mm = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM;
double curr_value_mm =
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
/ pcbIUScale.IU_PER_MM;
if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES )
{
@ -432,7 +445,8 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelScale( wxMouseEvent& event )
if( event.GetWheelRotation() >= 0 )
step = -step;
double curr_value = DoubleValueFromString( EDA_UNITS::UNSCALED, textCtrl->GetValue() );
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED,
textCtrl->GetValue() );
curr_value += step;
curr_value = std::max( 1/MAX_SCALE, curr_value );
@ -454,7 +468,8 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelRot( wxMouseEvent& event )
if( event.GetWheelRotation() >= 0 )
step = -step;
double curr_value = DoubleValueFromString( EDA_UNITS::DEGREES, textCtrl->GetValue() );
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::DEGREES,
textCtrl->GetValue() );
curr_value += step;
curr_value = std::max( -MAX_ROTATION, curr_value );
@ -484,7 +499,9 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelOffset( wxMouseEvent& event )
if( event.GetWheelRotation() >= 0 )
step_mm = -step_mm;
double curr_value_mm = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM;
double curr_value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
textCtrl->GetValue() )
/ pcbIUScale.IU_PER_MM;
curr_value_mm += step_mm;
curr_value_mm = std::max( -MAX_OFFSET, curr_value_mm );

View File

@ -1,400 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 CERN
* Copyright (C) 1992-2021 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 2
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @author Wayne Stambaugh <stambaughw@gmail.com>
* @file base_units.cpp
* @brief Code to handle objects that require both schematic and board internal units.
* @note This file is an ugly hack to solve the problem of formatting the base units
* for either schematics or boards in objects that are include in both domains.
* At some point in the future. This code should be rolled back into the
* appropriate object and build with the correct internal unit formatting
* depending on the application.
*/
#include <base_units.h>
#include <string_utils.h>
#include <math/util.h> // for KiROUND
#include <macros.h>
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
#define IU_TO_MM( x ) ( x / IU_PER_MM )
#define IU_TO_IN( x ) ( x / IU_PER_MILS / 1000 )
#define IU_TO_MILS( x ) ( x / IU_PER_MILS )
#define MM_TO_IU( x ) ( x * IU_PER_MM )
#define IN_TO_IU( x ) ( x * IU_PER_MILS * 1000 )
#define MILS_TO_IU( x ) ( x * IU_PER_MILS )
#else
#error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW."
#endif
double To_User_Unit( EDA_UNITS aUnit, double aValue )
{
switch( aUnit )
{
case EDA_UNITS::MILLIMETRES:
return IU_TO_MM( aValue );
case EDA_UNITS::MILS:
return IU_TO_MILS( aValue );
case EDA_UNITS::INCHES:
return IU_TO_IN( aValue );
case EDA_UNITS::DEGREES:
return aValue;
default:
return aValue;
}
}
/**
* Convert a value to a string using double notation.
*
* For readability, the mantissa has 0, 1, 3 or 4 digits, depending on units
* for unit = inch the mantissa has 3 digits (Eeschema) or 4 digits
* for unit = mil the mantissa has 0 digits (Eeschema) or 1 digits
* for unit = mm the mantissa has 3 digits (Eeschema) or 4 digits
* Should be used only to display info in status,
* but not in dialogs, because 4 digits only
* could truncate the actual value
*/
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aUnits, double( aValue ), aAddUnitLabel, aType );
}
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aUnits, double( aValue ), aAddUnitLabel, aType );
}
wxString MessageTextFromValue( EDA_ANGLE aValue, bool aAddUnitLabel )
{
if( aAddUnitLabel )
return wxString::Format( wxT( "%.1f°" ), aValue.AsDegrees() );
else
return wxString::Format( wxT( "%.1f" ), aValue.AsDegrees() );
}
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
wxString text;
const wxChar* format;
double value = aValue;
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
value = To_User_Unit( aUnits, value );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
value = To_User_Unit( aUnits, value );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
value = To_User_Unit( aUnits, value );
}
switch( aUnits )
{
default:
case EDA_UNITS::MILLIMETRES:
#if defined( EESCHEMA )
format = wxT( "%.2f" );
#else
format = wxT( "%.4f" );
#endif
break;
case EDA_UNITS::MILS:
#if defined( EESCHEMA )
format = wxT( "%.0f" );
#else
format = wxT( "%.2f" );
#endif
break;
case EDA_UNITS::INCHES:
#if defined( EESCHEMA )
format = wxT( "%.3f" );
#else
format = wxT( "%.4f" );
#endif
break;
case EDA_UNITS::DEGREES:
// 3 digits in mantissa should be good for rotation in degree
format = wxT( "%.3f" );
break;
case EDA_UNITS::UNSCALED:
format = wxT( "%.0f" );
break;
}
text.Printf( format, value );
if( aAddUnitLabel )
text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return text;
}
/**
* Convert a value to a string using double notation.
*
* For readability, the mantissa has 3 or more digits,
* the trailing 0 are removed if the mantissa has more than 3 digits
* and some trailing 0
* This function should be used to display values in dialogs because a value
* entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa
* if displayed in inch to avoid truncation or rounding made just by the printf function.
* otherwise the actual value is rounded when read from dialog and converted
* in internal units, and therefore modified.
*/
wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol,
EDA_DATA_TYPE aType )
{
double value_to_print = aValue;
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
value_to_print = To_User_Unit( aUnits, value_to_print );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
value_to_print = To_User_Unit( aUnits, value_to_print );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
value_to_print = To_User_Unit( aUnits, value_to_print );
}
char buf[50];
if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
{
int len = snprintf( buf, sizeof( buf ) - 1, "%.10f", value_to_print );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( len >= 0 && ( buf[len]=='.' || buf[len]==',' ) )
buf[len] = '\0';
}
else
{
snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print );
}
wxString stringValue( buf, wxConvUTF8 );
if( aAddUnitSymbol )
stringValue += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return stringValue;
}
double From_User_Unit( EDA_UNITS aUnits, double aValue )
{
switch( aUnits )
{
case EDA_UNITS::MILLIMETRES:
return MM_TO_IU( aValue );
case EDA_UNITS::MILS:
return MILS_TO_IU( aValue );
case EDA_UNITS::INCHES:
return IN_TO_IU( aValue );
default:
case EDA_UNITS::DEGREES:
case EDA_UNITS::UNSCALED:
case EDA_UNITS::PERCENT:
return aValue;
}
}
double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_DATA_TYPE aType )
{
double dtmp = 0;
// 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 any entered decimal point separators to the 'right' one
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
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;
}
// Extract the numeric part
buf.Left( brk_point ).ToDouble( &dtmp );
// Check the optional unit designator (2 ch significant)
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( aUnits == EDA_UNITS::MILLIMETRES || aUnits == EDA_UNITS::MILS
|| aUnits == EDA_UNITS::INCHES )
{
if( unit == wxT( "mm" ) )
{
aUnits = EDA_UNITS::MILLIMETRES;
}
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) )
{
aUnits = EDA_UNITS::MILS;
}
else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
{
aUnits = EDA_UNITS::INCHES;
}
else if( unit == "oz" ) // 1 oz = 1.37 mils
{
aUnits = EDA_UNITS::MILS;
dtmp *= 1.37;
}
}
else if( aUnits == EDA_UNITS::DEGREES )
{
if( unit == wxT( "ra" ) ) // Radians
dtmp *= 180.0f / M_PI;
}
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
dtmp = From_User_Unit( aUnits, dtmp );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
dtmp = From_User_Unit( aUnits, dtmp );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
dtmp = From_User_Unit( aUnits, dtmp );
}
return dtmp;
}
long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_DATA_TYPE aType )
{
double value = DoubleValueFromString( aUnits, aTextValue, aType );
return KiROUND<double, long long int>( value );
}
std::string FormatInternalUnits( int aValue )
{
char buf[50];
double engUnits = aValue;
int len;
engUnits /= IU_PER_MM;
if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
{
len = snprintf( buf, sizeof(buf), "%.10f", engUnits );
// Make sure snprintf() didn't fail and the locale numeric separator is correct.
wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr, std::string( "" ) );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( buf[len] == '.' )
buf[len] = '\0';
else
++len;
}
else
{
len = snprintf( buf, sizeof(buf), "%.10g", engUnits );
// Make sure snprintf() didn't fail and the locale numeric separator is correct.
wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr , std::string( "" ) );
}
return std::string( buf, len );
}
std::string FormatInternalUnits( const wxPoint& aPoint )
{
return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
}
std::string FormatInternalUnits( const VECTOR2I& aPoint )
{
return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
}
std::string FormatInternalUnits( const wxSize& aSize )
{
return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
}

View File

@ -118,8 +118,10 @@ bool DIALOG_GRID_SETTINGS::TransferDataFromWindow()
gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
m_parent->SetGridOrigin( wxPoint( m_gridOriginX.GetValue(), m_gridOriginY.GetValue() ) );
gridCfg.user_grid_x = StringFromValue( GetUserUnits(), m_userGridX.GetValue(), true );
gridCfg.user_grid_y = StringFromValue( GetUserUnits(), m_userGridY.GetValue(), true );
gridCfg.user_grid_x = EDA_UNIT_UTILS::UI::StringFromValue( m_parent->GetIuScale(), GetUserUnits(),
m_userGridX.GetValue(), true );
gridCfg.user_grid_y = EDA_UNIT_UTILS::UI::StringFromValue( m_parent->GetIuScale(), GetUserUnits(),
m_userGridY.GetValue(), true );
gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
@ -148,8 +150,10 @@ bool DIALOG_GRID_SETTINGS::TransferDataToWindow()
m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx );
m_userGridX.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_x ) );
m_userGridY.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_y ) );
m_userGridX.SetValue( EDA_UNIT_UTILS::UI::ValueFromString( m_parent->GetIuScale(),
GetUserUnits(), gridCfg.user_grid_x ) );
m_userGridY.SetValue( EDA_UNIT_UTILS::UI::ValueFromString( m_parent->GetIuScale(),
GetUserUnits(), gridCfg.user_grid_y ) );
m_gridOriginX.SetValue( m_parent->GetGridOrigin().x );
m_gridOriginY.SetValue( m_parent->GetGridOrigin().y );

View File

@ -235,10 +235,11 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
int row = 0;
auto setCell =
[&]( int aRow, int aCol, int aValue )
{
m_netclassGrid->SetCellValue( aRow, aCol, StringFromValue( units, aValue, true ) );
};
[&]( int aRow, int aCol, int aValue )
{
m_netclassGrid->SetCellValue( aRow, aCol,
EDA_UNIT_UTILS::UI::StringFromValue( m_frame->GetIuScale(), units, aValue, true ) );
};
auto netclassToGridRow =
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
@ -341,7 +342,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
auto getCell =
[this, units]( int aRow, int aCol ) -> long long int
{
return ValueFromString( units, m_netclassGrid->GetCellValue( aRow, aCol ) );
return EDA_UNIT_UTILS::UI::ValueFromString( m_frame->GetIuScale(),units, m_netclassGrid->GetCellValue( aRow, aCol ) );
};
auto getCellStr =

View File

@ -139,15 +139,19 @@ void DS_DRAW_ITEM_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
aList.emplace_back( _( "First Page Option" ), msg );
msg = MessageTextFromValue( EDA_UNITS::UNSCALED, dataItem->m_RepeatCount );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), EDA_UNITS::UNSCALED,
dataItem->m_RepeatCount );
aList.emplace_back( _( "Repeat Count" ), msg );
msg = MessageTextFromValue( EDA_UNITS::UNSCALED, dataItem->m_IncrementLabel );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), EDA_UNITS::UNSCALED,
dataItem->m_IncrementLabel );
aList.emplace_back( _( "Repeat Label Increment" ), msg );
msg.Printf( wxT( "(%s, %s)" ),
MessageTextFromValue( aFrame->GetUserUnits(), dataItem->m_IncrementVector.x ),
MessageTextFromValue( aFrame->GetUserUnits(), dataItem->m_IncrementVector.y ) );
EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), aFrame->GetUserUnits(),
dataItem->m_IncrementVector.x ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), aFrame->GetUserUnits(),
dataItem->m_IncrementVector.y ) );
aList.emplace_back( _( "Repeat Position Increment" ), msg );
@ -380,8 +384,10 @@ bool DS_DRAW_ITEM_RECT::HitTest( const BOX2I& aRect, bool aContained, int aAccur
wxString DS_DRAW_ITEM_RECT::GetSelectMenuText( EDA_UNITS aUnits ) const
{
return wxString::Format( _( "Rectangle, width %s height %s" ),
MessageTextFromValue( aUnits, std::abs( GetStart().x - GetEnd().x ) ),
MessageTextFromValue( aUnits, std::abs( GetStart().y - GetEnd().y ) ) );
EDA_UNIT_UTILS::UI::MessageTextFromValue( drawSheetIUScale, aUnits,
std::abs( GetStart().x - GetEnd().x ) ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( drawSheetIUScale, aUnits,
std::abs( GetStart().y - GetEnd().y ) ) );
}
@ -413,7 +419,7 @@ bool DS_DRAW_ITEM_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) cons
wxString DS_DRAW_ITEM_LINE::GetSelectMenuText( EDA_UNITS aUnits ) const
{
return wxString::Format( _( "Line, length %s" ),
MessageTextFromValue( aUnits, EuclideanNorm( GetStart() - GetEnd() ) ) );
EDA_UNIT_UTILS::UI::MessageTextFromValue( drawSheetIUScale, aUnits, EuclideanNorm( GetStart() - GetEnd() ) ) );
}

View File

@ -81,8 +81,9 @@ END_EVENT_TABLE()
EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
long aStyle, const wxString & aFrameName ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
m_iuScale( aIuScale )
{
m_socketServer = nullptr;
m_mainToolBar = nullptr;
@ -577,9 +578,10 @@ void EDA_DRAW_FRAME::DisplayGridMsg()
{
wxString line;
line.Printf( "grid %s",
MessageTextFromValue( GetUserUnits(), GetCanvas()->GetGAL()->GetGridSize().x,
false ) );
line.Printf( "grid %s", EDA_UNIT_UTILS::UI::MessageTextFromValue(
GetIuScale(), GetUserUnits(),
GetCanvas()->GetGAL()->GetGridSize().x,
false ) );
SetStatusText( line, 4 );
}

View File

@ -574,24 +574,24 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
case SHAPE_T::CIRCLE:
aList.emplace_back( shape, _( "Circle" ) );
msg = MessageTextFromValue( units, GetRadius() );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units, GetRadius() );
aList.emplace_back( _( "Radius" ), msg );
break;
case SHAPE_T::ARC:
aList.emplace_back( shape, _( "Arc" ) );
msg = MessageTextFromValue( GetArcAngle() );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( GetArcAngle() );
aList.emplace_back( _( "Angle" ), msg );
msg = MessageTextFromValue( units, GetRadius() );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units, GetRadius() );
aList.emplace_back( _( "Radius" ), msg );
break;
case SHAPE_T::BEZIER:
aList.emplace_back( shape, _( "Curve" ) );
msg = MessageTextFromValue( units, GetLength() );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units, GetLength() );
aList.emplace_back( _( "Length" ), msg );
break;
@ -608,10 +608,12 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
else
aList.emplace_back( shape, _( "Rectangle" ) );
msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units,
std::abs( GetEnd().x - GetStart().x ) );
aList.emplace_back( _( "Width" ), msg );
msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units,
std::abs( GetEnd().y - GetStart().y ) );
aList.emplace_back( _( "Height" ), msg );
break;
@ -619,13 +621,14 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
{
aList.emplace_back( shape, _( "Segment" ) );
msg = MessageTextFromValue( units, GetLineLength( GetStart(), GetEnd() ) );
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( aFrame->GetIuScale(), units,
GetLineLength( GetStart(), GetEnd() ) );
aList.emplace_back( _( "Length" ), msg );
// angle counter-clockwise from 3'o-clock
EDA_ANGLE angle( atan2( (double)( GetStart().y - GetEnd().y ),
(double)( GetEnd().x - GetStart().x ) ), RADIANS_T );
aList.emplace_back( _( "Angle" ), MessageTextFromValue( angle ) );
aList.emplace_back( _( "Angle" ), EDA_UNIT_UTILS::UI::MessageTextFromValue( angle ) );
break;
}
@ -634,7 +637,7 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
break;
}
m_stroke.GetMsgPanelInfo( units, aList );
m_stroke.GetMsgPanelInfo( aFrame->GetIuScale(), units, aList );
}

View File

@ -87,18 +87,21 @@ GR_TEXT_V_ALIGN_T EDA_TEXT::MapVertJustify( int aVertJustify )
}
EDA_TEXT::EDA_TEXT( int aDefaultSizeIu, const wxString& aText ) :
EDA_TEXT::EDA_TEXT( const EDA_IU_SCALE& aIuScale, const wxString& aText ) :
m_text( aText ),
m_IuScale( aIuScale ),
m_bounding_box_cache_valid( false ),
m_bounding_box_cache_line( -1 ),
m_bounding_box_cache_inverted( false )
{
SetTextSize( VECTOR2I( aDefaultSizeIu, aDefaultSizeIu ) );
SetTextSize( VECTOR2I( EDA_UNIT_UTILS::Mils2IU( m_IuScale, DEFAULT_SIZE_TEXT ),
EDA_UNIT_UTILS::Mils2IU( m_IuScale, DEFAULT_SIZE_TEXT ) ) );
cacheShownText();
}
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText )
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) :
m_IuScale( aText.m_IuScale )
{
m_text = aText.m_text;
m_shown_text = aText.m_shown_text;
@ -780,8 +783,8 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
// Text size
aFormatter->Print( 0, " (size %s %s)",
FormatInternalUnits( GetTextHeight() ).c_str(),
FormatInternalUnits( GetTextWidth() ).c_str() );
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextHeight() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextWidth() ).c_str() );
if( GetLineSpacing() != 1.0 )
{
@ -792,7 +795,7 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
if( GetTextThickness() )
{
aFormatter->Print( 0, " (thickness %s)",
FormatInternalUnits( GetTextThickness() ).c_str() );
EDA_UNIT_UTILS::FormatInternalUnits( m_IuScale, GetTextThickness() ).c_str() );
}
if( IsBold() )

View File

@ -23,6 +23,7 @@
#include <eda_units.h>
#include <math/util.h> // for KiROUND
#include <convert_to_biu.h>
#include <macros.h>
bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit )
@ -133,4 +134,417 @@ std::string EDA_UNIT_UTILS::FormatAngle( const EDA_ANGLE& aAngle )
len = snprintf( temp, sizeof( temp ), "%.10g", aAngle.AsDegrees() );
return std::string( temp, len );
}
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale, int aValue )
{
char buf[50];
double engUnits = aValue;
int len;
engUnits /= aIuScale.IU_PER_MM;
if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
{
len = snprintf( buf, sizeof( buf ), "%.10f", engUnits );
// Make sure snprintf() didn't fail and the locale numeric separator is correct.
wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr, std::string( "" ) );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( buf[len] == '.' )
buf[len] = '\0';
else
++len;
}
else
{
len = snprintf( buf, sizeof( buf ), "%.10g", engUnits );
// Make sure snprintf() didn't fail and the locale numeric separator is correct.
wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr, std::string( "" ) );
}
return std::string( buf, len );
}
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale,
const wxPoint& aPoint )
{
return FormatInternalUnits( aIuScale, aPoint.x ) + " "
+ FormatInternalUnits( aIuScale, aPoint.y );
}
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale,
const VECTOR2I& aPoint )
{
return FormatInternalUnits( aIuScale, aPoint.x ) + " "
+ FormatInternalUnits( aIuScale, aPoint.y );
}
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale, const wxSize& aSize )
{
return FormatInternalUnits( aIuScale, aSize.GetWidth() ) + " "
+ FormatInternalUnits( aIuScale, aSize.GetHeight() );
}
#define IU_TO_MM( x, scale ) ( x / scale.IU_PER_MM )
#define IU_TO_IN( x, scale ) ( x / scale.IU_PER_MILS / 1000 )
#define IU_TO_MILS( x, scale ) ( x / scale.IU_PER_MILS )
#define MM_TO_IU( x, scale ) ( x * scale.IU_PER_MM )
#define IN_TO_IU( x, scale ) ( x * scale.IU_PER_MILS * 1000 )
#define MILS_TO_IU( x, scale ) ( x * scale.IU_PER_MILS )
double EDA_UNIT_UTILS::UI::ToUserUnit( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnit,
double aValue )
{
switch( aUnit )
{
case EDA_UNITS::MILLIMETRES:
return IU_TO_MM( aValue, aIuScale );
case EDA_UNITS::MILS:
return IU_TO_MILS( aValue, aIuScale );
case EDA_UNITS::INCHES:
return IU_TO_IN( aValue, aIuScale );
case EDA_UNITS::DEGREES:
return aValue;
default:
return aValue;
}
}
/**
* Convert a value to a string using double notation.
*
* For readability, the mantissa has 3 or more digits,
* the trailing 0 are removed if the mantissa has more than 3 digits
* and some trailing 0
* This function should be used to display values in dialogs because a value
* entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa
* if displayed in inch to avoid truncation or rounding made just by the printf function.
* otherwise the actual value is rounded when read from dialog and converted
* in internal units, and therefore modified.
*/
wxString EDA_UNIT_UTILS::UI::StringFromValue( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
double aValue, bool aAddUnitSymbol,
EDA_DATA_TYPE aType )
{
double value_to_print = aValue;
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
}
char buf[50];
if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
{
int len = snprintf( buf, sizeof( buf ) - 1, "%.10f", value_to_print );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( len >= 0 && ( buf[len] == '.' || buf[len] == ',' ) )
buf[len] = '\0';
}
else
{
snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print );
}
wxString stringValue( buf, wxConvUTF8 );
if( aAddUnitSymbol )
stringValue += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return stringValue;
}
/**
* Convert a value to a string using double notation.
*
* For readability, the mantissa has 0, 1, 3 or 4 digits, depending on units
* for unit = inch the mantissa has 3 digits (Eeschema) or 4 digits
* for unit = mil the mantissa has 0 digits (Eeschema) or 1 digits
* for unit = mm the mantissa has 3 digits (Eeschema) or 4 digits
* Should be used only to display info in status,
* but not in dialogs, because 4 digits only
* could truncate the actual value
*/
// A lower-precision (for readability) version of StringFromValue()
wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
int aValue,
bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aIuScale, aUnits, double( aValue ), aAddUnitLabel, aType );
}
// A lower-precision (for readability) version of StringFromValue()
wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
long long int aValue,
bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aIuScale, aUnits, double( aValue ), aAddUnitLabel, aType );
}
wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( EDA_ANGLE aValue, bool aAddUnitLabel )
{
if( aAddUnitLabel )
return wxString::Format( wxT( "%.1f°" ), aValue.AsDegrees() );
else
return wxString::Format( wxT( "%.1f" ), aValue.AsDegrees() );
}
// A lower-precision (for readability) version of StringFromValue()
wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
double aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
wxString text;
const wxChar* format;
double value = aValue;
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
value = ToUserUnit( aIuScale, aUnits, value );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
value = ToUserUnit( aIuScale, aUnits, value );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
value = ToUserUnit( aIuScale, aUnits, value );
}
switch( aUnits )
{
default:
case EDA_UNITS::MILLIMETRES:
#if defined( EESCHEMA )
format = wxT( "%.2f" );
#else
format = wxT( "%.4f" );
#endif
break;
case EDA_UNITS::MILS:
#if defined( EESCHEMA )
format = wxT( "%.0f" );
#else
format = wxT( "%.2f" );
#endif
break;
case EDA_UNITS::INCHES:
#if defined( EESCHEMA )
format = wxT( "%.3f" );
#else
format = wxT( "%.4f" );
#endif
break;
case EDA_UNITS::DEGREES:
// 3 digits in mantissa should be good for rotation in degree
format = wxT( "%.3f" );
break;
case EDA_UNITS::UNSCALED:
format = wxT( "%.0f" );
break;
}
text.Printf( format, value );
if( aAddUnitLabel )
text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return text;
}
double EDA_UNIT_UTILS::UI::FromUserUnit( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
double aValue )
{
switch( aUnits )
{
case EDA_UNITS::MILLIMETRES:
return MM_TO_IU( aValue, aIuScale );
case EDA_UNITS::MILS:
return MILS_TO_IU( aValue, aIuScale );
case EDA_UNITS::INCHES:
return IN_TO_IU( aValue, aIuScale );
default:
case EDA_UNITS::DEGREES:
case EDA_UNITS::UNSCALED:
case EDA_UNITS::PERCENT:
return aValue;
}
}
double EDA_UNIT_UTILS::UI::DoubleValueFromString( const wxString& aTextValue )
{
double dtmp = 0;
// 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 any entered decimal point separators to the 'right' one
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
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;
}
// Extract the numeric part
buf.Left( brk_point ).ToDouble( &dtmp );
return dtmp;
}
double EDA_UNIT_UTILS::UI::DoubleValueFromString( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
const wxString& aTextValue, EDA_DATA_TYPE aType )
{
double dtmp = 0;
// 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 any entered decimal point separators to the 'right' one
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
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;
}
// Extract the numeric part
buf.Left( brk_point ).ToDouble( &dtmp );
// Check the optional unit designator (2 ch significant)
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( aUnits == EDA_UNITS::MILLIMETRES || aUnits == EDA_UNITS::MILS
|| aUnits == EDA_UNITS::INCHES )
{
if( unit == wxT( "mm" ) )
{
aUnits = EDA_UNITS::MILLIMETRES;
}
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) )
{
aUnits = EDA_UNITS::MILS;
}
else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
{
aUnits = EDA_UNITS::INCHES;
}
else if( unit == "oz" ) // 1 oz = 1.37 mils
{
aUnits = EDA_UNITS::MILS;
dtmp *= 1.37;
}
}
else if( aUnits == EDA_UNITS::DEGREES )
{
if( unit == wxT( "ra" ) ) // Radians
dtmp *= 180.0f / M_PI;
}
switch( aType )
{
case EDA_DATA_TYPE::VOLUME:
dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
}
return dtmp;
}
long long int EDA_UNIT_UTILS::UI::ValueFromString( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
const wxString& aTextValue, EDA_DATA_TYPE aType )
{
double value = DoubleValueFromString( aIuScale, aUnits, aTextValue, aType );
return KiROUND<double, long long int>( value );
}
long long int EDA_UNIT_UTILS::UI::ValueFromString( const wxString& aTextValue )
{
double value = DoubleValueFromString( aTextValue );
return KiROUND<double, long long int>( value );
}

View File

@ -1011,7 +1011,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
m_unitResolver->GetSupportedUnitsMessage() );
reportError( CST_CODEGEN, msg, node->srcPos );
value = DoubleValueFromString( EDA_UNITS::UNSCALED, *node->value.str );
value = EDA_UNIT_UTILS::UI::DoubleValueFromString( *node->value.str );
}
node->SetUop( TR_UOP_PUSH_VALUE, value );

View File

@ -34,9 +34,11 @@
using namespace KIGFX::PREVIEW;
ARC_ASSISTANT::ARC_ASSISTANT( const ARC_GEOM_MANAGER& aManager, EDA_UNITS aUnits ) :
ARC_ASSISTANT::ARC_ASSISTANT( const ARC_GEOM_MANAGER& aManager, const EDA_IU_SCALE& aIuScale,
EDA_UNITS aUnits ) :
EDA_ITEM( NOT_USED ),
m_constructMan( aManager ),
m_iuScale( aIuScale ),
m_units( aUnits )
{
}
@ -90,8 +92,9 @@ void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
initAngle.Normalize720();
cursorStrings.push_back( DimensionLabel( "r", m_constructMan.GetRadius(), m_units ) );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), initAngle.AsDegrees(),
cursorStrings.push_back(
DimensionLabel( "r", m_constructMan.GetRadius(), m_iuScale, m_units ) );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), initAngle.AsDegrees(), m_iuScale,
EDA_UNITS::DEGREES ) );
}
else
@ -106,9 +109,9 @@ void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetLastPoint(), true );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "Δθ" ), subtended.AsDegrees(),
EDA_UNITS::DEGREES ) );
m_iuScale, EDA_UNITS::DEGREES ) );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), endAngle.AsDegrees(),
EDA_UNITS::DEGREES ) );
m_iuScale, EDA_UNITS::DEGREES ) );
}
// place the text next to cursor, on opposite side from radius

View File

@ -30,7 +30,8 @@ double KIGFX::PREVIEW::PreviewOverlayDeemphAlpha( bool aDeemph )
}
wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal, EDA_UNITS aUnits,
wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal,
const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
bool aIncludeUnits )
{
wxString str;
@ -52,7 +53,7 @@ wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal, ED
case EDA_UNITS::UNSCALED: fmtStr = wxT( "%f" ); break;
}
str << wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
str << wxString::Format( fmtStr, EDA_UNIT_UTILS::UI::ToUserUnit( aIuScale, aUnits, aVal ) );
if( aIncludeUnits )
str << EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits );

View File

@ -53,7 +53,7 @@ static int getShadowLayer( KIGFX::GAL* aGal )
static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
const VECTOR2D& aRulerVec, EDA_UNITS aUnits,
const VECTOR2D& aRulerVec, const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
bool aDrawingDropShadows, bool aFlipX, bool aFlipY )
{
// draw the cursor labels
@ -67,13 +67,13 @@ static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
if( aFlipY )
temp.y = -temp.y;
cursorStrings.push_back( DimensionLabel( "x", temp.x, aUnits ) );
cursorStrings.push_back( DimensionLabel( "y", temp.y, aUnits ) );
cursorStrings.push_back( DimensionLabel( "x", temp.x, aIuScale, aUnits ) );
cursorStrings.push_back( DimensionLabel( "y", temp.y, aIuScale, aUnits ) );
cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aUnits ) );
cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aIuScale, aUnits ) );
EDA_ANGLE angle = -EDA_ANGLE( aRulerVec );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(),
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(), aIuScale,
EDA_UNITS::DEGREES ) );
temp = aRulerVec;
@ -148,7 +148,7 @@ static TICK_FORMAT getTickFormatForScale( double aScale, double& aTickSpace, EDA
* @param aMinorTickLen length of minor ticks in IU
*/
void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTOR2D& aLine,
double aMinorTickLen, EDA_UNITS aUnits, bool aDrawingDropShadows )
double aMinorTickLen, const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits, bool aDrawingDropShadows )
{
KIGFX::GAL* gal = aView->GetGAL();
KIFONT::FONT* font = KIFONT::FONT::GetFont();
@ -220,7 +220,7 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
if( drawLabel )
{
wxString label = DimensionLabel( "", tickSpace * i, aUnits, false );
wxString label = DimensionLabel( "", tickSpace * i, aIuScale, aUnits, false );
font->Draw( gal, label, tickPos + labelOffset, labelAttrs );
}
}
@ -267,11 +267,12 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO
}
RULER_ITEM::RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& aGeomMgr, EDA_UNITS userUnits,
RULER_ITEM::RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& aGeomMgr, const EDA_IU_SCALE& aIuScale, EDA_UNITS userUnits,
bool aFlipX, bool aFlipY )
: EDA_ITEM( NOT_USED ), // Never added to anything - just a preview
m_geomMgr( aGeomMgr ),
m_userUnits( userUnits ),
m_iuScale( aIuScale ),
m_flipX( aFlipX ),
m_flipY( aFlipY )
{
@ -330,13 +331,14 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
VECTOR2D rulerVec( end - origin );
drawCursorStrings( aView, end, rulerVec, m_userUnits, drawingDropShadows, m_flipX, m_flipY );
drawCursorStrings( aView, end, rulerVec, m_iuScale, m_userUnits, drawingDropShadows, m_flipX,
m_flipY );
// basic tick size
const double minorTickLen = 5.0 / gal->GetWorldScale();
const double majorTickLen = minorTickLen * majorTickLengthFactor;
drawTicksAlongLine( aView, origin, rulerVec, minorTickLen, m_userUnits, drawingDropShadows );
drawTicksAlongLine( aView, origin, rulerVec, minorTickLen, m_iuScale, m_userUnits, drawingDropShadows );
drawBacksideTicks( aView, origin, rulerVec, majorTickLen, 2, drawingDropShadows );

View File

@ -30,11 +30,13 @@
using namespace KIGFX::PREVIEW;
TWO_POINT_ASSISTANT::TWO_POINT_ASSISTANT( const TWO_POINT_GEOMETRY_MANAGER& aManager,
EDA_UNITS aUnits, GEOM_SHAPE aShape ) :
const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
GEOM_SHAPE aShape ) :
EDA_ITEM( NOT_USED ),
m_constructMan( aManager ),
m_units( aUnits ),
m_shape( aShape )
m_shape( aShape ),
m_iuScale( aIuScale )
{
}
@ -80,21 +82,23 @@ void TWO_POINT_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
if( m_shape == GEOM_SHAPE::SEGMENT )
{
cursorStrings.push_back( DimensionLabel( "l", radVec.EuclideanNorm(), m_units ) );
cursorStrings.push_back(
DimensionLabel( "l", radVec.EuclideanNorm(), m_iuScale, m_units ) );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), deltaAngle.AsDegrees(),
EDA_UNITS::DEGREES ) );
m_iuScale, EDA_UNITS::DEGREES ) );
}
else if( m_shape == GEOM_SHAPE::RECT )
{
cursorStrings.push_back( DimensionLabel( "x", std::abs( radVec.x ), m_units ) );
cursorStrings.push_back( DimensionLabel( "y", std::abs( radVec.y ), m_units ) );
cursorStrings.push_back( DimensionLabel( "x", std::abs( radVec.x ), m_iuScale, m_units ) );
cursorStrings.push_back( DimensionLabel( "y", std::abs( radVec.y ), m_iuScale, m_units ) );
}
else if( m_shape == GEOM_SHAPE::CIRCLE )
{
KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
preview_ctx.DrawLine( origin, end, false );
cursorStrings.push_back( DimensionLabel( "r", radVec.EuclideanNorm(), m_units ) );
cursorStrings.push_back(
DimensionLabel( "r", radVec.EuclideanNorm(), m_iuScale, m_units ) );
}
// place the text next to cursor, on opposite side from drawing

View File

@ -44,11 +44,11 @@ wxString RC_ITEM::GetErrorMessage() const
}
wxString RC_ITEM::ShowCoord( EDA_UNITS aUnits, const VECTOR2I& aPos )
wxString RC_ITEM::ShowCoord( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits, const VECTOR2I& aPos )
{
return wxString::Format( wxT( "@(%s, %s)" ),
MessageTextFromValue( aUnits, aPos.x ),
MessageTextFromValue( aUnits, aPos.y ) );
EDA_UNIT_UTILS::UI::MessageTextFromValue( aIuScale, aUnits, aPos.x ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( aIuScale, aUnits, aPos.y ) );
}
@ -76,7 +76,7 @@ void RC_ITEM::SetItems( const EDA_ITEM* aItem, const EDA_ITEM* bItem,
}
wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity,
wxString RC_ITEM::ShowReport( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits, SEVERITY aSeverity,
const std::map<KIID, EDA_ITEM*>& aItemMap ) const
{
wxString severity;
@ -120,9 +120,9 @@ wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity,
GetErrorMessage(),
GetViolatingRuleDesc(),
severity,
ShowCoord( aUnits, mainItem->GetPosition() ),
ShowCoord( aIuScale, aUnits, mainItem->GetPosition() ),
mainItem->GetSelectMenuText( aUnits ),
ShowCoord( aUnits, auxItem->GetPosition() ),
ShowCoord( aIuScale, aUnits, auxItem->GetPosition() ),
auxItem->GetSelectMenuText( aUnits ) );
}
else if( mainItem )
@ -132,7 +132,7 @@ wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity,
GetErrorMessage(),
GetViolatingRuleDesc(),
severity,
ShowCoord( aUnits, mainItem->GetPosition() ),
ShowCoord( aIuScale, aUnits, mainItem->GetPosition() ),
mainItem->GetSelectMenuText( aUnits ) );
}
else

View File

@ -190,7 +190,8 @@ wxString STROKE_PARAMS::GetLineStyleToken( PLOT_DASH_TYPE aStyle )
}
void STROKE_PARAMS::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList,
void STROKE_PARAMS::GetMsgPanelInfo( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
std::vector<MSG_PANEL_ITEM>& aList,
bool aIncludeStyle, bool aIncludeWidth )
{
if( aIncludeStyle )
@ -211,25 +212,26 @@ void STROKE_PARAMS::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITE
if( aIncludeWidth )
{
aList.emplace_back( _( "Line Width" ), MessageTextFromValue( aUnits, GetWidth() ) );
aList.emplace_back( _( "Line Width" ), EDA_UNIT_UTILS::UI::MessageTextFromValue( aIuScale, aUnits, GetWidth() ) );
}
}
void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel ) const
void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, const EDA_IU_SCALE& aIuScale,
int aNestLevel ) const
{
wxASSERT( aFormatter != nullptr );
if( GetColor() == KIGFX::COLOR4D::UNSPECIFIED )
{
aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s))",
FormatInternalUnits(GetWidth() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( aIuScale, GetWidth() ).c_str(),
TO_UTF8( GetLineStyleToken( GetPlotStyle() ) ) );
}
else
{
aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))",
FormatInternalUnits(GetWidth() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( aIuScale, GetWidth() ).c_str(),
TO_UTF8( GetLineStyleToken( GetPlotStyle() ) ),
KiROUND( GetColor().r * 255.0 ),
KiROUND( GetColor().g * 255.0 ),

View File

@ -59,12 +59,15 @@ void COMMON_TOOLS::Reset( RESET_REASON aReason )
for( const wxString& gridDef : settings.sizes )
{
int gridSize = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridDef );
int gridSize = (int) EDA_UNIT_UTILS::UI::ValueFromString( m_frame->GetIuScale(), EDA_UNITS::MILLIMETRES, gridDef );
m_grids.emplace_back( gridSize, gridSize );
}
m_grids.emplace_back( ValueFromString( EDA_UNITS::MILLIMETRES, settings.user_grid_x ),
ValueFromString( EDA_UNITS::MILLIMETRES, settings.user_grid_y ) );
m_grids.emplace_back(
EDA_UNIT_UTILS::UI::ValueFromString( m_frame->GetIuScale(), EDA_UNITS::MILLIMETRES,
settings.user_grid_x ),
EDA_UNIT_UTILS::UI::ValueFromString( m_frame->GetIuScale(), EDA_UNITS::MILLIMETRES,
settings.user_grid_y ) );
OnGridChanged();
}

View File

@ -94,22 +94,26 @@ void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* a
for( const wxString& gridSize : aCfg->m_Window.grid.sizes )
{
int val = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridSize );
int val = (int) EDA_UNIT_UTILS::UI::ValueFromString( aParent->GetIuScale(), EDA_UNITS::MILLIMETRES, gridSize );
msg.Printf( _( "Grid: %s (%s)" ),
MessageTextFromValue( primaryUnit, val ),
MessageTextFromValue( secondaryUnit, val ) );
msg.Printf(
_( "Grid: %s (%s)" ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( aParent->GetIuScale(), primaryUnit, val ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( aParent->GetIuScale(), secondaryUnit,
val ) );
aGridsList->Add( msg );
}
if( !aCfg->m_Window.grid.user_grid_x.empty() )
{
int val = (int) ValueFromString( EDA_UNITS::INCHES, aCfg->m_Window.grid.user_grid_x );
int val = (int) EDA_UNIT_UTILS::UI::ValueFromString( aParent->GetIuScale(),EDA_UNITS::INCHES,
aCfg->m_Window.grid.user_grid_x );
msg.Printf( _( "User grid: %s (%s)" ),
MessageTextFromValue( primaryUnit, val ),
MessageTextFromValue( secondaryUnit, val ) );
EDA_UNIT_UTILS::UI::MessageTextFromValue( aParent->GetIuScale(), primaryUnit, val ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( aParent->GetIuScale(), secondaryUnit,
val ) );
aGridsList->Add( msg );
}

View File

@ -37,12 +37,20 @@
wxDEFINE_EVENT( DELAY_FOCUS, wxCommandEvent );
UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValueCtrl,
UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValueCtrl,
wxStaticText* aUnitLabel, bool allowEval ) :
UNIT_BINDER( aParent, aParent->GetIuScale(), aLabel, aValueCtrl, aUnitLabel, allowEval )
{
}
UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale,
wxStaticText* aLabel, wxWindow* aValueCtrl,
wxStaticText* aUnitLabel, bool allowEval ) :
m_frame( aParent ),
m_label( aLabel ),
m_valueCtrl( aValueCtrl ),
m_unitLabel( aUnitLabel ),
m_iuScale( aIUScale ),
m_negativeZero( false ),
m_dataType( EDA_DATA_TYPE::DISTANCE ),
m_precision( 0 ),
@ -246,12 +254,12 @@ bool UNIT_BINDER::Validate( double aMin, double aMax, EDA_UNITS aUnits )
// TODO: Validate() does not currently support m_dataType being anything other than DISTANCE
// Note: aMin and aMax are not always given in internal units
if( GetValue() < From_User_Unit( aUnits, aMin ) )
if( GetValue() < EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMin ) )
{
double val_min_iu = From_User_Unit( aUnits, aMin );
double val_min_iu = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMin );
m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
valueDescriptionFromLabel( m_label ),
StringFromValue( m_units, val_min_iu, true ) );
EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, val_min_iu, true ) );
textEntry->SelectAll();
@ -261,12 +269,12 @@ bool UNIT_BINDER::Validate( double aMin, double aMax, EDA_UNITS aUnits )
return false;
}
if( GetValue() > From_User_Unit( aUnits, aMax ) )
if( GetValue() > EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMax ) )
{
double val_max_iu = From_User_Unit( aUnits, aMax );
double val_max_iu = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMax );
m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
valueDescriptionFromLabel( m_label ),
StringFromValue( m_units, val_max_iu, true ) );
EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, val_max_iu, true ) );
textEntry->SelectAll();
@ -286,9 +294,10 @@ void UNIT_BINDER::SetValue( long long int aValue )
double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
if( displayValue == 0 && m_negativeZero )
SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
SetValue( wxT( "-" ) + EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, displayValue, false, m_dataType ) );
else
SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
SetValue( EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, displayValue,
false, m_dataType ) );
}
@ -298,9 +307,12 @@ void UNIT_BINDER::SetDoubleValue( double aValue )
displayValue = setPrecision( displayValue, false );
if( displayValue == 0 && m_negativeZero )
SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
SetValue( wxT( "-" )
+ EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
displayValue, false, m_dataType ) );
else
SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
SetValue( EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, displayValue,
false, m_dataType ) );
}
@ -335,9 +347,12 @@ void UNIT_BINDER::ChangeValue( int aValue )
double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
if( displayValue == 0 && m_negativeZero )
ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false ) );
ChangeValue( wxT( "-" )
+ EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
displayValue, false ) );
else
ChangeValue( StringFromValue( m_units, displayValue, false ) );
ChangeValue( EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
displayValue, false ) );
}
@ -347,9 +362,12 @@ void UNIT_BINDER::ChangeDoubleValue( double aValue )
displayValue = setPrecision( displayValue, false );
if( displayValue == 0 && m_negativeZero )
ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
ChangeValue( wxT( "-" )
+ EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
displayValue, false, m_dataType ) );
else
ChangeValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
ChangeValue( EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
displayValue, false, m_dataType ) );
}
@ -400,7 +418,7 @@ long long int UNIT_BINDER::GetValue()
return 0;
}
long long int displayValue = ValueFromString( m_units, value, m_dataType );
long long int displayValue = EDA_UNIT_UTILS::UI::ValueFromString( m_iuScale, m_units, value, m_dataType );
return m_originTransforms.FromDisplay( displayValue, m_coordType );
}
@ -410,11 +428,16 @@ double UNIT_BINDER::setPrecision( double aValue, bool aValueUsesUserUnits )
if( m_precision > 1 )
{
int scale = pow( 10, m_precision );
long long tmp = aValueUsesUserUnits ? aValue : To_User_Unit( m_units, aValue ) * scale;
int64_t tmp = aValue;
if( !aValueUsesUserUnits )
{
tmp = EDA_UNIT_UTILS::UI::ToUserUnit( m_iuScale, m_units, aValue ) * scale;
}
aValue = static_cast<double>( tmp ) / scale;
if( !aValueUsesUserUnits )
aValue = From_User_Unit( m_units, aValue );
aValue = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, m_units, aValue );
}
return aValue;
@ -443,7 +466,8 @@ double UNIT_BINDER::GetDoubleValue()
return 0.0;
}
double displayValue = DoubleValueFromString( m_units, value, m_dataType );
double displayValue = EDA_UNIT_UTILS::UI::DoubleValueFromString( m_iuScale, m_units,
value, m_dataType );
displayValue = setPrecision( displayValue, false );
return m_originTransforms.FromDisplay( displayValue, m_coordType );

View File

@ -26,7 +26,6 @@ set( CVPCB_DIALOGS
)
set( CVPCB_SRCS
${CMAKE_SOURCE_DIR}/common/base_units.cpp
${CMAKE_SOURCE_DIR}/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp
${CMAKE_SOURCE_DIR}/pcbnew/footprint_info_impl.cpp
auto_associate.cpp

View File

@ -318,7 +318,6 @@ set( EESCHEMA_SRCS
set( EESCHEMA_COMMON_SRCS
${CMAKE_SOURCE_DIR}/common/base_units.cpp
)

View File

@ -304,7 +304,7 @@ ANNOTATE_ALGO_T DIALOG_ANNOTATE::GetAnnotateAlgo()
int DIALOG_ANNOTATE::GetStartNumber()
{
return ValueFromString( EDA_UNITS::UNSCALED, m_textNumberAfter->GetValue() );
return EDA_UNIT_UTILS::UI::ValueFromString( m_textNumberAfter->GetValue() );
}

View File

@ -983,7 +983,7 @@ bool DIALOG_ERC::writeReport( const wxString& aFullFileName )
default: break;
}
msg << marker->GetRCItem()->ShowReport( GetUserUnits(), severity, itemMap );
msg << marker->GetRCItem()->ShowReport( schIUScale, GetUserUnits(), severity, itemMap );
}
}

View File

@ -179,23 +179,28 @@ public:
break;
case COL_NUMBER_SIZE:
val = StringFromValue( aUserUnits, pin->GetNumberTextSize(), true );
val = EDA_UNIT_UTILS::UI::StringFromValue( schIUScale, aUserUnits,
pin->GetNumberTextSize(), true );
break;
case COL_NAME_SIZE:
val = StringFromValue( aUserUnits, pin->GetNameTextSize(), true );
val = EDA_UNIT_UTILS::UI::StringFromValue( schIUScale, aUserUnits,
pin->GetNameTextSize(), true );
break;
case COL_LENGTH:
val = StringFromValue( aUserUnits, pin->GetLength(), true );
val = EDA_UNIT_UTILS::UI::StringFromValue( schIUScale, aUserUnits,
pin->GetLength(), true );
break;
case COL_POSX:
val = StringFromValue( aUserUnits, pin->GetPosition().x, true );
val = EDA_UNIT_UTILS::UI::StringFromValue( schIUScale, aUserUnits,
pin->GetPosition().x, true );
break;
case COL_POSY:
val = StringFromValue( aUserUnits, -pin->GetPosition().y, true );
val = EDA_UNIT_UTILS::UI::StringFromValue( schIUScale, aUserUnits,
-pin->GetPosition().y, true );
break;
case COL_VISIBLE:
@ -348,25 +353,29 @@ public:
break;
case COL_NUMBER_SIZE:
pin->SetNumberTextSize( ValueFromString( m_frame->GetUserUnits(), aValue ) );
pin->SetNumberTextSize( EDA_UNIT_UTILS::UI::ValueFromString( schIUScale, m_frame->GetUserUnits(), aValue ) );
break;
case COL_NAME_SIZE:
pin->SetNameTextSize( ValueFromString( m_frame->GetUserUnits(), aValue ) );
pin->SetNameTextSize( EDA_UNIT_UTILS::UI::ValueFromString(
schIUScale, m_frame->GetUserUnits(), aValue ) );
break;
case COL_LENGTH:
pin->ChangeLength( ValueFromString( m_frame->GetUserUnits(), aValue ) );
pin->ChangeLength( EDA_UNIT_UTILS::UI::ValueFromString(
schIUScale, m_frame->GetUserUnits(), aValue ) );
break;
case COL_POSX:
pin->SetPosition( wxPoint( ValueFromString( m_frame->GetUserUnits(), aValue ),
pin->SetPosition( wxPoint( EDA_UNIT_UTILS::UI::ValueFromString(
schIUScale, m_frame->GetUserUnits(), aValue ),
pin->GetPosition().y ) );
break;
case COL_POSY:
pin->SetPosition( wxPoint( pin->GetPosition().x,
-ValueFromString( m_frame->GetUserUnits(), aValue ) ) );
-EDA_UNIT_UTILS::UI::ValueFromString(
schIUScale, m_frame->GetUserUnits(), aValue ) ) );
break;
case COL_VISIBLE:
@ -454,12 +463,14 @@ public:
break;
case COL_NUMBER_SIZE:
case COL_NAME_SIZE:
res = cmp( ValueFromString( units, lhStr ), ValueFromString( units, rhStr ) );
res = cmp( EDA_UNIT_UTILS::UI::ValueFromString( schIUScale, units, lhStr ),
EDA_UNIT_UTILS::UI::ValueFromString( schIUScale, units, rhStr ) );
break;
case COL_LENGTH:
case COL_POSX:
case COL_POSY:
res = cmp( ValueFromString( units, lhStr ), ValueFromString( units, rhStr ) );
res = cmp( EDA_UNIT_UTILS::UI::ValueFromString( schIUScale, units, lhStr ),
EDA_UNIT_UTILS::UI::ValueFromString( schIUScale, units, rhStr ) );
break;
case COL_VISIBLE:
case COL_DEMORGAN:

Some files were not shown because too many files have changed in this diff Show More