2017-02-26 17:45:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2022-12-09 16:11:56 +00:00
|
|
|
* Copyright (C) 2017-2022 Kicad Developers, see AUTHORS.txt for contributors.
|
2017-02-26 17:45:52 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <preview_items/polygon_item.h>
|
2019-08-31 14:35:33 +00:00
|
|
|
#include <painter.h>
|
2017-02-26 17:45:52 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
|
|
|
|
using namespace KIGFX::PREVIEW;
|
|
|
|
|
2020-07-01 16:14:47 +00:00
|
|
|
const double POLYGON_ITEM::POLY_LINE_WIDTH = 1;
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2020-11-07 21:21:56 +00:00
|
|
|
POLYGON_ITEM::POLYGON_ITEM() :
|
2017-02-26 17:45:52 +00:00
|
|
|
SIMPLE_OVERLAY_ITEM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-19 10:20:52 +00:00
|
|
|
|
|
|
|
void POLYGON_ITEM::SetPoints( const SHAPE_LINE_CHAIN& aLockedInPts,
|
2022-12-09 16:11:56 +00:00
|
|
|
const SHAPE_LINE_CHAIN& aLeaderPts, const SHAPE_LINE_CHAIN& aLoopPts )
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2018-02-19 10:20:52 +00:00
|
|
|
m_lockedChain = aLockedInPts;
|
|
|
|
m_leaderChain = aLeaderPts;
|
2022-12-09 16:11:56 +00:00
|
|
|
m_loopChain = aLoopPts;
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
m_polyfill.RemoveAllContours();
|
|
|
|
m_polyfill.NewOutline();
|
|
|
|
|
2018-02-19 10:20:52 +00:00
|
|
|
for( int i = 0; i < aLockedInPts.PointCount(); ++i )
|
|
|
|
m_polyfill.Append( aLockedInPts.CPoint( i ) );
|
|
|
|
|
|
|
|
for( int i = 0; i < aLeaderPts.PointCount(); ++i )
|
|
|
|
m_polyfill.Append( aLeaderPts.CPoint( i ) );
|
2022-12-09 16:11:56 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < aLoopPts.PointCount(); ++i )
|
|
|
|
m_polyfill.Append( aLoopPts.CPoint( i ) );
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
void POLYGON_ITEM::drawPreviewShape( KIGFX::VIEW* aView ) const
|
2017-02-26 17:45:52 +00:00
|
|
|
{
|
2020-11-07 21:21:56 +00:00
|
|
|
KIGFX::GAL& gal = *aView->GetGAL();
|
|
|
|
RENDER_SETTINGS* renderSettings = aView->GetPainter()->GetSettings();
|
2017-08-04 12:43:02 +00:00
|
|
|
|
2020-08-22 22:45:39 +00:00
|
|
|
if( m_lockedChain.PointCount() >= 2 )
|
|
|
|
{
|
|
|
|
gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) );
|
|
|
|
gal.DrawPolyline( m_lockedChain );
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
// draw the leader line in a different color
|
2020-08-22 22:45:39 +00:00
|
|
|
if( m_leaderChain.PointCount() >= 2 )
|
|
|
|
{
|
2020-11-07 21:21:56 +00:00
|
|
|
gal.SetStrokeColor( renderSettings->GetLayerColor( LAYER_AUX_ITEMS ) );
|
2020-08-22 22:45:39 +00:00
|
|
|
gal.DrawPolyline( m_leaderChain );
|
|
|
|
}
|
|
|
|
|
2022-12-09 16:11:56 +00:00
|
|
|
gal.SetIsStroke( false );
|
|
|
|
|
2020-08-22 22:45:39 +00:00
|
|
|
for( int j = 0; j < m_polyfill.OutlineCount(); ++j )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& outline = m_polyfill.COutline( j );
|
|
|
|
|
|
|
|
if( outline.PointCount() >= 2 )
|
|
|
|
gal.DrawPolygon( outline );
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const BOX2I POLYGON_ITEM::ViewBBox() const
|
|
|
|
{
|
|
|
|
return m_polyfill.BBox();
|
|
|
|
}
|