kicad/pcbnew/pcbtexte.cpp

406 lines
13 KiB
C++
Raw Normal View History

/**************************************************/
/* traitement des editions des textes sur modules */
/**************************************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "protos.h"
#define L_MIN_DESSIN 1 /* seuil de largeur des segments pour trace autre que filaire */
/* Routines Locales */
static void Move_Texte_Pcb( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void Exit_Texte_Pcb( WinEDA_DrawPanel* Panel, wxDC* DC );
2007-05-06 16:03:28 +00:00
/* Variables locales : */
static wxPoint old_pos; // position originelle du texte selecte
2007-05-06 16:03:28 +00:00
enum id_TextPCB_properties {
ID_ACCEPT_TEXTE_PCB_PROPERTIES = 1900,
ID_CLOSE_TEXTE_PCB_PROPERTIES,
ID_TEXTPCB_SELECT_LAYER
2007-05-06 16:03:28 +00:00
};
/************************************/
/* class WinEDA_TextPCBPropertiesFrame */
/************************************/
2007-05-06 16:03:28 +00:00
class WinEDA_TextPCBPropertiesFrame : public wxDialog
2007-05-06 16:03:28 +00:00
{
private:
WinEDA_PcbFrame* m_Parent;
wxDC* m_DC;
TEXTE_PCB* CurrentTextPCB;
WinEDA_EnterText* m_Name;
WinEDA_PositionCtrl* m_TxtPosCtrl;
WinEDA_SizeCtrl* m_TxtSizeCtrl;
WinEDA_ValueCtrl* m_TxtWidthCtlr;
wxRadioBox* m_Orient;
wxRadioBox* m_Mirror;
WinEDAChoiceBox* m_SelLayerBox;
2007-05-06 16:03:28 +00:00
public:
// Constructor and destructor
WinEDA_TextPCBPropertiesFrame( WinEDA_PcbFrame* parent,
TEXTE_PCB* TextPCB, wxDC* DC, const wxPoint& pos );
2007-09-01 12:00:30 +00:00
~WinEDA_TextPCBPropertiesFrame()
{
}
2007-05-06 16:03:28 +00:00
private:
void TextPCBPropertiesAccept( wxCommandEvent& event );
void OnQuit( wxCommandEvent& event );
2007-05-06 16:03:28 +00:00
DECLARE_EVENT_TABLE()
2007-05-06 16:03:28 +00:00
};
BEGIN_EVENT_TABLE( WinEDA_TextPCBPropertiesFrame, wxDialog )
EVT_BUTTON( ID_ACCEPT_TEXTE_PCB_PROPERTIES,
WinEDA_TextPCBPropertiesFrame::TextPCBPropertiesAccept )
EVT_BUTTON( ID_CLOSE_TEXTE_PCB_PROPERTIES,
WinEDA_TextPCBPropertiesFrame::OnQuit )
2007-05-06 16:03:28 +00:00
END_EVENT_TABLE()
/********************************************************************/
void WinEDA_PcbFrame::InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB,
wxDC* DC, const wxPoint& pos )
2007-05-06 16:03:28 +00:00
/********************************************************************/
{
DrawPanel->m_IgnoreMouseEvents = TRUE;
WinEDA_TextPCBPropertiesFrame* frame = new WinEDA_TextPCBPropertiesFrame( this,
TextPCB, DC, pos );
frame->ShowModal(); frame->Destroy();
DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = FALSE;
2007-05-06 16:03:28 +00:00
}
/************************************************************************************/
WinEDA_TextPCBPropertiesFrame::WinEDA_TextPCBPropertiesFrame( WinEDA_PcbFrame* parent,
TEXTE_PCB* TextPCB, wxDC* DC,
const wxPoint& framepos ) :
wxDialog( parent, -1, _( "TextPCB properties" ), framepos, wxSize( 390, 340 ),
DIALOG_STYLE )
2007-05-06 16:03:28 +00:00
/************************************************************************************/
{
wxButton* Button;
m_Parent = parent;
SetFont( *g_DialogFont );
m_DC = DC;
Centre();
CurrentTextPCB = TextPCB;
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( MainBoxSizer );
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* MiddleBoxSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
MainBoxSizer->Add( MiddleBoxSizer, 0, wxGROW | wxALL, 5 );
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
/* Creation des boutons de commande */
Button = new wxButton( this, ID_ACCEPT_TEXTE_PCB_PROPERTIES, _( "Ok" ) );
Button->SetForegroundColour( *wxRED );
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
Button->SetDefault();
Button = new wxButton( this, ID_CLOSE_TEXTE_PCB_PROPERTIES, _( "Cancel" ) );
Button->SetForegroundColour( *wxBLUE );
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
m_Name = new WinEDA_EnterText( this, _( "Text:" ),
TextPCB->m_Text,
LeftBoxSizer, wxSize( 200, -1 ) );
2007-05-06 16:03:28 +00:00
m_Name->SetFocus();
m_Name->SetSelection( -1, -1 );
m_TxtSizeCtrl = new WinEDA_SizeCtrl( this, _( "Size" ),
TextPCB->m_Size,
g_UnitMetric, LeftBoxSizer, m_Parent->m_InternalUnits );
m_TxtWidthCtlr = new WinEDA_ValueCtrl( this, _( "Width" ),
TextPCB->m_Width,
g_UnitMetric, LeftBoxSizer, m_Parent->m_InternalUnits );
m_TxtPosCtrl = new WinEDA_PositionCtrl( this, _( "Position" ),
TextPCB->m_Pos,
g_UnitMetric, LeftBoxSizer, m_Parent->m_InternalUnits );
m_SelLayerBox = new WinEDAChoiceBox( this, ID_TEXTPCB_SELECT_LAYER,
wxDefaultPosition, wxDefaultSize );
MiddleBoxSizer->Add( m_SelLayerBox, 0, wxGROW | wxALL, 5 );
int ii;
for( ii = 0; ii < 29; ii++ )
{
m_SelLayerBox->Append( ReturnPcbLayerName( ii ) );
}
2007-08-23 04:28:46 +00:00
m_SelLayerBox->SetSelection( TextPCB->GetLayer() );
wxString orient_msg[4] = { wxT( "0" ), wxT( "90" ), wxT( "180" ), wxT( "-90" ) };
m_Orient = new wxRadioBox( this, -1, _( "Orientation" ),
wxDefaultPosition, wxSize( -1, -1 ), 4, orient_msg,
1, wxRA_SPECIFY_COLS );
MiddleBoxSizer->Add( m_Orient, 0, wxGROW | wxALL, 5 );
switch( TextPCB->m_Orient )
{
default:
m_Orient->SetSelection( 0 );
break;
case 900:
m_Orient->SetSelection( 1 );
break;
case 1800:
m_Orient->SetSelection( 2 );
break;
case 2700:
m_Orient->SetSelection( 3 );
break;
}
wxString display_msg[2] = { _( "Normal" ), _( "Mirror" ) };
m_Mirror = new wxRadioBox( this, -1, _( "Display" ),
wxDefaultPosition, wxSize( -1, -1 ), 2, display_msg,
1, wxRA_SPECIFY_COLS );
if( !TextPCB->m_Miroir )
m_Mirror->SetSelection( 1 );;
MiddleBoxSizer->Add( m_Mirror, 0, wxGROW | wxALL, 5 );
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
2007-05-06 16:03:28 +00:00
}
/**********************************************************************/
void WinEDA_TextPCBPropertiesFrame::OnQuit( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
/**********************************************************************/
{
// true is to force the frame to close
Close( true );
2007-05-06 16:03:28 +00:00
}
/**************************************************************************************/
void WinEDA_TextPCBPropertiesFrame::TextPCBPropertiesAccept( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
/**************************************************************************************/
{
if( m_DC ) // Effacement ancien texte
{
CurrentTextPCB->Draw( m_Parent->DrawPanel, m_DC, wxPoint( 0, 0 ), GR_XOR );
}
if( !m_Name->GetValue().IsEmpty() )
{
CurrentTextPCB->m_Text = m_Name->GetValue();
}
CurrentTextPCB->m_Pos = m_TxtPosCtrl->GetValue();
CurrentTextPCB->m_Size = m_TxtSizeCtrl->GetValue();
CurrentTextPCB->m_Width = m_TxtWidthCtlr->GetValue();
CurrentTextPCB->m_Miroir = (m_Mirror->GetSelection() == 0) ? 1 : 0;
CurrentTextPCB->m_Orient = m_Orient->GetSelection() * 900;
2007-08-23 04:28:46 +00:00
CurrentTextPCB->SetLayer( m_SelLayerBox->GetChoice() );
CurrentTextPCB->CreateDrawData();
if( m_DC ) // Affichage nouveau texte
{
/* Redessin du Texte */
CurrentTextPCB->Draw( m_Parent->DrawPanel, m_DC, wxPoint( 0, 0 ), GR_OR );
}
m_Parent->m_CurrentScreen->SetModify();
Close( TRUE );
2007-05-06 16:03:28 +00:00
}
/******************************************************/
void Exit_Texte_Pcb( WinEDA_DrawPanel* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************************/
2007-05-06 16:03:28 +00:00
/*
* Routine de sortie du menu edit texte Pcb
* Si un texte est selectionne, ses coord initiales sont regenerees
*/
2007-05-06 16:03:28 +00:00
{
TEXTE_PCB* TextePcb;
2007-05-06 16:03:28 +00:00
TextePcb = (TEXTE_PCB*) Panel->GetScreen()->GetCurItem();
2007-05-06 16:03:28 +00:00
if( TextePcb )
{
TextePcb->Draw( Panel, DC, wxPoint( 0, 0 ), GR_XOR );
TextePcb->m_Pos = old_pos;
TextePcb->Draw( Panel, DC, wxPoint( 0, 0 ), GR_OR );
TextePcb->m_Flags = 0;
}
2007-05-06 16:03:28 +00:00
Panel->ManageCurseur = NULL;
Panel->ForceCloseManageCurseur = NULL;
Panel->GetScreen()->SetCurItem( NULL );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*********************************************************************/
void WinEDA_PcbFrame::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
/*********************************************************************/
2007-05-06 16:03:28 +00:00
/*
* Routine de placement du texte en cours de deplacement
*/
2007-05-06 16:03:28 +00:00
{
if( TextePcb == NULL )
return;
TextePcb->CreateDrawData();
TextePcb->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
m_CurrentScreen->SetCurItem( NULL );
m_CurrentScreen->SetModify();
TextePcb->m_Flags = 0;
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/***********************************************************************/
void WinEDA_PcbFrame::StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
/***********************************************************************/
/* Routine de preparation du deplacement d'un texte
*/
2007-05-06 16:03:28 +00:00
{
if( TextePcb == NULL )
return;
old_pos = TextePcb->m_Pos;
TextePcb->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
TextePcb->m_Flags |= IS_MOVED;
TextePcb->Display_Infos( this );
DrawPanel->ManageCurseur = Move_Texte_Pcb;
DrawPanel->ForceCloseManageCurseur = Exit_Texte_Pcb;
m_CurrentScreen->SetCurItem( TextePcb );
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*************************************************************************/
static void Move_Texte_Pcb( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
2007-05-06 16:03:28 +00:00
/*************************************************************************/
/* Routine deplacant le texte PCB suivant le curseur de la souris */
{
TEXTE_PCB* TextePcb = (TEXTE_PCB*)
panel->m_Parent->m_CurrentScreen->GetCurItem();
2007-05-06 16:03:28 +00:00
if( TextePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
/* effacement du texte : */
2007-05-06 16:03:28 +00:00
if( erase )
TextePcb->Draw( panel, DC, wxPoint( 0, 0 ), GR_XOR );
2007-05-06 16:03:28 +00:00
TextePcb->m_Pos = panel->m_Parent->m_CurrentScreen->m_Curseur;
2007-05-06 16:03:28 +00:00
/* Redessin du Texte */
TextePcb->Draw( panel, DC, wxPoint( 0, 0 ), GR_XOR );
2007-05-06 16:03:28 +00:00
}
/**********************************************************************/
void WinEDA_PcbFrame::Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
/**********************************************************************/
{
if( TextePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
TextePcb->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
2007-05-06 16:03:28 +00:00
/* Suppression du texte en Memoire*/
DeleteStructure( TextePcb );
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
m_CurrentScreen->SetCurItem( NULL );
2007-05-06 16:03:28 +00:00
}
/*******************************************************/
TEXTE_PCB* WinEDA_PcbFrame::Create_Texte_Pcb( wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************************/
{
TEXTE_PCB* TextePcb;
TextePcb = new TEXTE_PCB( m_Pcb );
/* Chainage de la nouvelle structure en debut de liste */
TextePcb->Pnext = m_Pcb->m_Drawings;
TextePcb->Pback = (EDA_BaseStruct*) m_Pcb;
if( m_Pcb->m_Drawings )
m_Pcb->m_Drawings->Pback = (EDA_BaseStruct*) TextePcb;
2007-08-23 04:28:46 +00:00
m_Pcb->m_Drawings = TextePcb;
/* Mise a jour des caracteristiques */
TextePcb->m_Flags = IS_NEW;
2007-08-23 04:28:46 +00:00
TextePcb->SetLayer( GetScreen()->m_Active_Layer );
TextePcb->m_Miroir = 1;
2007-08-23 04:28:46 +00:00
if( TextePcb->GetLayer() == CUIVRE_N )
TextePcb->m_Miroir = 0;
TextePcb->m_Size = g_DesignSettings.m_PcbTextSize;
TextePcb->m_Pos = m_CurrentScreen->m_Curseur;
TextePcb->m_Width = g_DesignSettings.m_PcbTextWidth;
InstallTextPCBOptionsFrame( TextePcb, DC, TextePcb->m_Pos );
if( TextePcb->m_Text.IsEmpty() )
{
DeleteStructure( TextePcb );
TextePcb = NULL;
}
else
StartMoveTextePcb( TextePcb, DC );
return TextePcb;
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/***********************************************************************/
void WinEDA_PcbFrame::Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2007-05-06 16:03:28 +00:00
/***********************************************************************/
{
int angle = 900;
int drawmode = GR_XOR;
2007-05-06 16:03:28 +00:00
if( TextePcb == NULL )
return;
2007-05-06 16:03:28 +00:00
/* effacement du texte : */
TextePcb->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
2007-05-06 16:03:28 +00:00
TextePcb->m_Orient += angle;
if( TextePcb->m_Orient >= 3600 )
TextePcb->m_Orient -= 3600;
if( TextePcb->m_Orient < 0 )
TextePcb->m_Orient += 3600;
2007-05-06 16:03:28 +00:00
TextePcb->CreateDrawData();
2007-05-06 16:03:28 +00:00
/* Redessin du Texte */
TextePcb->Draw( DrawPanel, DC, wxPoint( 0, 0 ), drawmode );
TextePcb->Display_Infos( this );
2007-05-06 16:03:28 +00:00
m_CurrentScreen->SetModify();
2007-05-06 16:03:28 +00:00
}