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>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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
|
|
|
|
2016-01-20 12:11:17 +00:00
|
|
|
int GERBVIEW_FRAME::BlockCommand( EDA_KEY 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
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_STOP );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
switch( GetScreen()->m_BlockLocate.GetCommand() )
|
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;
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
default:
|
2011-03-13 18:03:43 +00:00
|
|
|
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
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
switch( GetScreen()->m_BlockLocate.GetCommand() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
case BLOCK_MOVE: /* Move */
|
2012-03-26 23:47:08 +00:00
|
|
|
GetScreen()->m_BlockLocate.SetState( 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;
|
|
|
|
|
2011-03-13 18:03:43 +00:00
|
|
|
case BLOCK_ZOOM: /* Window Zoom */
|
|
|
|
zoom_command = true;
|
|
|
|
break;
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
default:
|
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
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T 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 );
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetMoveVector().x|| screen->m_BlockLocate.GetMoveVector().y )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel,
|
|
|
|
aDC,
|
2012-03-26 23:47:08 +00:00
|
|
|
screen->m_BlockLocate.GetMoveVector(),
|
2009-11-09 14:00:22 +00:00
|
|
|
g_XorMode,
|
|
|
|
Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetState() != STATE_BLOCK_STOP )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
const wxPoint& cross_hair = aPanel->GetParent()->GetCrossHairPosition();
|
|
|
|
|
|
|
|
screen->m_BlockLocate.SetMoveVector(
|
|
|
|
wxPoint( cross_hair.x - screen->m_BlockLocate.GetRight(),
|
|
|
|
cross_hair.y - 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 );
|
|
|
|
|
2012-03-26 23:47:08 +00:00
|
|
|
if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel,
|
|
|
|
aDC,
|
2012-03-26 23:47:08 +00:00
|
|
|
screen->m_BlockLocate.GetMoveVector(),
|
2009-11-09 14:00:22 +00:00
|
|
|
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_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
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
oldpos = GetCrossHairPosition();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
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. */
|
2012-03-26 23:47:08 +00:00
|
|
|
delta = GetScreen()->m_BlockLocate.GetMoveVector();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/* Move items in block */
|
2012-05-04 17:44:42 +00:00
|
|
|
for( GERBER_DRAW_ITEM* item = GetItemsList(); 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;
|
2012-03-26 23:47:08 +00:00
|
|
|
|
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
|
|
|
}
|