2014-10-21 15:48:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2018-05-23 17:41:37 +00:00
|
|
|
* Copyright (C) 2016 - 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2014-10-21 15:48:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <gr_basic.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-10-18 12:25:46 +00:00
|
|
|
#include <sch_painter.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-09-22 11:19:37 +00:00
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
|
|
|
|
#include <dialog_lib_edit_pin.h>
|
2018-05-23 17:41:37 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN( LIB_EDIT_FRAME* parent, LIB_PIN* aPin ) :
|
|
|
|
DIALOG_LIB_EDIT_PIN_BASE( parent ),
|
|
|
|
m_frame( parent ),
|
|
|
|
m_pin( aPin ),
|
|
|
|
m_posX( parent, m_posXLabel, m_posXCtrl, m_posXUnits, true ),
|
|
|
|
m_posY( parent, m_posYLabel, m_posYCtrl, m_posYUnits, true ),
|
2018-11-29 18:59:38 +00:00
|
|
|
m_pinLength( parent, m_pinLengthLabel, m_pinLengthCtrl, m_pinLengthUnits, true ),
|
|
|
|
m_nameSize( parent, m_nameSizeLabel, m_nameSizeCtrl, m_nameSizeUnits, true ),
|
|
|
|
m_numberSize( parent, m_numberSizeLabel, m_numberSizeCtrl, m_numberSizeUnits, true )
|
2012-09-22 11:19:37 +00:00
|
|
|
{
|
|
|
|
// Creates a dummy pin to show on a panel, inside this dialog:
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin = new LIB_PIN( *m_pin );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
// m_dummyPin changes do not propagate to other pins of the current lib component,
|
|
|
|
// so set parent to null and clear flags
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->SetParent( nullptr );
|
2012-09-22 11:19:37 +00:00
|
|
|
m_dummyPin->ClearFlags();
|
|
|
|
|
2018-10-18 12:25:46 +00:00
|
|
|
COLOR4D bgColor = parent->GetRenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
|
|
|
|
m_panelShowPin->SetBackgroundColour( bgColor.ToColour() );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
const wxArrayString& orientationNames = LIB_PIN::GetOrientationNames();
|
|
|
|
const BITMAP_DEF* orientationBitmaps = LIB_PIN::GetOrientationSymbols();
|
|
|
|
|
|
|
|
for ( unsigned ii = 0; ii < orientationNames.GetCount(); ii++ )
|
|
|
|
m_choiceOrientation->Insert( orientationNames[ii], KiBitmap( orientationBitmaps[ii] ), ii );
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
m_sdbSizerButtonsOK->SetDefault();
|
2018-05-23 17:41:37 +00:00
|
|
|
SetInitialFocus( m_textPinName );
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2015-03-14 11:50:39 +00:00
|
|
|
|
2015-03-14 16:47:25 +00:00
|
|
|
// On some windows manager (Unity, XFCE), this dialog is
|
|
|
|
// not always raised, depending on this dialog is run.
|
|
|
|
// Force it to be raised
|
|
|
|
Raise();
|
2012-09-22 11:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_LIB_EDIT_PIN::~DIALOG_LIB_EDIT_PIN()
|
|
|
|
{
|
|
|
|
delete m_dummyPin;
|
|
|
|
}
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
|
|
|
bool DIALOG_LIB_EDIT_PIN::TransferDataToWindow()
|
2015-09-13 22:43:38 +00:00
|
|
|
{
|
2018-05-23 17:41:37 +00:00
|
|
|
if( !DIALOG_SHIM::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_choiceOrientation->SetSelection( LIB_PIN::GetOrientationIndex( m_pin->GetOrientation() ) );
|
|
|
|
m_choiceStyle->SetSelection( m_pin->GetShape() );
|
|
|
|
m_choiceElectricalType->SetSelection( m_pin->GetType() );
|
|
|
|
m_textPinName->SetValue( m_pin->GetName() );
|
|
|
|
m_nameSize.SetValue( m_pin->GetNameTextSize() );
|
|
|
|
m_posX.SetValue( m_pin->GetPosition().x );
|
|
|
|
m_posY.SetValue( -m_pin->GetPosition().y );
|
|
|
|
m_textPinNumber->SetValue( m_pin->GetNumber() );
|
|
|
|
m_numberSize.SetValue( m_pin->GetNumberTextSize() );
|
|
|
|
m_pinLength.SetValue( m_pin->GetLength() );
|
|
|
|
m_checkApplyToAllParts->SetValue( m_pin->GetUnit() == 0 );
|
|
|
|
m_checkApplyToAllConversions->SetValue( m_pin->GetConvert() == 0 );
|
|
|
|
m_checkShow->SetValue( m_pin->IsVisible() );
|
|
|
|
|
2019-02-15 23:59:37 +00:00
|
|
|
m_dummyPin->SetVisible( m_pin->IsVisible() );
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-16 10:54:55 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
|
|
|
bool DIALOG_LIB_EDIT_PIN::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !DIALOG_SHIM::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const int acceptable_mingrid = 50;
|
|
|
|
|
|
|
|
if( ( m_posX.GetValue() % acceptable_mingrid ) || ( m_posY.GetValue() % acceptable_mingrid ) )
|
|
|
|
{
|
|
|
|
auto msg = wxString::Format( _( "This pin is not on a %d mils grid which will make it\n"
|
|
|
|
"difficult to connect to in the schematic.\n"
|
|
|
|
"Do you want to continue?" ),
|
|
|
|
acceptable_mingrid );
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_pin->InEditMode() )
|
|
|
|
m_frame->SaveCopyInUndoList( m_pin->GetParent() );
|
|
|
|
|
|
|
|
m_pin->SetName( m_textPinName->GetValue() );
|
|
|
|
m_pin->SetNumber( m_textPinNumber->GetValue() );
|
|
|
|
m_pin->SetNameTextSize( m_nameSize.GetValue() );
|
|
|
|
m_pin->SetNumberTextSize( m_numberSize.GetValue() );
|
|
|
|
m_pin->SetOrientation( LIB_PIN::GetOrientationCode( m_choiceOrientation->GetSelection() ) );
|
|
|
|
m_pin->SetLength( m_pinLength.GetValue() );
|
|
|
|
m_pin->SetPinPosition( wxPoint( m_posX.GetValue(), -m_posY.GetValue() ) );
|
|
|
|
m_pin->SetType( m_choiceElectricalType->GetPinTypeSelection() );
|
|
|
|
m_pin->SetShape( m_choiceStyle->GetPinShapeSelection() );
|
|
|
|
m_pin->SetConversion( m_checkApplyToAllConversions->GetValue() ? 0 : m_frame->GetConvert() );
|
|
|
|
m_pin->SetPartNumber( m_checkApplyToAllParts->GetValue() ? 0 : m_frame->GetUnit() );
|
|
|
|
m_pin->SetVisible( m_checkShow->GetValue() );
|
|
|
|
|
|
|
|
return true;
|
2015-09-13 22:43:38 +00:00
|
|
|
}
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
/*
|
2018-05-23 17:41:37 +00:00
|
|
|
* Draw (on m_panelShowPin) the pin currently edited accroding to current settings in dialog
|
2012-09-22 11:19:37 +00:00
|
|
|
*/
|
|
|
|
void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event )
|
|
|
|
{
|
|
|
|
wxPaintDC dc( m_panelShowPin );
|
|
|
|
wxSize dc_size = dc.GetSize();
|
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Give a parent to m_dummyPin only from draw purpose.
|
|
|
|
// In fact m_dummyPin should not have a parent, but draw functions need a parent
|
|
|
|
// to know some options, about pin texts
|
|
|
|
LIB_EDIT_FRAME* libframe = (LIB_EDIT_FRAME*) GetParent();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
m_dummyPin->SetParent( libframe->GetCurPart() );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
// Calculate a suitable scale to fit the available draw area
|
2019-02-15 23:59:37 +00:00
|
|
|
EDA_RECT bBox = m_dummyPin->GetBoundingBox( true );
|
2012-09-22 11:19:37 +00:00
|
|
|
double xscale = (double) dc_size.x / bBox.GetWidth();
|
|
|
|
double yscale = (double) dc_size.y / bBox.GetHeight();
|
|
|
|
double scale = std::min( xscale, yscale );
|
|
|
|
|
|
|
|
// Give a 10% margin
|
|
|
|
scale *= 0.9;
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
GRResetPenAndBrush( &dc );
|
2016-05-19 16:38:36 +00:00
|
|
|
|
|
|
|
// This is a flag for m_dummyPin->Draw
|
|
|
|
uintptr_t flags = uintptr_t( PIN_DRAW_TEXTS | PIN_DRAW_DANGLING );
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->Draw( nullptr, &dc, -bBox.Centre(), COLOR4D::UNSPECIFIED, GR_COPY, (void*)flags,
|
|
|
|
DefaultTransform );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->SetParent( nullptr );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event )
|
|
|
|
{
|
2018-05-23 17:41:37 +00:00
|
|
|
if( !IsShown() ) // do nothing at init time
|
2012-09-22 11:19:37 +00:00
|
|
|
return;
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->SetName( m_textPinName->GetValue() );
|
|
|
|
m_dummyPin->SetNumber( m_textPinNumber->GetValue() );
|
|
|
|
m_dummyPin->SetNameTextSize( m_nameSize.GetValue() );
|
|
|
|
m_dummyPin->SetNumberTextSize( m_numberSize.GetValue() );
|
|
|
|
m_dummyPin->SetOrientation( LIB_PIN::GetOrientationCode( m_choiceOrientation->GetSelection() ) );
|
|
|
|
m_dummyPin->SetLength( m_pinLength.GetValue() );
|
|
|
|
m_dummyPin->SetType( m_choiceElectricalType->GetPinTypeSelection() );
|
|
|
|
m_dummyPin->SetShape( m_choiceStyle->GetPinShapeSelection() );
|
|
|
|
m_dummyPin->SetVisible( m_checkShow->GetValue() );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
m_panelShowPin->Refresh();
|
|
|
|
}
|