2012-07-17 15:29:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-01-25 22:33:37 +00:00
|
|
|
* Copyright (C) 2006-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-07-17 15:29:29 +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
|
|
|
|
*/
|
|
|
|
|
2019-08-15 07:09:52 +00:00
|
|
|
#include <lib_item.h>
|
2021-08-06 19:54:26 +00:00
|
|
|
#include <dialog_lib_shape_properties.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2022-02-06 18:44:03 +00:00
|
|
|
#include <symbol_editor_settings.h>
|
2021-03-13 00:07:58 +00:00
|
|
|
#include <confirm.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <lib_shape.h>
|
2021-12-16 18:04:59 +00:00
|
|
|
#include <widgets/color_swatch.h>
|
2022-06-16 12:23:35 +00:00
|
|
|
#include <settings/color_settings.h>
|
2021-12-16 18:04:59 +00:00
|
|
|
#include <sch_painter.h>
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES( SYMBOL_EDIT_FRAME* aParent,
|
2022-06-16 12:23:35 +00:00
|
|
|
LIB_SHAPE* aShape ) :
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_LIB_SHAPE_PROPERTIES_BASE( aParent ),
|
2018-06-14 08:26:11 +00:00
|
|
|
m_frame( aParent ),
|
2022-06-16 12:23:35 +00:00
|
|
|
m_shape( aShape ),
|
|
|
|
m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
|
2010-07-22 20:12:40 +00:00
|
|
|
{
|
2022-09-25 01:10:21 +00:00
|
|
|
wxASSERT( aShape );
|
|
|
|
|
2023-09-14 15:49:32 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), aShape->EDA_SHAPE::GetFriendlyName() ) );
|
|
|
|
|
2021-12-24 17:23:41 +00:00
|
|
|
m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
2018-06-14 08:26:11 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
|
|
|
|
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
|
2021-12-16 18:04:59 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
m_borderColorSwatch->SetSwatchBackground( schematicBackground );
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
|
2024-01-22 03:55:13 +00:00
|
|
|
m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmapBundle( lineStyleDesc.bitmap ) );
|
2022-06-16 12:23:35 +00:00
|
|
|
|
|
|
|
m_borderStyleCombo->Append( DEFAULT_STYLE );
|
|
|
|
|
|
|
|
m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
m_fillColorSwatch->SetSwatchBackground( schematicBackground );
|
|
|
|
|
|
|
|
m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
|
|
|
|
2023-09-14 15:49:32 +00:00
|
|
|
if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
|
|
|
|
m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
SetInitialFocus( m_borderWidthCtrl );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2010-11-17 21:47:27 +00:00
|
|
|
// Required under wxGTK if we want to dismiss the dialog with the ESC key
|
2010-07-22 20:12:40 +00:00
|
|
|
SetFocus();
|
2020-12-22 02:29:27 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2021-02-10 22:56:26 +00:00
|
|
|
if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
|
2020-12-22 02:29:27 +00:00
|
|
|
{
|
|
|
|
m_sdbSizerCancel->SetDefault();
|
|
|
|
m_sdbSizerOK->SetLabel( _( "Read Only" ) );
|
|
|
|
m_sdbSizerOK->Enable( false );
|
|
|
|
}
|
2016-07-16 10:54:55 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_borderColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
|
|
|
|
m_fillColorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
|
2021-12-15 10:17:53 +00:00
|
|
|
|
2016-07-16 10:54:55 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2010-07-22 20:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
DIALOG_LIB_SHAPE_PROPERTIES::~DIALOG_LIB_SHAPE_PROPERTIES()
|
|
|
|
{
|
|
|
|
m_borderColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch, this );
|
|
|
|
m_fillColorSwatch->Unbind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_LIB_SHAPE_PROPERTIES::TransferDataToWindow()
|
2010-07-22 20:12:40 +00:00
|
|
|
{
|
2021-03-13 00:07:58 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
LIB_SYMBOL* symbol = m_shape->GetParent();
|
|
|
|
|
|
|
|
m_checkBorder->SetValue( m_shape->GetWidth() >= 0 );
|
|
|
|
|
|
|
|
if( m_shape->GetWidth() >= 0 )
|
|
|
|
m_borderWidth.SetValue( m_shape->GetWidth() );
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_borderWidth.Enable( m_shape->GetWidth() >= 0 );
|
|
|
|
m_helpLabel->Enable( m_shape->GetWidth() >= 0 );
|
|
|
|
m_borderColorLabel->Enable( m_shape->GetWidth() >= 0 );
|
|
|
|
m_borderColorSwatch->Enable( m_shape->GetWidth() >= 0 );
|
|
|
|
m_borderStyleLabel->Enable( m_shape->GetWidth() >= 0 );
|
|
|
|
m_borderStyleCombo->Enable( m_shape->GetWidth() >= 0 );
|
2022-02-06 18:44:03 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_borderColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
|
2022-02-06 18:44:03 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( style == -1 )
|
|
|
|
m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
|
|
|
|
else if( style < (int) lineTypeNames.size() )
|
|
|
|
m_borderStyleCombo->SetSelection( style );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Line type not found in the type lookup map" );
|
|
|
|
|
|
|
|
m_privateCheckbox->SetValue( m_shape->IsPrivate() );
|
2023-02-28 20:58:58 +00:00
|
|
|
m_checkApplyToAllUnits->SetValue(
|
|
|
|
symbol && symbol->GetUnitCount() > 1 && m_shape->GetUnit() == 0 );
|
2018-06-14 08:26:11 +00:00
|
|
|
m_checkApplyToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
|
2024-01-26 16:16:13 +00:00
|
|
|
m_checkApplyToAllBodyStyles->SetValue( m_shape->GetBodyStyle() == 0 );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
bool enableAlternateBodyStyle = symbol && symbol->HasAlternateBodyStyle();
|
2021-01-13 14:40:30 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
// If a symbol contains no body-style-specific pins or graphic items,
|
|
|
|
// symbol->HasAlternateBodyStyle() will return false.
|
|
|
|
// But when creating a new symbol, with DeMorgan option set, the m_checkApplyToAllBodyStyles
|
2022-03-24 18:30:53 +00:00
|
|
|
// must be enabled in order to be able to create graphic items shared by all body styles.
|
2018-06-14 08:26:11 +00:00
|
|
|
if( m_frame->GetShowDeMorgan() )
|
2024-01-26 16:16:13 +00:00
|
|
|
enableAlternateBodyStyle = true;
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
m_checkApplyToAllBodyStyles->Enable( enableAlternateBodyStyle );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2022-09-25 01:10:21 +00:00
|
|
|
m_rbFillNone->Enable( true );
|
|
|
|
m_rbFillOutline->Enable( true );
|
|
|
|
m_rbFillBackground->Enable( true );
|
|
|
|
m_rbFillCustom->Enable( true );
|
|
|
|
m_fillColorSwatch->Enable( true );
|
2021-12-16 18:04:59 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( m_shape->GetFillMode() == FILL_T::FILLED_SHAPE )
|
2021-12-15 10:17:53 +00:00
|
|
|
{
|
2021-12-16 18:04:59 +00:00
|
|
|
m_rbFillOutline->SetValue( true );
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
COLOR4D color = m_shape->GetStroke().GetColor();
|
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
2022-09-24 02:31:02 +00:00
|
|
|
color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
|
2022-06-16 12:23:35 +00:00
|
|
|
|
|
|
|
m_fillColorSwatch->SetSwatchColor( color, false );
|
2021-12-15 10:17:53 +00:00
|
|
|
}
|
2022-06-16 12:23:35 +00:00
|
|
|
else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
|
2021-12-16 18:04:59 +00:00
|
|
|
{
|
|
|
|
m_rbFillBackground->SetValue( true );
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2021-12-16 18:04:59 +00:00
|
|
|
COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->SetSwatchColor( color, false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
2022-06-16 12:23:35 +00:00
|
|
|
else if( m_shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
2021-12-16 18:04:59 +00:00
|
|
|
{
|
|
|
|
m_rbFillCustom->SetValue( true );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rbFillNone->SetValue( true );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
return true;
|
2010-07-22 20:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 18:04:59 +00:00
|
|
|
void DIALOG_LIB_SHAPE_PROPERTIES::onFill( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetId() == NO_FILL )
|
|
|
|
{
|
|
|
|
m_rbFillNone->SetValue( true );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == FILLED_SHAPE )
|
|
|
|
{
|
|
|
|
m_rbFillOutline->SetValue( true );
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
COLOR4D color = m_shape->GetStroke().GetColor();
|
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
2022-09-24 02:31:02 +00:00
|
|
|
color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE );
|
2022-06-16 12:23:35 +00:00
|
|
|
|
|
|
|
m_fillColorSwatch->SetSwatchColor( color, false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
{
|
|
|
|
m_rbFillBackground->SetValue( true );
|
|
|
|
|
|
|
|
COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->SetSwatchColor( color, false );
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == FILLED_WITH_COLOR )
|
|
|
|
{
|
|
|
|
m_rbFillCustom->SetValue( true );
|
2022-06-16 12:23:35 +00:00
|
|
|
m_fillColorSwatch->GetNewSwatchColor();
|
2021-12-16 18:04:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
void DIALOG_LIB_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
bool border = m_checkBorder->GetValue();
|
|
|
|
|
|
|
|
if( border && m_borderWidth.GetValue() < 0 )
|
2022-09-16 23:42:20 +00:00
|
|
|
m_borderWidth.SetValue( schIUScale.MilsToIU( m_frame->libeditconfig()->m_Defaults.line_width ) );
|
2022-06-16 12:23:35 +00:00
|
|
|
|
|
|
|
m_borderWidth.Enable( border );
|
|
|
|
m_borderColorLabel->Enable( border );
|
|
|
|
m_borderColorSwatch->Enable( border );
|
|
|
|
m_borderStyleLabel->Enable( border );
|
|
|
|
m_borderStyleCombo->Enable( border );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SHAPE_PROPERTIES::onBorderSwatch( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_rbFillOutline->GetValue() )
|
|
|
|
m_fillColorSwatch->SetSwatchColor( m_borderColorSwatch->GetSwatchColor(), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SHAPE_PROPERTIES::onFillSwatch( wxCommandEvent& aEvent )
|
2021-12-16 18:04:59 +00:00
|
|
|
{
|
|
|
|
m_rbFillCustom->SetValue( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_LIB_SHAPE_PROPERTIES::TransferDataFromWindow()
|
2010-07-22 20:12:40 +00:00
|
|
|
{
|
2021-03-13 00:07:58 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
STROKE_PARAMS stroke = m_shape->GetStroke();
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( m_checkBorder->GetValue() )
|
2021-07-17 19:56:18 +00:00
|
|
|
{
|
2022-06-16 12:23:35 +00:00
|
|
|
if( !m_borderWidth.IsIndeterminate() )
|
|
|
|
stroke.SetWidth( m_borderWidth.GetValue() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stroke.SetWidth( -1 );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2021-03-13 00:07:58 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
auto it = lineTypeNames.begin();
|
|
|
|
std::advance( it, m_borderStyleCombo->GetSelection() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( it == lineTypeNames.end() )
|
2023-11-25 13:05:45 +00:00
|
|
|
stroke.SetLineStyle( LINE_STYLE::DEFAULT );
|
2021-03-13 00:07:58 +00:00
|
|
|
else
|
2023-11-25 13:05:45 +00:00
|
|
|
stroke.SetLineStyle( it->first );
|
2021-03-13 00:07:58 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
|
|
|
|
|
|
|
|
m_shape->SetStroke( stroke );
|
|
|
|
|
|
|
|
if( m_rbFillOutline->GetValue() )
|
|
|
|
m_shape->SetFillMode( FILL_T::FILLED_SHAPE );
|
|
|
|
else if( m_rbFillBackground->GetValue() )
|
|
|
|
m_shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
|
|
|
|
else if( m_rbFillCustom->GetValue() )
|
|
|
|
m_shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
2021-03-13 00:07:58 +00:00
|
|
|
else
|
2022-06-16 12:23:35 +00:00
|
|
|
m_shape->SetFillMode( FILL_T::NO_FILL );
|
2021-03-13 00:07:58 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
m_shape->SetPrivate( m_privateCheckbox->GetValue() );
|
2010-07-22 20:12:40 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( GetApplyToAllConversions() )
|
2024-01-26 16:16:13 +00:00
|
|
|
m_shape->SetBodyStyle( 0 );
|
2022-06-16 12:23:35 +00:00
|
|
|
else
|
2024-01-26 16:16:13 +00:00
|
|
|
m_shape->SetBodyStyle( m_frame->GetBodyStyle() );
|
2022-02-06 18:44:03 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
if( GetApplyToAllUnits() )
|
|
|
|
m_shape->SetUnit( 0 );
|
|
|
|
else
|
|
|
|
m_shape->SetUnit( m_frame->GetUnit() );
|
2022-02-06 18:44:03 +00:00
|
|
|
|
2022-06-16 12:23:35 +00:00
|
|
|
return true;
|
2022-02-06 18:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_LIB_SHAPE_PROPERTIES::GetApplyToAllConversions()
|
2010-07-22 20:12:40 +00:00
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
return m_checkApplyToAllBodyStyles->IsChecked();
|
2010-07-22 20:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_LIB_SHAPE_PROPERTIES::GetApplyToAllUnits()
|
2010-07-22 20:12:40 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
return m_checkApplyToAllUnits->IsChecked();
|
2010-07-22 20:12:40 +00:00
|
|
|
}
|
|
|
|
|