2020-06-24 17:35:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-06-07 22:45:06 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-24 17:35:33 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <dialog_junction_props.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2020-08-18 17:01:19 +00:00
|
|
|
#include <widgets/color_swatch.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2020-06-24 17:35:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
DIALOG_JUNCTION_PROPS::DIALOG_JUNCTION_PROPS( SCH_EDIT_FRAME* aParent,
|
2020-08-18 17:01:19 +00:00
|
|
|
std::deque<SCH_JUNCTION*>& aJunctions ) :
|
2020-06-24 17:35:33 +00:00
|
|
|
DIALOG_JUNCTION_PROPS_BASE( aParent ),
|
|
|
|
m_frame( aParent ),
|
|
|
|
m_junctions( aJunctions ),
|
|
|
|
m_diameter( aParent, m_staticTextDiameter, m_textCtrlDiameter,
|
|
|
|
m_staticTextDiameterUnits, true )
|
|
|
|
{
|
2020-08-18 17:01:19 +00:00
|
|
|
m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
|
2022-09-05 11:43:08 +00:00
|
|
|
KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
|
|
|
|
m_colorSwatch->SetSwatchBackground( canvas.ToColour() );
|
|
|
|
|
2021-09-16 17:29:29 +00:00
|
|
|
m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
|
|
|
m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
2021-08-31 10:48:45 +00:00
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
SetInitialFocus( m_textCtrlDiameter );
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_APPLY, _( "Default" ) } } );
|
2020-06-24 17:35:33 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_JUNCTION_PROPS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
auto firstJunction = m_junctions.front();
|
|
|
|
|
|
|
|
if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
|
2020-08-18 17:01:19 +00:00
|
|
|
[&]( const SCH_JUNCTION* r )
|
|
|
|
{
|
|
|
|
return r->GetDiameter() == firstJunction->GetDiameter();
|
|
|
|
} ) )
|
2020-06-24 17:35:33 +00:00
|
|
|
{
|
|
|
|
m_diameter.SetValue( firstJunction->GetDiameter() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_diameter.SetValue( INDETERMINATE_ACTION );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( std::all_of( m_junctions.begin() + 1, m_junctions.end(),
|
2020-08-18 17:01:19 +00:00
|
|
|
[&]( const SCH_JUNCTION* r )
|
|
|
|
{
|
|
|
|
return r->GetColor() == firstJunction->GetColor();
|
|
|
|
} ) )
|
2020-06-24 17:35:33 +00:00
|
|
|
{
|
2020-08-18 17:01:19 +00:00
|
|
|
m_colorSwatch->SetSwatchColor( firstJunction->GetColor(), false );
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-18 17:01:19 +00:00
|
|
|
m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_JUNCTION_PROPS::resetDefaults( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_diameter.SetValue( 0 );
|
2020-08-18 17:01:19 +00:00
|
|
|
m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
|
2020-06-24 17:35:33 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_JUNCTION_PROPS::TransferDataFromWindow()
|
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_frame );
|
2020-06-24 17:35:33 +00:00
|
|
|
|
2020-08-18 17:01:19 +00:00
|
|
|
for( SCH_JUNCTION* junction : m_junctions )
|
2020-06-24 17:35:33 +00:00
|
|
|
{
|
2023-06-07 22:45:06 +00:00
|
|
|
commit.Modify( junction, m_frame->GetScreen() );
|
|
|
|
|
2020-06-24 17:35:33 +00:00
|
|
|
if( !m_diameter.IsIndeterminate() )
|
|
|
|
junction->SetDiameter( m_diameter.GetValue() );
|
|
|
|
|
2020-08-18 17:01:19 +00:00
|
|
|
junction->SetColor( m_colorSwatch->GetSwatchColor() );
|
|
|
|
|
|
|
|
m_frame->GetCanvas()->GetView()->Update( junction );
|
2020-06-24 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 22:45:06 +00:00
|
|
|
commit.Push( m_junctions.size() == 1 ? _( "Edit Junction" ) : _( "Edit Junctions" ),
|
|
|
|
SKIP_CONNECTIVITY );
|
2020-06-24 17:35:33 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|