2010-09-28 14:42:05 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-09-28 14:42:05 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 <Jean-Pierre Charras>
|
2011-09-30 18:15:37 +00:00
|
|
|
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
|
2010-09-28 14:42:05 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* @file gerbview/block.cpp
|
|
|
|
* @brief Block operations: displacement.
|
|
|
|
*/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gr_basic.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview.h>
|
|
|
|
#include <class_gerber_draw_item.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/debug.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#define BLOCK_COLOR BROWN
|
|
|
|
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool erase );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
int GERBVIEW_FRAME::ReturnBlockCommand( int key )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int cmd = 0;
|
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
cmd = key & 0x255;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
cmd = BLOCK_MOVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_KB_SHIFT:
|
|
|
|
case GR_KB_CTRL:
|
|
|
|
case GR_KB_SHIFTCTRL:
|
|
|
|
case GR_KB_ALT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_MIDDLE:
|
|
|
|
cmd = BLOCK_ZOOM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
wxASSERT( m_canvas->IsMouseCaptured() );
|
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_MOVE: /* Move */
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Block_Move( DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_COPY: /* Copy */
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Block_Duplicate( DC );
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PASTE:
|
2011-03-13 18:03:43 +00:00
|
|
|
case BLOCK_DRAG:
|
|
|
|
case BLOCK_PRESELECT_MOVE:
|
|
|
|
case BLOCK_ZOOM:
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_ROTATE:
|
2009-08-12 10:40:01 +00:00
|
|
|
case BLOCK_FLIP:
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_DELETE:
|
|
|
|
case BLOCK_SAVE:
|
|
|
|
case BLOCK_ABORT:
|
|
|
|
case BLOCK_SELECT_ITEMS_ONLY:
|
|
|
|
case BLOCK_MIRROR_X:
|
|
|
|
case BLOCK_MIRROR_Y:
|
2011-03-13 18:03:43 +00:00
|
|
|
case BLOCK_IDLE:
|
|
|
|
wxFAIL_MSG( wxT("HandleBlockPlace: Unexpected block command") );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetModify();
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->ClearBlockCommand();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-13 18:03:43 +00:00
|
|
|
wxASSERT( GetScreen()->m_BlockLocate.GetCount() == 0 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
DisplayToolMsg( wxEmptyString );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
bool nextcmd = false;
|
|
|
|
bool zoom_command = false;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
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_MOVE: /* Move */
|
|
|
|
case BLOCK_COPY: /* Copy */
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE;
|
2010-11-13 11:02:24 +00:00
|
|
|
nextcmd = true;
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
|
|
|
m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines );
|
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_DELETE: /* Delete */
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_STOP;
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
Block_Delete( DC );
|
|
|
|
break;
|
|
|
|
|
2011-03-13 18:03:43 +00:00
|
|
|
case BLOCK_ZOOM: /* Window Zoom */
|
|
|
|
zoom_command = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_PRESELECT_MOVE: /* Move with preselection list */
|
|
|
|
case BLOCK_DRAG:
|
|
|
|
case BLOCK_IDLE:
|
2010-09-28 14:42:05 +00:00
|
|
|
case BLOCK_MIRROR_X: /* Mirror, unused*/
|
|
|
|
case BLOCK_ROTATE: /* Unused */
|
|
|
|
case BLOCK_FLIP: /* Flip, unused */
|
|
|
|
case BLOCK_SAVE: /* Save (not used)*/
|
2007-08-20 01:20:48 +00:00
|
|
|
case BLOCK_PASTE:
|
|
|
|
case BLOCK_ABORT:
|
|
|
|
case BLOCK_SELECT_ITEMS_ONLY:
|
|
|
|
case BLOCK_MIRROR_Y:
|
2011-03-13 18:03:43 +00:00
|
|
|
wxFAIL_MSG( wxT("HandleBlockEnd: Unexpected block command") );
|
2007-08-20 01:20:48 +00:00
|
|
|
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
|
|
|
GetScreen()->ClearBlockCommand();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString,
|
|
|
|
false );
|
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
|
|
|
|
2010-11-13 11:02:24 +00:00
|
|
|
return nextcmd ;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Traces the outline of the block structures of a repositioning move
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon,
|
|
|
|
bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int Color;
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
Color = YELLOW;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
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
|
|
|
screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
|
|
|
|
|
|
|
|
if( screen->m_BlockLocate.m_MoveVector.x|| screen->m_BlockLocate.m_MoveVector.y )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel,
|
|
|
|
aDC,
|
2009-11-09 14:00:22 +00:00
|
|
|
screen->m_BlockLocate.m_MoveVector,
|
|
|
|
g_XorMode,
|
|
|
|
Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( screen->m_BlockLocate.m_State != STATE_BLOCK_STOP )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->m_BlockLocate.m_MoveVector.x = screen->GetCrossHairPosition().x -
|
2009-11-09 14:00:22 +00:00
|
|
|
screen->m_BlockLocate.GetRight();
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->m_BlockLocate.m_MoveVector.y = screen->GetCrossHairPosition().y -
|
2009-11-09 14:00:22 +00:00
|
|
|
screen->m_BlockLocate.GetBottom();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
|
|
|
|
|
|
|
|
if( screen->m_BlockLocate.m_MoveVector.x || screen->m_BlockLocate.m_MoveVector.y )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel,
|
|
|
|
aDC,
|
2009-11-09 14:00:22 +00:00
|
|
|
screen->m_BlockLocate.m_MoveVector,
|
|
|
|
g_XorMode,
|
|
|
|
Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::Block_Delete( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( !IsOK( this, _( "Ok to delete block ?" ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetScreen()->SetModify();
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.Normalize();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
BOARD_ITEM* item = GetBoard()->m_Drawings;
|
|
|
|
BOARD_ITEM* nextitem;
|
|
|
|
for( ; item; item = nextitem )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
nextitem = item->Next();
|
|
|
|
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item;
|
2010-10-10 17:57:54 +00:00
|
|
|
if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
|
2010-09-28 14:42:05 +00:00
|
|
|
gerb_item->DeleteStructure();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 18:13:43 +00:00
|
|
|
Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::Block_Move( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
wxPoint delta;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint oldpos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = GetScreen()->GetCrossHairPosition();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( oldpos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetModify();
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.Normalize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Calculate displacement vectors. */
|
2009-07-25 04:53:39 +00:00
|
|
|
delta = GetScreen()->m_BlockLocate.m_MoveVector;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/* Move items in block */
|
|
|
|
BOARD_ITEM* item = GetBoard()->m_Drawings;
|
|
|
|
for( ; item; item = item->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item;
|
2010-10-10 17:57:54 +00:00
|
|
|
if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
|
2010-10-15 18:59:26 +00:00
|
|
|
gerb_item->MoveAB( delta );
|
2009-05-02 18:53:04 +00:00
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh( true );
|
2009-05-02 18:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::Block_Duplicate( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
wxPoint delta;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint oldpos;
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
oldpos = GetScreen()->GetCrossHairPosition();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( oldpos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
GetScreen()->SetModify();
|
2009-07-25 04:53:39 +00:00
|
|
|
GetScreen()->m_BlockLocate.Normalize();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
delta = GetScreen()->m_BlockLocate.m_MoveVector;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/* Copy items in block */
|
|
|
|
BOARD_ITEM* item = GetBoard()->m_Drawings;
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
for( ; item; item = item->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item;
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
/* this item must be duplicated */
|
2010-10-15 18:59:26 +00:00
|
|
|
GERBER_DRAW_ITEM* new_item = gerb_item->Copy();
|
|
|
|
new_item->MoveAB( delta );
|
2010-09-28 14:42:05 +00:00
|
|
|
GetBoard()->m_Drawings.PushFront( new_item );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|