2013-08-16 18:41:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-08-28 16:14:39 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
|
2013-08-16 18:41:09 +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-09-23 13:57:12 +00:00
|
|
|
/**
|
2013-09-17 00:52:08 +00:00
|
|
|
* @file target_edit.cpp
|
2013-08-16 18:41:09 +00:00
|
|
|
* @brief Functions to edit targets (class #PCB_TARGET).
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_helpers.h>
|
2013-08-28 16:14:39 +00:00
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
2016-06-20 13:46:58 +00:00
|
|
|
#include <board_commit.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2013-08-28 16:14:39 +00:00
|
|
|
#include <dialog_target_properties_base.h>
|
2018-06-14 08:26:11 +00:00
|
|
|
#include <widgets/unit_binder.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Routines Locales
|
2011-01-21 19:30:59 +00:00
|
|
|
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel,
|
|
|
|
wxDC* aDC,
|
|
|
|
const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Local variables :
|
2013-08-16 18:41:09 +00:00
|
|
|
static int MireDefaultSize = Millimeter2iu( 5 );
|
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
static PCB_TARGET s_TargetCopy( NULL ); // Used to store "old" values of the current item
|
|
|
|
// parameters before editing for undo/redo/cancel
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
/**********************************/
|
|
|
|
/* class DIALOG_TARGET_PROPERTIES */
|
|
|
|
/**********************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
class DIALOG_TARGET_PROPERTIES : public DIALOG_TARGET_PROPERTIES_BASE
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
private:
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_EDIT_FRAME* m_Parent;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxDC* m_DC;
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET* m_Target;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
UNIT_BINDER m_Size;
|
|
|
|
UNIT_BINDER m_Thickness;
|
|
|
|
|
2010-08-23 17:30:51 +00:00
|
|
|
public:
|
2018-06-14 08:26:11 +00:00
|
|
|
DIALOG_TARGET_PROPERTIES( PCB_EDIT_FRAME* aParent, PCB_TARGET* aTarget, wxDC* aDC );
|
|
|
|
~DIALOG_TARGET_PROPERTIES() { }
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
private:
|
2018-06-14 08:26:11 +00:00
|
|
|
bool TransferDataToWindow() override;
|
|
|
|
bool TransferDataFromWindow() override;
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_EDIT_FRAME::ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
DIALOG_TARGET_PROPERTIES dialog( this, aTarget, DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
dialog.ShowModal();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
DIALOG_TARGET_PROPERTIES::DIALOG_TARGET_PROPERTIES( PCB_EDIT_FRAME* aParent, PCB_TARGET* aTarget,
|
|
|
|
wxDC* aDC ) :
|
|
|
|
DIALOG_TARGET_PROPERTIES_BASE( aParent ),
|
|
|
|
m_Parent( aParent ),
|
|
|
|
m_DC( aDC ),
|
|
|
|
m_Target( aTarget ),
|
2018-11-29 18:59:38 +00:00
|
|
|
m_Size( aParent, m_sizeLabel, m_sizeCtrl, m_sizeUnits, true ),
|
|
|
|
m_Thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits, true )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
m_sdbSizerButtsOK->SetDefault();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
SetInitialFocus( m_sizeCtrl );
|
2013-11-20 16:03:09 +00:00
|
|
|
|
2016-07-14 14:25:35 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
bool DIALOG_TARGET_PROPERTIES::TransferDataToWindow()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-06-14 08:26:11 +00:00
|
|
|
m_Size.SetValue( m_Target->GetSize() );
|
|
|
|
m_Thickness.SetValue( m_Target->GetWidth() );
|
|
|
|
|
|
|
|
m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
|
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
bool DIALOG_TARGET_PROPERTIES::TransferDataFromWindow()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-11-29 18:59:38 +00:00
|
|
|
// Zero-size targets are hard to see/select.
|
|
|
|
if( !m_Size.Validate( Mils2iu( 1 ), INT_MAX ) )
|
|
|
|
return false;
|
|
|
|
|
2016-06-20 13:46:58 +00:00
|
|
|
BOARD_COMMIT commit( m_Parent );
|
|
|
|
commit.Modify( m_Target );
|
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
if( m_DC )
|
|
|
|
m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
// Save old item in undo list, if is is not currently edited (will be later if so)
|
2016-06-20 13:46:58 +00:00
|
|
|
bool pushCommit = ( m_Target->GetFlags() == 0 );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
if( m_Target->GetFlags() != 0 ) // other edit in progress (MOVE, NEW ..)
|
2011-12-21 13:42:02 +00:00
|
|
|
m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
|
2018-06-14 08:26:11 +00:00
|
|
|
// undo/redo/abort proper operation
|
2013-08-28 16:14:39 +00:00
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
m_Target->SetWidth( m_Thickness.GetValue() );
|
|
|
|
m_Target->SetSize( m_Size.GetValue() );
|
2013-11-18 17:52:18 +00:00
|
|
|
m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-02-11 16:15:33 +00:00
|
|
|
if( m_DC )
|
|
|
|
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2016-06-20 13:46:58 +00:00
|
|
|
if( pushCommit )
|
|
|
|
commit.Push( _( "Modified alignment target" ) );
|
|
|
|
|
2018-06-14 08:26:11 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_EDIT_FRAME::DeleteTarget( PCB_TARGET* aTarget, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aTarget == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aTarget->Draw( m_canvas, DC, GR_XOR );
|
2011-09-07 19:41:04 +00:00
|
|
|
SaveCopyInUndoList( aTarget, UR_DELETED );
|
|
|
|
aTarget->UnLink();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
BASE_SCREEN* screen = Panel->GetScreen();
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-02-13 09:07:30 +00:00
|
|
|
Panel->SetMouseCapture( NULL, NULL );
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( target == NULL )
|
2009-08-03 07:55:08 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
target->Draw( Panel, DC, GR_XOR );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( target->IsNew() ) // If it is new, delete it
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
target->Draw( Panel, DC, GR_XOR );
|
|
|
|
target->DeleteStructure();
|
|
|
|
target = NULL;
|
2009-08-03 07:55:08 +00:00
|
|
|
}
|
2011-12-14 04:29:25 +00:00
|
|
|
else // it is an existing item: retrieve initial values of parameters
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( ( target->GetFlags() & (IN_EDIT | IS_MOVED) ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
target->SetPosition( s_TargetCopy.GetPosition() );
|
2013-08-16 18:41:09 +00:00
|
|
|
target->SetWidth( s_TargetCopy.GetWidth() );
|
|
|
|
target->SetSize( s_TargetCopy.GetSize() );
|
|
|
|
target->SetShape( s_TargetCopy.GetShape() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2013-08-16 18:41:09 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
target->ClearFlags();
|
2011-09-07 19:41:04 +00:00
|
|
|
target->Draw( Panel, DC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET* PCB_EDIT_FRAME::CreateTarget( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET* target = new PCB_TARGET( GetBoard() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
target->SetFlags( IS_NEW );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
GetBoard()->Add( target );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
target->SetLayer( Edge_Cuts );
|
2018-04-28 15:22:25 +00:00
|
|
|
target->SetWidth( GetDesignSettings().GetLineThickness( Edge_Cuts ) );
|
2011-12-14 04:29:25 +00:00
|
|
|
target->SetSize( MireDefaultSize );
|
2013-08-03 05:15:23 +00:00
|
|
|
target->SetPosition( GetCrossHairPosition() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PlaceTarget( target, DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
return target;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_EDIT_FRAME::BeginMoveTarget( PCB_TARGET* aTarget, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aTarget == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
s_TargetCopy = *aTarget;
|
2011-12-21 13:42:02 +00:00
|
|
|
aTarget->SetFlags( IS_MOVED );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( ShowTargetShapeWhileMovingMouse, AbortMoveAndEditTarget );
|
2011-09-07 19:41:04 +00:00
|
|
|
SetCurItem( aTarget );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aTarget == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
aTarget->Draw( m_canvas, DC, GR_OR );
|
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2007-09-12 02:14:07 +00:00
|
|
|
SetCurItem( NULL );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aTarget->IsNew() )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
SaveCopyInUndoList( aTarget, UR_NEW );
|
2011-12-21 13:42:02 +00:00
|
|
|
aTarget->ClearFlags();
|
2009-08-03 07:55:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( aTarget->GetFlags() == IS_MOVED )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
SaveCopyInUndoList( aTarget, UR_MOVED,
|
|
|
|
aTarget->GetPosition() - s_TargetCopy.GetPosition() );
|
|
|
|
aTarget->ClearFlags();
|
2009-08-03 07:55:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( (aTarget->GetFlags() & IN_EDIT) )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2013-11-20 17:26:47 +00:00
|
|
|
aTarget->SwapData( &s_TargetCopy );
|
2011-09-07 19:41:04 +00:00
|
|
|
SaveCopyInUndoList( aTarget, UR_CHANGED );
|
2013-11-20 17:26:47 +00:00
|
|
|
aTarget->SwapData( &s_TargetCopy );
|
2009-08-03 07:55:08 +00:00
|
|
|
}
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
aTarget->ClearFlags();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Redraw the contour of the track while moving the mouse
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( target == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
2011-09-07 19:41:04 +00:00
|
|
|
target->Draw( aPanel, aDC, GR_XOR );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
target->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
target->Draw( aPanel, aDC, GR_XOR );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|