Commit b6e8c338 authored by charras's avatar charras

Eeschema: fixed: bad undo/redo for Drag commands

parent ab74cfed
......@@ -36,6 +36,7 @@ ITEM_PICKER::ITEM_PICKER( EDA_BaseStruct* aItem, UndoRedoOpType aUndoRedoStatus
m_UndoRedoStatus = aUndoRedoStatus;
m_PickedItem = aItem;
m_PickedItemType = TYPE_NOT_INIT;
m_PickerFlags = 0;
m_Link = NULL;
}
......@@ -216,6 +217,18 @@ UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
return UR_UNSPECIFIED;
}
/** function GetPickerFlags
* return the value of the picker flag
* @param aIdx = index of the picker in the picked list
* @return the value stored in the picker, if the picker exists, or 0 if does not exist
*/
int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
return m_ItemsList[aIdx].m_PickerFlags;
else
return 0;
}
/** function SetPickedItem
* @param aItem = a pointer to the item to pick
......@@ -289,6 +302,22 @@ bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aI
else
return false;
}
/** function SetPickerFlags
* Set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags = the value to save in picker
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
{
m_ItemsList[aIdx].m_PickerFlags = aFlags;
return true;
}
else
return false;
}
/** function RemovePicker
......
......@@ -241,7 +241,6 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
case BLOCK_DRAG: /* Drag */
BreakSegmentOnJunction( (SCH_SCREEN*) GetScreen() );
case BLOCK_MOVE: /* Move */
case BLOCK_COPY: /* Copy */
PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
......@@ -584,7 +583,6 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
{
SCH_ITEM* Struct;
EDA_DrawLineStruct* SegmStruct;
int ox, oy, fx, fy;
PICKED_ITEMS_LIST* pickedlist = &screen->m_BlockLocate.m_ItemsSelection;
......@@ -609,7 +607,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
{
for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
{
Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetPickedItem( ii );
Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
Struct->m_Flags = SELECTED;
}
}
......@@ -617,16 +615,6 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
if( screen->m_BlockLocate.m_Command != BLOCK_DRAG )
return;
ox = screen->m_BlockLocate.GetX();
oy = screen->m_BlockLocate.GetY();
fx = screen->m_BlockLocate.GetRight();
fy = screen->m_BlockLocate.GetBottom();
if( fx < ox )
EXCHG( fx, ox );
if( fy < oy )
EXCHG( fy, oy );
/* Suppression du deplacement des extremites de segments hors cadre
* de selection */
......@@ -636,13 +624,15 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
if( Struct->Type() == DRAW_SEGMENT_STRUCT_TYPE )
{
SegmStruct = (EDA_DrawLineStruct*) Struct;
if( (SegmStruct->m_Start.x < ox) || (SegmStruct->m_Start.x > fx)
|| (SegmStruct->m_Start.y < oy) || (SegmStruct->m_Start.y > fy) )
if( ! screen->m_BlockLocate.Inside(SegmStruct->m_Start) )
SegmStruct->m_Flags |= STARTPOINT;
if( (SegmStruct->m_End.x < ox) || (SegmStruct->m_End.x > fx)
|| (SegmStruct->m_End.y < oy) || (SegmStruct->m_End.y > fy) )
if( ! screen->m_BlockLocate.Inside(SegmStruct->m_End) )
SegmStruct->m_Flags |= ENDPOINT;
// Save m_Flags for Undo/redo drag operations:
pickedlist->SetPickerFlags(SegmStruct->m_Flags, ii);
}
}
......@@ -660,7 +650,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
DrawItem = GetNextPinPosition( (SCH_COMPONENT*) Struct, pos );
while( DrawItem )
{
if( (pos.x < ox) || (pos.x > fx) || (pos.y < oy) || (pos.y > fy) )
if( ! screen->m_BlockLocate.Inside(pos) )
{
// This pin is outside area,
// but because it it the pin of a selected component
......@@ -724,6 +714,9 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
if( STRUCT->m_End == position )
STRUCT->m_Flags &= ~ENDPOINT;
// Save m_Flags for Undo/redo drag operations:
pickedlist->SetPickerFlags(STRUCT->m_Flags, ii);
break;
default:
......@@ -768,12 +761,16 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
{
Struct->m_Flags = SELECTED | ENDPOINT | STARTPOINT;
Struct->m_Flags &= ~STARTPOINT;
// Save m_Flags for Undo/redo drag operations:
picker.m_PickerFlags= Struct->m_Flags;
pickedlist->PushItem( picker );
}
else if( STRUCT->m_End == position )
{
Struct->m_Flags = SELECTED | ENDPOINT | STARTPOINT;
Struct->m_Flags &= ~ENDPOINT;
// Save m_Flags for Undo/redo drag operations:
picker.m_PickerFlags= Struct->m_Flags;
pickedlist->PushItem( picker );
}
break;
......
......@@ -223,7 +223,10 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItem,
ITEM_PICKER itemWrapper( aItem, aCommandType );
if( aItem )
{
itemWrapper.m_PickedItemType = aItem->Type();
itemWrapper.m_PickerFlags = aItem->m_Flags;
}
switch( aCommandType )
{
......@@ -368,7 +371,9 @@ void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bo
break;
case UR_MOVED:
item->m_Flags = aList->GetPickerFlags(ii);
item->Move( aRedoCommand ? aList->m_TransformPoint : - aList->m_TransformPoint );
item->m_Flags = 0;
break;
case UR_MIRRORED_Y:
......
......@@ -75,6 +75,7 @@ public:
*/
KICAD_T m_PickedItemType; /* type of schematic or board item that is concerned
*/
int m_PickerFlags; /* a copy of m_Flags member. usefull in mode/drag undo/redo commands */
EDA_BaseStruct* m_Link; /* Pointer on an other item. Used in undo redo command
* used when a duplicate exists i.e. when an item is modified,
* and the copy of initial item exists (the duplicate)
......@@ -174,6 +175,13 @@ public:
*/
UndoRedoOpType GetPickedItemStatus( unsigned int aIdx );
/** function GetPickerFlags
* return the value of the picker flag
* @param aIdx = index of the picker in the picked list
* @return the value stored in the picker, if the picker exists, or 0 if does not exist
*/
int GetPickerFlags( unsigned aIdx );
/** function SetPickedItem
* @param aItem = a pointer to the item to pick
* @param aIdx = index of the picker in the picked list
......@@ -198,13 +206,21 @@ public:
bool SetPickedItemLink( EDA_BaseStruct* aLink, unsigned aIdx );
/** function SetPickedItemStatus
* Set the the type of undo/redo operation for a given picked item
* Set the type of undo/redo operation for a given picked item
* @param aStatus = the type of undo/redo operation associated to the picked item
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
/** function SetPickerFlags
* Set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags = the value to save in picker
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool SetPickerFlags( int aFlags, unsigned aIdx );
/** function RemovePicker
* remove one entry (one picker) from the list of picked items
* @param aIdx = index of the picker in the picked list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment