Eeschema: fixed some issues in undo/redo and ESC commands related to hierarchical sheets
This commit is contained in:
parent
be946a7562
commit
aa35b98036
|
@ -92,8 +92,7 @@ void WinEDA_SchematicFrame::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry,
|
|||
if( BusEntry == NULL )
|
||||
return;
|
||||
|
||||
if( (BusEntry->m_Flags & IS_NEW) == 0 ) // => not already in edit, save
|
||||
// shape */
|
||||
if( (BusEntry->m_Flags & IS_NEW) == 0 ) // not already in edit, save shape
|
||||
{
|
||||
delete g_ItemToUndoCopy;
|
||||
g_ItemToUndoCopy = BusEntry->GenCopy();
|
||||
|
|
|
@ -208,6 +208,22 @@ void SCH_SHEET::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
|
|||
return;
|
||||
}
|
||||
}
|
||||
else /* save old text in undo list */
|
||||
{
|
||||
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == Type() ) )
|
||||
{
|
||||
/* restore old values and save new ones */
|
||||
SwapData( (SCH_SHEET*) g_ItemToUndoCopy );
|
||||
|
||||
/* save in undo list */
|
||||
frame->SaveCopyInUndoList( this, UR_CHANGED );
|
||||
|
||||
/* restore new values */
|
||||
SwapData( (SCH_SHEET*) g_ItemToUndoCopy );
|
||||
|
||||
SAFE_DELETE( g_ItemToUndoCopy );
|
||||
}
|
||||
}
|
||||
|
||||
SCH_ITEM::Place( frame, DC ); //puts it on the EEDrawList.
|
||||
if( isnew )
|
||||
|
|
|
@ -551,7 +551,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
GetScreen()->SetCurItem( (SCH_ITEM*) DrawStruct );
|
||||
|
||||
// Create the events for moving a component or other schematic item
|
||||
wxCommandEvent eventMoveComponent( wxEVT_COMMAND_TOOL_CLICKED,
|
||||
wxCommandEvent eventMoveOrDragComponent( wxEVT_COMMAND_TOOL_CLICKED,
|
||||
HK_Descr->m_IdMenuEvent );
|
||||
wxCommandEvent eventMoveItem( wxEVT_COMMAND_TOOL_CLICKED,
|
||||
ID_POPUP_SCH_MOVE_ITEM_REQUEST );
|
||||
|
@ -564,21 +564,23 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
{
|
||||
// select the correct event for moving an schematic object
|
||||
// and add it to the event queue
|
||||
case DRAW_SHEET_STRUCT_TYPE:
|
||||
case TYPE_SCH_COMPONENT:
|
||||
wxPostEvent( this, eventMoveComponent );
|
||||
wxPostEvent( this, eventMoveOrDragComponent );
|
||||
break;
|
||||
|
||||
case TYPE_SCH_TEXT:
|
||||
case TYPE_SCH_LABEL:
|
||||
case TYPE_SCH_GLOBALLABEL:
|
||||
case TYPE_SCH_HIERLABEL:
|
||||
case DRAW_SHEET_STRUCT_TYPE:
|
||||
case DRAW_PART_TEXT_STRUCT_TYPE:
|
||||
case DRAW_BUSENTRY_STRUCT_TYPE:
|
||||
if( HK_Descr->m_Idcommand != HK_DRAG )
|
||||
wxPostEvent( this, eventMoveItem );
|
||||
break;
|
||||
|
||||
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
|
||||
if( HK_Descr->m_Idcommand != HK_DRAG )
|
||||
wxPostEvent( this, eventMovePinsheet );
|
||||
break;
|
||||
|
||||
|
|
|
@ -439,11 +439,11 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
|
|||
msg = AddHotkeyName( _( "Rotate Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
|
||||
_( "Rotate Hierarchical Label" ), rotate_glabel_xpm );
|
||||
msg, rotate_glabel_xpm );
|
||||
msg = AddHotkeyName( _( "Edit Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
|
||||
_( "Edit Hierarchical Label" ), edit_text_xpm );
|
||||
msg, edit_text_xpm );
|
||||
msg = AddHotkeyName( _( "Delete Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_DELETE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE,
|
||||
|
@ -678,6 +678,11 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
|
|||
s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT_OR_ITEM );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST,
|
||||
msg, move_sheet_xpm );
|
||||
|
||||
msg = AddHotkeyName( _( "Drag Sheet" ), s_Schematic_Hokeys_Descr,
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST,
|
||||
msg, move_sheet_xpm );
|
||||
}
|
||||
|
||||
if( Sheet->m_Flags )
|
||||
|
|
|
@ -181,79 +181,92 @@ void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
|
|||
}
|
||||
|
||||
|
||||
/* Routine to create a new copy of given struct.
|
||||
/** function DuplicateStruct
|
||||
* Routine to create a new copy of given struct.
|
||||
* The new object is not put in draw list (not linked)
|
||||
* @param aDrawStruct = the SCH_ITEM to duplicate
|
||||
* @param aClone (default = false)
|
||||
* if true duplicate also some parameters that must be unique
|
||||
* (timestamp and sheet name)
|
||||
* aClone must be false. use true only is undo/redo duplications
|
||||
*/
|
||||
SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct )
|
||||
SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone )
|
||||
{
|
||||
SCH_ITEM* NewDrawStruct = NULL;
|
||||
|
||||
if( DrawStruct == NULL )
|
||||
if( aDrawStruct == NULL )
|
||||
{
|
||||
wxMessageBox( wxT( "DuplicateStruct error: NULL struct" ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch( DrawStruct->Type() )
|
||||
switch( aDrawStruct->Type() )
|
||||
{
|
||||
case DRAW_POLYLINE_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_POLYLINE*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_POLYLINE*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case DRAW_SEGMENT_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_LINE*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_LINE*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case DRAW_BUSENTRY_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_BUS_ENTRY*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_BUS_ENTRY*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case DRAW_JUNCTION_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_JUNCTION*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_JUNCTION*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_MARKER:
|
||||
NewDrawStruct = ( (SCH_MARKER*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_MARKER*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case DRAW_NOCONNECT_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_NO_CONNECT*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_NO_CONNECT*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_TEXT:
|
||||
NewDrawStruct = ( (SCH_TEXT*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_TEXT*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_LABEL:
|
||||
NewDrawStruct = ( (SCH_LABEL*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_LABEL*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_HIERLABEL:
|
||||
NewDrawStruct = ( (SCH_HIERLABEL*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_HIERLABEL*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_GLOBALLABEL:
|
||||
NewDrawStruct = ( (SCH_GLOBALLABEL*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_GLOBALLABEL*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case TYPE_SCH_COMPONENT:
|
||||
NewDrawStruct = ( (SCH_COMPONENT*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_COMPONENT*) aDrawStruct )->GenCopy();
|
||||
break;
|
||||
|
||||
case DRAW_SHEET_STRUCT_TYPE:
|
||||
NewDrawStruct = ( (SCH_SHEET*) DrawStruct )->GenCopy();
|
||||
NewDrawStruct = ( (SCH_SHEET*) aDrawStruct )->GenCopy();
|
||||
if ( aClone )
|
||||
{
|
||||
((SCH_SHEET*)NewDrawStruct)->m_SheetName = ((SCH_SHEET*)aDrawStruct)->m_SheetName;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
wxString msg;
|
||||
msg << wxT( "DuplicateStruct error: unexpected StructType " )
|
||||
<< DrawStruct->Type() << wxT( " " ) << DrawStruct->GetClass();
|
||||
<< aDrawStruct->Type() << wxT( " " ) << aDrawStruct->GetClass();
|
||||
wxMessageBox( msg );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
NewDrawStruct->m_Image = DrawStruct;
|
||||
if ( aClone )
|
||||
NewDrawStruct->m_TimeStamp = aDrawStruct->m_TimeStamp;
|
||||
|
||||
NewDrawStruct->m_Image = aDrawStruct;
|
||||
return NewDrawStruct;
|
||||
}
|
||||
|
|
|
@ -71,11 +71,21 @@ bool LibItemInBox( int x1, int y1, int x2, int y2,
|
|||
/************/
|
||||
/* BLOCK.CPP */
|
||||
/************/
|
||||
SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct );
|
||||
void DeleteStruct( WinEDA_DrawPanel* panel,
|
||||
wxDC* DC,
|
||||
SCH_ITEM* DrawStruct );
|
||||
|
||||
// operations_on_item_lists.cpp
|
||||
/** function DuplicateStruct
|
||||
* Routine to create a new copy of given struct.
|
||||
* @param aDrawStruct = the SCH_ITEM to duplicate
|
||||
* @param aClone (defualt = true)
|
||||
* if true duplicate also some parameters that must be unique
|
||||
* (timestamp and sheet name)
|
||||
* aClone must be false. use true only is undo/redo duplications
|
||||
*/
|
||||
SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false );
|
||||
|
||||
/*************/
|
||||
/* LOCATE.CPP */
|
||||
/*************/
|
||||
|
|
|
@ -397,20 +397,20 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
case ID_POPUP_SCH_DRAG_CMP_REQUEST:
|
||||
case ID_POPUP_SCH_MOVE_CMP_REQUEST:
|
||||
|
||||
// Ensure the struct is a component (could be a struct of a
|
||||
// component, like Field, text..)
|
||||
if( screen->GetCurItem()->Type() != TYPE_SCH_COMPONENT )
|
||||
// component, like Field, text..) or a hierachical sheet
|
||||
if( (screen->GetCurItem()->Type() != TYPE_SCH_COMPONENT)
|
||||
&& (screen->GetCurItem()->Type() != DRAW_SHEET_STRUCT_TYPE) )
|
||||
screen->SetCurItem( LocateSmallestComponent( screen ) );
|
||||
if( screen->GetCurItem() == NULL )
|
||||
break;
|
||||
|
||||
// fall through
|
||||
case ID_POPUP_SCH_MOVE_ITEM_REQUEST:
|
||||
DrawPanel->MouseToCursorSchema();
|
||||
if( id == ID_POPUP_SCH_DRAG_CMP_REQUEST )
|
||||
{
|
||||
// The easiest way to handle a drag component is to simulate a
|
||||
// block drag command
|
||||
// The easiest way to handle a drag component or sheet command
|
||||
// is to simulate a block drag command
|
||||
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
|
||||
{
|
||||
if( !HandleBlockBegin( &dc, BLOCK_DRAG,
|
||||
|
|
|
@ -180,35 +180,6 @@ void SwapData( EDA_BaseStruct* aItem, EDA_BaseStruct* aImage )
|
|||
}
|
||||
|
||||
|
||||
/** function CloneStruct
|
||||
* must be used only in undo/redo functions
|
||||
*
|
||||
* Routine to create a new copy of given schùatic object.
|
||||
* It does the same job as DuplicateStruct, but
|
||||
* but clone time stamp and sheet name when cloning a SCH_SHEET objects
|
||||
* (because time stamp and sheets name must be unique
|
||||
* DuplicateStruct does not copy these members
|
||||
*/
|
||||
static SCH_ITEM* CloneStruct( SCH_ITEM* aDrawStruct )
|
||||
{
|
||||
SCH_ITEM* item = DuplicateStruct( aDrawStruct );
|
||||
if( item == NULL )
|
||||
return NULL;
|
||||
|
||||
item->m_TimeStamp = aDrawStruct->m_TimeStamp;
|
||||
switch( item->Type() )
|
||||
{
|
||||
case DRAW_SHEET_STRUCT_TYPE:
|
||||
((SCH_SHEET*)item)->m_SheetName = ((SCH_SHEET*)aDrawStruct)->m_SheetName;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/** function SaveCopyInUndoList
|
||||
* Create a copy of the current schematic item, and put it in the undo list.
|
||||
|
@ -260,7 +231,7 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItem,
|
|||
switch( aCommandType )
|
||||
{
|
||||
case UR_CHANGED: /* Create a copy of item */
|
||||
CopyOfItem = CloneStruct( aItem );
|
||||
CopyOfItem = DuplicateStruct( aItem, true );
|
||||
itemWrapper.m_Link = CopyOfItem;
|
||||
if ( CopyOfItem )
|
||||
commandToUndo->PushItem( itemWrapper );
|
||||
|
@ -330,7 +301,7 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
|
|||
* If this link is not null, the copy is already done
|
||||
*/
|
||||
if( commandToUndo->GetPickedItemLink(ii) == NULL )
|
||||
commandToUndo->SetPickedItemLink( CloneStruct( item ), ii );
|
||||
commandToUndo->SetPickedItemLink( DuplicateStruct( item, true ), ii );
|
||||
wxASSERT( commandToUndo->GetPickedItemLink(ii) );
|
||||
break;
|
||||
|
||||
|
|
|
@ -106,6 +106,9 @@ structures and cannot be undone.\nOk to continue renaming?" );
|
|||
}
|
||||
}
|
||||
|
||||
else
|
||||
SaveCopyInUndoList( aSheet, UR_CHANGED );
|
||||
|
||||
aSheet->m_FileNameSize = ReturnValueFromString( g_UnitMetric,
|
||||
dlg.GetFileNameTextSize(),
|
||||
m_InternalUnits );
|
||||
|
@ -202,6 +205,7 @@ static void ExitSheet( WinEDA_DrawPanel* aPanel, wxDC* aDC )
|
|||
screen->SetCurItem( NULL );
|
||||
aPanel->ManageCurseur = NULL;
|
||||
aPanel->ForceCloseManageCurseur = NULL;
|
||||
SAFE_DELETE( g_ItemToUndoCopy );
|
||||
}
|
||||
|
||||
|
||||
|
@ -213,6 +217,7 @@ static void ExitSheet( WinEDA_DrawPanel* aPanel, wxDC* aDC )
|
|||
SCH_SHEET* WinEDA_SchematicFrame::CreateSheet( wxDC* aDC )
|
||||
{
|
||||
g_ItemToRepeat = NULL;
|
||||
SAFE_DELETE( g_ItemToUndoCopy );
|
||||
|
||||
SCH_SHEET* sheet = new SCH_SHEET( GetScreen()->m_Curseur );
|
||||
|
||||
|
@ -273,6 +278,12 @@ void WinEDA_SchematicFrame::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
|||
DrawPanel->ManageCurseur = MoveOrResizeSheet;
|
||||
DrawPanel->ForceCloseManageCurseur = ExitSheet;
|
||||
DrawPanel->ManageCurseur( DrawPanel, aDC, true );
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,4 +302,10 @@ void WinEDA_SchematicFrame::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC )
|
|||
DrawPanel->ForceCloseManageCurseur = ExitSheet;
|
||||
DrawPanel->ManageCurseur( DrawPanel, aDC, true );
|
||||
DrawPanel->CursorOn( aDC );
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,9 +168,14 @@ static void ExitPinSheet( WinEDA_DrawPanel* Panel, wxDC* DC )
|
|||
void SCH_SHEET_PIN::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
|
||||
{
|
||||
SCH_SHEET* Sheet = (SCH_SHEET*) GetParent();
|
||||
SAFE_DELETE( g_ItemToUndoCopy );
|
||||
|
||||
if( m_Flags & IS_NEW )
|
||||
int flags = m_Flags;
|
||||
m_Flags = 0;
|
||||
|
||||
if( flags & IS_NEW )
|
||||
{
|
||||
frame->SaveCopyInUndoList( Sheet, UR_CHANGED );
|
||||
if( Sheet->m_Label == NULL )
|
||||
Sheet->m_Label = this;
|
||||
else
|
||||
|
@ -188,10 +193,19 @@ void SCH_SHEET_PIN::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
|
|||
}
|
||||
}
|
||||
|
||||
m_Flags = 0;
|
||||
else // pin sheet was existing and only moved
|
||||
{
|
||||
wxPoint tmp = m_Pos;
|
||||
m_Pos = s_InitialPosition;
|
||||
m_Edge = 0;
|
||||
if( m_Pos.x > ( Sheet->m_Pos.x + (Sheet->m_Size.x / 2) ) )
|
||||
m_Edge = 1;
|
||||
frame->SaveCopyInUndoList( Sheet, UR_CHANGED );
|
||||
m_Pos = tmp;
|
||||
}
|
||||
|
||||
m_Pos.x = Sheet->m_Pos.x;
|
||||
m_Edge = 0;
|
||||
|
||||
if( frame->GetScreen()->m_Curseur.x > ( Sheet->m_Pos.x + (Sheet->m_Size.x / 2) ) )
|
||||
{
|
||||
m_Edge = 1;
|
||||
|
@ -350,11 +364,13 @@ SCH_SHEET_PIN* WinEDA_SchematicFrame::Import_PinSheet( SCH_SHEET* Sheet,
|
|||
|
||||
if( (HLabel == NULL ) || SheetLabel )
|
||||
{
|
||||
DisplayError( this, _( "No new hierarchical labels found" ), 10 );
|
||||
DisplayInfoMessage( this, _( "No new hierarchical labels found" ), 10 );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OnModify( );
|
||||
SAFE_DELETE( g_ItemToUndoCopy );
|
||||
SaveCopyInUndoList( Sheet, UR_CHANGED );
|
||||
|
||||
NewSheetLabel = new SCH_SHEET_PIN( Sheet, wxPoint( 0, 0 ), HLabel->m_Text );
|
||||
NewSheetLabel->m_Flags = IS_NEW;
|
||||
|
|
Loading…
Reference in New Issue