2009-07-27 14:32:40 +00:00
|
|
|
/***************************************************
|
2009-11-04 20:46:53 +00:00
|
|
|
* operations_on_item_lists.cpp
|
2010-09-05 17:01:48 +00:00
|
|
|
* functions used in block commands, or undo/redo,
|
|
|
|
* to move, mirror, delete, copy ... lists of schematic items
|
|
|
|
*/
|
2009-07-27 14:32:40 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "appl_wxstruct.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "class_drawpanel.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-07-27 14:32:40 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "class_marker_sch.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
|
|
|
|
item->Rotate( rotationPoint ); // Place it in its new position.
|
|
|
|
item->m_Flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
void DeleteItemsInList( WinEDA_DrawPanel* panel,
|
2009-09-25 18:49:04 +00:00
|
|
|
PICKED_ITEMS_LIST& aItemsList );
|
|
|
|
void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
const wxPoint aMoveVector );
|
2009-07-27 14:32:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
|
2009-07-27 14:32:40 +00:00
|
|
|
item->Mirror_Y( aMirrorPoint.x ); // Place it in its new position.
|
|
|
|
item->m_Flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
|
|
|
|
item->Mirror_X( aMirrorPoint.y ); // Place it in its new position.
|
|
|
|
item->m_Flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-27 14:32:40 +00:00
|
|
|
/** Function MoveItemsInList
|
2009-12-02 21:44:03 +00:00
|
|
|
* Move a list of items to a given move vector
|
2009-11-04 20:46:53 +00:00
|
|
|
* @param aItemsList = list of picked items
|
|
|
|
* @param aMoveVector = the move vector value
|
|
|
|
*/
|
2009-07-27 14:32:40 +00:00
|
|
|
void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
|
2009-07-27 14:32:40 +00:00
|
|
|
item->Move( aMoveVector );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** function DeleteItemsInList
|
|
|
|
* delete schematic items in aItemsList
|
|
|
|
* deleted items are put in undo list
|
|
|
|
*/
|
|
|
|
void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
|
2009-12-21 12:05:36 +00:00
|
|
|
WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->GetParent();
|
2009-07-27 14:32:40 +00:00
|
|
|
PICKED_ITEMS_LIST itemsList;
|
|
|
|
ITEM_PICKER itemWrapper;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
|
2009-11-04 20:46:53 +00:00
|
|
|
itemWrapper.m_PickedItem = item;
|
2009-07-27 14:32:40 +00:00
|
|
|
itemWrapper.m_UndoRedoStatus = UR_DELETED;
|
|
|
|
if( item->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
{
|
|
|
|
/* this item is depending on a sheet, and is not in global list */
|
2010-09-05 17:01:48 +00:00
|
|
|
wxMessageBox( wxT(
|
|
|
|
"DeleteItemsInList() err: unexpected \
|
|
|
|
DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE" ) );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screen->RemoveFromDrawList( item );
|
|
|
|
|
|
|
|
/* Unlink the structure */
|
|
|
|
item->SetNext( 0 );
|
|
|
|
item->SetBack( 0 );
|
|
|
|
itemsList.PushItem( itemWrapper );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->SaveCopyInUndoList( itemsList, UR_DELETED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine to delete an object from global drawing object list.
|
|
|
|
* Object is put in Undo list
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, SCH_ITEM* DrawStruct )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
|
2009-12-21 12:05:36 +00:00
|
|
|
WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->GetParent();
|
2009-07-27 14:32:40 +00:00
|
|
|
|
|
|
|
if( !DrawStruct )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( DrawStruct->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
|
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
/* This structure is attached to a node, and is not accessible by
|
|
|
|
* the global list directly. */
|
|
|
|
frame->SaveCopyInUndoList(
|
2010-09-05 17:01:48 +00:00
|
|
|
(SCH_ITEM*)( (SCH_SHEET_PIN*) DrawStruct )->GetParent(),
|
2009-11-04 20:46:53 +00:00
|
|
|
UR_CHANGED );
|
2009-07-27 14:32:40 +00:00
|
|
|
frame->DeleteSheetLabel( DC ? true : false,
|
2009-11-04 20:46:53 +00:00
|
|
|
(SCH_SHEET_PIN*) DrawStruct );
|
2009-07-27 14:32:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
screen->RemoveFromDrawList( DrawStruct );
|
|
|
|
|
|
|
|
panel->PostDirtyRect( DrawStruct->GetBoundingBox() );
|
|
|
|
|
|
|
|
/* Unlink the structure */
|
|
|
|
DrawStruct->SetNext( 0 );
|
|
|
|
DrawStruct->SetBack( 0 ); // Only one struct -> no link
|
|
|
|
|
|
|
|
frame->SaveCopyInUndoList( DrawStruct, UR_DELETED );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Routine to copy a new entity of an object for each object in list and
|
|
|
|
* reposition it.
|
2009-07-27 14:32:40 +00:00
|
|
|
* Return the new created object list in aItemsList
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
const wxPoint aMoveVector )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* newitem;
|
|
|
|
|
|
|
|
if( aItemsList.GetCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
|
|
|
|
aItemsList.SetPickedItem( newitem, ii );
|
|
|
|
aItemsList.SetPickedItemStatus( UR_NEW, ii );
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
switch( newitem->Type() )
|
|
|
|
{
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
case TYPE_SCH_TEXT:
|
|
|
|
case TYPE_SCH_LABEL:
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
|
2009-12-02 21:44:03 +00:00
|
|
|
case TYPE_SCH_MARKER:
|
2009-07-27 14:32:40 +00:00
|
|
|
case DRAW_NOCONNECT_STRUCT_TYPE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SHEET_STRUCT_TYPE:
|
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) newitem;
|
2009-07-27 14:32:40 +00:00
|
|
|
sheet->m_TimeStamp = GetTimeStamp();
|
|
|
|
sheet->SetSon( NULL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_SCH_COMPONENT:
|
|
|
|
( (SCH_COMPONENT*) newitem )->m_TimeStamp = GetTimeStamp();
|
|
|
|
( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetaParent( newitem, screen );
|
|
|
|
newitem->SetNext( screen->EEDrawList );
|
|
|
|
screen->EEDrawList = newitem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MoveItemsInList( aItemsList, aMoveVector );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 18:26:04 +00:00
|
|
|
/** function DuplicateStruct
|
|
|
|
* Routine to create a new copy of given struct.
|
2009-07-27 14:32:40 +00:00
|
|
|
* The new object is not put in draw list (not linked)
|
2010-03-24 18:26:04 +00:00
|
|
|
* @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
|
2009-07-27 14:32:40 +00:00
|
|
|
*/
|
2010-03-24 18:26:04 +00:00
|
|
|
SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* NewDrawStruct = NULL;
|
|
|
|
|
2010-03-24 18:26:04 +00:00
|
|
|
if( aDrawStruct == NULL )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "DuplicateStruct error: NULL struct" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-03-24 18:26:04 +00:00
|
|
|
switch( aDrawStruct->Type() )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_POLYLINE*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_LINE*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_BUS_ENTRY*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_JUNCTION*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case TYPE_SCH_MARKER:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_MARKER*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_NOCONNECT_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_NO_CONNECT*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_TEXT:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_TEXT*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_LABEL:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_LABEL*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_HIERLABEL*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_GLOBALLABEL*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_COMPONENT:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_COMPONENT*) aDrawStruct )->GenCopy();
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SHEET_STRUCT_TYPE:
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct = ( (SCH_SHEET*) aDrawStruct )->GenCopy();
|
2010-09-05 17:01:48 +00:00
|
|
|
if( aClone )
|
2010-03-24 18:26:04 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
( (SCH_SHEET*) NewDrawStruct )->m_SheetName =
|
|
|
|
( (SCH_SHEET*) aDrawStruct )->m_SheetName;
|
2010-03-24 18:26:04 +00:00
|
|
|
}
|
2009-07-27 14:32:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-12-02 21:44:03 +00:00
|
|
|
msg << wxT( "DuplicateStruct error: unexpected StructType " )
|
2010-03-24 18:26:04 +00:00
|
|
|
<< aDrawStruct->Type() << wxT( " " ) << aDrawStruct->GetClass();
|
2009-07-27 14:32:40 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( aClone )
|
2010-03-24 18:26:04 +00:00
|
|
|
NewDrawStruct->m_TimeStamp = aDrawStruct->m_TimeStamp;
|
|
|
|
|
|
|
|
NewDrawStruct->m_Image = aDrawStruct;
|
2009-07-27 14:32:40 +00:00
|
|
|
return NewDrawStruct;
|
|
|
|
}
|