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"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "gr_basic.h"
|
2008-12-22 21:06:44 +00:00
|
|
|
#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"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "wxBasePcbFrame.h"
|
|
|
|
|
|
|
|
#include "class_module.h"
|
|
|
|
#include "class_text_mod.h"
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
#include "dialog_edit_module_text_base.h"
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
extern wxPoint MoveVector; // Move vector for move edge, imported from edtxtmod.cpp
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
/*************** **************/
|
|
|
|
/* class DialogEditModuleText */
|
|
|
|
/*************** **************/
|
|
|
|
class DialogEditModuleText : public DialogEditModuleText_base
|
|
|
|
{
|
|
|
|
private:
|
2011-10-18 17:28:49 +00:00
|
|
|
PCB_BASE_FRAME* m_parent;
|
|
|
|
wxDC* m_dc;
|
|
|
|
MODULE* m_module;
|
|
|
|
TEXTE_MODULE* m_currentText;
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
public:
|
2011-10-18 17:28:49 +00:00
|
|
|
DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC );
|
2009-01-05 05:21:35 +00:00
|
|
|
~DialogEditModuleText() {};
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
private:
|
2011-10-18 17:28:49 +00:00
|
|
|
void initDlg( );
|
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
|
|
|
/*************************************************************************************/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC )
|
2009-08-11 10:27:21 +00:00
|
|
|
/**************************************************************************************/
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent,
|
|
|
|
TEXTE_MODULE* aTextMod, wxDC* aDC ) :
|
|
|
|
DialogEditModuleText_base( aParent )
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
{
|
2011-10-18 17:28:49 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_dc = aDC;
|
|
|
|
m_module = NULL;
|
|
|
|
m_currentText = aTextMod;
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
if( m_currentText )
|
|
|
|
m_module = (MODULE*) m_currentText->GetParent();
|
2011-03-14 15:17:18 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
initDlg( );
|
2009-08-19 14:19:35 +00:00
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
m_buttonOK->SetDefault();
|
2009-08-19 14:19:35 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2011-10-18 17:28:49 +00:00
|
|
|
|
|
|
|
Centre();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
2011-10-18 17:28:49 +00:00
|
|
|
void DialogEditModuleText::initDlg( )
|
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;
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
if( m_module )
|
2008-12-22 21:06:44 +00:00
|
|
|
{
|
|
|
|
wxString format = m_ModuleInfoText->GetLabel();
|
|
|
|
msg.Printf( format,
|
2011-10-18 17:28:49 +00:00
|
|
|
GetChars( m_module->m_Reference->m_Text ),
|
|
|
|
GetChars( m_module->m_Value->m_Text ),
|
|
|
|
(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 );
|
|
|
|
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
if( m_currentText->m_Type == TEXT_is_VALUE )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_TextDataTitle->SetLabel( _( "Value:" ) );
|
2011-10-18 17:28:49 +00:00
|
|
|
else if( m_currentText->m_Type == TEXT_is_DIVERS )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_TextDataTitle->SetLabel( _( "Text:" ) );
|
2011-10-18 17:28:49 +00:00
|
|
|
else if( m_currentText->m_Type != TEXT_is_REFERENCE )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_TextDataTitle->SetLabel( wxT( "???" ) );
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
m_Name->SetValue( m_currentText->m_Text );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
m_Style->SetSelection( m_currentText->m_Italic ? 1 : 0 );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
AddUnitSymbol( *m_SizeXTitle );
|
2011-10-18 17:28:49 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->m_Size.x,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
AddUnitSymbol( *m_SizeYTitle );
|
2011-10-18 17:28:49 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->m_Size.y,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
AddUnitSymbol( *m_PosXTitle );
|
2011-10-18 17:28:49 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->m_Pos0.x,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
AddUnitSymbol( *m_PosYTitle );
|
2011-10-18 17:28:49 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->m_Pos0.y,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
AddUnitSymbol( *m_WidthTitle );
|
2011-10-18 17:28:49 +00:00
|
|
|
PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->m_Thickness,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
int text_orient = m_currentText->m_Orient;
|
2009-01-05 05:21:35 +00:00
|
|
|
NORMALIZE_ANGLE_90(text_orient)
|
2008-12-22 21:06:44 +00:00
|
|
|
if( (text_orient != 0) )
|
|
|
|
m_Orient->SetSelection( 1 );
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
if( m_currentText->m_NoShow )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Show->SetSelection( 1 );;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************/
|
|
|
|
void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
|
|
|
|
/*********************************************************************************/
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
if ( m_module)
|
|
|
|
m_parent->SaveCopyInUndoList( m_module, UR_CHANGED );
|
|
|
|
if( m_dc ) //Erase old text on screen
|
2008-12-22 21:06:44 +00:00
|
|
|
{
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->Draw( m_parent->DrawPanel, m_dc, GR_XOR,
|
|
|
|
(m_currentText->m_Flags & IS_MOVED) ? MoveVector : wxPoint( 0, 0 ) );
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Text = m_Name->GetValue();
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Italic = m_Style->GetSelection() == 1 ? true : false;
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
msg = m_TxtPosCtrlX->GetValue();
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Pos0.x = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
msg = m_TxtPosCtrlY->GetValue();
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Pos0.y = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
msg = m_TxtSizeCtrlX->GetValue();
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Size.x = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
msg = m_TxtSizeCtrlY->GetValue();
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Size.y = ReturnValueFromString( g_UserUnit, msg,
|
|
|
|
m_parent->m_InternalUnits );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
// Test for a reasonnable size:
|
2011-10-18 17:28:49 +00:00
|
|
|
if( m_currentText->m_Size.x< TEXTS_MIN_SIZE )
|
|
|
|
m_currentText->m_Size.x = TEXTS_MIN_SIZE;
|
|
|
|
if( m_currentText->m_Size.y< TEXTS_MIN_SIZE )
|
|
|
|
m_currentText->m_Size.y = TEXTS_MIN_SIZE;
|
2008-12-22 21:06:44 +00:00
|
|
|
|
|
|
|
msg = m_TxtWidthCtlr->GetValue();
|
2011-10-18 17:28:49 +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;
|
2011-10-18 17:28:49 +00:00
|
|
|
int maxthickness = Clamp_Text_PenSize(width, m_currentText->m_Size );
|
2009-05-30 16:06:01 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->SetThickness( width );
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->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;
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->m_Orient = text_orient;
|
2008-12-22 21:06:44 +00:00
|
|
|
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->SetDrawCoord();
|
|
|
|
if( m_dc ) // Display new text
|
2008-12-22 21:06:44 +00:00
|
|
|
{
|
2011-10-18 17:28:49 +00:00
|
|
|
m_currentText->Draw( m_parent->DrawPanel, m_dc, GR_XOR,
|
|
|
|
(m_currentText->m_Flags & IS_MOVED) ? MoveVector : wxPoint( 0, 0 ) );
|
2008-12-22 21:06:44 +00:00
|
|
|
}
|
2011-10-18 17:28:49 +00:00
|
|
|
m_parent->OnModify();
|
|
|
|
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
|
|
|
}
|