2022-07-07 10:17:21 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2022-07-07 10:17:21 -04: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
|
|
|
|
*/
|
|
|
|
|
2023-10-23 18:23:24 +01:00
|
|
|
#include <dialogs/dialog_reference_image_properties.h>
|
2022-07-07 10:17:21 -04:00
|
|
|
#include <dialogs/panel_image_editor.h>
|
|
|
|
|
|
|
|
#include <pcb_base_edit_frame.h>
|
2023-10-23 18:23:24 +01:00
|
|
|
#include <pcb_reference_image.h>
|
2022-07-07 10:17:21 -04:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
2024-04-27 22:57:24 +03:00
|
|
|
#include <board.h>
|
2022-07-07 10:17:21 -04:00
|
|
|
#include <pcb_layer_box_selector.h>
|
|
|
|
|
|
|
|
|
2023-10-23 18:23:24 +01:00
|
|
|
DIALOG_REFERENCE_IMAGE_PROPERTIES::DIALOG_REFERENCE_IMAGE_PROPERTIES( PCB_BASE_FRAME* aParent,
|
2024-09-29 22:03:53 +01:00
|
|
|
PCB_REFERENCE_IMAGE& aBitmap ) :
|
2023-10-23 18:23:24 +01:00
|
|
|
DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE( aParent ),
|
|
|
|
m_frame( aParent ),
|
|
|
|
m_bitmap( aBitmap ),
|
2022-07-07 10:17:21 -04:00
|
|
|
m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ),
|
2025-08-26 11:06:43 -07:00
|
|
|
m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ),
|
|
|
|
m_width( aParent, m_WidthLabel, m_ModWidth, m_WidthUnit ),
|
|
|
|
m_height( aParent, m_HeightLabel, m_ModHeight, m_HeightUnit )
|
2022-07-07 10:17:21 -04:00
|
|
|
{
|
|
|
|
// Create the image editor page
|
2025-08-23 20:31:37 +01:00
|
|
|
m_imageEditor = new PANEL_IMAGE_EDITOR( aParent, this, aBitmap.GetReferenceImage().MutableImage() );
|
|
|
|
|
|
|
|
m_imageSizer->Add( m_imageEditor, 1, wxEXPAND | wxALL, 5 );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
|
|
|
m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
2025-08-26 11:06:43 -07:00
|
|
|
m_width.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
|
|
|
m_height.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
|
|
|
|
|
|
|
m_ModWidth->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onWidthChanged, this );
|
|
|
|
m_ModHeight->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onHeightChanged, this );
|
|
|
|
m_imageEditor->GetScaleCtrl()->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged, this );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
// Only show unactivated board layers if the bitmap is on one of them
|
2024-09-29 22:03:53 +01:00
|
|
|
if( !m_frame->GetBoard()->IsLayerEnabled( m_bitmap.GetLayer() ) )
|
2022-07-07 10:17:21 -04:00
|
|
|
m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
|
|
|
|
|
|
|
|
m_LayerSelectionCtrl->SetLayersHotkeys( false );
|
|
|
|
m_LayerSelectionCtrl->SetBoardFrame( m_frame );
|
|
|
|
m_LayerSelectionCtrl->Resync();
|
|
|
|
|
|
|
|
SetupStandardButtons();
|
|
|
|
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-23 18:23:24 +01:00
|
|
|
void PCB_BASE_EDIT_FRAME::ShowReferenceImagePropertiesDialog( BOARD_ITEM* aBitmap )
|
2022-07-07 10:17:21 -04:00
|
|
|
{
|
2024-09-29 22:03:53 +01:00
|
|
|
PCB_REFERENCE_IMAGE& bitmap = static_cast<PCB_REFERENCE_IMAGE&>( *aBitmap );
|
2023-10-23 18:23:24 +01:00
|
|
|
DIALOG_REFERENCE_IMAGE_PROPERTIES dlg( this, bitmap );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
// The bitmap is cached in Opengl: clear the cache in case it has become invalid
|
|
|
|
GetCanvas()->GetView()->RecacheAllItems();
|
|
|
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-23 18:23:24 +01:00
|
|
|
bool DIALOG_REFERENCE_IMAGE_PROPERTIES::TransferDataToWindow()
|
2022-07-07 10:17:21 -04:00
|
|
|
{
|
2024-09-29 22:03:53 +01:00
|
|
|
m_posX.SetValue( m_bitmap.GetPosition().x );
|
|
|
|
m_posY.SetValue( m_bitmap.GetPosition().y );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
2024-09-29 22:03:53 +01:00
|
|
|
m_LayerSelectionCtrl->SetLayerSelection( m_bitmap.GetLayer() );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
2024-09-29 22:03:53 +01:00
|
|
|
m_cbLocked->SetValue( m_bitmap.IsLocked() );
|
2025-08-08 13:54:14 +01:00
|
|
|
m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be "
|
|
|
|
"selected when the 'Locked items' checkbox is checked in the selection filter." ) );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
2025-08-26 11:06:43 -07:00
|
|
|
m_imageEditor->TransferDataToWindow();
|
|
|
|
VECTOR2I size = m_imageEditor->GetImageSize();
|
|
|
|
m_width.SetValue( size.x );
|
|
|
|
m_height.SetValue( size.y );
|
|
|
|
|
|
|
|
return true;
|
2022-07-07 10:17:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-23 18:23:24 +01:00
|
|
|
bool DIALOG_REFERENCE_IMAGE_PROPERTIES::TransferDataFromWindow()
|
2022-07-07 10:17:21 -04:00
|
|
|
{
|
|
|
|
if( m_imageEditor->TransferDataFromWindow() )
|
|
|
|
{
|
|
|
|
// Save old image in undo list if not already in edit
|
2024-09-29 22:03:53 +01:00
|
|
|
if( m_bitmap.GetEditFlags() == 0 )
|
|
|
|
m_frame->SaveCopyInUndoList( &m_bitmap, UNDO_REDO::CHANGED );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
// Update our bitmap from the editor
|
2024-09-29 22:03:53 +01:00
|
|
|
m_imageEditor->TransferToImage( m_bitmap.GetReferenceImage().MutableImage() );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
// Set position, etc.
|
2025-08-23 20:31:37 +01:00
|
|
|
m_bitmap.SetPosition( VECTOR2I( m_posX.GetIntValue(), m_posY.GetIntValue() ) );
|
2024-09-29 22:03:53 +01:00
|
|
|
m_bitmap.SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
|
|
|
|
m_bitmap.SetLocked( m_cbLocked->GetValue() );
|
2022-07-07 10:17:21 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2025-08-26 11:06:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_REFERENCE_IMAGE_PROPERTIES::onWidthChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
double newWidth = m_width.GetDoubleValue();
|
|
|
|
VECTOR2I size = m_imageEditor->GetImageSize();
|
|
|
|
|
|
|
|
if( size.x > 0 )
|
|
|
|
{
|
|
|
|
double scale = m_imageEditor->GetScale() * newWidth / size.x;
|
|
|
|
m_imageEditor->SetScale( scale );
|
|
|
|
VECTOR2I newSize = m_imageEditor->GetImageSize();
|
|
|
|
m_height.ChangeDoubleValue( newSize.y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_REFERENCE_IMAGE_PROPERTIES::onHeightChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
double newHeight = m_height.GetDoubleValue();
|
|
|
|
VECTOR2I size = m_imageEditor->GetImageSize();
|
|
|
|
|
|
|
|
if( size.y > 0 )
|
|
|
|
{
|
|
|
|
double scale = m_imageEditor->GetScale() * newHeight / size.y;
|
|
|
|
m_imageEditor->SetScale( scale );
|
|
|
|
VECTOR2I newSize = m_imageEditor->GetImageSize();
|
|
|
|
m_width.ChangeDoubleValue( newSize.x );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
double scale = m_imageEditor->GetScale();
|
|
|
|
|
|
|
|
if( scale <= 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_imageEditor->SetScale( scale );
|
|
|
|
VECTOR2I size = m_imageEditor->GetImageSize();
|
|
|
|
m_width.ChangeDoubleValue( size.x );
|
|
|
|
m_height.ChangeDoubleValue( size.y );
|
|
|
|
}
|