2010-09-28 14:42:05 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-09-28 14:42:05 +00:00
|
|
|
*
|
2017-05-01 18:42:18 +00:00
|
|
|
* Copyright (C) 1992-2017 <Jean-Pierre Charras>
|
2023-02-10 09:04:52 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2010-09-28 14:42:05 +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
|
|
|
|
*/
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2018-05-17 08:24:09 +00:00
|
|
|
#include <bitmaps.h>
|
2020-10-25 04:12:20 +00:00
|
|
|
#include <eda_text.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2017-09-17 22:43:20 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerber_draw_item.h>
|
|
|
|
#include <gerber_file_image.h>
|
|
|
|
#include <gerber_file_image_list.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-01-03 13:27:00 +00:00
|
|
|
#include <geometry/shape_arc.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
|
2016-05-26 11:57:43 +00:00
|
|
|
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberImageFile ) :
|
2021-07-16 20:13:26 +00:00
|
|
|
EDA_ITEM( nullptr, GERBER_DRAW_ITEM_T )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2016-05-26 07:50:49 +00:00
|
|
|
m_GerberImageFile = aGerberImageFile;
|
2023-02-10 09:04:52 +00:00
|
|
|
m_ShapeType = GBR_SEGMENT;
|
2010-10-09 20:05:03 +00:00
|
|
|
m_Flashed = false;
|
|
|
|
m_DCode = 0;
|
|
|
|
m_UnitsMetric = false;
|
2010-10-03 15:39:06 +00:00
|
|
|
m_LayerNegative = false;
|
2010-10-09 20:05:03 +00:00
|
|
|
m_swapAxis = false;
|
|
|
|
m_mirrorA = false;
|
|
|
|
m_mirrorB = false;
|
|
|
|
m_drawScale.x = m_drawScale.y = 1.0;
|
2010-10-17 16:42:06 +00:00
|
|
|
m_lyrRotation = 0;
|
2016-09-07 08:28:16 +00:00
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
if( m_GerberImageFile )
|
2010-10-09 20:05:03 +00:00
|
|
|
SetLayerParameters();
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GERBER_DRAW_ITEM::~GERBER_DRAW_ITEM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-16 10:56:20 +00:00
|
|
|
void GERBER_DRAW_ITEM::SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes )
|
|
|
|
{
|
|
|
|
m_netAttributes = aNetAttributes;
|
|
|
|
|
2021-09-09 20:49:16 +00:00
|
|
|
if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP )
|
|
|
|
|| ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_PAD ) )
|
|
|
|
{
|
2016-08-16 10:56:20 +00:00
|
|
|
m_GerberImageFile->m_ComponentsList.insert( std::make_pair( m_netAttributes.m_Cmpref, 0 ) );
|
2021-09-09 20:49:16 +00:00
|
|
|
}
|
2016-08-16 10:56:20 +00:00
|
|
|
|
|
|
|
if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_NET ) )
|
|
|
|
m_GerberImageFile->m_NetnamesList.insert( std::make_pair( m_netAttributes.m_Netname, 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-26 11:57:43 +00:00
|
|
|
int GERBER_DRAW_ITEM::GetLayer() const
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
// Return the layer this item is on, or 0 if the m_GerberImageFile is null.
|
2016-05-26 11:57:43 +00:00
|
|
|
return m_GerberImageFile ? m_GerberImageFile->m_GraphicLayer : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-11 13:47:21 +00:00
|
|
|
bool GERBER_DRAW_ITEM::GetTextD_CodePrms( int& aSize, VECTOR2I& aPos, EDA_ANGLE& aOrientation )
|
2017-11-13 10:30:23 +00:00
|
|
|
{
|
|
|
|
// calculate the best size and orientation of the D_Code text
|
|
|
|
|
|
|
|
if( m_DCode <= 0 )
|
|
|
|
return false; // No D_Code for this item
|
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
if( m_Flashed || m_ShapeType == GBR_ARC )
|
2017-11-13 10:30:23 +00:00
|
|
|
aPos = m_Start;
|
|
|
|
else // it is a line:
|
|
|
|
aPos = ( m_Start + m_End) / 2;
|
|
|
|
|
|
|
|
aPos = GetABPosition( aPos );
|
|
|
|
|
|
|
|
int size; // the best size for the text
|
|
|
|
|
|
|
|
if( GetDcodeDescr() )
|
|
|
|
size = GetDcodeDescr()->GetShapeDim( this );
|
|
|
|
else
|
|
|
|
size = std::min( m_Size.x, m_Size.y );
|
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
aOrientation = ANGLE_HORIZONTAL;
|
2017-11-13 10:30:23 +00:00
|
|
|
|
|
|
|
if( m_Flashed )
|
|
|
|
{
|
|
|
|
// A reasonable size for text is min_dim/3 because most of time this text has 3 chars.
|
|
|
|
aSize = size / 3;
|
|
|
|
}
|
|
|
|
else // this item is a line
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I delta = m_Start - m_End;
|
2022-01-15 00:20:02 +00:00
|
|
|
EDA_ANGLE angle( delta );
|
2017-11-13 10:30:23 +00:00
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
aOrientation = angle.Normalize90();
|
2017-11-13 10:30:23 +00:00
|
|
|
|
|
|
|
// A reasonable size for text is size/2 because text needs margin below and above it.
|
|
|
|
// a margin = size/4 seems good, expecting the line len is large enough to show 3 chars,
|
|
|
|
// that is the case most of time.
|
|
|
|
aSize = size / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GERBER_DRAW_ITEM::GetABPosition( const VECTOR2I& aXYPosition ) const
|
2010-10-09 20:05:03 +00:00
|
|
|
{
|
|
|
|
/* Note: RS274Xrevd_e is obscure about the order of transforms:
|
|
|
|
* For instance: Rotation must be made after or before mirroring ?
|
2010-10-10 17:57:54 +00:00
|
|
|
* Note: if something is changed here, GetYXPosition must reflect changes
|
2010-10-09 20:05:03 +00:00
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I abPos = aXYPosition + m_GerberImageFile->m_ImageJustifyOffset;
|
2010-10-09 20:05:03 +00:00
|
|
|
|
2023-09-06 16:54:54 +00:00
|
|
|
// We have also a draw transform (rotation and offset)
|
|
|
|
// order is rotation and after offset
|
|
|
|
|
2010-10-09 20:05:03 +00:00
|
|
|
if( m_swapAxis )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( abPos.x, abPos.y );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
abPos += m_layerOffset + m_GerberImageFile->m_ImageOffset;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
abPos.x = KiROUND( abPos.x * m_drawScale.x );
|
|
|
|
abPos.y = KiROUND( abPos.y * m_drawScale.y );
|
2022-01-18 02:14:09 +00:00
|
|
|
EDA_ANGLE rotation( m_lyrRotation + m_GerberImageFile->m_ImageRotation, DEGREES_T );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-18 02:14:09 +00:00
|
|
|
if( !rotation.IsZero() )
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( abPos, -rotation );
|
2010-10-17 16:42:06 +00:00
|
|
|
|
|
|
|
// Negate A axis if mirrored
|
2010-10-09 20:05:03 +00:00
|
|
|
if( m_mirrorA )
|
2015-06-26 13:41:56 +00:00
|
|
|
abPos.x = -abPos.x;
|
2010-10-16 14:51:22 +00:00
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
// abPos.y must be negated when no mirror, because draw axis is top to bottom
|
2010-10-10 17:57:54 +00:00
|
|
|
if( !m_mirrorB )
|
2015-06-26 13:41:56 +00:00
|
|
|
abPos.y = -abPos.y;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2023-09-06 16:54:54 +00:00
|
|
|
// Now generate the draw transform
|
2023-09-08 08:43:59 +00:00
|
|
|
if( !m_GerberImageFile->m_DisplayRotation.IsZero() )
|
|
|
|
RotatePoint( abPos, m_GerberImageFile->m_DisplayRotation );
|
2023-09-06 16:54:54 +00:00
|
|
|
|
2023-09-08 08:43:59 +00:00
|
|
|
abPos.x += KiROUND( m_GerberImageFile->m_DisplayOffset.x * m_drawScale.x );
|
|
|
|
abPos.y += KiROUND( m_GerberImageFile->m_DisplayOffset.y * m_drawScale.y );
|
2023-09-06 16:54:54 +00:00
|
|
|
|
2010-10-09 20:05:03 +00:00
|
|
|
return abPos;
|
|
|
|
}
|
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GERBER_DRAW_ITEM::GetXYPosition( const VECTOR2I& aABPosition ) const
|
2010-10-10 17:57:54 +00:00
|
|
|
{
|
2011-10-17 20:01:27 +00:00
|
|
|
// do the inverse transform made by GetABPosition
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I xyPos = aABPosition;
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2023-09-06 16:54:54 +00:00
|
|
|
// First, undo the draw transform
|
2023-09-08 08:43:59 +00:00
|
|
|
xyPos.x -= KiROUND( m_GerberImageFile->m_DisplayOffset.x * m_drawScale.x );
|
|
|
|
xyPos.y -= KiROUND( m_GerberImageFile->m_DisplayOffset.y * m_drawScale.y );
|
2023-09-06 16:54:54 +00:00
|
|
|
|
2023-09-08 08:43:59 +00:00
|
|
|
if( !m_GerberImageFile->m_DisplayRotation.IsZero() )
|
|
|
|
RotatePoint( xyPos, -m_GerberImageFile->m_DisplayRotation );
|
2023-09-06 16:54:54 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
if( m_mirrorA )
|
2015-06-26 13:41:56 +00:00
|
|
|
xyPos.x = -xyPos.x;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
if( !m_mirrorB )
|
2015-06-26 13:41:56 +00:00
|
|
|
xyPos.y = -xyPos.y;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-18 02:14:09 +00:00
|
|
|
EDA_ANGLE rotation( m_lyrRotation + m_GerberImageFile->m_ImageRotation, DEGREES_T );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-18 02:14:09 +00:00
|
|
|
if( !rotation.IsZero() )
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( xyPos, rotation );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
xyPos.x = KiROUND( xyPos.x / m_drawScale.x );
|
|
|
|
xyPos.y = KiROUND( xyPos.y / m_drawScale.y );
|
2016-05-26 07:50:49 +00:00
|
|
|
xyPos -= m_layerOffset + m_GerberImageFile->m_ImageOffset;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
if( m_swapAxis )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( xyPos.x, xyPos.y );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2016-05-26 07:50:49 +00:00
|
|
|
return xyPos - m_GerberImageFile->m_ImageJustifyOffset;
|
2010-10-10 17:57:54 +00:00
|
|
|
}
|
2010-10-09 20:05:03 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
|
2010-10-09 20:05:03 +00:00
|
|
|
void GERBER_DRAW_ITEM::SetLayerParameters()
|
|
|
|
{
|
2016-05-26 07:50:49 +00:00
|
|
|
m_UnitsMetric = m_GerberImageFile->m_GerbMetric;
|
|
|
|
m_swapAxis = m_GerberImageFile->m_SwapAxis; // false if A = X, B = Y;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
// true if A =Y, B = Y
|
2016-05-26 07:50:49 +00:00
|
|
|
m_mirrorA = m_GerberImageFile->m_MirrorA; // true: mirror / axe A
|
|
|
|
m_mirrorB = m_GerberImageFile->m_MirrorB; // true: mirror / axe B
|
|
|
|
m_drawScale = m_GerberImageFile->m_Scale; // A and B scaling factor
|
|
|
|
m_layerOffset = m_GerberImageFile->m_Offset; // Offset from OF command
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
// Rotation from RO command:
|
2016-05-26 07:50:49 +00:00
|
|
|
m_lyrRotation = m_GerberImageFile->m_LocalRotation;
|
|
|
|
m_LayerNegative = m_GerberImageFile->GetLayerParams().m_LayerNegative;
|
2010-10-09 20:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
wxString GERBER_DRAW_ITEM::ShowGBRShape() const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2021-09-09 20:49:16 +00:00
|
|
|
case GBR_SEGMENT: return _( "Line" );
|
|
|
|
case GBR_ARC: return _( "Arc" );
|
|
|
|
case GBR_CIRCLE: return _( "Circle" );
|
|
|
|
case GBR_SPOT_OVAL: return wxT( "spot_oval" );
|
|
|
|
case GBR_SPOT_CIRCLE: return wxT( "spot_circle" );
|
|
|
|
case GBR_SPOT_RECT: return wxT( "spot_rect" );
|
|
|
|
case GBR_SPOT_POLY: return wxT( "spot_poly" );
|
|
|
|
case GBR_POLYGON: return wxT( "polygon" );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
case GBR_SPOT_MACRO:
|
2010-10-25 07:43:50 +00:00
|
|
|
{
|
|
|
|
wxString name = wxT( "apt_macro" );
|
|
|
|
D_CODE* dcode = GetDcodeDescr();
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
if( dcode && dcode->GetMacro() )
|
2023-01-13 17:57:18 +00:00
|
|
|
name << wxT(" ") << dcode->GetMacro()->m_AmName;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
return name;
|
|
|
|
}
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2021-09-09 20:49:16 +00:00
|
|
|
default: return wxT( "??" );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
D_CODE* GERBER_DRAW_ITEM::GetDcodeDescr() const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( ( m_DCode < FIRST_DCODE ) || ( m_DCode > LAST_DCODE ) )
|
|
|
|
return nullptr;
|
2014-11-22 11:52:57 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( m_GerberImageFile == nullptr )
|
|
|
|
return nullptr;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
return m_GerberImageFile->GetDCODE( m_DCode );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GERBER_DRAW_ITEM::GetBoundingBox() const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
// return a rectangle which is (pos,dim) in nature. therefore the +1
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox( m_Start, VECTOR2I( 1, 1 ) );
|
2017-09-17 22:43:20 +00:00
|
|
|
D_CODE* code = GetDcodeDescr();
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
// TODO(JE) GERBER_DRAW_ITEM maybe should actually be a number of subclasses.
|
|
|
|
// Until/unless that is changed, we need to do different things depending on
|
|
|
|
// what is actually being represented by this GERBER_DRAW_ITEM.
|
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
|
|
|
case GBR_POLYGON:
|
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
BOX2I bb = m_ShapeAsPolygon.BBox();
|
2017-09-17 22:43:20 +00:00
|
|
|
bbox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 );
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.SetOrigin( bb.GetOrigin() );
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBR_CIRCLE:
|
|
|
|
{
|
2024-05-31 19:22:16 +00:00
|
|
|
double radius = m_Start.Distance( m_End );
|
2017-09-17 22:43:20 +00:00
|
|
|
bbox.Inflate( radius, radius );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBR_ARC:
|
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
EDA_ANGLE angle( atan2( double( m_End.y - m_ArcCentre.y ),
|
|
|
|
double( m_End.x - m_ArcCentre.x ) )
|
|
|
|
- atan2( double( m_Start.y - m_ArcCentre.y ),
|
|
|
|
double( m_Start.x - m_ArcCentre.x ) ),
|
|
|
|
RADIANS_T );
|
2020-01-03 13:27:00 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( m_End == m_Start ) // Arc with the end point = start point is expected to be a circle.
|
2022-01-14 15:34:41 +00:00
|
|
|
angle = ANGLE_360;
|
|
|
|
else
|
|
|
|
angle.Normalize();
|
2020-01-03 13:27:00 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
SHAPE_ARC arc( m_ArcCentre, m_Start, angle );
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox = arc.BBox( m_Size.x / 2 ); // m_Size.x is the line thickness
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBR_SPOT_CIRCLE:
|
|
|
|
{
|
2018-03-19 01:55:07 +00:00
|
|
|
if( code )
|
|
|
|
{
|
|
|
|
int radius = code->m_Size.x >> 1;
|
|
|
|
bbox.Inflate( radius, radius );
|
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBR_SPOT_RECT:
|
|
|
|
{
|
2018-03-19 01:55:07 +00:00
|
|
|
if( code )
|
|
|
|
bbox.Inflate( code->m_Size.x / 2, code->m_Size.y / 2 );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBR_SPOT_OVAL:
|
|
|
|
{
|
2018-03-19 01:55:07 +00:00
|
|
|
if( code )
|
2020-03-27 15:15:39 +00:00
|
|
|
bbox.Inflate( code->m_Size.x /2, code->m_Size.y / 2 );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-01-18 15:35:09 +00:00
|
|
|
case GBR_SPOT_MACRO:
|
2017-09-17 22:43:20 +00:00
|
|
|
case GBR_SPOT_POLY:
|
2018-03-19 01:55:07 +00:00
|
|
|
if( code )
|
|
|
|
{
|
|
|
|
if( code->m_Polygon.OutlineCount() == 0 )
|
2022-09-07 16:54:04 +00:00
|
|
|
code->ConvertShapeToPolygon( this );
|
2017-09-17 22:43:20 +00:00
|
|
|
|
2018-03-19 01:55:07 +00:00
|
|
|
bbox.Inflate( code->m_Polygon.BBox().GetWidth() / 2,
|
|
|
|
code->m_Polygon.BBox().GetHeight() / 2 );
|
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_SEGMENT:
|
|
|
|
{
|
2023-02-10 10:18:09 +00:00
|
|
|
if( code && code->m_ApertType == APT_RECT )
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
if( m_ShapeAsPolygon.OutlineCount() == 0 )
|
2021-09-14 12:04:25 +00:00
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
// We cannot initialize m_ShapeAsPolygon, because we are in a const function.
|
2021-09-14 12:04:25 +00:00
|
|
|
// So use a temporary polygon
|
|
|
|
SHAPE_POLY_SET poly_shape;
|
|
|
|
ConvertSegmentToPolygon( &poly_shape );
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox = poly_shape.BBox();
|
2021-09-14 12:04:25 +00:00
|
|
|
}
|
2021-09-14 08:44:40 +00:00
|
|
|
|
2021-09-14 12:04:25 +00:00
|
|
|
else
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
bbox = m_ShapeAsPolygon.BBox();
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int radius = ( m_Size.x + 1 ) / 2;
|
|
|
|
|
|
|
|
int ymax = std::max( m_Start.y, m_End.y ) + radius;
|
|
|
|
int xmax = std::max( m_Start.x, m_End.x ) + radius;
|
|
|
|
|
|
|
|
int ymin = std::min( m_Start.y, m_End.y ) - radius;
|
|
|
|
int xmin = std::min( m_Start.x, m_End.x ) - radius;
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox = BOX2I( VECTOR2I( xmin, ymin ), VECTOR2I( xmax - xmin + 1, ymax - ymin + 1 ) );
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, wxT( "GERBER_DRAW_ITEM shape is unknown!" ) );
|
|
|
|
break;
|
|
|
|
}
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// calculate the corners coordinates in current Gerber axis orientations
|
2023-09-08 08:43:59 +00:00
|
|
|
// because the initial bbox is a horizontal rect, but the bbox in AB position
|
|
|
|
// is the bbox image with perhaps a rotation, we need to calculate the coords of the
|
|
|
|
// corners of the bbox rotated, and then calculate the final bounding box
|
|
|
|
VECTOR2I corners[4];
|
2023-09-11 07:38:53 +00:00
|
|
|
bbox.Normalize();
|
|
|
|
|
|
|
|
// Shape:
|
|
|
|
// 0...1
|
|
|
|
// . .
|
|
|
|
// . .
|
|
|
|
// 3...2
|
2023-09-08 08:43:59 +00:00
|
|
|
corners[0] = bbox.GetOrigin(); // top left
|
|
|
|
corners[2] = bbox.GetEnd(); // bottom right
|
|
|
|
corners[1] = VECTOR2I( corners[2].x, corners[0].y ); // top right
|
|
|
|
corners[3] = VECTOR2I( corners[0].x, corners[2].y ); // bottom left
|
|
|
|
|
2023-09-11 07:38:53 +00:00
|
|
|
VECTOR2I org = GetABPosition( bbox.GetOrigin() );;
|
|
|
|
VECTOR2I end = GetABPosition( bbox.GetEnd() );;
|
2023-09-08 08:43:59 +00:00
|
|
|
|
2023-09-11 07:38:53 +00:00
|
|
|
// Now calculate the bounding box of bbox, if the display image is rotated
|
|
|
|
// It will be perhaps a bit bigger than a better bounding box calculation, but it is fast
|
|
|
|
// and easy
|
|
|
|
// (if not rotated, this is a nop)
|
2023-09-08 08:43:59 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
corners[ii] = GetABPosition( corners[ii] );
|
|
|
|
|
|
|
|
org.x = std::min( org.x, corners[ii].x );
|
|
|
|
org.y = std::min( org.y, corners[ii].y );
|
|
|
|
|
|
|
|
end.x = std::max( end.x, corners[ii].x );
|
|
|
|
end.y = std::max( end.y, corners[ii].y );
|
|
|
|
}
|
|
|
|
|
2016-06-15 08:26:41 +00:00
|
|
|
// Set the corners position:
|
|
|
|
bbox.SetOrigin( org );
|
|
|
|
bbox.SetEnd( end );
|
|
|
|
bbox.Normalize();
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void GERBER_DRAW_ITEM::MoveXY( const VECTOR2I& aMoveVector )
|
2010-10-15 18:59:26 +00:00
|
|
|
{
|
|
|
|
m_Start += aMoveVector;
|
|
|
|
m_End += aMoveVector;
|
|
|
|
m_ArcCentre += aMoveVector;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2023-02-10 10:50:20 +00:00
|
|
|
m_ShapeAsPolygon.Move( aMoveVector );
|
2010-10-15 18:59:26 +00:00
|
|
|
}
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
bool GERBER_DRAW_ITEM::HasNegativeItems()
|
|
|
|
{
|
2016-05-26 07:50:49 +00:00
|
|
|
bool isClear = m_LayerNegative ^ m_GerberImageFile->m_ImageNegative;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
// if isClear is true, this item has negative shape
|
2016-06-03 16:42:24 +00:00
|
|
|
return isClear;
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void GERBER_DRAW_ITEM::Print( wxDC* aDC, const VECTOR2I& aOffset, GBR_DISPLAY_OPTIONS* aOptions )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2011-10-17 20:01:27 +00:00
|
|
|
// used when a D_CODE is not found. default D_CODE to draw a flashed item
|
|
|
|
static D_CODE dummyD_CODE( 0 );
|
2010-09-28 14:42:05 +00:00
|
|
|
bool isFilled;
|
|
|
|
int radius;
|
|
|
|
int halfPenWidth;
|
|
|
|
static bool show_err;
|
|
|
|
D_CODE* d_codeDescr = GetDcodeDescr();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( d_codeDescr == nullptr )
|
2010-09-28 14:42:05 +00:00
|
|
|
d_codeDescr = &dummyD_CODE;
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color = m_GerberImageFile->GetPositiveDrawColor();
|
2010-10-03 15:39:06 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
/* isDark is true if flash is positive and should use a drawing
|
|
|
|
* color other than the background color, else use the background color
|
|
|
|
* when drawing so that an erasure happens.
|
|
|
|
*/
|
2016-05-26 07:50:49 +00:00
|
|
|
bool isDark = !(m_LayerNegative ^ m_GerberImageFile->m_ImageNegative);
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
if( !isDark )
|
2010-10-03 15:39:06 +00:00
|
|
|
{
|
2010-10-16 14:51:22 +00:00
|
|
|
// draw in background color ("negative" color)
|
2019-05-31 12:15:25 +00:00
|
|
|
color = aOptions->m_NegativeDrawColor;
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
isFilled = aOptions->m_DisplayLinesFill;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
case GBR_POLYGON:
|
2019-05-31 12:15:25 +00:00
|
|
|
isFilled = aOptions->m_DisplayPolygonsFill;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-16 14:51:22 +00:00
|
|
|
if( !isDark )
|
2010-09-28 14:42:05 +00:00
|
|
|
isFilled = true;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
PrintGerberPoly( aDC, color, aOffset, isFilled );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_CIRCLE:
|
2024-05-31 19:22:16 +00:00
|
|
|
radius = KiROUND( m_Start.Distance( m_End ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
halfPenWidth = m_Size.x >> 1;
|
|
|
|
|
2010-09-29 19:58:22 +00:00
|
|
|
if( !isFilled )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
// draw the border of the pen's path using two circles, each as narrow as possible
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCircle( aDC, GetABPosition( m_Start ), radius - halfPenWidth, 0, color );
|
|
|
|
GRCircle( aDC, GetABPosition( m_Start ), radius + halfPenWidth, 0, color );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2010-09-29 19:58:22 +00:00
|
|
|
else // Filled mode
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCircle( aDC, GetABPosition( m_Start ), radius, m_Size.x, color );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_ARC:
|
2011-04-23 19:01:41 +00:00
|
|
|
// Currently, arcs plotted with a rectangular aperture are not supported.
|
2010-10-25 07:43:50 +00:00
|
|
|
// a round pen only is expected.
|
2010-09-28 14:42:05 +00:00
|
|
|
if( !isFilled )
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRArc( aDC, GetABPosition( m_Start ), GetABPosition( m_End ),
|
|
|
|
GetABPosition( m_ArcCentre ), 0, color );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRArc( aDC, GetABPosition( m_Start ), GetABPosition( m_End ),
|
|
|
|
GetABPosition( m_ArcCentre ), m_Size.x, color );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_SPOT_CIRCLE:
|
|
|
|
case GBR_SPOT_RECT:
|
|
|
|
case GBR_SPOT_OVAL:
|
2010-09-28 19:34:16 +00:00
|
|
|
case GBR_SPOT_POLY:
|
2010-10-01 19:11:30 +00:00
|
|
|
case GBR_SPOT_MACRO:
|
2019-05-31 12:15:25 +00:00
|
|
|
isFilled = aOptions->m_DisplayFlashedItemsFill;
|
2022-01-28 22:51:34 +00:00
|
|
|
d_codeDescr->DrawFlashedShape( this, aDC, color, m_Start, isFilled );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_SEGMENT:
|
2010-10-25 07:43:50 +00:00
|
|
|
/* Plot a line from m_Start to m_End.
|
2021-07-16 20:13:26 +00:00
|
|
|
* Usually, a round pen is used, but some Gerber files use a rectangular pen
|
2010-10-25 07:43:50 +00:00
|
|
|
* In fact, any aperture can be used to plot a line.
|
|
|
|
* currently: only a square pen is handled (I believe using a polygon gives a strange plot).
|
|
|
|
*/
|
2023-02-10 10:18:09 +00:00
|
|
|
if( d_codeDescr->m_ApertType == APT_RECT )
|
2010-10-25 07:43:50 +00:00
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
if( m_ShapeAsPolygon.OutlineCount() == 0 )
|
2017-09-17 22:43:20 +00:00
|
|
|
ConvertSegmentToPolygon();
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
PrintGerberPoly( aDC, color, aOffset, isFilled );
|
2010-10-25 07:43:50 +00:00
|
|
|
}
|
2022-01-28 22:51:34 +00:00
|
|
|
else if( !isFilled )
|
|
|
|
{
|
|
|
|
GRCSegm( aDC, GetABPosition( m_Start ), GetABPosition( m_End ), m_Size.x, color );
|
|
|
|
}
|
2010-09-28 14:42:05 +00:00
|
|
|
else
|
2010-10-25 07:43:50 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledSegment( aDC, GetABPosition( m_Start ), GetABPosition( m_End ), m_Size.x,
|
|
|
|
color );
|
2010-10-25 07:43:50 +00:00
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if( !show_err )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "Trace_Segment() type error" ) );
|
2011-10-17 20:01:27 +00:00
|
|
|
show_err = true;
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2021-09-14 12:04:25 +00:00
|
|
|
void GERBER_DRAW_ITEM::ConvertSegmentToPolygon( SHAPE_POLY_SET* aPolygon ) const
|
2010-10-25 07:43:50 +00:00
|
|
|
{
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->RemoveAllContours();
|
|
|
|
aPolygon->NewOutline();
|
2010-10-25 07:43:50 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = m_Start;
|
|
|
|
VECTOR2I end = m_End;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
// make calculations more easy if ensure start.x < end.x
|
|
|
|
// (only 2 quadrants to consider)
|
|
|
|
if( start.x > end.x )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( start, end );
|
2010-10-25 07:43:50 +00:00
|
|
|
|
|
|
|
// calculate values relative to start point:
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I delta = end - start;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
// calculate corners for the first quadrant only (delta.x and delta.y > 0 )
|
|
|
|
// currently, delta.x already is > 0.
|
|
|
|
// make delta.y > 0
|
|
|
|
bool change = delta.y < 0;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
if( change )
|
2015-06-26 13:41:56 +00:00
|
|
|
delta.y = -delta.y;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
// Now create the full polygon.
|
2011-10-17 20:01:27 +00:00
|
|
|
// Due to previous changes, the shape is always something like
|
2016-09-07 08:28:16 +00:00
|
|
|
// 3 4
|
|
|
|
// 2 5
|
2010-10-25 07:43:50 +00:00
|
|
|
// 1 6
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I corner;
|
2010-10-25 07:43:50 +00:00
|
|
|
corner.x -= m_Size.x/2;
|
|
|
|
corner.y -= m_Size.y/2;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I close = corner;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // Lower left corner, start point (1)
|
2010-10-25 07:43:50 +00:00
|
|
|
corner.y += m_Size.y;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // upper left corner, start point (2)
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( delta.x || delta.y )
|
2010-10-25 07:43:50 +00:00
|
|
|
{
|
|
|
|
corner += delta;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // upper left corner, end point (3)
|
2010-10-25 07:43:50 +00:00
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
corner.x += m_Size.x;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // upper right corner, end point (4)
|
2010-10-25 07:43:50 +00:00
|
|
|
corner.y -= m_Size.y;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // lower right corner, end point (5)
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
if( delta.x || delta.y )
|
|
|
|
{
|
|
|
|
corner -= delta;
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( corner ) ); // lower left corner, start point (6)
|
2010-10-25 07:43:50 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Append( VECTOR2I( close ) ); // close the shape
|
2017-09-17 22:43:20 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
// Create final polygon:
|
2019-03-23 18:26:44 +00:00
|
|
|
if( change )
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Mirror( false, true );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2021-09-14 12:04:25 +00:00
|
|
|
aPolygon->Move( VECTOR2I( start ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_DRAW_ITEM::ConvertSegmentToPolygon()
|
|
|
|
{
|
2023-02-10 10:50:20 +00:00
|
|
|
ConvertSegmentToPolygon( &m_ShapeAsPolygon );
|
2010-10-25 07:43:50 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void GERBER_DRAW_ITEM::PrintGerberPoly( wxDC* aDC, const COLOR4D& aColor, const VECTOR2I& aOffset,
|
2019-05-31 12:15:25 +00:00
|
|
|
bool aFilledShape )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
2023-02-10 10:50:20 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = m_ShapeAsPolygon.Outline( 0 );
|
2017-09-17 22:43:20 +00:00
|
|
|
int pointCount = poly.PointCount() - 1;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
points.reserve( pointCount );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < pointCount; ii++ )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
|
2017-09-17 22:43:20 +00:00
|
|
|
points[ii] = p + aOffset;
|
|
|
|
points[ii] = GetABPosition( points[ii] );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRClosedPoly( aDC, pointCount, &points[0], aFilledShape, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void GERBER_DRAW_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2016-08-01 17:47:35 +00:00
|
|
|
wxString text;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
msg = ShowGBRShape();
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "Type" ), msg );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
2019-10-12 11:56:59 +00:00
|
|
|
// Display D_Code value with its attributes for items using a DCode:
|
2023-02-10 09:04:52 +00:00
|
|
|
if( m_ShapeType == GBR_POLYGON ) // Has no DCode, but can have an attribute
|
2019-10-12 11:56:59 +00:00
|
|
|
{
|
2019-10-15 15:51:29 +00:00
|
|
|
msg = _( "Attribute" );
|
2016-08-01 17:47:35 +00:00
|
|
|
|
2019-10-12 11:56:59 +00:00
|
|
|
if( m_AperFunction.IsEmpty() )
|
|
|
|
text = _( "No attribute" );
|
|
|
|
else
|
|
|
|
text = m_AperFunction;
|
|
|
|
}
|
2016-08-01 17:47:35 +00:00
|
|
|
else
|
2019-10-12 11:56:59 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "D Code %d" ), m_DCode );
|
|
|
|
D_CODE* apertDescr = GetDcodeDescr();
|
|
|
|
|
|
|
|
if( !apertDescr || apertDescr->m_AperFunction.IsEmpty() )
|
|
|
|
text = _( "No attribute" );
|
|
|
|
else
|
|
|
|
text = apertDescr->m_AperFunction;
|
|
|
|
}
|
2016-08-01 17:47:35 +00:00
|
|
|
|
2020-12-08 05:52:21 +00:00
|
|
|
aList.emplace_back( msg, text );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2017-05-01 18:42:18 +00:00
|
|
|
// Display graphic layer name
|
2016-09-07 08:28:16 +00:00
|
|
|
msg = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true );
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "Graphic Layer" ), msg );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2021-08-16 20:15:13 +00:00
|
|
|
// Display item position
|
2022-09-16 04:38:10 +00:00
|
|
|
auto xStart = EDA_UNIT_UTILS::UI::ToUserUnit( gerbIUScale, aFrame->GetUserUnits(), m_Start.x );
|
|
|
|
auto yStart = EDA_UNIT_UTILS::UI::ToUserUnit( gerbIUScale, aFrame->GetUserUnits(), m_Start.y );
|
|
|
|
auto xEnd = EDA_UNIT_UTILS::UI::ToUserUnit( gerbIUScale, aFrame->GetUserUnits(), m_End.x );
|
|
|
|
auto yEnd = EDA_UNIT_UTILS::UI::ToUserUnit( gerbIUScale, aFrame->GetUserUnits(), m_End.y );
|
2021-08-16 20:15:13 +00:00
|
|
|
|
|
|
|
if( m_Flashed )
|
|
|
|
{
|
|
|
|
msg.Printf( wxT( "(%.4f, %.4f)" ), xStart, yStart );
|
2022-07-22 22:05:25 +00:00
|
|
|
aList.emplace_back( _( "Position" ), msg );
|
2021-08-16 20:15:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( wxT( "(%.4f, %.4f)" ), xStart, yStart );
|
2022-07-22 22:05:25 +00:00
|
|
|
aList.emplace_back( _( "Start" ), msg );
|
2021-08-16 20:15:13 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%.4f, %.4f)" ), xEnd, yEnd );
|
2022-07-22 22:05:25 +00:00
|
|
|
aList.emplace_back( _( "End" ), msg );
|
2021-08-16 20:15:13 +00:00
|
|
|
}
|
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
// Display item rotation
|
|
|
|
// The full rotation is Image rotation + m_lyrRotation
|
|
|
|
// but m_lyrRotation is specific to this object
|
|
|
|
// so we display only this parameter
|
|
|
|
msg.Printf( wxT( "%f" ), m_lyrRotation );
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "Rotation" ), msg );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
// Display item polarity (item specific)
|
|
|
|
msg = m_LayerNegative ? _("Clear") : _("Dark");
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "Polarity" ), msg );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
// Display mirroring (item specific)
|
2021-07-16 20:13:26 +00:00
|
|
|
msg.Printf( wxT( "A:%s B:%s" ), m_mirrorA ? _( "Yes" ) : _( "No" ),
|
|
|
|
m_mirrorB ? _( "Yes" ) : _( "No" ) );
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "Mirror" ), msg );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
// Display AB axis swap (item specific)
|
2010-10-16 14:51:22 +00:00
|
|
|
msg = m_swapAxis ? wxT( "A=Y B=X" ) : wxT( "A=X B=Y" );
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( _( "AB axis" ), msg );
|
2016-07-27 13:27:19 +00:00
|
|
|
|
|
|
|
// Display net info, if exists
|
2016-08-16 10:56:20 +00:00
|
|
|
if( m_netAttributes.m_NetAttribType == GBR_NETLIST_METADATA::GBR_NETINFO_UNSPECIFIED )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Build full net info:
|
|
|
|
wxString net_msg;
|
|
|
|
wxString cmp_pad_msg;
|
|
|
|
|
|
|
|
if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_NET ) )
|
2016-07-27 13:27:19 +00:00
|
|
|
{
|
2016-08-16 10:56:20 +00:00
|
|
|
net_msg = _( "Net:" );
|
2022-02-05 19:31:22 +00:00
|
|
|
net_msg << wxS( " " );
|
2017-05-01 18:42:18 +00:00
|
|
|
|
2016-10-23 17:43:31 +00:00
|
|
|
if( m_netAttributes.m_Netname.IsEmpty() )
|
2022-12-15 13:59:25 +00:00
|
|
|
net_msg << _( "<no net>" );
|
2016-10-23 17:43:31 +00:00
|
|
|
else
|
2018-10-19 11:28:34 +00:00
|
|
|
net_msg << UnescapeString( m_netAttributes.m_Netname );
|
2016-07-27 13:27:19 +00:00
|
|
|
}
|
2016-08-16 10:56:20 +00:00
|
|
|
|
|
|
|
if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_PAD ) )
|
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
if( m_netAttributes.m_PadPinFunction.IsEmpty() )
|
2021-09-09 20:49:16 +00:00
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
cmp_pad_msg.Printf( _( "Cmp: %s Pad: %s" ),
|
2018-10-19 11:28:34 +00:00
|
|
|
m_netAttributes.m_Cmpref,
|
2019-11-17 09:11:29 +00:00
|
|
|
m_netAttributes.m_Padname.GetValue() );
|
2021-09-09 20:49:16 +00:00
|
|
|
}
|
2019-11-17 09:11:29 +00:00
|
|
|
else
|
2021-09-09 20:49:16 +00:00
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
cmp_pad_msg.Printf( _( "Cmp: %s Pad: %s Fct %s" ),
|
|
|
|
m_netAttributes.m_Cmpref,
|
|
|
|
m_netAttributes.m_Padname.GetValue(),
|
|
|
|
m_netAttributes.m_PadPinFunction.GetValue() );
|
2021-09-09 20:49:16 +00:00
|
|
|
}
|
2016-08-16 10:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP ) )
|
|
|
|
{
|
|
|
|
cmp_pad_msg = _( "Cmp:" );
|
2022-02-05 19:31:22 +00:00
|
|
|
cmp_pad_msg << wxS( " " ) << m_netAttributes.m_Cmpref;
|
2016-08-16 10:56:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 05:50:25 +00:00
|
|
|
aList.emplace_back( net_msg, cmp_pad_msg );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS GERBER_DRAW_ITEM::GetMenuImage() const
|
2018-05-17 08:24:09 +00:00
|
|
|
{
|
|
|
|
if( m_Flashed )
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::pad;
|
2018-05-17 08:24:09 +00:00
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2018-05-17 08:24:09 +00:00
|
|
|
{
|
|
|
|
case GBR_SEGMENT:
|
|
|
|
case GBR_ARC:
|
|
|
|
case GBR_CIRCLE:
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_line;
|
2018-05-17 08:24:09 +00:00
|
|
|
|
|
|
|
case GBR_SPOT_OVAL:
|
|
|
|
case GBR_SPOT_CIRCLE:
|
|
|
|
case GBR_SPOT_RECT:
|
|
|
|
case GBR_SPOT_POLY:
|
|
|
|
case GBR_SPOT_MACRO:
|
|
|
|
// should be handles by m_Flashed == true
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::pad;
|
2018-05-17 08:24:09 +00:00
|
|
|
|
|
|
|
case GBR_POLYGON:
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_graphical_polygon;
|
2018-05-17 08:24:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::info;
|
2018-05-17 08:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool GERBER_DRAW_ITEM::HitTest( const VECTOR2I& aRefPos, int aAccuracy ) const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2018-03-30 02:04:51 +00:00
|
|
|
// In case the item has a very tiny width defined, allow it to be selected
|
2022-09-16 11:33:56 +00:00
|
|
|
const int MIN_HIT_TEST_RADIUS = gerbIUScale.mmToIU( 0.01 );
|
2018-03-30 02:04:51 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// calculate aRefPos in XY Gerber axis:
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I ref_pos = GetXYPosition( aRefPos );
|
2010-10-10 17:57:54 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
|
|
|
case GBR_POLYGON:
|
2023-02-10 10:50:20 +00:00
|
|
|
poly = m_ShapeAsPolygon;
|
2019-07-13 16:35:57 +00:00
|
|
|
return poly.Contains( VECTOR2I( ref_pos ), 0, aAccuracy );
|
2017-09-17 22:43:20 +00:00
|
|
|
|
|
|
|
case GBR_SPOT_POLY:
|
|
|
|
poly = GetDcodeDescr()->m_Polygon;
|
2019-03-23 18:26:44 +00:00
|
|
|
poly.Move( VECTOR2I( m_Start ) );
|
2019-07-13 16:35:57 +00:00
|
|
|
return poly.Contains( VECTOR2I( ref_pos ), 0, aAccuracy );
|
2017-09-17 22:43:20 +00:00
|
|
|
|
|
|
|
case GBR_SPOT_RECT:
|
|
|
|
return GetBoundingBox().Contains( aRefPos );
|
|
|
|
|
2020-03-27 15:15:39 +00:00
|
|
|
case GBR_SPOT_OVAL:
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2I bbox = GetBoundingBox();
|
2020-03-27 15:15:39 +00:00
|
|
|
|
2022-08-31 22:57:24 +00:00
|
|
|
if( ! bbox.Contains( aRefPos ) )
|
|
|
|
return false;
|
2020-03-27 15:15:39 +00:00
|
|
|
|
|
|
|
// This is similar to a segment with thickness = min( m_Size.x, m_Size.y )
|
|
|
|
int radius = std::min( m_Size.x, m_Size.y )/2;
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I start, end;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-03-27 15:15:39 +00:00
|
|
|
if( m_Size.x > m_Size.y ) // Horizontal oval
|
|
|
|
{
|
|
|
|
int len = m_Size.y - m_Size.x;
|
|
|
|
start.x = -len/2;
|
|
|
|
end.x = len/2;
|
|
|
|
}
|
|
|
|
else // Vertical oval
|
|
|
|
{
|
|
|
|
int len = m_Size.x - m_Size.y;
|
|
|
|
start.y = -len/2;
|
|
|
|
end.y = len/2;
|
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-03-27 15:15:39 +00:00
|
|
|
start += bbox.Centre();
|
|
|
|
end += bbox.Centre();
|
|
|
|
|
|
|
|
if( radius < MIN_HIT_TEST_RADIUS )
|
|
|
|
radius = MIN_HIT_TEST_RADIUS;
|
|
|
|
|
|
|
|
return TestSegmentHit( aRefPos, start, end, radius );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
2020-03-27 15:15:39 +00:00
|
|
|
|
2018-02-28 03:17:42 +00:00
|
|
|
case GBR_ARC:
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2024-05-31 19:22:16 +00:00
|
|
|
double radius = m_Start.Distance( m_ArcCentre );
|
2021-07-16 20:13:26 +00:00
|
|
|
VECTOR2D test_radius = VECTOR2D( ref_pos ) - VECTOR2D( m_ArcCentre );
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
int size = ( ( m_Size.x < MIN_HIT_TEST_RADIUS ) ? MIN_HIT_TEST_RADIUS : m_Size.x );
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// Are we close enough to the radius?
|
|
|
|
bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < size );
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( radius_hit )
|
|
|
|
{
|
|
|
|
// Now check that we are within the arc angle
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
VECTOR2D start = VECTOR2D( m_Start ) - VECTOR2D( m_ArcCentre );
|
|
|
|
VECTOR2D end = VECTOR2D( m_End ) - VECTOR2D( m_ArcCentre );
|
|
|
|
EDA_ANGLE start_angle( start );
|
|
|
|
EDA_ANGLE end_angle( end );
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
start_angle.Normalize();
|
|
|
|
end_angle.Normalize();
|
2018-02-28 03:17:42 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( m_Start == m_End )
|
|
|
|
{
|
2022-01-15 00:20:02 +00:00
|
|
|
start_angle = ANGLE_0;
|
|
|
|
end_angle = ANGLE_360;
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
|
|
|
else if( end_angle < start_angle )
|
|
|
|
{
|
2022-01-15 00:20:02 +00:00
|
|
|
end_angle += ANGLE_360;
|
2018-02-28 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
EDA_ANGLE test_angle( test_radius );
|
|
|
|
test_angle.Normalize();
|
2021-07-16 20:13:26 +00:00
|
|
|
|
|
|
|
return ( test_angle > start_angle && test_angle < end_angle );
|
2018-02-28 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
case GBR_SPOT_MACRO:
|
2023-02-11 11:00:02 +00:00
|
|
|
return m_AbsolutePolygon.Contains( VECTOR2I( aRefPos ), -1, aAccuracy );
|
2017-09-17 22:43:20 +00:00
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
case GBR_SEGMENT:
|
|
|
|
case GBR_CIRCLE:
|
|
|
|
case GBR_SPOT_CIRCLE:
|
|
|
|
break; // handled below.
|
|
|
|
}
|
|
|
|
|
2017-10-23 09:32:05 +00:00
|
|
|
// TODO: a better analyze of the shape (perhaps create a D_CODE::HitTest for flashed items)
|
|
|
|
int radius = std::min( m_Size.x, m_Size.y ) >> 1;
|
|
|
|
|
2018-03-30 02:04:51 +00:00
|
|
|
if( radius < MIN_HIT_TEST_RADIUS )
|
|
|
|
radius = MIN_HIT_TEST_RADIUS;
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
if( m_Flashed )
|
2024-05-31 19:22:16 +00:00
|
|
|
return m_Start.Distance( ref_pos ) <= radius;
|
2010-09-28 14:42:05 +00:00
|
|
|
else
|
2012-12-27 16:42:41 +00:00
|
|
|
return TestSegmentHit( ref_pos, m_Start, m_End, radius );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool GERBER_DRAW_ITEM::HitTest( const BOX2I& aRefArea, bool aContained, int aAccuracy ) const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = GetABPosition( m_Start );
|
2010-10-16 14:51:22 +00:00
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
if( aRefArea.Contains( pos ) )
|
2010-09-28 14:42:05 +00:00
|
|
|
return true;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
pos = GetABPosition( m_End );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
if( aRefArea.Contains( pos ) )
|
2010-09-28 14:42:05 +00:00
|
|
|
return true;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void GERBER_DRAW_ITEM::Show( int nestLevel, std::ostream& os ) const
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2023-02-10 09:04:52 +00:00
|
|
|
" shape=\"" << m_ShapeType << '"' <<
|
2020-11-14 18:11:28 +00:00
|
|
|
" addr=\"" << std::hex << this << std::dec << '"' <<
|
|
|
|
" layer=\"" << GetLayer() << '"' <<
|
|
|
|
" size=\"" << m_Size << '"' <<
|
|
|
|
" flags=\"" << m_flags << '"' <<
|
2010-09-28 14:42:05 +00:00
|
|
|
"<start" << m_Start << "/>" <<
|
|
|
|
"<end" << m_End << "/>";
|
|
|
|
|
|
|
|
os << "</" << GetClass().Lower().mb_str() << ">\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-09-17 22:43:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
void GERBER_DRAW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2017-09-20 19:56:22 +00:00
|
|
|
aCount = 2;
|
2017-09-18 01:54:02 +00:00
|
|
|
|
2017-09-20 19:56:22 +00:00
|
|
|
aLayers[0] = GERBER_DRAW_LAYER( GetLayer() );
|
|
|
|
aLayers[1] = GERBER_DCODE_LAYER( aLayers[0] );
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const BOX2I GERBER_DRAW_ITEM::ViewBBox() const
|
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
return GetBoundingBox();
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-21 15:03:08 +00:00
|
|
|
double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2017-11-13 08:11:54 +00:00
|
|
|
// DCodes will be shown only if zoom is appropriate:
|
|
|
|
// Returns the level of detail of the item.
|
|
|
|
// A level of detail (LOD) is the minimal VIEW scale that
|
|
|
|
// is sufficient for an item to be shown on a given layer.
|
2017-09-17 22:43:20 +00:00
|
|
|
if( IsDCodeLayer( aLayer ) )
|
|
|
|
{
|
2017-11-12 16:44:00 +00:00
|
|
|
int size = 0;
|
|
|
|
|
2023-02-10 09:04:52 +00:00
|
|
|
switch( m_ShapeType )
|
2017-11-12 16:44:00 +00:00
|
|
|
{
|
|
|
|
case GBR_SPOT_MACRO:
|
2023-01-18 15:35:09 +00:00
|
|
|
size = GetDcodeDescr()->m_Polygon.BBox().GetWidth();
|
2017-11-12 16:44:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBR_ARC:
|
2024-05-31 19:22:16 +00:00
|
|
|
size = m_Start.Distance( m_ArcCentre );
|
2017-11-12 16:44:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
size = m_Size.x;
|
|
|
|
}
|
|
|
|
|
2017-11-13 08:11:54 +00:00
|
|
|
// the level of details is chosen experimentally, to show
|
|
|
|
// only a readable text:
|
2022-09-16 11:33:56 +00:00
|
|
|
double level = (double) gerbIUScale.mmToIU( 3 );
|
2020-09-21 15:03:08 +00:00
|
|
|
return level / ( size + 1 );
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Other layers are shown without any conditions
|
2020-09-21 15:03:08 +00:00
|
|
|
return 0.0;
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
INSPECT_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
for( KICAD_T scanType : aScanTypes )
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == Type() )
|
|
|
|
{
|
|
|
|
if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
|
|
|
}
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
return INSPECT_RESULT::CONTINUE;
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString GERBER_DRAW_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2017-09-17 22:43:20 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
wxString layerName = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true );
|
2017-09-17 22:43:20 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "%s (D%d) on layer %d: %s" ),
|
|
|
|
ShowGBRShape(),
|
|
|
|
m_DCode,
|
|
|
|
GetLayer() + 1,
|
|
|
|
layerName );
|
2017-09-17 22:43:20 +00:00
|
|
|
}
|