2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file mirepcb.cpp
|
|
|
|
* @brief Functions to edit targets (class MIRE).
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <gr_basic.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_mire.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2007-05-06 16:03:28 +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
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
/* Local variables : */
|
2007-08-20 01:20:48 +00:00
|
|
|
static int MireDefaultSize = 5000;
|
2011-09-07 19:41:04 +00:00
|
|
|
static PCB_TARGET s_TargetCopy( NULL ); /* Used to store "old" values of the
|
2009-11-18 12:52:19 +00:00
|
|
|
* current item parameters before
|
|
|
|
* edition (used in undo/redo or
|
|
|
|
* cancel operations)
|
2009-08-03 07:55:08 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/************************************/
|
2010-08-10 18:34:26 +00:00
|
|
|
/* class TARGET_PROPERTIES_DIALOG_EDITOR */
|
2007-08-20 01:20:48 +00:00
|
|
|
/************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-08-10 18:34:26 +00:00
|
|
|
class TARGET_PROPERTIES_DIALOG_EDITOR : public wxDialog
|
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;
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_VALUE_CTRL* m_MireWidthCtrl;
|
|
|
|
EDA_VALUE_CTRL* m_MireSizeCtrl;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxRadioBox* m_MireShape;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-08-23 17:30:51 +00:00
|
|
|
public:
|
2011-09-07 19:41:04 +00:00
|
|
|
TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, PCB_TARGET* Mire, wxDC* DC );
|
2010-08-10 18:34:26 +00:00
|
|
|
~TARGET_PROPERTIES_DIALOG_EDITOR() { }
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
private:
|
2009-08-03 07:55:08 +00:00
|
|
|
void OnOkClick( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2010-08-10 18:34:26 +00:00
|
|
|
BEGIN_EVENT_TABLE( TARGET_PROPERTIES_DIALOG_EDITOR, wxDialog )
|
|
|
|
EVT_BUTTON( wxID_OK, TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-08-10 18:34:26 +00:00
|
|
|
TARGET_PROPERTIES_DIALOG_EDITOR* frame =
|
2011-09-07 19:41:04 +00:00
|
|
|
new TARGET_PROPERTIES_DIALOG_EDITOR( this, aTarget, DC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-10-11 04:56:44 +00:00
|
|
|
frame->ShowModal();
|
|
|
|
frame->Destroy();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent,
|
|
|
|
PCB_TARGET* aTarget, wxDC* DC ) :
|
2010-08-23 17:30:51 +00:00
|
|
|
wxDialog( parent, wxID_ANY, wxString( _( "Target Properties" ) ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString number;
|
|
|
|
wxButton* Button;
|
|
|
|
|
|
|
|
m_Parent = parent;
|
2009-08-03 07:55:08 +00:00
|
|
|
m_DC = DC;
|
2007-08-20 01:20:48 +00:00
|
|
|
Centre();
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
m_Target = aTarget;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( MainBoxSizer );
|
|
|
|
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Create of the command buttons. */
|
2007-10-11 04:56:44 +00:00
|
|
|
Button = new wxButton( this, wxID_OK, _( "OK" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2007-10-11 04:56:44 +00:00
|
|
|
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
// Size:
|
2011-09-06 19:42:46 +00:00
|
|
|
m_MireSizeCtrl = new EDA_VALUE_CTRL( this, _( "Size" ),
|
2011-12-14 04:29:25 +00:00
|
|
|
m_Target->GetSize(),
|
2012-04-16 17:39:32 +00:00
|
|
|
g_UserUnit, LeftBoxSizer );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Width:
|
2011-09-06 19:42:46 +00:00
|
|
|
m_MireWidthCtrl = new EDA_VALUE_CTRL( this, _( "Width" ),
|
2011-12-14 04:29:25 +00:00
|
|
|
m_Target->GetWidth(),
|
2012-04-16 17:39:32 +00:00
|
|
|
g_UserUnit, LeftBoxSizer );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Shape
|
|
|
|
wxString shape_list[2] = { _( "shape +" ), _( "shape X" ) };
|
2009-10-28 11:48:47 +00:00
|
|
|
m_MireShape = new wxRadioBox( this, wxID_ANY,
|
2007-10-10 14:08:26 +00:00
|
|
|
_( "Target Shape:" ),
|
2007-08-20 01:20:48 +00:00
|
|
|
wxDefaultPosition, wxSize( -1, -1 ),
|
|
|
|
2, shape_list, 1 );
|
2011-12-14 04:29:25 +00:00
|
|
|
m_MireShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
|
2007-08-20 01:20:48 +00:00
|
|
|
LeftBoxSizer->Add( m_MireShape, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-11 04:56:44 +00:00
|
|
|
EndModal( -1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Updates the different parameters for the component being edited
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-08-10 18:34:26 +00:00
|
|
|
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
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)
|
2011-12-21 13:42:02 +00:00
|
|
|
if( m_Target->GetFlags() == 0 )
|
2011-09-07 19:41:04 +00:00
|
|
|
m_Parent->SaveCopyInUndoList( m_Target, UR_CHANGED );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( m_Target->GetFlags() != 0 ) // other edition in progress (MOVE, NEW ..)
|
|
|
|
m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
|
|
|
|
// undo/redo/abort proper operation
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
m_Target->SetWidth( m_MireWidthCtrl->GetValue() );
|
|
|
|
MireDefaultSize = m_MireSizeCtrl->GetValue();
|
|
|
|
m_Target->SetSize( m_MireSizeCtrl->GetValue() );
|
|
|
|
m_Target->SetShape( m_MireShape->GetSelection() ? 1 : 0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
m_Parent->OnModify();
|
2007-10-11 04:56:44 +00:00
|
|
|
EndModal( 1 );
|
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() );
|
|
|
|
target->SetWidth( s_TargetCopy.GetWidth() );
|
|
|
|
target->SetSize( s_TargetCopy.GetSize() );
|
|
|
|
target->SetShape( s_TargetCopy.GetShape() );
|
2007-08-20 01:20:48 +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
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Draw Symbol PCB type MIRE.
|
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
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
target->SetLayer( EDGE_N );
|
2012-02-02 17:45:37 +00:00
|
|
|
target->SetWidth( GetDesignSettings().m_EdgeSegmentWidth );
|
2011-12-14 04:29:25 +00:00
|
|
|
target->SetSize( MireDefaultSize );
|
2011-12-22 13:28:11 +00:00
|
|
|
target->SetPosition( m_canvas->GetScreen()->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Routine to initialize the displacement of a focal
|
2007-08-20 01:20:48 +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
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
SwapData( aTarget, &s_TargetCopy );
|
|
|
|
SaveCopyInUndoList( aTarget, UR_CHANGED );
|
|
|
|
SwapData( aTarget, &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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +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
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
target->SetPosition( screen->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
|
|
|
}
|