Browse Source
More internal unit improvements.
More internal unit improvements.
* Move all convert from internal to user units functions into separate file. * Remove internal units parameter from all moved conversion functions. * Revise all source code that calls the moved conversion functions. * Compile these conversion routines separately for the appropriate pcb or schematic internal units. * Move internal units specific status bar update code into the appropriate application for updating the status bar. * Move millimeter user units rounding function to common.cpp.pull/1/head
57 changed files with 714 additions and 578 deletions
-
1common/CMakeLists.txt
-
161common/base_units.cpp
-
123common/common.cpp
-
107common/drawframe.cpp
-
36common/wxwineda.cpp
-
35common/zoom.cpp
-
1eeschema/CMakeLists.txt
-
8eeschema/dialogs/dialog_SVG_print.cpp
-
5eeschema/dialogs/dialog_edit_component_in_schematic.cpp
-
4eeschema/dialogs/dialog_edit_label.cpp
-
5eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp
-
4eeschema/dialogs/dialog_edit_one_field.cpp
-
7eeschema/dialogs/dialog_lib_edit_text.cpp
-
11eeschema/dialogs/dialog_plot_schematic_HPGL.cpp
-
4eeschema/dialogs/dialog_plot_schematic_PS.cpp
-
1eeschema/dialogs/dialog_print_using_printer.cpp
-
7eeschema/find.cpp
-
9eeschema/lib_arc.cpp
-
3eeschema/lib_bezier.cpp
-
11eeschema/lib_circle.cpp
-
5eeschema/lib_field.cpp
-
3eeschema/lib_pin.cpp
-
9eeschema/lib_polyline.cpp
-
11eeschema/lib_rectangle.cpp
-
3eeschema/lib_text.cpp
-
9eeschema/pinedit.cpp
-
67eeschema/sch_base_frame.cpp
-
9eeschema/sch_line.cpp
-
9eeschema/sheet.cpp
-
5eeschema/sheetlab.cpp
-
3eeschema/symbdraw.cpp
-
83include/base_units.h
-
59include/common.h
-
2include/sch_base_frame.h
-
76pcbnew/basepcbframe.cpp
-
7pcbnew/dialogs/dialog_SVG_print.cpp
-
21pcbnew/dialogs/dialog_copper_zones.cpp
-
51pcbnew/dialogs/dialog_design_rules.cpp
-
20pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp
-
14pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp
-
16pcbnew/dialogs/dialog_edit_module_text.cpp
-
22pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp
-
22pcbnew/dialogs/dialog_graphic_item_properties.cpp
-
19pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp
-
34pcbnew/dialogs/dialog_graphic_items_options.cpp
-
10pcbnew/dialogs/dialog_mask_clearance.cpp
-
38pcbnew/dialogs/dialog_pad_properties.cpp
-
16pcbnew/dialogs/dialog_pcb_text_properties.cpp
-
5pcbnew/dialogs/dialog_print_using_printer.cpp
-
16pcbnew/dimension.cpp
-
12pcbnew/drc.cpp
-
4pcbnew/edgemod.cpp
-
8pcbnew/muonde.cpp
-
8pcbnew/onrightclick.cpp
-
27pcbnew/pcbplot.cpp
-
5pcbnew/set_grid.cpp
-
5pcbnew/zones_non_copper_type_functions.cpp
@ -0,0 +1,161 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2012 CERN |
|||
* Copyright (C) 1992-2011 KiCad Developers, see change_log.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@verizon.net> |
|||
* @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_struct.h>
|
|||
#include <class_title_block.h>
|
|||
#include <common.h>
|
|||
#include <base_units.h>
|
|||
|
|||
|
|||
#if defined( PCBNEW )
|
|||
#if defined( USE_PCBNEW_NANOMETRES )
|
|||
#define IU_TO_MM( x ) ( x * 1e-6 )
|
|||
#define IU_TO_IN( x ) ( ( x * 1e-6 ) / 25.4 )
|
|||
#else
|
|||
#define IU_TO_MM( x ) ( ( x * 0.0001 ) * 25.4 )
|
|||
#define IU_TO_IN( x ) ( x * 0.0001 )
|
|||
#endif
|
|||
#elif defined( EESCHEMA )
|
|||
#define IU_TO_MM( x ) ( ( x * 0.001 ) * 25.4 )
|
|||
#define IU_TO_IN( x ) ( x * 0.001 )
|
|||
#else
|
|||
#error "Cannot resolve internal units due to no definition of EESCHEMA or PCBNEW."
|
|||
#endif
|
|||
|
|||
|
|||
double To_User_Unit( EDA_UNITS_T aUnit, double aValue ) |
|||
{ |
|||
switch( aUnit ) |
|||
{ |
|||
case MILLIMETRES: |
|||
return IU_TO_MM( aValue ); |
|||
|
|||
case INCHES: |
|||
return IU_TO_IN( aValue ); |
|||
|
|||
default: |
|||
return aValue; |
|||
} |
|||
} |
|||
|
|||
|
|||
wxString CoordinateToString( int aValue, bool aConvertToMils ) |
|||
{ |
|||
wxString text; |
|||
const wxChar* format; |
|||
double value = To_User_Unit( g_UserUnit, aValue ); |
|||
|
|||
if( g_UserUnit == INCHES ) |
|||
{ |
|||
if( aConvertToMils ) |
|||
{ |
|||
#if defined( EESCHEMA )
|
|||
format = wxT( "%.0f" ); |
|||
#else
|
|||
format = wxT( "%.1f" ); |
|||
#endif
|
|||
if( aConvertToMils ) |
|||
value *= 1000; |
|||
} |
|||
else |
|||
{ |
|||
#if defined( EESCHEMA )
|
|||
format = wxT( "%.3f" ); |
|||
#else
|
|||
format = wxT( "%.4f" ); |
|||
#endif
|
|||
} |
|||
} |
|||
else |
|||
{ |
|||
#if defined( EESCHEMA )
|
|||
format = wxT( "%.2f" ); |
|||
#else
|
|||
format = wxT( "%.3f" ); |
|||
#endif
|
|||
} |
|||
|
|||
text.Printf( format, value ); |
|||
|
|||
if( g_UserUnit == INCHES ) |
|||
text += ( aConvertToMils ) ? _( " mils" ) : _( " in" ); |
|||
else |
|||
text += _( " mm" ); |
|||
|
|||
return text; |
|||
} |
|||
|
|||
|
|||
wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol ) |
|||
{ |
|||
wxString StringValue; |
|||
double value_to_print; |
|||
|
|||
value_to_print = To_User_Unit( aUnit, aValue ); |
|||
|
|||
#if defined( PCBNEW )
|
|||
StringValue.Printf( wxT( "%.4f" ), value_to_print ); |
|||
#else
|
|||
StringValue.Printf( wxT( "%.3f" ), value_to_print ); |
|||
#endif
|
|||
|
|||
if( aAddUnitSymbol ) |
|||
{ |
|||
switch( aUnit ) |
|||
{ |
|||
case INCHES: |
|||
StringValue += _( " \"" ); |
|||
break; |
|||
|
|||
case MILLIMETRES: |
|||
StringValue += _( " mm" ); |
|||
break; |
|||
|
|||
case UNSCALED_UNITS: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return StringValue; |
|||
} |
|||
|
|||
|
|||
void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue ) |
|||
{ |
|||
wxString msg = ReturnStringFromValue( g_UserUnit, aValue ); |
|||
|
|||
aTextCtr.SetValue( msg ); |
|||
} |
@ -0,0 +1,83 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2012 CERN |
|||
* Copyright (C) 1992-2011 KiCad Developers, see change_log.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@verizon.net> |
|||
* @file base_units.h |
|||
* @brief Implementation of conversion functions that require both schematic and board |
|||
* internal units. |
|||
*/ |
|||
|
|||
#ifndef _BASE_UNITS_H_ |
|||
#define _BASE_UNITS_H_ |
|||
|
|||
|
|||
#include <common.h> |
|||
|
|||
|
|||
/** |
|||
* Function To_User_Unit |
|||
* convert \a aValue in internal units to the appropriate user units defined by \a aUnit. |
|||
* |
|||
* @return The converted value, in double |
|||
* @param aUnit The units to convert \a aValue to. |
|||
* @param aValue The value in internal units to convert. |
|||
*/ |
|||
double To_User_Unit( EDA_UNITS_T aUnit, double aValue ); |
|||
|
|||
/** |
|||
* Function CoordinateToString |
|||
* is a helper to convert the integer coordinate \a aValue to a string in inches, |
|||
* millimeters, or unscaled units according to the current user units setting. |
|||
* |
|||
* @param aValue The coordinate to convert. |
|||
* @param aConvertToMils Convert inch values to mils if true. This setting has no effect if |
|||
* the current user unit is millimeters. |
|||
* @return The converted string for display in user interface elements. |
|||
*/ |
|||
wxString CoordinateToString( int aValue, bool aConvertToMils = false ); |
|||
|
|||
|
|||
/** |
|||
* Function ReturnStringFromValue |
|||
* returns the string from \a aValue according to units (inch, mm ...) for display, |
|||
* and the initial unit for value. |
|||
* @param aUnit = display units (INCHES, MILLIMETRE ..) |
|||
* @param aValue = value in Internal_Unit |
|||
* @param aAddUnitSymbol = true to add symbol unit to the string value |
|||
* @return A wxString object containing value and optionally the symbol unit (like 2.000 mm) |
|||
*/ |
|||
wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false ); |
|||
|
|||
/** |
|||
* Function PutValueInLocalUnits |
|||
* converts \a aValue from internal units to user units and append the units notation |
|||
* (mm or ")then inserts the string an \a aTextCtrl. |
|||
* |
|||
* This function is used in dialog boxes for entering values depending on selected units. |
|||
*/ |
|||
void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue ); |
|||
|
|||
#endif // _BASE_UNITS_H_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue