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"
|
|
|
|
#include "common.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 "program.h"
|
|
|
|
#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"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "libeditfrm.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
bool erase );
|
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 ..)
|
|
|
|
*/
|
2009-09-04 18:57:37 +00:00
|
|
|
int WinEDA_LibeditFrame::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
|
|
|
*/
|
2009-09-04 18:57:37 +00:00
|
|
|
int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
int ItemCount = 0;
|
2009-09-04 18:57:37 +00:00
|
|
|
int MustDoPlace = 0;
|
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;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ForceCloseManageCurseur( DrawPanel, DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = state;
|
|
|
|
GetScreen()->m_BlockLocate.m_Command = command;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->ManageCurseur = DrawAndSizingBlockOutlines;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = AbortBlockCurrentCommand;
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_Curseur.x = GetScreen()->m_BlockLocate.GetRight();
|
|
|
|
GetScreen()->m_Curseur.y = GetScreen()->m_BlockLocate.GetBottom();
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
}
|
|
|
|
|
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,
|
2009-09-25 18:49:04 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
|
|
|
if( ItemCount )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
MustDoPlace = 1;
|
|
|
|
if( DrawPanel->ManageCurseur != NULL )
|
|
|
|
{
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
|
|
|
DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->Refresh( TRUE );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
|
|
|
|
MustDoPlace = 1;
|
|
|
|
DrawPanel->ManageCurseur = 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,
|
2009-09-25 18:49:04 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
|
|
|
if( ItemCount )
|
|
|
|
SaveCopyInUndoList( m_component );
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( m_component )
|
|
|
|
m_component->DeleteSelectedItems();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_SAVE: /* Save */
|
|
|
|
case BLOCK_PASTE:
|
|
|
|
case BLOCK_ROTATE:
|
|
|
|
case BLOCK_MIRROR_X:
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_FLIP:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
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,
|
2009-09-25 18:49:04 +00:00
|
|
|
m_unit, m_convert,
|
|
|
|
g_EditPinByPinIsOn );
|
|
|
|
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 )
|
|
|
|
m_component->MirrorSelectedItemsH( pt );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( MustDoPlace <= 0 )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
if( GetScreen()->m_BlockLocate.m_Command != BLOCK_SELECT_ITEMS_ONLY )
|
2009-10-10 17:27:53 +00:00
|
|
|
if ( 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
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
GetScreen()->SetCurItem( NULL );
|
2009-09-04 18:57:37 +00:00
|
|
|
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor,
|
|
|
|
wxEmptyString );
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->Refresh( TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return MustDoPlace;
|
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
|
|
|
*/
|
2009-09-04 18:57:37 +00:00
|
|
|
void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
bool err = FALSE;
|
2009-09-29 18:38:21 +00:00
|
|
|
wxPoint pt;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( DrawPanel->ManageCurseur == NULL )
|
|
|
|
{
|
|
|
|
err = TRUE;
|
|
|
|
DisplayError( this, wxT( "HandleBlockPLace : ManageCurseur = NULL" ) );
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
err = TRUE;
|
|
|
|
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 );
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->Refresh( TRUE );
|
|
|
|
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;
|
|
|
|
|
2009-08-12 10:40:01 +00:00
|
|
|
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 )
|
|
|
|
m_component->MirrorSelectedItemsH( pt );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_ZOOM: // Handled by HandleBlockEnd
|
|
|
|
case BLOCK_DELETE:
|
|
|
|
case BLOCK_SAVE:
|
|
|
|
case BLOCK_ROTATE:
|
|
|
|
case BLOCK_ABORT:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetScreen()->SetModify();
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
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 );
|
|
|
|
DrawPanel->Refresh( TRUE );
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor,
|
|
|
|
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
|
|
|
*/
|
2009-09-22 12:27:57 +00:00
|
|
|
void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
BLOCK_SELECTOR* PtBlock;
|
2008-04-17 16:25:29 +00:00
|
|
|
BASE_SCREEN* screen = panel->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
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
WinEDA_LibeditFrame* parent = ( WinEDA_LibeditFrame* ) panel->GetParent();
|
|
|
|
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();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( erase )
|
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode,
|
|
|
|
PtBlock->m_Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
component->Draw( panel, DC, PtBlock->m_MoveVector, unit, convert,
|
|
|
|
g_XorMode, -1, DefaultTransformMatrix,
|
|
|
|
true, true, true );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Repaint new view */
|
2009-09-04 18:57:37 +00:00
|
|
|
PtBlock->m_MoveVector.x =
|
|
|
|
screen->m_Curseur.x - PtBlock->m_BlockLastCursorPosition.x;
|
|
|
|
PtBlock->m_MoveVector.y =
|
|
|
|
screen->m_Curseur.y - PtBlock->m_BlockLastCursorPosition.y;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, g_XorMode );
|
2009-09-04 18:57:37 +00:00
|
|
|
PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode,
|
|
|
|
PtBlock->m_Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
component->Draw( panel, DC, PtBlock->m_MoveVector, unit, convert,
|
|
|
|
g_XorMode, -1, DefaultTransformMatrix,
|
|
|
|
true, true, true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|