2023-01-20 08:45:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2017 Jean-Pierre Charras <jp.charras at wanadoo.fr>
|
|
|
|
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file aperture_macro.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <gerbview.h>
|
|
|
|
#include <aperture_macro.h>
|
2023-02-10 15:10:29 +00:00
|
|
|
#include <gerber_draw_item.h>
|
2023-01-20 08:45:03 +00:00
|
|
|
|
|
|
|
|
2023-01-28 15:39:48 +00:00
|
|
|
void APERTURE_MACRO::AddPrimitiveToList( AM_PRIMITIVE& aPrimitive )
|
|
|
|
{
|
|
|
|
m_primitivesList.push_back( aPrimitive );
|
|
|
|
m_primitivesList.back().m_LocalParamLevel = m_localParamStack.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void APERTURE_MACRO::AddLocalParamDefToStack()
|
|
|
|
{
|
|
|
|
m_localParamStack.push_back( AM_PARAM() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AM_PARAM& APERTURE_MACRO::GetLastLocalParamDefFromStack()
|
|
|
|
{
|
|
|
|
return m_localParamStack.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-20 08:45:03 +00:00
|
|
|
SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent,
|
|
|
|
const VECTOR2I& aShapePos )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET holeBuffer;
|
|
|
|
|
|
|
|
m_shape.RemoveAllContours();
|
2023-02-10 15:10:29 +00:00
|
|
|
D_CODE * dcode = aParent->GetDcodeDescr();
|
2023-01-20 08:45:03 +00:00
|
|
|
|
2023-01-28 15:39:48 +00:00
|
|
|
for( AM_PRIMITIVE& prim_macro : m_primitivesList )
|
2023-01-20 08:45:03 +00:00
|
|
|
{
|
|
|
|
if( prim_macro.m_Primitive_id == AMP_COMMENT )
|
|
|
|
continue;
|
|
|
|
|
2023-02-10 15:10:29 +00:00
|
|
|
if( prim_macro.IsAMPrimitiveExposureOn( dcode ) )
|
2023-01-20 08:45:03 +00:00
|
|
|
{
|
2023-02-10 15:10:29 +00:00
|
|
|
prim_macro.ConvertBasicShapeToPolygon( dcode, m_shape );
|
2023-01-20 08:45:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-10 15:10:29 +00:00
|
|
|
prim_macro.ConvertBasicShapeToPolygon( dcode, holeBuffer );
|
2023-01-20 08:45:03 +00:00
|
|
|
|
|
|
|
if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
|
|
|
|
{
|
|
|
|
m_shape.BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
holeBuffer.RemoveAllContours();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge and cleanup basic shape polygons
|
|
|
|
m_shape.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
// A hole can be is defined inside a polygon, or the polygons themselve can create
|
|
|
|
// a hole when merged, so we must fracture the polygon to be able to drawn it
|
|
|
|
// (i.e link holes by overlapping edges)
|
|
|
|
m_shape.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2023-02-10 15:10:29 +00:00
|
|
|
// Move m_shape to the actual draw position:
|
|
|
|
for( int icnt = 0; icnt < m_shape.OutlineCount(); icnt++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN& outline = m_shape.Outline( icnt );
|
|
|
|
|
|
|
|
for( int jj = 0; jj < outline.PointCount(); jj++ )
|
|
|
|
{
|
|
|
|
VECTOR2I point = outline.CPoint( jj );
|
|
|
|
point += aShapePos;
|
|
|
|
point = aParent->GetABPosition( point );
|
|
|
|
outline.SetPoint( jj, point );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 08:45:03 +00:00
|
|
|
return &m_shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double APERTURE_MACRO::GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) const
|
|
|
|
{
|
|
|
|
// find parameter descr.
|
|
|
|
const AM_PARAM * param = nullptr;
|
|
|
|
|
2023-01-28 15:39:48 +00:00
|
|
|
for( unsigned ii = 0; ii < m_localParamStack.size(); ii ++ )
|
2023-01-20 08:45:03 +00:00
|
|
|
{
|
2023-01-28 15:39:48 +00:00
|
|
|
if( m_localParamStack[ii].GetIndex() == aParamId )
|
2023-01-20 08:45:03 +00:00
|
|
|
{
|
2023-01-28 15:39:48 +00:00
|
|
|
param = &m_localParamStack[ii];
|
2023-01-20 08:45:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( param == nullptr ) // not found
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
// Evaluate parameter
|
|
|
|
double value = param->GetValue( aDcode );
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|