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
|
|
|
|
* Copyright (C) 2018 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
|
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2018-01-29 10:37:29 +00:00
|
|
|
#include "base_screen.h"
|
2009-07-06 18:02:26 +00:00
|
|
|
#include "common.h"
|
2009-07-07 17:50:02 +00:00
|
|
|
#include "macros.h"
|
2018-01-28 21:02:31 +00:00
|
|
|
#include "marker_base.h"
|
2018-12-19 18:53:27 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2009-07-13 15:25:41 +00:00
|
|
|
#include "dialog_display_info_HTML_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
|
|
|
|
|
|
|
/*******************/
|
|
|
|
/* Classe MARKER_BASE */
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
void MARKER_BASE::init()
|
|
|
|
{
|
2015-07-29 12:18:53 +00:00
|
|
|
m_MarkerType = MARKER_UNSPEC;
|
2015-07-29 18:06:45 +00:00
|
|
|
m_ErrorLevel = MARKER_SEVERITY_UNSPEC;
|
2009-07-07 17:50:02 +00:00
|
|
|
m_Color = RED;
|
2018-12-19 14:07:07 +00:00
|
|
|
const VECTOR2I* point_shape = GetShapePolygon();
|
|
|
|
wxPoint start( point_shape->x, point_shape->y );
|
|
|
|
wxPoint end = start;
|
2014-03-12 14:53:20 +00:00
|
|
|
|
2018-12-19 14:07:07 +00:00
|
|
|
for( int ii = 1; ii < GetShapePolygonCornerCount(); ii++ )
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
2018-12-19 14:07:07 +00:00
|
|
|
++point_shape;
|
|
|
|
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
|
|
|
|
|
|
|
m_ShapeBoundingBox.SetOrigin(start);
|
|
|
|
m_ShapeBoundingBox.SetEnd(end);
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( const MARKER_BASE& aMarker )
|
|
|
|
{
|
|
|
|
m_Pos = aMarker.m_Pos;
|
2015-08-01 10:20:23 +00:00
|
|
|
m_ErrorLevel = aMarker.m_ErrorLevel;
|
2010-12-21 15:13:09 +00:00
|
|
|
m_MarkerType = aMarker.m_MarkerType;
|
|
|
|
m_Color = aMarker.m_Color;
|
|
|
|
m_ShapeBoundingBox = aMarker.m_ShapeBoundingBox;
|
|
|
|
m_ScalingFactor = aMarker.m_ScalingFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-19 18:53:27 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( int aScalingFactor )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
2018-12-19 18:53:27 +00:00
|
|
|
m_ScalingFactor = aScalingFactor;
|
2009-07-06 18:02:26 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-15 04:49:50 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
|
2018-01-28 09:35:33 +00:00
|
|
|
EDA_ITEM* aItem, const wxPoint& aPos,
|
2018-12-19 18:53:27 +00:00
|
|
|
EDA_ITEM* bItem, const wxPoint& bPos, int aScalingFactor )
|
2018-01-28 09:35:33 +00:00
|
|
|
{
|
2018-12-19 18:53:27 +00:00
|
|
|
m_ScalingFactor = aScalingFactor;
|
2018-01-28 09:35:33 +00:00
|
|
|
init();
|
|
|
|
|
2018-06-15 04:49:50 +00:00
|
|
|
SetData( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos );
|
2018-01-28 09:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
|
2009-07-07 17:50:02 +00:00
|
|
|
const wxString& aText, const wxPoint& aPos,
|
2018-12-19 18:53:27 +00:00
|
|
|
const wxString& bText, const wxPoint& bPos, int aScalingFactor )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
2018-12-19 18:53:27 +00:00
|
|
|
m_ScalingFactor = aScalingFactor;
|
2009-07-06 18:02:26 +00:00
|
|
|
init();
|
|
|
|
|
2018-01-28 09:35:33 +00:00
|
|
|
SetData( aErrorCode, aMarkerPos, aText, aPos, bText, bPos );
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
|
2018-12-19 18:53:27 +00:00
|
|
|
const wxString& aText, const wxPoint& aPos, int aScalingFactor )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
2018-12-19 18:53:27 +00:00
|
|
|
m_ScalingFactor = aScalingFactor;
|
2009-07-06 18:02:26 +00:00
|
|
|
init();
|
2018-06-15 04:49:50 +00:00
|
|
|
|
2009-07-06 18:02:26 +00:00
|
|
|
SetData( aErrorCode, aMarkerPos, aText, aPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MARKER_BASE::~MARKER_BASE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-15 04:49:50 +00:00
|
|
|
void MARKER_BASE::SetData( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
|
2018-01-28 09:35:33 +00:00
|
|
|
EDA_ITEM* aItem, const wxPoint& aPos,
|
|
|
|
EDA_ITEM* bItem, const wxPoint& bPos )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
|
|
|
m_Pos = aMarkerPos;
|
2018-06-15 04:49:50 +00:00
|
|
|
m_drc.SetData( aUnits, aErrorCode, aItem, aPos, bItem, bPos );
|
2018-03-20 02:25:55 +00:00
|
|
|
m_drc.SetParent( this );
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
|
2018-01-28 09:35:33 +00:00
|
|
|
const wxString& aText, const wxPoint& aPos,
|
|
|
|
const wxString& bText, const wxPoint& bPos )
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
|
|
|
m_Pos = aMarkerPos;
|
2018-01-28 09:35:33 +00:00
|
|
|
m_drc.SetData( aErrorCode, aText, aPos, bText, bPos );
|
2018-03-20 02:25:55 +00:00
|
|
|
m_drc.SetParent( this );
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool MARKER_BASE::HitTestMarker( const wxPoint& aHitPosition, int aAccuracy ) const
|
2018-12-19 14:07:07 +00:00
|
|
|
{
|
|
|
|
EDA_RECT 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MARKER_BASE::ShapeToPolygon( SHAPE_LINE_CHAIN& aPolygon) const
|
|
|
|
{
|
|
|
|
// Build the marker shape polygon in internal units:
|
|
|
|
const int ccount = GetShapePolygonCornerCount();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < ccount; ii++ )
|
|
|
|
aPolygon.Append( GetShapePolygonCorner( ii ) * MarkerScale() );
|
|
|
|
|
|
|
|
// Be sure aPolygon is seen as a closed polyline:
|
|
|
|
aPolygon.SetClosed( true );
|
2018-12-19 14:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const VECTOR2I* MARKER_BASE::GetShapePolygon() const
|
2009-07-06 18:02:26 +00:00
|
|
|
{
|
2018-12-19 14:07:07 +00:00
|
|
|
return MarkerShapeCorners;
|
|
|
|
}
|
|
|
|
|
2009-07-09 17:02:15 +00:00
|
|
|
|
2018-12-19 14:07:07 +00:00
|
|
|
const VECTOR2I& MARKER_BASE::GetShapePolygonCorner( int aIdx ) const
|
|
|
|
{
|
|
|
|
return MarkerShapeCorners[aIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MARKER_BASE::GetShapePolygonCornerCount() const
|
|
|
|
{
|
|
|
|
return CORNERS_COUNT;
|
2009-07-06 18:02:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT MARKER_BASE::GetBoundingBoxMarker() const
|
2009-07-08 15:42:45 +00:00
|
|
|
{
|
2018-12-19 14:07:07 +00:00
|
|
|
wxSize size_iu = m_ShapeBoundingBox.GetSize();
|
|
|
|
wxPoint position_iu = m_ShapeBoundingBox.GetPosition();
|
|
|
|
size_iu.x *= m_ScalingFactor;
|
|
|
|
size_iu.y *= m_ScalingFactor;
|
|
|
|
position_iu.x *= m_ScalingFactor;
|
|
|
|
position_iu.y *= m_ScalingFactor;
|
|
|
|
position_iu += m_Pos;
|
|
|
|
|
|
|
|
return EDA_RECT( position_iu, size_iu );
|
2009-07-08 15:42:45 +00:00
|
|
|
}
|
2009-07-06 18:02:26 +00:00
|
|
|
|
2009-07-13 15:25:41 +00:00
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void MARKER_BASE::DisplayMarkerInfo( EDA_DRAW_FRAME* aFrame )
|
2009-07-13 15:25:41 +00:00
|
|
|
{
|
2018-06-15 04:49:50 +00:00
|
|
|
wxString msg = m_drc.ShowHtml( aFrame->GetUserUnits() );
|
2010-12-21 15:13:09 +00:00
|
|
|
DIALOG_DISPLAY_HTML_TEXT_BASE infodisplay( (wxWindow*)aFrame, wxID_ANY, _( "Marker Info" ),
|
|
|
|
wxGetMousePosition(), wxSize( 550, 140 ) );
|
2009-07-13 15:25:41 +00:00
|
|
|
|
|
|
|
infodisplay.m_htmlWindow->SetPage( msg );
|
|
|
|
infodisplay.ShowModal();
|
|
|
|
}
|
2019-05-31 12:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MARKER_BASE::PrintMarker( wxDC* aDC, const wxPoint& aOffset )
|
|
|
|
{
|
|
|
|
// Build the marker shape polygon in internal units:
|
|
|
|
const int ccount = GetShapePolygonCornerCount();
|
|
|
|
std::vector<wxPoint> shape;
|
|
|
|
shape.reserve( ccount );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < ccount; ii++ )
|
|
|
|
{
|
|
|
|
shape.push_back( wxPoint( GetShapePolygonCorner( ii ).x * MarkerScale(),
|
|
|
|
GetShapePolygonCorner( ii ).y * MarkerScale() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int ii = 0; ii < ccount; ii++ )
|
|
|
|
shape[ii] += m_Pos + aOffset;
|
|
|
|
|
|
|
|
GRClosedPoly( nullptr, aDC, ccount, &shape[0], true, 0, m_Color, m_Color );
|
|
|
|
}
|