2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
/* BLOCK.CPP */
|
2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.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 "wxEeschemaStruct.h"
|
|
|
|
#include "class_sch_screen.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2009-07-26 17:16:42 +00:00
|
|
|
#include "protos.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_marker.h"
|
2011-01-12 21:47:54 +00:00
|
|
|
#include "sch_junction.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_line.h"
|
|
|
|
#include "sch_no_connect.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_text.h"
|
|
|
|
#include "sch_component.h"
|
|
|
|
#include "sch_sheet.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
// Imported functions:
|
2011-01-20 11:26:10 +00:00
|
|
|
extern void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen );
|
|
|
|
extern void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector );
|
|
|
|
extern void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
|
|
|
|
extern void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint );
|
|
|
|
extern void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
|
|
|
|
extern void DuplicateItemsInList( SCH_SCREEN* screen,
|
2011-01-07 19:24:24 +00:00
|
|
|
PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
const wxPoint aMoveVector );
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
|
2007-08-20 01:20:48 +00:00
|
|
|
* the key (ALT, SHIFT ALT ..)
|
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
int SCH_EDIT_FRAME::ReturnBlockCommand( int key )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int cmd;
|
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
cmd = key & 0xFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
cmd = BLOCK_MOVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_ALT:
|
|
|
|
case GR_KB_SHIFT:
|
|
|
|
cmd = BLOCK_COPY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_CTRL:
|
|
|
|
cmd = BLOCK_DRAG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_SHIFTCTRL:
|
|
|
|
cmd = BLOCK_DELETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_MIDDLE:
|
|
|
|
cmd = BLOCK_ZOOM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Init the parameters used by the block paste command
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::InitBlockPasteInfos()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
block->m_ItemsSelection.CopyList( m_blockItems.m_ItemsSelection );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback = DrawMovingBlockOutlines;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Routine to handle the BLOCK PLACE command
|
2007-08-20 01:20:48 +00:00
|
|
|
* Last routine for block operation for:
|
|
|
|
* - block move & drag
|
2009-11-03 13:26:31 +00:00
|
|
|
* - block copy & paste
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( !DrawPanel->IsMouseCaptured() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DisplayError( this, wxT( "HandleBlockPLace() : m_mouseCaptureCallback = NULL" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-11-03 14:13:15 +00:00
|
|
|
msg.Printf( wxT( "HandleBlockPLace() error : no items to place (cmd %d, state %d)" ),
|
2007-08-20 01:20:48 +00:00
|
|
|
block->m_Command, block->m_State );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
block->m_State = STATE_BLOCK_STOP;
|
|
|
|
|
|
|
|
switch( block->m_Command )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
case BLOCK_IDLE:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
case BLOCK_ROTATE:
|
|
|
|
case BLOCK_MIRROR_X:
|
|
|
|
case BLOCK_MIRROR_Y:
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_DRAG: /* Drag */
|
|
|
|
case BLOCK_MOVE: /* Move */
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
SaveCopyInUndoList( block->m_ItemsSelection, UR_MOVED, block->m_MoveVector );
|
2009-07-27 14:32:40 +00:00
|
|
|
MoveItemsInList( block->m_ItemsSelection, block->m_MoveVector );
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_COPY: /* Copy */
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
DuplicateItemsInList( GetScreen(), block->m_ItemsSelection, block->m_MoveVector );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
SaveCopyInUndoList( block->m_ItemsSelection,
|
|
|
|
( block->m_Command == BLOCK_PRESELECT_MOVE ) ? UR_CHANGED : UR_NEW );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case BLOCK_PASTE:
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
PasteListOfItems( DC );
|
|
|
|
block->ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: // Handled by HandleBlockEnd()
|
|
|
|
case BLOCK_DELETE:
|
|
|
|
case BLOCK_SAVE:
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_FLIP:
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_ABORT:
|
|
|
|
case BLOCK_SELECT_ITEMS_ONLY:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
// clear struct.m_Flags.
|
|
|
|
GetScreen()->ClearDrawingState();
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->ClearBlockCommand();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
DisplayError( this, wxT( "HandleBlockPLace() error: some items left in buffer" ) );
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2011-03-09 20:09:11 +00:00
|
|
|
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
|
2009-11-03 13:26:31 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-13 11:02:24 +00:00
|
|
|
/**
|
|
|
|
* Function HandleBlockEnd( )
|
|
|
|
* Handle the "end" of a block command,
|
|
|
|
* i.e. is called at the end of the definition of the area of a block.
|
|
|
|
* depending on the current block command, this command is executed
|
|
|
|
* or parameters are initialized to prepare a call to HandleBlockPlace
|
|
|
|
* in GetScreen()->m_BlockLocate
|
|
|
|
* @return false if no item selected, or command finished,
|
|
|
|
* true if some items found and HandleBlockPlace must be called later
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
bool nextcmd = false;
|
|
|
|
bool zoom_command = false;
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
BlockState state = block->m_State;
|
|
|
|
CmdBlockType command = block->m_Command;
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->m_endMouseCaptureCallback )
|
|
|
|
DrawPanel->m_endMouseCaptureCallback( DrawPanel, DC );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
block->m_State = state;
|
|
|
|
block->m_Command = command;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand );
|
|
|
|
GetScreen()->SetCrossHairPosition( block->GetEnd() );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( block->m_Command != BLOCK_ABORT )
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
2010-12-20 17:44:25 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
switch( block->m_Command )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
case BLOCK_IDLE:
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayError( this, wxT( "Error in HandleBlockPLace()" ) );
|
|
|
|
break;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case BLOCK_DRAG: /* Drag */
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->BreakSegmentsOnJunctions();
|
2010-12-20 17:44:25 +00:00
|
|
|
// fall through
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
case BLOCK_ROTATE:
|
|
|
|
case BLOCK_MIRROR_X:
|
|
|
|
case BLOCK_MIRROR_Y:
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_MOVE: /* Move */
|
|
|
|
case BLOCK_COPY: /* Copy */
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2010-12-20 17:44:25 +00:00
|
|
|
// fall through
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
nextcmd = true;
|
2011-01-07 19:24:24 +00:00
|
|
|
GetScreen()->SelectBlockItems();
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
|
|
|
DrawPanel->m_mouseCaptureCallback = DrawMovingBlockOutlines;
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
block->m_State = STATE_BLOCK_MOVE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DELETE: /* Delete */
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawAndSizingBlockOutlines( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case BLOCK_SAVE: /* Save */
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawAndSizingBlockOutlines( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
|
2011-01-07 19:24:24 +00:00
|
|
|
copyBlockItems( block->m_ItemsSelection );
|
|
|
|
MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector );
|
2010-11-13 11:02:24 +00:00
|
|
|
}
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PASTE:
|
|
|
|
block->m_State = STATE_BLOCK_MOVE;
|
|
|
|
break;
|
|
|
|
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_FLIP: /* pcbnew only! */
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: /* Window Zoom */
|
2010-11-13 11:02:24 +00:00
|
|
|
zoom_command = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_SELECT_ITEMS_ONLY: /* Not used */
|
|
|
|
case BLOCK_ABORT: /* not executed here */
|
|
|
|
break;
|
|
|
|
}
|
2010-12-20 17:44:25 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( block->m_Command == BLOCK_ABORT )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
2011-01-30 22:22:38 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 11:02:24 +00:00
|
|
|
if( ! nextcmd )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
block->m_Flags = 0;
|
|
|
|
block->m_State = STATE_NO_BLOCK;
|
|
|
|
block->m_Command = BLOCK_IDLE;
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2011-03-09 20:09:11 +00:00
|
|
|
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( zoom_command )
|
2009-07-25 04:53:39 +00:00
|
|
|
Window_Zoom( GetScreen()->m_BlockLocate );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
return nextcmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Manage end block command from context menu.
|
2010-09-06 09:10:12 +00:00
|
|
|
* Can be called only :
|
|
|
|
* after HandleBlockEnd
|
|
|
|
* and if the current command is block move.
|
|
|
|
* Execute a command other than block move from the current block move selected items list.
|
|
|
|
* Due to (minor) problems in undo/redo or/and display block,
|
2011-01-07 19:24:24 +00:00
|
|
|
* a mirror/rotate command is immediately executed and multiple block commands
|
2010-09-06 09:10:12 +00:00
|
|
|
* are not allowed (multiple commands are tricky to undo/redo in one time)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-09-06 09:10:12 +00:00
|
|
|
bool blockCmdFinished = true; /* set to false for block command which
|
|
|
|
* have a next step
|
|
|
|
* and true if the block command is finished here
|
|
|
|
*/
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-09-06 09:10:12 +00:00
|
|
|
// can convert only a block move command to an other command
|
2007-08-20 01:20:48 +00:00
|
|
|
if( block->m_Command != BLOCK_MOVE )
|
|
|
|
return;
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2010-09-06 09:10:12 +00:00
|
|
|
// Useless if the new command is block move because we are already in block move.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Command == BLOCK_MOVE )
|
|
|
|
return;
|
|
|
|
|
|
|
|
block->m_Command = (CmdBlockType) Command;
|
|
|
|
block->SetMessageBlock( this );
|
|
|
|
|
|
|
|
switch( block->m_Command )
|
|
|
|
{
|
|
|
|
case BLOCK_COPY: /* move to copy */
|
|
|
|
block->m_State = STATE_BLOCK_MOVE;
|
2010-09-06 09:10:12 +00:00
|
|
|
blockCmdFinished = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DRAG: /* move to Drag */
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2010-09-06 09:10:12 +00:00
|
|
|
// Clear list of items to move, and rebuild it with items to drag:
|
2009-07-25 04:53:39 +00:00
|
|
|
block->ClearItemsList();
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->BreakSegmentsOnJunctions();
|
2011-01-10 16:50:40 +00:00
|
|
|
GetScreen()->UpdatePickList();
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-09-06 09:10:12 +00:00
|
|
|
blockCmdFinished = false;
|
2011-01-07 19:24:24 +00:00
|
|
|
GetScreen()->SelectBlockItems();
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
block->m_State = STATE_BLOCK_MOVE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DELETE: /* move to Delete */
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-06 09:10:12 +00:00
|
|
|
case BLOCK_SAVE: /* Save list in paste buffer*/
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-03 14:13:15 +00:00
|
|
|
wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
|
2011-01-07 19:24:24 +00:00
|
|
|
copyBlockItems( block->m_ItemsSelection );
|
|
|
|
MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: /* Window Zoom */
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_endMouseCaptureCallback( DrawPanel, DC );
|
2011-02-08 14:48:38 +00:00
|
|
|
DrawPanel->SetCursor( DrawPanel->GetDefaultCursor() );
|
2009-07-25 04:53:39 +00:00
|
|
|
Window_Zoom( GetScreen()->m_BlockLocate );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BLOCK_ROTATE:
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( block->GetCount() )
|
|
|
|
{
|
|
|
|
/* Compute the rotation center and put it on grid */
|
|
|
|
wxPoint rotationPoint = block->Centre();
|
2011-07-20 05:57:06 +00:00
|
|
|
rotationPoint = GetScreen()->GetNearestGridPosition( rotationPoint );
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( rotationPoint );
|
2010-11-03 14:13:15 +00:00
|
|
|
SaveCopyInUndoList( block->m_ItemsSelection, UR_ROTATED, rotationPoint );
|
2010-09-05 17:01:48 +00:00
|
|
|
RotateListOfItems( block->m_ItemsSelection, rotationPoint );
|
|
|
|
OnModify();
|
|
|
|
}
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2010-09-05 17:01:48 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_MIRROR_X:
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( block->GetCount() )
|
|
|
|
{
|
|
|
|
/* Compute the mirror center and put it on grid */
|
|
|
|
wxPoint mirrorPoint = block->Centre();
|
2011-07-20 05:57:06 +00:00
|
|
|
mirrorPoint = GetScreen()->GetNearestGridPosition( mirrorPoint );
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( mirrorPoint );
|
2010-11-03 14:13:15 +00:00
|
|
|
SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_X, mirrorPoint );
|
2010-09-05 17:01:48 +00:00
|
|
|
Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint );
|
|
|
|
OnModify();
|
|
|
|
}
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2010-09-05 17:01:48 +00:00
|
|
|
DrawPanel->Refresh();
|
|
|
|
break;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_MIRROR_Y:
|
2011-02-11 20:48:13 +00:00
|
|
|
if( DrawPanel->IsMouseCaptured() )
|
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( block->GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Compute the mirror center and put it on grid */
|
2009-07-26 17:16:42 +00:00
|
|
|
wxPoint mirrorPoint = block->Centre();
|
2011-07-20 05:57:06 +00:00
|
|
|
mirrorPoint = GetScreen()->GetNearestGridPosition( mirrorPoint );
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( mirrorPoint );
|
2010-11-03 14:13:15 +00:00
|
|
|
SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_Y, mirrorPoint );
|
2009-07-26 17:16:42 +00:00
|
|
|
MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-06 09:10:12 +00:00
|
|
|
if( blockCmdFinished )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
block->Clear();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2011-02-24 20:22:12 +00:00
|
|
|
SetToolID( GetToolId(), DrawPanel->GetDefaultCursor(), wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Traces the outline of the search block structures
|
|
|
|
* The entire block follows the cursor
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2011-03-03 19:08:13 +00:00
|
|
|
BLOCK_SELECTOR* block = &screen->m_BlockLocate;
|
2009-07-25 04:53:39 +00:00
|
|
|
SCH_ITEM* schitem;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Erase old block contents. */
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
block->Draw( aPanel, aDC, block->m_MoveVector, g_XorMode, block->m_Color );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
for( unsigned ii = 0; ii < block->GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
|
2011-02-03 19:27:28 +00:00
|
|
|
schitem->Draw( aPanel, aDC, block->m_MoveVector, g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Repaint new view. */
|
2011-02-11 20:48:13 +00:00
|
|
|
block->m_MoveVector = screen->GetCrossHairPosition() - block->m_BlockLastCursorPosition;
|
2011-02-03 19:27:28 +00:00
|
|
|
block->Draw( aPanel, aDC, block->m_MoveVector, g_XorMode, block->m_Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
for( unsigned ii = 0; ii < block->GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-31 05:33:11 +00:00
|
|
|
schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
|
2011-02-03 19:27:28 +00:00
|
|
|
schitem->Draw( aPanel, aDC, block->m_MoveVector, g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-01-07 19:24:24 +00:00
|
|
|
m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-23 13:16:06 +00:00
|
|
|
// Clear m_Flag member of selected items:
|
2011-03-10 19:36:30 +00:00
|
|
|
aItemsList.GetPickedItem( ii )->ClearFlags();
|
2009-07-25 04:53:39 +00:00
|
|
|
/* Make a copy of the original picked item. */
|
2011-03-10 19:36:30 +00:00
|
|
|
SCH_ITEM* copy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
|
|
|
|
copy->SetParent( NULL );
|
|
|
|
|
|
|
|
// In list the wrapper is owner of the schematic item, we can use the UR_DELETED
|
|
|
|
// status for the picker because pickers with this status are owner of the picked item
|
|
|
|
// (or TODO ?: create a new status like UR_DUPLICATE)
|
|
|
|
ITEM_PICKER item( copy, UR_DELETED );
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
m_blockItems.PushItem( item );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2011-01-07 19:24:24 +00:00
|
|
|
* Routine to paste a structure from the m_blockItems stack.
|
2009-12-02 21:44:03 +00:00
|
|
|
* This routine is the same as undelete but original list is NOT removed.
|
2007-05-06 16:03:28 +00:00
|
|
|
*****************************************************************************/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
SCH_ITEM* Struct;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
if( m_blockItems.GetCount() == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "No struct to paste" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
PICKED_ITEMS_LIST picklist;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
for( unsigned ii = 0; ii < m_blockItems.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-07 19:24:24 +00:00
|
|
|
Struct = DuplicateStruct( (SCH_ITEM*) m_blockItems.m_ItemsSelection.GetPickedItem( ii ) );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
// Creates data, and push it as new data in undo item list buffer
|
|
|
|
ITEM_PICKER picker( Struct, UR_NEW );
|
2009-07-25 04:53:39 +00:00
|
|
|
picklist.PushItem( picker );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
// Clear annotation and init new time stamp for the new components:
|
2010-12-10 19:47:44 +00:00
|
|
|
if( Struct->Type() == SCH_COMPONENT_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
( (SCH_COMPONENT*) Struct )->m_TimeStamp = GetTimeStamp();
|
|
|
|
( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
SetSchItemParent( Struct, GetScreen() );
|
2011-01-07 19:24:24 +00:00
|
|
|
Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2010-12-08 20:12:46 +00:00
|
|
|
Struct->SetNext( GetScreen()->GetDrawItems() );
|
|
|
|
GetScreen()->SetDrawItems( Struct );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( picklist, UR_NEW );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2009-07-27 14:32:40 +00:00
|
|
|
MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
// Clear flags for all items.
|
2010-11-03 14:13:15 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|