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 // Don't show locked control in the footprint editor
64 if( m_frame->GetBoard()->IsFootprintHolder() )
65 m_cbLocked->Show(false);
66
67 m_LayerSelectionCtrl->SetLayersHotkeys( false );
68 m_LayerSelectionCtrl->SetBoardFrame( m_frame );
69 m_LayerSelectionCtrl->Resync();
70
72
74}
75
76
78{
79 PCB_REFERENCE_IMAGE& bitmap = static_cast<PCB_REFERENCE_IMAGE&>( *aBitmap );
80 DIALOG_REFERENCE_IMAGE_PROPERTIES dlg( this, bitmap );
81
82 if( dlg.ShowModal() == wxID_OK )
83 {
84 // The bitmap is cached in Opengl: clear the cache in case it has become invalid
87 OnModify();
88 }
89}
90
91
93{
94 m_posX.SetValue( m_bitmap.GetPosition().x );
95 m_posY.SetValue( m_bitmap.GetPosition().y );
96
97 m_LayerSelectionCtrl->SetLayerSelection( m_bitmap.GetLayer() );
98
99 // Don't populate the locked control in the footprint editor
100 if( !m_frame->GetBoard()->IsFootprintHolder() )
101 {
102 m_cbLocked->SetValue( m_bitmap.IsLocked() );
103 m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be "
104 "selected when the 'Locked items' checkbox is checked in the selection filter." ) );
105 }
106
107 m_imageEditor->TransferDataToWindow();
108 VECTOR2I size = m_imageEditor->GetImageSize();
109 m_width.SetValue( size.x );
110 m_height.SetValue( size.y );
111
112 return true;
113}
114
115
117{
118 if( m_imageEditor->TransferDataFromWindow() )
119 {
120 // Save old image in undo list if not already in edit
121 if( m_bitmap.GetEditFlags() == 0 )
122 m_frame->SaveCopyInUndoList( &m_bitmap, UNDO_REDO::CHANGED );
123
124 // Update our bitmap from the editor
125 m_imageEditor->TransferToImage( m_bitmap.GetReferenceImage().MutableImage() );
126
127 // Set position, etc.
128 m_bitmap.SetPosition( VECTOR2I( m_posX.GetIntValue(), m_posY.GetIntValue() ) );
129 m_bitmap.SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
130
131 // Only save locked status on non-footprint editor windows
132 if( !m_frame->GetBoard()->IsFootprintHolder() )
133 m_bitmap.SetLocked( m_cbLocked->GetValue() );
134
135 return true;
136 }
137
138 return false;
139}
140
141
143{
144 double newWidth = m_width.GetDoubleValue();
145 VECTOR2I size = m_imageEditor->GetImageSize();
146
147 if( size.x > 0 )
148 {
149 double scale = m_imageEditor->GetScale() * newWidth / size.x;
150 m_imageEditor->SetScale( scale );
151 VECTOR2I newSize = m_imageEditor->GetImageSize();
152 m_height.ChangeDoubleValue( newSize.y );
153 }
154}
155
156
158{
159 double newHeight = m_height.GetDoubleValue();
160 VECTOR2I size = m_imageEditor->GetImageSize();
161
162 if( size.y > 0 )
163 {
164 double scale = m_imageEditor->GetScale() * newHeight / size.y;
165 m_imageEditor->SetScale( scale );
166 VECTOR2I newSize = m_imageEditor->GetImageSize();
167 m_width.ChangeDoubleValue( newSize.x );
168 }
169}
170
171
173{
174 double scale = m_imageEditor->GetScale();
175
176 if( scale <= 0 )
177 return;
178
179 m_imageEditor->SetScale( scale );
180 VECTOR2I size = m_imageEditor->GetImageSize();
181 m_width.ChangeDoubleValue( size.x );
182 m_height.ChangeDoubleValue( size.y );
183}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
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:352
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1469
void ShowReferenceImagePropertiesDialog(BOARD_ITEM *aBitmap)
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:754
const int scale
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695