KiCad PCB EDA Suite
dialog_lib_shape_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 (C) 2006-2021 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 
24 #include <lib_item.h>
26 #include <symbol_edit_frame.h>
27 #include <confirm.h>
28 
29 
31  LIB_ITEM* aItem ) :
33  m_frame( aParent ),
34  m_item( aItem ),
35  m_lineWidth( aParent, m_widthLabel, m_widthCtrl, m_widthUnits, true )
36 {
37  SetTitle( aItem->GetTypeName() + wxT( " " ) + GetTitle() );
38  m_helpLabel->SetFont( KIUI::GetInfoFont( this ) );
39 
41 
42  // Required under wxGTK if we want to dismiss the dialog with the ESC key
43  SetFocus();
44 
45  if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
46  {
47  m_sdbSizerCancel->SetDefault();
48  m_sdbSizerOK->SetLabel( _( "Read Only" ) );
49  m_sdbSizerOK->Enable( false );
50  }
51  else
52  {
53  m_sdbSizerOK->SetDefault();
54  }
55 
56  // Now all widgets have the size fixed, call FinishDialogSettings
58 }
59 
60 
62 {
63  if( !wxDialog::TransferDataToWindow() )
64  return false;
65 
66  LIB_SYMBOL* symbol = m_item->GetParent();
67  EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( m_item );
68 
69  if( shape )
70  m_lineWidth.SetValue( shape->GetWidth() );
71 
72  m_checkApplyToAllUnits->SetValue( m_item->GetUnit() == 0 );
73  m_checkApplyToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
74  m_checkApplyToAllConversions->SetValue( m_item->GetConvert() == 0 );
75 
76  bool enblConvOptStyle = symbol && symbol->HasConversion();
77 
78  // If a symbol contains no conversion-specific pins or graphic items, symbol->HasConversion()
79  // will return false.
80  // But when creating a new symbol, with DeMorgan option set, the ApplyToAllConversions
81  // must be enabled in order to be able to create graphic items shared by all body styles.
82  if( m_frame->GetShowDeMorgan() )
83  enblConvOptStyle = true;
84 
85  m_checkApplyToAllConversions->Enable( enblConvOptStyle );
86 
87  if( shape )
88  m_fillCtrl->SetSelection( static_cast<int>( shape->GetFillType() ) - 1 );
89 
90  m_fillCtrl->Enable( shape != nullptr );
91 
92  return true;
93 }
94 
95 
97 {
98  if( !wxDialog::TransferDataFromWindow() )
99  return false;
100 
101  EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( m_item );
102 
103  if( shape )
104  shape->SetFillMode( static_cast<FILL_T>( std::max( m_fillCtrl->GetSelection() + 1, 1 ) ) );
105 
106  if( shape )
107  shape->SetWidth( m_lineWidth.GetValue() );
108 
110  m_item->SetConvert( 0 );
111  else
113 
114  if( GetApplyToAllUnits() )
115  m_item->SetUnit( 0 );
116  else
117  m_item->SetUnit( m_frame->GetUnit() );
118 
119  return true;
120 }
121 
122 
124 {
125  return m_checkApplyToAllConversions->IsChecked();
126 }
127 
128 
130 {
131  return m_checkApplyToAllUnits->IsChecked();
132 }
133 
Class DIALOG_LIB_SHAPE_PROPERTIES_BASE.
int GetWidth() const
Definition: eda_shape.h:98
This file is part of the common library.
DIALOG_LIB_SHAPE_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_ITEM *aItem)
Constructor.
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
Define a library symbol object.
Definition: lib_symbol.h:96
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
bool GetShowDeMorgan() const
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
int GetUnit() const
Definition: lib_item.h:266
bool IsSymbolAlias() const
Restore the empty editor screen, without any symbol or library selected.
int GetUnitCount() const override
For items with units, return the number of units.
#define _(s)
void SetWidth(int aWidth)
Definition: eda_shape.h:97
int GetConvert() const
Definition: lib_item.h:269
void SetConvert(int aConvert)
Definition: lib_item.h:268
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:164
void SetUnit(int aUnit)
Definition: lib_item.h:265
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87
FILL_T GetFillType() const
Definition: eda_shape.h:88
The symbol library editor main window.