2011-10-21 13:59:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file sheetlab.cpp
|
|
|
|
* @brief Create and edit the SCH_SHEET_PIN items.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
|
|
|
|
#include <dialogs/dialog_sch_edit_sheet_pin.h>
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
int SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
|
|
|
|
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( DEFAULT_SIZE_TEXT, DEFAULT_SIZE_TEXT );
|
|
|
|
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( aSheetPin == NULL )
|
2009-12-06 18:04:41 +00:00
|
|
|
return wxID_CANCEL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
DIALOG_SCH_EDIT_SHEET_PIN dlg( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
dlg.SetLabelName( aSheetPin->GetText() );
|
|
|
|
dlg.SetTextHeight( ReturnStringFromValue( g_UserUnit, aSheetPin->GetSize().y ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextHeightUnits( GetUnitsLabel( g_UserUnit ) );
|
2013-03-18 19:36:07 +00:00
|
|
|
dlg.SetTextWidth( ReturnStringFromValue( g_UserUnit, aSheetPin->GetSize().x ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextWidthUnits( GetUnitsLabel( g_UserUnit ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
dlg.SetConnectionType( aSheetPin->GetShape() );
|
2009-12-06 18:04:41 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
/* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
|
|
|
|
* the flex grid sizer in wxGTK that prevents the last column from being sized
|
|
|
|
* correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
|
|
|
|
* in ugly #ifdef __WXGTK__ #endif.
|
|
|
|
*/
|
|
|
|
dlg.Layout();
|
|
|
|
dlg.Fit();
|
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return wxID_CANCEL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( aDC )
|
2011-12-22 13:28:11 +00:00
|
|
|
aSheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-10-21 13:59:15 +00:00
|
|
|
if( !aSheetPin->IsNew() )
|
|
|
|
{
|
|
|
|
SaveCopyInUndoList( (SCH_ITEM*) aSheetPin->GetParent(), UR_CHANGED );
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aSheetPin->SetText( dlg.GetLabelName() );
|
|
|
|
aSheetPin->SetSize( wxSize( ReturnValueFromString( g_UserUnit, dlg.GetTextHeight() ),
|
|
|
|
ReturnValueFromString( g_UserUnit, dlg.GetTextWidth() ) ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
aSheetPin->SetShape( dlg.GetConnectionType() );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
if( aDC )
|
2011-12-22 13:28:11 +00:00
|
|
|
aSheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
return wxID_OK;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxString line;
|
|
|
|
SCH_SHEET_PIN* sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
|
|
|
|
sheetPin->SetFlags( IS_NEW );
|
2013-03-18 19:36:07 +00:00
|
|
|
sheetPin->SetSize( m_lastSheetPinTextSize );
|
2011-12-08 15:45:01 +00:00
|
|
|
sheetPin->SetShape( m_lastSheetPinType );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
int response = EditSheetPin( sheetPin, NULL );
|
2009-12-06 18:04:41 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
|
2009-12-06 18:04:41 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
delete sheetPin;
|
2009-12-06 18:04:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_lastSheetPinType = sheetPin->GetShape();
|
2013-03-18 19:36:07 +00:00
|
|
|
m_lastSheetPinTextSize = sheetPin->GetSize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->SetPosition( GetCrossHairPosition() );
|
|
|
|
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-10-21 13:59:15 +00:00
|
|
|
MoveItem( (SCH_ITEM*) sheetPin, aDC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
EDA_ITEM* item;
|
|
|
|
SCH_SHEET_PIN* sheetPin;
|
|
|
|
SCH_HIERLABEL* label = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( !aSheet->GetScreen() )
|
2009-11-04 20:46:53 +00:00
|
|
|
return NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
item = aSheet->GetScreen()->GetDrawItems();
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
for( ; item != NULL; item = item->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( item->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
label = (SCH_HIERLABEL*) item;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
/* A global label has been found: check if there a corresponding sheet label. */
|
2013-03-18 19:36:07 +00:00
|
|
|
if( !aSheet->HasPin( label->GetText() ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
label = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( label == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin->SetFlags( IS_NEW );
|
2013-03-18 19:36:07 +00:00
|
|
|
sheetPin->SetSize( m_lastSheetPinTextSize );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_lastSheetPinType = label->GetShape();
|
|
|
|
sheetPin->SetShape( label->GetShape() );
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->SetPosition( GetCrossHairPosition() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-10-21 13:59:15 +00:00
|
|
|
MoveItem( (SCH_ITEM*) sheetPin, aDC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|