2009-11-04 20:46:53 +00:00
|
|
|
/**********************************************************/
|
|
|
|
/* sheetlab.cpp create and edit the SCH_SHEET_PIN items */
|
|
|
|
/**********************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "macros.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
#include "dialogs/dialog_sch_edit_sheet_pin.h"
|
|
|
|
|
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;
|
|
|
|
int SCH_EDIT_FRAME::m_lastSheetPinEdge;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-03-23 19:15:27 +00:00
|
|
|
/* Called when aborting a move pinsheet label
|
|
|
|
* delete a new pin sheet label, or restire its old position
|
|
|
|
*/
|
2011-03-30 19:26:05 +00:00
|
|
|
static void abortSheetPinMove( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxCHECK_RET( (aPanel != NULL) && (aDC != NULL), wxT( "Invalid panel or device context." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
|
|
|
|
SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aPanel->GetScreen()->GetCurItem();
|
|
|
|
|
|
|
|
wxCHECK_RET( (frame != NULL) && (sheetPin != NULL) && (sheetPin->Type() == SCH_SHEET_PIN_T),
|
|
|
|
wxT( "Invalid frame or sheet pin." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
|
|
|
|
if( sheetPin->IsNew() )
|
2009-11-04 20:46:53 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
SAFE_DELETE( sheetPin );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
// Restore edge position:
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin->m_Pos = frame->GetLastSheetPinPosition();
|
|
|
|
sheetPin->SetEdge( frame->GetLastSheetPinEdge() );
|
|
|
|
sheetPin->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
sheetPin->ClearFlags();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
aPanel->GetScreen()->SetCurItem( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
static void moveSheetPin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aPanel->GetScreen()->GetCurItem();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( sheetPin == NULL || sheetPin->Type() != SCH_SHEET_PIN_T )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( aErase )
|
|
|
|
sheetPin->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin->ConstraintOnEdge( aPanel->GetScreen()->GetCrossHairPosition() );
|
|
|
|
sheetPin->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
void SCH_EDIT_FRAME::MoveSheetPin( SCH_SHEET_PIN* aSheetPin, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxCHECK_RET( (aSheetPin != NULL) && (aSheetPin->Type() == SCH_SHEET_PIN_T),
|
|
|
|
wxT( "Cannot move invalid schematic sheet pin object." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
m_lastSheetPinTextSize = aSheetPin->m_Size;
|
|
|
|
m_lastSheetPinType = aSheetPin->m_Shape;
|
|
|
|
m_lastSheetPinPosition = aSheetPin->m_Pos;
|
|
|
|
m_lastSheetPinEdge = aSheetPin->GetEdge();
|
|
|
|
aSheetPin->SetFlags( IS_MOVED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
DrawPanel->SetMouseCapture( moveSheetPin, abortSheetPinMove );
|
|
|
|
moveSheetPin( DrawPanel, aDC, wxDefaultPosition, true );
|
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
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
dlg.SetLabelName( aSheetPin->m_Text );
|
|
|
|
dlg.SetTextHeight( ReturnStringFromValue( g_UserUnit, aSheetPin->m_Size.y, m_InternalUnits ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextHeightUnits( GetUnitsLabel( g_UserUnit ) );
|
2011-03-30 19:26:05 +00:00
|
|
|
dlg.SetTextWidth( ReturnStringFromValue( g_UserUnit, aSheetPin->m_Size.x, m_InternalUnits ) );
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetTextWidthUnits( GetUnitsLabel( g_UserUnit ) );
|
2011-03-30 19:26:05 +00:00
|
|
|
dlg.SetConnectionType( aSheetPin->m_Shape );
|
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-03-30 19:26:05 +00:00
|
|
|
aSheetPin->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
aSheetPin->m_Text = dlg.GetLabelName();
|
|
|
|
aSheetPin->m_Size.y = ReturnValueFromString( g_UserUnit, dlg.GetTextHeight(), m_InternalUnits );
|
|
|
|
aSheetPin->m_Size.x = ReturnValueFromString( g_UserUnit, dlg.GetTextWidth(), m_InternalUnits );
|
|
|
|
aSheetPin->m_Shape = dlg.GetConnectionType();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
|
|
|
if( aDC )
|
2011-03-30 19:26:05 +00:00
|
|
|
aSheetPin->Draw( DrawPanel, 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 );
|
|
|
|
sheetPin->m_Size = m_lastSheetPinTextSize;
|
|
|
|
sheetPin->m_Shape = 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
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( sheetPin->m_Text.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-03-30 19:26:05 +00:00
|
|
|
GetScreen()->SetCurItem( sheetPin );
|
|
|
|
m_lastSheetPinType = sheetPin->m_Shape;
|
|
|
|
m_lastSheetPinTextSize = sheetPin->m_Size;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
DrawPanel->SetMouseCapture( moveSheetPin, abortSheetPinMove );
|
|
|
|
moveSheetPin( DrawPanel, aDC, wxDefaultPosition, false );
|
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. */
|
2011-03-30 19:26:05 +00:00
|
|
|
if( !aSheet->HasPin( label->m_Text ) )
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2011-03-30 19:26:05 +00:00
|
|
|
SaveCopyInUndoList( aSheet, UR_CHANGED );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->m_Text );
|
|
|
|
sheetPin->SetFlags( IS_NEW );
|
|
|
|
sheetPin->m_Size = m_lastSheetPinTextSize;
|
|
|
|
m_lastSheetPinType = sheetPin->m_Shape = label->m_Shape;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
GetScreen()->SetCurItem( sheetPin );
|
|
|
|
DrawPanel->SetMouseCapture( moveSheetPin, abortSheetPinMove );
|
|
|
|
moveSheetPin( DrawPanel, aDC, wxDefaultPosition, false );
|
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
|
|
|
}
|