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, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <pcb_base_edit_frame.h>
24#include <pcb_reference_image.h>
25#include <tool/tool_manager.h>
26#include <tool/actions.h>
27#include <board.h>
29
30
32 PCB_REFERENCE_IMAGE& aBitmap ) :
34 m_frame( aParent ),
35 m_bitmap( aBitmap ),
41{
42 // Create the image editor page
43 m_imageEditor = new PANEL_IMAGE_EDITOR( aParent, this, aBitmap.GetReferenceImage().MutableImage() );
44
45 m_imageSizer->Add( m_imageEditor, 1, wxEXPAND | wxALL, 5 );
46
52
55 m_imageEditor->GetScaleCtrl()->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged, this );
56
57 // Only show unactivated board layers if the bitmap is on one of them
58 if( !m_frame->GetBoard()->IsLayerEnabled( m_bitmap.GetLayer() ) )
59 m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
60
61 // Don't show locked control in the footprint editor
62 if( m_frame->GetBoard()->IsFootprintHolder() )
63 m_cbLocked->Show(false);
64
65 m_LayerSelectionCtrl->SetLayersHotkeys( false );
66 m_LayerSelectionCtrl->SetBoardFrame( m_frame );
67 m_LayerSelectionCtrl->Resync();
68
70
72}
73
74
76{
77 PCB_REFERENCE_IMAGE& bitmap = static_cast<PCB_REFERENCE_IMAGE&>( *aBitmap );
78 DIALOG_REFERENCE_IMAGE_PROPERTIES dlg( this, bitmap );
79
80 if( dlg.ShowModal() == wxID_OK )
81 {
82 // The bitmap is cached in Opengl: clear the cache in case it has become invalid
85 OnModify();
86 }
87}
88
89
91{
92 m_posX.SetValue( m_bitmap.GetPosition().x );
93 m_posY.SetValue( m_bitmap.GetPosition().y );
94 m_rotation.SetAngleValue( m_bitmap.GetReferenceImage().GetOrientation() );
95
96 // A UNIT_BINDER only reads wxTextEntry and wxStaticText controls, so a spin control would
97 // silently report 0.
98 m_ModOpacity->SetValue( m_bitmap.GetReferenceImage().GetOpacity() );
99
100 m_LayerSelectionCtrl->SetLayerSelection( m_bitmap.GetLayer() );
101
102 // Don't populate the locked control in the footprint editor
103 if( !m_frame->GetBoard()->IsFootprintHolder() )
104 {
105 m_cbLocked->SetValue( m_bitmap.IsLocked() );
106 m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be "
107 "selected when the 'Locked items' checkbox is checked in the selection filter." ) );
108 }
109
110 m_imageEditor->TransferDataToWindow();
111 VECTOR2I size = m_imageEditor->GetImageSize();
112 m_width.SetValue( size.x );
113 m_height.SetValue( size.y );
114
115 return true;
116}
117
118
120{
121 if( m_imageEditor->TransferDataFromWindow() )
122 {
123 // Save old image in undo list if not already in edit
124 if( m_bitmap.GetEditFlags() == 0 )
125 m_frame->SaveCopyInUndoList( &m_bitmap, UNDO_REDO::CHANGED );
126
127 // Update our bitmap from the editor
128 m_imageEditor->TransferToImage( m_bitmap.GetReferenceImage().MutableImage() );
129
130 // Set position, etc.
131 m_bitmap.SetPosition( VECTOR2I( m_posX.GetIntValue(), m_posY.GetIntValue() ) );
132 m_bitmap.GetReferenceImage().SetOrientation( m_rotation.GetAngleValue() );
133 m_bitmap.GetReferenceImage().SetOpacity( m_ModOpacity->GetValue() );
134 m_bitmap.SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
135
136 // Only save locked status on non-footprint editor windows
137 if( !m_frame->GetBoard()->IsFootprintHolder() )
138 m_bitmap.SetLocked( m_cbLocked->GetValue() );
139
140 return true;
141 }
142
143 return false;
144}
145
146
148{
149 double newWidth = m_width.GetDoubleValue();
150
151 if( newWidth <= 0 )
152 return;
153
154 VECTOR2I size = m_imageEditor->GetImageSize();
155
156 if( size.x > 0 )
157 {
158 double scale = m_imageEditor->GetScale() * newWidth / size.x;
159 m_imageEditor->SetScale( scale );
160 VECTOR2I newSize = m_imageEditor->GetImageSize();
161 m_height.ChangeDoubleValue( newSize.y );
162 }
163}
164
165
167{
168 double newHeight = m_height.GetDoubleValue();
169
170 if( newHeight <= 0 )
171 return;
172
173 VECTOR2I size = m_imageEditor->GetImageSize();
174
175 if( size.y > 0 )
176 {
177 double scale = m_imageEditor->GetScale() * newHeight / size.y;
178 m_imageEditor->SetScale( scale );
179 VECTOR2I newSize = m_imageEditor->GetImageSize();
180 m_width.ChangeDoubleValue( newSize.x );
181 }
182}
183
184
186{
187 double scale = m_imageEditor->GetScale();
188
189 if( scale <= 0 )
190 return;
191
192 // Update the preview and size fields, but leave the scale field alone. SetScale()
193 // would rewrite it and send the caret back to the start on every keystroke.
194 m_imageEditor->UpdateImageScale( scale );
195 VECTOR2I size = m_imageEditor->GetImageSize();
196 m_width.ChangeDoubleValue( size.x );
197 m_height.ChangeDoubleValue( size.y );
198}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
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_REFERENCE_IMAGE & m_bitmap
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 item had a property changed (except movement)
Definition actions.h:353
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:2222
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 KIGFX::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:750
const int scale
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708