2010-11-11 21:10:27 +00:00
|
|
|
/***********************************************/
|
|
|
|
/* sch_field.cpp : handle the class SCH_FIELD */
|
|
|
|
/***********************************************/
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Fields are texts attached to a component, having a special meaning
|
2008-12-31 15:01:29 +00:00
|
|
|
* Fields 0 and 1 are very important: reference and value
|
|
|
|
* Field 2 is used as default footprint name.
|
|
|
|
* Field 3 is reserved (not currently used
|
|
|
|
* Fields 4 and more are user fields.
|
|
|
|
* They can be renamed and can appear in reports
|
|
|
|
*/
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "base_struct.h"
|
2008-09-20 17:20:40 +00:00
|
|
|
#include "gr_basic.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "drawtxt.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "macros.h"
|
2010-09-05 17:01:48 +00:00
|
|
|
#include "trigo.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
|
|
|
#include "sch_field.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "template_fieldnames.h"
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId,
|
|
|
|
SCH_COMPONENT* aParent, wxString aName ) :
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_ITEM( aParent, SCH_FIELD_T ),
|
2008-10-06 05:44:29 +00:00
|
|
|
EDA_TextStruct()
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2009-10-16 07:48:26 +00:00
|
|
|
m_Pos = aPos;
|
|
|
|
m_FieldId = aFieldId;
|
2008-09-20 17:20:40 +00:00
|
|
|
m_AddExtraText = false;
|
2008-10-06 05:44:29 +00:00
|
|
|
m_Attributs = TEXT_NO_VISIBLE;
|
2009-10-16 07:48:26 +00:00
|
|
|
m_Name = aName;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
SetLayer( LAYER_FIELDS );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD::~SCH_FIELD()
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetPenSize
|
2009-06-30 17:57:27 +00:00
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
int SCH_FIELD::GetPenSize() const
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
int pensize = m_Thickness;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
|
|
|
if( pensize == 0 ) // Use default values for pen size
|
|
|
|
{
|
|
|
|
if( m_Bold )
|
|
|
|
pensize = GetPenSizeForBold( m_Size.x );
|
|
|
|
else
|
|
|
|
pensize = g_DrawDefaultLineThickness;
|
|
|
|
}
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
// Clip pen size for small texts:
|
|
|
|
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
2009-11-03 13:26:31 +00:00
|
|
|
* Draw schematic component fields.
|
2009-04-05 20:49:15 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_FIELD::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int orient;
|
|
|
|
EDA_Colors color;
|
2009-10-16 07:48:26 +00:00
|
|
|
wxPoint textpos;
|
|
|
|
SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
|
2010-11-27 13:09:18 +00:00
|
|
|
int LineWidth = m_Thickness;
|
2009-06-30 17:57:27 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
if( LineWidth == 0 ) // Use default values for pen size
|
2009-06-11 14:26:17 +00:00
|
|
|
{
|
2009-10-16 07:48:26 +00:00
|
|
|
if( m_Bold )
|
2009-06-11 14:26:17 +00:00
|
|
|
LineWidth = GetPenSizeForBold( m_Size.x );
|
|
|
|
else
|
|
|
|
LineWidth = g_DrawDefaultLineThickness;
|
|
|
|
}
|
|
|
|
|
2009-06-02 07:26:49 +00:00
|
|
|
|
|
|
|
// Clip pen size for small texts:
|
|
|
|
LineWidth = Clamp_Text_PenSize( LineWidth, m_Size, m_Bold );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( ( m_Attributs & TEXT_NO_VISIBLE ) || IsVoid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Calculate the text orientation, according to the component
|
|
|
|
* orientation/mirror */
|
2009-10-16 07:48:26 +00:00
|
|
|
orient = m_Orient;
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees.
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
if( orient == TEXT_ORIENT_HORIZ )
|
|
|
|
orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
orient = TEXT_ORIENT_HORIZ;
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Calculate the text justification, according to the component
|
|
|
|
* orientation/mirror this is a bit complicated due to cumulative
|
|
|
|
* calculations:
|
2009-10-16 07:48:26 +00:00
|
|
|
* - numerous cases (mirrored or not, rotation)
|
2009-12-02 21:44:03 +00:00
|
|
|
* - the DrawGraphicText function recalculate also H and H justifications
|
|
|
|
* according to the text orientation.
|
|
|
|
* - When a component is mirrored, the text is not mirrored and
|
|
|
|
* justifications are complicated to calculate
|
2009-10-16 07:48:26 +00:00
|
|
|
* so the more easily way is to use no justifications ( Centered text )
|
|
|
|
* and use GetBoundaryBox to know the text coordinate considered as centered
|
2010-09-05 17:01:48 +00:00
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect BoundaryBox = GetBoundingBox();
|
2009-10-16 07:48:26 +00:00
|
|
|
GRTextHorizJustifyType hjustify = GR_TEXT_HJUSTIFY_CENTER;
|
2010-09-05 17:01:48 +00:00
|
|
|
GRTextVertJustifyType vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
2009-10-16 07:48:26 +00:00
|
|
|
textpos = BoundaryBox.Centre();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_FieldId == REFERENCE )
|
|
|
|
color = ReturnLayerColor( LAYER_REFERENCEPART );
|
|
|
|
else if( m_FieldId == VALUE )
|
|
|
|
color = ReturnLayerColor( LAYER_VALUEPART );
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( LAYER_FIELDS );
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
if( !m_AddExtraText || ( m_FieldId != REFERENCE ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-16 07:48:26 +00:00
|
|
|
DrawGraphicText( panel, DC, textpos, color, m_Text,
|
|
|
|
orient,
|
|
|
|
m_Size, hjustify, vjustify,
|
|
|
|
LineWidth, m_Italic, m_Bold );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For more than one part per package, we must add the part selection
|
|
|
|
* A, B, ... or 1, 2, .. to the reference. */
|
|
|
|
wxString fulltext = m_Text;
|
2010-12-14 15:56:30 +00:00
|
|
|
fulltext << LIB_COMPONENT::ReturnSubReference( parentComponent->GetUnit() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
DrawGraphicText( panel, DC, textpos, color, fulltext,
|
|
|
|
orient,
|
|
|
|
m_Size, hjustify, vjustify,
|
2010-11-20 19:53:00 +00:00
|
|
|
LineWidth, m_Italic, m_Bold );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2010-03-16 12:05:47 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
/* Enable this to draw the bounding box around the text field to validate
|
|
|
|
* the bounding box calculations.
|
2010-09-05 17:01:48 +00:00
|
|
|
*/
|
2009-10-16 07:48:26 +00:00
|
|
|
#if 0
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
// Draw boundary box:
|
|
|
|
int x1 = BoundaryBox.GetX();
|
|
|
|
int y1 = BoundaryBox.GetY();
|
|
|
|
int x2 = BoundaryBox.GetRight();
|
|
|
|
int y2 = BoundaryBox.GetBottom();
|
|
|
|
GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
// Draw the text anchor point
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Calculate the text position, according to the component
|
|
|
|
* orientation/mirror */
|
2009-10-16 07:48:26 +00:00
|
|
|
textpos = m_Pos - parentComponent->m_Pos;
|
|
|
|
textpos = parentComponent->GetScreenCoord( textpos );
|
|
|
|
textpos += parentComponent->m_Pos;
|
|
|
|
x1 = textpos.x;
|
|
|
|
y1 = textpos.y;
|
|
|
|
int len = 10;
|
|
|
|
GRLine( &panel->m_ClipBox, DC, x1 - len, y1, x1 + len, y1, 0, BLUE );
|
2010-09-05 17:01:48 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, x1, y1 - len, x1, y1 + len, 0, BLUE );
|
2009-10-16 07:48:26 +00:00
|
|
|
#endif
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ImportValues
|
2008-12-31 15:01:29 +00:00
|
|
|
* copy parameters from a source.
|
|
|
|
* Pointers and specific values (position, texts) are not copied
|
|
|
|
* used to init a field from the model read from a lib entry
|
2009-10-08 13:19:28 +00:00
|
|
|
* @param aSource = the LIB_FIELD to read
|
2008-12-31 15:01:29 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
m_Orient = aSource.m_Orient;
|
|
|
|
m_Size = aSource.m_Size;
|
|
|
|
m_HJustify = aSource.m_HJustify;
|
|
|
|
m_VJustify = aSource.m_VJustify;
|
|
|
|
m_Italic = aSource.m_Italic;
|
|
|
|
m_Bold = aSource.m_Bold;
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = aSource.m_Thickness;
|
2008-12-31 15:01:29 +00:00
|
|
|
m_Attributs = aSource.m_Attributs;
|
2009-10-08 13:19:28 +00:00
|
|
|
m_Mirror = aSource.m_Mirror;
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Used if undo / redo command:
|
2008-09-20 17:20:40 +00:00
|
|
|
* swap data between this and copyitem
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_FIELD::SwapData( SCH_FIELD* copyitem )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
EXCHG( m_Text, copyitem->m_Text );
|
|
|
|
EXCHG( m_Layer, copyitem->m_Layer );
|
|
|
|
EXCHG( m_Pos, copyitem->m_Pos );
|
|
|
|
EXCHG( m_Size, copyitem->m_Size );
|
2010-11-27 13:09:18 +00:00
|
|
|
EXCHG( m_Thickness, copyitem->m_Thickness );
|
2008-09-20 17:20:40 +00:00
|
|
|
EXCHG( m_Orient, copyitem->m_Orient );
|
2008-12-20 20:38:39 +00:00
|
|
|
EXCHG( m_Mirror, copyitem->m_Mirror );
|
2008-09-20 17:20:40 +00:00
|
|
|
EXCHG( m_Attributs, copyitem->m_Attributs );
|
2008-12-16 19:44:57 +00:00
|
|
|
EXCHG( m_Italic, copyitem->m_Italic );
|
2009-05-28 17:39:40 +00:00
|
|
|
EXCHG( m_Bold, copyitem->m_Bold );
|
2008-09-20 17:20:40 +00:00
|
|
|
EXCHG( m_HJustify, copyitem->m_HJustify );
|
|
|
|
EXCHG( m_VJustify, copyitem->m_VJustify );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function GetBoundaryBox
|
2010-12-10 19:47:44 +00:00
|
|
|
* @return an EDA_Rect contains the real (user coordinates) boundary box for a text field.
|
2008-09-20 17:20:40 +00:00
|
|
|
* according to the component position, rotation, mirror ...
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect SCH_FIELD::GetBoundingBox() const
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
int hjustify, vjustify;
|
|
|
|
int orient;
|
|
|
|
wxSize size;
|
|
|
|
wxPoint pos1, pos2;
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
orient = m_Orient;
|
2010-09-05 17:01:48 +00:00
|
|
|
wxPoint pos = parentComponent->m_Pos;
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1 = m_Pos - pos;
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
size.x = LenSize( m_Text );
|
|
|
|
size.y = m_Size.y;
|
2008-09-20 17:20:40 +00:00
|
|
|
hjustify = m_HJustify;
|
|
|
|
vjustify = m_VJustify;
|
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
pos2 = pos + parentComponent->GetTransform().TransformCoordinate( pos1 );
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
// Calculate the text orientation, according to the component orientation/mirror.
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().y1 )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
if( orient == TEXT_ORIENT_HORIZ )
|
|
|
|
orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
orient = TEXT_ORIENT_HORIZ;
|
2009-10-16 07:48:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
// Calculate the text justification, according to the component orientation/mirror.
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().y1 )
|
2009-10-16 07:48:26 +00:00
|
|
|
{
|
2008-09-20 17:20:40 +00:00
|
|
|
/* is it mirrored (for text justify)*/
|
|
|
|
EXCHG( hjustify, vjustify );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().x2 < 0 )
|
2009-10-16 07:48:26 +00:00
|
|
|
NEGATE( vjustify );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().y1 > 0 )
|
2009-10-16 07:48:26 +00:00
|
|
|
NEGATE( hjustify );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
else /* component horizontal: is it mirrored (for text justify)*/
|
|
|
|
{
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().x1 < 0 )
|
2009-10-16 07:48:26 +00:00
|
|
|
NEGATE( hjustify );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
if( parentComponent->GetTransform().y2 > 0 )
|
2009-10-16 07:48:26 +00:00
|
|
|
NEGATE( vjustify );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( orient == TEXT_ORIENT_VERT )
|
2010-03-16 12:05:47 +00:00
|
|
|
EXCHG( size.x, size.y );
|
2008-09-20 17:20:40 +00:00
|
|
|
|
|
|
|
switch( hjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.x = pos2.x - (size.x / 2);
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.x = pos2.x - size.x;
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.x = pos2.x;
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( vjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.y = pos2.y - (size.y / 2);
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.y = pos2.y - size.y;
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-03-16 12:05:47 +00:00
|
|
|
pos1.y = pos2.y;
|
2008-09-20 17:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-16 12:05:47 +00:00
|
|
|
BoundaryBox.SetOrigin( pos1 );
|
|
|
|
BoundaryBox.SetSize( size );
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2009-06-02 07:26:49 +00:00
|
|
|
// Take thickness in account:
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
|
2009-10-16 07:48:26 +00:00
|
|
|
BoundaryBox.Inflate( linewidth, linewidth );
|
2009-06-02 07:26:49 +00:00
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
return BoundaryBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_FIELD::Save( FILE* aFile ) const
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
char hjustify = 'C';
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
hjustify = 'L';
|
|
|
|
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
hjustify = 'R';
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
char vjustify = 'C';
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
vjustify = 'B';
|
|
|
|
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
vjustify = 'T';
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-12-28 18:00:37 +00:00
|
|
|
if( fprintf( aFile, "F %d \"%s\" %c %-3d %-3d %-3d %4.4X %c %c%c%c",
|
2009-04-05 20:49:15 +00:00
|
|
|
m_FieldId,
|
|
|
|
CONV_TO_UTF8( m_Text ),
|
|
|
|
m_Orient == TEXT_ORIENT_HORIZ ? 'H' : 'V',
|
|
|
|
m_Pos.x, m_Pos.y,
|
|
|
|
m_Size.x,
|
|
|
|
m_Attributs,
|
|
|
|
hjustify, vjustify,
|
|
|
|
m_Italic ? 'I' : 'N',
|
2009-05-28 17:39:40 +00:00
|
|
|
m_Bold ? 'B' : 'N' ) == EOF )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
// Save field name, if the name is user definable
|
|
|
|
if( m_FieldId >= FIELD1 )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
if( fprintf( aFile, " \"%s\"", CONV_TO_UTF8( m_Name ) ) == EOF )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
return false;
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "\n" ) == EOF )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-16 07:48:26 +00:00
|
|
|
int fieldNdx;
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* Entry;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
frame->DrawPanel->ManageCurseur = NULL;
|
|
|
|
frame->DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
|
|
|
|
|
|
|
|
// save old cmp in undo list
|
2009-10-16 07:48:26 +00:00
|
|
|
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == component->Type() ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
|
2009-07-26 17:16:42 +00:00
|
|
|
frame->SaveCopyInUndoList( component, UR_CHANGED );
|
2009-04-05 20:49:15 +00:00
|
|
|
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldNdx = m_FieldId;
|
|
|
|
m_AddExtraText = 0;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fieldNdx == REFERENCE )
|
|
|
|
{
|
2010-12-14 15:56:30 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( Entry != NULL )
|
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( Entry->GetPartCount() > 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
m_AddExtraText = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Flags = 0;
|
|
|
|
frame->GetScreen()->SetCurItem( NULL );
|
2010-09-05 17:01:48 +00:00
|
|
|
frame->OnModify();
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->SetCurrentField( NULL );
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint * aFindLocation )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2010-10-20 19:43:58 +00:00
|
|
|
bool match;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-04-01 13:15:48 +00:00
|
|
|
if( aAuxData && m_FieldId == REFERENCE )
|
|
|
|
{
|
2010-10-20 19:43:58 +00:00
|
|
|
// reference is a special field because:
|
|
|
|
// >> a part identifier is added in multi parts per package
|
|
|
|
// (the .m_AddExtraText of the field is set in this case )
|
|
|
|
// >> In complex hierarchies, the actual reference depend on the sheet path.
|
2010-09-05 17:01:48 +00:00
|
|
|
SCH_COMPONENT* pSch = (SCH_COMPONENT*) m_Parent;
|
|
|
|
SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
|
|
|
|
wxString fulltext = pSch->GetRef( sheet );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-04-01 13:15:48 +00:00
|
|
|
if( m_AddExtraText )
|
|
|
|
{
|
|
|
|
/* For more than one part per package, we must add the part selection
|
|
|
|
* A, B, ... or 1, 2, .. to the reference. */
|
|
|
|
int part_id = pSch->GetUnitSelection( sheet );
|
2010-04-24 11:27:38 +00:00
|
|
|
fulltext << LIB_COMPONENT::ReturnSubReference( part_id );
|
2010-04-01 13:15:48 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
match = SCH_ITEM::Matches( fulltext, aSearchData );
|
2010-04-01 13:15:48 +00:00
|
|
|
}
|
2010-10-20 19:43:58 +00:00
|
|
|
else
|
|
|
|
match = SCH_ITEM::Matches( m_Text, aSearchData );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( match )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect BoundaryBox = GetBoundingBox();
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( aFindLocation )
|
2010-12-10 19:47:44 +00:00
|
|
|
*aFindLocation = GetBoundingBox().Centre();
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
return false;
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::DoHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
// Do not hit test hidden fields.
|
|
|
|
if( !IsVisible() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
EDA_Rect rect = GetBoundingBox();
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
return rect.Inside( aPoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::DoHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const
|
|
|
|
{
|
|
|
|
// Do not hit test hidden fields.
|
|
|
|
if( !IsVisible() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
EDA_Rect rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Inside( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|