2015-06-18 15:51:53 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 CERN
|
2020-01-19 04:42:10 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-06-18 15:51:53 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-01-19 11:52:34 +00:00
|
|
|
#include <array>
|
2019-06-08 22:14:57 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2020-01-19 11:52:34 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2020-01-19 04:42:10 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2015-06-18 15:51:53 +00:00
|
|
|
#include <origin_viewitem.h>
|
|
|
|
|
|
|
|
using namespace KIGFX;
|
|
|
|
|
|
|
|
ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
|
2020-09-09 02:54:17 +00:00
|
|
|
EDA_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD/SCHEMATIC so it needs no type
|
2019-10-31 00:05:57 +00:00
|
|
|
m_position( aPosition ),
|
|
|
|
m_size( aSize ),
|
|
|
|
m_color( aColor ),
|
|
|
|
m_style( aStyle ),
|
|
|
|
m_drawAtZero( false )
|
2015-06-18 15:51:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const VECTOR2D& aPosition, EDA_ITEM_FLAGS flags ) :
|
2020-09-09 02:54:17 +00:00
|
|
|
EDA_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD/SCHEMATIC so it needs no type
|
2019-10-31 00:05:57 +00:00
|
|
|
m_position( aPosition ),
|
|
|
|
m_size( NOT_USED ),
|
|
|
|
m_color( UNSPECIFIED_COLOR ),
|
|
|
|
m_style( NO_GRAPHIC ),
|
|
|
|
m_drawAtZero( false )
|
2018-01-24 21:27:56 +00:00
|
|
|
{
|
|
|
|
SetFlags( flags );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-24 10:19:33 +00:00
|
|
|
ORIGIN_VIEWITEM* ORIGIN_VIEWITEM::Clone() const
|
|
|
|
{
|
|
|
|
return new ORIGIN_VIEWITEM( m_color, m_style, m_size, m_position );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 15:51:53 +00:00
|
|
|
const BOX2I ORIGIN_VIEWITEM::ViewBBox() const
|
|
|
|
{
|
|
|
|
BOX2I bbox;
|
2018-08-06 23:55:00 +00:00
|
|
|
bbox.SetMaximum();
|
2015-06-18 15:51:53 +00:00
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
|
2015-06-18 15:51:53 +00:00
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
GAL* gal = aView->GetGAL();
|
2019-06-01 11:11:05 +00:00
|
|
|
|
|
|
|
// Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is.
|
2015-09-05 19:47:35 +00:00
|
|
|
if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
|
2015-06-18 15:51:53 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->SetIsStroke( true );
|
|
|
|
gal->SetIsFill( false );
|
|
|
|
gal->SetLineWidth( 1 );
|
|
|
|
gal->SetStrokeColor( m_color );
|
|
|
|
VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
|
2015-09-05 19:47:35 +00:00
|
|
|
|
|
|
|
// Draw a circle around the marker's centre point if the style demands it
|
|
|
|
if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
|
2016-12-08 21:55:06 +00:00
|
|
|
gal->DrawCircle( m_position, fabs( scaledSize.x ) );
|
2015-06-18 15:51:53 +00:00
|
|
|
|
|
|
|
switch( m_style )
|
|
|
|
{
|
2019-10-31 00:05:57 +00:00
|
|
|
case NO_GRAPHIC:
|
2015-06-18 15:51:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CROSS:
|
2015-09-05 19:47:35 +00:00
|
|
|
case CIRCLE_CROSS:
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
|
2015-09-05 19:47:35 +00:00
|
|
|
m_position + VECTOR2D( scaledSize.x, 0 ) );
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
|
2015-09-05 19:47:35 +00:00
|
|
|
m_position + VECTOR2D( 0, scaledSize.y ) );
|
2015-06-18 15:51:53 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-19 04:42:10 +00:00
|
|
|
case DASH_LINE:
|
|
|
|
{
|
|
|
|
gal->DrawCircle( m_position, scaledSize.x / 4 );
|
|
|
|
|
|
|
|
VECTOR2D start( m_position );
|
|
|
|
VECTOR2D end( m_end );
|
2022-01-04 01:00:40 +00:00
|
|
|
EDA_RECT clip( VECTOR2I( start ), VECTOR2I( end.x - start.x, end.y - start.y ) );
|
2020-01-19 04:42:10 +00:00
|
|
|
clip.Normalize();
|
|
|
|
|
|
|
|
double theta = atan2( end.y - start.y, end.x - start.x );
|
2020-09-09 02:54:17 +00:00
|
|
|
std::array<double,2> strokes = { scaledSize.x, scaledSize.x / 2 };
|
2020-01-19 04:42:10 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < 10000; ++i )
|
|
|
|
{
|
|
|
|
VECTOR2D next( start.x + strokes[ i % 2 ] * cos( theta ),
|
|
|
|
start.y + strokes[ i % 2 ] * sin( theta ) );
|
|
|
|
|
|
|
|
// Drawing each segment can be done rounded to ints.
|
2022-01-04 01:00:40 +00:00
|
|
|
VECTOR2I segStart( KiROUND( start.x ), KiROUND( start.y ) );
|
|
|
|
VECTOR2I segEnd( KiROUND( next.x ), KiROUND( next.y ) );
|
2020-01-19 04:42:10 +00:00
|
|
|
|
|
|
|
if( ClipLine( &clip, segStart.x, segStart.y, segEnd.x, segEnd.y ) )
|
|
|
|
break;
|
|
|
|
else if( i % 2 == 0 )
|
|
|
|
gal->DrawLine( segStart, segEnd );
|
|
|
|
|
|
|
|
start = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
gal->DrawCircle( m_end, scaledSize.x / 4 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-18 15:51:53 +00:00
|
|
|
case X:
|
2015-09-05 19:47:35 +00:00
|
|
|
case CIRCLE_X:
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
|
2015-06-18 15:51:53 +00:00
|
|
|
scaledSize.y = -scaledSize.y;
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
|
2015-06-18 15:51:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DOT:
|
2015-09-05 19:47:35 +00:00
|
|
|
case CIRCLE_DOT:
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->DrawCircle( m_position, scaledSize.x / 4 );
|
2015-06-18 15:51:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|