KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_reference_image_properties.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26
27#include <pcb_base_edit_frame.h>
28#include <pcb_reference_image.h>
29#include <tool/tool_manager.h>
30#include <tool/actions.h>
31#include <board.h>
33
34
36 PCB_REFERENCE_IMAGE& aBitmap ) :
38 m_frame( aParent ),
39 m_bitmap( aBitmap ),
44{
45 // Create the image editor page
46 m_imageEditor = new PANEL_IMAGE_EDITOR( aParent, this, aBitmap.GetReferenceImage().MutableImage() );
47
48 m_imageSizer->Add( m_imageEditor, 1, wxEXPAND | wxALL, 5 );
49
54
57 m_imageEditor->GetScaleCtrl()->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged, this );
58
59 // Only show unactivated board layers if the bitmap is on one of them
60 if( !m_frame->GetBoard()->IsLayerEnabled( m_bitmap.GetLayer() ) )
61 m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
62
63 m_LayerSelectionCtrl->SetLayersHotkeys( false );
64 m_LayerSelectionCtrl->SetBoardFrame( m_frame );
65 m_LayerSelectionCtrl->Resync();
66
68
70}
71
72
74{
75 PCB_REFERENCE_IMAGE& bitmap = static_cast<PCB_REFERENCE_IMAGE&>( *aBitmap );
76 DIALOG_REFERENCE_IMAGE_PROPERTIES dlg( this, bitmap );
77
78 if( dlg.ShowModal() == wxID_OK )
79 {
80 // The bitmap is cached in Opengl: clear the cache in case it has become invalid
83 OnModify();
84 }
85}
86
87
89{
90 m_posX.SetValue( m_bitmap.GetPosition().x );
91 m_posY.SetValue( m_bitmap.GetPosition().y );
92
93 m_LayerSelectionCtrl->SetLayerSelection( m_bitmap.GetLayer() );
94
95 m_cbLocked->SetValue( m_bitmap.IsLocked() );
96 m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be "
97 "selected when the 'Locked items' checkbox is checked in the selection filter." ) );
98
99 m_imageEditor->TransferDataToWindow();
100 VECTOR2I size = m_imageEditor->GetImageSize();
101 m_width.SetValue( size.x );
102 m_height.SetValue( size.y );
103
104 return true;
105}
106
107
109{
110 if( m_imageEditor->TransferDataFromWindow() )
111 {
112 // Save old image in undo list if not already in edit
113 if( m_bitmap.GetEditFlags() == 0 )
114 m_frame->SaveCopyInUndoList( &m_bitmap, UNDO_REDO::CHANGED );
115
116 // Update our bitmap from the editor
117 m_imageEditor->TransferToImage( m_bitmap.GetReferenceImage().MutableImage() );
118
119 // Set position, etc.
120 m_bitmap.SetPosition( VECTOR2I( m_posX.GetIntValue(), m_posY.GetIntValue() ) );
121 m_bitmap.SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
122 m_bitmap.SetLocked( m_cbLocked->GetValue() );
123
124 return true;
125 }
126
127 return false;
128}
129
130
132{
133 double newWidth = m_width.GetDoubleValue();
134 VECTOR2I size = m_imageEditor->GetImageSize();
135
136 if( size.x > 0 )
137 {
138 double scale = m_imageEditor->GetScale() * newWidth / size.x;
139 m_imageEditor->SetScale( scale );
140 VECTOR2I newSize = m_imageEditor->GetImageSize();
141 m_height.ChangeDoubleValue( newSize.y );
142 }
143}
144
145
147{
148 double newHeight = m_height.GetDoubleValue();
149 VECTOR2I size = m_imageEditor->GetImageSize();
150
151 if( size.y > 0 )
152 {
153 double scale = m_imageEditor->GetScale() * newHeight / size.y;
154 m_imageEditor->SetScale( scale );
155 VECTOR2I newSize = m_imageEditor->GetImageSize();
156 m_width.ChangeDoubleValue( newSize.x );
157 }
158}
159
160
162{
163 double scale = m_imageEditor->GetScale();
164
165 if( scale <= 0 )
166 return;
167
168 m_imageEditor->SetScale( scale );
169 VECTOR2I size = m_imageEditor->GetImageSize();
170 m_width.ChangeDoubleValue( size.x );
171 m_height.ChangeDoubleValue( size.y );
172}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Reference Image Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_REFERENCE_IMAGE_PROPERTIES(PCB_BASE_FRAME *aParent, PCB_REFERENCE_IMAGE &aBitmap)
PCB_BASE_FRAME * m_frame
The reference image being edited.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:353
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1451
void ShowReferenceImagePropertiesDialog(BOARD_ITEM *aBitmap)
Set the angle used for rotate operations.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Object to handle a bitmap image that can be inserted in a PCB.
REFERENCE_IMAGE & GetReferenceImage()
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
TOOL_MANAGER * m_toolManager
#define _(s)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
const int scale
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695