KiCad PCB EDA Suite
dialog_lib_edit_pin.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) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2016 KiCad Developers, see CHANGELOG.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 <fctsys.h>
26 #include <macros.h>
27 #include <gr_basic.h>
28 #include <base_units.h>
29 #include <bitmaps.h>
30 
31 #include <libeditframe.h>
32 #include <class_libentry.h>
33 #include <lib_pin.h>
34 
35 #include <dialog_lib_edit_pin.h>
36 
38  DIALOG_LIB_EDIT_PIN_BASE( parent )
39 {
40  // Creates a dummy pin to show on a panel, inside this dialog:
41  m_dummyPin = new LIB_PIN( *aPin );
42 
43  // m_dummyPin changes do not propagate to other pins of the current lib component,
44  // so set parent to null and clear flags
45  m_dummyPin->SetParent( NULL );
47 
48  m_panelShowPin->SetBackgroundColour( parent->GetDrawBgColor().ToColour() );
49 
50  // Set tab order
51  m_textPadName->MoveAfterInTabOrder(m_textPinName);
52  m_sdbSizerButtonsOK->SetDefault();
53 
54  // On some windows manager (Unity, XFCE), this dialog is
55  // not always raised, depending on this dialog is run.
56  // Force it to be raised
57  Raise();
58 }
59 
60 
62 {
63  delete m_dummyPin;
64 }
65 
66 void DIALOG_LIB_EDIT_PIN::OnInitDialog( wxInitDialogEvent& event )
67 {
68  m_textPinName->SetFocus();
69 
70  // Now all widgets have the size fixed, call FinishDialogSettings
72 }
73 
74 /*
75  * Draw (on m_panelShowPin) the pin currently edited
76  * accroding to current settings in dialog
77  */
78 void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event )
79 {
80  wxPaintDC dc( m_panelShowPin );
81  wxSize dc_size = dc.GetSize();
82  dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
83 
84  // Give a parent to m_dummyPin only from draw purpose.
85  // In fact m_dummyPin should not have a parent, but draw functions need a parent
86  // to know some options, about pin texts
87  LIB_EDIT_FRAME* libframe = (LIB_EDIT_FRAME*) GetParent();
88  m_dummyPin->SetParent( libframe->GetCurPart() );
89 
90  // Calculate a suitable scale to fit the available draw area
92  double xscale = (double) dc_size.x / bBox.GetWidth();
93  double yscale = (double) dc_size.y / bBox.GetHeight();
94  double scale = std::min( xscale, yscale );
95 
96  // Give a 10% margin
97  scale *= 0.9;
98  dc.SetUserScale( scale, scale );
99 
100  wxPoint offset = -bBox.Centre();
101 
102  GRResetPenAndBrush( &dc );
103 
104  // This is a flag for m_dummyPin->Draw
105  uintptr_t flags = uintptr_t( PIN_DRAW_TEXTS | PIN_DRAW_DANGLING );
106 
107  m_dummyPin->Draw( NULL, &dc, offset, COLOR4D::UNSPECIFIED, GR_COPY,
108  (void*)flags, DefaultTransform );
109 
110  m_dummyPin->SetParent(NULL);
111 
112  event.Skip();
113 }
114 
115 void DIALOG_LIB_EDIT_PIN::OnCloseDialog( wxCloseEvent& event )
116 {
117  EndModal( wxID_CANCEL );
118 }
119 
120 void DIALOG_LIB_EDIT_PIN::OnCancelButtonClick( wxCommandEvent& event )
121 {
122  EndModal( wxID_CANCEL );
123 }
124 
125 void DIALOG_LIB_EDIT_PIN::OnOKButtonClick( wxCommandEvent& event )
126 {
127  EndModal( wxID_OK );
128 }
129 
130 // Called when a pin properties changes
131 void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event )
132 {
133  if( ! IsShown() ) // do nothing at init time
134  return;
135 
136  int pinNameSize = ValueFromString( g_UserUnit, GetPinNameTextSize() );
137  int pinNumSize = ValueFromString( g_UserUnit, GetPadNameTextSize());
138  int pinOrient = LIB_PIN::GetOrientationCode( GetOrientation() );
139  int pinLength = ValueFromString( g_UserUnit, GetLength() );
140  GRAPHIC_PINSHAPE pinShape = GetStyle();
142 
144  m_dummyPin->SetNameTextSize( pinNameSize );
146  m_dummyPin->SetNumberTextSize( pinNumSize );
147  m_dummyPin->SetOrientation( pinOrient );
148  m_dummyPin->SetLength( pinLength );
149  m_dummyPin->SetShape( pinShape );
151  m_dummyPin->SetType( pinType );
152 
153  m_panelShowPin->Refresh();
154 }
155 
156 void DIALOG_LIB_EDIT_PIN::SetDlgUnitsLabel( const wxString& units )
157 {
158  m_staticNameTextSizeUnits->SetLabel( units );
159  m_staticNumberTextSizeUnits->SetLabel( units );
160  m_staticLengthUnits->SetLabel( units );
161  m_staticPosXUnits->SetLabel( units );
162  m_staticPosYUnits->SetLabel( units );
163 }
164 
165 void DIALOG_LIB_EDIT_PIN::SetOrientationList( const wxArrayString& list,
166  const BITMAP_DEF* aBitmaps )
167 {
168  for ( unsigned ii = 0; ii < list.GetCount(); ii++ )
169  {
170  if( aBitmaps == NULL )
171  m_choiceOrientation->Append( list[ii] );
172  else
173  m_choiceOrientation->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii );
174  }
175 }
void SetNumberTextSize(int aSize)
Set the size of the pin number text.
Definition: lib_pin.cpp:231
void GRResetPenAndBrush(wxDC *DC)
Definition: gr_basic.cpp:196
void OnCancelButtonClick(wxCommandEvent &event) override
wxString GetPadNameTextSize(void)
PNG memory record (file in memory).
Definition: bitmap_types.h:38
void SetOrientation(int aOrientation)
Set orientation on the pin.
Definition: lib_pin.cpp:256
Implementation of conversion functions that require both schematic and board internal units...
Class DIALOG_LIB_EDIT_PIN_BASE.
Subclass of DIALOG_LIB_EDIT_PIN_BASE, which is generated by wxFormBuilder.
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:282
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int GetHeight() const
void SetLength(int aLength)
Set the pin length.
Definition: lib_pin.cpp:344
void OnOKButtonClick(wxCommandEvent &event) override
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:138
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
void SetOrientationList(const wxArrayString &list, const BITMAP_DEF *aBitmaps)
This file contains miscellaneous commonly used macros and functions.
void OnCloseDialog(wxCloseEvent &event) override
ELECTRICAL_PINTYPE GetElectricalType(void)
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:214
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
void SetType(ELECTRICAL_PINTYPE aType)
Set the electrical type of the pin.
Definition: lib_pin.cpp:311
void OnPaintShowPanel(wxPaintEvent &event) override
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:286
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
Class LIB_ITEM definition.
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:459
wxPoint Centre() const
EDA_UNITS_T g_UserUnit
display units
Definition: common.cpp:57
void OnInitDialog(wxInitDialogEvent &event) override
The component library editor main window.
Definition: libeditframe.h:51
const int scale
GRAPHIC_PINSHAPE GetStyle(void)
TRANSFORM DefaultTransform
Definition: eeschema.cpp:57
void SetName(const wxString &aName)
Set the pin name.
Definition: lib_pin.cpp:160
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
void SetNameTextSize(int aSize)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:189
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
wxString GetPinNameTextSize(void)
wxBitmapComboBox * m_choiceOrientation
Class EDA_RECT handles the component boundary box.
LIB_PART * GetCurPart()
Function GetCurPart returns the current part being edited, or NULL if none selected.
int GetWidth() const
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
DIALOG_LIB_EDIT_PIN(EDA_DRAW_FRAME *parent, LIB_PIN *aPin)
Constructor.
void SetDlgUnitsLabel(const wxString &units)
wxString GetPinName(void)
Definition of class LIB_EDIT_FRAME.
void OnPropertiesChange(wxCommandEvent &event) override
#define min(a, b)
Definition: auxiliary.h:85
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:2280