KiCad PCB EDA Suite
dialog_lib_edit_draw_item.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 
28 #include <lib_item.h>
30 #include <symbol_edit_frame.h>
31 #include <confirm.h>
32 
33 
35  LIB_ITEM* aItem ) :
37  m_frame( aParent ),
38  m_item( aItem ),
39  m_lineWidth( aParent, m_widthLabel, m_widthCtrl, m_widthUnits, true )
40 {
41  SetTitle( aItem->GetTypeName() + wxT( " " ) + GetTitle() );
42 
44 
45  // Required under wxGTK if we want to dismiss the dialog with the ESC key
46  SetFocus();
47 
48  if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
49  {
50  m_sdbSizerCancel->SetDefault();
51  m_sdbSizerOK->SetLabel( _( "Read Only" ) );
52  m_sdbSizerOK->Enable( false );
53  }
54  else
55  {
56  m_sdbSizerOK->SetDefault();
57  }
58 
59  // Now all widgets have the size fixed, call FinishDialogSettings
61 }
62 
63 
65 {
66  if( !wxDialog::TransferDataToWindow() )
67  return false;
68 
69  LIB_PART* symbol = m_item->GetParent();
70 
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 graphic items, symbol->HasConversion() returns false.
79  // but when creating a new symbol, with DeMorgan option set, the ApplyToAllConversions
80  // must be enabled even if symbol->HasConversion() returns false in order to be able
81  // 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  m_fillCtrl->SetSelection( static_cast<int>( m_item->GetFillMode() ) );
88  m_fillCtrl->Enable( m_item->IsFillable() );
89 
90  return true;
91 }
92 
93 
95 {
96  if( !wxDialog::TransferDataFromWindow() )
97  return false;
98 
99  // Min. 1 um and max. 1 m are more than enough.
100  if( !m_lineWidth.Validate( 0, 1000.0, EDA_UNITS::MILLIMETRES ) )
101  return false;
102 
103  if( m_lineWidth.GetValue() == 0
104  && ( (FILL_TYPE) m_fillCtrl->GetSelection() ) != FILL_TYPE::FILLED_SHAPE )
105  {
106  DisplayError( this, _( "Line width may not be 0 for shapes other than filled with body "
107  "outline color." ) );
108  m_widthCtrl->SetFocus();
109  return false;
110  }
111 
112  if( m_item->IsFillable() )
113  m_item->SetFillMode( (FILL_TYPE) std::max( m_fillCtrl->GetSelection(), 0 ) );
114 
116 
118  m_item->SetConvert( 0 );
119  else
121 
122  if( GetApplyToAllUnits() )
123  m_item->SetUnit( 0 );
124  else
125  m_item->SetUnit( m_frame->GetUnit() );
126 
127  return true;
128 }
129 
130 
132 {
133  return m_checkApplyToAllConversions->IsChecked();
134 }
135 
136 
138 {
139  return m_checkApplyToAllUnits->IsChecked();
140 }
141 
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:28
This file is part of the common library.
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
LIB_PART * GetParent() const
Definition: lib_item.h:147
virtual void SetWidth(int aWidth)=0
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:265
Class DIALOG_LIB_EDIT_DRAW_ITEM_BASE.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
bool GetShowDeMorgan() const
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
FILL_TYPE GetFillMode() const
Definition: lib_item.h:266
int GetUnit() const
Definition: lib_item.h:260
int GetUnitCount() const override
For items with units, return the number of units.
bool IsSymbolAlias() const
Restore the empty editor screen, without any part or library selected.
Define a library symbol object.
Definition: lib_symbol.h:93
int GetConvert() const
Definition: lib_item.h:263
void SetConvert(int aConvert)
Definition: lib_item.h:262
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual int GetWidth() const =0
void SetUnit(int aUnit)
Definition: lib_item.h:259
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
#define _(s)
Definition: 3d_actions.cpp:33
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.
bool IsFillable() const
Check if draw object can be filled.
Definition: lib_item.h:257
DIALOG_LIB_EDIT_DRAW_ITEM(SYMBOL_EDIT_FRAME *parent, LIB_ITEM *aItem)
Constructor.
The symbol library editor main window.