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>
|
|
|
|
* Copyright (C) 1992-2012 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
|
|
|
|
*/
|
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
/**
|
|
|
|
* @file class_dimension.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <richio.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_dimension.h>
|
2012-04-27 14:15:11 +00:00
|
|
|
#include <base_units.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
DIMENSION::DIMENSION( BOARD_ITEM* aParent ) :
|
2011-12-14 04:29:25 +00:00
|
|
|
BOARD_ITEM( aParent, PCB_DIMENSION_T ),
|
2014-03-12 09:46:11 +00:00
|
|
|
m_Width( Millimeter2iu( 0.2 ) ), m_Unit( INCHES ), m_Value( 0 ), m_Height( 0 ), m_Text( this )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
m_Layer = Dwgs_User;
|
2015-02-27 14:33:13 +00:00
|
|
|
m_Shape = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
DIMENSION::~DIMENSION()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
void DIMENSION::SetPosition( const wxPoint& aPos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextPos( aPos );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-18 17:24:25 +00:00
|
|
|
const wxPoint DIMENSION::GetPosition() const
|
2012-12-19 19:31:36 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
return m_Text.GetTextPos();
|
2012-12-19 19:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
void DIMENSION::SetText( const wxString& aNewText )
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
m_Text.SetText( aNewText );
|
2007-09-25 08:23:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
const wxString DIMENSION::GetText() const
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
return m_Text.GetText();
|
2011-11-30 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
void DIMENSION::SetLayer( PCB_LAYER_ID aLayer )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
|
|
|
m_Layer = aLayer;
|
2012-12-19 19:31:36 +00:00
|
|
|
m_Text.SetLayer( aLayer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void DIMENSION::Move( const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.Offset( offset );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_crossBarO += offset;
|
|
|
|
m_crossBarF += offset;
|
|
|
|
m_featureLineGO += offset;
|
|
|
|
m_featureLineGF += offset;
|
|
|
|
m_featureLineDO += offset;
|
|
|
|
m_featureLineDF += offset;
|
|
|
|
m_arrowG1F += offset;
|
|
|
|
m_arrowG2F += offset;
|
|
|
|
m_arrowD1F += offset;
|
|
|
|
m_arrowD2F += offset;
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void DIMENSION::Rotate( const wxPoint& aRotCentre, double aAngle )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint tmp = m_Text.GetTextPos();
|
2013-03-18 19:36:07 +00:00
|
|
|
RotatePoint( &tmp, aRotCentre, aAngle );
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextPos( tmp );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-01-23 20:30:11 +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;
|
|
|
|
|
|
|
|
if( newAngle > 900 && newAngle < 2700 )
|
|
|
|
newAngle -= 1800;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextAngle( newAngle );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
RotatePoint( &m_crossBarO, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_crossBarF, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_featureLineGO, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_featureLineGF, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_featureLineDO, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_featureLineDF, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_arrowG1F, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_arrowG2F, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_arrowD1F, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_arrowD2F, aRotCentre, aAngle );
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
void DIMENSION::Flip( const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
Mirror( aCentre );
|
2015-12-27 15:51:13 +00:00
|
|
|
|
|
|
|
// DIMENSION items are not usually on copper layers, so
|
|
|
|
// copper layers count is not taken in accoun in Flip transform
|
2013-04-05 19:04:58 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer() ) );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void DIMENSION::Mirror( const wxPoint& axis_pos )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint newPos = m_Text.GetTextPos();
|
2013-03-18 19:36:07 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
#define INVERT( pos ) (pos) = axis_pos.y - ( (pos) - axis_pos.y )
|
2013-03-18 19:36:07 +00:00
|
|
|
INVERT( newPos.y );
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextPos( newPos );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
// invert angle
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextAngle( -m_Text.GetTextAngle() );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
INVERT( m_crossBarO.y );
|
|
|
|
INVERT( m_crossBarF.y );
|
|
|
|
INVERT( m_featureLineGO.y );
|
|
|
|
INVERT( m_featureLineGF.y );
|
|
|
|
INVERT( m_featureLineDO.y );
|
|
|
|
INVERT( m_featureLineDF.y );
|
|
|
|
INVERT( m_arrowG1F.y );
|
|
|
|
INVERT( m_arrowG2F.y );
|
|
|
|
INVERT( m_arrowD1F.y );
|
|
|
|
INVERT( m_arrowD2F.y );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
void DIMENSION::SetOrigin( const wxPoint& aOrigin )
|
|
|
|
{
|
|
|
|
m_featureLineGO = aOrigin;
|
|
|
|
|
|
|
|
AdjustDimensionDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIMENSION::SetEnd( const wxPoint& aEnd )
|
|
|
|
{
|
|
|
|
m_featureLineDO = aEnd;
|
|
|
|
|
|
|
|
AdjustDimensionDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
void DIMENSION::SetHeight( int aHeight )
|
2014-02-11 12:22:30 +00:00
|
|
|
{
|
2014-03-12 09:46:11 +00:00
|
|
|
m_Height = aHeight;
|
2014-02-11 12:22:30 +00:00
|
|
|
|
|
|
|
AdjustDimensionDetails();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
void DIMENSION::UpdateHeight()
|
|
|
|
{
|
|
|
|
VECTOR2D featureLine( m_crossBarO - m_featureLineGO );
|
|
|
|
VECTOR2D crossBar( m_featureLineDO - m_featureLineGO );
|
|
|
|
|
|
|
|
if( featureLine.Cross( crossBar ) > 0 )
|
|
|
|
m_Height = -featureLine.EuclideanNorm();
|
|
|
|
else
|
|
|
|
m_Height = featureLine.EuclideanNorm();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
|
|
|
|
{
|
2016-06-05 11:49:25 +00:00
|
|
|
const int arrowz = Mils2iu( 50 ); // size of arrows
|
2012-06-19 04:53:08 +00:00
|
|
|
int ii;
|
2012-12-19 19:31:36 +00:00
|
|
|
int measure, deltax, deltay; // value of the measure on X and Y axes
|
|
|
|
int arrow_up_X = 0, arrow_up_Y = 0; // coordinates of arrow line /
|
|
|
|
int arrow_dw_X = 0, arrow_dw_Y = 0; // coordinates of arrow line '\'
|
|
|
|
int hx, hy; // dimension line interval
|
2012-06-19 04:53:08 +00:00
|
|
|
double angle, angle_f;
|
|
|
|
wxString msg;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Init layer :
|
|
|
|
m_Text.SetLayer( GetLayer() );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// calculate the size of the dimension (text + line above the text)
|
2017-01-23 20:30:11 +00:00
|
|
|
ii = m_Text.GetTextHeight() + m_Text.GetThickness() + (m_Width * 3);
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
deltax = m_featureLineDO.x - m_featureLineGO.x;
|
|
|
|
deltay = m_featureLineDO.y - m_featureLineGO.y;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
// Calculate dimension value
|
2013-05-04 11:57:09 +00:00
|
|
|
measure = KiROUND( hypot( deltax, deltay ) );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2016-01-17 15:59:24 +00:00
|
|
|
angle = atan2( (double)deltay, (double)deltax );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
// Calculation of parameters X and Y dimensions of the arrows and lines.
|
2010-04-23 09:54:40 +00:00
|
|
|
hx = hy = ii;
|
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
// Taking into account the slope of the side lines.
|
2012-06-19 04:53:08 +00:00
|
|
|
if( measure )
|
2010-04-23 09:54:40 +00:00
|
|
|
{
|
2013-05-04 11:57:09 +00:00
|
|
|
hx = abs( KiROUND( ( (double) deltay * hx ) / measure ) );
|
|
|
|
hy = abs( KiROUND( ( (double) deltax * hy ) / measure ) );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
if( m_featureLineGO.x > m_crossBarO.x )
|
2010-04-23 09:54:40 +00:00
|
|
|
hx = -hx;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
if( m_featureLineGO.x == m_crossBarO.x )
|
2010-04-23 09:54:40 +00:00
|
|
|
hx = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
if( m_featureLineGO.y > m_crossBarO.y )
|
2010-04-23 09:54:40 +00:00
|
|
|
hy = -hy;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
if( m_featureLineGO.y == m_crossBarO.y )
|
2010-04-23 09:54:40 +00:00
|
|
|
hy = 0;
|
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
angle_f = angle + DEG2RAD( 27.5 );
|
|
|
|
arrow_up_X = wxRound( arrowz * cos( angle_f ) );
|
|
|
|
arrow_up_Y = wxRound( arrowz * sin( angle_f ) );
|
|
|
|
angle_f = angle - DEG2RAD( 27.5 );
|
|
|
|
arrow_dw_X = wxRound( arrowz * cos( angle_f ) );
|
|
|
|
arrow_dw_Y = wxRound( arrowz * sin( angle_f ) );
|
2010-04-23 09:54:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
int dx = KiROUND( m_Height * cos( angle + M_PI / 2 ) );
|
|
|
|
int dy = KiROUND( m_Height * sin( angle + M_PI / 2 ) );
|
|
|
|
m_crossBarO.x = m_featureLineGO.x + dx;
|
|
|
|
m_crossBarO.y = m_featureLineGO.y + dy;
|
|
|
|
m_crossBarF.x = m_featureLineDO.x + dx;
|
|
|
|
m_crossBarF.y = m_featureLineDO.y + dy;
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG1F.x = m_crossBarO.x + arrow_up_X;
|
|
|
|
m_arrowG1F.y = m_crossBarO.y + arrow_up_Y;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG2F.x = m_crossBarO.x + arrow_dw_X;
|
|
|
|
m_arrowG2F.y = m_crossBarO.y + arrow_dw_Y;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-09-20 15:07:52 +00:00
|
|
|
/* The right arrow is symmetrical to the left.
|
|
|
|
* / = -\ and \ = -/
|
2010-04-23 09:54:40 +00:00
|
|
|
*/
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD1F.x = m_crossBarF.x - arrow_dw_X;
|
|
|
|
m_arrowD1F.y = m_crossBarF.y - arrow_dw_Y;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD2F.x = m_crossBarF.x - arrow_up_X;
|
|
|
|
m_arrowD2F.y = m_crossBarF.y - arrow_up_Y;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_featureLineGF.x = m_crossBarO.x + hx;
|
|
|
|
m_featureLineGF.y = m_crossBarO.y + hy;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_featureLineDF.x = m_crossBarF.x + hx;
|
|
|
|
m_featureLineDF.y = m_crossBarF.y + hy;
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Calculate the better text position and orientation:
|
2013-03-18 19:36:07 +00:00
|
|
|
wxPoint textPos;
|
|
|
|
textPos.x = (m_crossBarF.x + m_featureLineGF.x) / 2;
|
|
|
|
textPos.y = (m_crossBarF.y + m_featureLineGF.y) / 2;
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextPos( textPos );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
2013-05-02 18:06:58 +00:00
|
|
|
double newAngle = -RAD2DECIDEG( angle );
|
2012-12-19 19:31:36 +00:00
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
NORMALIZE_ANGLE_POS( newAngle );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
if( newAngle > 900 && newAngle < 2700 )
|
|
|
|
newAngle -= 1800;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
m_Text.SetTextAngle( newAngle );
|
2010-04-23 09:54:40 +00:00
|
|
|
|
|
|
|
if( !aDoNotChangeText )
|
|
|
|
{
|
2012-06-19 04:53:08 +00:00
|
|
|
m_Value = measure;
|
2012-12-19 19:31:36 +00:00
|
|
|
msg = ::CoordinateToString( m_Value );
|
2010-04-23 09:54:40 +00:00
|
|
|
SetText( msg );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
void DIMENSION::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
|
|
|
|
const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-08 20:51:08 +00:00
|
|
|
return;
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
m_Text.Draw( panel, DC, mode_color, offset );
|
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
auto frame = static_cast<PCB_EDIT_FRAME*> ( panel->GetParent() );
|
|
|
|
auto gcolor = frame->Settings().Colors().GetLayerColor( m_Layer );
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
GRSetDrawMode( DC, mode_color );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
|
2015-02-02 08:06:39 +00:00
|
|
|
bool filled = displ_opts ? displ_opts->m_DisplayDrawItemsFill : FILLED;
|
|
|
|
int width = m_Width;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
if( filled )
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, m_crossBarO + offset,
|
|
|
|
m_crossBarF + offset, width, gcolor );
|
|
|
|
GRLine( panel->GetClipBox(), DC, m_featureLineGO + offset,
|
|
|
|
m_featureLineGF + offset, width, gcolor );
|
|
|
|
GRLine( panel->GetClipBox(), DC, m_featureLineDO + offset,
|
|
|
|
m_featureLineDF + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, m_crossBarF + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD1F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, m_crossBarF + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD2F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, m_crossBarO + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG1F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, m_crossBarO + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG2F + offset, width, gcolor );
|
2015-02-02 08:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-19 19:31:36 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_crossBarO + offset,
|
|
|
|
m_crossBarF + offset, width, gcolor );
|
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_featureLineGO + offset,
|
|
|
|
m_featureLineGF + offset, width, gcolor );
|
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_featureLineDO + offset,
|
|
|
|
m_featureLineDF + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_crossBarF + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD1F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_crossBarF + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowD2F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_crossBarO + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG1F + offset, width, gcolor );
|
2014-02-11 12:22:30 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, m_crossBarO + offset,
|
2012-12-19 19:31:36 +00:00
|
|
|
m_arrowG2F + offset, width, gcolor );
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
// see class_cotation.h
|
2013-01-12 17:32:24 +00:00
|
|
|
void DIMENSION::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
// for now, display only the text within the DIMENSION using class TEXTE_PCB.
|
2013-01-12 17:32:24 +00:00
|
|
|
m_Text.GetMsgPanelInfo( aList );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
bool DIMENSION::HitTest( const wxPoint& aPosition ) const
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +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
|
|
|
|
2012-12-27 16:42:41 +00:00
|
|
|
int dist_max = m_Width / 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
|
|
|
|
2012-12-27 16:42:41 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_crossBarO, m_crossBarF, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2012-12-27 16:42:41 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_featureLineGO, m_featureLineGF, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2012-12-27 16:42:41 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_featureLineDO, m_featureLineDF, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_crossBarF, m_arrowD1F, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_crossBarF, m_arrowD2F, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_crossBarO, m_arrowG1F, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
if( TestSegmentHit( aPosition, m_crossBarO, m_arrowG2F, dist_max ) )
|
2007-08-08 20:51:08 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
bool DIMENSION::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();
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT DIMENSION::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;
|
|
|
|
|
|
|
|
bBox = m_Text.GetTextBox( -1 );
|
|
|
|
xmin = bBox.GetX();
|
|
|
|
xmax = bBox.GetRight();
|
|
|
|
ymin = bBox.GetY();
|
|
|
|
ymax = bBox.GetBottom();
|
|
|
|
|
|
|
|
xmin = std::min( xmin, m_crossBarO.x );
|
|
|
|
xmin = std::min( xmin, m_crossBarF.x );
|
|
|
|
ymin = std::min( ymin, m_crossBarO.y );
|
|
|
|
ymin = std::min( ymin, m_crossBarF.y );
|
|
|
|
xmax = std::max( xmax, m_crossBarO.x );
|
|
|
|
xmax = std::max( xmax, m_crossBarF.x );
|
|
|
|
ymax = std::max( ymax, m_crossBarO.y );
|
|
|
|
ymax = std::max( ymax, m_crossBarF.y );
|
|
|
|
|
|
|
|
xmin = std::min( xmin, m_featureLineGO.x );
|
|
|
|
xmin = std::min( xmin, m_featureLineGF.x );
|
|
|
|
ymin = std::min( ymin, m_featureLineGO.y );
|
|
|
|
ymin = std::min( ymin, m_featureLineGF.y );
|
|
|
|
xmax = std::max( xmax, m_featureLineGO.x );
|
|
|
|
xmax = std::max( xmax, m_featureLineGF.x );
|
|
|
|
ymax = std::max( ymax, m_featureLineGO.y );
|
|
|
|
ymax = std::max( ymax, m_featureLineGF.y );
|
2011-02-25 16:23:24 +00:00
|
|
|
|
2013-09-16 12:44:03 +00:00
|
|
|
xmin = std::min( xmin, m_featureLineDO.x );
|
|
|
|
xmin = std::min( xmin, m_featureLineDF.x );
|
|
|
|
ymin = std::min( ymin, m_featureLineDO.y );
|
|
|
|
ymin = std::min( ymin, m_featureLineDF.y );
|
|
|
|
xmax = std::max( xmax, m_featureLineDO.x );
|
|
|
|
xmax = std::max( xmax, m_featureLineDF.x );
|
|
|
|
ymax = std::max( ymax, m_featureLineDO.y );
|
|
|
|
ymax = std::max( ymax, m_featureLineDF.y );
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
wxString DIMENSION::GetSelectMenuText() const
|
|
|
|
{
|
|
|
|
wxString text;
|
2013-04-09 17:49:01 +00:00
|
|
|
text.Printf( _( "Dimension \"%s\" on %s" ),
|
|
|
|
GetChars( GetText() ), GetChars( GetLayerName() ) );
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF DIMENSION::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_dimension_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 12:44:03 +00:00
|
|
|
const BOX2I DIMENSION::ViewBBox() const
|
|
|
|
{
|
|
|
|
BOX2I dimBBox = BOX2I( VECTOR2I( GetBoundingBox().GetPosition() ),
|
|
|
|
VECTOR2I( GetBoundingBox().GetSize() ) );
|
|
|
|
dimBBox.Merge( m_Text.ViewBBox() );
|
|
|
|
|
|
|
|
return dimBBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* DIMENSION::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new DIMENSION( *this );
|
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
|
|
|
void DIMENSION::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_DIMENSION_T );
|
|
|
|
|
|
|
|
std::swap( *((DIMENSION*) this), *((DIMENSION*) aImage) );
|
|
|
|
}
|