2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************/
|
2009-11-03 13:26:31 +00:00
|
|
|
/* block_libedit.cpp */
|
2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "block_commande.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "libeditframe.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-09-04 18:57:37 +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-11-19 16:28:46 +00:00
|
|
|
int LIB_EDIT_FRAME::ReturnBlockCommand( int key )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int cmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
cmd = key & 0x255;
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case - 1:
|
|
|
|
cmd = BLOCK_PRESELECT_MOVE;
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case 0:
|
|
|
|
cmd = BLOCK_MOVE;
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case GR_KB_ALT:
|
|
|
|
case GR_KB_SHIFT:
|
|
|
|
cmd = BLOCK_COPY;
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case GR_KB_SHIFTCTRL:
|
|
|
|
cmd = BLOCK_DELETE;
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case GR_KB_CTRL:
|
2009-08-12 10:40:01 +00:00
|
|
|
cmd = BLOCK_MIRROR_Y;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
case MOUSE_MIDDLE:
|
|
|
|
cmd = BLOCK_ZOOM;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return cmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
/*
|
|
|
|
* Command BLOCK END (end of block sizing)
|
2007-08-20 01:20:48 +00:00
|
|
|
* return :
|
|
|
|
* 0 if command finished (zoom, delete ...)
|
2009-09-04 18:57:37 +00:00
|
|
|
* 1 if HandleBlockPlace must follow (items found, and a block place
|
|
|
|
* command must follow)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-11-19 16:28:46 +00:00
|
|
|
bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
int ItemCount = 0;
|
2010-11-13 11:02:24 +00:00
|
|
|
int nextCmd = false;
|
2009-09-29 18:38:21 +00:00
|
|
|
wxPoint pt;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
if( GetScreen()->m_BlockLocate.GetCount() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BlockState state = GetScreen()->m_BlockLocate.m_State;
|
|
|
|
CmdBlockType command = GetScreen()->m_BlockLocate.m_Command;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_endMouseCaptureCallback( DrawPanel, DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = state;
|
|
|
|
GetScreen()->m_BlockLocate.m_Command = command;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand );
|
|
|
|
GetScreen()->SetCrossHairPosition( wxPoint( GetScreen()->m_BlockLocate.GetRight(),
|
|
|
|
GetScreen()->m_BlockLocate.GetBottom() ) );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
switch( GetScreen()->m_BlockLocate.m_Command )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case BLOCK_IDLE:
|
|
|
|
DisplayError( this, wxT( "Error in HandleBlockPLace" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DRAG: /* Drag */
|
|
|
|
case BLOCK_MOVE: /* Move */
|
|
|
|
case BLOCK_COPY: /* Copy */
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
|
2010-10-20 20:24:26 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
2009-09-25 18:49:04 +00:00
|
|
|
if( ItemCount )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
nextCmd = true;
|
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
|
|
|
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
|
|
|
}
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE;
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawPanel->Refresh( true );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
2010-11-13 11:02:24 +00:00
|
|
|
nextCmd = true;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback = DrawMovingBlockOutlines;
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DELETE: /* Delete */
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
|
2010-10-20 20:24:26 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
2009-09-25 18:49:04 +00:00
|
|
|
if( ItemCount )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
2011-01-23 12:32:33 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
m_component->DeleteSelectedItems();
|
2011-01-23 12:32:33 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_SAVE: /* Save */
|
|
|
|
case BLOCK_PASTE:
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_FLIP:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
2011-05-20 18:29:35 +00:00
|
|
|
case BLOCK_ROTATE:
|
|
|
|
case BLOCK_MIRROR_X:
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_MIRROR_Y:
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
|
2010-10-20 20:24:26 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
2009-09-25 18:49:04 +00:00
|
|
|
if( ItemCount )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-09-29 18:38:21 +00:00
|
|
|
pt = GetScreen()->m_BlockLocate.Centre();
|
|
|
|
pt.y *= -1;
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
2011-01-23 12:32:33 +00:00
|
|
|
{
|
|
|
|
OnModify();
|
2011-05-20 18:29:35 +00:00
|
|
|
int block_cmd = GetScreen()->m_BlockLocate.m_Command;
|
|
|
|
if( block_cmd == BLOCK_MIRROR_Y)
|
|
|
|
m_component->MirrorSelectedItemsH( pt );
|
|
|
|
else if( block_cmd == BLOCK_MIRROR_X)
|
|
|
|
m_component->MirrorSelectedItemsV( pt );
|
|
|
|
else if( block_cmd == BLOCK_ROTATE)
|
|
|
|
m_component->RotateSelectedItems( pt );
|
2011-01-23 12:32:33 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: /* Window Zoom */
|
2009-07-25 04:53:39 +00:00
|
|
|
Window_Zoom( GetScreen()->m_BlockLocate );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ABORT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_SELECT_ITEMS_ONLY:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-13 11:02:24 +00:00
|
|
|
if( ! nextCmd )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
if( GetScreen()->m_BlockLocate.m_Command != BLOCK_SELECT_ITEMS_ONLY && m_component )
|
|
|
|
m_component->ClearSelectedItems();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_Flags = 0;
|
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
|
|
|
|
GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( NULL, NULL );
|
2011-03-10 08:31:07 +00:00
|
|
|
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawPanel->Refresh( true );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 11:02:24 +00:00
|
|
|
return nextCmd;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +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-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
wxPoint pt;
|
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
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
switch( GetScreen()->m_BlockLocate.m_Command )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case BLOCK_IDLE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DRAG: /* Drag */
|
|
|
|
case BLOCK_MOVE: /* Move */
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-09-29 18:38:21 +00:00
|
|
|
pt = GetScreen()->m_BlockLocate.m_MoveVector;
|
|
|
|
pt.y *= -1;
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
m_component->MoveSelectedItems( pt );
|
2011-02-03 19:27:28 +00:00
|
|
|
DrawPanel->Refresh( true );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_COPY: /* Copy */
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-09-29 18:38:21 +00:00
|
|
|
pt = GetScreen()->m_BlockLocate.m_MoveVector;
|
|
|
|
pt.y *= -1;
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
m_component->CopySelectedItems( pt );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
case BLOCK_PASTE: /* Paste (recopy the last block saved) */
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-20 18:29:35 +00:00
|
|
|
case BLOCK_ROTATE: // Invert by popup menu, from block move
|
|
|
|
case BLOCK_MIRROR_X: // Invert by popup menu, from block move
|
|
|
|
case BLOCK_MIRROR_Y: // Invert by popup menu, from block move
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-09-29 18:38:21 +00:00
|
|
|
pt = GetScreen()->m_BlockLocate.Centre();
|
|
|
|
pt.y *= -1;
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
2011-05-20 18:29:35 +00:00
|
|
|
{
|
|
|
|
int block_cmd = GetScreen()->m_BlockLocate.m_Command;
|
|
|
|
if( block_cmd == BLOCK_MIRROR_Y)
|
|
|
|
m_component->MirrorSelectedItemsH( pt );
|
|
|
|
else if( block_cmd == BLOCK_MIRROR_X)
|
|
|
|
m_component->MirrorSelectedItemsV( pt );
|
|
|
|
else if( block_cmd == BLOCK_ROTATE )
|
|
|
|
m_component->RotateSelectedItems( pt );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: // Handled by HandleBlockEnd
|
|
|
|
case BLOCK_DELETE:
|
|
|
|
case BLOCK_SAVE:
|
|
|
|
case BLOCK_ABORT:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_Flags = 0;
|
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
|
|
|
|
GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
|
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-03 19:27:28 +00:00
|
|
|
DrawPanel->Refresh( true );
|
2011-03-10 08:31:07 +00:00
|
|
|
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +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
|
|
|
void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* PtBlock;
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint move_offset;
|
2009-07-25 04:53:39 +00:00
|
|
|
PtBlock = &screen->m_BlockLocate;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
LIB_EDIT_FRAME* parent = ( LIB_EDIT_FRAME* ) aPanel->GetParent();
|
2009-09-22 12:27:57 +00:00
|
|
|
wxASSERT( parent != NULL );
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_COMPONENT* component = parent->GetComponent();
|
2009-09-22 12:27:57 +00:00
|
|
|
|
|
|
|
if( component == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
int unit = parent->GetUnit();
|
|
|
|
int convert = parent->GetConvert();
|
|
|
|
|
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
|
|
|
PtBlock->Draw( aPanel, aDC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
component->Draw( aPanel, aDC, PtBlock->m_MoveVector, unit, convert,
|
2010-10-20 20:24:26 +00:00
|
|
|
g_XorMode, -1, DefaultTransform, true, true, true );
|
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
|
|
|
PtBlock->m_MoveVector = screen->GetCrossHairPosition() - PtBlock->m_BlockLastCursorPosition;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
GRSetDrawMode( aDC, g_XorMode );
|
|
|
|
PtBlock->Draw( aPanel, aDC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
component->Draw( aPanel, aDC, PtBlock->m_MoveVector, unit, convert,
|
2010-10-20 20:24:26 +00:00
|
|
|
g_XorMode, -1, DefaultTransform, true, true, true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|