2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-01-28 21:02:31 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2022-01-28 22:51:34 +00:00
|
|
|
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-19 20:20:16 +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-30 18:15:37 +00:00
|
|
|
/**
|
2018-01-29 10:37:29 +00:00
|
|
|
* @file marker_base.cpp
|
2011-09-30 18:15:37 +00:00
|
|
|
* @brief Implementation of MARKER_BASE class.
|
|
|
|
* Markers are used to show something (usually a drc/erc problem).
|
|
|
|
* Markers in Pcbnew and Eeschema are derived from this base class.
|
|
|
|
*/
|
2009-07-06 18:02:26 +00:00
|
|
|
|
|
|
|
|
2018-01-29 10:37:29 +00:00
|
|
|
#include "base_screen.h"
|
2018-01-28 21:02:31 +00:00
|
|
|
#include "marker_base.h"
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2018-12-19 18:53:27 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include <render_settings.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include "dialogs/dialog_display_html_text_base.h"
|
2009-07-06 18:02:26 +00:00
|
|
|
|
|
|
|
|
2015-07-29 18:06:45 +00:00
|
|
|
/* The graphic shape of markers is a polygon.
|
|
|
|
* MarkerShapeCorners contains the coordinates of corners of the polygonal default shape
|
2018-12-19 14:07:07 +00:00
|
|
|
* they are arbitrary units to make coding shape easy.
|
|
|
|
* internal units coordinates are these values scaled by .m_ScalingFactor
|
|
|
|
*/
|
|
|
|
static const VECTOR2I MarkerShapeCorners[] =
|
|
|
|
{
|
|
|
|
VECTOR2I( 0, 0 ),
|
|
|
|
VECTOR2I( 8, 1 ),
|
|
|
|
VECTOR2I( 4, 3 ),
|
|
|
|
VECTOR2I( 13, 8 ),
|
|
|
|
VECTOR2I( 9, 9 ),
|
|
|
|
VECTOR2I( 8, 13 ),
|
|
|
|
VECTOR2I( 3, 4 ),
|
|
|
|
VECTOR2I( 1, 8 ),
|
|
|
|
VECTOR2I( 0, 0 )
|
2009-07-06 18:02:26 +00:00
|
|
|
};
|
2019-01-06 16:43:12 +00:00
|
|
|
const unsigned CORNERS_COUNT = arrayDim( MarkerShapeCorners );
|
2009-07-06 18:02:26 +00:00
|
|
|
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( int aScalingFactor, std::shared_ptr<RC_ITEM> aItem, TYPEMARKER aType ) :
|
2020-03-16 11:05:01 +00:00
|
|
|
m_markerType( aType ),
|
|
|
|
m_excluded( false ),
|
|
|
|
m_rcItem( aItem ),
|
|
|
|
m_scalingFactor( aScalingFactor )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const VECTOR2I* point_shape = MarkerShapeCorners;
|
2022-01-04 01:00:40 +00:00
|
|
|
VECTOR2I start( point_shape->x, point_shape->y );
|
|
|
|
VECTOR2I end = start;
|
2014-03-12 14:53:20 +00:00
|
|
|
|
2020-03-22 08:45:51 +00:00
|
|
|
for( unsigned ii = 1; ii < CORNERS_COUNT; ii++ )
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2018-12-19 14:07:07 +00:00
|
|
|
++point_shape;
|
2022-08-30 23:28:18 +00:00
|
|
|
start.x = std::min( start.x, point_shape->x );
|
|
|
|
start.y = std::min( start.y, point_shape->y );
|
|
|
|
end.x = std::max( end.x, point_shape->x );
|
|
|
|
end.y = std::max( end.y, point_shape->y );
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
2009-07-09 17:02:15 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
m_shapeBoundingBox.SetOrigin( start);
|
|
|
|
m_shapeBoundingBox.SetEnd( end);
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MARKER_BASE::~MARKER_BASE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool MARKER_BASE::HitTestMarker( const VECTOR2I& aHitPosition, int aAccuracy ) const
|
2018-12-19 14:07:07 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = GetBoundingBoxMarker();
|
2019-05-05 10:33:34 +00:00
|
|
|
bbox.Inflate( aAccuracy );
|
2018-12-19 14:07:07 +00:00
|
|
|
|
2018-12-19 18:53:27 +00:00
|
|
|
// Fast hit test using boundary box. A finer test will be made if requested
|
|
|
|
bool hit = bbox.Contains( aHitPosition );
|
|
|
|
|
|
|
|
if( hit ) // Fine test
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN polygon;
|
|
|
|
ShapeToPolygon( polygon );
|
|
|
|
VECTOR2I rel_pos( aHitPosition - m_Pos );
|
2019-05-05 10:33:34 +00:00
|
|
|
hit = polygon.PointInside( rel_pos, aAccuracy );
|
2018-12-19 18:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-12 22:24:35 +00:00
|
|
|
void MARKER_BASE::ShapeToPolygon( SHAPE_LINE_CHAIN& aPolygon, int aScale ) const
|
2018-12-19 18:53:27 +00:00
|
|
|
{
|
2020-10-12 22:24:35 +00:00
|
|
|
if( aScale < 0 )
|
|
|
|
aScale = MarkerScale();
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( const VECTOR2I& corner : MarkerShapeCorners )
|
2020-10-12 22:24:35 +00:00
|
|
|
aPolygon.Append( corner * aScale );
|
2018-12-19 18:53:27 +00:00
|
|
|
|
|
|
|
// Be sure aPolygon is seen as a closed polyline:
|
|
|
|
aPolygon.SetClosed( true );
|
2018-12-19 14:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I MARKER_BASE::GetBoundingBoxMarker() const
|
2009-07-08 15:42:45 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = m_shapeBoundingBox;
|
|
|
|
|
|
|
|
VECTOR2I pos = m_Pos;
|
|
|
|
pos += m_shapeBoundingBox.GetPosition() * m_scalingFactor;
|
|
|
|
|
|
|
|
return BOX2I( pos, bbox.GetSize() * m_scalingFactor );
|
2009-07-08 15:42:45 +00:00
|
|
|
}
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2009-07-13 15:25:41 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void MARKER_BASE::PrintMarker( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2019-05-31 12:15:25 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
// Build the marker shape polygon in internal units:
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> shape;
|
2020-03-16 11:05:01 +00:00
|
|
|
shape.reserve( CORNERS_COUNT );
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( const VECTOR2I& corner : MarkerShapeCorners )
|
|
|
|
shape.emplace_back( corner * MarkerScale() + m_Pos + aOffset );
|
2019-05-31 12:15:25 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRClosedPoly( DC, CORNERS_COUNT, &shape[0], true, getColor() );
|
2019-05-31 12:15:25 +00:00
|
|
|
}
|