2021-07-17 19:56:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-04-05 22:32:48 +00:00
|
|
|
* Copyright (C) 2021-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 <widgets/color_swatch.h>
|
|
|
|
#include <stroke_params.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_shape.h>
|
|
|
|
#include <dialog_shape_properties.h>
|
2022-03-29 19:41:03 +00:00
|
|
|
#include <settings/color_settings.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
DIALOG_SHAPE_PROPERTIES::DIALOG_SHAPE_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHAPE* aShape ) :
|
|
|
|
DIALOG_SHAPE_PROPERTIES_BASE( aParent ),
|
2022-01-11 18:33:30 +00:00
|
|
|
m_frame( aParent ),
|
2021-07-17 19:56:18 +00:00
|
|
|
m_shape( aShape ),
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
|
|
|
SetTitle( wxString::Format( GetTitle(), aShape->ShowShape() ) );
|
|
|
|
|
2021-12-24 17:23:41 +00:00
|
|
|
m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
|
|
|
m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
SetInitialFocus( m_borderWidthCtrl );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderStyleCombo->Append( DEFAULT_STYLE );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
|
2022-03-29 19:41:03 +00:00
|
|
|
if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
|
|
|
|
m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
// Required under wxGTK if we want to dismiss the dialog with the ESC key
|
|
|
|
SetFocus();
|
2021-11-16 19:39:58 +00:00
|
|
|
|
|
|
|
SetupStandardButtons();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SHAPE_PROPERTIES::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
if( m_shape->GetWidth() >= 0 )
|
|
|
|
{
|
|
|
|
m_borderCheckbox->SetValue( true );
|
|
|
|
m_borderWidth.SetValue( m_shape->GetWidth() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_borderCheckbox->SetValue( false );
|
|
|
|
|
|
|
|
m_borderWidth.Enable( false );
|
|
|
|
m_borderColorLabel->Enable( false );
|
|
|
|
m_borderColorSwatch->Enable( false );
|
|
|
|
m_borderStyleLabel->Enable( false );
|
|
|
|
m_borderStyleCombo->Enable( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_borderColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
int style = static_cast<int>( m_shape->GetStroke().GetPlotStyle() );
|
|
|
|
|
|
|
|
if( style == -1 )
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
|
2021-07-17 19:56:18 +00:00
|
|
|
else if( style < (int) lineTypeNames.size() )
|
2022-04-05 22:32:48 +00:00
|
|
|
m_borderStyleCombo->SetSelection( style );
|
2021-07-17 19:56:18 +00:00
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Line type not found in the type lookup map" );
|
|
|
|
|
|
|
|
m_filledCtrl->SetValue( m_shape->IsFilled() );
|
|
|
|
m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
bool border = m_borderCheckbox->GetValue();
|
|
|
|
|
|
|
|
if( border && m_borderWidth.GetValue() < 0 )
|
|
|
|
m_borderWidth.SetValue( Mils2iu( m_frame->eeconfig()->m_Drawing.default_line_thickness ) );
|
|
|
|
|
|
|
|
m_borderWidth.Enable( border );
|
|
|
|
m_borderColorLabel->Enable( border );
|
|
|
|
m_borderColorSwatch->Enable( border );
|
|
|
|
m_borderStyleLabel->Enable( border );
|
|
|
|
m_borderStyleCombo->Enable( border );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SHAPE_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
bool fill = m_filledCtrl->GetValue();
|
|
|
|
|
|
|
|
m_fillColorLabel->Enable( fill );
|
|
|
|
m_fillColorSwatch->Enable( fill );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
bool DIALOG_SHAPE_PROPERTIES::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2022-01-11 18:33:30 +00:00
|
|
|
if( !m_shape->IsNew() )
|
2022-03-16 13:43:19 +00:00
|
|
|
{
|
|
|
|
m_frame->SaveCopyInUndoList( m_frame->GetScreen(), m_shape, UNDO_REDO::CHANGED, false,
|
|
|
|
false );
|
|
|
|
}
|
2022-01-11 18:33:30 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
STROKE_PARAMS stroke = m_shape->GetStroke();
|
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
if( m_borderCheckbox->GetValue() )
|
|
|
|
stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
|
|
|
|
else
|
|
|
|
stroke.SetWidth( -1 );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
auto it = lineTypeNames.begin();
|
2022-04-05 22:32:48 +00:00
|
|
|
std::advance( it, m_borderStyleCombo->GetSelection() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
if( it == lineTypeNames.end() )
|
|
|
|
stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
|
|
|
|
else
|
|
|
|
stroke.SetPlotStyle( it->first );
|
|
|
|
|
2022-04-05 22:32:48 +00:00
|
|
|
stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
m_shape->SetStroke( stroke );
|
|
|
|
|
|
|
|
m_shape->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL );
|
|
|
|
m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|