Split EDA_UNITS out from common.

This commit is contained in:
Marek Roszko 2020-10-24 10:45:37 -04:00
parent 7674d2ba91
commit e928b2d8fd
52 changed files with 180 additions and 76 deletions

View File

@ -325,6 +325,7 @@ set( COMMON_SRCS
eda_pattern_match.cpp
eda_rect.cpp
eda_size_ctrl.cpp
eda_units.cpp
env_paths.cpp
env_vars.cpp
exceptions.cpp

View File

@ -37,37 +37,6 @@
#include <wx/wx.h>
bool IsImperialUnit( EDA_UNITS aUnit )
{
switch( aUnit )
{
case EDA_UNITS::INCHES:
case EDA_UNITS::MILS:
return true;
default:
return false;
}
return false;
}
bool IsMetricUnit( EDA_UNITS aUnit )
{
switch( aUnit )
{
case EDA_UNITS::MILLIMETRES:
return true;
default:
return false;
}
return false;
}
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
{
wxCoord width;

View File

@ -24,6 +24,7 @@
#include <reporter.h>
#include <vector>
#include <wx/html/htmlwin.h>
#include <eda_units.h>
/**
* WX_HTML_REPORT_BOX

View File

@ -973,7 +973,7 @@ void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondary
aPrimaryUnit = GetUserUnits();
aSecondaryUnits = EDA_UNITS::MILS;
if( IsImperialUnit( aPrimaryUnit ) )
if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
{
if( cmnTool )
aSecondaryUnits = cmnTool->GetLastMetricUnits();

54
common/eda_units.cpp Normal file
View File

@ -0,0 +1,54 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* 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
*/
#include <eda_units.h>
bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit )
{
switch( aUnit )
{
case EDA_UNITS::INCHES:
case EDA_UNITS::MILS:
return true;
default:
return false;
}
return false;
}
bool EDA_UNIT_UTILS::IsMetricUnit( EDA_UNITS aUnit )
{
switch( aUnit )
{
case EDA_UNITS::MILLIMETRES:
return true;
default:
return false;
}
return false;
}

View File

@ -40,6 +40,7 @@
#include <thread>
#include <utility>
#include <wildcards_and_files_ext.h>
#include <wx/textfile.h>
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aLibNickname,

View File

@ -29,9 +29,11 @@
#include <set>
#include <common.h>
#include <kiface_i.h>
#include <lib_table_base.h>
#include <lib_table_lexer.h>
#include <macros.h>
#include <settings/app_settings.h>

View File

@ -24,6 +24,7 @@
*/
#include <netclass.h>
#include <macros.h>
#include <base_units.h>
// This will get mapped to "kicad_default" in the specctra_export.

View File

@ -46,6 +46,7 @@
#include <kiface_i.h>
#include <title_block.h>
#include <common.h>
#include <eda_item.h>
#include <page_layout/ws_data_item.h>
#include <page_layout/ws_data_model.h>

View File

@ -32,6 +32,7 @@
#include <eda_item.h>
#include <locale_io.h>
#include <macros.h>
#include <page_layout/ws_painter.h>
#include <page_layout/ws_draw_item.h>
#include <page_layout/ws_data_item.h>

View File

@ -28,6 +28,7 @@
#include <page_layout/ws_draw_item.h>
#include <page_layout/ws_data_item.h>
#include <page_layout/ws_painter.h>
#include <project.h>
#include <view/view.h>
using namespace KIGFX;

View File

@ -27,6 +27,7 @@
#include <fill_type.h>
#include <kicad_string.h>
#include <convert_basic_shapes_to_polygon.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
#include <render_settings.h>
#include <trigo.h>

View File

@ -32,6 +32,7 @@
#include <eda_item.h>
#include <wx/zstream.h>
#include <wx/mstream.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
#include <render_settings.h>

View File

@ -29,6 +29,7 @@
#include <eda_base_frame.h>
#include <convert_basic_shapes_to_polygon.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
#include <render_settings.h>
#include <trigo.h>

View File

@ -86,6 +86,7 @@ principle should be easily implemented by adapting the current STL containers.
#include <cstddef>
#include <eda_item.h>
#include <eda_rect.h>
#include <eda_units.h>
#include <common.h>
#include <richio.h>
#include <wx_python_helpers.h>
@ -116,6 +117,7 @@ principle should be easily implemented by adapting the current STL containers.
%include core/typeinfo.h
%include eda_item.h
%include eda_rect.h
%include eda_units.h
%include common.h
%include richio.h
%include title_block.h

View File

@ -24,6 +24,7 @@
#include <bitmaps.h>
#include <common.h>
#include <eda_units.h>
#include <frame_type.h>
#include <tool/actions.h>

View File

@ -72,9 +72,9 @@ void COMMON_TOOLS::Reset( RESET_REASON aReason )
void COMMON_TOOLS::SetLastUnits( EDA_UNITS aUnit )
{
if( IsImperialUnit( aUnit ) )
if( EDA_UNIT_UTILS::IsImperialUnit( aUnit ) )
m_imperialUnit = aUnit;
else if( IsMetricUnit( aUnit ) )
else if( EDA_UNIT_UTILS::IsMetricUnit( aUnit ) )
m_metricUnit = aUnit;
else
wxASSERT_MSG( false, "Invalid unit" );
@ -514,9 +514,9 @@ int COMMON_TOOLS::SwitchUnits( const TOOL_EVENT& aEvent )
{
EDA_UNITS newUnit = aEvent.Parameter<EDA_UNITS>();
if( IsMetricUnit( newUnit ) )
if( EDA_UNIT_UTILS::IsMetricUnit( newUnit ) )
m_metricUnit = newUnit;
else if( IsImperialUnit( newUnit ) )
else if( EDA_UNIT_UTILS::IsImperialUnit( newUnit ) )
m_imperialUnit = newUnit;
else
wxASSERT_MSG( false, "Invalid unit for the frame" );
@ -528,7 +528,7 @@ int COMMON_TOOLS::SwitchUnits( const TOOL_EVENT& aEvent )
int COMMON_TOOLS::ToggleUnits( const TOOL_EVENT& aEvent )
{
m_frame->ChangeUserUnits( IsImperialUnit( m_frame->GetUserUnits() ) ?
m_frame->ChangeUserUnits( EDA_UNIT_UTILS::IsImperialUnit( m_frame->GetUserUnits() ) ?
m_metricUnit :
m_imperialUnit );
return 0;

View File

@ -30,6 +30,7 @@
#include <kiway.h>
#include <kiway_player.h>
#include <dialog_shim.h>
#include <common.h>
#include <env_paths.h>
#include <widgets/grid_text_button_helpers.h>

View File

@ -30,6 +30,7 @@
#include <confirm.h>
#include <project.h>
#include <wx/textfile.h>
#include <wx/tokenzr.h>
#include <wx/wupdlock.h>

View File

@ -23,6 +23,7 @@
*/
#include <pgm_base.h>
#include <common.h>
#include <eda_item.h>
#include <gr_text.h>
#include <kicad_string.h>

View File

@ -25,6 +25,7 @@
* @file lib_text.cpp
*/
#include <common.h>
#include <sch_draw_panel.h>
#include <plotter.h>
#include <gr_text.h>

View File

@ -24,6 +24,7 @@
#include <pin_type.h>
#include <lib_pin.h>
#include <base_units.h>
#include <macros.h>
// These are true singletons so it's OK for them to be globals.

View File

@ -31,7 +31,9 @@
#include <settings/color_settings.h>
#include <bitmaps.h>
#include <base_units.h>
#include <common.h>
#include <eda_draw_frame.h>
#include <macros.h>
#include <sch_bitmap.h>
#include <trigo.h>

View File

@ -28,8 +28,10 @@
#include <sch_draw_panel.h>
#include <trigo.h>
#include <common.h>
#include <plotter.h>
#include <bitmaps.h>
#include <macros.h>
#include <sch_painter.h>
#include <sch_junction.h>

View File

@ -34,6 +34,7 @@
#include <sch_no_connect.h>
#include <settings/color_settings.h>
#include <default_values.h> // For some default values
#include <macros.h>
#include <trigo.h>

View File

@ -31,6 +31,7 @@
#include <layers_id_colors_and_visibility.h> // SCH_LAYER_ID
#include <plotter.h> // PLOT_DASH_TYPE
#include <sch_io_mgr.h>
#include <wx/filename.h>
class EDA_TEXT;
class LABEL_SPIN_STYLE;

View File

@ -24,6 +24,7 @@
*/
#include <convert_to_biu.h> // SCH_IU_PER_MM
#include <macros.h>
#include <sch_plugins/cadstar/cadstar_sch_archive_parser.h>

View File

@ -21,6 +21,7 @@
#include <gerbview.h>
#include <gerbview_frame.h>
#include <macros.h>
#include "panel_gerbview_settings.h"

View File

@ -69,6 +69,7 @@
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
#include <excellon_image.h>
#include <macros.h>
#include <kicad_string.h>
#include <locale_io.h>
#include <X2_gerber_attributes.h>

View File

@ -24,6 +24,7 @@
#include <trigo.h>
#include <bitmaps.h>
#include <common.h>
#include <msgpanel.h>
#include <gerbview_frame.h>
#include <convert_basic_shapes_to_polygon.h>

View File

@ -31,6 +31,7 @@
#include <gerbview.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>
#include <macros.h>
#include <X2_gerber_attributes.h>
#include <algorithm>
#include <map>

View File

@ -33,6 +33,7 @@
#include <gerbview.h>
#include <richio.h>
#include <locale_io.h>
#include <macros.h>
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
#include <gerbview_frame.h>

View File

@ -31,6 +31,7 @@
#include <gerbview.h>
#include <gerber_file_image.h>
#include <macros.h>
#include <X2_gerber_attributes.h>
#include <gbr_metadata.h>

View File

@ -34,7 +34,7 @@
#include <string>
#include <common.h>
#include <eda_units.h>
#include <convert_to_biu.h>
#include <math/util.h> // for KiROUND
#include <math/vector2d.h>

View File

@ -61,28 +61,6 @@ class REPORTER;
#define TEXT_ANGLE_HORIZ 0
#define TEXT_ANGLE_VERT 900
/**
* The type of unit.
*/
enum class EDA_DATA_TYPE
{
DISTANCE = 0,
AREA = 1,
VOLUME = 2
};
enum class EDA_UNITS
{
INCHES = 0,
MILLIMETRES = 1,
UNSCALED = 2,
DEGREES = 3,
PERCENT = 4,
MILS = 5,
};
bool IsImperialUnit( EDA_UNITS aUnit );
bool IsMetricUnit( EDA_UNITS aUnit );
/**
* Return the size of @a aSingleLine of text when it is rendered in @a aWindow

View File

@ -48,6 +48,7 @@
#include <tool/tools_holder.h>
#include <widgets/ui_common.h>
#include <undo_redo_container.h>
#include <eda_units.h>
// Option for main frames
#define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
@ -74,6 +75,7 @@ class DIALOG_EDIT_LIBRARY_TABLES;
class PANEL_HOTKEYS_EDITOR;
class FILE_HISTORY;
class SETTINGS_MANAGER;
class SEARCH_STACK;
class APP_SETTINGS_BASE;
class WX_INFOBAR;
struct WINDOW_SETTINGS;

55
include/eda_units.h Normal file
View File

@ -0,0 +1,55 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* 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
*/
#ifndef EDA_UNITS_H
#define EDA_UNITS_H
/**
* The type of unit.
*/
enum class EDA_DATA_TYPE
{
DISTANCE = 0,
AREA = 1,
VOLUME = 2
};
enum class EDA_UNITS
{
INCHES = 0,
MILLIMETRES = 1,
UNSCALED = 2,
DEGREES = 3,
PERCENT = 4,
MILS = 5,
};
namespace EDA_UNIT_UTILS
{
bool IsImperialUnit( EDA_UNITS aUnit );
bool IsMetricUnit( EDA_UNITS aUnit );
}
#endif

View File

@ -47,6 +47,7 @@ class FOOTPRINT_ASYNC_LOADER;
class PROGRESS_REPORTER;
class wxTopLevelWindow;
class KIWAY;
class wxTextFile;
/*

View File

@ -28,6 +28,7 @@
#include <stack>
#include <base_units.h>
#include <wx/intl.h>
#if defined(WIN32)
// This gets leaked by python headers on MSVC only and will cause chaos

View File

@ -31,6 +31,7 @@
#include <bitmap_base.h>
#include "msgpanel.h"
#include <geometry/shape_poly_set.h>
#include <eda_units.h>
#include <algorithm>
#include <vector>
@ -40,6 +41,7 @@ class TITLE_BLOCK;
class PAGE_INFO;
class EDA_ITEM;
class EDA_DRAW_FRAME;
class PROJECT;
/**
* Helper classes to handle basic graphic items used to draw/plot

View File

@ -30,6 +30,7 @@
class BOARD;
class PAGE_INFO;
class PROJECT;
class TITLE_BLOCK;
class WS_DRAW_ITEM_LINE;
class WS_DRAW_ITEM_RECT;

View File

@ -45,6 +45,7 @@ class COLOR_SETTINGS;
class SHAPE_POLY_SET;
class SHAPE_LINE_CHAIN;
class GBR_NETLIST_METADATA;
class PROJECT;
using KIGFX::RENDER_SETTINGS;

View File

@ -24,7 +24,7 @@
#ifndef PREVIEW_PREVIEW_UTILS__H_
#define PREVIEW_PREVIEW_UTILS__H_
#include <common.h>
#include <eda_units.h>
#include <gal/color4d.h>
#include <math/vector2d.h>

View File

@ -29,7 +29,7 @@
#include <set>
#include <vector>
#include <memory>
#include <common.h>
#include <eda_units.h>
class PROPERTY_BASE;
class TYPE_CAST_BASE;

View File

@ -25,8 +25,8 @@
#ifndef _REPORTER_H_
#define _REPORTER_H_
#include <eda_units.h>
#include <wx/string.h>
#include <common.h>
#include <widgets/ui_common.h>
/**

View File

@ -31,6 +31,7 @@
#include <tools/kicad_manager_control.h>
#include <dialogs/dialog_template_selector.h>
#include <gestfich.h>
#include <wx/dir.h>
///> Helper widget to select whether a new directory should be created for a project
class DIR_CHECKBOX : public wxPanel

View File

@ -36,7 +36,9 @@
#include <wx/string.h>
#include <bitmaps.h>
#include <common.h>
#include <gestfich.h>
#include <macros.h>
#include <menus_helpers.h>
#include <trace_helpers.h>
#include <wildcards_and_files_ext.h>

View File

@ -30,6 +30,7 @@
#include <grid_tricks.h>
#include <widgets/wx_grid.h>
#include <bitmaps.h>
#include <macros.h>
#define INITIAL_HELP \

View File

@ -43,6 +43,7 @@ class NETLIST;
class NETINFO_ITEM;
class PROGRESS_REPORTER;
class REPORTER;
class wxFileName;
namespace KIGFX
{

View File

@ -30,6 +30,7 @@
#include <layers_id_colors_and_visibility.h>
#include <netclass.h>
#include <libeval_compiler/libeval_compiler.h>
#include <wx/intl.h>
class BOARD_ITEM;
class PCB_EXPR_UCODE;

View File

@ -25,6 +25,7 @@
#include <cadstar_pcb_archive_parser.h>
#include <convert_to_biu.h> // PCB_IU_PER_MM
#include <macros.h>
void CADSTAR_PCB_ARCHIVE_PARSER::Parse()

View File

@ -627,7 +627,7 @@ void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool a
EDA_UNITS primaryUnit = GetUserUnits();
EDA_UNITS secondaryUnit = EDA_UNITS::MILS;
if( IsImperialUnit( primaryUnit ) )
if( EDA_UNIT_UTILS::IsImperialUnit( primaryUnit ) )
{
if( cmnTool )
secondaryUnit = cmnTool->GetLastMetricUnits();