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
|
2022-02-10 00:33:31 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-07-17 19:56:18 +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 <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>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <gr_basic.h>
|
2022-01-11 17:39:25 +00:00
|
|
|
#include <schematic.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <sch_shape.h>
|
|
|
|
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE::SCH_SHAPE( SHAPE_T aShape, SCH_LAYER_ID aLayer, int aLineWidth, FILL_T aFillType,
|
|
|
|
KICAD_T aType ) :
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_ITEM( nullptr, aType ),
|
2022-08-27 11:37:43 +00:00
|
|
|
EDA_SHAPE( aShape, aLineWidth, aFillType )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SetLayer( aLayer );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2023-07-08 17:37:47 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
|
|
|
|
2022-01-11 18:33:30 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-06 17:18:01 +00:00
|
|
|
void SCH_SHAPE::Normalize()
|
|
|
|
{
|
2023-07-24 16:07:56 +00:00
|
|
|
if( GetShape() == SHAPE_T::RECTANGLE )
|
2022-04-06 17:18:01 +00:00
|
|
|
{
|
|
|
|
VECTOR2I size = GetEnd() - GetPosition();
|
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
if( size.y < 0 )
|
2022-04-06 17:18:01 +00:00
|
|
|
{
|
|
|
|
SetStartY( GetStartY() + size.y );
|
|
|
|
SetEndY( GetStartY() - size.y );
|
|
|
|
}
|
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
if( size.x < 0 )
|
2022-04-06 17:18:01 +00:00
|
|
|
{
|
|
|
|
SetStartX( GetStartX() + size.x );
|
|
|
|
SetEndX( GetStartX() - size.x );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void SCH_SHAPE::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
rotate( aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
bool SCH_SHAPE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
return hitTest( aPosition, aAccuracy );
|
2024-04-15 20:18:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
bool SCH_SHAPE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
|
|
|
return false;
|
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
return hitTest( aRect, aContained, aAccuracy );
|
2024-04-15 20:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
|
|
|
|
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
|
|
|
|
int pen_size = GetEffectivePenWidth( renderSettings );
|
|
|
|
|
|
|
|
static std::vector<VECTOR2I> ptList;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
|
2024-04-15 20:18:54 +00:00
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
|
|
|
|
else
|
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2024-04-15 20:18:54 +00:00
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
2022-03-30 19:37:56 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
for( const VECTOR2I& pt : m_bezierPoints )
|
2022-02-10 19:49:25 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
|
2022-04-05 22:32:48 +00:00
|
|
|
else
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
COLOR4D color = GetStroke().GetColor();
|
|
|
|
COLOR4D bg = renderSettings->GetBackgroundColor();
|
|
|
|
LINE_STYLE lineStyle = GetStroke().GetLineStyle();
|
|
|
|
FILL_T fill = m_fill;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
if( aBackground )
|
|
|
|
{
|
|
|
|
if( !aPlotter->GetColorMode() )
|
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
switch( m_fill )
|
|
|
|
{
|
|
|
|
case FILL_T::FILLED_SHAPE:
|
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
case FILL_T::FILLED_WITH_COLOR:
|
|
|
|
color = GetFillColor();
|
|
|
|
break;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
|
|
|
|
color = renderSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
|
|
|
break;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
default:
|
|
|
|
return;
|
2022-02-10 19:49:25 +00:00
|
|
|
}
|
2024-04-15 20:18:54 +00:00
|
|
|
|
|
|
|
pen_size = 0;
|
|
|
|
lineStyle = LINE_STYLE::SOLID;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-02-10 19:49:25 +00:00
|
|
|
else /* if( aForeground ) */
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = renderSettings->GetLayerColor( m_layer );
|
|
|
|
|
|
|
|
if( lineStyle == LINE_STYLE::DEFAULT )
|
|
|
|
lineStyle = LINE_STYLE::SOLID;
|
|
|
|
|
|
|
|
if( m_fill == FILL_T::FILLED_SHAPE )
|
|
|
|
fill = m_fill;
|
2022-03-30 19:37:56 +00:00
|
|
|
else
|
2024-04-15 20:18:54 +00:00
|
|
|
fill = FILL_T::NO_FILL;
|
2022-03-30 19:37:56 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
pen_size = GetEffectivePenWidth( renderSettings );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
|
|
|
bg = COLOR4D::WHITE;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
color.Desaturate( );
|
|
|
|
color = color.Mix( bg, 0.5f );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
aPlotter->SetColor( color );
|
|
|
|
aPlotter->SetCurrentLineWidth( pen_size );
|
|
|
|
aPlotter->SetDash( pen_size, lineStyle );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
VECTOR2I start = m_start;
|
|
|
|
VECTOR2I end = m_end;
|
|
|
|
VECTOR2I mid, center;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
{
|
|
|
|
start = renderSettings->TransformCoordinate( start ) + aOffset;
|
|
|
|
end = renderSettings->TransformCoordinate( end ) + aOffset;
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
mid = GetArcMid();
|
|
|
|
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
mid = renderSettings->TransformCoordinate( mid ) + aOffset;
|
|
|
|
|
|
|
|
aPlotter->Arc( start, mid, end, fill, pen_size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
center = getCenter();
|
|
|
|
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
center = renderSettings->TransformCoordinate( center ) + aOffset;
|
|
|
|
|
|
|
|
aPlotter->Circle( center, GetRadius() * 2, fill, pen_size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECTANGLE:
|
|
|
|
aPlotter->Rect( start, end, fill, pen_size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
aPlotter->PlotPoly( ptList, fill, pen_size );
|
|
|
|
break;
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2024-04-15 20:18:54 +00:00
|
|
|
|
|
|
|
aPlotter->SetDash( pen_size, LINE_STYLE::SOLID );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
int SCH_SHAPE::GetEffectiveWidth() const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( GetPenWidth() > 0 )
|
|
|
|
return GetPenWidth();
|
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".
|
2024-04-15 20:18:54 +00:00
|
|
|
if( GetPenWidth() < 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;
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
const BOX2I SCH_SHAPE::GetBoundingBox() const
|
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
return getBoundingBox();
|
2024-04-15 20:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SHAPE::PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aDimmed )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
COLOR4D color;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
static std::vector<VECTOR2I> ptList;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
|
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
|
|
|
|
else
|
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
for( const VECTOR2I& pt : m_bezierPoints )
|
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
|
|
|
|
else
|
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
|
|
|
{
|
2022-04-05 22:32:48 +00:00
|
|
|
if( GetFillColor() == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_NOTES );
|
|
|
|
else
|
|
|
|
color = GetFillColor();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-02-10 00:33:31 +00:00
|
|
|
GRFilledArc( DC, GetEnd(), GetStart(), getCenter(), 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-02-10 00:33:31 +00:00
|
|
|
GRFilledCircle( DC, GetStart(), GetRadius(), 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-02-10 00:33:31 +00:00
|
|
|
GRFilledRect( DC, GetStart(), GetEnd(), 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), true, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), true, 0, color, color );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
2022-10-02 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SHAPE::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
|
2022-10-02 20:21:52 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
int penWidth = GetEffectivePenWidth( aSettings );
|
2022-10-02 20:21:52 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2023-02-14 14:42:19 +00:00
|
|
|
COLOR4D color = GetStroke().GetColor();
|
2024-04-15 20:18:54 +00:00
|
|
|
COLOR4D bg = aSettings->GetBackgroundColor();
|
2023-02-14 14:42:19 +00:00
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_NOTES );
|
2022-10-02 20:21:52 +00:00
|
|
|
|
2023-02-14 14:42:19 +00:00
|
|
|
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
|
|
|
|
bg = COLOR4D::WHITE;
|
2022-10-02 20:21:52 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
color.Desaturate( );
|
|
|
|
color = color.Mix( bg, 0.5f );
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::vector<VECTOR2I> ptList;
|
2022-10-02 20:21:52 +00:00
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
2022-10-02 20:21:52 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
|
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
|
|
|
|
else
|
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
2022-10-02 20:21:52 +00:00
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ptList.clear();
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : m_bezierPoints )
|
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
ptList.push_back( aSettings->TransformCoordinate( pt ) + aOffset );
|
|
|
|
else
|
|
|
|
ptList.push_back( pt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I start = GetStart();
|
|
|
|
VECTOR2I end = GetEnd();
|
|
|
|
VECTOR2I center = ( GetShape() == SHAPE_T::ARC ) ? getCenter() : VECTOR2I( 0, 0 );
|
|
|
|
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
{
|
|
|
|
start = aSettings->TransformCoordinate( start ) + aOffset;
|
|
|
|
end = aSettings->TransformCoordinate( end ) + aOffset;
|
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
|
|
|
center = aSettings->TransformCoordinate( center ) + aOffset;
|
|
|
|
|
|
|
|
EDA_ANGLE t1, t2;
|
2022-10-02 20:21:52 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
CalcArcAngles( t1, t2 );
|
|
|
|
|
|
|
|
// N.B. The order of evaluation is critical here as MapAngles will modify t1, t2
|
|
|
|
// and the Normalize routine depends on these modifications for the correct output
|
|
|
|
bool transformed = aSettings->m_Transform.MapAngles( &t1, &t2 );
|
|
|
|
EDA_ANGLE arc_angle = ( t1 - t2 ).Normalize180();
|
|
|
|
bool transformed2 = ( arc_angle > ANGLE_0 ) && ( arc_angle < ANGLE_180 );
|
|
|
|
|
|
|
|
if( transformed == transformed2 )
|
|
|
|
std::swap( start, end );
|
|
|
|
}
|
2022-10-02 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 14:42:19 +00:00
|
|
|
COLOR4D fillColor = COLOR4D::UNSPECIFIED;
|
|
|
|
|
|
|
|
if( GetFillMode() == FILL_T::FILLED_SHAPE )
|
|
|
|
fillColor = color;
|
|
|
|
else if( GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
|
|
|
fillColor = GetFillColor();
|
2024-04-15 20:18:54 +00:00
|
|
|
else if( GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
fillColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
if( fillColor != COLOR4D::UNSPECIFIED && !aForceNoFill )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
fillColor.Desaturate( );
|
|
|
|
fillColor = fillColor.Mix( bg, 0.5f );
|
|
|
|
}
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRFilledArc( DC, end, start, center, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRFilledCircle( DC, start, GetRadius(), 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRFilledRect( DC, start, end, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), true, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), true, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
|
|
|
|
|
2023-02-14 14:42:19 +00:00
|
|
|
if( penWidth > 0 )
|
|
|
|
{
|
2023-11-25 13:05:45 +00:00
|
|
|
if( GetEffectiveLineStyle() == LINE_STYLE::SOLID )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2023-02-14 14:42:19 +00:00
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRArc( DC, end, start, center, penWidth, color );
|
2023-02-14 14:42:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRCircle( DC, start, GetRadius(), penWidth, color );
|
2023-02-14 14:42:19 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRRect( DC, start, end, penWidth, color );
|
2023-02-14 14:42:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), false, penWidth, color, color );
|
2023-02-14 14:42:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
2024-04-15 20:18:54 +00:00
|
|
|
GRPoly( DC, (int) ptList.size(), ptList.data(), false, penWidth, color, color );
|
2023-02-14 14:42:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2023-02-14 14:42:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<SHAPE*> shapes = MakeEffectiveShapes( true );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-02-14 14:42:19 +00:00
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
{
|
|
|
|
STROKE_PARAMS::Stroke( shape, GetEffectiveLineStyle(), penWidth, aSettings,
|
2024-04-15 20:18:54 +00:00
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
|
|
|
{
|
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
{
|
|
|
|
VECTOR2I ptA = aSettings->TransformCoordinate( a ) + aOffset;
|
|
|
|
VECTOR2I ptB = aSettings->TransformCoordinate( b ) + aOffset;
|
|
|
|
GRLine( DC, ptA.x, ptA.y, ptB.x, ptB.y, penWidth, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRLine( DC, a.x, a.y, b.x, b.y, penWidth, color );
|
|
|
|
}
|
|
|
|
} );
|
2023-02-14 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( m_layer == LAYER_DEVICE )
|
|
|
|
getSymbolEditorMsgPanelInfo( aFrame, aList );
|
|
|
|
else
|
|
|
|
SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
ShapeGetMsgPanelInfo( aFrame, aList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString SCH_SHAPE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
return wxString::Format( _( "Arc, radius %s" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( GetRadius() ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
return wxString::Format( _( "Circle, radius %s" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( GetRadius() ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2021-07-17 19:56:18 +00:00
|
|
|
return wxString::Format( _( "Rectangle, width %s height %s" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( std::abs( m_start.x - m_end.x ) ),
|
|
|
|
aUnitsProvider->MessageTextFromValue( std::abs( m_start.y - m_end.y ) ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
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::RECTANGLE: return BITMAPS::add_rectangle;
|
|
|
|
case SHAPE_T::POLY: return BITMAPS::add_graphical_segments;
|
|
|
|
case SHAPE_T::BEZIER: return BITMAPS::add_bezier;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
return BITMAPS::question_mark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHAPE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 3;
|
2024-04-15 20:18:54 +00:00
|
|
|
aLayers[0] = IsPrivate() ? LAYER_PRIVATE_NOTES : m_layer;
|
|
|
|
|
|
|
|
if( m_layer == LAYER_PRIVATE_NOTES )
|
|
|
|
aLayers[1] = LAYER_NOTES_BACKGROUND;
|
|
|
|
else if( m_layer == LAYER_DEVICE )
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
|
|
|
else
|
|
|
|
aLayers[1] = LAYER_NOTES_BACKGROUND;
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
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() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool SCH_SHAPE::operator==( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_SHAPE& other = static_cast<const SCH_SHAPE&>( aOther );
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
return SCH_ITEM::operator==( aOther ) && EDA_SHAPE::operator==( other );
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_SHAPE::Similarity( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
if( m_Uuid == aOther.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const SCH_SHAPE& other = static_cast<const SCH_SHAPE&>( aOther );
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
double similarity = SimilarityBase( other );
|
|
|
|
|
|
|
|
similarity *= EDA_SHAPE::Similarity( other );
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
return similarity;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
int SCH_SHAPE::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
|
|
|
|
{
|
|
|
|
int retv = SCH_ITEM::compare( aOther, aCompareFlags );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
return EDA_SHAPE::Compare( &static_cast<const SCH_SHAPE&>( aOther ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
static struct SCH_SHAPE_DESC
|
|
|
|
{
|
|
|
|
SCH_SHAPE_DESC()
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
ENUM_MAP<FILL_T>& fillEnum = ENUM_MAP<FILL_T>::Instance();
|
|
|
|
|
|
|
|
if( fillEnum.Choices().GetCount() == 0 )
|
|
|
|
{
|
|
|
|
fillEnum.Map( FILL_T::NO_FILL, _HKI( "None" ) )
|
|
|
|
.Map( FILL_T::FILLED_SHAPE, _HKI( "Body outline color" ) )
|
|
|
|
.Map( FILL_T::FILLED_WITH_BG_BODYCOLOR, _HKI( "Body background color" ) )
|
|
|
|
.Map( FILL_T::FILLED_WITH_COLOR, _HKI( "Fill color" ) );
|
|
|
|
}
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_SHAPE );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<SCH_SHAPE, SCH_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<SCH_SHAPE, EDA_SHAPE> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_SHAPE ), TYPE_HASH( SCH_ITEM ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_SHAPE ), TYPE_HASH( EDA_SHAPE ) );
|
|
|
|
|
|
|
|
// Only polygons have meaningful Position properties.
|
|
|
|
// On other shapes, these are duplicates of the Start properties.
|
|
|
|
auto isPolygon =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
2024-01-18 16:09:03 +00:00
|
|
|
{
|
|
|
|
if( SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( aItem ) )
|
|
|
|
return shape->GetShape() == SHAPE_T::POLY;
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2024-01-18 16:09:03 +00:00
|
|
|
return false;
|
|
|
|
};
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
auto isSymbolItem =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( aItem ) )
|
|
|
|
return shape->GetLayer() == LAYER_DEVICE;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto isSchematicItem =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( aItem ) )
|
|
|
|
return shape->GetLayer() != LAYER_DEVICE;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( SCH_SHAPE ), TYPE_HASH( SCH_ITEM ),
|
|
|
|
_HKI( "Position X" ), isPolygon );
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( SCH_SHAPE ), TYPE_HASH( SCH_ITEM ),
|
|
|
|
_HKI( "Position Y" ), isPolygon );
|
2024-04-15 20:18:54 +00:00
|
|
|
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( SCH_SHAPE ), TYPE_HASH( EDA_SHAPE ),
|
|
|
|
_HKI( "Filled" ), isSchematicItem );
|
|
|
|
|
|
|
|
void ( SCH_SHAPE::*fillModeSetter )( FILL_T ) = &SCH_SHAPE::SetFillMode;
|
|
|
|
FILL_T ( SCH_SHAPE::*fillModeGetter )() const = &SCH_SHAPE::GetFillMode;
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<SCH_SHAPE, FILL_T>( _HKI( "Fill" ),
|
|
|
|
fillModeSetter, fillModeGetter ),
|
|
|
|
_HKI( "Shape Properties" ) )
|
|
|
|
.SetAvailableFunc( isSymbolItem );
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
} _SCH_SHAPE_DESC;
|
2024-04-15 20:18:54 +00:00
|
|
|
|
|
|
|
ENUM_TO_WXANY( FILL_T );
|