2008-12-22 21:06:44 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialog_edit_module_text.cpp
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Licence: GPL
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2008-12-22 21:06:44 +00:00
|
|
|
#include "pcbnew.h"
|
2009-05-30 16:06:01 +00:00
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "confirm.h"
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
#include "dialog_edit_module_text_base.h"
|
|
|
|
|
|
|
|
extern wxPoint MoveVector; // Move vector for move edge, imported from edtxtmod.cpp
|
|
|
|
|
|
|
|
/*************** **************/
|
|
|
|
/* class DialogEditModuleText */
|
|
|
|
/*************** **************/
|
|
|
|
class DialogEditModuleText : public DialogEditModuleText_base
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
WinEDA_BasePcbFrame* m_Parent;
|
|
|
|
wxDC* m_DC;
|
|
|
|
MODULE* m_Module;
|
|
|
|
TEXTE_MODULE* m_CurrentTextMod;
|
|
|
|
|
|
|
|
public:
|
2009-01-05 05:21:35 +00:00
|
|
|
DialogEditModuleText( WinEDA_BasePcbFrame* parent, TEXTE_MODULE* TextMod, wxDC* DC );
|
|
|
|
~DialogEditModuleText() {};
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
private:
|
2009-08-19 14:19:35 +00:00
|
|
|
void Init( );
|
2009-01-05 05:21:35 +00:00
|
|
|
void OnOkClick( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
2008-12-22 21:06:44 +00:00
|
|
|
};
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/*************************************************************************************/
|
|
|
|
void WinEDA_BasePcbFrame::InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC )
|
|
|
|
/**************************************************************************************/
|
2008-12-22 21:06:44 +00:00
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = TRUE;
|
2009-08-11 10:27:21 +00:00
|
|
|
DialogEditModuleText dialog( this, TextMod, DC );
|
|
|
|
dialog.ShowModal();
|
2008-12-22 21:06:44 +00:00
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
DialogEditModuleText::DialogEditModuleText( WinEDA_BasePcbFrame* parent, TEXTE_MODULE* TextMod, wxDC* DC ) :
|
2009-01-05 05:21:35 +00:00
|
|
|
DialogEditModuleText_base(parent)
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
m_Parent = parent;
|
|
|
|
m_DC = DC;
|
|
|
|
m_Module = NULL;
|
|
|
|
m_CurrentTextMod = TextMod;
|
|
|
|
if( m_CurrentTextMod )
|
|
|
|
m_Module = (MODULE*) m_CurrentTextMod->GetParent();
|
2009-08-19 14:19:35 +00:00
|
|
|
Init( );
|
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogEditModuleText::OnCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
2009-08-19 14:19:35 +00:00
|
|
|
EndModal(0);
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
2009-08-19 14:19:35 +00:00
|
|
|
void DialogEditModuleText::Init( )
|
2008-12-22 21:06:44 +00:00
|
|
|
/********************************************************/
|
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
SetFocus();
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( m_Module )
|
|
|
|
{
|
|
|
|
wxString format = m_ModuleInfoText->GetLabel();
|
|
|
|
msg.Printf( format,
|
2009-10-14 18:14:58 +00:00
|
|
|
GetChars( m_Module->m_Reference->m_Text ),
|
|
|
|
GetChars( m_Module->m_Value->m_Text ),
|
2009-08-19 14:19:35 +00:00
|
|
|
(float) m_Module->m_Orient / 10 );
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
else
|
|
|
|
msg.Empty();
|
|
|
|
|
|
|
|
m_ModuleInfoText->SetLabel( msg );
|
|
|
|
|
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
if( m_CurrentTextMod->m_Type == TEXT_is_VALUE )
|
|
|
|
m_TextDataTitle->SetLabel( _( "Value:" ) );
|
|
|
|
else if( m_CurrentTextMod->m_Type == TEXT_is_DIVERS )
|
|
|
|
m_TextDataTitle->SetLabel( _( "Text:" ) );
|
|
|
|
else if( m_CurrentTextMod->m_Type != TEXT_is_REFERENCE )
|
|
|
|
m_TextDataTitle->SetLabel( wxT( "???" ) );
|
|
|
|
|
|
|
|
m_Name->SetValue( m_CurrentTextMod->m_Text );
|
|
|
|
|
|
|
|
m_Style->SetSelection( m_CurrentTextMod->m_Italic ? 1 : 0 );
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_SizeXTitle );
|
|
|
|
PutValueInLocalUnits( *m_TxtSizeCtrlX, m_CurrentTextMod->m_Size.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_SizeYTitle );
|
|
|
|
PutValueInLocalUnits( *m_TxtSizeCtrlY, m_CurrentTextMod->m_Size.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_PosXTitle );
|
|
|
|
PutValueInLocalUnits( *m_TxtPosCtrlX, m_CurrentTextMod->m_Pos0.x,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_PosYTitle );
|
|
|
|
PutValueInLocalUnits( *m_TxtPosCtrlY, m_CurrentTextMod->m_Pos0.y,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
AddUnitSymbol( *m_WidthTitle );
|
|
|
|
PutValueInLocalUnits( *m_TxtWidthCtlr, m_CurrentTextMod->m_Width,
|
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
int text_orient = m_CurrentTextMod->m_Orient;
|
|
|
|
NORMALIZE_ANGLE_90(text_orient)
|
2008-12-22 21:06:44 +00:00
|
|
|
if( (text_orient != 0) )
|
|
|
|
m_Orient->SetSelection( 1 );
|
|
|
|
|
|
|
|
if( m_CurrentTextMod->m_NoShow )
|
|
|
|
m_Show->SetSelection( 1 );;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************/
|
|
|
|
void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
|
|
|
|
/*********************************************************************************/
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if ( m_Module)
|
|
|
|
m_Parent->SaveCopyInUndoList( m_Module, UR_CHANGED );
|
2008-12-22 21:06:44 +00:00
|
|
|
if( m_DC ) //Erase old text on screen
|
|
|
|
{
|
|
|
|
m_CurrentTextMod->Draw( m_Parent->DrawPanel, m_DC, GR_XOR,
|
|
|
|
(m_CurrentTextMod->m_Flags & IS_MOVED) ? MoveVector : wxPoint( 0, 0 ) );
|
|
|
|
}
|
|
|
|
m_CurrentTextMod->m_Text = m_Name->GetValue();
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
m_CurrentTextMod->m_Italic = m_Style->GetSelection() == 1 ? true : false;
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
msg = m_TxtPosCtrlX->GetValue();
|
2010-07-12 14:07:09 +00:00
|
|
|
m_CurrentTextMod->m_Pos0.x = ReturnValueFromString( g_UserUnit, msg,
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
msg = m_TxtPosCtrlY->GetValue();
|
2010-07-12 14:07:09 +00:00
|
|
|
m_CurrentTextMod->m_Pos0.y = ReturnValueFromString( g_UserUnit, msg,
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
msg = m_TxtSizeCtrlX->GetValue();
|
2010-07-12 14:07:09 +00:00
|
|
|
m_CurrentTextMod->m_Size.x = ReturnValueFromString( g_UserUnit, msg,
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
msg = m_TxtSizeCtrlY->GetValue();
|
2010-07-12 14:07:09 +00:00
|
|
|
m_CurrentTextMod->m_Size.y = ReturnValueFromString( g_UserUnit, msg,
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
|
|
|
// Test for a reasonnable size:
|
|
|
|
if( m_CurrentTextMod->m_Size.x< TEXTS_MIN_SIZE )
|
|
|
|
m_CurrentTextMod->m_Size.x = TEXTS_MIN_SIZE;
|
|
|
|
if( m_CurrentTextMod->m_Size.y< TEXTS_MIN_SIZE )
|
|
|
|
m_CurrentTextMod->m_Size.y = TEXTS_MIN_SIZE;
|
|
|
|
|
|
|
|
msg = m_TxtWidthCtlr->GetValue();
|
2010-07-12 14:07:09 +00:00
|
|
|
int width = ReturnValueFromString( g_UserUnit, msg, m_Parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
// Test for a reasonnable width:
|
|
|
|
if( width <= 1 )
|
|
|
|
width = 1;
|
2009-05-30 16:06:01 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize(width, m_CurrentTextMod->m_Size );
|
|
|
|
if( width > maxthickness )
|
|
|
|
{
|
2009-08-19 14:19:35 +00:00
|
|
|
DisplayError(NULL, _("The text thickness is too large for the text size. It will be clamped"));
|
2009-05-30 16:06:01 +00:00
|
|
|
width = maxthickness;
|
|
|
|
}
|
2008-12-22 21:06:44 +00:00
|
|
|
m_CurrentTextMod->SetWidth( width );
|
|
|
|
|
|
|
|
m_CurrentTextMod->m_NoShow = (m_Show->GetSelection() == 0) ? 0 : 1;
|
2009-01-05 05:21:35 +00:00
|
|
|
int text_orient = (m_Orient->GetSelection() == 0) ? 0 : 900;
|
2008-12-22 21:06:44 +00:00
|
|
|
m_CurrentTextMod->m_Orient = text_orient;
|
|
|
|
|
|
|
|
m_CurrentTextMod->SetDrawCoord();
|
|
|
|
if( m_DC ) // Display new text
|
|
|
|
{
|
|
|
|
m_CurrentTextMod->Draw( m_Parent->DrawPanel, m_DC, GR_XOR,
|
|
|
|
(m_CurrentTextMod->m_Flags & IS_MOVED) ? MoveVector : wxPoint( 0, 0 ) );
|
|
|
|
}
|
2010-02-19 13:23:58 +00:00
|
|
|
m_Parent->OnModify();
|
2009-08-11 10:27:21 +00:00
|
|
|
if( m_Module )
|
|
|
|
m_Module->m_LastEdit_Time = time( NULL );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2009-08-19 14:19:35 +00:00
|
|
|
EndModal(1);
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|