2010-11-27 13:09:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2010 Jean-Pierre Charras <jean-pierre.charras@gpisa-lab.inpg.fr>
|
|
|
|
* Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
#include "dialog_pcb_text_properties.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.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"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
/**
|
|
|
|
* DIALOG_PCB_TEXT_PROPERTIES, derived from DIALOG_PCB_TEXT_PROPERTIES_BASE
|
|
|
|
* @see dialog_dialog_pcb_text_properties_base.h and
|
|
|
|
* dialog_dialog_pcb_text_properties_base.cpp, automatically created by
|
|
|
|
* wxFormBuilder.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
DIALOG_PCB_TEXT_PROPERTIES::DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent,
|
|
|
|
TEXTE_PCB* passedTextPCB, wxDC* DC )
|
2010-11-27 13:09:18 +00:00
|
|
|
: DIALOG_PCB_TEXT_PROPERTIES_BASE( parent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_DC = DC;
|
|
|
|
m_SelectedPCBText = passedTextPCB;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
MyInit();
|
2011-03-14 15:17:18 +00:00
|
|
|
m_StandardSizerOK->SetDefault();
|
2010-11-27 13:09:18 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
/**
|
|
|
|
* Routine for main window class to launch text properties dialog.
|
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::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;
|
2010-11-27 13:09:18 +00:00
|
|
|
DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, DC );
|
|
|
|
dlg.ShowModal();
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
void DIALOG_PCB_TEXT_PROPERTIES::MyInit()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
SetFocus();
|
|
|
|
|
|
|
|
// Put units symbols to text labels where appropriate
|
|
|
|
AddUnitSymbol( *m_SizeXLabel );
|
|
|
|
AddUnitSymbol( *m_SizeYLabel );
|
|
|
|
AddUnitSymbol( *m_ThicknessLabel );
|
|
|
|
AddUnitSymbol( *m_PositionXLabel );
|
|
|
|
AddUnitSymbol( *m_PositionYLabel );
|
|
|
|
|
|
|
|
// Fill fields with current values
|
|
|
|
*m_TextContentCtrl << m_SelectedPCBText->m_Text;
|
|
|
|
|
|
|
|
PutValueInLocalUnits( *m_SizeXCtrl, m_SelectedPCBText->m_Size.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
PutValueInLocalUnits( *m_SizeYCtrl, m_SelectedPCBText->m_Size.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
PutValueInLocalUnits( *m_ThicknessCtrl, m_SelectedPCBText->m_Thickness,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
PutValueInLocalUnits( *m_PositionXCtrl, m_SelectedPCBText->m_Pos.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
PutValueInLocalUnits( *m_PositionYCtrl, m_SelectedPCBText->m_Pos.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
int enabledLayers = m_Parent->GetBoard()->GetEnabledLayers();
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int layer = 0; layer < NB_LAYERS; ++layer )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-07-04 21:32:49 +00:00
|
|
|
if( enabledLayers & (1 << layer) )
|
|
|
|
{
|
|
|
|
layerList.push_back( layer );
|
|
|
|
int itemIndex =
|
|
|
|
m_LayerSelectionCtrl->Append( m_Parent->GetBoard()->GetLayerName( layer ) );
|
|
|
|
if( m_SelectedPCBText->GetLayer() == layer )
|
|
|
|
m_LayerSelectionCtrl->SetSelection( itemIndex );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
switch( m_SelectedPCBText->m_Orient )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
default:
|
|
|
|
m_OrientationCtrl->SetSelection( 0 );
|
|
|
|
break;
|
|
|
|
case 900:
|
|
|
|
m_OrientationCtrl->SetSelection( 1 );
|
|
|
|
break;
|
|
|
|
case 1800:
|
|
|
|
m_OrientationCtrl->SetSelection( 2 );
|
|
|
|
break;
|
|
|
|
case 2700:
|
|
|
|
m_OrientationCtrl->SetSelection( 3 );
|
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( m_SelectedPCBText->m_Mirror )
|
|
|
|
m_DisplayCtrl->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_DisplayCtrl->SetSelection( 0 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( m_SelectedPCBText->m_Italic )
|
|
|
|
m_StyleCtrl->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_StyleCtrl->SetSelection( 0 );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
// Set justification
|
|
|
|
GRTextHorizJustifyType hJustify = m_SelectedPCBText->GetHorizJustify();
|
|
|
|
m_justifyChoice->SetSelection( (int) hJustify + 1 );
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Set focus on most important control
|
|
|
|
m_TextContentCtrl->SetFocus();
|
|
|
|
m_TextContentCtrl->SetSelection( -1, -1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
|
|
|
|
void DIALOG_PCB_TEXT_PROPERTIES::OnClose( wxCloseEvent& event )
|
|
|
|
{
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
void DIALOG_PCB_TEXT_PROPERTIES::OnCancelClick( wxCommandEvent& 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
|
|
|
}
|
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
void DIALOG_PCB_TEXT_PROPERTIES::OnOkClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
wxPoint newPosition;
|
|
|
|
wxSize newSize;
|
|
|
|
|
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)
|
2010-11-27 13:09:18 +00:00
|
|
|
if( m_SelectedPCBText->m_Flags == 0 )
|
|
|
|
m_Parent->SaveCopyInUndoList( m_SelectedPCBText, UR_CHANGED );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
/* 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 ..
|
|
|
|
*/
|
2010-11-27 13:09:18 +00:00
|
|
|
if( m_SelectedPCBText->m_Flags != 0 )
|
|
|
|
m_SelectedPCBText->m_Flags |= IN_EDIT;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Erase old text on screen if context is available
|
|
|
|
if( m_DC )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
m_SelectedPCBText->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Set the new text content
|
|
|
|
if( !m_TextContentCtrl->GetValue().IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
m_SelectedPCBText->m_Text = m_TextContentCtrl->GetValue();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2008-03-24 20:54:45 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Set PCB Text position
|
|
|
|
newPosition.x = ReturnValueFromString( g_UserUnit, m_PositionXCtrl->GetValue(), m_Parent->m_InternalUnits );
|
|
|
|
newPosition.y = ReturnValueFromString( g_UserUnit, m_PositionYCtrl->GetValue(), m_Parent->m_InternalUnits );
|
|
|
|
m_SelectedPCBText->m_Pos = newPosition;
|
|
|
|
|
|
|
|
// Check constraints and set PCB Text size
|
|
|
|
newSize.x = ReturnValueFromString( g_UserUnit, m_SizeXCtrl->GetValue(), m_Parent->m_InternalUnits );
|
|
|
|
newSize.y = ReturnValueFromString( g_UserUnit, m_SizeYCtrl->GetValue(), m_Parent->m_InternalUnits );
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( newSize.x < TEXTS_MIN_SIZE )
|
|
|
|
newSize.x = TEXTS_MIN_SIZE;
|
|
|
|
if( newSize.y < TEXTS_MIN_SIZE )
|
|
|
|
newSize.y = TEXTS_MIN_SIZE;
|
|
|
|
if( newSize.x > TEXTS_MAX_WIDTH )
|
|
|
|
newSize.x = TEXTS_MAX_WIDTH;
|
|
|
|
if( newSize.y > TEXTS_MAX_WIDTH )
|
|
|
|
newSize.y = TEXTS_MAX_WIDTH;
|
|
|
|
m_SelectedPCBText->m_Size = newSize;
|
|
|
|
|
|
|
|
// Set the new thickness
|
|
|
|
m_SelectedPCBText->m_Thickness = ReturnValueFromString( g_UserUnit, m_ThicknessCtrl->GetValue(), m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
// Test for acceptable values for thickness and size and clamp if fails
|
|
|
|
int maxthickness = Clamp_Text_PenSize( m_SelectedPCBText->m_Thickness, m_SelectedPCBText->m_Size );
|
|
|
|
if( m_SelectedPCBText->m_Thickness > maxthickness )
|
2009-05-30 16:06:01 +00:00
|
|
|
{
|
2010-12-09 18:15:01 +00:00
|
|
|
DisplayError(NULL, _("The text thickness is too large for the text size. It will be clamped"));
|
2010-11-27 13:09:18 +00:00
|
|
|
m_SelectedPCBText->m_Thickness = maxthickness;
|
2009-05-30 16:06:01 +00:00
|
|
|
}
|
2008-03-24 20:54:45 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Set the layer on which the PCB text is laying
|
2011-07-04 21:32:49 +00:00
|
|
|
m_SelectedPCBText->SetLayer( layerList[m_LayerSelectionCtrl->GetSelection()] );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
// Set whether the PCB text is mirrored (faced down from layer face perspective)
|
|
|
|
m_SelectedPCBText->m_Mirror = (m_DisplayCtrl->GetSelection() == 1) ? true : false;
|
|
|
|
|
|
|
|
// Set the text orientation
|
|
|
|
m_SelectedPCBText->m_Orient = m_OrientationCtrl->GetSelection() * 900;
|
|
|
|
|
|
|
|
// Set whether the PCB text is slanted (it is not italics, as italics has additional curves in style)
|
|
|
|
m_SelectedPCBText->m_Italic = m_StyleCtrl->GetSelection() ? 1 : 0;
|
2008-03-24 20:54:45 +00:00
|
|
|
|
2011-07-04 21:32:49 +00:00
|
|
|
// Set justification
|
|
|
|
switch( m_justifyChoice->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_SelectedPCBText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
// Finally, display new text if there is a context to do so
|
|
|
|
if( m_DC )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
m_SelectedPCBText->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
|
|
|
}
|