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>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerber_draw_item.h>
|
|
|
|
#include <gerber_file_image.h>
|
|
|
|
#include <gerber_file_image_list.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
// Call back function used in block command
|
|
|
|
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
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
Block_Move();
|
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
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D Color = COLOR4D( 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
|
|
|
{
|
2016-06-17 18:00:29 +00:00
|
|
|
screen->m_BlockLocate.Draw( aPanel, aDC,
|
2012-03-26 23:47:08 +00:00
|
|
|
screen->m_BlockLocate.GetMoveVector(),
|
2016-06-17 18:00:29 +00:00
|
|
|
g_XorMode, Color );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
void GERBVIEW_FRAME::Block_Move()
|
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();
|
2016-06-17 18:00:29 +00:00
|
|
|
GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-06-17 18:00:29 +00:00
|
|
|
for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2016-06-17 18:00:29 +00:00
|
|
|
GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
|
2012-03-26 23:47:08 +00:00
|
|
|
|
2016-05-26 11:57:43 +00:00
|
|
|
if( gerber == NULL ) // Graphic layer not yet used
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Move items in block */
|
|
|
|
for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
GERBER_DRAW_ITEM* gerb_item = item;
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
if( gerb_item->HitTest( GetScreen()->m_BlockLocate, true ) )
|
2016-05-26 11:57:43 +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
|
|
|
}
|