2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-11-16 11:45:53 +00:00
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-19 20:32:21 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <macros.h>
|
2015-02-21 09:46:44 +00:00
|
|
|
#include <schframe.h>
|
2017-11-16 11:45:53 +00:00
|
|
|
#include <class_plotter.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_field.h>
|
|
|
|
#include <kicad_string.h>
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent, const 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
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( aPos );
|
2011-12-07 18:47:59 +00:00
|
|
|
m_id = aFieldId;
|
|
|
|
m_name = aName;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetVisible( false );
|
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
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_FIELD::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_FIELD( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-25 17:09:55 +00:00
|
|
|
const wxString SCH_FIELD::GetFullyQualifiedText() 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
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( component->GetUnitCount() > 1 )
|
|
|
|
text << LIB_PART::SubReference( 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
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
int pensize = GetThickness();
|
2009-06-30 17:57:27 +00:00
|
|
|
|
|
|
|
if( pensize == 0 ) // Use default values for pen size
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsBold() )
|
|
|
|
pensize = GetPenSizeForBold( GetTextWidth() );
|
2009-06-30 17:57:27 +00:00
|
|
|
else
|
2012-09-28 17:47:41 +00:00
|
|
|
pensize = GetDefaultLineThickness();
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2009-06-30 17:57:27 +00:00
|
|
|
// Clip pen size for small texts:
|
2017-01-23 20:30:11 +00:00
|
|
|
pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
|
2009-06-30 17:57:27 +00:00
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2015-02-28 16:56:09 +00:00
|
|
|
void SCH_FIELD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
2017-02-20 16:57:41 +00:00
|
|
|
GR_DRAWMODE aDrawMode, COLOR4D aColor )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int orient;
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color;
|
2009-10-16 07:48:26 +00:00
|
|
|
wxPoint textpos;
|
|
|
|
SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
|
2017-01-23 20:30:11 +00:00
|
|
|
int lineWidth = GetThickness();
|
2009-06-30 17:57:27 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( lineWidth == 0 ) // Use default values for pen size
|
2009-06-11 14:26:17 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( IsBold() )
|
|
|
|
lineWidth = GetPenSizeForBold( GetTextWidth() );
|
2009-06-11 14:26:17 +00:00
|
|
|
else
|
2017-01-23 20:30:11 +00:00
|
|
|
lineWidth = GetDefaultLineThickness();
|
2009-06-11 14:26:17 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 07:26:49 +00:00
|
|
|
// Clip pen size for small texts:
|
2017-01-23 20:30:11 +00:00
|
|
|
lineWidth = Clamp_Text_PenSize( lineWidth, GetTextSize(), IsBold() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( ( !IsVisible() && !m_forceVisible) || IsVoid() )
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-28 16:56:09 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
// Calculate the text orientation according to the component orientation.
|
2017-01-23 20:30:11 +00:00
|
|
|
orient = GetTextAngle();
|
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
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( orient == TEXT_ANGLE_HORIZ )
|
|
|
|
orient = TEXT_ANGLE_VERT;
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2017-01-23 20:30:11 +00:00
|
|
|
orient = TEXT_ANGLE_HORIZ;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2015-02-28 16:56:09 +00:00
|
|
|
textpos = boundaryBox.Centre() + aOffset;
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
if( m_forceVisible )
|
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKGRAY );
|
2011-12-13 15:37:33 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2011-12-13 15:37:33 +00:00
|
|
|
{
|
|
|
|
if( m_id == REFERENCE )
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( LAYER_REFERENCEPART );
|
2011-12-13 15:37:33 +00:00
|
|
|
else if( m_id == VALUE )
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( LAYER_VALUEPART );
|
2011-12-13 15:37:33 +00:00
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( LAYER_FIELDS );
|
2011-12-13 15:37:33 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2015-02-28 16:56:09 +00:00
|
|
|
EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
|
2017-01-23 20:30:11 +00:00
|
|
|
DrawGraphicText( clipbox, aDC, textpos, color, GetFullyQualifiedText(), orient, GetTextSize(),
|
2011-11-12 09:51:06 +00:00
|
|
|
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
|
2017-01-23 20:30:11 +00:00
|
|
|
lineWidth, IsItalic(), IsBold() );
|
2010-03-16 12:05:47 +00:00
|
|
|
|
2014-02-11 21:54:30 +00:00
|
|
|
// While moving: don't loose visual contact to which component this label belongs.
|
|
|
|
if ( IsWireImage() )
|
|
|
|
{
|
|
|
|
const wxPoint origin = parentComponent->GetPosition();
|
2017-01-23 20:30:11 +00:00
|
|
|
textpos = GetTextPos() - origin;
|
2014-02-11 21:54:30 +00:00
|
|
|
textpos = parentComponent->GetScreenCoord( textpos );
|
|
|
|
textpos += parentComponent->GetPosition();
|
2015-02-28 16:56:09 +00:00
|
|
|
GRLine( clipbox, aDC, origin, textpos, 2, DARKGRAY );
|
2014-02-11 21:54:30 +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:
|
2015-02-28 16:56:09 +00:00
|
|
|
GRRect( aPanel->GetClipBox(), aDC, 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;
|
2015-02-28 16:56:09 +00:00
|
|
|
GRLine( clipbox, aDC,
|
2011-11-12 09:51:06 +00:00
|
|
|
textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
|
2015-02-28 16:56:09 +00:00
|
|
|
GRLine( clipbox, aDC,
|
2011-11-12 09:51:06 +00:00
|
|
|
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
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetEffects( aSource );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
|
2016-10-15 18:05:03 +00:00
|
|
|
void SCH_FIELD::ExportValues( LIB_FIELD& aDest ) const
|
|
|
|
{
|
|
|
|
aDest.SetId( GetId() );
|
|
|
|
aDest.SetText( m_Text ); // Set field value
|
|
|
|
aDest.SetName( GetName() );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
aDest.SetEffects( *this );
|
2016-10-15 18:05:03 +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;
|
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_Text, item->m_Text );
|
|
|
|
std::swap( m_Layer, item->m_Layer );
|
2017-01-23 20:30:11 +00:00
|
|
|
|
|
|
|
SwapEffects( *item );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const 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;
|
2017-01-23 20:30:11 +00:00
|
|
|
int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
|
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
|
2017-01-23 20:30:11 +00:00
|
|
|
linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
|
2011-11-12 09:51:06 +00:00
|
|
|
|
|
|
|
// Calculate the text bounding box:
|
2012-01-06 19:00:59 +00:00
|
|
|
EDA_RECT rect;
|
|
|
|
|
2014-04-25 16:49:32 +00:00
|
|
|
if( m_id == REFERENCE ) // multi units have one letter or more added to reference
|
2012-01-06 19:00:59 +00:00
|
|
|
{
|
2014-04-25 16:49:32 +00:00
|
|
|
SCH_FIELD text( *this ); // Make a local copy to change text
|
2012-01-06 19:00:59 +00:00
|
|
|
// because GetBoundingBox() is const
|
2014-04-25 16:49:32 +00:00
|
|
|
text.SetText( GetFullyQualifiedText() );
|
2012-01-06 19:00:59 +00:00
|
|
|
rect = text.GetTextBox( -1, linewidth );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rect = GetTextBox( -1, linewidth );
|
2011-11-12 09:51:06 +00:00
|
|
|
|
|
|
|
// Calculate the bounding box position relative to the component:
|
|
|
|
wxPoint origin = parentComponent->GetPosition();
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pos = GetTextPos() - origin;
|
2011-11-12 09:51:06 +00:00
|
|
|
wxPoint begin = rect.GetOrigin() - origin;
|
|
|
|
wxPoint end = rect.GetEnd() - origin;
|
2017-01-23 20:30:11 +00:00
|
|
|
RotatePoint( &begin, pos, GetTextAngle() );
|
|
|
|
RotatePoint( &end, pos, GetTextAngle() );
|
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:
|
2015-06-26 13:41:56 +00:00
|
|
|
MIRROR( begin.y, pos.y );
|
|
|
|
MIRROR( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
bool SCH_FIELD::IsHorizJustifyFlipped() const
|
|
|
|
{
|
|
|
|
wxPoint render_center = GetBoundingBox().Centre();
|
|
|
|
wxPoint pos = GetPosition();
|
|
|
|
|
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
return render_center.x < pos.x;
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
|
|
|
return render_center.x > pos.x;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-12-22 13:28:11 +00:00
|
|
|
frame->GetCanvas()->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
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
Draw( frame->GetCanvas(), 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;
|
2013-03-25 17:09:55 +00:00
|
|
|
wxString text = GetFullyQualifiedText();
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2013-07-14 18:08:20 +00:00
|
|
|
// User defined fields have an ID of -1.
|
|
|
|
if( ((m_id > VALUE || m_id < REFERENCE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS))
|
2011-12-21 20:21:15 +00:00
|
|
|
|| ((m_id == REFERENCE) && !(aSearchData.GetFlags() & FR_REPLACE_REFERENCES)) )
|
2011-12-01 16:49:28 +00:00
|
|
|
return false;
|
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
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;
|
|
|
|
|
2017-12-24 15:04:02 +00:00
|
|
|
wxCHECK_MSG( component != NULL, false, wxT( "No symbol associated with field" ) + text );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2016-02-15 20:17:51 +00:00
|
|
|
text = component->GetRef( (SCH_SHEET_PATH*) aAuxData );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( component->GetUnitCount() > 1 )
|
|
|
|
text << LIB_PART::SubReference( component->GetUnit() );
|
2011-11-17 01:06:08 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2011-12-21 20:21:15 +00:00
|
|
|
bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
|
|
|
|
{
|
|
|
|
bool isReplaced;
|
2013-03-25 17:09:55 +00:00
|
|
|
wxString text = GetFullyQualifiedText();
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2013-10-27 18:21:53 +00:00
|
|
|
if( m_id == REFERENCE )
|
2011-12-21 20:21:15 +00:00
|
|
|
{
|
2013-10-27 18:21:53 +00:00
|
|
|
wxCHECK_MSG( aAuxData != NULL, false,
|
|
|
|
wxT( "Cannot replace reference designator without valid sheet path." ) );
|
|
|
|
|
2011-12-21 20:21:15 +00:00
|
|
|
wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false,
|
2017-12-24 15:04:02 +00:00
|
|
|
wxT( "Invalid replace symbol reference field call." ) ) ;
|
2011-12-21 20:21:15 +00:00
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
|
|
|
|
|
|
|
|
wxCHECK_MSG( component != NULL, false,
|
2017-12-24 15:04:02 +00:00
|
|
|
wxT( "No symbol associated with field" ) + text );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2016-02-15 20:17:51 +00:00
|
|
|
text = component->GetRef( (SCH_SHEET_PATH*) aAuxData );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// if( component->GetUnitCount() > 1 )
|
|
|
|
// text << LIB_PART::SubReference( component->GetUnit() );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, text );
|
|
|
|
|
|
|
|
if( isReplaced )
|
2016-02-15 20:18:32 +00:00
|
|
|
component->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
|
2011-12-21 20:21:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, m_Text );
|
|
|
|
}
|
|
|
|
|
|
|
|
return isReplaced;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_FIELD::Rotate( wxPoint aPosition )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pt = GetTextPos();
|
|
|
|
RotatePoint( &pt, aPosition, 900 );
|
|
|
|
SetTextPos( pt );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_FIELD::HitTest( const wxPoint& aPosition, 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 );
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
return rect.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_FIELD::HitTest( 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
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_FIELD::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* parent = ( SCH_COMPONENT* ) GetParent();
|
|
|
|
|
|
|
|
wxCHECK_RET( parent != NULL && parent->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Cannot plot field with invalid parent." ) );
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D color = GetLayerColor( GetLayer() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( !IsVisible() )
|
2011-06-17 13:24:22 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( IsVoid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Calculate the text orientation, according to the component
|
|
|
|
* orientation/mirror */
|
2017-01-23 20:30:11 +00:00
|
|
|
int orient = GetTextAngle();
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( parent->GetTransform().y1 ) // Rotate component 90 deg.
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
if( orient == TEXT_ANGLE_HORIZ )
|
|
|
|
orient = TEXT_ANGLE_VERT;
|
2011-06-17 13:24:22 +00:00
|
|
|
else
|
2017-01-23 20:30:11 +00:00
|
|
|
orient = TEXT_ANGLE_HORIZ;
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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();
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
2011-06-17 13:24:22 +00:00
|
|
|
wxPoint textpos = BoundaryBox.Centre();
|
|
|
|
|
|
|
|
int thickness = GetPenSize();
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
aPlotter->Text( textpos, color, GetFullyQualifiedText(), orient, GetTextSize(),
|
|
|
|
hjustify, vjustify,
|
|
|
|
thickness, IsItalic(), IsBold() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_FIELD::SetPosition( const wxPoint& aPosition )
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( pos + component->GetTransform().InverseTransform().TransformCoordinate( pt ) );
|
2011-10-21 18:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
wxPoint SCH_FIELD::GetPosition() const
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
|
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
wxPoint pos = GetTextPos() - component->GetPosition();
|
2011-10-21 18:17:51 +00:00
|
|
|
|
|
|
|
return component->GetTransform().TransformCoordinate( pos ) + component->GetPosition();
|
|
|
|
}
|