Remove convert_to_biu.h, merge contents to base_units.h

This commit is contained in:
Marek Roszko 2022-09-16 21:07:36 -04:00
parent 66e8931405
commit 3d5913c825
56 changed files with 116 additions and 186 deletions

View File

@ -33,7 +33,6 @@
#include <3d_math.h>
#include "3d_fastmath.h"
#include <geometry/geometry_utils.h>
#include <convert_to_biu.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <wx/log.h>

View File

@ -31,7 +31,6 @@
#include <string>
#include <vector>
#include <convert_to_biu.h>
#include <layer_ids.h>
#include <locale_io.h>

View File

@ -22,7 +22,6 @@
*/
#include <trigo.h>
#include <convert_to_biu.h>
#include <convert_basic_shapes_to_polygon.h>
#include <geometry/geometry_utils.h>

View File

@ -23,7 +23,6 @@
#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 )

View File

@ -23,6 +23,7 @@
#include <vector>
#include <algorithm>
#include <eda_units.h>
#include <string_utils.h>
#include <wx/log.h>

View File

@ -27,7 +27,7 @@
#include <common.h>
#include <macros.h>
#include <validators.h>
#include <convert_to_biu.h>
#include <eda_units.h>
#include <property.h>
#include <widgets/color_swatch.h>

View File

@ -26,7 +26,7 @@
#include <settings/json_settings_internals.h>
#include <settings/settings_manager.h>
#include <string_utils.h>
#include <convert_to_biu.h>
#include <base_units.h>
// const int netSettingsSchemaVersion = 0;

View File

@ -20,6 +20,7 @@
#include <class_draw_panel_gal.h>
#include <common.h>
#include <eda_units.h>
#include <layer_ids.h>
#include <pgm_base.h>
#include <settings/app_settings.h>

View File

@ -96,7 +96,6 @@ principle should be easily implemented by adapting the current STL containers.
#include <title_block.h>
#include <marker_base.h>
#include <eda_text.h>
#include <convert_to_biu.h>
#include <id.h>
#include <build_version.h>
#include <layer_ids.h>

View File

@ -25,7 +25,7 @@
#include <iostream>
#include <unordered_map>
#include <convert_to_biu.h>
#include <base_units.h>
#include <ki_exception.h>
#include <wx/log.h>

View File

@ -23,7 +23,7 @@
* @brief Reads in a CADSTAR Schematic Archive (*.csa) file
*/
#include <convert_to_biu.h> // SCH_IU_PER_MM
#include <base_units.h>
#include <macros.h>
#include <sch_plugins/cadstar/cadstar_sch_archive_parser.h>
#include <progress_reporter.h>

View File

@ -32,8 +32,6 @@
#ifndef __SCH_SEXPR_PARSER_H__
#define __SCH_SEXPR_PARSER_H__
#include <convert_to_biu.h> // IU_PER_MM
#include <symbol_library.h>
#include <schematic_lexer.h>
#include <sch_file_versions.h>

View File

@ -21,7 +21,6 @@
#include <base_screen.h>
#include <lib_symbol.h>
#include <convert_to_biu.h>
#include <default_values.h>
#include <eeschema_settings.h>
#include <kiface_base.h>

View File

@ -20,7 +20,6 @@
#ifndef KICAD_SCHEMATIC_SETTINGS_H
#define KICAD_SCHEMATIC_SETTINGS_H
#include <convert_to_biu.h>
#include <default_values.h>
#include <settings/nested_settings.h>
#include <template_fieldnames.h>

View File

@ -28,7 +28,6 @@
*/
#include <trigo.h>
#include <convert_to_biu.h>
#include <convert_basic_shapes_to_polygon.h>
#include <math/util.h> // for KiROUND

View File

@ -31,7 +31,7 @@
#include <trigo.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>
#include <convert_to_biu.h>
#include <eda_units.h>
#include <convert_basic_shapes_to_polygon.h>
#define DCODE_DEFAULT_SIZE gerbIUScale.mmToIU( 0.1 )

View File

@ -22,7 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <convert_to_biu.h>
#include <geometry/shape_poly_set.h>
#include <layer_ids.h>

View File

@ -22,7 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <convert_to_biu.h>
#include <gerbview.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>

View File

@ -27,7 +27,6 @@
#include <eda_draw_frame.h>
#include <layer_ids.h>
#include <gerbview.h>
#include <convert_to_biu.h>
#include <gbr_layout.h>
#include <page_info.h>
#include <gbr_display_options.h>

View File

@ -25,7 +25,6 @@
#include <settings/color_settings.h>
#include <gerbview_settings.h>
#include <convert_basic_shapes_to_polygon.h>
#include <convert_to_biu.h>
#include <gerbview.h>
#include <trigo.h>

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 CERN
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2022 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
@ -22,16 +22,102 @@
* 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 <eda_units.h>
/* Note about internal units and max size for boards and items
The largest distance that we (and Kicad) can support is INT_MAX, since it represents
distance often in a wxCoord or wxSize. As a scalar, a distance is always
positive. Because int is 32 bits and INT_MAX is
2147483647. The most difficult distance for a virtual (world) cartesian
space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
puts the most stress on the distance magnitude within the bounded virtual
space. So if we allow this distance to be our constraint of <= INT_MAX, this
constraint then propagates to the maximum distance in X and in Y that can be
supported on each axis. Remember that the hypotenuse of a 1x1 square is
sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
hypotenuse of any square = sqrt(2) * deltaX;
Let maximum supported hypotenuse be INT_MAX, then:
MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
The next choice is what to use for internal units (IU), sometimes called
world units. If nanometers, then the virtual space must be limited to
about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
The maximum zoom factor then depends on the client window size. If we ask
wx to handle something outside INT_MIN to INT_MAX, there are unreported
problems in the non-Debug build because wxRound() goes silent.
Pcbnew uses nanometers because we need to convert coordinates and size between
millimeters and inches. using a iu = 1 nm avoid rounding issues
Gerbview uses iu = 10 nm because we can have coordinates far from origin, and
1 nm is too small to avoid int overflow.
(Conversions between millimeters and inches are not critical)
*/
/**
* @brief some define and functions to convert a value in mils, decimils or mm
* to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil)
* depending on compile time option
*/
constexpr double GERB_IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers.
constexpr double PCB_IU_PER_MM = 1e6; // Pcbnew IU is 1 nanometer.
constexpr double PL_IU_PER_MM = 1e3; // internal units in micron (should be enough)
constexpr double SCH_IU_PER_MM = 1e4; // Schematic internal units 1=100nm
struct EDA_IU_SCALE
{
const double IU_PER_MM;
const double IU_PER_MILS;
const double MM_PER_IU;
constexpr EDA_IU_SCALE( double aIUPerMM ) :
IU_PER_MM( aIUPerMM ), IU_PER_MILS( aIUPerMM * 0.0254 ), MM_PER_IU( 1 / IU_PER_MM )
{
}
constexpr inline double IUTomm( int iu ) const { return iu / IU_PER_MM; }
constexpr inline int mmToIU( double mm ) const
{
return (int) ( mm < 0 ? ( mm * IU_PER_MM - 0.5 ) : ( mm * IU_PER_MM + 0.5 ) );
}
constexpr inline int MilsToIU( int mils ) const
{
double x = mils * IU_PER_MILS;
return int( x < 0 ? x - 0.5 : x + 0.5 );
}
constexpr inline double IUToMils( int iu ) const
{
double mils = iu / IU_PER_MILS;
return static_cast<int>( mils < 0 ? mils - 0.5 : mils + 0.5 );
}
};
constexpr EDA_IU_SCALE gerbIUScale = EDA_IU_SCALE( GERB_IU_PER_MM );
constexpr EDA_IU_SCALE pcbIUScale = EDA_IU_SCALE( PCB_IU_PER_MM );
constexpr EDA_IU_SCALE drawSheetIUScale = EDA_IU_SCALE( PL_IU_PER_MM );
constexpr EDA_IU_SCALE schIUScale = EDA_IU_SCALE( SCH_IU_PER_MM );
#ifndef SWIG
// The max error is the distance between the middle of a segment, and the circle
// for circle/arc to segment approximation.
// Warning: too small values can create very long calculation time in zone filling
// 0.05 to 0.005 mm are reasonable values
constexpr int ARC_LOW_DEF = pcbIUScale.mmToIU( 0.02 );
constexpr int ARC_HIGH_DEF = pcbIUScale.mmToIU( 0.005 );
#endif
#endif // _BASE_UNITS_H_

View File

@ -28,7 +28,6 @@
#include <eda_item.h>
#include <eda_units.h>
#include <convert_to_biu.h>
#include <gr_basic.h>
#include <layer_ids.h>
#include <geometry/geometry_utils.h>

View File

@ -1,123 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 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
*/
#pragma once
/* Note about internal units and max size for boards and items
The largest distance that we (and Kicad) can support is INT_MAX, since it represents
distance often in a wxCoord or wxSize. As a scalar, a distance is always
positive. Because int is 32 bits and INT_MAX is
2147483647. The most difficult distance for a virtual (world) cartesian
space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
puts the most stress on the distance magnitude within the bounded virtual
space. So if we allow this distance to be our constraint of <= INT_MAX, this
constraint then propagates to the maximum distance in X and in Y that can be
supported on each axis. Remember that the hypotenuse of a 1x1 square is
sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
hypotenuse of any square = sqrt(2) * deltaX;
Let maximum supported hypotenuse be INT_MAX, then:
MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
The next choice is what to use for internal units (IU), sometimes called
world units. If nanometers, then the virtual space must be limited to
about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
The maximum zoom factor then depends on the client window size. If we ask
wx to handle something outside INT_MIN to INT_MAX, there are unreported
problems in the non-Debug build because wxRound() goes silent.
Pcbnew uses nanometers because we need to convert coordinates and size between
millimeters and inches. using a iu = 1 nm avoid rounding issues
Gerbview uses iu = 10 nm because we can have coordinates far from origin, and
1 nm is too small to avoid int overflow.
(Conversions between millimeters and inches are not critical)
*/
/**
* @brief some define and functions to convert a value in mils, decimils or mm
* to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil)
* depending on compile time option
*/
constexpr double GERB_IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers.
constexpr double PCB_IU_PER_MM = 1e6; // Pcbnew IU is 1 nanometer.
constexpr double PL_IU_PER_MM = 1e3; // internal units in micron (should be enough)
constexpr double SCH_IU_PER_MM = 1e4; // Schematic internal units 1=100nm
struct EDA_IU_SCALE
{
const double IU_PER_MM;
const double IU_PER_MILS;
const double MM_PER_IU;
constexpr EDA_IU_SCALE( double aIUPerMM ) :
IU_PER_MM( aIUPerMM ),
IU_PER_MILS( aIUPerMM * 0.0254 ),
MM_PER_IU( 1 / IU_PER_MM )
{
}
constexpr inline double IUTomm( int iu ) const { return iu / IU_PER_MM; }
constexpr inline int mmToIU( double mm ) const
{
return (int) ( mm < 0 ? ( mm * IU_PER_MM - 0.5 ) : ( mm * IU_PER_MM + 0.5 ) );
}
constexpr inline int MilsToIU( int mils ) const
{
double x = mils * IU_PER_MILS;
return int( x < 0 ? x - 0.5 : x + 0.5 );
}
constexpr inline double IUToMils( int iu ) const
{
double mils = iu / IU_PER_MILS;
return static_cast<int>( mils < 0 ? mils - 0.5 : mils + 0.5 );
}
};
constexpr EDA_IU_SCALE gerbIUScale = EDA_IU_SCALE( GERB_IU_PER_MM );
constexpr EDA_IU_SCALE pcbIUScale = EDA_IU_SCALE( PCB_IU_PER_MM );
constexpr EDA_IU_SCALE drawSheetIUScale = EDA_IU_SCALE( PL_IU_PER_MM );
constexpr EDA_IU_SCALE schIUScale = EDA_IU_SCALE( SCH_IU_PER_MM );
#ifndef SWIG
// The max error is the distance between the middle of a segment, and the circle
// for circle/arc to segment approximation.
// Warning: too small values can create very long calculation time in zone filling
// 0.05 to 0.005 mm are reasonable values
constexpr int ARC_LOW_DEF = pcbIUScale.mmToIU( 0.02 );
constexpr int ARC_HIGH_DEF = pcbIUScale.mmToIU( 0.005 );
#endif

View File

@ -27,7 +27,7 @@
#include <wx/string.h>
#include <geometry/eda_angle.h>
#include <convert_to_biu.h>
#include <base_units.h>
/**
* The type of unit.

View File

@ -71,7 +71,7 @@ Supported units are millimeters (mm), Mil (mil) and inch (")
#include <map>
#include <string>
#include <base_units.h>
#include <eda_units.h>
// This namespace is used for the lemon parser
namespace numEval

View File

@ -26,6 +26,7 @@
#include <map>
#include <bitmaps.h>
#include <eda_units.h>
#include <gal/color4d.h>
#include <wx/translation.h>
#include <geometry/shape.h>

View File

@ -27,7 +27,7 @@
#define __SHAPE_ARC_H
#include <geometry/shape.h>
#include <convert_to_biu.h>
#include <base_units.h>
#include <math/vector2d.h> // for VECTOR2I
#include <geometry/eda_angle.h>

View File

@ -35,7 +35,6 @@
*/
#include <algorithm>
#include <convert_to_biu.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <board.h>

View File

@ -20,7 +20,6 @@
#include "board_stackup.h"
#include <convert_to_biu.h>
#include <base_units.h>
#include <string_utils.h>
#include <layer_ids.h>

View File

@ -23,7 +23,6 @@
#include <board_design_settings.h>
#include <board.h>
#include <convert_to_biu.h>
#include <math/util.h>
#include <panel_setup_constraints.h>
#include <panel_setup_constraints_base.h>

View File

@ -28,6 +28,7 @@
#include <vector>
#include <unordered_map>
#include <eda_units.h>
#include <geometry/shape.h>
#include <drc/drc_rule.h>

View File

@ -41,7 +41,7 @@
#include "filename_resolver.h"
#include <convert_to_biu.h> // to define pcbIUScale.FromMillimeter(x)
#include <base_units.h> // to define pcbIUScale.FromMillimeter(x)
// assumed default graphical line thickness: == 0.1mm

View File

@ -38,7 +38,6 @@
#include "pad.h"
#include "pcb_text.h"
#include "pcb_track.h"
#include "convert_to_biu.h"
#include <core/arraydim.h>
#include <filename_resolver.h>
#include "plugins/3dapi/ifsg_all.h"

View File

@ -30,7 +30,6 @@
#include <board_item_container.h>
#include <board_item.h>
#include <collectors.h>
#include <convert_to_biu.h>
#include <layer_ids.h> // ALL_LAYERS definition.
#include <lib_id.h>
#include <list>

View File

@ -32,8 +32,6 @@
#include <memory>
#include <tuple>
#include "convert_to_biu.h"
GRAPHICS_IMPORTER_PCBNEW::GRAPHICS_IMPORTER_PCBNEW()
{

View File

@ -30,7 +30,6 @@
#include <math/vector2d.h>
#include "convert_to_biu.h"
#include <eda_item.h>
#include "graphics_importer.h"

View File

@ -44,7 +44,7 @@
#include <pad.h>
#include <pcb_shape.h>
#include <connectivity/connectivity_data.h>
#include <convert_to_biu.h>
#include <eda_units.h>
#include <convert_basic_shapes_to_polygon.h>
#include <widgets/msgpanel.h>
#include <pcb_painter.h>

View File

@ -28,7 +28,6 @@
#include <mutex>
#include <zones.h>
#include <board_connected_item.h>
#include <convert_to_biu.h>
#include <geometry/shape_poly_set.h>
#include <geometry/shape_compound.h>
#include <pad_shapes.h>

View File

@ -39,7 +39,6 @@
#include <pcb_bitmap.h>
#include <trigo.h>
#include <geometry/shape_rect.h>
#include <convert_to_biu.h>
#include <wx/mstream.h>

View File

@ -23,7 +23,6 @@
#include <board_design_settings.h>
#include <charconv>
#include <convert_to_biu.h>
#include <layer_ids.h>
#include <macros.h>
#include <math/util.h> // for KiROUND

View File

@ -37,7 +37,7 @@
#include <board_connected_item.h>
#include <convert_to_biu.h>
#include <base_units.h>
#include <geometry/shape_segment.h>
#include "core/minoptmax.h"

View File

@ -25,7 +25,7 @@
#ifndef PCBNEW_H
#define PCBNEW_H
#include <convert_to_biu.h> // to define pcbIUScale.MilsToIU() conversion function
#include <eda_units.h> // to define pcbIUScale.MilsToIU() conversion function
// These are only here for algorithmic safety, not to tell the user what to do
#define TEXTS_MIN_SIZE pcbIUScale.MilsToIU( 1 ) ///< Minimum text size in internal units (1 mil)

View File

@ -23,8 +23,8 @@
* @brief Parses a CADSTAR PCB Archive file
*/
#include <base_units.h>
#include <cadstar_pcb_archive_parser.h>
#include <convert_to_biu.h> // PCB_IU_PER_MM
#include <macros.h>
#include <progress_reporter.h>
#include <wx/translation.h>

View File

@ -41,7 +41,6 @@
#include <board.h>
#include <board_design_settings.h>
#include <board_item.h>
#include <convert_to_biu.h>
#include <footprint.h>
#include <fp_shape.h>
#include <pad.h>

View File

@ -30,7 +30,6 @@
#ifndef _PCBNEW_PARSER_H_
#define _PCBNEW_PARSER_H_
#include <convert_to_biu.h> // IU_PER_MM
#include <core/wx_stl_compat.h>
#include <hashtables.h>
#include <layer_ids.h> // PCB_LAYER_ID

View File

@ -85,7 +85,6 @@
#include <fp_shape.h>
#include <pcb_plot_params.h>
#include <pcb_plot_params_parser.h>
#include <convert_to_biu.h>
#include <trigo.h>
#include <confirm.h>
#include <math/util.h> // for KiROUND

View File

@ -30,7 +30,6 @@
#include <pcad/pcad2kicad_common.h>
#include <common.h>
#include <convert_to_biu.h>
#include <math/util.h> // for KiROUND
#include <trigo.h>
#include <xnode.h>

View File

@ -43,8 +43,6 @@
// mostly for KICAD_T
%include typeinfo.i
%include <convert_to_biu.h>
%{
#include <lib_id.h>
%}

View File

@ -27,7 +27,7 @@
#include <string>
#include <vector>
#include <convert_to_biu.h>
#include <base_units.h>
// IDs for targets when creating teardrops
enum TARGET_TD

View File

@ -32,7 +32,6 @@
#include <fp_shape.h>
#include <fp_textbox.h>
#include <collectors.h>
#include <convert_to_biu.h>
#include <pcb_edit_frame.h>
#include <drawing_sheet/ds_proxy_view_item.h>
#include <kiway.h>

View File

@ -46,7 +46,6 @@
#include <geometry/convex_hull.h>
#include <geometry/geometry_utils.h>
#include <confirm.h>
#include <convert_to_biu.h>
#include <thread_pool.h>
#include <math/util.h> // for KiROUND
#include "zone_filler.h"

View File

@ -25,7 +25,6 @@
#include <zone_settings.h>
#include <convert_to_biu.h>
#include <pcbnew.h>
#include <pcb_base_frame.h>
#include <board.h>

View File

@ -25,7 +25,7 @@
#define EDA_ITEM_TEST_UTILS_H
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <convert_to_biu.h>
#include <base_units.h>
#include <eda_item.h>

View File

@ -29,7 +29,7 @@
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <convert_to_biu.h>
#include <base_units.h>
class TEST_SCH_INTERNAL_UNITS

View File

@ -26,7 +26,7 @@
* Test suite for SCH_SHEET
*/
#include <convert_to_biu.h>
#include <base_units.h>
#include <ignore.h>
#include <sch_junction.h>
#include <sch_no_connect.h>

View File

@ -24,8 +24,6 @@
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <convert_to_biu.h>
#include <geometry/shape_poly_set.h>
#include <qa_utils/geometry/poly_set_construction.h>