2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-09 20:27:16 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
// Name: dialog_edit_label.cpp
|
|
|
|
// Author: jean-pierre Charras
|
2008-03-20 01:50:21 +00:00
|
|
|
// Modified by:
|
2008-12-19 20:40:08 +00:00
|
|
|
// Created: 18/12/2008 15:46:26
|
|
|
|
// Licence: GPL
|
2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wx/valgen.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2008-12-19 20:40:08 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
2009-12-27 14:01:21 +00:00
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "confirm.h"
|
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
|
|
|
/*************************************************************************/
|
|
|
|
void WinEDA_SchematicFrame::EditSchematicText( SCH_TEXT* TextStruct )
|
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).. )
|
|
|
|
* pointed by "TextStruct"
|
|
|
|
*/
|
|
|
|
if( TextStruct == NULL )
|
|
|
|
return;
|
2009-02-10 20:02:51 +00:00
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
DialogLabelEditor dialog( this, TextStruct );
|
|
|
|
dialog.ShowModal();
|
2009-02-10 20:02:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-13 10:26:11 +00:00
|
|
|
DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText ) :
|
|
|
|
DialogLabelEditor_Base( parent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-19 20:40:08 +00:00
|
|
|
m_Parent = parent;
|
2009-02-09 20:27:16 +00:00
|
|
|
m_CurrentText = CurrentText;
|
2009-12-27 14:01:21 +00:00
|
|
|
InitDialog();
|
|
|
|
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
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;
|
2009-09-26 17:22:47 +00:00
|
|
|
bool multine = false;
|
2009-11-02 20:36:20 +00:00
|
|
|
|
2009-05-13 10:26:11 +00:00
|
|
|
if( m_CurrentText->m_MultilineAllowed )
|
|
|
|
{
|
|
|
|
m_TextLabel = m_textCtrlMultiline;
|
|
|
|
m_TextLabelSingleline->Show(false);
|
2009-09-26 17:22:47 +00:00
|
|
|
multine = true;
|
2009-05-13 10:26:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TextLabel = m_TextLabelSingleline;
|
|
|
|
m_textCtrlMultiline->Show(false);
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
m_TextLabel->SetValue( m_CurrentText->m_Text );
|
2008-03-20 01:50:21 +00:00
|
|
|
m_TextLabel->SetFocus();
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
switch( m_CurrentText->Type() )
|
|
|
|
{
|
2009-02-09 20:27:16 +00:00
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
|
|
|
SetTitle( _( "Global Label Properties" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
SetTitle( _( "Hierarchal Label Properties" ) );
|
2009-03-22 11:34:14 +00:00
|
|
|
m_TextShape->SetLabel( _("Hlabel Shape") );
|
2009-02-09 20:27:16 +00:00
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
case TYPE_SCH_LABEL:
|
|
|
|
SetTitle( _( "Label Properties" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetTitle( _( "Text Properties" ) );
|
2009-04-28 19:34:42 +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
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
unsigned MINTEXTWIDTH = 30; // M's are big characters, a few establish a lot of width
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
if( m_CurrentText->m_Text.Length() < MINTEXTWIDTH )
|
|
|
|
{
|
|
|
|
wxString textWidth;
|
|
|
|
textWidth.Append( 'M', MINTEXTWIDTH );
|
|
|
|
EnsureTextCtrlWidth( m_TextLabel, &textWidth );
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2009-09-26 17:22:47 +00:00
|
|
|
else if ( ! multine )
|
2009-02-09 20:27:16 +00:00
|
|
|
EnsureTextCtrlWidth( m_TextLabel );
|
2009-09-26 17:22:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// calculate the lenght of the biggest line
|
|
|
|
// we cannot use the lenght of the entire text that has no meaning
|
|
|
|
int max_len = 0;
|
|
|
|
int curr_len = 0;
|
|
|
|
int imax = m_CurrentText->m_Text.Len();
|
|
|
|
for( int count = 0; count < imax; count++ )
|
|
|
|
{
|
|
|
|
if( m_CurrentText->m_Text[count] == '\n' ||
|
|
|
|
m_CurrentText->m_Text[count] == '\r' ) // new line
|
|
|
|
{
|
|
|
|
curr_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curr_len++;
|
|
|
|
if ( max_len < curr_len )
|
|
|
|
max_len = curr_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wxString textWidth;
|
|
|
|
textWidth.Append( 'M', max_len );
|
|
|
|
EnsureTextCtrlWidth( m_TextLabel, &textWidth );
|
|
|
|
}
|
2009-02-09 20:27:16 +00:00
|
|
|
|
|
|
|
// Set validators
|
2009-05-12 12:12:34 +00:00
|
|
|
m_TextOrient->SetSelection( m_CurrentText->GetSchematicTextOrientation() );
|
2009-02-09 20:27:16 +00:00
|
|
|
m_TextShape->SetSelection( m_CurrentText->m_Shape );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
int style = 0;
|
2009-02-09 20:27:16 +00:00
|
|
|
if( m_CurrentText->m_Italic )
|
2008-12-19 20:40:08 +00:00
|
|
|
style = 1;
|
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
|
|
|
|
|
|
|
msg = m_SizeTitle->GetLabel() + ReturnUnitSymbol();
|
2009-02-09 20:27:16 +00:00
|
|
|
m_SizeTitle->SetLabel( msg );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
msg = ReturnStringFromValue( g_UnitMetric, m_CurrentText->m_Size.x, m_Parent->m_InternalUnits );
|
|
|
|
m_TextSize->SetValue( msg );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-02-09 20:27:16 +00:00
|
|
|
if( m_CurrentText->Type() != TYPE_SCH_GLOBALLABEL
|
|
|
|
&& m_CurrentText->Type() != TYPE_SCH_HIERLABEL )
|
|
|
|
{
|
|
|
|
m_TextShape->Show( false );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
/*!
|
|
|
|
* wxTE_PROCESS_ENTER event handler for m_TextLabel
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DialogLabelEditor::onEnterKey( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
TextPropertiesAccept( event );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*!
|
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
|
|
|
|
*/
|
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
void DialogLabelEditor::OnButtonOKClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-02-09 20:27:16 +00:00
|
|
|
TextPropertiesAccept( event );
|
2009-11-02 20:36:20 +00:00
|
|
|
EndModal( wxID_OK );
|
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
|
|
|
*/
|
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
void DialogLabelEditor::OnButtonCANCEL_Click( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-11-07 04:24:25 +00:00
|
|
|
m_Parent->DrawPanel->MouseToCursorSchema();
|
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
|
|
|
|
2009-12-27 14:01:21 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
void DialogLabelEditor::TextPropertiesAccept( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
/****************************************************************************/
|
|
|
|
wxString text;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
/* save old text in undo list if not already in edit */
|
|
|
|
if( m_CurrentText->m_Flags == 0 )
|
|
|
|
m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );
|
|
|
|
|
|
|
|
m_Parent->DrawPanel->PostDirtyRect( m_CurrentText->GetBoundingBox() );
|
|
|
|
|
|
|
|
text = m_TextLabel->GetValue();
|
|
|
|
if( !text.IsEmpty() )
|
|
|
|
m_CurrentText->m_Text = text;
|
|
|
|
else if( (m_CurrentText->m_Flags & IS_NEW) == 0 )
|
|
|
|
DisplayError( this, _( "Empty Text!" ) );
|
|
|
|
|
|
|
|
m_CurrentText->SetSchematicTextOrientation( m_TextOrient->GetSelection() );
|
|
|
|
text = m_TextSize->GetValue();
|
|
|
|
value = ReturnValueFromString( g_UnitMetric, text,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
m_CurrentText->m_Size.x = m_CurrentText->m_Size.y = value;
|
|
|
|
if( m_TextShape )
|
|
|
|
m_CurrentText->m_Shape = m_TextShape->GetSelection();
|
|
|
|
|
|
|
|
int style = m_TextStyle->GetSelection();
|
|
|
|
if( ( style & 1 ) )
|
|
|
|
m_CurrentText->m_Italic = 1;
|
|
|
|
else
|
|
|
|
m_CurrentText->m_Italic = 0;
|
|
|
|
|
|
|
|
if( ( style & 2 ) )
|
|
|
|
{
|
|
|
|
m_CurrentText->m_Bold = true;
|
|
|
|
m_CurrentText->m_Width = GetPenSizeForBold( m_CurrentText->m_Size.x );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_CurrentText->m_Bold = false;
|
|
|
|
m_CurrentText->m_Width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Parent->GetScreen()->SetModify();
|
|
|
|
|
|
|
|
/* Make the text size as new default size if it is a new text */
|
|
|
|
if( (m_CurrentText->m_Flags & IS_NEW) != 0 )
|
|
|
|
g_DefaultTextLabelSize = m_CurrentText->m_Size.x;
|
|
|
|
|
|
|
|
m_Parent->DrawPanel->PostDirtyRect( m_CurrentText->GetBoundingBox() );
|
|
|
|
m_Parent->DrawPanel->MouseToCursorSchema();
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|