2011-10-21 13:59:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-04-16 15:26:51 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2011-10-21 13:59:15 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2015-04-16 15:26:51 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-21 13:59:15 +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
|
|
|
|
*/
|
|
|
|
|
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>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2016-02-28 18:16:59 +00:00
|
|
|
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
|
2014-05-16 13:57:53 +00:00
|
|
|
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
|
2011-03-30 19:26:05 +00:00
|
|
|
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-05-16 13:57:53 +00:00
|
|
|
const wxSize &SCH_EDIT_FRAME::GetLastSheetPinTextSize()
|
|
|
|
{
|
|
|
|
// Delayed initialization (need the preferences to be loaded)
|
|
|
|
if( m_lastSheetPinTextSize.x == -1 )
|
|
|
|
{
|
|
|
|
m_lastSheetPinTextSize.x = GetDefaultTextSize();
|
|
|
|
m_lastSheetPinTextSize.y = GetDefaultTextSize();
|
|
|
|
}
|
|
|
|
return m_lastSheetPinTextSize;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
|
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
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
DIALOG_SCH_EDIT_SHEET_PIN dlg( this, aSheetPin );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return wxID_CANCEL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
if( aRedraw )
|
2018-09-09 21:06:38 +00:00
|
|
|
RefreshItem( aSheetPin );
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
return wxID_OK;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet )
|
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 );
|
2017-01-23 20:30:11 +00:00
|
|
|
sheetPin->SetTextSize( GetLastSheetPinTextSize() );
|
2011-12-08 15:45:01 +00:00
|
|
|
sheetPin->SetShape( m_lastSheetPinType );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-27 09:12:32 +00:00
|
|
|
int response = EditSheetPin( sheetPin, false );
|
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();
|
2017-01-23 20:30:11 +00:00
|
|
|
m_lastSheetPinTextSize = sheetPin->GetTextSize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-19 16:27:13 +00:00
|
|
|
sheetPin->SetPosition( GetCrossHairPosition() );
|
2018-09-09 21:06:38 +00:00
|
|
|
PrepareMoveItem( sheetPin );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet )
|
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
|
|
|
{
|
2019-04-15 23:56:41 +00:00
|
|
|
if( item->Type() != SCH_HIER_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 );
|
2017-01-23 20:30:11 +00:00
|
|
|
sheetPin->SetTextSize( GetLastSheetPinTextSize() );
|
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
|
|
|
|
2018-09-09 21:06:38 +00:00
|
|
|
PrepareMoveItem( sheetPin );
|
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
|
|
|
}
|