2021-07-17 19:56:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2004-2021 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sch_draw_panel.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <plotters/plotter.h>
|
|
|
|
#include <base_units.h>
|
|
|
|
#include <widgets/msgpanel.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <eda_draw_frame.h>
|
|
|
|
#include <general.h>
|
2022-01-11 17:39:25 +00:00
|
|
|
#include <schematic.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <sch_shape.h>
|
|
|
|
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_SHAPE::SCH_SHAPE( SHAPE_T aShape, int aLineWidth, FILL_T aFillType, KICAD_T aType ) :
|
|
|
|
SCH_ITEM( nullptr, aType ),
|
2022-01-16 23:54:59 +00:00
|
|
|
EDA_SHAPE( aShape, aLineWidth, aFillType, false )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
SetLayer( LAYER_NOTES );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* SCH_SHAPE::Clone() const
|
|
|
|
{
|
|
|
|
return new SCH_SHAPE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-11 18:33:30 +00:00
|
|
|
void SCH_SHAPE::SwapData( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
|
|
|
|
|
|
|
|
EDA_SHAPE::SwapShape( shape );
|
|
|
|
std::swap( m_layer, shape->m_layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
void SCH_SHAPE::SetStroke( const STROKE_PARAMS& aStroke )
|
|
|
|
{
|
|
|
|
m_stroke = aStroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_SHAPE::Move( const VECTOR2I& aOffset )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
move( aOffset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::MirrorHorizontally( int aCenter )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
flip( VECTOR2I( aCenter, 0 ), true );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::MirrorVertically( int aCenter )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
flip( VECTOR2I( 0, aCenter ), false );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_SHAPE::Rotate( const VECTOR2I& aCenter )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-01-25 22:33:37 +00:00
|
|
|
rotate( aCenter, -ANGLE_90 );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::Plot( PLOTTER* aPlotter ) const
|
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
int pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
static std::vector<VECTOR2I> cornerList;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
cornerList.clear();
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
|
2022-01-01 18:08:03 +00:00
|
|
|
cornerList.push_back( pt );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( GetStroke().GetColor() == COLOR4D::UNSPECIFIED )
|
|
|
|
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOTES ) );
|
|
|
|
else
|
|
|
|
aPlotter->SetColor( GetStroke().GetColor() );
|
|
|
|
|
|
|
|
aPlotter->SetCurrentLineWidth( pen_size );
|
2022-01-14 15:40:24 +00:00
|
|
|
aPlotter->SetDash( GetEffectiveLineStyle() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Arc( getCenter(), GetStart(), GetEnd(), FILL_T::NO_FILL, pen_size, ARC_HIGH_DEF );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Circle( getCenter(), GetRadius() * 2, FILL_T::NO_FILL, pen_size );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts = GetRectCorners();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
aPlotter->MoveTo( pts[0] );
|
|
|
|
aPlotter->LineTo( pts[1] );
|
|
|
|
aPlotter->LineTo( pts[2] );
|
|
|
|
aPlotter->LineTo( pts[3] );
|
|
|
|
aPlotter->FinishTo( pts[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
{
|
|
|
|
aPlotter->MoveTo( cornerList[0] );
|
|
|
|
|
|
|
|
for( size_t ii = 1; ii < cornerList.size(); ++ii )
|
|
|
|
aPlotter->LineTo( cornerList[ii] );
|
|
|
|
|
|
|
|
aPlotter->FinishTo( cornerList[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
aPlotter->PlotPoly( m_bezierPoints, FILL_T::NO_FILL, pen_size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID );
|
|
|
|
|
|
|
|
if( m_fill == FILL_T::FILLED_WITH_COLOR && GetFillColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
|
|
|
aPlotter->SetColor( GetFillColor() );
|
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Arc( getCenter(), GetStart(), GetEnd(), m_fill, 0, ARC_HIGH_DEF );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Circle( getCenter(), GetRadius() * 2, m_fill, 0 );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
aPlotter->Rect( GetStart(), GetEnd(), m_fill, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
aPlotter->PlotPoly( cornerList, m_fill, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
aPlotter->PlotPoly( m_bezierPoints, m_fill, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SHAPE::GetPenWidth() const
|
|
|
|
{
|
2022-01-11 17:39:25 +00:00
|
|
|
if( m_stroke.GetWidth() > 0 )
|
2022-01-11 18:17:41 +00:00
|
|
|
return m_stroke.GetWidth();
|
2022-01-11 17:39:25 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
|
2022-01-31 19:11:21 +00:00
|
|
|
if( GetWidth() < 0 )
|
2021-07-17 19:56:18 +00:00
|
|
|
return 0;
|
2022-01-11 17:39:25 +00:00
|
|
|
|
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
|
|
|
|
if( schematic )
|
|
|
|
return schematic->Settings().m_DefaultLineWidth;
|
|
|
|
|
|
|
|
return Mils2iu( DEFAULT_LINE_WIDTH_MILS );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_SHAPE::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
int penWidth = GetPenWidth();
|
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pt1 = GetStart();
|
|
|
|
VECTOR2I pt2 = GetEnd();
|
|
|
|
VECTOR2I c;
|
2021-07-17 19:56:18 +00:00
|
|
|
COLOR4D color;
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
unsigned ptCount = 0;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I* buffer = nullptr;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN poly = m_poly.Outline( 0 );
|
|
|
|
|
|
|
|
ptCount = poly.GetPointCount();
|
2022-01-01 06:04:08 +00:00
|
|
|
buffer = new VECTOR2I[ptCount];
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < ptCount; ++ii )
|
2022-01-01 18:08:03 +00:00
|
|
|
buffer[ii] = poly.CPoint( ii );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
|
|
|
{
|
|
|
|
ptCount = m_bezierPoints.size();
|
2022-01-01 06:04:08 +00:00
|
|
|
buffer = new VECTOR2I[ptCount];
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < ptCount; ++ii )
|
|
|
|
buffer[ii] = m_bezierPoints[ii];
|
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
|
|
|
c = getCenter();
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE t1, t2;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
CalcArcAngles( t1, t2 );
|
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
if( ( t1 - t2 ).Normalize180() > ANGLE_0 )
|
2021-07-17 19:56:18 +00:00
|
|
|
std::swap( pt1, pt2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
|
|
|
{
|
|
|
|
color = GetFillColor();
|
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledArc( DC, pt1, pt2, c, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledCircle( DC, pt1, GetRadius(), 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledRect( DC, pt1, pt2, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, true, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, true, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetStroke().GetColor() == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_NOTES );
|
|
|
|
else
|
|
|
|
color = GetStroke().GetColor();
|
|
|
|
|
|
|
|
if( GetStroke().GetPlotStyle() <= PLOT_DASH_TYPE::FIRST_TYPE )
|
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRArc( DC, pt1, pt2, c, penWidth, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCircle( DC, pt1, GetRadius(), penWidth, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRRect( DC, pt1, pt2, penWidth, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, false, penWidth, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
2022-01-28 22:51:34 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, false, penWidth, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<SHAPE*> shapes = MakeEffectiveShapes( true );
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
{
|
|
|
|
STROKE_PARAMS::Stroke( shape, GetStroke().GetPlotStyle(), penWidth, aSettings,
|
2022-01-01 18:08:03 +00:00
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
|
|
|
|
|
|
|
|
ShapeGetMsgPanelInfo( aFrame, aList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_SHAPE::GetSelectMenuText( EDA_UNITS aUnits ) const
|
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
return wxString::Format( _( "Arc, radius %s" ),
|
|
|
|
MessageTextFromValue( aUnits, GetRadius() ) );
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
return wxString::Format( _( "Circle, radius %s" ),
|
|
|
|
MessageTextFromValue( aUnits, GetRadius() ) );
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
return wxString::Format( _( "Rectangle, width %s height %s" ),
|
|
|
|
MessageTextFromValue( aUnits, std::abs( m_start.x - m_end.x ) ),
|
|
|
|
MessageTextFromValue( aUnits, std::abs( m_start.y - m_end.y ) ) );
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
return wxString::Format( _( "Polyline, %d points" ),
|
|
|
|
int( m_poly.Outline( 0 ).GetPointCount() ) );
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
return wxString::Format( _( "Bezier Curve, %d points" ),
|
|
|
|
int( m_bezierPoints.size() ) );
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAPS SCH_SHAPE::GetMenuImage() const
|
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::SEGMENT: return BITMAPS::add_line;
|
|
|
|
case SHAPE_T::ARC: return BITMAPS::add_arc;
|
|
|
|
case SHAPE_T::CIRCLE: return BITMAPS::add_circle;
|
|
|
|
case SHAPE_T::RECT: return BITMAPS::add_rectangle;
|
|
|
|
case SHAPE_T::POLY: return BITMAPS::add_graphical_segments;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
return BITMAPS::question_mark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 3;
|
|
|
|
aLayers[0] = LAYER_NOTES;
|
|
|
|
aLayers[1] = LAYER_NOTES_BACKGROUND;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_SHAPE::AddPoint( const VECTOR2I& aPosition )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
if( m_poly.IsEmpty() )
|
|
|
|
m_poly.NewOutline();
|
|
|
|
|
|
|
|
m_poly.Outline( 0 ).Append( aPosition, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|