KiCad PCB EDA Suite
panel_edit_options.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 (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <kicad_string.h>
26 #include <panel_edit_options.h>
27 #include <pcb_edit_frame.h>
28 #include <pcb_painter.h>
29 #include <pcb_view.h>
30 #include <pcbnew_settings.h>
32 #include <widgets/paged_dialog.h>
33 #include <footprint_edit_frame.h>
34 
36  PANEL_EDIT_OPTIONS_BASE( aParent->GetTreebook() ), m_frame( aFrame )
37 {
38  m_magneticPads->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
39  m_magneticGraphics->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
40  m_flipLeftRight->Show( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) != nullptr );
41  m_allowFreePads->Show( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) != nullptr );
42 
43 #ifdef __WXOSX_MAC__
44  m_mouseCmdsOSX->Show( true );
45  m_mouseCmdsWinLin->Show( false );
46 #else
47  m_mouseCmdsWinLin->Show( true );
48  m_mouseCmdsOSX->Show( false );
49 #endif
50 
51  m_optionsBook->SetSelection( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) ? 1 : 0 );
52 }
53 
54 
56 {
57  const PCB_DISPLAY_OPTIONS& displ_opts = m_frame->GetDisplayOptions();
58  const PCBNEW_SETTINGS& general_opts = m_frame->Settings();
59 
60  m_segments45OnlyCtrl->SetValue( general_opts.m_Use45DegreeGraphicSegments );
61 
62  wxString rotationAngle;
63  rotationAngle = AngleToStringDegrees( (double) m_frame->GetRotationAngle() );
64  m_rotationAngle->SetValue( rotationAngle );
65 
66  if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
67  {
68  const MAGNETIC_SETTINGS& mag_opts = general_opts.m_MagneticItems;
69 
70  /* Set display options */
72  m_showSelectedRatsnest->SetValue( displ_opts.m_ShowModuleRatsnest );
73 
74  m_magneticPadChoice->SetSelection( static_cast<int>( mag_opts.pads ) );
75  m_magneticTrackChoice->SetSelection( static_cast<int>( mag_opts.tracks ) );
76  m_magneticGraphicsChoice->SetSelection( !mag_opts.graphics );
77 
78  m_flipLeftRight->SetValue( general_opts.m_FlipLeftRight );
79 
80  switch( general_opts.m_TrackDragAction )
81  {
82  case TRACK_DRAG_ACTION::MOVE: m_rbTrackDragMove->SetValue( true ); break;
83  case TRACK_DRAG_ACTION::DRAG: m_rbTrackDrag45->SetValue( true ); break;
84  case TRACK_DRAG_ACTION::DRAG_FREE_ANGLE: m_rbTrackDragFree->SetValue( true ); break;
85  }
86 
87  m_showPageLimits->SetValue( m_frame->ShowPageLimits() );
88  m_autoRefillZones->SetValue( general_opts.m_AutoRefillZones );
89  m_allowFreePads->SetValue( general_opts.m_AllowFreePads );
90  }
91  else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
92  {
94 
95  m_magneticPads->SetValue( mag_opts->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS );
96  m_magneticGraphics->SetValue( mag_opts->graphics );
97  }
98 
99  return true;
100 }
101 
102 
104 {
106 
107  m_frame->SetRotationAngle( wxRound( 10.0 * wxAtof( m_rotationAngle->GetValue() ) ) );
108 
110 
111  if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
112  {
113  PCBNEW_SETTINGS& pcbnewSettings = m_frame->Settings();
114  MAGNETIC_SETTINGS& mag_opts = pcbnewSettings.m_MagneticItems;
115 
117  displ_opts.m_ShowModuleRatsnest = m_showSelectedRatsnest->GetValue();
118 
119  mag_opts.pads = static_cast<MAGNETIC_OPTIONS>( m_magneticPadChoice->GetSelection() );
120  mag_opts.tracks = static_cast<MAGNETIC_OPTIONS>( m_magneticTrackChoice->GetSelection() );
121  mag_opts.graphics = !m_magneticGraphicsChoice->GetSelection();
122 
123  pcbnewSettings.m_FlipLeftRight = m_flipLeftRight->GetValue();
124  pcbnewSettings.m_AutoRefillZones = m_autoRefillZones->GetValue();
125  pcbnewSettings.m_AllowFreePads = m_allowFreePads->GetValue();
126 
128 
129  if( m_rbTrackDragMove->GetValue() )
131  else if( m_rbTrackDrag45->GetValue() )
133  else if( m_rbTrackDragFree->GetValue() )
135  }
136  else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
137  {
139 
140  mag_opts->pads = m_magneticPads->GetValue() ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS
142  mag_opts->graphics = m_magneticGraphics->GetValue();
143  }
144 
145  // Apply changes to the GAL
146  KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
147  KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
148  KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
149 
150  m_frame->SetDisplayOptions( displ_opts, false );
151  settings->LoadDisplayOptions( displ_opts, m_frame->ShowPageLimits() );
152 
154  []( KIGFX::VIEW_ITEM* aItem ) -> bool
155  {
156  return dynamic_cast<RATSNEST_VIEW_ITEM*>( aItem );
157  } );
159 
160  m_frame->GetCanvas()->Refresh();
161 
162  return true;
163 }
164 
165 
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition: view.cpp:1425
bool TransferDataToWindow() override
bool TransferDataFromWindow() override
PCB_BASE_EDIT_FRAME * m_frame
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
PANEL_EDIT_OPTIONS(PCB_BASE_EDIT_FRAME *aFrame, PAGED_DIALOG *aWindow)
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:241
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
bool ShowPageLimits() const
Auxiliary rendering target (noncached)
Definition: definitions.h:49
PCB specific render settings.
Definition: pcb_painter.h:64
bool m_Use45DegreeGraphicSegments
wxCheckBox * m_OptDisplayCurvedRatsnestLines
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
Container for display options like enable/disable some optional drawings.
Item needs to be redrawn.
Definition: view_item.h:57
TRACK_DRAG_ACTION m_TrackDragAction
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:247
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:574
wxString AngleToStringDegrees(double aAngle)
A helper to convert the double aAngle (in internal unit) to a string in degrees.
Definition: string.cpp:903
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int GetRotationAngle() const
Return the angle used for rotate operations.
Common, abstract interface for edit frames.
Class PANEL_EDIT_OPTIONS_BASE.
MAGNETIC_OPTIONS pads
PCBNEW_SETTINGS & Settings()
void SetShowPageLimits(bool aShow)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
MAGNETIC_SETTINGS m_MagneticItems
wxStaticBoxSizer * m_mouseCmdsWinLin
void SetRotationAngle(int aRotationAngle)
Set the angle used for rotate operations.
wxStaticBoxSizer * m_mouseCmdsOSX
MAGNETIC_OPTIONS tracks