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
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2004-2021 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
|
|
|
|
*/
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
/*
|
2021-05-05 21:41:51 +00:00
|
|
|
* Fields are texts attached to a symbol, some of which have a special meaning.
|
|
|
|
* Fields 0 and 1 are very important: reference and value.
|
2008-12-31 15:01:29 +00:00
|
|
|
* Field 2 is used as default footprint name.
|
2021-05-05 21:41:51 +00:00
|
|
|
* Field 3 is used to point to a datasheet (usually a URL).
|
|
|
|
* Fields 4+ are user fields. They can be renamed and can appear in reports.
|
2008-12-31 15:01:29 +00:00
|
|
|
*/
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2020-11-17 16:02:47 +00:00
|
|
|
#include <wx/menu.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <common.h> // for ExpandTextVars
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2021-10-01 10:52:34 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-03-26 11:02:59 +00:00
|
|
|
#include <kiway.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_field.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-03-06 03:00:30 +00:00
|
|
|
#include <settings/color_settings.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-11-17 16:02:47 +00:00
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/ee_actions.h>
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
|
2020-04-18 20:04:41 +00:00
|
|
|
const wxString& aName ) :
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_ITEM( aParent, SCH_FIELD_T ),
|
2020-05-06 14:47:51 +00:00
|
|
|
EDA_TEXT( wxEmptyString ),
|
|
|
|
m_id( 0 ),
|
|
|
|
m_name( aName )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
SetTextPos( aPos );
|
2020-05-06 14:47:51 +00:00
|
|
|
SetId( aFieldId ); // will also set the layer
|
2017-01-23 20:30:11 +00:00
|
|
|
SetVisible( false );
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 14:47:51 +00:00
|
|
|
void SCH_FIELD::SetId( int aId )
|
|
|
|
{
|
2022-01-01 01:17:00 +00:00
|
|
|
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
|
|
|
|
|
2020-05-06 14:47:51 +00:00
|
|
|
m_id = aId;
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2020-05-06 14:47:51 +00:00
|
|
|
{
|
|
|
|
switch( m_id )
|
|
|
|
{
|
|
|
|
case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
|
|
|
|
case SHEETFILENAME: SetLayer( LAYER_SHEETFILENAME ); break;
|
|
|
|
default: SetLayer( LAYER_SHEETFIELDS ); break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-05-06 14:47:51 +00:00
|
|
|
{
|
|
|
|
switch( m_id )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
case REFERENCE_FIELD: SetLayer( LAYER_REFERENCEPART ); break;
|
|
|
|
case VALUE_FIELD: SetLayer( LAYER_VALUEPART ); break;
|
|
|
|
default: SetLayer( LAYER_FIELDS ); break;
|
2020-05-06 14:47:51 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-01 01:17:00 +00:00
|
|
|
else if( m_parent && m_parent->IsType( labelTypes ) )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
// We can't use defined IDs for labels because there can be multiple net class
|
|
|
|
// assignments.
|
|
|
|
|
|
|
|
if( GetCanonicalName() == wxT( "Netclass" ) )
|
|
|
|
SetLayer( LAYER_NETCLASS_REFS );
|
|
|
|
else if( GetCanonicalName() == wxT( "Intersheetrefs" ) )
|
|
|
|
SetLayer( LAYER_INTERSHEET_REFS );
|
|
|
|
else
|
|
|
|
SetLayer( LAYER_FIELDS );
|
|
|
|
}
|
2020-05-06 14:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString SCH_FIELD::GetShownText( int aDepth ) const
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
std::function<bool( wxString* )> symbolResolver =
|
2020-04-06 13:06:57 +00:00
|
|
|
[&]( wxString* token ) -> bool
|
2020-04-05 19:51:48 +00:00
|
|
|
{
|
2020-07-29 17:02:39 +00:00
|
|
|
if( token->Contains( ':' ) )
|
|
|
|
{
|
|
|
|
if( Schematic()->ResolveCrossReference( token, aDepth ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-07-29 17:02:39 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( parentSymbol->ResolveTextVar( token, aDepth + 1 ) )
|
2020-07-29 17:02:39 +00:00
|
|
|
return true;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
SCHEMATIC* schematic = parentSymbol->Schematic();
|
2020-07-29 17:02:39 +00:00
|
|
|
SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
|
|
|
|
|
|
|
|
if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-28 12:11:11 +00:00
|
|
|
|
|
|
|
return false;
|
2020-04-05 19:51:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::function<bool( wxString* )> sheetResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
|
2020-04-06 13:06:57 +00:00
|
|
|
return sheet->ResolveTextVar( token, aDepth + 1 );
|
2020-04-05 19:51:48 +00:00
|
|
|
};
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
std::function<bool( wxString* )> labelResolver =
|
2020-11-17 16:02:47 +00:00
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
|
|
|
return label->ResolveTextVar( token, aDepth + 1 );
|
2020-11-17 16:02:47 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
PROJECT* project = nullptr;
|
2021-06-29 12:54:40 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText();
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2021-06-12 17:58:15 +00:00
|
|
|
if( text == "~" ) // Legacy placeholder for empty string
|
|
|
|
{
|
|
|
|
text = "";
|
|
|
|
}
|
2021-06-29 12:54:40 +00:00
|
|
|
else if( HasTextVars() )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
if( Schematic() )
|
2020-05-21 02:27:48 +00:00
|
|
|
project = &Schematic()->Prj();
|
2020-04-24 20:33:59 +00:00
|
|
|
|
|
|
|
if( aDepth < 10 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2021-01-17 15:47:04 +00:00
|
|
|
text = ExpandTextVars( text, &symbolResolver, nullptr, project );
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2021-01-17 15:47:04 +00:00
|
|
|
text = ExpandTextVars( text, &sheetResolver, nullptr, project );
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( m_parent && m_parent->IsType( labelTypes ) )
|
|
|
|
text = ExpandTextVars( text, &labelResolver, nullptr, project );
|
2020-04-24 20:33:59 +00:00
|
|
|
else
|
2021-01-17 15:47:04 +00:00
|
|
|
text = ExpandTextVars( text, project );
|
2020-04-24 20:33:59 +00:00
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
// WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
|
2020-03-06 12:05:21 +00:00
|
|
|
// id and the parent's type.
|
2011-10-21 18:17:51 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( m_id == REFERENCE_FIELD )
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
|
|
|
// For more than one part per package, we must add the part selection
|
|
|
|
// A, B, ... or 1, 2, .. to the reference.
|
2020-11-15 17:03:27 +00:00
|
|
|
if( parentSymbol->GetUnitCount() > 1 )
|
2021-06-10 18:51:46 +00:00
|
|
|
text << LIB_SYMBOL::SubReference( parentSymbol->GetUnit() );
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
}
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
2020-03-12 13:56:44 +00:00
|
|
|
if( m_id == SHEETFILENAME )
|
2020-10-20 19:05:04 +00:00
|
|
|
text = _( "File:" ) + wxS( " " )+ text;
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 18:17:51 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int SCH_FIELD::GetPenWidth() const
|
2009-06-30 17:57:27 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
return GetEffectiveTextPenWidth();
|
2009-06-30 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2020-11-14 14:29:11 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( IsForceVisible() ? LAYER_HIDDEN : m_layer );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I textpos;
|
2020-04-30 06:59:43 +00:00
|
|
|
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2020-04-18 11:04:52 +00:00
|
|
|
if( ( !IsVisible() && !IsForceVisible() ) || IsVoid() )
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Calculate the text orientation according to the symbol orientation.
|
2021-12-28 22:13:54 +00:00
|
|
|
EDA_ANGLE orient = GetTextAngle();
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( orient == EDA_ANGLE::HORIZONTAL )
|
|
|
|
orient = EDA_ANGLE::VERTICAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
orient = EDA_ANGLE::HORIZONTAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
/*
|
|
|
|
* Calculate the text justification, according to the symbol 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)
|
2020-11-15 17:03:27 +00:00
|
|
|
* - the GRText function will also recalculate H and V justifications according to the text
|
|
|
|
* orientation.
|
|
|
|
* - When a symbol 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
|
|
|
|
* GetBoundingBox to know the text coordinate considered as centered
|
2010-09-05 17:01:48 +00:00
|
|
|
*/
|
2021-10-26 12:18:08 +00:00
|
|
|
textpos = GetBoundingBox().Centre() + aOffset;
|
2009-10-16 07:48:26 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GRText( DC, textpos, color, GetShownText(), orient, GetTextSize(), GR_TEXT_H_ALIGN_CENTER,
|
2021-12-29 17:31:40 +00:00
|
|
|
GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetFont() );
|
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
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
SetAttributes( 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
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
void SCH_FIELD::SwapData( SCH_ITEM* aItem )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ),
|
2011-10-19 20:32:21 +00:00
|
|
|
wxT( "Cannot swap field data with invalid item." ) );
|
|
|
|
|
|
|
|
SCH_FIELD* item = (SCH_FIELD*) aItem;
|
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, item->m_layer );
|
2019-08-02 00:10:25 +00:00
|
|
|
SwapText( *item );
|
2021-12-28 22:13:54 +00:00
|
|
|
SwapAttributes( *item );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
EDA_ANGLE SCH_FIELD::GetDrawRotation() const
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
|
|
|
// Calculate the text orientation according to the symbol orientation.
|
2021-12-28 22:13:54 +00:00
|
|
|
EDA_ANGLE orient = GetTextAngle();
|
2021-11-01 21:05:30 +00:00
|
|
|
|
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
|
|
|
|
|
|
|
if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( orient.IsHorizontal() )
|
|
|
|
orient = EDA_ANGLE::VERTICAL;
|
2021-11-01 21:05:30 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
orient = EDA_ANGLE::HORIZONTAL;
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return orient;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_FIELD::GetDrawPos() const
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
return GetBoundingBox().Centre();
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T SCH_FIELD::GetDrawHorizJustify() const
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_H_ALIGN_CENTER;
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_V_ALIGN_T SCH_FIELD::GetDrawVertJustify() const
|
2021-11-01 21:05:30 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_V_ALIGN_CENTER;
|
2021-11-01 21:05:30 +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
|
|
|
{
|
2011-11-12 09:51:06 +00:00
|
|
|
// Calculate the text bounding box:
|
2020-04-24 20:33:59 +00:00
|
|
|
EDA_RECT rect = GetTextBox();
|
2020-03-06 12:05:21 +00:00
|
|
|
|
|
|
|
// Calculate the bounding box position relative to the parent:
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I origin = GetParentPosition();
|
|
|
|
VECTOR2I pos = GetTextPos() - origin;
|
|
|
|
VECTOR2I begin = rect.GetOrigin() - origin;
|
|
|
|
VECTOR2I end = rect.GetEnd() - origin;
|
|
|
|
RotatePoint( begin, pos, GetTextAngle() );
|
|
|
|
RotatePoint( end, pos, GetTextAngle() );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Now, apply the symbol transform (mirror/rot)
|
2020-03-06 20:02:58 +00:00
|
|
|
TRANSFORM transform;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// Due to the Y axis direction, we must mirror the bounding box,
|
|
|
|
// relative to the text position:
|
|
|
|
MIRROR( begin.y, pos.y );
|
|
|
|
MIRROR( end.y, pos.y );
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
transform = parentSymbol->GetTransform();
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
transform = TRANSFORM( 1, 0, 0, 1 ); // identity transform
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.SetOrigin( transform.TransformCoordinate( begin ) );
|
|
|
|
rect.SetEnd( transform.TransformCoordinate( end ) );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
rect.Move( origin );
|
|
|
|
rect.Normalize();
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2011-11-12 09:51:06 +00:00
|
|
|
return rect;
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
bool SCH_FIELD::IsHorizJustifyFlipped() const
|
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I render_center = GetBoundingBox().Centre();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = GetPosition();
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
|
|
|
if( GetDrawRotation().IsVertical() )
|
2021-11-03 18:11:08 +00:00
|
|
|
return render_center.y > pos.y;
|
|
|
|
else
|
|
|
|
return render_center.x < pos.x;
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
|
|
|
if( GetDrawRotation().IsVertical() )
|
2021-11-03 18:11:08 +00:00
|
|
|
return render_center.y < pos.y;
|
|
|
|
else
|
|
|
|
return render_center.x > pos.x;
|
2015-12-13 16:56:47 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T SCH_FIELD::GetEffectiveHorizJustify() const
|
2021-11-03 18:11:08 +00:00
|
|
|
{
|
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
|
|
|
return IsHorizJustifyFlipped() ? GR_TEXT_H_ALIGN_RIGHT : GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
|
|
|
return IsHorizJustifyFlipped() ? GR_TEXT_H_ALIGN_LEFT : GR_TEXT_H_ALIGN_RIGHT;
|
2021-11-03 18:11:08 +00:00
|
|
|
default:
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_H_ALIGN_CENTER;
|
2021-11-03 18:11:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::IsVertJustifyFlipped() const
|
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I render_center = GetBoundingBox().Centre();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = GetPosition();
|
2021-11-03 18:11:08 +00:00
|
|
|
|
|
|
|
switch( GetVertJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
|
|
|
if( GetDrawRotation().IsVertical() )
|
2021-11-03 18:11:08 +00:00
|
|
|
return render_center.x < pos.x;
|
|
|
|
else
|
|
|
|
return render_center.y < pos.y;
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
|
|
|
if( GetDrawRotation().IsVertical() )
|
2021-11-03 18:11:08 +00:00
|
|
|
return render_center.x > pos.x;
|
|
|
|
else
|
|
|
|
return render_center.y > pos.y;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_V_ALIGN_T SCH_FIELD::GetEffectiveVertJustify() const
|
2021-11-03 18:11:08 +00:00
|
|
|
{
|
|
|
|
switch( GetVertJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
|
|
|
return IsVertJustifyFlipped() ? GR_TEXT_V_ALIGN_BOTTOM : GR_TEXT_V_ALIGN_TOP;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
|
|
|
return IsVertJustifyFlipped() ? GR_TEXT_V_ALIGN_TOP : GR_TEXT_V_ALIGN_BOTTOM;
|
2021-11-03 18:11:08 +00:00
|
|
|
default:
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_V_ALIGN_CENTER;
|
2021-11-03 18:11:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-02 23:53:06 +00:00
|
|
|
bool SCH_FIELD::IsVoid() const
|
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
return GetText().Len() == 0;
|
2019-04-02 23:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:27:51 +00:00
|
|
|
bool SCH_FIELD::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
wxString text = GetShownText();
|
2019-05-30 13:39:31 +00:00
|
|
|
int flags = aSearchData.GetFlags();
|
2020-04-18 11:04:52 +00:00
|
|
|
bool searchHiddenFields = flags & FR_SEARCH_ALL_FIELDS;
|
2020-03-12 13:56:44 +00:00
|
|
|
bool searchAndReplace = flags & FR_SEARCH_REPLACE;
|
|
|
|
bool replaceReferences = flags & FR_REPLACE_REFERENCES;
|
2019-05-30 13:39:31 +00:00
|
|
|
|
2020-03-12 13:56:44 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " child item " )
|
2020-03-06 12:05:21 +00:00
|
|
|
+ GetSelectMenuText( EDA_UNITS::MILLIMETRES ) );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2020-04-18 11:04:52 +00:00
|
|
|
if( !IsVisible() && !searchHiddenFields )
|
|
|
|
return false;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T && m_id == REFERENCE_FIELD )
|
2011-11-17 01:06:08 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( searchAndReplace && !replaceReferences )
|
2020-03-12 13:56:44 +00:00
|
|
|
return false;
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-09-20 17:52:56 +00:00
|
|
|
wxASSERT( aAuxData );
|
|
|
|
|
2020-03-12 13:56:44 +00:00
|
|
|
// Take sheet path into account which effects the reference field and the unit for
|
2020-11-15 17:03:27 +00:00
|
|
|
// symbols with multiple parts.
|
2020-09-20 17:52:56 +00:00
|
|
|
if( aAuxData )
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2020-11-15 17:03:27 +00:00
|
|
|
text = parentSymbol->GetRef((SCH_SHEET_PATH*) aAuxData );
|
2011-11-17 01:06:08 +00:00
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
if( SCH_ITEM::Matches( text, aSearchData ) )
|
|
|
|
return true;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( parentSymbol->GetUnitCount() > 1 )
|
2021-06-10 18:51:46 +00:00
|
|
|
text << LIB_SYMBOL::SubReference( parentSymbol->GetUnit() );
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
return SCH_ITEM::Matches( text, aSearchData );
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
|
2018-05-17 23:43:03 +00:00
|
|
|
bool SCH_FIELD::IsReplaceable() const
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( m_id == VALUE_FIELD )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( parentSymbol->GetLibSymbolRef() && parentSymbol->GetLibSymbolRef()->IsPower() )
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2020-03-12 13:56:44 +00:00
|
|
|
// See comments in SCH_FIELD::Replace(), below.
|
2020-03-06 20:02:58 +00:00
|
|
|
if( m_id == SHEETFILENAME )
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( m_id == 0 /* IntersheetRefs */ )
|
|
|
|
return false;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2018-05-17 23:43:03 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
return true;
|
2018-05-17 23:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:27:51 +00:00
|
|
|
bool SCH_FIELD::Replace( const wxFindReplaceData& aSearchData, void* aAuxData )
|
2011-12-21 20:21:15 +00:00
|
|
|
{
|
2021-04-30 16:54:15 +00:00
|
|
|
wxString text;
|
|
|
|
bool resolve = false; // Replace in source text, not shown text
|
|
|
|
bool isReplaced = false;
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2011-12-21 20:21:15 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2021-04-30 16:54:15 +00:00
|
|
|
switch( m_id )
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2021-04-30 16:54:15 +00:00
|
|
|
case REFERENCE_FIELD:
|
|
|
|
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2020-08-12 14:04:51 +00:00
|
|
|
if( !( aSearchData.GetFlags() & FR_REPLACE_REFERENCES ) )
|
|
|
|
return false;
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2021-04-30 16:54:15 +00:00
|
|
|
text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
|
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, text );
|
|
|
|
|
|
|
|
if( isReplaced )
|
|
|
|
parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2021-04-30 16:54:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VALUE_FIELD:
|
|
|
|
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
|
|
|
|
|
|
|
|
text = parentSymbol->GetValue((SCH_SHEET_PATH*) aAuxData, resolve );
|
2020-03-12 13:56:44 +00:00
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, text );
|
2011-12-21 20:21:15 +00:00
|
|
|
|
2020-03-12 13:56:44 +00:00
|
|
|
if( isReplaced )
|
2021-04-30 16:54:15 +00:00
|
|
|
parentSymbol->SetValue( (SCH_SHEET_PATH*) aAuxData, text );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
|
|
|
|
|
|
|
|
text = parentSymbol->GetFootprint((SCH_SHEET_PATH*) aAuxData, resolve );
|
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, text );
|
|
|
|
|
|
|
|
if( isReplaced )
|
|
|
|
parentSymbol->SetFootprint( (SCH_SHEET_PATH*) aAuxData, text );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-03-12 13:56:44 +00:00
|
|
|
isReplaced = EDA_TEXT::Replace( aSearchData );
|
|
|
|
}
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2011-12-21 20:21:15 +00:00
|
|
|
{
|
2019-08-02 00:10:25 +00:00
|
|
|
isReplaced = EDA_TEXT::Replace( aSearchData );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
|
|
|
if( m_id == SHEETFILENAME && isReplaced )
|
|
|
|
{
|
|
|
|
// If we allowed this we'd have a bunch of work to do here, including warning
|
|
|
|
// about it not being undoable, checking for recursive hierarchies, reloading
|
2020-10-06 13:17:45 +00:00
|
|
|
// sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2011-12-21 20:21:15 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
isReplaced = EDA_TEXT::Replace( aSearchData );
|
|
|
|
}
|
2011-12-21 20:21:15 +00:00
|
|
|
|
|
|
|
return isReplaced;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_FIELD::Rotate( const VECTOR2I& aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pt = GetPosition();
|
|
|
|
RotatePoint( pt, aCenter, 900 );
|
2021-03-19 19:33:06 +00:00
|
|
|
SetPosition( pt );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Symbol Field" ), GetName() );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Text" ), UnescapeString( GetText() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Style" ), GetTextStyleName() );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Text Size" ), MessageTextFromValue( aFrame->GetUserUnits(),
|
|
|
|
GetTextWidth() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
switch ( GetHorizJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
|
2021-09-26 23:22:32 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "H Justification" ), msg );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
switch ( GetVertJustify() )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
|
2021-09-26 23:22:32 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "V Justification" ), msg );
|
2021-09-26 23:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame )
|
|
|
|
{
|
2021-03-09 11:16:47 +00:00
|
|
|
constexpr int START_ID = 1;
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
static wxString back = "HYPERTEXT_BACK";
|
|
|
|
wxMenu menu;
|
|
|
|
SCH_TEXT* label = dynamic_cast<SCH_TEXT*>( m_parent );
|
|
|
|
|
|
|
|
if( label && Schematic() )
|
|
|
|
{
|
|
|
|
auto it = Schematic()->GetPageRefsMap().find( label->GetText() );
|
|
|
|
|
|
|
|
if( it != Schematic()->GetPageRefsMap().end() )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> sheetNames;
|
|
|
|
std::vector<wxString> pageListCopy;
|
|
|
|
|
|
|
|
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
2021-03-04 21:29:41 +00:00
|
|
|
if( !Schematic()->Settings().m_IntersheetRefsListOwnPage )
|
|
|
|
{
|
2021-12-06 12:47:18 +00:00
|
|
|
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
|
2021-10-01 10:52:34 +00:00
|
|
|
alg::delete_matching( pageListCopy, currentPage );
|
2021-03-04 21:29:41 +00:00
|
|
|
|
|
|
|
if( pageListCopy.empty() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:52:34 +00:00
|
|
|
std::sort( pageListCopy.begin(), pageListCopy.end(),
|
|
|
|
[]( const wxString& a, const wxString& b ) -> bool
|
|
|
|
{
|
|
|
|
return StrNumCmp( a, b, true ) < 0;
|
|
|
|
} );
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
|
2020-11-29 16:31:43 +00:00
|
|
|
{
|
|
|
|
if( sheet.size() == 1 )
|
2021-12-06 12:47:18 +00:00
|
|
|
sheetNames[ sheet.GetPageNumber() ] = _( "<root sheet>" );
|
2020-11-29 16:31:43 +00:00
|
|
|
else
|
2021-12-06 12:47:18 +00:00
|
|
|
sheetNames[ sheet.GetPageNumber() ] = sheet.Last()->GetName();
|
2020-11-29 16:31:43 +00:00
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-01-25 00:55:01 +00:00
|
|
|
for( int i = 0; i < (int) pageListCopy.size(); ++i )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-03-09 11:16:47 +00:00
|
|
|
menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
|
|
|
|
pageListCopy[i],
|
|
|
|
sheetNames[ pageListCopy[i] ] ) );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
2021-03-09 11:51:07 +00:00
|
|
|
menu.Append( 999, _( "Back to Previous Selected Sheet" ) );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2021-03-09 11:16:47 +00:00
|
|
|
int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
|
2020-11-17 16:02:47 +00:00
|
|
|
void* param = nullptr;
|
|
|
|
|
2021-01-25 00:55:01 +00:00
|
|
|
if( sel >= 0 && sel < (int) pageListCopy.size() )
|
|
|
|
param = (void*) &pageListCopy[ sel ];
|
|
|
|
else if( sel == 999 )
|
2020-11-17 16:02:47 +00:00
|
|
|
param = (void*) &back;
|
|
|
|
|
|
|
|
if( param )
|
|
|
|
aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
|
|
|
|
|
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( m_id < MANDATORY_FIELDS )
|
|
|
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
|
|
|
|
else if( m_name.IsEmpty() && aUseDefaultName )
|
2020-03-06 20:02:58 +00:00
|
|
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
if( m_id < SHEET_MANDATORY_FIELDS )
|
|
|
|
return SCH_SHEET::GetDefaultFieldName( m_id );
|
|
|
|
else if( m_name.IsEmpty() && aUseDefaultName )
|
2020-03-06 20:02:58 +00:00
|
|
|
return SCH_SHEET::GetDefaultFieldName( m_id );
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
else if( m_parent && m_parent->IsType( labelTypes ) )
|
|
|
|
{
|
|
|
|
return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( "Unhandled field owner type." );
|
|
|
|
return m_name;
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
wxString SCH_FIELD::GetCanonicalName() const
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
|
|
|
switch( m_id )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
case REFERENCE_FIELD: return wxT( "Reference" );
|
|
|
|
case VALUE_FIELD: return wxT( "Value" );
|
|
|
|
case FOOTPRINT_FIELD: return wxT( "Footprint" );
|
|
|
|
case DATASHEET_FIELD: return wxT( "Datasheet" );
|
2021-10-12 20:05:37 +00:00
|
|
|
default: return m_name;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
|
|
|
switch( m_id )
|
|
|
|
{
|
|
|
|
case SHEETNAME: return wxT( "Sheetname" );
|
|
|
|
case SHEETFILENAME: return wxT( "Sheetfile" );
|
2021-10-12 20:05:37 +00:00
|
|
|
default: return m_name;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( m_parent && m_parent->IsType( labelTypes ) )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
// These should be stored in canonical format, but just in case:
|
|
|
|
if( m_name == _( "Net Class" ) )
|
|
|
|
return wxT( "Netclass" );
|
|
|
|
else if (m_name == _( "Sheet References" ) )
|
|
|
|
return wxT( "Intersheetrefs" );
|
|
|
|
else
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-02 13:54:27 +00:00
|
|
|
if( m_parent )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxString::Format( "Unhandled field owner type (id %d, parent type %d).",
|
|
|
|
m_id, m_parent->Type() ) );
|
|
|
|
}
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
return m_name;
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS SCH_FIELD::GetMenuImage() const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
|
|
|
switch( m_id )
|
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
case REFERENCE_FIELD: return BITMAPS::edit_comp_ref;
|
|
|
|
case VALUE_FIELD: return BITMAPS::edit_comp_value;
|
|
|
|
case FOOTPRINT_FIELD: return BITMAPS::edit_comp_footprint;
|
|
|
|
default: return BITMAPS::text;
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::text;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_FIELD::HitTest( const VECTOR2I& 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
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_FIELD::Plot( PLOTTER* aPlotter ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2020-09-08 19:18:50 +00:00
|
|
|
RENDER_SETTINGS* settings = aPlotter->RenderSettings();
|
|
|
|
COLOR4D color = settings->GetLayerColor( GetLayer() );
|
|
|
|
int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
|
|
|
|
|
|
|
|
penWidth = std::max( penWidth, settings->GetMinPenWidth() );
|
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;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Calculate the text orientation, according to the symbol orientation/mirror
|
2021-12-28 22:13:54 +00:00
|
|
|
EDA_ANGLE orient = GetTextAngle();
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
if( orient.IsHorizontal() )
|
|
|
|
orient = EDA_ANGLE::VERTICAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
orient = EDA_ANGLE::HORIZONTAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
/*
|
2020-11-15 17:03:27 +00:00
|
|
|
* Calculate the text justification, according to the symbol orientation/mirror.
|
|
|
|
* This is a bit complicated due to cumulative calculations:
|
2011-06-17 13:24:22 +00:00
|
|
|
* - numerous cases (mirrored or not, rotation)
|
2020-11-15 17:03:27 +00:00
|
|
|
* - the plotter's Text function will also recalculate H and V justifications according to
|
|
|
|
* the text orientation.
|
|
|
|
* - When a symbol is mirrored, the text is not mirrored and justifications are complicated
|
|
|
|
* to calculate so the easier way is to use no justifications (centered text) and use
|
|
|
|
* GetBoundingBox to know the text coordinate considered as centered
|
2011-06-17 13:24:22 +00:00
|
|
|
*/
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_CENTER;
|
|
|
|
GR_TEXT_V_ALIGN_T vjustify = GR_TEXT_V_ALIGN_CENTER;
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I textpos = GetBoundingBox().Centre();
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
aPlotter->Text( textpos, color, GetShownText(), orient, GetTextSize(), hjustify, vjustify,
|
2020-04-18 20:04:41 +00:00
|
|
|
penWidth, IsItalic(), IsBold() );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
2021-05-05 21:41:51 +00:00
|
|
|
// Actual positions are calculated by the rotation/mirror transform of the parent symbol
|
|
|
|
// of the field. The inverse transform is used to calculate the position relative to the
|
|
|
|
// parent symbol.
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
SetTextPos( relPos + parentSymbol->GetPosition() );
|
2020-03-30 11:26:14 +00:00
|
|
|
return;
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
2020-03-12 13:56:44 +00:00
|
|
|
SetTextPos( aPosition );
|
2011-10-21 18:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_FIELD::GetPosition() const
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
return relativePos + parentSymbol->GetPosition();
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2011-10-21 18:17:51 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
return GetTextPos();
|
2011-10-21 18:17:51 +00:00
|
|
|
}
|
2020-01-28 20:33:23 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I SCH_FIELD::GetParentPosition() const
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
2022-01-04 01:00:40 +00:00
|
|
|
return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-28 20:33:23 +00:00
|
|
|
bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
|
|
|
auto field = static_cast<const SCH_FIELD*>( &aItem );
|
|
|
|
|
|
|
|
if( GetId() != field->GetId() )
|
|
|
|
return GetId() < field->GetId();
|
|
|
|
|
|
|
|
if( GetText() != field->GetText() )
|
|
|
|
return GetText() < field->GetText();
|
|
|
|
|
|
|
|
if( GetLibPosition().x != field->GetLibPosition().x )
|
|
|
|
return GetLibPosition().x < field->GetLibPosition().x;
|
|
|
|
|
|
|
|
if( GetLibPosition().y != field->GetLibPosition().y )
|
|
|
|
return GetLibPosition().y < field->GetLibPosition().y;
|
|
|
|
|
|
|
|
return GetName() < field->GetName();
|
|
|
|
}
|