2011-12-08 15:45:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_text.h
|
|
|
|
* @brief Implementation of the label properties dialog.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wx/valgen.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "wxEeschemaStruct.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2008-12-19 20:40:08 +00:00
|
|
|
#include "general.h"
|
2009-12-27 14:01:21 +00:00
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "confirm.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_text.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "dialog_edit_label.h"
|
|
|
|
|
2009-02-10 20:02:51 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
/* Edit the properties of the text (Label, Global label, graphic text).. )
|
2010-03-16 18:22:59 +00:00
|
|
|
* pointed by "aTextStruct"
|
2009-12-27 14:01:21 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::EditSchematicText( SCH_TEXT* aTextItem )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
if( aTextItem == NULL )
|
2009-12-27 14:01:21 +00:00
|
|
|
return;
|
2009-02-10 20:02:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
DialogLabelEditor dialog( this, aTextItem );
|
2009-02-10 20:02:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
dialog.ShowModal();
|
2009-02-10 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DialogLabelEditor::DialogLabelEditor( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) :
|
2010-03-16 18:22:59 +00:00
|
|
|
DialogLabelEditor_Base( aParent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
m_Parent = aParent;
|
|
|
|
m_CurrentText = aTextItem;
|
2009-12-27 14:01:21 +00:00
|
|
|
InitDialog();
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Layout();
|
|
|
|
Fit();
|
|
|
|
SetMinSize( GetBestSize() );
|
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
Centre();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
void DialogLabelEditor::InitDialog()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-02-09 20:27:16 +00:00
|
|
|
wxString msg;
|
2010-03-16 18:22:59 +00:00
|
|
|
bool multiLine = false;
|
2009-11-02 20:36:20 +00:00
|
|
|
|
2009-05-13 10:26:11 +00:00
|
|
|
if( m_CurrentText->m_MultilineAllowed )
|
|
|
|
{
|
2010-03-30 10:10:33 +00:00
|
|
|
m_textLabel = m_textLabelMultiLine;
|
|
|
|
m_textLabelSingleLine->Show(false);
|
2010-03-16 18:22:59 +00:00
|
|
|
multiLine = true;
|
2009-05-13 10:26:11 +00:00
|
|
|
}
|
2010-03-30 10:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_textLabel = m_textLabelSingleLine;
|
|
|
|
m_textLabelMultiLine->Show(false);
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
m_textLabel->SetValue( m_CurrentText->m_Text );
|
|
|
|
m_textLabel->SetFocus();
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
switch( m_CurrentText->Type() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2009-02-09 20:27:16 +00:00
|
|
|
SetTitle( _( "Global Label Properties" ) );
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
2011-03-25 19:16:05 +00:00
|
|
|
SetTitle( _( "Hierarchical Label Properties" ) );
|
2009-02-09 20:27:16 +00:00
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_LABEL_T:
|
2009-02-09 20:27:16 +00:00
|
|
|
SetTitle( _( "Label Properties" ) );
|
|
|
|
break;
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
2011-03-25 19:16:05 +00:00
|
|
|
SetTitle( _( "Hierarchical Sheet Pin Properties." ) );
|
|
|
|
break;
|
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
default:
|
|
|
|
SetTitle( _( "Text Properties" ) );
|
2010-03-16 18:22:59 +00:00
|
|
|
m_textLabel->Disconnect( wxEVT_COMMAND_TEXT_ENTER,
|
|
|
|
wxCommandEventHandler ( DialogLabelEditor::OnEnterKey ),
|
|
|
|
NULL, this );
|
2009-02-09 20:27:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-12-22 14:11:01 +00:00
|
|
|
int MINTEXTWIDTH = 40; // M's are big characters, a few establish a lot of width
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-12-22 14:11:01 +00:00
|
|
|
int max_len = 0;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-12-22 14:11:01 +00:00
|
|
|
if ( !multiLine )
|
2009-02-09 20:27:16 +00:00
|
|
|
{
|
2010-12-22 14:11:01 +00:00
|
|
|
max_len =m_CurrentText->m_Text.Length();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2009-09-26 17:22:47 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
// calculate the length of the biggest line
|
|
|
|
// we cannot use the length of the entire text that has no meaning
|
2010-12-22 14:11:01 +00:00
|
|
|
int curr_len = MINTEXTWIDTH;
|
2009-09-26 17:22:47 +00:00
|
|
|
int imax = m_CurrentText->m_Text.Len();
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-09-26 17:22:47 +00:00
|
|
|
for( int count = 0; count < imax; count++ )
|
|
|
|
{
|
|
|
|
if( m_CurrentText->m_Text[count] == '\n' ||
|
2010-03-16 18:22:59 +00:00
|
|
|
m_CurrentText->m_Text[count] == '\r' ) // new line
|
|
|
|
{
|
|
|
|
curr_len = 0;
|
|
|
|
}
|
2009-09-26 17:22:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
curr_len++;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-09-26 17:22:47 +00:00
|
|
|
if ( max_len < curr_len )
|
|
|
|
max_len = curr_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-12-22 14:11:01 +00:00
|
|
|
if( max_len < MINTEXTWIDTH )
|
|
|
|
max_len = MINTEXTWIDTH;
|
|
|
|
|
|
|
|
wxString textWidth;
|
|
|
|
textWidth.Append( 'M', MINTEXTWIDTH );
|
|
|
|
EnsureTextCtrlWidth( m_textLabel, &textWidth );
|
2009-02-09 20:27:16 +00:00
|
|
|
|
|
|
|
// Set validators
|
2011-03-03 01:58:12 +00:00
|
|
|
m_TextOrient->SetSelection( m_CurrentText->GetOrientation() );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_TextShape->SetSelection( m_CurrentText->GetShape() );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
int style = 0;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
if( m_CurrentText->m_Italic )
|
2008-12-19 20:40:08 +00:00
|
|
|
style = 1;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( m_CurrentText->m_Bold )
|
2008-12-19 20:40:08 +00:00
|
|
|
style += 2;
|
2009-02-09 20:27:16 +00:00
|
|
|
|
|
|
|
m_TextStyle->SetSelection( style );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
wxString units = ReturnUnitSymbol( g_UserUnit, wxT( "(%s)" ) );
|
2010-03-16 18:22:59 +00:00
|
|
|
msg = _( "H" ) + units + _( " x W" ) + units;
|
|
|
|
m_staticSizeUnits->SetLabel( msg );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, m_CurrentText->m_Size.x,
|
2011-12-16 13:32:23 +00:00
|
|
|
m_Parent->GetInternalUnits() );
|
2009-02-09 20:27:16 +00:00
|
|
|
m_TextSize->SetValue( msg );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( m_CurrentText->Type() != SCH_GLOBAL_LABEL_T
|
|
|
|
&& m_CurrentText->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2009-02-09 20:27:16 +00:00
|
|
|
{
|
|
|
|
m_TextShape->Show( false );
|
|
|
|
}
|
2010-11-18 21:10:52 +00:00
|
|
|
|
|
|
|
m_sdbSizer1OK->SetDefault();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
/*!
|
2010-03-16 18:22:59 +00:00
|
|
|
* wxTE_PROCESS_ENTER event handler for m_textLabel
|
2009-04-28 19:34:42 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DialogLabelEditor::OnEnterKey( wxCommandEvent& aEvent )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
TextPropertiesAccept( aEvent );
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*!
|
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
|
|
|
|
*/
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DialogLabelEditor::OnOkClick( wxCommandEvent& aEvent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
TextPropertiesAccept( aEvent );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*!
|
2007-11-07 04:24:25 +00:00
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
|
2007-05-06 16:03:28 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void DialogLabelEditor::OnCancelClick( wxCommandEvent& aEvent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->MoveCursorToCrossHair();
|
2009-11-02 20:36:20 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2009-04-26 17:00:59 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
void DialogLabelEditor::TextPropertiesAccept( wxCommandEvent& aEvent )
|
2009-12-27 14:01:21 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
/* save old text in undo list if not already in edit */
|
2011-12-21 13:42:02 +00:00
|
|
|
if( m_CurrentText->GetFlags() == 0 )
|
2009-12-27 14:01:21 +00:00
|
|
|
m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
|
2009-12-27 14:01:21 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
text = m_textLabel->GetValue();
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
if( !text.IsEmpty() )
|
|
|
|
m_CurrentText->m_Text = text;
|
2011-12-21 13:42:02 +00:00
|
|
|
else if( !m_CurrentText->IsNew() )
|
2009-12-27 14:01:21 +00:00
|
|
|
DisplayError( this, _( "Empty Text!" ) );
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
m_CurrentText->SetOrientation( m_TextOrient->GetSelection() );
|
2009-12-27 14:01:21 +00:00
|
|
|
text = m_TextSize->GetValue();
|
2011-12-16 13:32:23 +00:00
|
|
|
value = ReturnValueFromString( g_UserUnit, text, m_Parent->GetInternalUnits() );
|
2009-12-27 14:01:21 +00:00
|
|
|
m_CurrentText->m_Size.x = m_CurrentText->m_Size.y = value;
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
if( m_TextShape )
|
2011-12-08 15:45:01 +00:00
|
|
|
m_CurrentText->SetShape( m_TextShape->GetSelection() );
|
2009-12-27 14:01:21 +00:00
|
|
|
|
|
|
|
int style = m_TextStyle->GetSelection();
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
if( ( style & 1 ) )
|
|
|
|
m_CurrentText->m_Italic = 1;
|
|
|
|
else
|
|
|
|
m_CurrentText->m_Italic = 0;
|
|
|
|
|
|
|
|
if( ( style & 2 ) )
|
|
|
|
{
|
|
|
|
m_CurrentText->m_Bold = true;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_CurrentText->m_Thickness = GetPenSizeForBold( m_CurrentText->m_Size.x );
|
2009-12-27 14:01:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_CurrentText->m_Bold = false;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_CurrentText->m_Thickness = 0;
|
2009-12-27 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
m_Parent->OnModify();
|
2009-12-27 14:01:21 +00:00
|
|
|
|
|
|
|
/* Make the text size as new default size if it is a new text */
|
2011-12-21 13:42:02 +00:00
|
|
|
if( m_CurrentText->IsNew() )
|
2009-12-27 14:01:21 +00:00
|
|
|
g_DefaultTextLabelSize = m_CurrentText->m_Size.x;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
|
|
|
|
m_Parent->GetCanvas()->MoveCursorToCrossHair();
|
2010-03-16 18:22:59 +00:00
|
|
|
EndModal( wxID_OK );
|
2009-12-27 14:01:21 +00:00
|
|
|
}
|