2009-11-12 15:43:38 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* class_module.cpp : TEXT_MODULE class implementation. */
|
|
|
|
/********************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "trigo.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "drawtxt.h"
|
|
|
|
#include "kicad_string.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "pcbcommon.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"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
/* Class TEXTE_MODULE base class type of text elements in a module */
|
|
|
|
/*******************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
TEXTE_MODULE::TEXTE_MODULE( MODULE* parent, int text_type ) :
|
2011-03-29 19:33:07 +00:00
|
|
|
BOARD_ITEM( parent, TYPE_TEXTE_MODULE ), EDA_TEXT()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
m_Type = text_type; /* Reference */
|
2007-08-04 20:05:54 +00:00
|
|
|
if( (m_Type != TEXT_is_REFERENCE) && (m_Type != TEXT_is_VALUE) )
|
|
|
|
m_Type = TEXT_is_DIVERS;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
m_NoShow = false;
|
|
|
|
m_Size.x = m_Size.y = 400;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = 120; /* Set default dimension to a reasonable value. */
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-12-21 17:56:25 +00:00
|
|
|
SetLayer( SILKSCREEN_N_FRONT );
|
2009-11-12 15:43:38 +00:00
|
|
|
if( Module && ( Module->Type() == TYPE_MODULE ) )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-08-09 08:05:42 +00:00
|
|
|
m_Pos = Module->m_Pos;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
int moduleLayer = Module->GetLayer();
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( moduleLayer == LAYER_N_BACK )
|
2009-12-21 17:56:25 +00:00
|
|
|
SetLayer( SILKSCREEN_N_BACK );
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( moduleLayer == LAYER_N_FRONT )
|
2009-12-21 17:56:25 +00:00
|
|
|
SetLayer( SILKSCREEN_N_FRONT );
|
2008-03-04 04:22:27 +00:00
|
|
|
else
|
2007-08-23 04:28:46 +00:00
|
|
|
SetLayer( moduleLayer );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-12-21 17:56:25 +00:00
|
|
|
if( moduleLayer == SILKSCREEN_N_BACK
|
|
|
|
|| moduleLayer == ADHESIVE_N_BACK
|
2009-12-07 03:46:13 +00:00
|
|
|
|| moduleLayer == LAYER_N_BACK )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Mirror = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
TEXTE_MODULE::~TEXTE_MODULE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
|
|
|
* writes the data structures for this object out to a FILE in "*.brd" format.
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
bool TEXTE_MODULE::Save( FILE* aFile ) const
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
MODULE* parent = (MODULE*) GetParent();
|
|
|
|
int orient = m_Orient;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Due to the pcbnew history, m_Orient is saved in screen value
|
|
|
|
// but it is handled as relative to its parent footprint
|
2007-10-30 21:30:58 +00:00
|
|
|
if( parent )
|
|
|
|
orient += parent->m_Orient;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-03-25 20:44:48 +00:00
|
|
|
int ret = fprintf( aFile, "T%d %d %d %d %d %d %d %c %c %d %c %s\n",
|
2009-11-23 21:03:26 +00:00
|
|
|
m_Type,
|
|
|
|
m_Pos0.x, m_Pos0.y,
|
|
|
|
m_Size.y, m_Size.x,
|
|
|
|
orient,
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness,
|
2009-11-23 21:03:26 +00:00
|
|
|
m_Mirror ? 'M' : 'N', m_NoShow ? 'I' : 'V',
|
|
|
|
GetLayer(),
|
|
|
|
m_Italic ? 'I' : 'N',
|
2011-03-25 20:07:27 +00:00
|
|
|
EscapedUTF8( m_Text ).c_str()
|
|
|
|
);
|
2008-08-09 08:05:42 +00:00
|
|
|
|
|
|
|
return ret > 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-12-29 17:47:32 +00:00
|
|
|
* Function ReadDescr
|
2008-08-09 08:05:42 +00:00
|
|
|
* Read description from a given line in "*.brd" format.
|
2011-02-22 16:43:03 +00:00
|
|
|
* @param aReader The line reader object which contains the first line of description.
|
2008-08-09 08:05:42 +00:00
|
|
|
* @return int - > 0 if success reading else 0.
|
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int TEXTE_MODULE::ReadDescr( LINE_READER* aReader )
|
2008-08-09 08:05:42 +00:00
|
|
|
{
|
2011-03-25 20:07:27 +00:00
|
|
|
int success = true;
|
|
|
|
int type;
|
|
|
|
char BufCar1[128], BufCar2[128], BufCar3[128];
|
|
|
|
char* line = aReader->Line();
|
2011-01-14 17:43:30 +00:00
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
int layer = SILKSCREEN_N_FRONT;
|
2008-08-09 08:05:42 +00:00
|
|
|
|
|
|
|
BufCar1[0] = 0;
|
|
|
|
BufCar2[0] = 0;
|
2008-12-22 21:06:44 +00:00
|
|
|
BufCar3[0] = 0;
|
2011-03-25 20:07:27 +00:00
|
|
|
|
|
|
|
if( sscanf( line + 1, "%d %d %d %d %d %d %d %s %s %d %s",
|
2009-11-23 21:03:26 +00:00
|
|
|
&type,
|
|
|
|
&m_Pos0.x, &m_Pos0.y,
|
|
|
|
&m_Size.y, &m_Size.x,
|
2010-11-27 13:09:18 +00:00
|
|
|
&m_Orient, &m_Thickness,
|
2009-11-23 21:03:26 +00:00
|
|
|
BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
|
2011-03-25 20:07:27 +00:00
|
|
|
{
|
2008-08-09 08:05:42 +00:00
|
|
|
success = true;
|
2011-03-25 20:07:27 +00:00
|
|
|
}
|
2008-08-09 08:05:42 +00:00
|
|
|
|
|
|
|
if( (type != TEXT_is_REFERENCE) && (type != TEXT_is_VALUE) )
|
|
|
|
type = TEXT_is_DIVERS;
|
2011-03-25 20:07:27 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
m_Type = type;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Due to the pcbnew history, .m_Orient is saved in screen value
|
|
|
|
// but it is handled as relative to its parent footprint
|
2009-11-23 21:03:26 +00:00
|
|
|
m_Orient -= ( (MODULE*) m_Parent )->m_Orient;
|
2011-03-25 20:07:27 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
if( BufCar1[0] == 'M' )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Mirror = true;
|
2008-08-09 08:05:42 +00:00
|
|
|
else
|
2008-12-22 21:06:44 +00:00
|
|
|
m_Mirror = false;
|
2011-03-25 20:07:27 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
if( BufCar2[0] == 'I' )
|
2008-12-22 21:06:44 +00:00
|
|
|
m_NoShow = true;
|
2008-08-09 08:05:42 +00:00
|
|
|
else
|
2008-12-22 21:06:44 +00:00
|
|
|
m_NoShow = false;
|
|
|
|
|
|
|
|
if( BufCar3[0] == 'I' )
|
|
|
|
m_Italic = true;
|
|
|
|
else
|
|
|
|
m_Italic = false;
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Test for a reasonable layer:
|
2008-08-09 08:05:42 +00:00
|
|
|
if( layer < 0 )
|
|
|
|
layer = 0;
|
|
|
|
if( layer > LAST_NO_COPPER_LAYER )
|
|
|
|
layer = LAST_NO_COPPER_LAYER;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( layer == LAYER_N_BACK )
|
2009-12-21 17:56:25 +00:00
|
|
|
layer = SILKSCREEN_N_BACK;
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( layer == LAYER_N_FRONT )
|
2009-12-21 17:56:25 +00:00
|
|
|
layer = SILKSCREEN_N_FRONT;
|
2008-08-09 08:05:42 +00:00
|
|
|
|
|
|
|
SetLayer( layer );
|
|
|
|
|
2011-03-25 20:44:48 +00:00
|
|
|
// Calculate the actual position.
|
2008-08-09 08:05:42 +00:00
|
|
|
SetDrawCoord();
|
2011-03-25 20:07:27 +00:00
|
|
|
|
|
|
|
|
2011-03-25 20:44:48 +00:00
|
|
|
// Search and read the "text" string (a quoted text).
|
2011-03-25 20:07:27 +00:00
|
|
|
ReadDelimitedText( &m_Text, line );
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Test for a reasonable size:
|
2008-08-09 08:05:42 +00:00
|
|
|
if( m_Size.x < TEXTS_MIN_SIZE )
|
|
|
|
m_Size.x = TEXTS_MIN_SIZE;
|
|
|
|
if( m_Size.y < TEXTS_MIN_SIZE )
|
|
|
|
m_Size.y = TEXTS_MIN_SIZE;
|
|
|
|
|
2009-11-23 21:03:26 +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
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
return success;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
void TEXTE_MODULE::Copy( TEXTE_MODULE* source )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
if( source == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
m_Pos = source->m_Pos;
|
2007-08-23 04:28:46 +00:00
|
|
|
SetLayer( source->GetLayer() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Mirror = source->m_Mirror;
|
|
|
|
m_NoShow = source->m_NoShow;
|
|
|
|
m_Type = source->m_Type;
|
|
|
|
m_Orient = source->m_Orient;
|
|
|
|
m_Pos0 = source->m_Pos0;
|
|
|
|
m_Size = source->m_Size;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = source->m_Thickness;
|
2009-05-30 16:06:01 +00:00
|
|
|
m_Italic = source->m_Italic;
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Bold = source->m_Bold;
|
|
|
|
m_Text = source->m_Text;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
int TEXTE_MODULE:: GetLength() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
return m_Text.Len();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Update draw coordinates
|
2007-09-01 12:00:30 +00:00
|
|
|
void TEXTE_MODULE:: SetDrawCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
m_Pos = m_Pos0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
int angle = Module->m_Orient;
|
|
|
|
NORMALIZE_ANGLE_POS( angle );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
RotatePoint( &m_Pos.x, &m_Pos.y, angle );
|
2009-08-11 10:27:21 +00:00
|
|
|
m_Pos += Module->m_Pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Update "local" coordinates (coordinates relatives to the footprint
|
|
|
|
// anchor point)
|
2007-09-01 12:00:30 +00:00
|
|
|
void TEXTE_MODULE:: SetLocalCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
if( Module == NULL )
|
2009-08-11 10:27:21 +00:00
|
|
|
{
|
|
|
|
m_Pos0 = m_Pos;
|
2007-08-04 20:05:54 +00:00
|
|
|
return;
|
2009-08-11 10:27:21 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
m_Pos0 = m_Pos - Module->m_Pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
int angle = Module->m_Orient;
|
|
|
|
NORMALIZE_ANGLE_POS( angle );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetTextRect
|
2011-03-29 19:33:07 +00:00
|
|
|
* @return an EDA_RECT which gives the position and size of the text area
|
2009-11-12 15:43:38 +00:00
|
|
|
* (for the footprint orientation)
|
2008-03-13 21:18:05 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT TEXTE_MODULE::GetTextRect( void ) const
|
2008-03-13 21:18:05 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
int dx, dy;
|
|
|
|
|
|
|
|
dx = ( m_Size.x * GetLength() ) / 2;
|
|
|
|
dx = (dx * 10) / 9; /* letter size = 10/9 */
|
2010-11-27 13:09:18 +00:00
|
|
|
dx += m_Thickness / 2;
|
|
|
|
dy = ( m_Size.y + m_Thickness ) / 2;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
wxPoint Org = m_Pos; // This is the position of the center of the area
|
2008-04-01 05:21:50 +00:00
|
|
|
Org.x -= dx;
|
|
|
|
Org.y -= dy;
|
2008-08-09 08:05:42 +00:00
|
|
|
area.SetOrigin( Org );
|
|
|
|
area.SetHeight( 2 * dy );
|
|
|
|
area.SetWidth( 2 * dx );
|
2008-04-01 05:21:50 +00:00
|
|
|
area.Normalize();
|
|
|
|
|
|
|
|
return area;
|
2008-03-13 21:18:05 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aRefPos A wxPoint to test
|
2010-12-28 11:24:42 +00:00
|
|
|
* @return true if a hit, else false
|
2008-03-15 10:24:32 +00:00
|
|
|
*/
|
2010-12-29 17:47:32 +00:00
|
|
|
bool TEXTE_MODULE::HitTest( const wxPoint& aRefPos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-08-09 08:05:42 +00:00
|
|
|
wxPoint rel_pos;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area = GetTextRect();
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
/* Rotate refPos to - angle
|
2009-11-12 15:43:38 +00:00
|
|
|
* to test if refPos is within area (which is relative to an horizontal
|
|
|
|
* text)
|
2008-08-09 08:05:42 +00:00
|
|
|
*/
|
2010-12-29 17:47:32 +00:00
|
|
|
rel_pos = aRefPos;
|
2008-08-09 08:05:42 +00:00
|
|
|
RotatePoint( &rel_pos, m_Pos, -GetDrawRotation() );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
if( area.Contains( rel_pos ) )
|
2007-08-04 20:05:54 +00:00
|
|
|
return true;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundingBox
|
2009-11-12 15:43:38 +00:00
|
|
|
* returns the bounding box of this Text (according to text and footprint
|
|
|
|
* orientation)
|
2008-03-15 10:24:32 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT TEXTE_MODULE::GetBoundingBox() const
|
2008-03-15 10:24:32 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
// Calculate area without text fields:
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT text_area;
|
2008-08-09 08:05:42 +00:00
|
|
|
int angle = GetDrawRotation();
|
|
|
|
wxPoint textstart, textend;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
|
|
|
text_area = GetTextRect();
|
|
|
|
textstart = text_area.GetOrigin();
|
2008-08-09 08:05:42 +00:00
|
|
|
textend = text_area.GetEnd();
|
|
|
|
RotatePoint( &textstart, m_Pos, angle );
|
|
|
|
RotatePoint( &textend, m_Pos, angle );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
text_area.SetOrigin( textstart );
|
|
|
|
text_area.SetEnd( textend );
|
2008-04-01 05:21:50 +00:00
|
|
|
text_area.Normalize();
|
|
|
|
return text_area;
|
2008-03-15 10:24:32 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-08-09 08:05:42 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
2009-11-12 15:43:38 +00:00
|
|
|
* Draw the text according to the footprint pos and orient
|
2008-03-15 10:24:32 +00:00
|
|
|
* @param panel = draw panel, Used to know the clip box
|
|
|
|
* @param DC = Current Device Context
|
|
|
|
* @param offset = draw offset (usually wxPoint(0,0)
|
|
|
|
* @param draw_mode = GR_OR, GR_XOR..
|
2007-08-04 20:05:54 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +00:00
|
|
|
int width, color, orient;
|
|
|
|
wxSize size;
|
|
|
|
wxPoint pos; // Center of text
|
|
|
|
PCB_BASE_FRAME* frame;
|
|
|
|
MODULE* Module = (MODULE*) m_Parent; /* parent must *not* be null
|
|
|
|
* (a module text without a footprint
|
|
|
|
* parent has no sense) */
|
2007-08-04 20:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( panel == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
frame = (PCB_BASE_FRAME*) panel->GetParent();
|
2007-08-04 20:05:54 +00:00
|
|
|
|
|
|
|
pos.x = m_Pos.x - offset.x;
|
|
|
|
pos.y = m_Pos.y - offset.y;
|
|
|
|
|
|
|
|
size = m_Size;
|
|
|
|
orient = GetDrawRotation();
|
2010-11-27 13:09:18 +00:00
|
|
|
width = m_Thickness;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( frame->m_DisplayModText == FILAIRE )
|
2011-01-30 22:22:38 +00:00
|
|
|
|| ( DC->LogicalToDeviceXRel( width ) < L_MIN_DESSIN ) )
|
2007-08-04 20:05:54 +00:00
|
|
|
width = 0;
|
|
|
|
else if( frame->m_DisplayModText == SKETCH )
|
|
|
|
width = -width;
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, draw_mode );
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD * brd = GetBoard( );
|
|
|
|
if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetVisibleElementColor(ANCHOR_VISIBLE);
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
int anchor_size = DC->DeviceToLogicalXRel( 2 );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
2009-01-29 14:26:20 +00:00
|
|
|
pos.x - anchor_size, pos.y,
|
2010-01-29 20:36:12 +00:00
|
|
|
pos.x + anchor_size, pos.y, 0, color );
|
2007-08-04 20:05:54 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
2009-01-29 14:26:20 +00:00
|
|
|
pos.x, pos.y - anchor_size,
|
2010-01-29 20:36:12 +00:00
|
|
|
pos.x, pos.y + anchor_size, 0, color );
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetLayerColor(Module->GetLayer());
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_BACK )
|
2009-10-10 01:25:53 +00:00
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( MOD_TEXT_BK_VISIBLE ) == false )
|
2009-10-10 01:25:53 +00:00
|
|
|
return;
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetVisibleElementColor(MOD_TEXT_BK_VISIBLE);
|
2009-10-10 01:25:53 +00:00
|
|
|
}
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( Module->GetLayer() == LAYER_N_FRONT )
|
2009-10-10 01:25:53 +00:00
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( MOD_TEXT_FR_VISIBLE ) == false )
|
2009-10-10 01:25:53 +00:00
|
|
|
return;
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetVisibleElementColor(MOD_TEXT_FR_VISIBLE);
|
2009-10-10 01:25:53 +00:00
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
|
|
|
|
if( m_NoShow )
|
2009-11-12 15:43:38 +00:00
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( MOD_TEXT_INVISIBLE ) == false )
|
2009-10-10 01:25:53 +00:00
|
|
|
return;
|
2010-01-31 20:01:46 +00:00
|
|
|
color = brd->GetVisibleElementColor(MOD_TEXT_INVISIBLE);
|
2009-11-12 15:43:38 +00:00
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
/* If the text is mirrored : negate size.x (mirror / Y axis) */
|
|
|
|
if( m_Mirror )
|
2007-08-04 20:05:54 +00:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
DrawGraphicText( panel, DC, pos, (enum EDA_Colors) color, m_Text, orient,
|
|
|
|
size, m_HJustify, m_VJustify, width, m_Italic, m_Bold );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-28 11:24:42 +00:00
|
|
|
/* Rraws a line from the TEXTE_MODULE origin to parent MODULE origin.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
|
|
|
|
wxDC* aDC,
|
|
|
|
int aDrawMode,
|
|
|
|
const wxPoint& aOffset )
|
2010-11-18 13:38:08 +00:00
|
|
|
{
|
|
|
|
MODULE* parent = (MODULE*) GetParent();
|
|
|
|
if( !parent )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
|
|
|
GRLine( &aPanel->m_ClipBox, aDC,
|
2010-12-28 11:24:42 +00:00
|
|
|
parent->GetPosition(), GetPosition() + aOffset,
|
2010-11-18 13:38:08 +00:00
|
|
|
0, UMBILICAL_COLOR);
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Return text rotation for drawings and plotting
|
2007-08-04 20:05:54 +00:00
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
int TEXTE_MODULE::GetDrawRotation() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
int rotation;
|
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
|
|
|
|
|
|
|
rotation = m_Orient;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
if( Module )
|
|
|
|
rotation += Module->m_Orient;
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS( rotation );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
// For angle = 0 .. 180 deg
|
2007-08-04 20:05:54 +00:00
|
|
|
while( rotation > 900 )
|
|
|
|
rotation -= 1800;
|
|
|
|
|
|
|
|
return rotation;
|
|
|
|
}
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
// see class_text_mod.h
|
2011-01-21 19:30:59 +00:00
|
|
|
void TEXTE_MODULE::DisplayInfo( EDA_DRAW_FRAME* frame )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-23 21:03:26 +00:00
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
if( module == NULL ) // Happens in modedit, and for new texts
|
2007-08-20 19:33:15 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
wxString msg, Line;
|
|
|
|
int ii;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
static const wxString text_type_msg[3] =
|
|
|
|
{
|
2008-08-09 08:05:42 +00:00
|
|
|
_( "Ref." ), _( "Value" ), _( "Text" )
|
|
|
|
};
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->ClearMsgPanel();
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
Line = module->m_Reference->m_Text;
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Module" ), Line, DARKCYAN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
Line = m_Text;
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Text" ), Line, BROWN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
ii = m_Type;
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ii > 2 )
|
|
|
|
ii = 2;
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Type" ), text_type_msg[ii], DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
if( m_NoShow )
|
2008-08-09 08:05:42 +00:00
|
|
|
msg = _( "No" );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2008-08-09 08:05:42 +00:00
|
|
|
msg = _( "Yes" );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Display" ), msg, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
// Display text layer (use layer name if possible)
|
|
|
|
BOARD* board = NULL;
|
|
|
|
board = (BOARD*) module->GetParent();
|
|
|
|
if( m_Layer < NB_LAYERS && board )
|
|
|
|
msg = board->GetLayerName( m_Layer );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2009-08-11 10:27:21 +00:00
|
|
|
msg.Printf( wxT( "%d" ), m_Layer );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Layer" ), msg, DARKGREEN );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
msg = _( " No" );
|
|
|
|
if( m_Mirror )
|
|
|
|
msg = _( " Yes" );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Mirror" ), msg, 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, DARKGREEN );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
// see class_text_mod.h
|
|
|
|
bool TEXTE_MODULE::IsOnLayer( int aLayer ) const
|
|
|
|
{
|
|
|
|
if( m_Layer == aLayer )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* test the parent, which is a MODULE */
|
|
|
|
if( aLayer == GetParent()->GetLayer() )
|
|
|
|
return true;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( aLayer == LAYER_N_BACK )
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
2009-12-21 17:56:25 +00:00
|
|
|
if( m_Layer==ADHESIVE_N_BACK || m_Layer==SILKSCREEN_N_BACK )
|
2007-08-24 03:40:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( aLayer == LAYER_N_FRONT )
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
2009-12-21 17:56:25 +00:00
|
|
|
if( m_Layer==ADHESIVE_N_FRONT || m_Layer==SILKSCREEN_N_FRONT )
|
2007-08-24 03:40:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
/* see class_text_mod.h
|
2009-11-23 21:03:26 +00:00
|
|
|
* bool TEXTE_MODULE::IsOnOneOfTheseLayers( int aLayerMask ) const
|
|
|
|
* {
|
2008-08-09 08:05:42 +00:00
|
|
|
*
|
2009-11-23 21:03:26 +00:00
|
|
|
* }
|
2008-08-09 08:05:42 +00:00
|
|
|
*/
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
#if defined(DEBUG)
|
2007-08-24 03:40:04 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
/**
|
|
|
|
* 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-06 20:26:59 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void TEXTE_MODULE::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
// for now, make it look like XML:
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2008-08-09 08:05:42 +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-08-06 20:26:59 +00:00
|
|
|
}
|
2008-08-09 08:05:42 +00:00
|
|
|
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#endif
|