From efdead20089ea677cbb274a854510e5d63b6bd83 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 6 Sep 2023 18:54:54 +0200 Subject: [PATCH] Gerbview: added (in Layers Manager) a new setting to adjust draw offset and rotation of the active layer. This is a draw option only. --- gerbview/CMakeLists.txt | 2 + .../dialogs/dialog_draw_layers_settings.cpp | 79 ++ .../dialogs/dialog_draw_layers_settings.h | 50 ++ .../dialog_draw_layers_settings_base.cpp | 104 +++ .../dialog_draw_layers_settings_base.fbp | 807 ++++++++++++++++++ .../dialog_draw_layers_settings_base.h | 64 ++ gerbview/gerber_draw_item.cpp | 17 + gerbview/gerber_file_image.cpp | 16 + gerbview/gerber_file_image.h | 14 + gerbview/gerbview_frame.cpp | 24 + gerbview/gerbview_frame.h | 3 + gerbview/widgets/gerbview_layer_widget.cpp | 9 + gerbview/widgets/gerbview_layer_widget.h | 1 + 13 files changed, 1190 insertions(+) create mode 100644 gerbview/dialogs/dialog_draw_layers_settings.cpp create mode 100644 gerbview/dialogs/dialog_draw_layers_settings.h create mode 100644 gerbview/dialogs/dialog_draw_layers_settings_base.cpp create mode 100644 gerbview/dialogs/dialog_draw_layers_settings_base.fbp create mode 100644 gerbview/dialogs/dialog_draw_layers_settings_base.h diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index 723a4c2b09..dcc565e0c8 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -22,6 +22,8 @@ set( DIALOGS_SRCS dialogs/panel_gerbview_display_options_base.cpp dialogs/panel_gerbview_excellon_settings.cpp dialogs/panel_gerbview_excellon_settings_base.cpp + dialogs/dialog_draw_layers_settings.cpp + dialogs/dialog_draw_layers_settings_base.cpp dialogs/dialog_layers_select_to_pcb.cpp dialogs/dialog_layers_select_to_pcb_base.cpp dialogs/dialog_print_gerbview.cpp diff --git a/gerbview/dialogs/dialog_draw_layers_settings.cpp b/gerbview/dialogs/dialog_draw_layers_settings.cpp new file mode 100644 index 0000000000..cbba1faf5f --- /dev/null +++ b/gerbview/dialogs/dialog_draw_layers_settings.cpp @@ -0,0 +1,79 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Jean-Pierre Charras jp.charras at wanadoo.fr + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 +#include +#include +#include +#include + + +DIALOG_DRAW_LAYERS_SETTINGS::DIALOG_DRAW_LAYERS_SETTINGS( GERBVIEW_FRAME* aParent ) : + DIALOG_DRAW_LAYERS_SETTINGS_BASE( aParent ), + m_parent( aParent ), + m_offsetX( aParent, m_stOffsetX, m_tcOffsetX, m_stUnitX, true ), + m_offsetY( aParent, m_stOffsetY, m_tcOffsetY, m_stUnitY, true ), + m_rotation( aParent, m_stLayerRot, m_tcRotation, m_stUnitRot, true ) +{ + m_rotation.SetUnits( EDA_UNITS::DEGREES ); + m_rotation.SetPrecision( 3 ); + + SetupStandardButtons(); + finishDialogSettings(); +} + + +bool DIALOG_DRAW_LAYERS_SETTINGS::TransferDataToWindow() +{ + GERBER_FILE_IMAGE* gbrImage = m_parent->GetGbrImage( m_parent->GetActiveLayer() ); + + if( !gbrImage ) + return true; + + wxFileName filename( gbrImage->m_FileName ); + m_stLayerName->SetLabel( filename.GetFullName() ); + + m_offsetX.SetValue( gbrImage->m_DrawOffset.x ); + m_offsetY.SetValue( gbrImage->m_DrawOffset.y ); + m_rotation.SetValue( gbrImage->m_DrawRotation.AsDegrees() ); + + return true; +} + +bool DIALOG_DRAW_LAYERS_SETTINGS::TransferDataFromWindow() +{ + GERBER_FILE_IMAGE* gbrImage = m_parent->GetGbrImage( m_parent->GetActiveLayer() ); + + if( !gbrImage ) + return true; + + double offsetX = m_offsetX.GetValue(); + double offsetY = m_offsetY.GetValue(); + EDA_ANGLE rot = m_rotation.GetAngleValue(); + + gbrImage->SetDrawOffetAndRotation( VECTOR2D( offsetX/gerbIUScale.IU_PER_MM, + offsetY/gerbIUScale.IU_PER_MM ), rot ); + + return true; +} \ No newline at end of file diff --git a/gerbview/dialogs/dialog_draw_layers_settings.h b/gerbview/dialogs/dialog_draw_layers_settings.h new file mode 100644 index 0000000000..2f6b3099be --- /dev/null +++ b/gerbview/dialogs/dialog_draw_layers_settings.h @@ -0,0 +1,50 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Jean-Pierre Charras jp.charras at wanadoo.fr + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + +#pragma once + +#include +#include + + +class DIALOG_DRAW_LAYERS_SETTINGS : public DIALOG_DRAW_LAYERS_SETTINGS_BASE +{ +public: + DIALOG_DRAW_LAYERS_SETTINGS( GERBVIEW_FRAME* aParent ); + ~DIALOG_DRAW_LAYERS_SETTINGS() {}; + +private: + bool TransferDataToWindow() override; + bool TransferDataFromWindow() override; + + ///< Update layerset basing on the selected layers + int setLayerSetFromList(); + + GERBVIEW_FRAME* m_parent; + + UNIT_BINDER m_offsetX; + UNIT_BINDER m_offsetY; + UNIT_BINDER m_rotation; + +}; diff --git a/gerbview/dialogs/dialog_draw_layers_settings_base.cpp b/gerbview/dialogs/dialog_draw_layers_settings_base.cpp new file mode 100644 index 0000000000..7a32858c33 --- /dev/null +++ b/gerbview/dialogs/dialog_draw_layers_settings_base.cpp @@ -0,0 +1,104 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_draw_layers_settings_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_DRAW_LAYERS_SETTINGS_BASE::DIALOG_DRAW_LAYERS_SETTINGS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + m_namiSizer = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizer3; + bSizer3 = new wxBoxSizer( wxHORIZONTAL ); + + m_stLayerNameTitle = new wxStaticText( this, wxID_ANY, _("Layer name:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stLayerNameTitle->Wrap( -1 ); + bSizer3->Add( m_stLayerNameTitle, 0, wxALL, 5 ); + + m_stLayerName = new wxStaticText( this, wxID_ANY, _("dummy"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stLayerName->Wrap( -1 ); + bSizer3->Add( m_stLayerName, 0, wxALL, 5 ); + + + m_namiSizer->Add( bSizer3, 0, wxEXPAND, 5 ); + + wxFlexGridSizer* fgSizer; + fgSizer = new wxFlexGridSizer( 3, 3, 0, 0 ); + fgSizer->AddGrowableCol( 1 ); + fgSizer->SetFlexibleDirection( wxBOTH ); + fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + m_stOffsetX = new wxStaticText( this, wxID_ANY, _("Offset X"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stOffsetX->Wrap( -1 ); + fgSizer->Add( m_stOffsetX, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_tcOffsetX = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_tcOffsetX, 0, wxALL|wxEXPAND, 5 ); + + m_stUnitX = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stUnitX->Wrap( -1 ); + fgSizer->Add( m_stUnitX, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_stOffsetY = new wxStaticText( this, wxID_ANY, _("Offset Y"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stOffsetY->Wrap( -1 ); + fgSizer->Add( m_stOffsetY, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_tcOffsetY = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_tcOffsetY, 0, wxALL|wxEXPAND, 5 ); + + m_stUnitY = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stUnitY->Wrap( -1 ); + fgSizer->Add( m_stUnitY, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_stLayerRot = new wxStaticText( this, wxID_ANY, _("Rotation"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stLayerRot->Wrap( -1 ); + fgSizer->Add( m_stLayerRot, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_tcRotation = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer->Add( m_tcRotation, 0, wxALL|wxEXPAND, 5 ); + + m_stUnitRot = new wxStaticText( this, wxID_ANY, _("dummy"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stUnitRot->Wrap( -1 ); + fgSizer->Add( m_stUnitRot, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + + m_namiSizer->Add( fgSizer, 1, wxEXPAND, 5 ); + + wxBoxSizer* bottomButtonsSizer; + bottomButtonsSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_sdbSizerStdButtons = new wxStdDialogButtonSizer(); + m_sdbSizerStdButtonsOK = new wxButton( this, wxID_OK ); + m_sdbSizerStdButtons->AddButton( m_sdbSizerStdButtonsOK ); + m_sdbSizerStdButtonsCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizerStdButtons->AddButton( m_sdbSizerStdButtonsCancel ); + m_sdbSizerStdButtons->Realize(); + + bottomButtonsSizer->Add( m_sdbSizerStdButtons, 1, wxEXPAND|wxALL, 5 ); + + + m_namiSizer->Add( bottomButtonsSizer, 0, wxEXPAND|wxLEFT, 5 ); + + + this->SetSizer( m_namiSizer ); + this->Layout(); + + // Connect Events + this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DRAW_LAYERS_SETTINGS_BASE::OnInitDlg ) ); + this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_DRAW_LAYERS_SETTINGS_BASE::OnUpdateUI ) ); +} + +DIALOG_DRAW_LAYERS_SETTINGS_BASE::~DIALOG_DRAW_LAYERS_SETTINGS_BASE() +{ + // Disconnect Events + this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_DRAW_LAYERS_SETTINGS_BASE::OnInitDlg ) ); + this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_DRAW_LAYERS_SETTINGS_BASE::OnUpdateUI ) ); + +} diff --git a/gerbview/dialogs/dialog_draw_layers_settings_base.fbp b/gerbview/dialogs/dialog_draw_layers_settings_base.fbp new file mode 100644 index 0000000000..03cce550a6 --- /dev/null +++ b/gerbview/dialogs/dialog_draw_layers_settings_base.fbp @@ -0,0 +1,807 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_draw_layers_settings_base + 1000 + none + + + 1 + dialog_draw_layers_settings_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_DRAW_LAYERS_SETTINGS_BASE + + 311,203 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Footprint Properties + + 0 + + + + OnInitDlg + OnUpdateUI + + + m_namiSizer + wxVERTICAL + private + + 5 + wxEXPAND + 0 + + + bSizer3 + wxHORIZONTAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Layer name: + 0 + + 0 + + + 0 + + 1 + m_stLayerNameTitle + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + dummy + 0 + + 0 + + + 0 + + 1 + m_stLayerName + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + + + 5 + wxEXPAND + 1 + + 3 + wxBOTH + 1 + + 0 + + fgSizer + wxFLEX_GROWMODE_SPECIFIED + none + 3 + 0 + + 5 + wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Offset X + 0 + + 0 + + + 0 + + 1 + m_stOffsetX + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_tcOffsetX + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + mm + 0 + + 0 + + + 0 + + 1 + m_stUnitX + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Offset Y + 0 + + 0 + + + 0 + + 1 + m_stOffsetY + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_tcOffsetY + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + mm + 0 + + 0 + + + 0 + + 1 + m_stUnitY + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Rotation + 0 + + 0 + + + 0 + + 1 + m_stLayerRot + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_tcRotation + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + dummy + 0 + + 0 + + + 0 + + 1 + m_stUnitRot + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + + + 5 + wxEXPAND|wxLEFT + 0 + + + bottomButtonsSizer + wxHORIZONTAL + none + + 5 + wxEXPAND|wxALL + 1 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizerStdButtons + protected + + + + + + + + diff --git a/gerbview/dialogs/dialog_draw_layers_settings_base.h b/gerbview/dialogs/dialog_draw_layers_settings_base.h new file mode 100644 index 0000000000..3c6135ae5b --- /dev/null +++ b/gerbview/dialogs/dialog_draw_layers_settings_base.h @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_DRAW_LAYERS_SETTINGS_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_DRAW_LAYERS_SETTINGS_BASE : public DIALOG_SHIM +{ + private: + wxBoxSizer* m_namiSizer; + + protected: + wxStaticText* m_stLayerNameTitle; + wxStaticText* m_stLayerName; + wxStaticText* m_stOffsetX; + wxTextCtrl* m_tcOffsetX; + wxStaticText* m_stUnitX; + wxStaticText* m_stOffsetY; + wxTextCtrl* m_tcOffsetY; + wxStaticText* m_stUnitY; + wxStaticText* m_stLayerRot; + wxTextCtrl* m_tcRotation; + wxStaticText* m_stUnitRot; + wxStdDialogButtonSizer* m_sdbSizerStdButtons; + wxButton* m_sdbSizerStdButtonsOK; + wxButton* m_sdbSizerStdButtonsCancel; + + // Virtual event handlers, override them in your derived class + virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); } + virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } + + + public: + + DIALOG_DRAW_LAYERS_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 311,203 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + ~DIALOG_DRAW_LAYERS_SETTINGS_BASE(); + +}; + diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 27554abe1b..6168e70784 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -138,6 +138,9 @@ VECTOR2I GERBER_DRAW_ITEM::GetABPosition( const VECTOR2I& aXYPosition ) const */ VECTOR2I abPos = aXYPosition + m_GerberImageFile->m_ImageJustifyOffset; + // We have also a draw transform (rotation and offset) + // order is rotation and after offset + if( m_swapAxis ) std::swap( abPos.x, abPos.y ); @@ -157,6 +160,13 @@ VECTOR2I GERBER_DRAW_ITEM::GetABPosition( const VECTOR2I& aXYPosition ) const if( !m_mirrorB ) abPos.y = -abPos.y; + // Now generate the draw transform + if( !m_GerberImageFile->m_DrawRotation.IsZero() ) + RotatePoint( abPos, m_GerberImageFile->m_DrawRotation ); + + abPos.x += KiROUND( m_GerberImageFile->m_DrawOffset.x * m_drawScale.x ); + abPos.y += KiROUND( m_GerberImageFile->m_DrawOffset.y * m_drawScale.y ); + return abPos; } @@ -166,6 +176,13 @@ VECTOR2I GERBER_DRAW_ITEM::GetXYPosition( const VECTOR2I& aABPosition ) const // do the inverse transform made by GetABPosition VECTOR2I xyPos = aABPosition; + // First, undo the draw transform + xyPos.x -= KiROUND( m_GerberImageFile->m_DrawOffset.x * m_drawScale.x ); + xyPos.y -= KiROUND( m_GerberImageFile->m_DrawOffset.y * m_drawScale.y ); + + if( !m_GerberImageFile->m_DrawRotation.IsZero() ) + RotatePoint( xyPos, -m_GerberImageFile->m_DrawRotation ); + if( m_mirrorA ) xyPos.x = -xyPos.x; diff --git a/gerbview/gerber_file_image.cpp b/gerbview/gerber_file_image.cpp index 4e70465159..c70bbe1798 100644 --- a/gerbview/gerber_file_image.cpp +++ b/gerbview/gerber_file_image.cpp @@ -109,6 +109,19 @@ GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE() } +void GERBER_FILE_IMAGE::SetDrawOffetAndRotation( VECTOR2D aOffsetMM, EDA_ANGLE aRotation ) +{ + m_DrawOffset.x = KiROUND( aOffsetMM.x * gerbIUScale.IU_PER_MM ); + m_DrawOffset.y = KiROUND( aOffsetMM.y * gerbIUScale.IU_PER_MM ); + m_DrawRotation = aRotation; + + // Clear m_AbsolutePolygon member of Gerber items, because draw coordinates + // are now outdated + for( GERBER_DRAW_ITEM* item : GetItems() ) + item->m_AbsolutePolygon.RemoveAllContours(); +} + + D_CODE* GERBER_FILE_IMAGE::GetDCODEOrCreate( int aDCODE, bool aCreateIfNoExist ) { unsigned ndx = aDCODE - FIRST_DCODE; @@ -212,6 +225,9 @@ void GERBER_FILE_IMAGE::ResetDefaultValues() m_Selected_Tool = 0; m_Last_Pen_Command = 0; m_Exposure = false; + + m_DrawOffset.x = m_DrawOffset.y = 0; + m_DrawRotation = ANGLE_0; } diff --git a/gerbview/gerber_file_image.h b/gerbview/gerber_file_image.h index 4fc7e90f54..b074dae00f 100644 --- a/gerbview/gerber_file_image.h +++ b/gerbview/gerber_file_image.h @@ -280,6 +280,15 @@ public: */ void DisplayImageInfo( GERBVIEW_FRAME* aMainFrame ); + /** + * Set the offset and rotation to draw a file image + * Does not change any coordinate od draw items + * @param aOffsetMM is the draw offset in millimeters + * @param aRotation is the draw roation + * draw transform order is rotation and after offset + */ + void SetDrawOffetAndRotation( VECTOR2D aOffsetMM, EDA_ANGLE aRotation ); + /** * Called when a %TD command is found the Gerber file * @@ -455,6 +464,11 @@ public: GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer GERBER_DRAW_ITEMS m_drawings; // linked list of Gerber Items to draw + ///< Parameters used only to draw items on this layer. + ///< Not not change actual coordinates/orientation + VECTOR2I m_DrawOffset; + EDA_ANGLE m_DrawRotation; + private: wxArrayString m_messagesList; // A list of messages created when reading a file diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 6953057420..ad9b46db15 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -53,6 +53,7 @@ #include "widgets/gbr_layer_box_selector.h" #include "widgets/gerbview_layer_widget.h" #include "widgets/dcode_selection_box.h" +#include #include @@ -560,6 +561,29 @@ void GERBVIEW_FRAME::RemapLayers( std::unordered_map remapping ) } +void GERBVIEW_FRAME::SetLayerDrawPrms() +{ + // Adjust draw params: draw offset and draw rotation for a gerber file image + GERBER_FILE_IMAGE* gerber = GetGbrImage( GetActiveLayer() ); + + if( !gerber ) + return; + + DIALOG_DRAW_LAYERS_SETTINGS dlg( this ); + + if( dlg.ShowModal() != wxID_OK ) + return; + + KIGFX::VIEW* view = GetCanvas()->GetView(); + + view->RecacheAllItems(); + view->MarkDirty(); + view->UpdateAllItems( KIGFX::ALL ); + + GetCanvas()->Refresh(); +} + + void GERBVIEW_FRAME::UpdateXORLayers() { auto target = GetCanvas()->GetBackend() == GERBVIEW_DRAW_PANEL_GAL::GAL_TYPE_OPENGL diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index e34a3bb937..ddffc862a5 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -351,6 +351,9 @@ public: void SortLayersByFileExtension(); void SortLayersByX2Attributes(); + // Adjust draw params: draw offset and draw rotation for a gerber file image + void SetLayerDrawPrms(); + /** * Takes a layer remapping and reorders the layers. * diff --git a/gerbview/widgets/gerbview_layer_widget.cpp b/gerbview/widgets/gerbview_layer_widget.cpp index 492a4c64f6..0bd04d0939 100644 --- a/gerbview/widgets/gerbview_layer_widget.cpp +++ b/gerbview/widgets/gerbview_layer_widget.cpp @@ -182,6 +182,11 @@ void GERBER_LAYER_WIDGET::AddRightClickMenuItems( wxMenu* aMenu ) aMenu->AppendSeparator(); + AddMenuItem( aMenu, ID_SET_GBR_LAYERS_DRAW_PRMS, _( "Active Layer Draw Params: Set Offset and Rotation" ), + KiBitmap( BITMAPS::tools ) ); + + aMenu->AppendSeparator(); + AddMenuItem( aMenu, ID_LAYER_MOVE_UP, _( "Move Current Layer Up" ), KiBitmap( BITMAPS::up ) ); AddMenuItem( aMenu, ID_LAYER_MOVE_DOWN, _( "Move Current Layer Down" ), @@ -251,6 +256,10 @@ void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) m_frame->SortLayersByFileExtension(); break; + case ID_SET_GBR_LAYERS_DRAW_PRMS: + m_frame->SetLayerDrawPrms(); + break; + case ID_LAYER_MOVE_UP: m_frame->GetToolManager()->RunAction( GERBVIEW_ACTIONS::moveLayerUp ); break; diff --git a/gerbview/widgets/gerbview_layer_widget.h b/gerbview/widgets/gerbview_layer_widget.h index 9d4c858752..57f52947ec 100644 --- a/gerbview/widgets/gerbview_layer_widget.h +++ b/gerbview/widgets/gerbview_layer_widget.h @@ -102,6 +102,7 @@ protected: ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE, ID_SORT_GBR_LAYERS_X2, ID_SORT_GBR_LAYERS_FILE_EXT, + ID_SET_GBR_LAYERS_DRAW_PRMS, ID_LAYER_MOVE_UP, ID_LAYER_MOVE_DOWN, ID_LAYER_DELETE,