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 ),
40{
41 // Create the image editor page
42 m_imageEditor = new PANEL_IMAGE_EDITOR( aParent, this, aBitmap.GetReferenceImage().MutableImage() );
43
44 m_imageSizer->Add( m_imageEditor, 1, wxEXPAND | wxALL, 5 );
45
50
53 m_imageEditor->GetScaleCtrl()->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged, this );
54
55 // Only show unactivated board layers if the bitmap is on one of them
56 if( !m_frame->GetBoard()->IsLayerEnabled( m_bitmap.GetLayer() ) )
57 m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
58
59 // Don't show locked control in the footprint editor
60 if( m_frame->GetBoard()->IsFootprintHolder() )
61 m_cbLocked->Show(false);
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 // Don't populate the locked control in the footprint editor
96 if( !m_frame->GetBoard()->IsFootprintHolder() )
97 {
98 m_cbLocked->SetValue( m_bitmap.IsLocked() );
99 m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be "
100 "selected when the 'Locked items' checkbox is checked in the selection filter." ) );
101 }
102
103 m_imageEditor->TransferDataToWindow();
104 VECTOR2I size = m_imageEditor->GetImageSize();
105 m_width.SetValue( size.x );
106 m_height.SetValue( size.y );
107
108 return true;
109}
110
111
113{
114 if( m_imageEditor->TransferDataFromWindow() )
115 {
116 // Save old image in undo list if not already in edit
117 if( m_bitmap.GetEditFlags() == 0 )
118 m_frame->SaveCopyInUndoList( &m_bitmap, UNDO_REDO::CHANGED );
119
120 // Update our bitmap from the editor
121 m_imageEditor->TransferToImage( m_bitmap.GetReferenceImage().MutableImage() );
122
123 // Set position, etc.
124 m_bitmap.SetPosition( VECTOR2I( m_posX.GetIntValue(), m_posY.GetIntValue() ) );
125 m_bitmap.SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
126
127 // Only save locked status on non-footprint editor windows
128 if( !m_frame->GetBoard()->IsFootprintHolder() )
129 m_bitmap.SetLocked( m_cbLocked->GetValue() );
130
131 return true;
132 }
133
134 return false;
135}
136
137
139{
140 double newWidth = m_width.GetDoubleValue();
141
142 if( newWidth <= 0 )
143 return;
144
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
161 if( newHeight <= 0 )
162 return;
163
164 VECTOR2I size = m_imageEditor->GetImageSize();
165
166 if( size.y > 0 )
167 {
168 double scale = m_imageEditor->GetScale() * newHeight / size.y;
169 m_imageEditor->SetScale( scale );
170 VECTOR2I newSize = m_imageEditor->GetImageSize();
171 m_width.ChangeDoubleValue( newSize.x );
172 }
173}
174
175
177{
178 double scale = m_imageEditor->GetScale();
179
180 if( scale <= 0 )
181 return;
182
183 m_imageEditor->SetScale( scale );
184 VECTOR2I size = m_imageEditor->GetImageSize();
185 m_width.ChangeDoubleValue( size.x );
186 m_height.ChangeDoubleValue( size.y );
187}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
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:348
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1552
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:750
const int scale
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683