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"
|
|
|
|
#include "common.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
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
static void ExitPinSheet( WinEDA_DrawPanel* Panel, wxDC* DC );
|
|
|
|
static void Move_PinSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
static int s_CurrentTypeLabel = NET_INPUT;
|
|
|
|
static wxSize NetSheetTextSize( DEFAULT_SIZE_TEXT, DEFAULT_SIZE_TEXT );
|
|
|
|
static wxPoint s_InitialPosition; // remember the initial value of the pin label when moving it
|
2010-09-05 17:01:48 +00:00
|
|
|
static int s_InitialEdge;
|
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
|
|
|
|
*/
|
2007-08-20 01:20:48 +00:00
|
|
|
static void ExitPinSheet( WinEDA_DrawPanel* Panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
SCH_SHEET_PIN* SheetLabel = (SCH_SHEET_PIN*) Panel->GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( SheetLabel == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( SheetLabel->m_Flags & IS_NEW )
|
2009-11-04 20:46:53 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
RedrawOneStruct( Panel, DC, SheetLabel, g_XorMode );
|
2008-03-20 01:50:21 +00:00
|
|
|
SAFE_DELETE( SheetLabel );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-23 19:15:27 +00:00
|
|
|
RedrawOneStruct( Panel, DC, SheetLabel, g_XorMode );
|
|
|
|
SheetLabel->m_Pos = s_InitialPosition;
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
// Restore edge position:
|
|
|
|
SheetLabel->SetEdge( s_InitialEdge );
|
2007-08-20 01:20:48 +00:00
|
|
|
RedrawOneStruct( Panel, DC, SheetLabel, GR_DEFAULT_DRAWMODE );
|
|
|
|
SheetLabel->m_Flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Panel->GetScreen()->SetCurItem( NULL );
|
|
|
|
Panel->ManageCurseur = NULL;
|
|
|
|
Panel->ForceCloseManageCurseur = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_SHEET_PIN::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* Sheet = (SCH_SHEET*) GetParent();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( Sheet != NULL && Sheet->Type() == SCH_SHEET_T );
|
2010-03-24 18:26:04 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2010-03-24 18:26:04 +00:00
|
|
|
int flags = m_Flags;
|
|
|
|
m_Flags = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-03-24 18:26:04 +00:00
|
|
|
if( flags & IS_NEW )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-03-24 18:26:04 +00:00
|
|
|
frame->SaveCopyInUndoList( Sheet, UR_CHANGED );
|
2010-06-24 18:31:43 +00:00
|
|
|
Sheet->AddLabel( this );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-03-24 18:26:04 +00:00
|
|
|
else // pin sheet was existing and only moved
|
|
|
|
{
|
|
|
|
wxPoint tmp = m_Pos;
|
|
|
|
m_Pos = s_InitialPosition;
|
2010-09-05 17:01:48 +00:00
|
|
|
SetEdge( s_InitialEdge );
|
2010-03-24 18:26:04 +00:00
|
|
|
frame->SaveCopyInUndoList( Sheet, UR_CHANGED );
|
|
|
|
m_Pos = tmp;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
ConstraintOnEdge( frame->GetScreen()->m_Curseur );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
RedrawOneStruct( frame->DrawPanel, DC, Sheet, GR_DEFAULT_DRAWMODE );
|
|
|
|
frame->DrawPanel->ManageCurseur = NULL;
|
|
|
|
frame->DrawPanel->ForceCloseManageCurseur = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::StartMove_PinSheet( SCH_SHEET_PIN* SheetLabel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
NetSheetTextSize = SheetLabel->m_Size;
|
2009-12-06 18:04:41 +00:00
|
|
|
s_CurrentTypeLabel = SheetLabel->m_Shape;
|
2007-08-20 01:20:48 +00:00
|
|
|
SheetLabel->m_Flags |= IS_MOVED;
|
2010-09-05 17:01:48 +00:00
|
|
|
s_InitialPosition = SheetLabel->m_Pos;
|
|
|
|
s_InitialEdge = SheetLabel->GetEdge();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ManageCurseur = Move_PinSheet;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
static void Move_PinSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
SCH_SHEET_PIN* SheetLabel = (SCH_SHEET_PIN*) panel->GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( SheetLabel == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( erase )
|
|
|
|
RedrawOneStruct( panel, DC, SheetLabel, g_XorMode );
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
SheetLabel->ConstraintOnEdge( panel->GetScreen()->m_Curseur );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
RedrawOneStruct( panel, DC, SheetLabel, g_XorMode );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
int SCH_EDIT_FRAME::Edit_PinSheet( SCH_SHEET_PIN* aLabel, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-20 21:59:00 +00:00
|
|
|
if( aLabel == 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
|
|
|
if( aDC )
|
|
|
|
RedrawOneStruct( DrawPanel, aDC, aLabel, g_XorMode );
|
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
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
dlg.SetLabelName( aLabel->m_Text );
|
|
|
|
dlg.SetTextHeight( ReturnStringFromValue( g_UserUnit, aLabel->m_Size.y, m_InternalUnits ) );
|
|
|
|
dlg.SetTextHeightUnits( GetUnitsLabel( g_UserUnit ) );
|
|
|
|
dlg.SetTextWidth( ReturnStringFromValue( g_UserUnit, aLabel->m_Size.x, m_InternalUnits ) );
|
|
|
|
dlg.SetTextWidthUnits( GetUnitsLabel( g_UserUnit ) );
|
|
|
|
dlg.SetConnectionType( aLabel->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
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
aLabel->m_Text = dlg.GetLabelName();
|
|
|
|
aLabel->m_Size.y = ReturnValueFromString( g_UserUnit, dlg.GetTextHeight(), m_InternalUnits );
|
|
|
|
aLabel->m_Size.x = ReturnValueFromString( g_UserUnit, dlg.GetTextWidth(), m_InternalUnits );
|
|
|
|
aLabel->m_Shape = dlg.GetConnectionType();
|
|
|
|
|
|
|
|
if( aDC )
|
|
|
|
RedrawOneStruct( DrawPanel, aDC, aLabel, GR_DEFAULT_DRAWMODE );
|
|
|
|
|
|
|
|
return wxID_OK;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Add a new sheet pin to the sheet at the current cursor position.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::Create_PinSheet( SCH_SHEET* Sheet, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
wxString Line, Text;
|
|
|
|
SCH_SHEET_PIN* NewSheetLabel;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
NewSheetLabel = new SCH_SHEET_PIN( Sheet, wxPoint( 0, 0 ), Line );
|
2007-08-20 01:20:48 +00:00
|
|
|
NewSheetLabel->m_Flags = IS_NEW;
|
|
|
|
NewSheetLabel->m_Size = NetSheetTextSize;
|
2009-12-06 18:04:41 +00:00
|
|
|
NewSheetLabel->m_Shape = s_CurrentTypeLabel;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-06 18:04:41 +00:00
|
|
|
int diag = Edit_PinSheet( NewSheetLabel, NULL );
|
|
|
|
|
|
|
|
if( NewSheetLabel->m_Text.IsEmpty() || (diag == wxID_CANCEL) )
|
|
|
|
{
|
|
|
|
delete NewSheetLabel;
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NewSheetLabel );
|
2009-12-06 18:04:41 +00:00
|
|
|
s_CurrentTypeLabel = NewSheetLabel->m_Shape;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ManageCurseur = Move_PinSheet;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NewSheetLabel;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Automatically create a sheet labels from global labels for each node in
|
|
|
|
* the corresponding hierarchy.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* DrawStruct;
|
|
|
|
SCH_SHEET_PIN* NewSheetLabel;
|
|
|
|
SCH_HIERLABEL* HLabel = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
if( !Sheet->m_AssociatedScreen )
|
|
|
|
return NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DrawStruct = Sheet->m_AssociatedScreen->GetDrawItems();
|
2009-11-04 20:46:53 +00:00
|
|
|
HLabel = NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
HLabel = (SCH_HIERLABEL*) DrawStruct;
|
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. */
|
|
|
|
if( !Sheet->HasLabel( HLabel->m_Text ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
|
|
|
HLabel = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
if( HLabel == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +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();
|
2010-03-24 18:26:04 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
|
|
|
SaveCopyInUndoList( Sheet, UR_CHANGED );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
NewSheetLabel = new SCH_SHEET_PIN( Sheet, wxPoint( 0, 0 ), HLabel->m_Text );
|
2007-08-20 01:20:48 +00:00
|
|
|
NewSheetLabel->m_Flags = IS_NEW;
|
|
|
|
NewSheetLabel->m_Size = NetSheetTextSize;
|
2009-12-06 18:04:41 +00:00
|
|
|
s_CurrentTypeLabel = NewSheetLabel->m_Shape = HLabel->m_Shape;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
GetScreen()->SetCurItem( NewSheetLabel );
|
|
|
|
DrawPanel->ManageCurseur = Move_PinSheet;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
|
|
|
|
Move_PinSheet( DrawPanel, DC, FALSE );
|
|
|
|
|
|
|
|
return NewSheetLabel;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Remove sheet label.
|
|
|
|
*
|
|
|
|
* This sheet label can not be put in a pile "undelete" because it would not
|
|
|
|
* Possible to link it back it's 'SCH_SHEET' parent.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::DeleteSheetLabel( bool aRedraw, SCH_SHEET_PIN* aSheetLabelToDel )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* parent = (SCH_SHEET*) aSheetLabelToDel->GetParent();
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
wxASSERT( parent );
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( parent->Type() == SCH_SHEET_T );
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
|
|
|
std::cout << "\n\nbefore deleting:\n" << std::flush;
|
|
|
|
parent->Show( 0, std::cout );
|
|
|
|
std::cout << "\n\n\n" << std::flush;
|
|
|
|
#endif
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
parent->RemoveLabel( aSheetLabelToDel );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-04-25 07:33:45 +00:00
|
|
|
if( aRedraw )
|
|
|
|
DrawPanel->PostDirtyRect( parent->GetBoundingBox() );
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
|
|
|
std::cout << "\n\nafter deleting:\n" << std::flush;
|
|
|
|
parent->Show( 0, std::cout );
|
|
|
|
std::cout << "~after deleting\n\n" << std::flush;
|
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|