2017-01-13 17:51:22 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_pad_basicshapes_properties.cpp
|
|
|
|
* @brief basic shapes for pads crude editor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-01-28 22:51:34 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-13 17:51:22 +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 <algorithm>
|
|
|
|
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2017-01-13 17:51:22 +00:00
|
|
|
#include <base_units.h>
|
2018-08-19 16:10:14 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
#include <dialog_pad_properties.h>
|
2018-05-23 06:11:47 +00:00
|
|
|
#include <bitmaps.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/dcclient.h>
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
|
|
|
|
DIALOG_PAD_PRIMITIVES_PROPERTIES::DIALOG_PAD_PRIMITIVES_PROPERTIES( wxWindow* aParent,
|
|
|
|
PCB_BASE_FRAME* aFrame,
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* aShape ) :
|
2018-05-23 06:11:47 +00:00
|
|
|
DIALOG_PAD_PRIMITIVES_PROPERTIES_BASE( aParent ),
|
|
|
|
m_shape( aShape ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_startX( aFrame, m_startXLabel, m_startXCtrl, m_startXUnits ),
|
|
|
|
m_startY( aFrame, m_startYLabel, m_startYCtrl, m_startYUnits ),
|
|
|
|
m_ctrl1X( aFrame, m_ctrl1XLabel, m_ctrl1XCtrl, m_ctrl1XUnits ),
|
|
|
|
m_ctrl1Y( aFrame, m_ctrl1YLabel, m_ctrl1YCtrl, m_ctrl1YUnits ),
|
|
|
|
m_ctrl2X( aFrame, m_ctrl2XLabel, m_ctrl2XCtrl, m_ctrl2XUnits ),
|
|
|
|
m_ctrl2Y( aFrame, m_ctrl2YLabel, m_ctrl2YCtrl, m_ctrl2YUnits ),
|
|
|
|
m_endX( aFrame, m_endXLabel, m_endXCtrl, m_endXUnits ),
|
|
|
|
m_endY( aFrame, m_endYLabel, m_endYCtrl, m_endYUnits ),
|
|
|
|
m_radius( aFrame, m_radiusLabel, m_radiusCtrl, m_radiusUnits ),
|
|
|
|
m_thickness( aFrame, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-05-23 06:11:47 +00:00
|
|
|
SetInitialFocus( m_startXCtrl );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
if( m_shape == nullptr )
|
2017-01-13 17:51:22 +00:00
|
|
|
return false;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
m_thickness.SetValue( m_shape->GetWidth() );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->SetValue( m_shape->IsFilled() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
switch( m_shape->GetShape() )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2017-01-13 17:51:22 +00:00
|
|
|
SetTitle( _( "Segment" ) );
|
2020-06-24 11:12:39 +00:00
|
|
|
m_startX.SetValue( m_shape->GetStart().x );
|
|
|
|
m_startY.SetValue( m_shape->GetStart().y );
|
|
|
|
m_endX.SetValue( m_shape->GetEnd().x );
|
|
|
|
m_endY.SetValue( m_shape->GetEnd().y );
|
2019-04-14 17:58:35 +00:00
|
|
|
m_ctrl1X.Show( false, true );
|
|
|
|
m_ctrl1Y.Show( false, true );
|
|
|
|
m_ctrl2X.Show( false, true );
|
|
|
|
m_ctrl2Y.Show( false, true );
|
|
|
|
m_staticTextPosCtrl1->Show( false );
|
|
|
|
m_staticTextPosCtrl1->SetSize( 0, 0 );
|
|
|
|
m_staticTextPosCtrl2->Show( false );
|
|
|
|
m_staticTextPosCtrl2->SetSize( 0, 0 );
|
|
|
|
m_radius.Show( false );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->Show( false );
|
2019-04-14 17:58:35 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2019-04-14 17:58:35 +00:00
|
|
|
SetTitle( _( "Bezier" ) );
|
2020-06-24 11:12:39 +00:00
|
|
|
m_startX.SetValue( m_shape->GetStart().x );
|
|
|
|
m_startY.SetValue( m_shape->GetStart().y );
|
|
|
|
m_endX.SetValue( m_shape->GetEnd().x );
|
|
|
|
m_endY.SetValue( m_shape->GetEnd().y );
|
2021-07-18 12:31:56 +00:00
|
|
|
m_ctrl1X.SetValue( m_shape->GetBezierC1().x );
|
|
|
|
m_ctrl1Y.SetValue( m_shape->GetBezierC1().y );
|
|
|
|
m_ctrl2X.SetValue( m_shape->GetBezierC2().x );
|
|
|
|
m_ctrl2Y.SetValue( m_shape->GetBezierC2().y );
|
2018-05-23 06:11:47 +00:00
|
|
|
m_radius.Show( false );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->Show( false );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2017-01-13 17:51:22 +00:00
|
|
|
SetTitle( _( "Arc" ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_startX.SetValue( m_shape->GetStart().x );
|
|
|
|
m_startY.SetValue( m_shape->GetStart().y );
|
2022-10-03 19:47:45 +00:00
|
|
|
m_staticTextPosEnd->SetLabel( _( "Center Point:" ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_endX.SetValue( m_shape->GetCenter().x );
|
|
|
|
m_endY.SetValue( m_shape->GetCenter().y );
|
2018-05-23 06:11:47 +00:00
|
|
|
m_radiusLabel->SetLabel( _( "Angle:" ) );
|
2019-12-20 14:11:39 +00:00
|
|
|
m_radius.SetUnits( EDA_UNITS::DEGREES );
|
2022-01-16 21:15:20 +00:00
|
|
|
m_radius.SetAngleValue( m_shape->GetArcAngle() );
|
2019-04-14 17:58:35 +00:00
|
|
|
m_ctrl1X.Show( false, true );
|
|
|
|
m_ctrl1Y.Show( false, true );
|
|
|
|
m_ctrl2X.Show( false, true );
|
|
|
|
m_ctrl2Y.Show( false, true );
|
|
|
|
m_staticTextPosCtrl1->Show( false );
|
|
|
|
m_staticTextPosCtrl1->SetSize( 0, 0 );
|
|
|
|
m_staticTextPosCtrl2->Show( false );
|
|
|
|
m_staticTextPosCtrl2->SetSize( 0, 0 );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->Show( false );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2020-06-24 11:12:39 +00:00
|
|
|
if( m_shape->GetWidth() )
|
2017-01-13 17:51:22 +00:00
|
|
|
SetTitle( _( "Ring" ) );
|
|
|
|
else
|
|
|
|
SetTitle( _( "Circle" ) );
|
|
|
|
|
|
|
|
// End point does not exist for a circle or ring:
|
|
|
|
m_staticTextPosEnd->Show( false );
|
2018-05-23 06:11:47 +00:00
|
|
|
m_endX.Show( false );
|
|
|
|
m_endY.Show( false );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Circle center uses position controls:
|
2022-10-03 19:47:45 +00:00
|
|
|
m_staticTextPosStart->SetLabel( _( "Center Point:" ) );
|
2020-06-24 11:12:39 +00:00
|
|
|
m_startX.SetValue( m_shape->GetStart().x );
|
|
|
|
m_startY.SetValue( m_shape->GetStart().y );
|
|
|
|
m_radius.SetValue( m_shape->GetRadius() );
|
2019-04-14 17:58:35 +00:00
|
|
|
m_ctrl1X.Show( false, true );
|
|
|
|
m_ctrl1Y.Show( false, true );
|
|
|
|
m_ctrl2X.Show( false, true );
|
|
|
|
m_ctrl2Y.Show( false, true );
|
|
|
|
m_staticTextPosCtrl1->Show( false );
|
|
|
|
m_staticTextPosCtrl1->SetSize( 0, 0 );
|
|
|
|
m_staticTextPosCtrl2->Show( false );
|
|
|
|
m_staticTextPosCtrl2->SetSize( 0, 0 );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->Show( true );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2022-09-14 10:34:10 +00:00
|
|
|
case SHAPE_T::RECT:
|
|
|
|
if( m_shape->IsAnnotationProxy() )
|
|
|
|
SetTitle( _( "Number Box" ) );
|
|
|
|
else
|
|
|
|
SetTitle( _( "Rectangle" ) );
|
|
|
|
|
|
|
|
m_startX.SetValue( m_shape->GetStart().x );
|
|
|
|
m_startY.SetValue( m_shape->GetStart().y );
|
|
|
|
m_endX.SetValue( m_shape->GetEnd().x );
|
|
|
|
m_endY.SetValue( m_shape->GetEnd().y );
|
|
|
|
m_ctrl1X.Show( false, true );
|
|
|
|
m_ctrl1Y.Show( false, true );
|
|
|
|
m_ctrl2X.Show( false, true );
|
|
|
|
m_ctrl2Y.Show( false, true );
|
|
|
|
m_staticTextPosCtrl1->Show( false );
|
|
|
|
m_staticTextPosCtrl1->SetSize( 0, 0 );
|
|
|
|
m_staticTextPosCtrl2->Show( false );
|
|
|
|
m_staticTextPosCtrl2->SetSize( 0, 0 );
|
|
|
|
m_radius.Show( false );
|
|
|
|
m_filledCtrl->Show( false );
|
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2018-05-23 06:11:47 +00:00
|
|
|
// polygon has a specific dialog editor. So nothing here
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-09-14 10:34:10 +00:00
|
|
|
SetTitle( "Unknown Basic Shape" );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
if( m_thickness.GetValue() == 0 && !m_filledCtrl->GetValue() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Line width may not be 0 for unfilled shapes." ) );
|
|
|
|
m_thicknessCtrl->SetFocus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
// Transfer data out of the GUI.
|
2021-07-17 19:56:18 +00:00
|
|
|
STROKE_PARAMS stroke = m_shape->GetStroke();
|
|
|
|
stroke.SetWidth( m_thickness.GetValue() );
|
|
|
|
m_shape->SetStroke( stroke );
|
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
m_shape->SetFilled( m_filledCtrl->GetValue() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
switch( m_shape->GetShape() )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2022-09-14 10:34:10 +00:00
|
|
|
case SHAPE_T::RECT:
|
2022-01-16 16:15:07 +00:00
|
|
|
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
|
|
|
|
m_shape->SetEnd( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2022-01-16 16:15:07 +00:00
|
|
|
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
|
|
|
|
m_shape->SetEnd( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
|
|
|
|
m_shape->SetBezierC1( VECTOR2I( m_ctrl1X.GetValue(), m_ctrl1Y.GetValue()));
|
2022-03-06 00:35:53 +00:00
|
|
|
m_shape->SetBezierC2( VECTOR2I( m_ctrl2X.GetValue(), m_ctrl2Y.GetValue()));
|
2019-04-14 17:58:35 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2022-01-16 16:15:07 +00:00
|
|
|
m_shape->SetCenter( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
|
|
|
|
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
|
|
|
|
m_shape->SetArcAngleAndEnd( m_radius.GetAngleValue() );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-16 16:15:07 +00:00
|
|
|
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
|
|
|
|
m_shape->SetEnd( m_shape->GetStart() + VECTOR2I( m_radius.GetValue(), 0 ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2018-05-23 06:11:47 +00:00
|
|
|
// polygon has a specific dialog editor. So nothing here
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS( wxWindow* aParent,
|
|
|
|
PCB_BASE_FRAME* aFrame,
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* aShape ) :
|
2018-05-23 06:11:47 +00:00
|
|
|
DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE( aParent ),
|
2022-09-19 09:25:20 +00:00
|
|
|
m_frame( aFrame ),
|
2018-05-23 06:11:47 +00:00
|
|
|
m_shape( aShape ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_thickness( aFrame, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2020-07-02 16:06:09 +00:00
|
|
|
if( !m_shape->GetPolyShape().IsEmpty() )
|
|
|
|
{
|
|
|
|
for( const VECTOR2I& pt : m_shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
m_currPoints.emplace_back( pt );
|
|
|
|
}
|
2020-06-24 11:12:39 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_addButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_deleteButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_warningIcon->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
m_gridCornersList->SetUnitsProvider( aFrame );
|
|
|
|
m_gridCornersList->SetAutoEvalCols( { 0, 1 } );
|
|
|
|
|
|
|
|
m_gridCornersList->SetDefaultRowSize( m_gridCornersList->GetDefaultRowSize() + 4 );
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
// Test for acceptable polygon (more than 2 corners, and not self-intersecting) and
|
|
|
|
// remove any redundant corners. A warning message is displayed if not OK.
|
|
|
|
doValidate( true );
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gridCornersList->Connect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ),
|
|
|
|
nullptr, this );
|
2019-04-14 17:58:35 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
DIALOG_PAD_PRIMITIVE_POLY_PROPS::~DIALOG_PAD_PRIMITIVE_POLY_PROPS()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gridCornersList->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging ),
|
|
|
|
nullptr, this );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
if( m_shape == nullptr )
|
2017-01-13 17:51:22 +00:00
|
|
|
return false;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
m_thickness.SetValue( m_shape->GetWidth() );
|
2020-11-14 01:16:02 +00:00
|
|
|
m_filledCtrl->SetValue( m_shape->IsFilled() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Populates the list of corners
|
2020-06-24 11:12:39 +00:00
|
|
|
int extra_rows = m_currPoints.size() - m_gridCornersList->GetNumberRows();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
if( extra_rows > 0 )
|
|
|
|
{
|
|
|
|
m_gridCornersList->AppendRows( extra_rows );
|
|
|
|
}
|
|
|
|
else if( extra_rows < 0 )
|
|
|
|
{
|
|
|
|
extra_rows = -extra_rows;
|
|
|
|
m_gridCornersList->DeleteRows( 0, extra_rows );
|
|
|
|
}
|
|
|
|
|
|
|
|
// enter others corner coordinates
|
2020-06-24 11:12:39 +00:00
|
|
|
for( unsigned row = 0; row < m_currPoints.size(); ++row )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
// Row label is "Corner x"
|
2022-10-11 17:01:47 +00:00
|
|
|
m_gridCornersList->SetRowLabelValue( row, wxString::Format( _( "Corner %d" ), row+1 ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
m_gridCornersList->SetUnitValue( row, 0, m_currPoints[row].x );
|
|
|
|
m_gridCornersList->SetUnitValue( row, 1, m_currPoints[row].y );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataFromWindow()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
if( !Validate() )
|
|
|
|
return false;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
m_shape->SetPolyPoints( m_currPoints );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
STROKE_PARAMS stroke = m_shape->GetStroke();
|
|
|
|
stroke.SetWidth( m_thickness.GetValue() );
|
|
|
|
m_shape->SetStroke( stroke );
|
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
m_shape->SetFilled( m_filledCtrl->GetValue() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::Validate()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-05-23 06:11:47 +00:00
|
|
|
// Don't remove redundant corners while user is editing corner list
|
|
|
|
return doValidate( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate( bool aRemoveRedundantCorners )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_gridCornersList->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
if( m_currPoints.size() < 3 )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-05-23 06:11:47 +00:00
|
|
|
m_warningText->SetLabel( _("Polygon must have at least 3 corners" ) );
|
|
|
|
m_warningText->Show( true );
|
|
|
|
m_warningIcon->Show( true );
|
2017-01-13 17:51:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid = true;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
SHAPE_LINE_CHAIN polyline( m_currPoints, true );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Remove redundant corners:
|
|
|
|
polyline.Simplify();
|
|
|
|
|
|
|
|
if( polyline.PointCount() < 3 )
|
|
|
|
{
|
2020-02-25 15:36:41 +00:00
|
|
|
m_warningText->SetLabel( _( "Polygon must have at least 3 corners after simplification" ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( valid && polyline.SelfIntersecting() )
|
|
|
|
{
|
2020-02-25 15:36:41 +00:00
|
|
|
m_warningText->SetLabel( _( "Polygon can not be self-intersecting" ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
m_warningIcon->Show( !valid );
|
|
|
|
m_warningText->Show( !valid );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
if( aRemoveRedundantCorners )
|
|
|
|
{
|
2020-06-24 11:12:39 +00:00
|
|
|
if( polyline.PointCount() != (int) m_currPoints.size() )
|
2018-05-23 06:11:47 +00:00
|
|
|
{ // Happens after simplification
|
2020-06-24 11:12:39 +00:00
|
|
|
m_currPoints.clear();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
for( const VECTOR2I& pt : polyline.CPoints() )
|
|
|
|
m_currPoints.emplace_back( pt );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
m_warningIcon->Show( true );
|
|
|
|
m_warningText->Show( true );
|
2020-02-25 15:36:41 +00:00
|
|
|
m_warningText->SetLabel( _( "Note: redundant corners removed" ) );
|
2018-05-23 06:11:47 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonAdd( wxCommandEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_gridCornersList->CommitPendingChanges() )
|
|
|
|
return;
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
// Insert a new corner after the currently selected:
|
2018-05-23 06:11:47 +00:00
|
|
|
wxArrayInt selections = m_gridCornersList->GetSelectedRows();
|
2017-01-13 17:51:22 +00:00
|
|
|
int row = -1;
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
if( m_gridCornersList->GetNumberRows() == 0 )
|
2017-01-13 17:51:22 +00:00
|
|
|
row = 0;
|
2018-05-23 06:11:47 +00:00
|
|
|
else if( selections.size() > 0 )
|
|
|
|
row = selections[ selections.size() - 1 ] + 1;
|
|
|
|
else
|
|
|
|
row = m_gridCornersList->GetGridCursorRow() + 1;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
if( row < 0 )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Select a corner to add the new corner after." ) );
|
|
|
|
return;
|
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
if( m_currPoints.size() == 0 || row >= (int) m_currPoints.size() )
|
|
|
|
m_currPoints.emplace_back( 0, 0 );
|
2017-01-13 17:51:22 +00:00
|
|
|
else
|
2020-06-24 11:12:39 +00:00
|
|
|
m_currPoints.insert( m_currPoints.begin() + row, wxPoint( 0, 0 ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
Validate();
|
2017-01-13 17:51:22 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
m_gridCornersList->ForceRefresh();
|
|
|
|
// Select the new row
|
|
|
|
m_gridCornersList->SelectRow( row, false );
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
m_panelPoly->Refresh();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonDelete( wxCommandEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_gridCornersList->CommitPendingChanges() )
|
|
|
|
return;
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
wxArrayInt selections = m_gridCornersList->GetSelectedRows();
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
if( m_gridCornersList->GetNumberRows() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( selections.size() == 0 && m_gridCornersList->GetGridCursorRow() >= 0 )
|
|
|
|
selections.push_back( m_gridCornersList->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selections.size() == 0 )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2018-05-23 06:11:47 +00:00
|
|
|
wxMessageBox( _( "Select a corner to delete." ) );
|
|
|
|
return;
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
// remove corners:
|
|
|
|
std::sort( selections.begin(), selections.end() );
|
|
|
|
|
|
|
|
for( int ii = selections.size()-1; ii >= 0 ; --ii )
|
2020-06-24 11:12:39 +00:00
|
|
|
m_currPoints.erase( m_currPoints.begin() + selections[ii] );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
Validate();
|
2017-01-13 17:51:22 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
m_gridCornersList->ForceRefresh();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
// select the row previous to the last deleted row
|
|
|
|
m_gridCornersList->SelectRow( std::max( 0, selections[ 0 ] - 1 ) );
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
m_panelPoly->Refresh();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel( wxPaintEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
wxPaintDC dc( m_panelPoly );
|
|
|
|
wxSize dc_size = dc.GetSize();
|
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Calculate a suitable scale to fit the available draw area
|
2022-09-16 11:33:56 +00:00
|
|
|
int minsize( pcbIUScale.mmToIU( 0.5 ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
for( unsigned ii = 0; ii < m_currPoints.size(); ++ii )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2020-06-24 11:12:39 +00:00
|
|
|
minsize = std::max( minsize, std::abs( m_currPoints[ii].x ) );
|
|
|
|
minsize = std::max( minsize, std::abs( m_currPoints[ii].y ) );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The draw origin is the center of the window.
|
|
|
|
// Therefore the window size is twice the minsize just calculated
|
2020-02-25 15:36:41 +00:00
|
|
|
minsize *= 2;
|
2020-06-24 11:12:39 +00:00
|
|
|
minsize += m_thickness.GetValue();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Give a margin
|
2020-02-25 15:36:41 +00:00
|
|
|
double scale = std::min( double( dc_size.x ) / minsize, double( dc_size.y ) / minsize ) * 0.9;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
|
|
|
|
// Draw X and Y axis. This is particularly useful to show the
|
|
|
|
// reference position of basic shape
|
|
|
|
// Axis are drawn before the polygon to avoid masking segments on axis
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( &dc, -dc_size.x, 0, dc_size.x, 0, 0, LIGHTBLUE ); // X axis
|
|
|
|
GRLine( &dc, 0, -dc_size.y, 0, dc_size.y, 0, LIGHTBLUE ); // Y axis
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Draw polygon.
|
|
|
|
// The selected edge(s) are shown in selectcolor, the others in normalcolor.
|
|
|
|
EDA_COLOR_T normalcolor = WHITE;
|
|
|
|
EDA_COLOR_T selectcolor = RED;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
for( unsigned ii = 0; ii < m_currPoints.size(); ++ii )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
EDA_COLOR_T color = normalcolor;
|
|
|
|
|
|
|
|
if( m_gridCornersList->IsInSelection (ii, 0) ||
|
|
|
|
m_gridCornersList->IsInSelection (ii, 1) ||
|
|
|
|
m_gridCornersList->GetGridCursorRow() == (int)ii )
|
|
|
|
color = selectcolor;
|
|
|
|
|
|
|
|
unsigned jj = ii + 1;
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
if( jj >= m_currPoints.size() )
|
2017-01-13 17:51:22 +00:00
|
|
|
jj = 0;
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( &dc, m_currPoints[ii] * scale, m_currPoints[jj] * scale,
|
2021-07-19 23:56:05 +00:00
|
|
|
m_thickness.GetValue() * scale, color );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPolyPanelResize( wxSizeEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
m_panelPoly->Refresh();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onGridSelect( wxGridRangeSelectEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
m_panelPoly->Refresh();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging( wxGridEvent& event )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2022-10-11 17:01:47 +00:00
|
|
|
int row = event.GetRow();
|
|
|
|
int col = event.GetCol();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
CallAfter(
|
|
|
|
[this, row, col]()
|
|
|
|
{
|
|
|
|
if( col == 0 ) // Set the X value
|
|
|
|
m_currPoints[row].x = m_gridCornersList->GetUnitValue( row, col );
|
|
|
|
else // Set the Y value
|
|
|
|
m_currPoints[row].y = m_gridCornersList->GetUnitValue( row, col );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
Validate();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
m_panelPoly->Refresh();
|
|
|
|
} );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
DIALOG_PAD_PRIMITIVES_TRANSFORM::DIALOG_PAD_PRIMITIVES_TRANSFORM( wxWindow* aParent,
|
|
|
|
PCB_BASE_FRAME* aFrame,
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<std::shared_ptr<PCB_SHAPE>>& aList,
|
2018-05-23 06:11:47 +00:00
|
|
|
bool aShowDuplicate ) :
|
|
|
|
DIALOG_PAD_PRIMITIVES_TRANSFORM_BASE( aParent ),
|
|
|
|
m_list( aList ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_vectorX( aFrame, m_xLabel, m_xCtrl, m_xUnits ),
|
|
|
|
m_vectorY( aFrame, m_yLabel, m_yCtrl, m_yUnits ),
|
2018-05-23 06:11:47 +00:00
|
|
|
m_rotation( aFrame, m_rotationLabel, m_rotationCtrl, m_rotationUnits )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
m_rotation.SetUnits( EDA_UNITS::DEGREES );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
if( !aShowDuplicate ) // means no duplicate transform
|
|
|
|
{
|
2017-09-20 14:14:23 +00:00
|
|
|
m_staticTextDupCnt->Show( false );
|
|
|
|
m_spinCtrlDuplicateCount->Show( false );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
}
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform( std::vector<std::shared_ptr<PCB_SHAPE>>* aList,
|
2020-06-24 11:12:39 +00:00
|
|
|
int aDuplicateCount )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2022-01-16 19:19:55 +00:00
|
|
|
VECTOR2I move_vect( m_vectorX.GetValue(), m_vectorY.GetValue() );
|
|
|
|
EDA_ANGLE rotation = m_rotation.GetAngleValue();
|
2022-09-16 04:38:10 +00:00
|
|
|
double scale = EDA_UNIT_UTILS::UI::DoubleValueFromString( m_scaleCtrl->GetValue() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
// Avoid too small / too large scale, which could create issues:
|
2017-01-13 17:51:22 +00:00
|
|
|
if( scale < 0.01 )
|
|
|
|
scale = 0.01;
|
|
|
|
|
|
|
|
if( scale > 100.0 )
|
|
|
|
scale = 100.0;
|
|
|
|
|
|
|
|
// Transform shapes
|
|
|
|
// shapes are scaled, then moved then rotated.
|
|
|
|
// if aList != NULL, the initial shape will be duplicated, and transform
|
|
|
|
// applied to the duplicated shape
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2022-01-16 19:19:55 +00:00
|
|
|
VECTOR2I currMoveVect = move_vect;
|
|
|
|
EDA_ANGLE curr_rotation = rotation;
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
do {
|
|
|
|
for( unsigned idx = 0; idx < m_list.size(); ++idx )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::shared_ptr<PCB_SHAPE> shape;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aList == nullptr )
|
|
|
|
{
|
2017-01-13 17:51:22 +00:00
|
|
|
shape = m_list[idx];
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
aList->emplace_back( std::make_shared<PCB_SHAPE>( *m_list[idx] ) );
|
2020-06-24 11:12:39 +00:00
|
|
|
shape = aList->back();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transform parameters common to all shape types (some can be unused)
|
2021-07-17 19:56:18 +00:00
|
|
|
STROKE_PARAMS stroke = shape->GetStroke();
|
|
|
|
stroke.SetWidth( KiROUND( shape->GetWidth() * scale ) );
|
|
|
|
shape->SetStroke( stroke );
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
shape->Move( currMoveVect );
|
|
|
|
shape->Scale( scale );
|
2022-01-16 19:19:55 +00:00
|
|
|
shape->Rotate( VECTOR2I( 0, 0 ), curr_rotation );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare new transform on duplication:
|
|
|
|
// Each new item is rotated (or moved) by the transform from the last duplication
|
2018-02-20 15:25:58 +00:00
|
|
|
curr_rotation += rotation;
|
|
|
|
currMoveVect += move_vect;
|
2017-01-13 17:51:22 +00:00
|
|
|
} while( aList && --aDuplicateCount > 0 );
|
|
|
|
}
|
|
|
|
|