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
|
2024-04-06 13:14:44 +00:00
|
|
|
* Copyright (C) 2004-2024 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>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <plotters/plotter.h>
|
|
|
|
#include <macros.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <widgets/msgpanel.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <eda_draw_frame.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <lib_shape.h>
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
LIB_SHAPE::LIB_SHAPE( SCH_ITEM* aParent, SHAPE_T aShape, int aLineWidth, FILL_T aFillType,
|
2022-01-25 22:33:37 +00:00
|
|
|
KICAD_T aType ) :
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM( aParent, aType ),
|
2022-08-27 11:37:43 +00:00
|
|
|
EDA_SHAPE( aShape, aLineWidth, aFillType )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
m_editState = 0;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool LIB_SHAPE::HitTest( const VECTOR2I& aPosRef, int aAccuracy ) const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-09-16 23:42:20 +00:00
|
|
|
if( aAccuracy < schIUScale.MilsToIU( MINIMUM_SELECTION_DISTANCE ) )
|
|
|
|
aAccuracy = schIUScale.MilsToIU( MINIMUM_SELECTION_DISTANCE );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
return hitTest( DefaultTransform.TransformCoordinate( aPosRef ), aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool LIB_SHAPE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
|
|
|
return false;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
return hitTest( DefaultTransform.TransformCoordinate( aRect ), aContained, aAccuracy );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EDA_ITEM* LIB_SHAPE::Clone() const
|
|
|
|
{
|
|
|
|
return new LIB_SHAPE( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
int LIB_SHAPE::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
int retv = SCH_ITEM::compare( aOther, aCompareFlags );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
return EDA_SHAPE::Compare( &static_cast<const LIB_SHAPE&>( aOther ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
void LIB_SHAPE::Move( const VECTOR2I& aOffset )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
move( aOffset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-06 17:18:01 +00:00
|
|
|
void LIB_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();
|
|
|
|
|
2022-04-07 10:51:00 +00:00
|
|
|
if( size.y > 0 )
|
2022-04-06 17:18:01 +00:00
|
|
|
{
|
|
|
|
SetStartY( GetStartY() + size.y );
|
|
|
|
SetEndY( GetStartY() - size.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size.x < 0 )
|
|
|
|
{
|
|
|
|
SetStartX( GetStartX() + size.x );
|
|
|
|
SetEndX( GetStartX() - size.x );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 23:03:32 +00:00
|
|
|
void LIB_SHAPE::MirrorHorizontally( int aCenter )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-04 23:03:32 +00:00
|
|
|
flip( VECTOR2I( aCenter, 0 ), true );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 23:03:32 +00:00
|
|
|
void LIB_SHAPE::MirrorVertically( int aCenter )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-04 23:03:32 +00:00
|
|
|
flip( VECTOR2I( 0, aCenter ), false );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void LIB_SHAPE::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
rotate( aCenter, rot_angle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void LIB_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
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
|
|
|
|
|
|
|
|
VECTOR2I start = renderSettings->TransformCoordinate( m_start ) + aOffset;
|
|
|
|
VECTOR2I end = renderSettings->TransformCoordinate( m_end ) + aOffset;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
static std::vector<VECTOR2I> cornerList;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 );
|
2021-07-17 19:56:18 +00:00
|
|
|
cornerList.clear();
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( const VECTOR2I& pt : poly.CPoints() )
|
2024-04-05 21:35:32 +00:00
|
|
|
cornerList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
cornerList.clear();
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& pt : m_bezierPoints )
|
2024-04-05 21:35:32 +00:00
|
|
|
cornerList.push_back( renderSettings->TransformCoordinate( pt ) + aOffset );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
int penWidth;
|
|
|
|
COLOR4D color = GetStroke().GetColor();
|
|
|
|
LINE_STYLE lineStyle = GetStroke().GetLineStyle();
|
|
|
|
FILL_T fill = m_fill;
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
{
|
2022-02-15 22:31:14 +00:00
|
|
|
if( !aPlotter->GetColorMode() )
|
2022-02-10 19:49:25 +00:00
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
switch( m_fill )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
case FILL_T::FILLED_SHAPE:
|
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
case FILL_T::FILLED_WITH_COLOR:
|
|
|
|
color = GetFillColor();
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
case FILL_T::FILLED_WITH_BG_BODYCOLOR:
|
2024-04-05 21:35:32 +00:00
|
|
|
color = renderSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-10 19:49:25 +00:00
|
|
|
return;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
penWidth = 0;
|
2023-11-25 13:05:45 +00:00
|
|
|
lineStyle = LINE_STYLE::SOLID;
|
2022-02-10 19:49:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-29 12:51:49 +00:00
|
|
|
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
|
2024-04-05 21:35:32 +00:00
|
|
|
color = renderSettings->GetLayerColor( LAYER_DEVICE );
|
2022-04-29 12:51:49 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
if( lineStyle == LINE_STYLE::DEFAULT )
|
|
|
|
lineStyle = LINE_STYLE::SOLID;
|
2022-04-29 12:51:49 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
if( m_fill == FILL_T::FILLED_SHAPE )
|
|
|
|
fill = m_fill;
|
2021-07-17 19:56:18 +00:00
|
|
|
else
|
|
|
|
fill = FILL_T::NO_FILL;
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
penWidth = GetEffectivePenWidth( renderSettings );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
COLOR4D bg = renderSettings->GetBackgroundColor();
|
2022-09-16 16:20:36 +00:00
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->SetColor( color );
|
2022-06-28 18:06:17 +00:00
|
|
|
aPlotter->SetDash( penWidth, lineStyle );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-06-22 23:44:35 +00:00
|
|
|
{
|
2024-04-05 21:35:32 +00:00
|
|
|
VECTOR2I mid = renderSettings->TransformCoordinate( GetArcMid() ) + aOffset;
|
2023-08-07 01:53:08 +00:00
|
|
|
|
2023-08-22 13:06:53 +00:00
|
|
|
aPlotter->Arc( start, mid, end, fill, penWidth );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2023-08-07 01:53:08 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2023-08-07 01:53:08 +00:00
|
|
|
{
|
2024-04-05 21:35:32 +00:00
|
|
|
VECTOR2I center = renderSettings->TransformCoordinate( getCenter() ) + aOffset;
|
2023-08-07 01:53:08 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Circle( center, GetRadius() * 2, fill, penWidth );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2023-08-07 01:53:08 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->Rect( start, end, fill, penWidth );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
case SHAPE_T::BEZIER:
|
2022-01-25 22:33:37 +00:00
|
|
|
aPlotter->PlotPoly( cornerList, fill, penWidth );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-07-18 23:08:54 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-04-29 12:51:49 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
aPlotter->SetDash( penWidth, LINE_STYLE::SOLID );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LIB_SHAPE::GetPenWidth() const
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
return GetWidth();
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void LIB_SHAPE::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2021-11-01 14:48:18 +00:00
|
|
|
int penWidth = GetEffectivePenWidth( aSettings );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
if( aForceNoFill && IsFilled() && penWidth == 0 )
|
2021-07-17 19:56:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2024-04-02 17:28:17 +00:00
|
|
|
VECTOR2I pt1 = aSettings->m_Transform.TransformCoordinate( m_start ) + aOffset;
|
|
|
|
VECTOR2I pt2 = aSettings->m_Transform.TransformCoordinate( m_end ) + aOffset;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I c;
|
2022-07-10 16:47:04 +00:00
|
|
|
COLOR4D color = GetStroke().GetColor();
|
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_DEVICE );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
COLOR4D bg = aSettings->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
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
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
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 )
|
2024-04-02 17:28:17 +00:00
|
|
|
buffer[ii] = aSettings->m_Transform.TransformCoordinate( poly.CPoint( ii ) ) + aOffset;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
else if( GetShape() == SHAPE_T::BEZIER )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
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 )
|
2024-04-02 17:28:17 +00:00
|
|
|
buffer[ii] = aSettings->m_Transform.TransformCoordinate( m_bezierPoints[ii] ) + aOffset;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
2024-04-02 17:28:17 +00:00
|
|
|
c = aSettings->m_Transform.TransformCoordinate( getCenter() ) + aOffset;
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE t1, t2;
|
2021-11-17 10:59:49 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
CalcArcAngles( t1, t2 );
|
2021-10-14 23:39:31 +00:00
|
|
|
|
2022-03-08 00:41:26 +00:00
|
|
|
// 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
|
2024-04-02 17:28:17 +00:00
|
|
|
bool transformed = aSettings->m_Transform.MapAngles( &t1, &t2 );
|
2022-09-24 08:00:21 +00:00
|
|
|
EDA_ANGLE arc_angle = ( t1 - t2 ).Normalize180();
|
|
|
|
bool transformed2 = ( arc_angle > ANGLE_0 ) && ( arc_angle < ANGLE_180 );
|
2022-03-08 00:41:26 +00:00
|
|
|
|
|
|
|
if( transformed == transformed2 )
|
2021-10-30 14:08:44 +00:00
|
|
|
std::swap( pt1, pt2 );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 14:27:40 +00:00
|
|
|
COLOR4D fillColor = COLOR4D::UNSPECIFIED;
|
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
if( !aForceNoFill )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-06-28 14:27:40 +00:00
|
|
|
if( GetFillMode() == FILL_T::FILLED_SHAPE )
|
|
|
|
fillColor = color;
|
|
|
|
else if( GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
fillColor = aSettings->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
|
|
|
else if( GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
|
|
|
fillColor = GetFillColor();
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-06-28 14:27:40 +00:00
|
|
|
if( fillColor != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
2023-01-11 20:53:09 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
fillColor.Desaturate( );
|
2023-01-12 04:37:42 +00:00
|
|
|
fillColor = fillColor.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2022-06-28 14:27:40 +00:00
|
|
|
GRFilledArc( DC, pt1, pt2, c, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-06-28 14:27:40 +00:00
|
|
|
GRFilledCircle( DC, pt1, 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:
|
2022-06-28 14:27:40 +00:00
|
|
|
GRFilledRect( DC, pt1, pt2, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
2022-06-28 14:27:40 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, true, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2022-06-28 14:27:40 +00:00
|
|
|
GRPoly( DC, ptCount, buffer, true, 0, fillColor, fillColor );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-07-18 23:08:54 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-14 14:42:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() );
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2023-02-14 14:42:19 +00:00
|
|
|
if( penWidth > 0 )
|
2022-06-28 14:27:40 +00:00
|
|
|
{
|
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:
|
|
|
|
GRArc( DC, pt1, pt2, c, penWidth, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
GRCircle( DC, pt1, GetRadius(), penWidth, color );
|
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2023-02-14 14:42:19 +00:00
|
|
|
GRRect( DC, pt1, pt2, penWidth, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
GRPoly( DC, ptCount, buffer, false, penWidth, color, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
GRPoly( DC, ptCount, buffer, false, penWidth, color, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2023-02-14 14:42:19 +00:00
|
|
|
else
|
2022-06-28 14:27:40 +00:00
|
|
|
{
|
2023-02-14 14:42:19 +00:00
|
|
|
std::vector<SHAPE*> shapes = MakeEffectiveShapes( true );
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
{
|
|
|
|
STROKE_PARAMS::Stroke( shape, GetEffectiveLineStyle(), penWidth, aSettings,
|
2024-04-02 17:28:17 +00:00
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
|
|
|
{
|
|
|
|
VECTOR2I pts = aSettings->m_Transform.TransformCoordinate( a ) + aOffset;
|
|
|
|
VECTOR2I pte = aSettings->m_Transform.TransformCoordinate( b ) + aOffset;
|
|
|
|
GRLine( DC, pts.x, pts.y, pte.x, pte.y, penWidth, color );
|
|
|
|
} );
|
2023-02-14 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
2022-06-28 14:27:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I LIB_SHAPE::GetBoundingBox() const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox = getBoundingBox();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bbox.RevertYAxis();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return bbox;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-14 23:39:31 +00:00
|
|
|
void LIB_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
getSymbolEditorMsgPanelInfo( aFrame, aList );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
ShapeGetMsgPanelInfo( aFrame, aList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString LIB_SHAPE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
2023-03-09 17:41:18 +00:00
|
|
|
return wxString::Format( _( "Arc with 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:
|
2023-03-09 17:41:18 +00:00
|
|
|
return wxString::Format( _( "Circle with 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:
|
2023-03-09 17:41:18 +00:00
|
|
|
return wxString::Format( _( "Rectangle with 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
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
2023-03-09 17:41:18 +00:00
|
|
|
return wxString::Format( _( "Polyline with %d points" ),
|
2021-07-17 19:56:18 +00:00
|
|
|
int( m_poly.Outline( 0 ).GetPointCount() ) );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2023-03-09 17:41:18 +00:00
|
|
|
return wxString::Format( _( "Bezier Curve with %d points" ),
|
2021-07-17 19:56:18 +00:00
|
|
|
int( m_bezierPoints.size() ) );
|
|
|
|
|
|
|
|
default:
|
2021-07-18 23:08:54 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAPS LIB_SHAPE::GetMenuImage() const
|
|
|
|
{
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
2023-10-30 17:29:38 +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;
|
2024-02-14 01:00:01 +00:00
|
|
|
case SHAPE_T::BEZIER: return BITMAPS::add_bezier;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
default:
|
2021-07-18 23:08:54 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
return BITMAPS::question_mark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void LIB_SHAPE::AddPoint( const VECTOR2I& aPosition )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( GetShape() == SHAPE_T::POLY )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
if( m_poly.IsEmpty() )
|
|
|
|
m_poly.NewOutline();
|
|
|
|
|
|
|
|
m_poly.Outline( 0 ).Append( aPosition, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
bool LIB_SHAPE::operator==( const SCH_ITEM& aOther ) const
|
2023-09-14 21:39:42 +00:00
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const LIB_SHAPE& other = static_cast<const LIB_SHAPE&>( aOther );
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
return SCH_ITEM::operator==( aOther ) && EDA_SHAPE::operator==( other );
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
double LIB_SHAPE::Similarity( const SCH_ITEM& aOther ) const
|
2023-09-14 21:39:42 +00:00
|
|
|
{
|
|
|
|
if( m_Uuid == aOther.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const LIB_SHAPE& other = static_cast<const LIB_SHAPE&>( aOther );
|
|
|
|
|
|
|
|
double similarity = SimilarityBase( other );
|
|
|
|
|
|
|
|
similarity *= EDA_SHAPE::Similarity( other );
|
|
|
|
|
|
|
|
return similarity;
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LIB_SHAPE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 3;
|
2022-07-07 04:51:23 +00:00
|
|
|
aLayers[0] = IsPrivate() ? LAYER_PRIVATE_NOTES : LAYER_DEVICE;
|
2022-01-25 22:33:37 +00:00
|
|
|
aLayers[1] = IsPrivate() ? LAYER_NOTES_BACKGROUND : LAYER_DEVICE_BACKGROUND;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
2023-07-26 22:32:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct LIB_SHAPE_DESC
|
|
|
|
{
|
|
|
|
LIB_SHAPE_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( LIB_SHAPE );
|
2024-04-06 13:14:44 +00:00
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<LIB_SHAPE, SCH_ITEM> );
|
2023-07-26 22:32:06 +00:00
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<LIB_SHAPE, EDA_SHAPE> );
|
2024-04-06 13:14:44 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( LIB_SHAPE ), TYPE_HASH( SCH_ITEM ) );
|
2023-07-26 22:32:06 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( LIB_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
|
|
|
|
{
|
|
|
|
if( LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( aItem ) )
|
|
|
|
return shape->GetShape() == SHAPE_T::POLY;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( LIB_SHAPE ), TYPE_HASH( SCH_ITEM ),
|
2023-07-26 22:32:06 +00:00
|
|
|
_HKI( "Position X" ), isPolygon );
|
2024-04-06 13:14:44 +00:00
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( LIB_SHAPE ), TYPE_HASH( SCH_ITEM ),
|
2023-07-26 22:32:06 +00:00
|
|
|
_HKI( "Position Y" ), isPolygon );
|
2023-10-30 17:29:38 +00:00
|
|
|
|
|
|
|
propMgr.Mask( TYPE_HASH( LIB_SHAPE ), TYPE_HASH( EDA_SHAPE ), _HKI( "Filled" ) );
|
|
|
|
|
|
|
|
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" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ( LIB_SHAPE::*fillModeSetter )( FILL_T ) = &LIB_SHAPE::SetFillMode;
|
|
|
|
FILL_T ( LIB_SHAPE::*fillModeGetter )() const = &LIB_SHAPE::GetFillMode;
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM< LIB_SHAPE, FILL_T>( _HKI( "Fill" ),
|
2024-03-21 16:17:49 +00:00
|
|
|
fillModeSetter, fillModeGetter ),
|
|
|
|
_HKI( "Shape Properties" ) );
|
2023-07-26 22:32:06 +00:00
|
|
|
}
|
|
|
|
} _LIB_SHAPE_DESC;
|
2023-10-30 17:29:38 +00:00
|
|
|
|
|
|
|
ENUM_TO_WXANY( FILL_T )
|