2008-12-20 17:28:25 +00:00
|
|
|
/*********************************************************/
|
|
|
|
/* class TEXTE_PCB : texts on copper or technical layers */
|
|
|
|
/*********************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "gr_basic.h"
|
2009-05-30 16:06:01 +00:00
|
|
|
#include "base_struct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
2009-05-30 16:06:01 +00:00
|
|
|
#include "drawtxt.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "kicad_string.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2009-08-01 19:26:05 +00:00
|
|
|
#include "trigo.h"
|
|
|
|
#include "protos.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
/*******************/
|
|
|
|
/* class TEXTE_PCB */
|
|
|
|
/*******************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
TEXTE_PCB::TEXTE_PCB( BOARD_ITEM* parent ) :
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_ITEM( parent, TYPE_TEXTE ),
|
2007-08-07 06:21:19 +00:00
|
|
|
EDA_TextStruct()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-05 17:32:07 +00:00
|
|
|
m_MultilineAllowed = true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
TEXTE_PCB:: ~TEXTE_PCB()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
|
|
|
void TEXTE_PCB::Copy( TEXTE_PCB* source )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-07 06:21:19 +00:00
|
|
|
m_Parent = source->m_Parent;
|
|
|
|
Pback = Pnext = NULL;
|
2008-12-20 20:38:39 +00:00
|
|
|
m_Mirror = source->m_Mirror;
|
2007-08-07 06:21:19 +00:00
|
|
|
m_Size = source->m_Size;
|
|
|
|
m_Orient = source->m_Orient;
|
|
|
|
m_Pos = source->m_Pos;
|
|
|
|
m_Layer = source->m_Layer;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = source->m_Thickness;
|
2007-08-07 06:21:19 +00:00
|
|
|
m_Attributs = source->m_Attributs;
|
2008-12-20 17:28:25 +00:00
|
|
|
m_Italic = source->m_Italic;
|
2009-05-30 16:06:01 +00:00
|
|
|
m_Bold = source->m_Bold;
|
2007-08-07 06:21:19 +00:00
|
|
|
m_HJustify = source->m_HJustify;
|
|
|
|
m_VJustify = source->m_VJustify;
|
2009-05-05 17:32:07 +00:00
|
|
|
m_MultilineAllowed = m_MultilineAllowed;
|
2007-08-07 06:21:19 +00:00
|
|
|
|
|
|
|
m_Text = source->m_Text;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ReadTextePcbDescr
|
2009-11-12 15:43:38 +00:00
|
|
|
* Read a text description from pcb file.
|
|
|
|
*
|
|
|
|
* For a single line text:
|
|
|
|
*
|
|
|
|
* $TEXTPCB
|
|
|
|
* Te "Text example"
|
|
|
|
* Po 66750 53450 600 800 150 0
|
|
|
|
* From 24 1 0 Italic
|
|
|
|
* $EndTEXTPCB
|
2009-05-01 16:46:56 +00:00
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* For a multi line text
|
2009-05-01 16:46:56 +00:00
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* $TEXTPCB
|
|
|
|
* Te "Text example"
|
|
|
|
* Nl "Line 2"
|
|
|
|
* Po 66750 53450 600 800 150 0
|
|
|
|
* From 24 1 0 Italic
|
|
|
|
* $EndTEXTPCB
|
|
|
|
* Nl "line nn" is a line added to the current text
|
2009-05-01 16:46:56 +00:00
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-27 05:43:19 +00:00
|
|
|
char* line;
|
2011-01-14 17:43:30 +00:00
|
|
|
char text[1024];
|
|
|
|
char style[256];
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( aReader->ReadLine() )
|
2007-08-07 06:21:19 +00:00
|
|
|
{
|
2011-02-27 05:43:19 +00:00
|
|
|
line = aReader->Line();
|
|
|
|
if( strnicmp( line, "$EndTEXTPCB", 11 ) == 0 )
|
2007-08-07 06:21:19 +00:00
|
|
|
return 0;
|
2011-02-27 05:43:19 +00:00
|
|
|
if( strncmp( line, "Te", 2 ) == 0 ) /* Text line (first line for multi line texts */
|
2007-08-07 06:21:19 +00:00
|
|
|
{
|
2011-02-27 05:43:19 +00:00
|
|
|
ReadDelimitedText( text, line + 2, sizeof(text) );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Text = FROM_UTF8( text );
|
2007-08-07 06:21:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-02-27 05:43:19 +00:00
|
|
|
if( strncmp( line, "nl", 2 ) == 0 ) /* next line of the current text */
|
2009-05-01 16:46:56 +00:00
|
|
|
{
|
2011-02-27 05:43:19 +00:00
|
|
|
ReadDelimitedText( text, line + 2, sizeof(text) );
|
2009-05-01 16:46:56 +00:00
|
|
|
m_Text.Append( '\n' );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Text += FROM_UTF8( text );
|
2009-05-01 16:46:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-02-27 05:43:19 +00:00
|
|
|
if( strncmp( line, "Po", 2 ) == 0 )
|
2007-08-07 06:21:19 +00:00
|
|
|
{
|
2011-02-27 05:43:19 +00:00
|
|
|
sscanf( line + 2, " %d %d %d %d %d %d",
|
2007-08-07 06:21:19 +00:00
|
|
|
&m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y,
|
2010-11-27 13:09:18 +00:00
|
|
|
&m_Thickness, &m_Orient );
|
2009-05-01 16:46:56 +00:00
|
|
|
|
2008-03-24 20:54:45 +00:00
|
|
|
// Ensure the text has minimal size to see this text on screen:
|
2009-05-01 16:46:56 +00:00
|
|
|
if( m_Size.x < 5 )
|
|
|
|
m_Size.x = 5;
|
|
|
|
if( m_Size.y < 5 )
|
|
|
|
m_Size.y = 5;
|
2007-08-07 06:21:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-02-27 05:43:19 +00:00
|
|
|
if( strncmp( line, "De", 2 ) == 0 )
|
2007-08-07 06:21:19 +00:00
|
|
|
{
|
2009-05-01 16:46:56 +00:00
|
|
|
style[0] = 0;
|
|
|
|
int normal_display = 1;
|
2011-02-27 05:43:19 +00:00
|
|
|
sscanf( line + 2, " %d %d %lX %s\n", &m_Layer, &normal_display,
|
2008-12-20 17:28:25 +00:00
|
|
|
&m_TimeStamp, style );
|
2008-12-20 20:38:39 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
m_Mirror = normal_display ? false : true;
|
2008-12-20 20:38:39 +00:00
|
|
|
|
2007-11-01 05:27:31 +00:00
|
|
|
if( m_Layer < FIRST_COPPER_LAYER )
|
|
|
|
m_Layer = FIRST_COPPER_LAYER;
|
2007-08-07 06:21:19 +00:00
|
|
|
if( m_Layer > LAST_NO_COPPER_LAYER )
|
|
|
|
m_Layer = LAST_NO_COPPER_LAYER;
|
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
if( strnicmp( style, "Italic", 6 ) == 0 )
|
|
|
|
m_Italic = 1;
|
|
|
|
else
|
|
|
|
m_Italic = 0;
|
2007-08-07 06:21:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Set a reasonable width:
|
2010-11-27 13:09:18 +00:00
|
|
|
if( m_Thickness < 1 )
|
|
|
|
m_Thickness = 1;
|
|
|
|
m_Thickness = Clamp_Text_PenSize( m_Thickness, m_Size );
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
bool TEXTE_PCB::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
if( m_Text.IsEmpty() )
|
|
|
|
return true;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
if( fprintf( aFile, "$TEXTPCB\n" ) != sizeof("$TEXTPCB\n") - 1 )
|
|
|
|
return false;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
const char* style = m_Italic ? "Italic" : "Normal";
|
|
|
|
|
|
|
|
wxArrayString* list = wxStringSplit( m_Text, '\n' );
|
2011-02-27 05:43:19 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
for( unsigned ii = 0; ii < list->Count(); ii++ )
|
|
|
|
{
|
|
|
|
wxString txt = list->Item( ii );
|
2011-02-27 05:43:19 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
if ( ii == 0 )
|
2011-02-27 05:43:19 +00:00
|
|
|
fprintf( aFile, "Te \"%s\"\n", EscapedUTF8( txt ).c_str() );
|
2009-05-01 16:46:56 +00:00
|
|
|
else
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "nl \"%s\"\n", TO_UTF8( txt ) );
|
2009-05-01 16:46:56 +00:00
|
|
|
}
|
2011-02-27 05:43:19 +00:00
|
|
|
|
|
|
|
delete list;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "Po %d %d %d %d %d %d\n",
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_Size.x, m_Size.y, m_Thickness, m_Orient );
|
2011-02-27 05:43:19 +00:00
|
|
|
|
2008-12-20 20:38:39 +00:00
|
|
|
fprintf( aFile, "De %d %d %lX %s\n", m_Layer,
|
2009-05-01 16:46:56 +00:00
|
|
|
m_Mirror ? 0 : 1,
|
|
|
|
m_TimeStamp, style );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
if( fprintf( aFile, "$EndTEXTPCB\n" ) != sizeof("$EndTEXTPCB\n") - 1 )
|
|
|
|
return false;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
return true;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
/*
|
2010-11-12 16:36:43 +00:00
|
|
|
* Function Draw
|
2009-05-12 13:38:47 +00:00
|
|
|
* Like tracks, texts are drawn in filled or sketch mode, never in line mode
|
|
|
|
* because the line mode does not keep the actual size of the text
|
|
|
|
* and the actual size is very important, especially for copper texts
|
2007-08-07 06:21:19 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
2009-11-12 15:43:38 +00:00
|
|
|
int DrawMode, const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD * brd = GetBoard( );
|
|
|
|
|
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-07 06:21:19 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
int color = brd->GetLayerColor(m_Layer);
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
GRTraceMode fillmode = FILLED;
|
2009-05-12 13:38:47 +00:00
|
|
|
if ( DisplayOpt.DisplayDrawItems == SKETCH)
|
2009-05-12 13:46:43 +00:00
|
|
|
fillmode = SKETCH;
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
int anchor_color = UNSPECIFIED_COLOR;
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
|
|
|
|
anchor_color = brd->GetVisibleElementColor(ANCHOR_VISIBLE);
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
EDA_TextStruct::Draw( panel, DC, offset, (EDA_Colors) color,
|
2010-01-29 20:36:12 +00:00
|
|
|
DrawMode, fillmode, (EDA_Colors) anchor_color );
|
2007-08-07 06:21:19 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
// see class_pcb_text.h
|
2011-01-21 19:30:59 +00:00
|
|
|
void TEXTE_PCB::DisplayInfo( EDA_DRAW_FRAME* frame )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-05-01 16:46:56 +00:00
|
|
|
wxString msg;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-11 05:41:33 +00:00
|
|
|
BOARD* board;
|
|
|
|
BOARD_ITEM* parent = (BOARD_ITEM*) m_Parent;
|
2009-05-01 16:46:56 +00:00
|
|
|
|
2008-03-11 05:41:33 +00:00
|
|
|
wxASSERT( parent );
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
if( parent->Type() == TYPE_DIMENSION )
|
2008-11-24 06:53:43 +00:00
|
|
|
board = (BOARD*) parent->GetParent();
|
2008-03-11 05:41:33 +00:00
|
|
|
else
|
|
|
|
board = (BOARD*) parent;
|
2008-03-04 04:22:27 +00:00
|
|
|
wxASSERT( board );
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->ClearMsgPanel();
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
if( m_Parent && m_Parent->Type() == TYPE_DIMENSION )
|
|
|
|
frame->AppendMsgPanel( _( "DIMENSION" ), m_Text, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "PCB Text" ), m_Text, DARKGREEN );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Layer" ),
|
2009-10-11 13:04:47 +00:00
|
|
|
board->GetLayerName( m_Layer ), BLUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
if( !m_Mirror )
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Mirror" ), _( "No" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Mirror" ), _( "Yes" ), DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Orient" ), msg, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
valeur_param( m_Thickness, msg );
|
|
|
|
frame->AppendMsgPanel( _( "Thickness" ), msg, MAGENTA );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
valeur_param( m_Size.x, msg );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "H Size" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
valeur_param( m_Size.y, msg );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "V Size" ), msg, RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Rotate
|
|
|
|
* Rotate this object.
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aRotCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
* @param aAngle - the rotation angle in 0.1 degree.
|
|
|
|
*/
|
|
|
|
void TEXTE_PCB::Rotate(const wxPoint& aRotCentre, int aAngle)
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, aRotCentre, aAngle );
|
|
|
|
m_Orient += aAngle;
|
|
|
|
while( m_Orient >= 3600 )
|
|
|
|
m_Orient -= 3600;
|
|
|
|
while( m_Orient < -3600 )
|
|
|
|
m_Orient += 3600;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Flip
|
|
|
|
* Flip this object, i.e. change the board side for this object
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
|
|
|
void TEXTE_PCB::Flip(const wxPoint& aCentre )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
|
2009-08-01 19:26:05 +00:00
|
|
|
NEGATE( m_Orient );
|
2009-12-07 03:46:13 +00:00
|
|
|
if( ( GetLayer() == LAYER_N_BACK ) || ( GetLayer() == LAYER_N_FRONT ) )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Mirror = not m_Mirror; /* inverse mirror */
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
SetLayer( ChangeSideNumLayer( GetLayer() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2008-03-04 04:22:27 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2007-08-07 06:21:19 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void TEXTE_PCB::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
|
|
|
// for now, make it look like XML:
|
2007-08-08 03:50:44 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2009-05-01 16:46:56 +00:00
|
|
|
" string=\"" << m_Text.mb_str() << "\"/>\n";
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str()
|
|
|
|
// << ">\n";
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
#endif
|