2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: sheet.cpp
|
2007-08-20 01:20:48 +00:00
|
|
|
// Purpose:
|
2007-05-06 16:03:28 +00:00
|
|
|
// Author: jean-pierre Charras
|
2009-12-15 21:11:05 +00:00
|
|
|
// Modified by: Wayne Stambaugh
|
2007-05-06 16:03:28 +00:00
|
|
|
// Created: 08/02/2006 18:37:02
|
2007-08-20 01:20:48 +00:00
|
|
|
// RCS-ID:
|
2007-05-06 16:03:28 +00:00
|
|
|
// Copyright: License GNU
|
2009-11-04 20:46:53 +00:00
|
|
|
// License:
|
2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
#include "dialog_sch_sheet_props.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
static int s_PreviousSheetWidth;
|
|
|
|
static int s_PreviousSheetHeight;
|
2009-11-04 20:46:53 +00:00
|
|
|
static wxPoint s_OldPos; /* Former position for cancellation or move ReSize */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
/* Routine to edit the SheetName and the FileName for the sheet "Sheet" */
|
|
|
|
bool WinEDA_SchematicFrame::EditSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
bool edit = true;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSheet == NULL )
|
|
|
|
return false;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
/* Get the new texts */
|
|
|
|
RedrawOneStruct( DrawPanel, aDC, aSheet, g_XorMode );
|
|
|
|
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = true;
|
|
|
|
|
|
|
|
DIALOG_SCH_SHEET_PROPS dlg( this );
|
|
|
|
|
|
|
|
wxString units = GetUnitsLabel( g_UnitMetric );
|
|
|
|
dlg.SetFileName( aSheet->GetFileName() );
|
|
|
|
dlg.SetFileNameTextSize( ReturnStringFromValue( g_UnitMetric,
|
|
|
|
aSheet->m_FileNameSize,
|
|
|
|
m_InternalUnits ) );
|
|
|
|
dlg.SetFileNameTextSizeUnits( units );
|
|
|
|
dlg.SetSheetName( aSheet->m_SheetName );
|
|
|
|
dlg.SetSheetNameTextSize( ReturnStringFromValue( g_UnitMetric,
|
|
|
|
aSheet->m_SheetNameSize,
|
|
|
|
m_InternalUnits ) );
|
|
|
|
dlg.SetSheetNameTextSizeUnits( units );
|
|
|
|
|
|
|
|
/* 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() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxFileName fileName;
|
|
|
|
wxString msg;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
fileName = dlg.GetFileName();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( !fileName.IsOk() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "File name is not valid! Aborted" ) );
|
|
|
|
edit = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fileName.SetExt( SchematicFileExtension );
|
|
|
|
|
|
|
|
/* m_CurrentSheet->m_AssociatedScreen must be a valid screen, and the
|
|
|
|
* sheet must have a valid associated filename,
|
|
|
|
* so we must call m_CurrentSheet->ChangeFileName to set a filename,
|
|
|
|
* AND always when a new sheet is created ( when
|
|
|
|
* m_CurrentSheet->m_AssociatedScreen is null ),
|
|
|
|
* to create or set an Associated Screen
|
|
|
|
*/
|
|
|
|
if( ( fileName.GetFullPath() != aSheet->GetFileName() )
|
|
|
|
|| ( aSheet->m_AssociatedScreen == NULL ) )
|
|
|
|
{
|
|
|
|
msg = _( "Changing the sheet file name can change all the schematic \
|
|
|
|
structures and cannot be undone.\nOk to continue renaming?" );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSheet->m_AssociatedScreen == NULL || IsOK( NULL, msg ) )
|
|
|
|
{
|
|
|
|
// do not prompt on a new sheet. in fact, we should not allow a
|
|
|
|
// sheet to be created without a valid associated filename to be
|
|
|
|
// read from.
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
|
|
|
|
|
|
|
// set filename and the associated screen
|
|
|
|
aSheet->ChangeFileName( this, fileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
}
|
2010-03-24 18:26:04 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
SaveCopyInUndoList( aSheet, UR_CHANGED );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
|
|
|
aSheet->m_FileNameSize = ReturnValueFromString( g_UnitMetric,
|
|
|
|
dlg.GetFileNameTextSize(),
|
|
|
|
m_InternalUnits );
|
|
|
|
|
|
|
|
aSheet->m_SheetName = dlg.GetSheetName();
|
|
|
|
aSheet->m_SheetNameSize = ReturnValueFromString( g_UnitMetric,
|
|
|
|
dlg.GetSheetNameTextSize(),
|
|
|
|
m_InternalUnits );
|
|
|
|
|
|
|
|
if( aSheet->m_SheetName.IsEmpty() )
|
|
|
|
{
|
|
|
|
aSheet->m_SheetName.Printf( wxT( "Sheet%8.8lX" ), GetTimeStamp() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-02-28 19:27:25 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
edit = false;
|
2008-02-28 19:27:25 +00:00
|
|
|
}
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
RedrawOneStruct( DrawPanel, aDC, aSheet, GR_DEFAULT_DRAWMODE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
return edit;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
/* Move selected sheet with the cursor.
|
|
|
|
* Callback function use by ManageCurseur.
|
2008-02-29 12:33:07 +00:00
|
|
|
*/
|
2010-03-23 19:15:27 +00:00
|
|
|
static void MoveOrResizeSheet( WinEDA_DrawPanel* aPanel, wxDC* aDC, bool aErase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxPoint moveVector;
|
|
|
|
SCH_SHEET_PIN* sheetLabel;
|
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aErase )
|
|
|
|
RedrawOneStruct( aPanel, aDC, sheet, g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( sheet->m_Flags & IS_RESIZED )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
sheet->m_Size.x = MAX( s_PreviousSheetWidth, screen->m_Curseur.x - sheet->m_Pos.x );
|
|
|
|
sheet->m_Size.y = MAX( s_PreviousSheetHeight, screen->m_Curseur.y - sheet->m_Pos.y );
|
|
|
|
sheetLabel = sheet->m_Label;
|
2008-03-30 15:12:08 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
while( sheetLabel )
|
2009-11-04 20:46:53 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( sheetLabel->m_Edge )
|
|
|
|
sheetLabel->m_Pos.x = sheet->m_Pos.x + sheet->m_Size.x;
|
|
|
|
sheetLabel = sheetLabel->Next();
|
2008-03-30 15:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-15 21:11:05 +00:00
|
|
|
else /* Move Sheet */
|
2008-02-28 20:39:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
moveVector = screen->m_Curseur - sheet->m_Pos;
|
|
|
|
sheet->Move( moveVector );
|
2008-02-28 20:39:04 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
RedrawOneStruct( aPanel, aDC, sheet, g_XorMode );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
/* Complete sheet move. */
|
|
|
|
static void ExitSheet( WinEDA_DrawPanel* aPanel, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) screen->GetCurItem();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( sheet == NULL )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( sheet->m_Flags & IS_NEW )
|
|
|
|
{
|
|
|
|
RedrawOneStruct( aPanel, aDC, sheet, g_XorMode );
|
|
|
|
SAFE_DELETE( sheet );
|
|
|
|
}
|
2010-03-23 19:15:27 +00:00
|
|
|
else if( (sheet->m_Flags & (IS_RESIZED|IS_MOVED)) )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
|
|
|
wxPoint curspos = screen->m_Curseur;
|
|
|
|
aPanel->GetScreen()->m_Curseur = s_OldPos;
|
2010-03-23 19:15:27 +00:00
|
|
|
MoveOrResizeSheet( aPanel, aDC, true );
|
2009-12-15 21:11:05 +00:00
|
|
|
RedrawOneStruct( aPanel, aDC, sheet, GR_DEFAULT_DRAWMODE );
|
|
|
|
sheet->m_Flags = 0;
|
|
|
|
screen->m_Curseur = curspos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sheet->m_Flags = 0;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
screen->SetCurItem( NULL );
|
|
|
|
aPanel->ManageCurseur = NULL;
|
|
|
|
aPanel->ForceCloseManageCurseur = NULL;
|
2010-03-24 18:26:04 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define SHEET_MIN_WIDTH 500
|
|
|
|
#define SHEET_MIN_HEIGHT 150
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Create hierarchy sheet. */
|
2009-12-15 21:11:05 +00:00
|
|
|
SCH_SHEET* WinEDA_SchematicFrame::CreateSheet( wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
g_ItemToRepeat = NULL;
|
2010-03-24 18:26:04 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( GetScreen()->m_Curseur );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
sheet->m_Flags = IS_NEW | IS_RESIZED;
|
|
|
|
sheet->m_TimeStamp = GetTimeStamp();
|
|
|
|
sheet->SetParent( GetScreen() );
|
|
|
|
sheet->m_AssociatedScreen = NULL;
|
|
|
|
s_PreviousSheetWidth = SHEET_MIN_WIDTH;
|
|
|
|
s_PreviousSheetHeight = SHEET_MIN_HEIGHT;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
// need to check if this is being added to the EEDrawList.
|
|
|
|
// also need to update the hierarchy, if we are adding
|
2008-02-26 19:19:54 +00:00
|
|
|
// a sheet to a screen that already has multiple instances (!)
|
2009-12-15 21:11:05 +00:00
|
|
|
GetScreen()->SetCurItem( sheet );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-03-23 19:15:27 +00:00
|
|
|
DrawPanel->ManageCurseur = MoveOrResizeSheet;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitSheet;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
DrawPanel->ManageCurseur( DrawPanel, aDC, false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
return sheet;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void WinEDA_SchematicFrame::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetLabel;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSheet == NULL || aSheet->m_Flags & IS_NEW )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSheet->Type() != DRAW_SHEET_STRUCT_TYPE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
DisplayError( this,
|
|
|
|
wxT( "WinEDA_SchematicFrame::ReSizeSheet: Bad SructType" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2009-12-15 21:11:05 +00:00
|
|
|
aSheet->m_Flags |= IS_RESIZED;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-03-23 19:15:27 +00:00
|
|
|
s_OldPos = aSheet->m_Pos + aSheet->m_Size;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
s_PreviousSheetWidth = SHEET_MIN_WIDTH;
|
|
|
|
s_PreviousSheetHeight = SHEET_MIN_HEIGHT;
|
|
|
|
sheetLabel = aSheet->m_Label;
|
|
|
|
|
|
|
|
while( sheetLabel )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
s_PreviousSheetWidth = MAX( s_PreviousSheetWidth,
|
|
|
|
(int) ( ( sheetLabel->GetLength() + 1 ) *
|
|
|
|
sheetLabel->m_Size.x ) );
|
|
|
|
s_PreviousSheetHeight = MAX( s_PreviousSheetHeight,
|
|
|
|
sheetLabel->m_Pos.y - aSheet->m_Pos.y );
|
|
|
|
sheetLabel = sheetLabel->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 19:15:27 +00:00
|
|
|
DrawPanel->ManageCurseur = MoveOrResizeSheet;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitSheet;
|
2009-12-15 21:11:05 +00:00
|
|
|
DrawPanel->ManageCurseur( DrawPanel, aDC, true );
|
2010-03-24 18:26:04 +00:00
|
|
|
|
|
|
|
if( (aSheet->m_Flags & IS_NEW) == 0 ) // not already in edit, save a copy for undo/redo
|
|
|
|
{
|
|
|
|
delete g_ItemToUndoCopy;
|
|
|
|
g_ItemToUndoCopy = DuplicateStruct( aSheet, true );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void WinEDA_SchematicFrame::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ( aSheet == NULL ) || ( aSheet->Type() != DRAW_SHEET_STRUCT_TYPE ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
DrawPanel->CursorOff( aDC );
|
|
|
|
GetScreen()->m_Curseur = aSheet->m_Pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
s_OldPos = aSheet->m_Pos;
|
|
|
|
aSheet->m_Flags |= IS_MOVED;
|
2010-03-23 19:15:27 +00:00
|
|
|
DrawPanel->ManageCurseur = MoveOrResizeSheet;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitSheet;
|
2009-12-15 21:11:05 +00:00
|
|
|
DrawPanel->ManageCurseur( DrawPanel, aDC, true );
|
|
|
|
DrawPanel->CursorOn( aDC );
|
2010-03-24 18:26:04 +00:00
|
|
|
|
|
|
|
if( (aSheet->m_Flags & IS_NEW) == 0 ) // not already in edit, save a copy for undo/redo
|
|
|
|
{
|
|
|
|
delete g_ItemToUndoCopy;
|
|
|
|
g_ItemToUndoCopy = DuplicateStruct( aSheet, true );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|