2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file sch_field.cpp
|
|
|
|
* @brief Implementation of the SCH_FIELD class.
|
|
|
|
*/
|
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 "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 "wxEeschemaStruct.h"
|
2011-06-17 13:24:22 +00:00
|
|
|
#include "plot_common.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"
|
2011-03-25 20:07:27 +00:00
|
|
|
#include "kicad_string.h"
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2010-12-21 15:13:09 +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 ),
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT()
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
m_Pos = aPos;
|
|
|
|
m_id = aFieldId;
|
|
|
|
m_Attributs = TEXT_NO_VISIBLE;
|
|
|
|
m_name = aName;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
SetLayer( LAYER_FIELDS );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
|
|
|
|
SCH_ITEM( aField ),
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT( aField )
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
m_id = aField.m_id;
|
|
|
|
m_name = aField.m_name;
|
2010-12-21 15:13:09 +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-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_FIELD::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_FIELD( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
const wxString SCH_FIELD::GetText() const
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
|
|
|
wxString text = m_Text;
|
|
|
|
|
|
|
|
/* For more than one part per package, we must add the part selection
|
|
|
|
* A, B, ... or 1, 2, .. to the reference. */
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == REFERENCE )
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
|
|
|
|
|
|
|
|
wxCHECK_MSG( component != NULL, text,
|
|
|
|
wxT( "No component associated with field" ) + text );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2011-10-24 13:11:11 +00:00
|
|
|
if( component->GetPartCount() > 1 )
|
|
|
|
text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() );
|
2011-10-21 18:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
2009-12-02 21:44:03 +00:00
|
|
|
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-21 15:13:09 +00:00
|
|
|
|
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
|
|
|
*/
|
2011-11-12 09:51:06 +00:00
|
|
|
EDA_RECT boundaryBox = GetBoundingBox();
|
|
|
|
textpos = boundaryBox.Centre();
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == REFERENCE )
|
2009-04-05 20:49:15 +00:00
|
|
|
color = ReturnLayerColor( LAYER_REFERENCEPART );
|
2011-12-07 18:47:59 +00:00
|
|
|
else if( m_id == VALUE )
|
2009-04-05 20:49:15 +00:00
|
|
|
color = ReturnLayerColor( LAYER_VALUEPART );
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( LAYER_FIELDS );
|
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
DrawGraphicText( panel, DC, textpos, color, GetText(), orient, m_Size,
|
|
|
|
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
|
2011-10-21 18:17:51 +00:00
|
|
|
LineWidth, m_Italic, m_Bold );
|
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
|
|
|
*/
|
2011-11-12 09:58:20 +00:00
|
|
|
#if 0
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
// Draw boundary box:
|
2011-11-12 09:51:06 +00:00
|
|
|
GRRect( &panel->m_ClipBox, DC, boundaryBox, 0, 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 */
|
2011-10-19 20:32:21 +00:00
|
|
|
textpos = m_Pos - parentComponent->GetPosition();
|
2009-10-16 07:48:26 +00:00
|
|
|
textpos = parentComponent->GetScreenCoord( textpos );
|
2011-10-19 20:32:21 +00:00
|
|
|
textpos += parentComponent->GetPosition();
|
2011-11-12 09:51:06 +00:00
|
|
|
const int len = 10;
|
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
|
|
|
textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
|
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
|
|
|
textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE );
|
2009-10-16 07:48:26 +00:00
|
|
|
#endif
|
2009-04-05 20:49:15 +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-12-21 15:13:09 +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
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_FIELD::SwapData( SCH_ITEM* aItem )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2011-10-19 20:32:21 +00:00
|
|
|
wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_FIELD_T),
|
|
|
|
wxT( "Cannot swap field data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_FIELD* item = (SCH_FIELD*) aItem;
|
|
|
|
|
|
|
|
EXCHG( m_Text, item->m_Text );
|
|
|
|
EXCHG( m_Layer, item->m_Layer );
|
|
|
|
EXCHG( m_Pos, item->m_Pos );
|
|
|
|
EXCHG( m_Size, item->m_Size );
|
|
|
|
EXCHG( m_Thickness, item->m_Thickness );
|
|
|
|
EXCHG( m_Orient, item->m_Orient );
|
|
|
|
EXCHG( m_Mirror, item->m_Mirror );
|
|
|
|
EXCHG( m_Attributs, item->m_Attributs );
|
|
|
|
EXCHG( m_Italic, item->m_Italic );
|
|
|
|
EXCHG( m_Bold, item->m_Bold );
|
|
|
|
EXCHG( m_HJustify, item->m_HJustify );
|
|
|
|
EXCHG( m_VJustify, item->m_VJustify );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_FIELD::GetBoundingBox() const
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2009-10-16 07:48:26 +00:00
|
|
|
SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
|
2010-11-27 13:09:18 +00:00
|
|
|
int linewidth = ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
|
2009-06-02 07:26:49 +00:00
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
// We must pass the effective text thickness to GetTextBox
|
|
|
|
// when calculating the bounding box
|
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
|
|
|
|
|
|
|
|
// Calculate the text bounding box:
|
|
|
|
EDA_RECT rect = GetTextBox( -1, linewidth );
|
|
|
|
|
|
|
|
// Calculate the bounding box position relative to the component:
|
|
|
|
wxPoint origin = parentComponent->GetPosition();
|
|
|
|
wxPoint pos = m_Pos - origin;
|
|
|
|
wxPoint begin = rect.GetOrigin() - origin;
|
|
|
|
wxPoint end = rect.GetEnd() - origin;
|
|
|
|
RotatePoint( &begin, pos, m_Orient );
|
|
|
|
RotatePoint( &end, pos, m_Orient );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
// Due to the Y axis direction, we must mirror the bounding box,
|
|
|
|
// relative to the text position:
|
|
|
|
begin.y -= pos.y;
|
|
|
|
end.y -= pos.y;
|
|
|
|
NEGATE( begin.y );
|
|
|
|
NEGATE( end.y );
|
|
|
|
begin.y += pos.y;
|
|
|
|
end.y += pos.y;
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
// Now, apply the component transform (mirror/rot)
|
|
|
|
begin = parentComponent->GetTransform().TransformCoordinate( begin );
|
|
|
|
end = parentComponent->GetTransform().TransformCoordinate( end );
|
|
|
|
rect.SetOrigin( begin);
|
|
|
|
rect.SetEnd( end);
|
|
|
|
rect.Move( origin );
|
|
|
|
rect.Normalize();
|
|
|
|
return rect;
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
if( fprintf( aFile, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
|
2011-12-07 18:47:59 +00:00
|
|
|
m_id,
|
2011-03-25 20:07:27 +00:00
|
|
|
EscapedUTF8( m_Text ).c_str(), // wraps in quotes too
|
2009-04-05 20:49:15 +00:00
|
|
|
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
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id >= FIELD1 )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
if( fprintf( aFile, " %s", EscapedUTF8( m_name ).c_str() ) == 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
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
frame->DrawPanel->SetMouseCapture( NULL, NULL );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
|
|
|
|
|
|
|
|
// save old cmp in undo list
|
2011-04-05 14:46:51 +00:00
|
|
|
frame->SaveUndoItemInUndoList( component );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-04-05 14:46:51 +00:00
|
|
|
ClearFlags();
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->GetScreen()->SetCurItem( NULL );
|
2010-09-05 17:01:48 +00:00
|
|
|
frame->OnModify();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2011-11-17 01:06:08 +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;
|
2011-11-17 01:06:08 +00:00
|
|
|
wxString text = GetText();
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
if( (m_id > VALUE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS) )
|
2011-12-01 16:49:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
wxLogTrace( traceFindReplace, wxT( " child item " ) + GetSelectMenuText() );
|
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
// Take sheet path into account which effects the reference field and the unit for
|
|
|
|
// components with multiple parts.
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == REFERENCE && aAuxData != NULL )
|
2011-11-17 01:06:08 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
|
|
|
|
|
|
|
|
wxCHECK_MSG( component != NULL, false,
|
|
|
|
wxT( "No component associated with field" ) + text );
|
|
|
|
|
|
|
|
text = component->GetRef( (SCH_SHEET_PATH*) aAuxData );
|
|
|
|
|
|
|
|
if( component->GetPartCount() > 1 )
|
|
|
|
text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() );
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
match = SCH_ITEM::Matches( text, aSearchData );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( match )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString SCH_FIELD::GetSelectMenuText() const
|
|
|
|
{
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString tmp;
|
2011-03-30 11:20:05 +00:00
|
|
|
tmp.Printf( _( "Field %s" ), GetChars( GetName() ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-03-26 10:08:50 +00:00
|
|
|
return tmp;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
if( !m_name.IsEmpty() )
|
|
|
|
return m_name;
|
|
|
|
else if( aUseDefaultName )
|
|
|
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
|
|
|
|
|
|
|
|
return wxEmptyString;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
BITMAP_DEF SCH_FIELD::GetMenuImage() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == REFERENCE )
|
2011-08-29 03:04:59 +00:00
|
|
|
return edit_comp_ref_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == VALUE )
|
2011-08-29 03:04:59 +00:00
|
|
|
return edit_comp_value_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_id == FOOTPRINT )
|
2011-08-29 03:04:59 +00:00
|
|
|
return edit_comp_footprint_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
return edit_text_xpm;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
// Do not hit test hidden or empty fields.
|
2011-03-25 19:16:05 +00:00
|
|
|
if( !IsVisible() || IsVoid() )
|
2010-12-10 19:47:44 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( aPoint );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
bool SCH_FIELD::doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
|
|
|
// Do not hit test hidden fields.
|
2011-03-25 19:16:05 +00:00
|
|
|
if( !IsVisible() || IsVoid() )
|
2010-12-10 19:47:44 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( GetBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::doPlot( PLOTTER* aPlotter )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* parent = ( SCH_COMPONENT* ) GetParent();
|
|
|
|
|
|
|
|
wxCHECK_RET( parent != NULL && parent->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Cannot plot field with invalid parent." ) );
|
|
|
|
|
|
|
|
EDA_Colors color = UNSPECIFIED_COLOR;
|
|
|
|
|
|
|
|
color = ReturnLayerColor( GetLayer() );
|
|
|
|
|
|
|
|
if( m_Attributs & TEXT_NO_VISIBLE )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( IsVoid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Calculate the text orientation, according to the component
|
|
|
|
* orientation/mirror */
|
|
|
|
int orient = m_Orient;
|
|
|
|
|
|
|
|
if( parent->GetTransform().y1 ) // Rotate component 90 deg.
|
|
|
|
{
|
|
|
|
if( orient == TEXT_ORIENT_HORIZ )
|
|
|
|
orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
orient = TEXT_ORIENT_HORIZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the text justification, according to the component
|
|
|
|
* orientation/mirror
|
|
|
|
* this is a bit complicated due to cumulative calculations:
|
|
|
|
* - numerous cases (mirrored or not, rotation)
|
|
|
|
* - 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
|
|
|
|
* so the more easily way is to use no justifications ( Centered text )
|
|
|
|
* and use GetBoundaryBox to know the text coordinate considered as centered
|
|
|
|
*/
|
|
|
|
EDA_RECT BoundaryBox = GetBoundingBox();
|
|
|
|
GRTextHorizJustifyType hjustify = GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
GRTextVertJustifyType vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
wxPoint textpos = BoundaryBox.Centre();
|
|
|
|
|
|
|
|
int thickness = GetPenSize();
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
if( (parent->GetPartCount() <= 1) || (m_id != REFERENCE) )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
|
|
|
aPlotter->text( textpos, color, m_Text, orient, m_Size, hjustify, vjustify,
|
|
|
|
thickness, m_Italic, m_Bold );
|
|
|
|
}
|
|
|
|
else /* We plot the reference, for a multiple parts per package */
|
|
|
|
{
|
|
|
|
/* Adding A, B ... to the reference */
|
|
|
|
wxString Text = m_Text + LIB_COMPONENT::ReturnSubReference( parent->GetUnit() );
|
|
|
|
|
|
|
|
aPlotter->text( textpos, color, Text, orient, m_Size, hjustify, vjustify,
|
|
|
|
thickness, m_Italic, m_Bold );
|
|
|
|
}
|
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::doSetPosition( const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
|
|
|
|
|
|
|
|
wxPoint pos = ( (SCH_COMPONENT*) GetParent() )->GetPosition();
|
|
|
|
|
|
|
|
// Actual positions are calculated by the rotation/mirror transform of the
|
|
|
|
// parent component of the field. The inverse transfrom is used to calculate
|
|
|
|
// the position relative to the parent component.
|
|
|
|
wxPoint pt = aPosition - pos;
|
|
|
|
|
|
|
|
m_Pos = pos + component->GetTransform().InverseTransform().TransformCoordinate( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxPoint SCH_FIELD::doGetPosition() const
|
|
|
|
{
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
|
|
|
|
|
|
|
|
wxPoint pos = m_Pos - component->GetPosition();
|
|
|
|
|
|
|
|
return component->GetTransform().TransformCoordinate( pos ) + component->GetPosition();
|
|
|
|
}
|