2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
2020-09-16 18:26:34 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-01-14 19:50:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <base_units.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <dimension.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2020-09-12 20:09:40 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-10-16 15:51:24 +00:00
|
|
|
#include <i18n_utility.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE::DIMENSION_BASE( BOARD_ITEM* aParent, KICAD_T aType ) :
|
2020-09-12 20:09:40 +00:00
|
|
|
BOARD_ITEM( aParent, aType ),
|
2020-09-11 23:52:45 +00:00
|
|
|
m_overrideTextEnabled( false ),
|
|
|
|
m_units( EDA_UNITS::INCHES ),
|
|
|
|
m_autoUnits( false ),
|
|
|
|
m_unitsFormat( DIM_UNITS_FORMAT::BARE_SUFFIX ),
|
|
|
|
m_precision( 4 ),
|
|
|
|
m_suppressZeroes( false ),
|
|
|
|
m_lineThickness( Millimeter2iu( 0.2 ) ),
|
|
|
|
m_arrowLength( Mils2iu( 50 ) ),
|
|
|
|
m_extensionOffset( 0 ),
|
|
|
|
m_textPosition( DIM_TEXT_POSITION::OUTSIDE ),
|
|
|
|
m_keepTextAligned( true ),
|
2020-09-12 14:23:07 +00:00
|
|
|
m_text( aParent ),
|
2020-09-11 23:52:45 +00:00
|
|
|
m_measuredValue( 0 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = Dwgs_User;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetParent( EDA_ITEM* aParent )
|
2020-09-12 14:23:07 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM::SetParent( aParent );
|
|
|
|
m_text.SetParent( aParent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::updateText()
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
|
|
|
wxString text = m_overrideTextEnabled ? m_valueString : GetValueText();
|
|
|
|
|
|
|
|
switch( m_unitsFormat )
|
|
|
|
{
|
|
|
|
case DIM_UNITS_FORMAT::NO_SUFFIX: // no units
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIM_UNITS_FORMAT::BARE_SUFFIX: // normal
|
|
|
|
text += " ";
|
2020-10-02 20:51:24 +00:00
|
|
|
text += GetAbbreviatedUnitsLabel( m_units );
|
2020-09-11 23:52:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIM_UNITS_FORMAT::PAREN_SUFFIX: // parenthetical
|
|
|
|
text += " (";
|
2020-10-02 20:51:24 +00:00
|
|
|
text += GetAbbreviatedUnitsLabel( m_units );
|
2020-09-11 23:52:45 +00:00
|
|
|
text += ")";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
text.Prepend( m_prefix );
|
|
|
|
text.Append( m_suffix );
|
|
|
|
|
|
|
|
m_text.SetText( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
template<typename ShapeType>
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::addShape( const ShapeType& aShape )
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
2020-10-01 19:11:35 +00:00
|
|
|
m_shapes.push_back( std::make_shared<ShapeType>( aShape ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
wxString DIMENSION_BASE::GetValueText() const
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
2020-09-30 22:26:37 +00:00
|
|
|
struct lconv* lc = localeconv();
|
|
|
|
wxChar sep = lc->decimal_point[0];
|
2020-09-11 23:52:45 +00:00
|
|
|
|
2020-09-30 22:26:37 +00:00
|
|
|
int val = GetMeasuredValue();
|
2020-09-11 23:52:45 +00:00
|
|
|
wxString text;
|
|
|
|
wxString format = wxT( "%." ) + wxString::Format( "%i", m_precision ) + wxT( "f" );
|
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
text.Printf( format, To_User_Unit( m_units, val ) );
|
2020-09-11 23:52:45 +00:00
|
|
|
|
|
|
|
if( m_suppressZeroes )
|
|
|
|
{
|
|
|
|
while( text.Last() == '0' )
|
|
|
|
{
|
|
|
|
text.RemoveLast();
|
|
|
|
|
2020-09-30 22:26:37 +00:00
|
|
|
if( text.Last() == '.' || text.Last() == sep )
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
|
|
|
text.RemoveLast();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetPrefix( const wxString& aPrefix )
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
|
|
|
m_prefix = aPrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetSuffix( const wxString& aSuffix )
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
|
|
|
m_suffix = aSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetUnits( EDA_UNITS aUnits )
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
|
|
|
m_units = aUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
DIM_UNITS_MODE DIMENSION_BASE::GetUnitsMode() const
|
2012-12-19 19:31:36 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
if( m_autoUnits )
|
2020-10-02 20:51:24 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
return DIM_UNITS_MODE::AUTOMATIC;
|
2020-10-02 20:51:24 +00:00
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
else
|
2020-10-02 20:51:24 +00:00
|
|
|
{
|
|
|
|
switch( m_units )
|
|
|
|
{
|
|
|
|
case EDA_UNITS::MILLIMETRES:
|
|
|
|
return DIM_UNITS_MODE::MILLIMETRES;
|
|
|
|
|
|
|
|
case EDA_UNITS::MILS:
|
|
|
|
return DIM_UNITS_MODE::MILS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case EDA_UNITS::INCHES:
|
|
|
|
return DIM_UNITS_MODE::INCHES;
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetUnitsMode( DIM_UNITS_MODE aMode )
|
2020-09-09 03:17:08 +00:00
|
|
|
{
|
|
|
|
m_autoUnits = false;
|
|
|
|
|
|
|
|
switch( aMode )
|
|
|
|
{
|
|
|
|
case DIM_UNITS_MODE::INCHES:
|
2020-09-11 23:52:45 +00:00
|
|
|
m_units = EDA_UNITS::INCHES;
|
2020-09-09 03:17:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIM_UNITS_MODE::MILS:
|
2020-10-02 22:04:16 +00:00
|
|
|
m_units = EDA_UNITS::MILS;
|
2020-09-09 03:17:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIM_UNITS_MODE::MILLIMETRES:
|
|
|
|
m_units = EDA_UNITS::MILLIMETRES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIM_UNITS_MODE::AUTOMATIC:
|
|
|
|
m_autoUnits = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetText( const wxString& aNewText )
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
2020-09-11 23:52:45 +00:00
|
|
|
m_valueString = aNewText;
|
|
|
|
updateText();
|
2007-09-25 08:23:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const wxString DIMENSION_BASE::GetText() const
|
2011-11-30 21:15:56 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
return m_text.GetText();
|
2011-11-30 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::SetLayer( PCB_LAYER_ID aLayer )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2020-11-14 14:29:11 +00:00
|
|
|
m_layer = aLayer;
|
2020-09-09 03:17:08 +00:00
|
|
|
m_text.SetLayer( aLayer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::Move( const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
m_text.Offset( offset );
|
|
|
|
|
|
|
|
m_start += offset;
|
|
|
|
m_end += offset;
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
Update();
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::Rotate( const wxPoint& aRotCentre, double aAngle )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2020-09-12 00:45:36 +00:00
|
|
|
if( m_keepTextAligned )
|
|
|
|
m_keepTextAligned = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
double newAngle = m_text.GetTextAngle() + aAngle;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
if( newAngle >= 3600 )
|
|
|
|
newAngle -= 3600;
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
m_text.SetTextAngle( newAngle );
|
|
|
|
|
2020-11-21 23:52:36 +00:00
|
|
|
wxPoint pt = m_text.GetTextPos();
|
|
|
|
RotatePoint( &pt, aRotCentre, aAngle );
|
|
|
|
m_text.SetTextPos( pt );
|
|
|
|
|
|
|
|
RotatePoint( &m_start, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_end, aRotCentre, aAngle );
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
Update();
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
Mirror( aCentre );
|
2015-12-27 15:51:13 +00:00
|
|
|
|
2021-02-20 12:16:45 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2019-07-12 21:02:10 +00:00
|
|
|
int axis = aMirrorLeftRight ? axis_pos.x : axis_pos.y;
|
2020-09-09 03:17:08 +00:00
|
|
|
wxPoint newPos = m_text.GetTextPos();
|
2013-03-18 19:36:07 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
#define INVERT( pos ) ( ( pos ) = axis - ( ( pos ) - axis ) )
|
2019-07-12 21:02:10 +00:00
|
|
|
if( aMirrorLeftRight )
|
|
|
|
INVERT( newPos.x );
|
|
|
|
else
|
|
|
|
INVERT( newPos.y );
|
2013-03-18 19:36:07 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
m_text.SetTextPos( newPos );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
// invert angle
|
2020-09-09 03:17:08 +00:00
|
|
|
m_text.SetTextAngle( -m_text.GetTextAngle() );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2019-07-12 21:02:10 +00:00
|
|
|
if( aMirrorLeftRight )
|
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
INVERT( m_start.x );
|
|
|
|
INVERT( m_end.x );
|
2019-07-12 21:02:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
INVERT( m_start.y );
|
|
|
|
INVERT( m_end.y );
|
2019-07-12 21:02:10 +00:00
|
|
|
}
|
2014-02-11 12:22:30 +00:00
|
|
|
|
2020-11-03 22:45:26 +00:00
|
|
|
m_text.SetMirrored( !m_text.IsMirrored() );
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
Update();
|
2014-02-11 12:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
// for now, display only the text within the DIMENSION using class PCB_TEXT.
|
2020-09-24 21:23:16 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
wxCHECK_RET( m_parent != NULL, wxT( "PCB_TEXT::GetMsgPanelInfo() m_Parent is NULL." ) );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Dimension" ), m_text.GetShownText() );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Prefix" ), GetPrefix() );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
|
|
|
if( GetOverrideTextEnabled() )
|
|
|
|
{
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Override Text" ), GetOverrideText() );
|
2020-09-24 21:23:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Value" ), GetValueText() );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
|
|
|
msg = "%" + wxString::Format( "1.%df", GetPrecision() );
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Precision" ), wxString::Format( msg, 0.0 ) );
|
2020-09-24 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Suffix" ), GetSuffix() );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
|
|
|
EDA_UNITS units;
|
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
GetUnits( units );
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Units" ), GetAbbreviatedUnitsLabel( units ) );
|
2020-09-24 23:40:35 +00:00
|
|
|
|
|
|
|
ORIGIN_TRANSFORMS originTransforms = aFrame->GetOriginTransforms();
|
|
|
|
units = aFrame->GetUserUnits();
|
|
|
|
|
|
|
|
if( Type() == PCB_DIM_CENTER_T )
|
|
|
|
{
|
|
|
|
wxPoint startCoord = originTransforms.ToDisplayAbs( GetStart() );
|
|
|
|
wxString start = wxString::Format( "@(%s, %s)",
|
|
|
|
MessageTextFromValue( units, startCoord.x ),
|
|
|
|
MessageTextFromValue( units, startCoord.y ) );
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( start, wxEmptyString );
|
2020-09-24 23:40:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint startCoord = originTransforms.ToDisplayAbs( GetStart() );
|
|
|
|
wxString start = wxString::Format( "@(%s, %s)",
|
|
|
|
MessageTextFromValue( units, startCoord.x ),
|
|
|
|
MessageTextFromValue( units, startCoord.y ) );
|
|
|
|
wxPoint endCoord = originTransforms.ToDisplayAbs( GetEnd() );
|
|
|
|
wxString end = wxString::Format( "@(%s, %s)",
|
|
|
|
MessageTextFromValue( units, endCoord.x ),
|
|
|
|
MessageTextFromValue( units, endCoord.y ) );
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( start, end );
|
2020-09-24 23:40:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName() );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
std::shared_ptr<SHAPE> DIMENSION_BASE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
|
2020-09-19 11:47:43 +00:00
|
|
|
{
|
2020-10-31 21:00:40 +00:00
|
|
|
std::shared_ptr<SHAPE_COMPOUND> effectiveShape = std::make_shared<SHAPE_COMPOUND>();
|
2020-10-31 19:13:30 +00:00
|
|
|
|
2020-10-31 21:00:40 +00:00
|
|
|
effectiveShape->AddShape( Text().GetEffectiveTextShape()->Clone() );
|
2020-09-19 11:47:43 +00:00
|
|
|
|
|
|
|
for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
|
2020-10-31 21:00:40 +00:00
|
|
|
effectiveShape->AddShape( shape->Clone() );
|
2020-09-19 11:47:43 +00:00
|
|
|
|
2020-10-31 21:00:40 +00:00
|
|
|
return effectiveShape;
|
2020-09-19 11:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool DIMENSION_BASE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
if( m_text.TextHitTest( aPosition ) )
|
2011-09-20 15:07:52 +00:00
|
|
|
return true;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
int dist_max = aAccuracy + ( m_lineThickness / 2 );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2012-12-27 16:42:41 +00:00
|
|
|
// Locate SEGMENTS
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
|
2020-09-09 03:17:08 +00:00
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
if( shape->Collide( aPosition, dist_max ) )
|
2020-09-09 03:17:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-08-08 20:51:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool DIMENSION_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2013-09-21 18:09:41 +00:00
|
|
|
EDA_RECT arect = aRect;
|
|
|
|
arect.Inflate( aAccuracy );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
2020-09-17 00:54:58 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
if( aAccuracy )
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return arect.Contains( rect );
|
|
|
|
|
|
|
|
return arect.Intersects( rect );
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2011-02-25 16:23:24 +00:00
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const EDA_RECT DIMENSION_BASE::GetBoundingBox() const
|
2011-02-25 16:23:24 +00:00
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
EDA_RECT bBox;
|
|
|
|
int xmin, xmax, ymin, ymax;
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
bBox = m_text.GetTextBox();
|
2012-12-19 19:31:36 +00:00
|
|
|
xmin = bBox.GetX();
|
|
|
|
xmax = bBox.GetRight();
|
|
|
|
ymin = bBox.GetY();
|
|
|
|
ymax = bBox.GetBottom();
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
for( const std::shared_ptr<SHAPE>& shape : GetShapes() )
|
2020-09-09 03:17:08 +00:00
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
BOX2I shapeBox = shape->BBox();
|
2020-09-17 00:54:58 +00:00
|
|
|
shapeBox.Inflate( m_lineThickness / 2 );
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
xmin = std::min( xmin, shapeBox.GetOrigin().x );
|
|
|
|
xmax = std::max( xmax, shapeBox.GetEnd().x );
|
|
|
|
ymin = std::min( ymin, shapeBox.GetOrigin().y );
|
|
|
|
ymax = std::max( ymax, shapeBox.GetEnd().y );
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
2013-09-16 12:44:03 +00:00
|
|
|
|
2011-02-25 16:23:24 +00:00
|
|
|
bBox.SetX( xmin );
|
|
|
|
bBox.SetY( ymin );
|
|
|
|
bBox.SetWidth( xmax - xmin + 1 );
|
|
|
|
bBox.SetHeight( ymax - ymin + 1 );
|
|
|
|
|
|
|
|
bBox.Normalize();
|
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
wxString DIMENSION_BASE::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2020-09-19 18:53:58 +00:00
|
|
|
return wxString::Format( _( "Dimension '%s' on %s" ),
|
2020-09-19 16:12:00 +00:00
|
|
|
GetText(),
|
|
|
|
GetLayerName() );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const BOX2I DIMENSION_BASE::ViewBBox() const
|
2013-09-16 12:44:03 +00:00
|
|
|
{
|
|
|
|
BOX2I dimBBox = BOX2I( VECTOR2I( GetBoundingBox().GetPosition() ),
|
|
|
|
VECTOR2I( GetBoundingBox().GetSize() ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
dimBBox.Merge( m_text.ViewBBox() );
|
2013-09-16 12:44:03 +00:00
|
|
|
|
|
|
|
return dimBBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
OPT_VECTOR2I DIMENSION_BASE::segPolyIntersection( const SHAPE_POLY_SET& aPoly, const SEG& aSeg, bool aStart )
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
|
|
|
VECTOR2I start( aStart ? aSeg.A : aSeg.B );
|
|
|
|
VECTOR2I endpoint( aStart ? aSeg.B : aSeg.A );
|
|
|
|
|
|
|
|
if( aPoly.Contains( start ) )
|
|
|
|
return NULLOPT;
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( SHAPE_POLY_SET::CONST_SEGMENT_ITERATOR seg = aPoly.CIterateSegments(); seg; ++seg )
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
|
|
|
if( OPT_VECTOR2I intersection = ( *seg ).Intersect( aSeg ) )
|
|
|
|
{
|
|
|
|
if( ( *intersection - start ).SquaredEuclideanNorm() <
|
|
|
|
( endpoint - start ).SquaredEuclideanNorm() )
|
|
|
|
endpoint = *intersection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( start == endpoint )
|
|
|
|
return NULLOPT;
|
|
|
|
|
|
|
|
return OPT_VECTOR2I( endpoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-05 23:10:18 +00:00
|
|
|
OPT_VECTOR2I DIMENSION_BASE::segCircleIntersection( CIRCLE& aCircle, SEG& aSeg, bool aStart )
|
|
|
|
{
|
|
|
|
VECTOR2I start( aStart ? aSeg.A : aSeg.B );
|
|
|
|
VECTOR2I endpoint( aStart ? aSeg.B : aSeg.A );
|
|
|
|
|
|
|
|
if( aCircle.Contains( start ) )
|
|
|
|
return NULLOPT;
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> intersections = aCircle.Intersect( aSeg );
|
|
|
|
|
|
|
|
for( VECTOR2I& intersection : aCircle.Intersect( aSeg ) )
|
|
|
|
{
|
|
|
|
if( ( intersection - start ).SquaredEuclideanNorm() <
|
|
|
|
( endpoint - start ).SquaredEuclideanNorm() )
|
|
|
|
endpoint = intersection;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( start == endpoint )
|
|
|
|
return NULLOPT;
|
|
|
|
|
|
|
|
return OPT_VECTOR2I( endpoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
ALIGNED_DIMENSION::ALIGNED_DIMENSION( BOARD_ITEM* aParent, KICAD_T aType ) :
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE( aParent, aType ),
|
2020-09-09 03:17:08 +00:00
|
|
|
m_height( 0 )
|
|
|
|
{
|
|
|
|
// To preserve look of old dimensions, initialize extension height based on default arrow length
|
2020-09-11 23:52:45 +00:00
|
|
|
m_extensionHeight = static_cast<int>( m_arrowLength * std::sin( DEG2RAD( s_arrowAngle ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* ALIGNED_DIMENSION::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
return new ALIGNED_DIMENSION( *this );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
void ALIGNED_DIMENSION::SwapData( BOARD_ITEM* aImage )
|
2017-10-31 13:59:03 +00:00
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
assert( aImage->Type() == PCB_DIM_ALIGNED_T );
|
|
|
|
|
|
|
|
m_shapes.clear();
|
|
|
|
static_cast<ALIGNED_DIMENSION*>( aImage )->m_shapes.clear();
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
std::swap( *static_cast<ALIGNED_DIMENSION*>( this ),
|
|
|
|
*static_cast<ALIGNED_DIMENSION*>( aImage ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAP_DEF ALIGNED_DIMENSION::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_aligned_dimension_xpm;
|
2017-10-31 13:59:03 +00:00
|
|
|
}
|
2020-02-02 18:40:14 +00:00
|
|
|
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
void ALIGNED_DIMENSION::UpdateHeight( const wxPoint& aCrossbarStart, const wxPoint& aCrossbarEnd )
|
|
|
|
{
|
|
|
|
VECTOR2D height( aCrossbarStart - GetStart() );
|
|
|
|
VECTOR2D crossBar( aCrossbarEnd - aCrossbarStart );
|
|
|
|
|
|
|
|
if( height.Cross( crossBar ) > 0 )
|
|
|
|
m_height = -height.EuclideanNorm();
|
|
|
|
else
|
|
|
|
m_height = height.EuclideanNorm();
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
Update();
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALIGNED_DIMENSION::updateGeometry()
|
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
m_shapes.clear();
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
VECTOR2I dimension( m_end - m_start );
|
|
|
|
|
|
|
|
m_measuredValue = KiROUND( dimension.EuclideanNorm() );
|
|
|
|
|
|
|
|
VECTOR2I extension;
|
|
|
|
|
|
|
|
if( m_height > 0 )
|
|
|
|
extension = VECTOR2I( -dimension.y, dimension.x );
|
|
|
|
else
|
|
|
|
extension = VECTOR2I( dimension.y, -dimension.x );
|
|
|
|
|
|
|
|
// Add extension lines
|
|
|
|
int extensionHeight = std::abs( m_height ) - m_extensionOffset + m_extensionHeight;
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
VECTOR2I extStart( m_start );
|
|
|
|
extStart += extension.Resize( m_extensionOffset );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-10-01 19:11:35 +00:00
|
|
|
addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
extStart = VECTOR2I( m_end );
|
|
|
|
extStart += extension.Resize( m_extensionOffset );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-10-01 19:11:35 +00:00
|
|
|
addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
// Add crossbar
|
|
|
|
VECTOR2I crossBarDistance = sign( m_height ) * extension.Resize( m_height );
|
|
|
|
m_crossBarStart = m_start + wxPoint( crossBarDistance );
|
|
|
|
m_crossBarEnd = m_end + wxPoint( crossBarDistance );
|
|
|
|
|
|
|
|
// Update text after calculating crossbar position but before adding crossbar lines
|
|
|
|
updateText();
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
// Now that we have the text updated, we can determine how to draw the crossbar.
|
|
|
|
// First we need to create an appropriate bounding polygon to collide with
|
|
|
|
EDA_RECT textBox = m_text.GetTextBox().Inflate( m_text.GetTextWidth() / 2,
|
|
|
|
m_text.GetEffectiveTextPenWidth() );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET polyBox;
|
|
|
|
polyBox.NewOutline();
|
|
|
|
polyBox.Append( textBox.GetOrigin() );
|
|
|
|
polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
|
|
|
|
polyBox.Append( textBox.GetEnd() );
|
|
|
|
polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
|
|
|
|
polyBox.Rotate( -m_text.GetTextAngleRadians(), textBox.GetCenter() );
|
|
|
|
|
|
|
|
// The ideal crossbar, if the text doesn't collide
|
|
|
|
SEG crossbar( m_crossBarStart, m_crossBarEnd );
|
|
|
|
|
|
|
|
// Now we can draw 0, 1, or 2 crossbar lines depending on how the polygon collides
|
|
|
|
bool containsA = polyBox.Contains( crossbar.A );
|
|
|
|
bool containsB = polyBox.Contains( crossbar.B );
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
OPT_VECTOR2I endpointA = segPolyIntersection( polyBox, crossbar );
|
|
|
|
OPT_VECTOR2I endpointB = segPolyIntersection( polyBox, crossbar, false );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
if( endpointA )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( crossbar.A, *endpointA ) );
|
2020-09-11 23:52:45 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
if( endpointB )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( *endpointB, crossbar.B ) );
|
|
|
|
|
|
|
|
if( !containsA && !containsB && !endpointA && !endpointB )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( crossbar ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
// Add arrows
|
|
|
|
VECTOR2I arrowEnd( m_arrowLength, 0 );
|
|
|
|
|
|
|
|
double arrowRotPos = dimension.Angle() + DEG2RAD( s_arrowAngle );
|
|
|
|
double arrowRotNeg = dimension.Angle() - DEG2RAD( s_arrowAngle );
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarStart,
|
|
|
|
m_crossBarStart + wxPoint( arrowEnd.Rotate( arrowRotPos ) ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarStart,
|
|
|
|
m_crossBarStart + wxPoint( arrowEnd.Rotate( arrowRotNeg ) ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarEnd,
|
|
|
|
m_crossBarEnd - wxPoint( arrowEnd.Rotate( arrowRotPos ) ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarEnd,
|
|
|
|
m_crossBarEnd - wxPoint( arrowEnd.Rotate( arrowRotNeg ) ) ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ALIGNED_DIMENSION::updateText()
|
|
|
|
{
|
|
|
|
VECTOR2I crossbarCenter( ( m_crossBarEnd - m_crossBarStart ) / 2 );
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
if( m_textPosition == DIM_TEXT_POSITION::OUTSIDE )
|
2020-09-09 03:17:08 +00:00
|
|
|
{
|
|
|
|
int textOffsetDistance = m_text.GetEffectiveTextPenWidth() + m_text.GetTextHeight();
|
|
|
|
|
|
|
|
double rotation = std::copysign( DEG2RAD( 90 ), m_height );
|
|
|
|
VECTOR2I textOffset = crossbarCenter.Rotate( rotation ).Resize( textOffsetDistance );
|
|
|
|
textOffset += crossbarCenter;
|
|
|
|
|
|
|
|
m_text.SetTextPos( m_crossBarStart + wxPoint( textOffset ) );
|
|
|
|
}
|
2020-09-11 23:52:45 +00:00
|
|
|
else if( m_textPosition == DIM_TEXT_POSITION::INLINE )
|
|
|
|
{
|
|
|
|
m_text.SetTextPos( m_crossBarStart + wxPoint( crossbarCenter ) );
|
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
if( m_keepTextAligned )
|
2020-09-22 02:32:40 +00:00
|
|
|
{
|
|
|
|
double textAngle = 3600 - RAD2DECIDEG( crossbarCenter.Angle() );
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS( textAngle );
|
|
|
|
|
|
|
|
if( textAngle > 900 && textAngle < 2700 )
|
|
|
|
textAngle -= 1800;
|
|
|
|
|
|
|
|
m_text.SetTextAngle( textAngle );
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE::updateText();
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-19 16:08:37 +00:00
|
|
|
void ALIGNED_DIMENSION::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
DIMENSION_BASE::GetMsgPanelInfo( aFrame, aList );
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Height" ), MessageTextFromValue( aFrame->GetUserUnits(), m_height ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
ORTHOGONAL_DIMENSION::ORTHOGONAL_DIMENSION( BOARD_ITEM* aParent ) :
|
|
|
|
ALIGNED_DIMENSION( aParent, PCB_DIM_ORTHOGONAL_T )
|
|
|
|
{
|
|
|
|
// To preserve look of old dimensions, initialize extension height based on default arrow length
|
|
|
|
m_extensionHeight = static_cast<int>( m_arrowLength * std::sin( DEG2RAD( s_arrowAngle ) ) );
|
2020-10-03 10:47:41 +00:00
|
|
|
m_orientation = DIR::HORIZONTAL;
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* ORTHOGONAL_DIMENSION::Clone() const
|
|
|
|
{
|
|
|
|
return new ORTHOGONAL_DIMENSION( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ORTHOGONAL_DIMENSION::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_DIM_ORTHOGONAL_T );
|
|
|
|
|
|
|
|
m_shapes.clear();
|
|
|
|
static_cast<ORTHOGONAL_DIMENSION*>( aImage )->m_shapes.clear();
|
|
|
|
|
|
|
|
std::swap( *static_cast<ORTHOGONAL_DIMENSION*>( this ),
|
|
|
|
*static_cast<ORTHOGONAL_DIMENSION*>( aImage ) );
|
|
|
|
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAP_DEF ORTHOGONAL_DIMENSION::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_orthogonal_dimension_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ORTHOGONAL_DIMENSION::updateGeometry()
|
|
|
|
{
|
|
|
|
m_shapes.clear();
|
|
|
|
|
|
|
|
int measurement = ( m_orientation == DIR::HORIZONTAL ? m_end.x - m_start.x :
|
|
|
|
m_end.y - m_start.y );
|
|
|
|
m_measuredValue = KiROUND( std::abs( measurement ) );
|
|
|
|
|
|
|
|
VECTOR2I extension;
|
|
|
|
|
|
|
|
if( m_orientation == DIR::HORIZONTAL )
|
|
|
|
extension = VECTOR2I( 0, m_height );
|
|
|
|
else
|
|
|
|
extension = VECTOR2I( m_height, 0 );
|
|
|
|
|
|
|
|
// Add first extension line
|
|
|
|
int extensionHeight = std::abs( m_height ) - m_extensionOffset + m_extensionHeight;
|
|
|
|
|
|
|
|
VECTOR2I extStart( m_start );
|
|
|
|
extStart += extension.Resize( m_extensionOffset );
|
|
|
|
|
2020-10-01 19:11:35 +00:00
|
|
|
addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
|
2020-09-22 02:32:40 +00:00
|
|
|
|
|
|
|
// Add crossbar
|
|
|
|
VECTOR2I crossBarDistance = sign( m_height ) * extension.Resize( m_height );
|
|
|
|
m_crossBarStart = m_start + wxPoint( crossBarDistance );
|
|
|
|
|
|
|
|
if( m_orientation == DIR::HORIZONTAL )
|
|
|
|
m_crossBarEnd = wxPoint( m_end.x, m_crossBarStart.y );
|
|
|
|
else
|
|
|
|
m_crossBarEnd = wxPoint( m_crossBarStart.x, m_end.y );
|
|
|
|
|
|
|
|
// Add second extension line (m_end to crossbar end)
|
|
|
|
if( m_orientation == DIR::HORIZONTAL )
|
|
|
|
extension = VECTOR2I( 0, m_end.y - m_crossBarEnd.y );
|
|
|
|
else
|
|
|
|
extension = VECTOR2I( m_end.x - m_crossBarEnd.x, 0 );
|
|
|
|
|
|
|
|
extensionHeight = extension.EuclideanNorm() - m_extensionOffset + m_extensionHeight;
|
|
|
|
|
|
|
|
extStart = VECTOR2I( m_crossBarEnd );
|
|
|
|
extStart -= extension.Resize( m_extensionHeight );
|
|
|
|
|
2020-10-01 19:11:35 +00:00
|
|
|
addShape( SHAPE_SEGMENT( extStart, extStart + extension.Resize( extensionHeight ) ) );
|
2020-09-22 02:32:40 +00:00
|
|
|
|
|
|
|
// Update text after calculating crossbar position but before adding crossbar lines
|
|
|
|
updateText();
|
|
|
|
|
|
|
|
// Now that we have the text updated, we can determine how to draw the crossbar.
|
|
|
|
// First we need to create an appropriate bounding polygon to collide with
|
|
|
|
EDA_RECT textBox = m_text.GetTextBox().Inflate( m_text.GetTextWidth() / 2,
|
|
|
|
m_text.GetEffectiveTextPenWidth() );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET polyBox;
|
|
|
|
polyBox.NewOutline();
|
|
|
|
polyBox.Append( textBox.GetOrigin() );
|
|
|
|
polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
|
|
|
|
polyBox.Append( textBox.GetEnd() );
|
|
|
|
polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
|
|
|
|
polyBox.Rotate( -m_text.GetTextAngleRadians(), textBox.GetCenter() );
|
|
|
|
|
|
|
|
// The ideal crossbar, if the text doesn't collide
|
|
|
|
SEG crossbar( m_crossBarStart, m_crossBarEnd );
|
|
|
|
|
|
|
|
// Now we can draw 0, 1, or 2 crossbar lines depending on how the polygon collides
|
|
|
|
bool containsA = polyBox.Contains( crossbar.A );
|
|
|
|
bool containsB = polyBox.Contains( crossbar.B );
|
|
|
|
|
|
|
|
OPT_VECTOR2I endpointA = segPolyIntersection( polyBox, crossbar );
|
|
|
|
OPT_VECTOR2I endpointB = segPolyIntersection( polyBox, crossbar, false );
|
|
|
|
|
|
|
|
if( endpointA )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( crossbar.A, *endpointA ) );
|
|
|
|
|
|
|
|
if( endpointB )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( *endpointB, crossbar.B ) );
|
|
|
|
|
|
|
|
if( !containsA && !containsB && !endpointA && !endpointB )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( crossbar ) );
|
|
|
|
|
|
|
|
// Add arrows
|
|
|
|
VECTOR2I crossBarAngle( m_crossBarEnd - m_crossBarStart );
|
|
|
|
VECTOR2I arrowEnd( m_arrowLength, 0 );
|
|
|
|
|
|
|
|
double arrowRotPos = crossBarAngle.Angle() + DEG2RAD( s_arrowAngle );
|
|
|
|
double arrowRotNeg = crossBarAngle.Angle() - DEG2RAD( s_arrowAngle );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarStart,
|
|
|
|
m_crossBarStart + wxPoint( arrowEnd.Rotate( arrowRotPos ) ) ) );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarStart,
|
|
|
|
m_crossBarStart + wxPoint( arrowEnd.Rotate( arrowRotNeg ) ) ) );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarEnd,
|
|
|
|
m_crossBarEnd - wxPoint( arrowEnd.Rotate( arrowRotPos ) ) ) );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_crossBarEnd,
|
|
|
|
m_crossBarEnd - wxPoint( arrowEnd.Rotate( arrowRotNeg ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ORTHOGONAL_DIMENSION::updateText()
|
|
|
|
{
|
|
|
|
VECTOR2I crossbarCenter( ( m_crossBarEnd - m_crossBarStart ) / 2 );
|
|
|
|
|
|
|
|
if( m_textPosition == DIM_TEXT_POSITION::OUTSIDE )
|
|
|
|
{
|
|
|
|
int textOffsetDistance = m_text.GetEffectiveTextPenWidth() + m_text.GetTextHeight();
|
|
|
|
|
2020-10-13 15:47:57 +00:00
|
|
|
VECTOR2D height( m_crossBarStart - GetStart() );
|
|
|
|
VECTOR2D crossBar( m_crossBarEnd - m_crossBarStart );
|
|
|
|
|
2021-03-01 22:40:44 +00:00
|
|
|
double sign = height.Cross( crossBar ) > 0 ? 1 : -1;
|
|
|
|
double rotation = sign * DEG2RAD( -90 );
|
2020-10-13 15:47:57 +00:00
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
VECTOR2I textOffset = crossbarCenter.Rotate( rotation ).Resize( textOffsetDistance );
|
|
|
|
textOffset += crossbarCenter;
|
|
|
|
|
|
|
|
m_text.SetTextPos( m_crossBarStart + wxPoint( textOffset ) );
|
2020-10-13 15:47:57 +00:00
|
|
|
m_text.SetTextAngle(rotation);
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
else if( m_textPosition == DIM_TEXT_POSITION::INLINE )
|
|
|
|
{
|
|
|
|
m_text.SetTextPos( m_crossBarStart + wxPoint( crossbarCenter ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_keepTextAligned )
|
2020-09-09 03:17:08 +00:00
|
|
|
{
|
|
|
|
double textAngle = 3600 - RAD2DECIDEG( crossbarCenter.Angle() );
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS( textAngle );
|
|
|
|
|
|
|
|
if( textAngle > 900 && textAngle < 2700 )
|
|
|
|
textAngle -= 1800;
|
|
|
|
|
|
|
|
m_text.SetTextAngle( textAngle );
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE::updateText();
|
2020-09-09 03:17:08 +00:00
|
|
|
}
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
LEADER::LEADER( BOARD_ITEM* aParent ) :
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE( aParent, PCB_DIM_LEADER_T ),
|
2020-09-12 20:09:40 +00:00
|
|
|
m_textFrame( DIM_TEXT_FRAME::NONE )
|
|
|
|
{
|
|
|
|
m_unitsFormat = DIM_UNITS_FORMAT::NO_SUFFIX;
|
|
|
|
m_overrideTextEnabled = true;
|
|
|
|
m_keepTextAligned = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* LEADER::Clone() const
|
|
|
|
{
|
|
|
|
return new LEADER( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEADER::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_DIM_LEADER_T );
|
|
|
|
|
|
|
|
std::swap( *static_cast<LEADER*>( this ), *static_cast<LEADER*>( aImage ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAP_DEF LEADER::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_leader_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEADER::updateGeometry()
|
|
|
|
{
|
|
|
|
m_shapes.clear();
|
|
|
|
|
2021-01-13 08:02:02 +00:00
|
|
|
updateText();
|
|
|
|
|
|
|
|
// Now that we have the text updated, we can determine how to draw the second line
|
|
|
|
// First we need to create an appropriate bounding polygon to collide with
|
|
|
|
EDA_RECT textBox = m_text.GetTextBox().Inflate( m_text.GetTextWidth() / 2,
|
|
|
|
m_text.GetEffectiveTextPenWidth() );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET polyBox;
|
|
|
|
polyBox.NewOutline();
|
|
|
|
polyBox.Append( textBox.GetOrigin() );
|
|
|
|
polyBox.Append( textBox.GetOrigin().x, textBox.GetEnd().y );
|
|
|
|
polyBox.Append( textBox.GetEnd() );
|
|
|
|
polyBox.Append( textBox.GetEnd().x, textBox.GetOrigin().y );
|
|
|
|
polyBox.Rotate( -m_text.GetTextAngleRadians(), textBox.GetCenter() );
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
VECTOR2I firstLine( m_end - m_start );
|
|
|
|
VECTOR2I start( m_start );
|
|
|
|
start += firstLine.Resize( m_extensionOffset );
|
|
|
|
|
2021-03-05 23:10:18 +00:00
|
|
|
SEG arrowSeg( m_start, m_end );
|
|
|
|
SEG textSeg( m_end, m_text.GetPosition() );
|
|
|
|
OPT_VECTOR2I arrowSegEnd, textSegEnd;
|
|
|
|
|
|
|
|
if( m_textFrame == DIM_TEXT_FRAME::CIRCLE )
|
|
|
|
{
|
|
|
|
double penWidth = m_text.GetEffectiveTextPenWidth() / 2.0;
|
|
|
|
double radius = ( textBox.GetWidth() / 2.0 ) - penWidth;
|
|
|
|
CIRCLE circle( textBox.GetCenter(), radius );
|
|
|
|
|
|
|
|
arrowSegEnd = segCircleIntersection( circle, arrowSeg );
|
|
|
|
textSegEnd = segCircleIntersection( circle, textSeg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arrowSegEnd = segPolyIntersection( polyBox, arrowSeg );
|
|
|
|
textSegEnd = segPolyIntersection( polyBox, textSeg );
|
|
|
|
}
|
2021-01-13 08:02:02 +00:00
|
|
|
|
2021-03-05 23:10:18 +00:00
|
|
|
if( !arrowSegEnd )
|
|
|
|
arrowSegEnd = m_end;
|
2021-01-13 08:02:02 +00:00
|
|
|
|
2021-03-05 23:10:18 +00:00
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( start, *arrowSegEnd ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
// Add arrows
|
|
|
|
VECTOR2I arrowEnd( m_arrowLength, 0 );
|
|
|
|
|
|
|
|
double arrowRotPos = firstLine.Angle() + DEG2RAD( s_arrowAngle );
|
|
|
|
double arrowRotNeg = firstLine.Angle() - DEG2RAD( s_arrowAngle );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( start,
|
|
|
|
start + wxPoint( arrowEnd.Rotate( arrowRotPos ) ) ) );
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( start,
|
|
|
|
start + wxPoint( arrowEnd.Rotate( arrowRotNeg ) ) ) );
|
|
|
|
|
|
|
|
|
|
|
|
if( !GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
switch( m_textFrame )
|
|
|
|
{
|
2020-09-16 18:26:34 +00:00
|
|
|
case DIM_TEXT_FRAME::RECTANGLE:
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
|
|
|
for( SHAPE_POLY_SET::SEGMENT_ITERATOR seg = polyBox.IterateSegments(); seg; seg++ )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( *seg ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIM_TEXT_FRAME::CIRCLE:
|
|
|
|
{
|
|
|
|
double penWidth = m_text.GetEffectiveTextPenWidth() / 2.0;
|
|
|
|
double radius = ( textBox.GetWidth() / 2.0 ) - penWidth;
|
|
|
|
m_shapes.emplace_back( new SHAPE_CIRCLE( textBox.GetCenter(), radius ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 23:10:18 +00:00
|
|
|
if( textSegEnd && *arrowSegEnd == m_end )
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( m_end, *textSegEnd ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
2020-09-17 00:54:58 +00:00
|
|
|
|
|
|
|
|
2020-09-24 21:23:16 +00:00
|
|
|
void LEADER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Leader" ), m_text.GetShownText() );
|
2020-09-24 21:23:16 +00:00
|
|
|
|
2020-09-24 23:40:35 +00:00
|
|
|
ORIGIN_TRANSFORMS originTransforms = aFrame->GetOriginTransforms();
|
|
|
|
EDA_UNITS units = aFrame->GetUserUnits();
|
|
|
|
|
|
|
|
wxPoint startCoord = originTransforms.ToDisplayAbs( GetStart() );
|
|
|
|
wxString start = wxString::Format( "@(%s, %s)",
|
|
|
|
MessageTextFromValue( units, startCoord.x ),
|
|
|
|
MessageTextFromValue( units, startCoord.y ) );
|
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( start, wxEmptyString );
|
2020-09-24 23:40:35 +00:00
|
|
|
|
2020-11-30 14:35:48 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName() );
|
2020-09-24 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
CENTER_DIMENSION::CENTER_DIMENSION( BOARD_ITEM* aParent ) :
|
2020-11-11 23:05:59 +00:00
|
|
|
DIMENSION_BASE( aParent, PCB_DIM_CENTER_T )
|
2020-09-17 00:54:58 +00:00
|
|
|
{
|
|
|
|
m_unitsFormat = DIM_UNITS_FORMAT::NO_SUFFIX;
|
|
|
|
m_overrideTextEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* CENTER_DIMENSION::Clone() const
|
|
|
|
{
|
|
|
|
return new CENTER_DIMENSION( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CENTER_DIMENSION::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_DIM_CENTER_T );
|
|
|
|
|
|
|
|
std::swap( *static_cast<CENTER_DIMENSION*>( this ), *static_cast<CENTER_DIMENSION*>( aImage ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAP_DEF CENTER_DIMENSION::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_center_dimension_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT CENTER_DIMENSION::GetBoundingBox() const
|
|
|
|
{
|
|
|
|
int halfWidth = VECTOR2I( m_end - m_start ).x + ( m_lineThickness / 2.0 );
|
|
|
|
|
|
|
|
EDA_RECT bBox;
|
|
|
|
|
|
|
|
bBox.SetX( m_start.x - halfWidth );
|
|
|
|
bBox.SetY( m_start.y - halfWidth );
|
|
|
|
bBox.SetWidth( halfWidth * 2 );
|
|
|
|
bBox.SetHeight( halfWidth * 2 );
|
|
|
|
|
|
|
|
bBox.Normalize();
|
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const BOX2I CENTER_DIMENSION::ViewBBox() const
|
|
|
|
{
|
|
|
|
return BOX2I( VECTOR2I( GetBoundingBox().GetPosition() ),
|
|
|
|
VECTOR2I( GetBoundingBox().GetSize() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CENTER_DIMENSION::updateGeometry()
|
|
|
|
{
|
|
|
|
m_shapes.clear();
|
|
|
|
|
|
|
|
VECTOR2I center( m_start );
|
|
|
|
VECTOR2I arm( m_end - m_start );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( center - arm, center + arm ) );
|
|
|
|
|
|
|
|
arm = arm.Rotate( DEG2RAD( 90 ) );
|
|
|
|
|
|
|
|
m_shapes.emplace_back( new SHAPE_SEGMENT( center - arm, center + arm ) );
|
|
|
|
}
|
2020-10-16 15:51:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct DIMENSION_DESC
|
|
|
|
{
|
|
|
|
DIMENSION_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2020-11-11 23:05:59 +00:00
|
|
|
REGISTER_TYPE( DIMENSION_BASE );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( DIMENSION_BASE ), TYPE_HASH( BOARD_ITEM ) );
|
2020-10-16 15:51:24 +00:00
|
|
|
// TODO: add dimension properties:
|
|
|
|
//propMgr.AddProperty( new PROPERTY<DIMENSION, int>( _HKI( "Height" ),
|
|
|
|
//&DIMENSION::SetHeight, &DIMENSION::GetHeight, PROPERTY_DISPLAY::DISTANCE ) );
|
|
|
|
}
|
|
|
|
} _DIMENSION_DESC;
|
|
|
|
|
|
|
|
|