2008-12-20 17:28:25 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
/* Dialog editor for text on copper and technical layers (TEXTE_PCB class) */
|
|
|
|
/***************************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2009-05-30 16:06:01 +00:00
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "confirm.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
enum id_TextPCB_properties {
|
2007-10-07 03:08:24 +00:00
|
|
|
ID_TEXTPCB_SELECT_LAYER = 1900
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/************************************/
|
|
|
|
/* class WinEDA_TextPCBPropertiesFrame */
|
|
|
|
/************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
class WinEDA_TextPCBPropertiesFrame : public wxDialog
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
WinEDA_PcbFrame* m_Parent;
|
|
|
|
wxDC* m_DC;
|
|
|
|
TEXTE_PCB* CurrentTextPCB;
|
|
|
|
WinEDA_EnterText* m_Name;
|
|
|
|
WinEDA_PositionCtrl* m_TxtPosCtrl;
|
|
|
|
WinEDA_SizeCtrl* m_TxtSizeCtrl;
|
|
|
|
WinEDA_ValueCtrl* m_TxtWidthCtlr;
|
|
|
|
wxRadioBox* m_Orient;
|
|
|
|
wxRadioBox* m_Mirror;
|
2008-12-20 17:28:25 +00:00
|
|
|
wxRadioBox* m_Style;
|
2007-08-20 01:20:48 +00:00
|
|
|
WinEDAChoiceBox* m_SelLayerBox;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
public:
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Constructor and destructor
|
|
|
|
WinEDA_TextPCBPropertiesFrame( WinEDA_PcbFrame* parent,
|
2008-12-20 17:28:25 +00:00
|
|
|
TEXTE_PCB* TextPCB, wxDC* DC );
|
2007-09-01 12:00:30 +00:00
|
|
|
~WinEDA_TextPCBPropertiesFrame()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
private:
|
2009-05-01 19:46:52 +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
|
|
|
};
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_TextPCBPropertiesFrame, wxDialog )
|
2009-05-01 19:46:52 +00:00
|
|
|
EVT_BUTTON( wxID_OK, WinEDA_TextPCBPropertiesFrame::OnOkClick )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, WinEDA_TextPCBPropertiesFrame::OnCancelClick )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
void WinEDA_PcbFrame::InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->m_IgnoreMouseEvents = TRUE;
|
2009-05-01 19:46:52 +00:00
|
|
|
WinEDA_TextPCBPropertiesFrame* frame =
|
|
|
|
new WinEDA_TextPCBPropertiesFrame( this, TextPCB, DC );
|
2007-10-07 03:08:24 +00:00
|
|
|
frame->ShowModal();
|
|
|
|
frame->Destroy();
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
WinEDA_TextPCBPropertiesFrame::WinEDA_TextPCBPropertiesFrame( WinEDA_PcbFrame* parent,
|
2009-05-01 19:46:52 +00:00
|
|
|
TEXTE_PCB* TextPCB,
|
|
|
|
wxDC* DC ) :
|
2009-09-28 19:28:22 +00:00
|
|
|
wxDialog( parent, -1, _( "PCB Text properties" ), wxDefaultPosition,
|
2009-05-01 19:46:52 +00:00
|
|
|
wxSize( 390, 340 ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-01 19:46:52 +00:00
|
|
|
wxButton* Button;
|
|
|
|
BOARD* board = parent->GetBoard();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
m_Parent = parent;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
m_DC = DC;
|
|
|
|
Centre();
|
|
|
|
|
|
|
|
CurrentTextPCB = TextPCB;
|
|
|
|
|
|
|
|
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( MainBoxSizer );
|
|
|
|
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer* MiddleBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
MainBoxSizer->Add( MiddleBoxSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/* Creation des boutons de commande */
|
2007-10-07 03:08:24 +00:00
|
|
|
Button = new wxButton( this, wxID_OK, _( "OK" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
Button->SetDefault();
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
m_Name = new WinEDA_EnterText( this, _( "Text:" ),
|
2009-05-01 19:46:52 +00:00
|
|
|
TextPCB->m_Text,
|
|
|
|
LeftBoxSizer, wxSize( 200, 60 ), true );
|
2007-05-06 16:03:28 +00:00
|
|
|
m_Name->SetFocus();
|
2007-08-20 01:20:48 +00:00
|
|
|
m_Name->SetSelection( -1, -1 );
|
|
|
|
|
|
|
|
m_TxtSizeCtrl = new WinEDA_SizeCtrl( this, _( "Size" ),
|
|
|
|
TextPCB->m_Size,
|
2009-05-01 19:46:52 +00:00
|
|
|
g_UnitMetric, LeftBoxSizer,
|
|
|
|
m_Parent->m_InternalUnits );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
m_TxtWidthCtlr = new WinEDA_ValueCtrl( this, _( "Width" ),
|
|
|
|
TextPCB->m_Width,
|
2009-05-01 19:46:52 +00:00
|
|
|
g_UnitMetric, LeftBoxSizer,
|
|
|
|
m_Parent->m_InternalUnits );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
m_TxtPosCtrl = new WinEDA_PositionCtrl( this, _( "Position" ),
|
|
|
|
TextPCB->m_Pos,
|
2009-05-01 19:46:52 +00:00
|
|
|
g_UnitMetric, LeftBoxSizer,
|
|
|
|
m_Parent->m_InternalUnits );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
m_SelLayerBox = new WinEDAChoiceBox( this, ID_TEXTPCB_SELECT_LAYER,
|
|
|
|
wxDefaultPosition, wxDefaultSize );
|
|
|
|
MiddleBoxSizer->Add( m_SelLayerBox, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
for( int layer = 0; layer<NB_LAYERS; ++layer )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-03-04 04:22:27 +00:00
|
|
|
m_SelLayerBox->Append( board->GetLayerName( layer ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
m_SelLayerBox->SetSelection( TextPCB->GetLayer() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
static const wxString orient_msg[4] =
|
|
|
|
{
|
|
|
|
wxT( "0" ), wxT( "90" ), wxT( "180" ), wxT( "-90" )
|
|
|
|
};
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
m_Orient = new wxRadioBox( this, -1, _( "Orientation" ), wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 4, orient_msg,
|
2007-08-20 01:20:48 +00:00
|
|
|
1, wxRA_SPECIFY_COLS );
|
|
|
|
MiddleBoxSizer->Add( m_Orient, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
switch( TextPCB->m_Orient )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
m_Orient->SetSelection( 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 900:
|
|
|
|
m_Orient->SetSelection( 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1800:
|
|
|
|
m_Orient->SetSelection( 2 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2700:
|
|
|
|
m_Orient->SetSelection( 3 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString display_msg[2] = { _( "Normal" ), _( "Mirror" ) };
|
2009-05-01 19:46:52 +00:00
|
|
|
m_Mirror = new wxRadioBox( this, -1, _( "Display" ), wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 2, display_msg,
|
2007-08-20 01:20:48 +00:00
|
|
|
1, wxRA_SPECIFY_COLS );
|
2008-12-20 20:38:39 +00:00
|
|
|
if( TextPCB->m_Mirror )
|
2007-10-07 03:08:24 +00:00
|
|
|
m_Mirror->SetSelection( 1 );
|
2007-08-20 01:20:48 +00:00
|
|
|
MiddleBoxSizer->Add( m_Mirror, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
int style = 0;
|
|
|
|
if( CurrentTextPCB->m_Italic )
|
2009-01-05 05:21:35 +00:00
|
|
|
style = 1;
|
2008-12-20 17:28:25 +00:00
|
|
|
wxString style_msg[] = { _( "Normal" ), _( "Italic" ) };
|
2009-05-01 19:46:52 +00:00
|
|
|
m_Style = new wxRadioBox( this, -1, _( "Style" ), wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 2, style_msg,
|
|
|
|
1, wxRA_SPECIFY_COLS );
|
|
|
|
m_Style->SetSelection( style );
|
2008-12-20 17:28:25 +00:00
|
|
|
MiddleBoxSizer->Add( m_Style, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
void WinEDA_TextPCBPropertiesFrame::OnCancelClick( wxCommandEvent& WXUNUSED( event ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-01 19:46:52 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
void WinEDA_TextPCBPropertiesFrame::OnOkClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
// If no other command in progress, prepare undo command
|
|
|
|
// (for a command in progress, will be made later, at the completion of command)
|
|
|
|
if( CurrentTextPCB->m_Flags == 0 )
|
|
|
|
m_Parent->SaveCopyInUndoList( CurrentTextPCB, UR_CHANGED );
|
|
|
|
|
|
|
|
/* set flag in edit to force undo/redo/abort proper operation,
|
|
|
|
* and avoid new calls to SaveCopyInUndoList for the same text
|
|
|
|
* this can occurs when a text is moved, and then rotated, edited ..
|
|
|
|
*/
|
|
|
|
if( CurrentTextPCB->m_Flags != 0 )
|
|
|
|
CurrentTextPCB->m_Flags |= IN_EDIT;
|
|
|
|
|
2009-05-01 19:46:52 +00:00
|
|
|
// test for acceptable values for parameters:
|
|
|
|
wxSize newsize = m_TxtSizeCtrl->GetValue();
|
|
|
|
|
|
|
|
if( newsize.x < TEXTS_MIN_SIZE )
|
2008-03-24 20:54:45 +00:00
|
|
|
newsize.x = TEXTS_MIN_SIZE;
|
2009-05-01 19:46:52 +00:00
|
|
|
if( newsize.y < TEXTS_MIN_SIZE )
|
2008-03-24 20:54:45 +00:00
|
|
|
newsize.y = TEXTS_MIN_SIZE;
|
2009-05-01 19:46:52 +00:00
|
|
|
if( newsize.x > TEXTS_MAX_WIDTH )
|
2008-03-24 20:54:45 +00:00
|
|
|
newsize.x = TEXTS_MAX_WIDTH;
|
2009-05-01 19:46:52 +00:00
|
|
|
if( newsize.y > TEXTS_MAX_WIDTH )
|
2008-03-24 20:54:45 +00:00
|
|
|
newsize.y = TEXTS_MAX_WIDTH;
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
if( m_DC ) // Erase old text on screen
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-04-01 05:21:50 +00:00
|
|
|
CurrentTextPCB->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_Name->GetValue().IsEmpty() )
|
|
|
|
{
|
|
|
|
CurrentTextPCB->m_Text = m_Name->GetValue();
|
|
|
|
}
|
2009-05-01 19:46:52 +00:00
|
|
|
CurrentTextPCB->m_Pos = m_TxtPosCtrl->GetValue();
|
|
|
|
CurrentTextPCB->m_Size = newsize;
|
|
|
|
|
|
|
|
CurrentTextPCB->m_Width = m_TxtWidthCtlr->GetValue();
|
2008-03-24 20:54:45 +00:00
|
|
|
|
|
|
|
// test for acceptable values for parameters:
|
2009-05-30 16:06:01 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize( CurrentTextPCB->m_Width, CurrentTextPCB->m_Size );
|
|
|
|
if( CurrentTextPCB->m_Width > maxthickness )
|
|
|
|
{
|
|
|
|
DisplayError(this, _("The text thickness is too large for the text size. It will be clamped"));
|
|
|
|
CurrentTextPCB->m_Width = maxthickness;
|
|
|
|
}
|
2008-03-24 20:54:45 +00:00
|
|
|
|
2008-12-20 20:38:39 +00:00
|
|
|
CurrentTextPCB->m_Mirror = (m_Mirror->GetSelection() == 1) ? true : false;
|
2007-08-20 01:20:48 +00:00
|
|
|
CurrentTextPCB->m_Orient = m_Orient->GetSelection() * 900;
|
2007-08-23 04:28:46 +00:00
|
|
|
CurrentTextPCB->SetLayer( m_SelLayerBox->GetChoice() );
|
2009-01-05 05:21:35 +00:00
|
|
|
CurrentTextPCB->m_Italic = m_Style->GetSelection() ? 1 : 0;
|
2008-03-24 20:54:45 +00:00
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
if( m_DC ) // Display new text
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-05-01 19:46:52 +00:00
|
|
|
CurrentTextPCB->Draw( m_Parent->DrawPanel, m_DC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-02-19 13:23:58 +00:00
|
|
|
m_Parent->OnModify();
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|