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
|
2024-04-15 07:56:19 +00:00
|
|
|
* Copyright (C) 2004-2024 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>
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <common.h> // for ExpandTextVars
|
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>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-03-26 11:02:59 +00:00
|
|
|
#include <kiway.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>
|
2022-01-24 13:40:39 +00:00
|
|
|
#include <sch_label.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-11-17 16:02:47 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2022-08-27 22:28:31 +00:00
|
|
|
#include <tools/sch_navigate_tool.h>
|
2022-01-07 17:42:43 +00:00
|
|
|
#include <font/outline_font.h>
|
2023-08-02 19:11:59 +00:00
|
|
|
#include "sim/sim_lib_mgr.h"
|
2022-01-07 17:42:43 +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 ) :
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_ITEM( aParent, SCH_FIELD_T ),
|
|
|
|
EDA_TEXT( schIUScale, wxEmptyString ),
|
|
|
|
m_id( 0 ),
|
|
|
|
m_showName( false ),
|
|
|
|
m_allowAutoPlace( true ),
|
|
|
|
m_autoAdded( false ),
|
|
|
|
m_showInChooser( true ),
|
|
|
|
m_renderCacheValid( false ),
|
|
|
|
m_lastResolvedColor( COLOR4D::UNSPECIFIED )
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( aName.IsEmpty() )
|
|
|
|
SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldId ) );
|
|
|
|
else
|
|
|
|
SetName( aName );
|
|
|
|
|
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
|
2024-04-15 16:19:19 +00:00
|
|
|
SetVisible( true );
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName) :
|
|
|
|
SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_ITEM( aField ),
|
|
|
|
EDA_TEXT( aField )
|
2022-01-07 17:42:43 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
m_id = aField.m_id;
|
|
|
|
m_name = aField.m_name;
|
|
|
|
m_showName = aField.m_showName;
|
|
|
|
m_allowAutoPlace = aField.m_allowAutoPlace;
|
2023-07-12 15:28:23 +00:00
|
|
|
m_isNamedVariable = aField.m_isNamedVariable;
|
2024-04-12 21:00:41 +00:00
|
|
|
m_autoAdded = aField.m_autoAdded;
|
|
|
|
m_showInChooser = aField.m_showInChooser;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
m_renderCache.clear();
|
|
|
|
|
|
|
|
for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
|
|
|
|
{
|
2023-08-26 15:12:12 +00:00
|
|
|
if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
|
|
|
|
else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
|
2022-01-07 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_renderCacheValid = aField.m_renderCacheValid;
|
|
|
|
m_renderCachePos = aField.m_renderCachePos;
|
2022-09-24 22:50:52 +00:00
|
|
|
|
|
|
|
m_lastResolvedColor = aField.m_lastResolvedColor;
|
2022-01-07 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField )
|
|
|
|
{
|
|
|
|
EDA_TEXT::operator=( aField );
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
m_id = aField.m_id;
|
|
|
|
m_name = aField.m_name;
|
|
|
|
m_showName = aField.m_showName;
|
|
|
|
m_allowAutoPlace = aField.m_allowAutoPlace;
|
|
|
|
m_isNamedVariable = aField.m_isNamedVariable;
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
m_renderCache.clear();
|
|
|
|
|
|
|
|
for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
|
|
|
|
{
|
2023-08-26 15:12:12 +00:00
|
|
|
if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
|
|
|
|
else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
|
|
|
|
m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
|
2022-01-07 17:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_renderCacheValid = aField.m_renderCacheValid;
|
|
|
|
m_renderCachePos = aField.m_renderCachePos;
|
|
|
|
|
2022-09-24 22:50:52 +00:00
|
|
|
m_lastResolvedColor = aField.m_lastResolvedColor;
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
void SCH_FIELD::Copy( SCH_FIELD* aTarget ) const
|
|
|
|
{
|
|
|
|
*aTarget = *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 14:47:51 +00:00
|
|
|
void SCH_FIELD::SetId( int aId )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-04-12 21:00:41 +00:00
|
|
|
else if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_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-08-20 09:27:35 +00:00
|
|
|
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
wxString SCH_FIELD::GetShownName() const
|
|
|
|
{
|
|
|
|
return m_isNamedVariable ? GetTextVars( GetName() ) : GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
|
|
|
|
int aDepth ) const
|
2011-10-21 18:17:51 +00:00
|
|
|
{
|
2024-05-29 21:52:39 +00:00
|
|
|
std::function<bool( wxString* )> libSymbolResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( m_parent );
|
|
|
|
return symbol->ResolveTextVar( token, aDepth + 1 );
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2023-11-11 17:41:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
|
|
|
|
return symbol->ResolveTextVar( aPath, token, aDepth + 1 );
|
2020-04-05 19:51:48 +00:00
|
|
|
};
|
|
|
|
|
2024-04-20 20:38:35 +00:00
|
|
|
std::function<bool( wxString* )> schematicResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
2024-05-29 21:52:39 +00:00
|
|
|
if( !aPath )
|
|
|
|
return false;
|
|
|
|
|
2024-04-20 20:38:35 +00:00
|
|
|
if( SCHEMATIC* schematic = Schematic() )
|
|
|
|
return schematic->ResolveTextVar( aPath, token, aDepth + 1 );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
std::function<bool( wxString* )> sheetResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
2024-05-29 21:52:39 +00:00
|
|
|
if( !aPath )
|
|
|
|
return false;
|
|
|
|
|
2023-11-11 17:41:44 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
|
|
|
|
|
2024-04-20 20:38:35 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
2023-11-11 17:41:44 +00:00
|
|
|
SCH_SHEET_PATH path = *aPath;
|
|
|
|
path.push_back( sheet );
|
|
|
|
|
2024-04-20 20:38:35 +00:00
|
|
|
bool retval = sheet->ResolveTextVar( &path, token, aDepth + 1 );
|
|
|
|
|
|
|
|
if( schematic )
|
|
|
|
retval |= schematic->ResolveTextVar( &path, token, aDepth + 1 );
|
|
|
|
|
|
|
|
return retval;
|
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
|
|
|
|
{
|
2024-05-29 21:52:39 +00:00
|
|
|
if( !aPath )
|
|
|
|
return false;
|
|
|
|
|
2023-11-11 17:41:44 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
|
|
|
return label->ResolveTextVar( aPath, token, aDepth + 1 );
|
2020-11-17 16:02:47 +00:00
|
|
|
};
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2023-04-25 10:42:58 +00:00
|
|
|
if( IsNameShown() && aAllowExtraText )
|
2023-07-12 15:28:23 +00:00
|
|
|
text = GetShownName() << wxS( ": " ) << text;
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2022-09-22 17:04:17 +00:00
|
|
|
if( text == wxS( "~" ) ) // Legacy placeholder for empty string
|
|
|
|
text = wxS( "" );
|
2024-04-20 20:38:35 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 10 && text.Contains( wxT( "${" ) ); ++ii )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-04-24 20:33:59 +00:00
|
|
|
if( aDepth < 10 )
|
|
|
|
{
|
2024-05-29 21:52:39 +00:00
|
|
|
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
|
|
|
|
text = ExpandTextVars( text, &libSymbolResolver );
|
|
|
|
else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2023-01-17 16:54:08 +00:00
|
|
|
text = ExpandTextVars( text, &symbolResolver );
|
2020-11-14 18:11:28 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
2023-01-17 16:54:08 +00:00
|
|
|
text = ExpandTextVars( text, &sheetResolver );
|
2022-08-20 09:27:35 +00:00
|
|
|
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
|
2023-01-17 16:54:08 +00:00
|
|
|
text = ExpandTextVars( text, &labelResolver );
|
|
|
|
else if( Schematic() )
|
2024-04-20 20:38:35 +00:00
|
|
|
{
|
2023-01-17 16:54:08 +00:00
|
|
|
text = ExpandTextVars( text, &Schematic()->Prj() );
|
2024-04-20 20:38:35 +00:00
|
|
|
text = ExpandTextVars( text, &schematicResolver );
|
|
|
|
}
|
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
|
|
|
|
2024-05-29 21:52:39 +00:00
|
|
|
if( m_id == REFERENCE_FIELD && aPath )
|
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 )
|
2023-11-12 23:42:36 +00:00
|
|
|
text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( aPath ) );
|
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
|
|
|
{
|
2023-10-07 09:40:53 +00:00
|
|
|
if( m_id == SHEETFILENAME && aAllowExtraText && !IsNameShown() )
|
|
|
|
text = _( "File:" ) + wxS( " " ) + text;
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 18:17:51 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-28 19:46:39 +00:00
|
|
|
wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
|
|
|
|
{
|
|
|
|
if( SCHEMATIC* schematic = Schematic() )
|
|
|
|
return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
|
|
|
|
else
|
2024-04-12 21:00:41 +00:00
|
|
|
return GetShownText( nullptr, aAllowExtraText, aDepth );
|
2023-05-28 19:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
wxString SCH_FIELD::GetFullText( int unit ) const
|
|
|
|
{
|
|
|
|
if( GetId() != REFERENCE_FIELD )
|
|
|
|
return GetText();
|
|
|
|
|
|
|
|
wxString text = GetText();
|
|
|
|
text << wxT( "?" );
|
|
|
|
|
|
|
|
if( GetParentSymbol() && GetParentSymbol()->IsMulti() )
|
|
|
|
text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2023-05-28 19:46:39 +00:00
|
|
|
|
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-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* SCH_FIELD::getDrawFont() const
|
2022-01-07 00:47:23 +00:00
|
|
|
{
|
|
|
|
KIFONT::FONT* font = EDA_TEXT::GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
void SCH_FIELD::ClearCaches()
|
|
|
|
{
|
|
|
|
ClearRenderCache();
|
|
|
|
EDA_TEXT::ClearBoundingBoxCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::ClearRenderCache()
|
|
|
|
{
|
|
|
|
EDA_TEXT::ClearRenderCache();
|
|
|
|
m_renderCacheValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>*
|
|
|
|
SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
|
|
|
|
TEXT_ATTRIBUTES& aAttrs ) const
|
|
|
|
{
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
if( font->IsOutline() )
|
2022-01-07 17:42:43 +00:00
|
|
|
{
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
|
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
if( m_renderCache.empty() || !m_renderCacheValid )
|
|
|
|
{
|
|
|
|
m_renderCache.clear();
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs,
|
|
|
|
GetFontMetrics() );
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
m_renderCachePos = forPosition;
|
|
|
|
m_renderCacheValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_renderCachePos != forPosition )
|
|
|
|
{
|
|
|
|
VECTOR2I delta = forPosition - m_renderCachePos;
|
|
|
|
|
|
|
|
for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
|
2024-03-18 22:10:36 +00:00
|
|
|
{
|
|
|
|
if( glyph->IsOutline() )
|
|
|
|
static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
|
|
|
|
else
|
|
|
|
static_cast<KIFONT::STROKE_GLYPH*>( glyph.get() )->Move( delta );
|
|
|
|
}
|
2022-01-07 17:42:43 +00:00
|
|
|
|
|
|
|
m_renderCachePos = forPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &m_renderCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_FIELD::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
wxString text;
|
|
|
|
|
|
|
|
if( Schematic() )
|
|
|
|
text = GetShownText( &Schematic()->CurrentSheet(), true );
|
|
|
|
else
|
|
|
|
text = GetShownText( true );
|
|
|
|
|
|
|
|
if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
COLOR4D color = aSettings->GetLayerColor( IsForceVisible() ? LAYER_HIDDEN : m_layer );
|
|
|
|
bool blackAndWhiteMode = GetGRForceBlackPenState();
|
|
|
|
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
|
|
|
|
|
2022-10-21 21:55:01 +00:00
|
|
|
COLOR4D bg = aSettings->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( IsForceVisible() )
|
|
|
|
bg = aSettings->GetLayerColor( LAYER_HIDDEN );
|
|
|
|
|
2022-04-27 21:45:22 +00:00
|
|
|
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
color = GetTextColor();
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
color.Desaturate( );
|
|
|
|
color = color.Mix( bg, 0.5f );
|
|
|
|
}
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Calculate the text orientation according to the symbol orientation.
|
2024-04-12 21:00:41 +00:00
|
|
|
EDA_ANGLE orient = GetTextAngle();
|
|
|
|
VECTOR2I textpos = GetTextPos();
|
|
|
|
GR_TEXT_H_ALIGN_T hjustify = GetHorizJustify();
|
|
|
|
GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
|
|
|
|
KIFONT::FONT* font = GetFont();
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
textpos = aSettings->TransformCoordinate( GetTextPos() ) + aOffset;
|
|
|
|
}
|
|
|
|
else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Calculate the text justification, according to the symbol orientation/mirror.
|
|
|
|
* This is a bit complicated due to cumulative calculations:
|
|
|
|
* - numerous cases (mirrored or not, rotation)
|
|
|
|
* - the GRText function will also recalculate H and V justifications according to the
|
|
|
|
* text orientation.
|
|
|
|
* - when 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
|
|
|
|
*/
|
|
|
|
hjustify = GR_TEXT_H_ALIGN_CENTER;
|
|
|
|
vjustify = GR_TEXT_V_ALIGN_CENTER;
|
|
|
|
textpos = GetBoundingBox().Centre() + aOffset;
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( aSettings->m_Transform.y1 ) // Rotate symbol 90 degrees.
|
2020-03-12 13:56:44 +00:00
|
|
|
{
|
2022-01-13 12:29:46 +00:00
|
|
|
if( orient == ANGLE_HORIZONTAL )
|
|
|
|
orient = ANGLE_VERTICAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
else
|
2022-01-13 12:29:46 +00:00
|
|
|
orient = ANGLE_HORIZONTAL;
|
2020-03-12 13:56:44 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2024-04-12 21:00:41 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
|
2023-06-17 17:11:16 +00:00
|
|
|
{
|
|
|
|
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
|
|
|
|
textpos += label->GetSchematicTextOffset( aSettings );
|
|
|
|
}
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
GRPrintText( DC, textpos, color, text, orient, GetTextSize(), hjustify, vjustify, penWidth,
|
|
|
|
IsItalic(), IsBold(), font, GetFontMetrics() );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
void SCH_FIELD::ImportValues( const SCH_FIELD& aSource )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
SetAttributes( aSource );
|
2022-09-03 20:54:05 +00:00
|
|
|
SetNameShown( aSource.IsNameShown() );
|
2022-09-04 16:34:16 +00:00
|
|
|
SetCanAutoplace( aSource.CanAutoplace() );
|
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
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
wxCHECK_RET( aItem && aItem->Type() == SCH_FIELD_T, wxT( "Cannot swap with invalid item." ) );
|
2023-07-08 17:37:47 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD* item = static_cast<SCH_FIELD*>( aItem );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, item->m_layer );
|
2022-09-03 20:54:05 +00:00
|
|
|
std::swap( m_showName, item->m_showName );
|
2022-09-04 16:34:16 +00:00
|
|
|
std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
|
2023-07-12 15:28:23 +00:00
|
|
|
std::swap( m_isNamedVariable, item->m_isNamedVariable );
|
2019-08-02 00:10:25 +00:00
|
|
|
SwapText( *item );
|
2021-12-28 22:13:54 +00:00
|
|
|
SwapAttributes( *item );
|
2022-09-24 22:50:52 +00:00
|
|
|
|
|
|
|
std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COLOR4D SCH_FIELD::GetFieldColor() const
|
|
|
|
{
|
|
|
|
if( GetTextColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
|
|
|
m_lastResolvedColor = GetTextColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
|
|
|
|
|
|
|
|
if( parentLabel && !parentLabel->IsConnectivityDirty() )
|
|
|
|
m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor();
|
2023-01-23 09:22:42 +00:00
|
|
|
else
|
|
|
|
m_lastResolvedColor = GetTextColor();
|
2022-09-24 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_lastResolvedColor;
|
2008-09-20 17:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-01 11:12:48 +00:00
|
|
|
void SCH_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
aCount = 2;
|
2024-04-13 18:53:58 +00:00
|
|
|
aLayers[0] = GetDefaultLayer();
|
2023-06-01 11:12:48 +00:00
|
|
|
aLayers[1] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_LAYER_ID SCH_FIELD::GetDefaultLayer() const
|
|
|
|
{
|
2024-04-13 18:53:58 +00:00
|
|
|
if( m_parent && ( m_parent->Type() == LIB_SYMBOL_T || m_parent->Type() == SCH_SYMBOL_T ) )
|
2024-04-12 21:00:41 +00:00
|
|
|
{
|
2024-04-13 18:53:58 +00:00
|
|
|
if( m_id == REFERENCE_FIELD )
|
|
|
|
return LAYER_REFERENCEPART;
|
|
|
|
else if( m_id == VALUE_FIELD )
|
|
|
|
return LAYER_VALUEPART;
|
2024-04-12 21:00:41 +00:00
|
|
|
}
|
2024-04-15 07:56:19 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
if( m_id == SHEETNAME )
|
|
|
|
return LAYER_SHEETNAME;
|
|
|
|
else if( m_id == SHEETFILENAME )
|
|
|
|
return LAYER_SHEETFILENAME;
|
|
|
|
else
|
|
|
|
return LAYER_SHEETFIELDS;
|
|
|
|
}
|
2024-04-13 18:53:58 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_LABEL_T )
|
|
|
|
{
|
|
|
|
if( GetCanonicalName() == wxT( "Netclass" ) )
|
|
|
|
return LAYER_NETCLASS_REFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LAYER_FIELDS;
|
2024-04-12 21:00:41 +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() )
|
2022-01-13 12:29:46 +00:00
|
|
|
orient = ANGLE_VERTICAL;
|
2021-11-01 21:05:30 +00:00
|
|
|
else
|
2022-01-13 12:29:46 +00:00
|
|
|
orient = ANGLE_HORIZONTAL;
|
2021-11-01 21:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return orient;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_FIELD::GetBoundingBox() const
|
2008-09-20 17:20:40 +00:00
|
|
|
{
|
2024-04-27 12:47:56 +00:00
|
|
|
BOX2I bbox = GetTextBox();
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
// Calculate the bounding box position relative to the parent:
|
|
|
|
VECTOR2I origin = GetParentPosition();
|
|
|
|
VECTOR2I pos = GetTextPos() - origin;
|
|
|
|
VECTOR2I begin = bbox.GetOrigin() - origin;
|
|
|
|
VECTOR2I end = bbox.GetEnd() - origin;
|
|
|
|
RotatePoint( begin, pos, GetTextAngle() );
|
|
|
|
RotatePoint( end, pos, GetTextAngle() );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
// Now, apply the symbol transform (mirror/rot)
|
|
|
|
TRANSFORM transform;
|
2020-03-12 13:56:44 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
2024-05-08 10:27:57 +00:00
|
|
|
transform = static_cast<SCH_SYMBOL*>( m_parent )->GetTransform();
|
2024-04-12 21:00:41 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
bbox.SetOrigin( transform.TransformCoordinate( begin ) );
|
|
|
|
bbox.SetEnd( transform.TransformCoordinate( end ) );
|
2024-04-12 21:00:41 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
bbox.Move( origin );
|
|
|
|
bbox.Normalize();
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return bbox;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-07 23:08:47 +00:00
|
|
|
void SCH_FIELD::SetEffectiveHorizJustify( GR_TEXT_H_ALIGN_T aJustify )
|
|
|
|
{
|
|
|
|
GR_TEXT_H_ALIGN_T actualJustify;
|
|
|
|
|
|
|
|
switch( aJustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
|
|
|
actualJustify = IsHorizJustifyFlipped() ? GR_TEXT_H_ALIGN_RIGHT : GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
|
|
|
actualJustify = IsHorizJustifyFlipped() ? GR_TEXT_H_ALIGN_LEFT : GR_TEXT_H_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
actualJustify = aJustify;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetHorizJustify( actualJustify );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-07 23:08:47 +00:00
|
|
|
void SCH_FIELD::SetEffectiveVertJustify( GR_TEXT_V_ALIGN_T aJustify )
|
|
|
|
{
|
|
|
|
GR_TEXT_V_ALIGN_T actualJustify;
|
|
|
|
|
|
|
|
switch( aJustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
|
|
|
actualJustify = IsVertJustifyFlipped() ? GR_TEXT_V_ALIGN_BOTTOM : GR_TEXT_V_ALIGN_TOP;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
|
|
|
actualJustify = IsVertJustifyFlipped() ? GR_TEXT_V_ALIGN_TOP : GR_TEXT_V_ALIGN_BOTTOM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
actualJustify = aJustify;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetVertJustify( actualJustify );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
bool searchHiddenFields = false;
|
|
|
|
bool searchAndReplace = false;
|
|
|
|
bool replaceReferences = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData ); // downcast
|
|
|
|
searchHiddenFields = schSearchData.searchAllFields;
|
|
|
|
searchAndReplace = schSearchData.searchAndReplace;
|
|
|
|
replaceReferences = schSearchData.replaceReferences;
|
|
|
|
}
|
2022-09-18 12:42:42 +00:00
|
|
|
catch( const std::bad_cast& )
|
2022-08-05 02:40:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString text = UnescapeString( GetText() );
|
2019-05-30 13:39:31 +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
|
|
|
{
|
2023-11-12 23:42:36 +00:00
|
|
|
SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
|
|
|
|
text = parentSymbol->GetRef( sheet );
|
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 )
|
2023-11-12 23:42:36 +00:00
|
|
|
text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( sheet ) );
|
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
|
|
|
|
|
|
|
|
2023-08-02 19:11:59 +00:00
|
|
|
void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks,
|
|
|
|
wxStyledTextEvent &aEvent ) const
|
|
|
|
{
|
|
|
|
SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( GetParent() );
|
|
|
|
SCHEMATIC* schematic = parent ? parent->Schematic() : nullptr;
|
|
|
|
|
|
|
|
if( !schematic )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxStyledTextCtrl* scintilla = aScintillaTricks->Scintilla();
|
|
|
|
int key = aEvent.GetKey();
|
|
|
|
|
|
|
|
wxArrayString autocompleteTokens;
|
|
|
|
int pos = scintilla->GetCurrentPos();
|
|
|
|
int start = scintilla->WordStartPosition( pos, true );
|
|
|
|
wxString partial;
|
|
|
|
|
2023-10-01 13:04:25 +00:00
|
|
|
// Multi-line fields are not allowed. So remove '\n' if entered.
|
2023-08-02 19:11:59 +00:00
|
|
|
if( key == '\n' )
|
|
|
|
{
|
|
|
|
wxString text = scintilla->GetText();
|
|
|
|
int currpos = scintilla->GetCurrentPos();
|
|
|
|
text.Replace( wxS( "\n" ), wxS( "" ) );
|
|
|
|
scintilla->SetText( text );
|
|
|
|
scintilla->GotoPos( currpos-1 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto textVarRef =
|
|
|
|
[&]( int pt )
|
|
|
|
{
|
|
|
|
return pt >= 2
|
|
|
|
&& scintilla->GetCharAt( pt - 2 ) == '$'
|
|
|
|
&& scintilla->GetCharAt( pt - 1 ) == '{';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check for cross-reference
|
|
|
|
if( start > 1 && scintilla->GetCharAt( start - 1 ) == ':' )
|
|
|
|
{
|
|
|
|
int refStart = scintilla->WordStartPosition( start - 1, true );
|
|
|
|
|
|
|
|
if( textVarRef( refStart ) )
|
|
|
|
{
|
|
|
|
partial = scintilla->GetRange( start, pos );
|
|
|
|
|
|
|
|
wxString ref = scintilla->GetRange( refStart, start - 1 );
|
|
|
|
|
|
|
|
if( ref == wxS( "OP" ) )
|
|
|
|
{
|
|
|
|
// SPICE operating points use ':' syntax for ports
|
|
|
|
if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
NULL_REPORTER devnull;
|
2023-08-02 19:11:59 +00:00
|
|
|
SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
|
|
|
|
SIM_LIB_MGR mgr( &schematic->Prj() );
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, devnull ).model;
|
2023-08-02 19:11:59 +00:00
|
|
|
|
|
|
|
for( wxString pin : model.GetPinNames() )
|
|
|
|
{
|
|
|
|
if( pin.StartsWith( '<' ) && pin.EndsWith( '>' ) )
|
|
|
|
autocompleteTokens.push_back( pin.Mid( 1, pin.Length() - 2 ) );
|
|
|
|
else
|
|
|
|
autocompleteTokens.push_back( pin );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_REFERENCE_LIST refs;
|
|
|
|
SCH_SYMBOL* refSymbol = nullptr;
|
|
|
|
|
2024-06-06 16:58:48 +00:00
|
|
|
schematic->BuildUnorderedSheetList().GetSymbols( refs );
|
2023-08-02 19:11:59 +00:00
|
|
|
|
|
|
|
for( size_t jj = 0; jj < refs.GetCount(); jj++ )
|
|
|
|
{
|
|
|
|
if( refs[ jj ].GetSymbol()->GetRef( &refs[ jj ].GetSheetPath(), true ) == ref )
|
|
|
|
{
|
|
|
|
refSymbol = refs[ jj ].GetSymbol();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( refSymbol )
|
|
|
|
refSymbol->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( textVarRef( start ) )
|
|
|
|
{
|
|
|
|
partial = scintilla->GetTextRange( start, pos );
|
|
|
|
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent );
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( parent );
|
|
|
|
SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( parent );
|
|
|
|
|
|
|
|
if( symbol )
|
|
|
|
{
|
|
|
|
symbol->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
|
|
|
|
if( schematic->CurrentSheet().Last() )
|
|
|
|
schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sheet )
|
|
|
|
sheet->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
|
|
|
|
if( label )
|
|
|
|
label->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
|
|
|
|
for( std::pair<wxString, wxString> entry : schematic->Prj().GetTextVars() )
|
|
|
|
autocompleteTokens.push_back( entry.first );
|
|
|
|
}
|
|
|
|
|
|
|
|
aScintillaTricks->DoAutocomplete( partial, autocompleteTokens );
|
|
|
|
scintilla->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 23:43:03 +00:00
|
|
|
bool SCH_FIELD::IsReplaceable() const
|
|
|
|
{
|
2023-01-18 17:49:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
|
2011-12-21 20:21:15 +00:00
|
|
|
{
|
2022-08-05 02:40:38 +00:00
|
|
|
bool replaceReferences = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
|
|
|
|
replaceReferences = schSearchData.replaceReferences;
|
|
|
|
}
|
2022-09-18 12:42:42 +00:00
|
|
|
catch( const std::bad_cast& )
|
2022-08-05 02:40:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-30 16:54:15 +00:00
|
|
|
wxString 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
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
if( !replaceReferences )
|
2020-08-12 14:04:51 +00:00
|
|
|
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." ) );
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
text = parentSymbol->GetField( VALUE_FIELD )->GetText();
|
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 )
|
2022-11-25 14:25:39 +00:00
|
|
|
parentSymbol->SetValueFieldText( text );
|
2021-04-30 16:54:15 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
text = parentSymbol->GetField( FOOTPRINT_FIELD )->GetText();
|
2021-04-30 16:54:15 +00:00
|
|
|
isReplaced = EDA_ITEM::Replace( aSearchData, text );
|
|
|
|
|
|
|
|
if( isReplaced )
|
2022-11-25 14:25:39 +00:00
|
|
|
parentSymbol->SetFootprintFieldText( text );
|
2021-04-30 16:54:15 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void SCH_FIELD::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pt = GetPosition();
|
2024-05-12 19:42:45 +00:00
|
|
|
RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
|
2021-03-19 19:33:06 +00:00
|
|
|
SetPosition( pt );
|
2024-04-12 21:00:41 +00:00
|
|
|
|
|
|
|
SetTextAngle( GetTextAngle() != ANGLE_HORIZONTAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::MirrorHorizontally( int aCenter )
|
|
|
|
{
|
|
|
|
int x = GetTextPos().x;
|
|
|
|
|
|
|
|
x -= aCenter;
|
|
|
|
x *= -1;
|
|
|
|
x += aCenter;
|
|
|
|
|
|
|
|
SetTextX( x );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::MirrorVertically( int aCenter )
|
|
|
|
{
|
|
|
|
int y = GetTextPos().y;
|
|
|
|
|
|
|
|
y -= aCenter;
|
|
|
|
y *= -1;
|
|
|
|
y += aCenter;
|
|
|
|
|
|
|
|
SetTextY( y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::BeginEdit( const VECTOR2I& aPosition )
|
|
|
|
{
|
|
|
|
SetTextPos( aPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::CalcEdit( const VECTOR2I& aPosition )
|
|
|
|
{
|
|
|
|
SetTextPos( aPosition );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
return wxString::Format( "%s '%s'", UnescapeString( GetName() ), KIUI::EllipsizeMenuText( GetText() ) );
|
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;
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2023-05-05 13:21:56 +00:00
|
|
|
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, 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
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
|
2022-04-26 17:52:53 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Style" ), GetTextStyleName() );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
|
2021-09-26 23:22:32 +00:00
|
|
|
|
|
|
|
switch ( GetHorizJustify() )
|
|
|
|
{
|
2024-02-16 12:54:28 +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;
|
|
|
|
case GR_TEXT_H_ALIGN_INDETERMINATE: msg = INDETERMINATE_STATE; 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() )
|
|
|
|
{
|
2024-02-16 12:54:28 +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;
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE: msg = INDETERMINATE_STATE; 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
void SCH_FIELD::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2021-03-09 11:16:47 +00:00
|
|
|
constexpr int START_ID = 1;
|
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
if( IsHypertext() )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
2024-03-23 16:50:00 +00:00
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
|
|
|
SCH_SHEET_PATH* sheet = &label->Schematic()->CurrentSheet();
|
|
|
|
wxMenu menu;
|
|
|
|
wxString href;
|
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
std::vector<std::pair<wxString, wxString>> pages;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2024-03-23 16:50:00 +00:00
|
|
|
label->GetIntersheetRefs( sheet, &pages );
|
2021-03-04 21:29:41 +00:00
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
for( int i = 0; i < (int) pages.size(); ++i )
|
|
|
|
{
|
|
|
|
menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
|
|
|
|
pages[i].first,
|
|
|
|
pages[i].second ) );
|
|
|
|
}
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
if( sel >= 0 && sel < (int) pages.size() )
|
|
|
|
href = wxT( "#" ) + pages[ sel ].first;
|
|
|
|
else if( sel == 999 )
|
|
|
|
href = SCH_NAVIGATE_TOOL::g_BackLink;
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-08-27 22:28:31 +00:00
|
|
|
if( !href.IsEmpty() )
|
|
|
|
{
|
|
|
|
SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>();
|
2022-09-01 20:15:35 +00:00
|
|
|
navTool->HypertextCommand( href );
|
2020-11-17 16:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
void SCH_FIELD::SetName( const wxString& aName )
|
|
|
|
{
|
|
|
|
m_name = aName;
|
|
|
|
m_isNamedVariable = m_name.StartsWith( wxT( "${" ) );
|
|
|
|
|
|
|
|
if( m_isNamedVariable )
|
|
|
|
EDA_TEXT::SetText( aName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_FIELD::SetText( const wxString& aText )
|
|
|
|
{
|
|
|
|
// Don't allow modification of text value when using named variables
|
|
|
|
// as field name.
|
|
|
|
if( m_isNamedVariable )
|
|
|
|
return;
|
|
|
|
|
2024-06-06 18:46:38 +00:00
|
|
|
// Mandatory fields should not have leading or trailing whitespace.
|
|
|
|
if( IsMandatory() )
|
|
|
|
EDA_TEXT::SetText( aText.Strip( wxString::both ) );
|
|
|
|
else
|
|
|
|
EDA_TEXT::SetText( aText );
|
2023-07-12 15:28:23 +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
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( IsMandatory() )
|
2023-10-03 16:14:03 +00:00
|
|
|
return GetCanonicalFieldName( m_id );
|
2021-10-12 20:05:37 +00:00
|
|
|
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 if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( IsMandatory() )
|
2021-10-12 20:05:37 +00:00
|
|
|
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
|
|
|
}
|
2022-08-20 09:27:35 +00:00
|
|
|
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
|
|
|
|
}
|
2024-04-12 21:00:41 +00:00
|
|
|
|
|
|
|
return m_name;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
wxString SCH_FIELD::GetCanonicalName() const
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
|
2020-03-26 11:02:59 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( IsMandatory() )
|
2023-10-03 16:14:03 +00:00
|
|
|
return GetCanonicalFieldName( m_id );
|
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
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_id == SHEETNAME )
|
|
|
|
return wxT( "Sheetname" );
|
|
|
|
else if( m_id == SHEETFILENAME )
|
|
|
|
return wxT( "Sheetfile" );
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
2022-08-20 09:27:35 +00:00
|
|
|
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
|
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:
|
2022-12-11 17:56:14 +00:00
|
|
|
if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) )
|
2024-01-23 12:37:02 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
return wxT( "Netclass" );
|
2024-01-23 12:37:02 +00:00
|
|
|
}
|
2022-12-12 15:37:27 +00:00
|
|
|
else if( m_name == _( "Sheet References" )
|
|
|
|
|| m_name == wxT( "Sheet References" )
|
|
|
|
|| m_name == wxT( "Intersheet References" ) )
|
2024-01-23 12:37:02 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
return wxT( "Intersheetrefs" );
|
2024-01-23 12:37:02 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2022-01-02 13:54:27 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
return m_name;
|
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
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_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
|
|
|
{
|
2024-04-17 09:44:26 +00:00
|
|
|
if( GetShownText( true ).IsEmpty() )
|
2010-12-10 19:47:44 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I rect = GetBoundingBox();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
// Text in symbol editor can have additional chars (ie: reference designators U? or U?A)
|
|
|
|
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_FIELD temp( *this );
|
|
|
|
temp.SetText( GetFullText() );
|
|
|
|
rect = temp.GetBoundingBox();
|
|
|
|
}
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
|
2022-03-19 16:36:32 +00:00
|
|
|
{
|
|
|
|
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
|
|
|
|
rect.Offset( label->GetSchematicTextOffset( nullptr ) );
|
|
|
|
}
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
return rect.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2024-04-17 09:44:26 +00:00
|
|
|
if( GetShownText( true ).IsEmpty() )
|
2024-04-12 21:00:41 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
2010-12-10 19:47:44 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2022-03-19 16:36:32 +00:00
|
|
|
if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
|
|
|
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
|
|
|
|
rect.Offset( label->GetSchematicTextOffset( nullptr ) );
|
|
|
|
}
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
|
|
|
|
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
wxString text;
|
2024-03-23 16:50:00 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( Schematic() )
|
|
|
|
text = GetShownText( &Schematic()->CurrentSheet(), true );
|
|
|
|
else
|
|
|
|
text = GetShownText( true );
|
|
|
|
|
|
|
|
if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() || aBackground )
|
2022-02-10 19:49:25 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-08 12:32:11 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
|
|
|
|
COLOR4D color = renderSettings->GetLayerColor( GetLayer() );
|
|
|
|
int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
|
2020-09-08 19:18:50 +00:00
|
|
|
|
2024-04-08 12:32:11 +00:00
|
|
|
COLOR4D bg = renderSettings->GetBackgroundColor();;
|
2022-09-16 16:20:36 +00:00
|
|
|
|
2022-10-22 15:02:45 +00:00
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
2022-09-16 16:20:36 +00:00
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
2022-04-27 21:45:22 +00:00
|
|
|
if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
|
|
|
|
color = GetTextColor();
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( aDimmed )
|
|
|
|
{
|
|
|
|
color.Desaturate( );
|
|
|
|
color = color.Mix( bg, 0.5f );
|
|
|
|
}
|
|
|
|
|
2024-04-08 12:32:11 +00:00
|
|
|
penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
// clamp the pen width to be sure the text is readable
|
|
|
|
penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
|
|
|
|
|
2024-04-08 12:32:11 +00:00
|
|
|
if( !IsVisible() && !renderSettings->m_ShowHiddenFields )
|
2011-06-17 13:24:22 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Calculate the text orientation, according to the symbol orientation/mirror
|
2022-08-29 10:52:40 +00:00
|
|
|
EDA_ANGLE orient = GetTextAngle();
|
|
|
|
VECTOR2I textpos = GetTextPos();
|
|
|
|
GR_TEXT_H_ALIGN_T hjustify = GetHorizJustify();
|
|
|
|
GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
if( orient.IsHorizontal() )
|
|
|
|
orient = ANGLE_VERTICAL;
|
|
|
|
else
|
|
|
|
orient = ANGLE_HORIZONTAL;
|
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
2022-08-29 10:52:40 +00:00
|
|
|
/*
|
|
|
|
* Calculate the text justification, according to the symbol orientation/mirror. This is
|
|
|
|
* a bit complicated due to cumulative calculations:
|
|
|
|
* - numerous cases (mirrored or not, rotation)
|
|
|
|
* - 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, and justifications become a nightmare
|
|
|
|
*
|
2024-04-12 21:00:41 +00:00
|
|
|
* So the easier way is to use no justifications (centered text) and use GetBoundingBox
|
|
|
|
* to know the text coordinate considered as centered.
|
2022-08-29 10:52:40 +00:00
|
|
|
*/
|
|
|
|
hjustify = GR_TEXT_H_ALIGN_CENTER;
|
|
|
|
vjustify = GR_TEXT_V_ALIGN_CENTER;
|
|
|
|
textpos = GetBoundingBox().Centre();
|
|
|
|
}
|
2023-02-09 18:01:46 +00:00
|
|
|
else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
|
|
|
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
|
2024-04-08 12:32:11 +00:00
|
|
|
textpos += label->GetSchematicTextOffset( renderSettings );
|
2023-02-09 18:01:46 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
2024-04-08 12:32:11 +00:00
|
|
|
font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
|
2022-10-22 20:32:10 +00:00
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
|
|
|
attrs.m_StrokeWidth = penWidth;
|
|
|
|
attrs.m_Halign = hjustify;
|
|
|
|
attrs.m_Valign = vjustify;
|
|
|
|
attrs.m_Angle = orient;
|
|
|
|
attrs.m_Multiline = false;
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
aPlotter->PlotText( textpos, color, text, attrs, font, GetFontMetrics() );
|
2022-08-27 22:28:31 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( IsHypertext() && Schematic() )
|
2022-08-27 22:28:31 +00:00
|
|
|
{
|
|
|
|
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
|
|
|
|
std::vector<std::pair<wxString, wxString>> pages;
|
|
|
|
std::vector<wxString> pageHrefs;
|
2022-09-06 10:18:09 +00:00
|
|
|
BOX2I bbox = GetBoundingBox();
|
2022-08-27 22:28:31 +00:00
|
|
|
|
2023-03-02 14:04:37 +00:00
|
|
|
wxCHECK( label, /* void */ );
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
label->GetIntersheetRefs( &Schematic()->CurrentSheet(), &pages );
|
2022-08-27 22:28:31 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
for( const auto& [ pageNumber, sheetName ] : pages )
|
|
|
|
pageHrefs.push_back( wxT( "#" ) + pageNumber );
|
2022-08-27 22:28:31 +00:00
|
|
|
|
2024-04-08 12:32:11 +00:00
|
|
|
bbox.Offset( label->GetSchematicTextOffset( renderSettings ) );
|
2022-09-06 10:18:09 +00:00
|
|
|
|
|
|
|
aPlotter->HyperlinkMenu( bbox, pageHrefs );
|
2022-08-27 22:28:31 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
bool SCH_FIELD::IsMandatory() const
|
|
|
|
{
|
|
|
|
if( m_parent && m_parent->Type() == SCH_SHEET_T )
|
|
|
|
return m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS;
|
|
|
|
else
|
|
|
|
return m_id >= 0 && m_id < MANDATORY_FIELDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::operator<( const SCH_ITEM& aItem ) const
|
2020-01-28 20:33:23 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
|
|
|
|
bool SCH_FIELD::operator==(const SCH_ITEM& aOther) const
|
2023-09-14 21:39:42 +00:00
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
return *this == field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
// Identical fields of different symbols are not equal.
|
|
|
|
if( !GetParentSymbol() || !aOther.GetParentSymbol()
|
|
|
|
|| GetParentSymbol()->m_Uuid != aOther.GetParentSymbol()->m_Uuid )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
if( GetId() != aOther.GetId() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
if( GetPosition() != aOther.GetPosition() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
if( IsNamedVariable() != aOther.IsNamedVariable() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
if( IsNameShown() != aOther.IsNameShown() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
2024-04-13 03:05:00 +00:00
|
|
|
if( CanAutoplace() != aOther.CanAutoplace() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
return EDA_TEXT::operator==( aOther );
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
if( m_Uuid == aOther.m_Uuid )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
|
|
|
|
|
2024-01-16 20:43:22 +00:00
|
|
|
double similarity = 0.99; // The UUIDs are different, so we start with non-identity
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( GetId() != field.GetId() )
|
|
|
|
{
|
|
|
|
// We don't allow swapping of mandatory fields, so these cannot be the same item
|
|
|
|
if( GetId() < MANDATORY_FIELDS || field.GetId() < MANDATORY_FIELDS )
|
|
|
|
return 0.0;
|
|
|
|
else
|
2024-01-16 20:43:22 +00:00
|
|
|
similarity *= 0.5;
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
similarity *= SimilarityBase( aOther );
|
|
|
|
|
|
|
|
similarity *= EDA_TEXT::Similarity( field );
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
if( GetPosition() != field.GetPosition() )
|
2024-01-16 20:43:22 +00:00
|
|
|
similarity *= 0.5;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( IsNamedVariable() != field.IsNamedVariable() )
|
2024-01-16 20:43:22 +00:00
|
|
|
similarity *= 0.5;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( IsNameShown() != field.IsNameShown() )
|
2024-01-16 20:43:22 +00:00
|
|
|
similarity *= 0.5;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( CanAutoplace() != field.CanAutoplace() )
|
2024-01-16 20:43:22 +00:00
|
|
|
similarity *= 0.5;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
2024-01-16 20:43:22 +00:00
|
|
|
return similarity;
|
2023-09-14 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
int SCH_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
|
|
|
|
{
|
|
|
|
wxASSERT( aOther.Type() == SCH_FIELD_T );
|
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
int compareFlags = aCompareFlags;
|
|
|
|
|
|
|
|
// For ERC tests, the field position has no matter, so do not test it
|
|
|
|
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC )
|
|
|
|
compareFlags |= SCH_ITEM::COMPARE_FLAGS::SKIP_TST_POS;
|
|
|
|
|
|
|
|
int retv = SCH_ITEM::compare( aOther, compareFlags );
|
2024-04-12 21:00:41 +00:00
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
const SCH_FIELD* tmp = static_cast<const SCH_FIELD*>( &aOther );
|
|
|
|
|
|
|
|
// Equality test will vary depending whether or not the field is mandatory. Otherwise,
|
|
|
|
// sorting is done by ordinal.
|
|
|
|
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
|
|
|
|
{
|
|
|
|
// Mandatory fields have fixed ordinals and their names can vary due to translated field
|
|
|
|
// names. Optional fields have fixed names and their ordinals can vary.
|
|
|
|
if( IsMandatory() )
|
|
|
|
{
|
|
|
|
if( m_id != tmp->m_id )
|
|
|
|
return m_id - tmp->m_id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retv = m_name.Cmp( tmp->m_name );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // assume we're sorting
|
|
|
|
{
|
|
|
|
if( m_id != tmp->m_id )
|
|
|
|
return m_id - tmp->m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ignoreFieldText = false;
|
|
|
|
|
|
|
|
if( m_id == REFERENCE_FIELD && !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY ) )
|
|
|
|
ignoreFieldText = true;
|
|
|
|
|
|
|
|
if( m_id == VALUE_FIELD && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
|
|
|
|
ignoreFieldText = true;
|
|
|
|
|
|
|
|
if( !ignoreFieldText )
|
|
|
|
{
|
|
|
|
retv = GetText().CmpNoCase( tmp->GetText() );
|
|
|
|
|
|
|
|
if( retv != 0 )
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
|
|
|
|
{
|
|
|
|
if( GetTextPos().x != tmp->GetTextPos().x )
|
|
|
|
return GetTextPos().x - tmp->GetTextPos().x;
|
|
|
|
|
|
|
|
if( GetTextPos().y != tmp->GetTextPos().y )
|
|
|
|
return GetTextPos().y - tmp->GetTextPos().y;
|
|
|
|
}
|
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
// For ERC tests, the field size has no matter, so do not test it
|
|
|
|
if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
|
|
|
|
{
|
|
|
|
if( GetTextWidth() != tmp->GetTextWidth() )
|
|
|
|
return GetTextWidth() - tmp->GetTextWidth();
|
2024-04-12 21:00:41 +00:00
|
|
|
|
2024-04-25 17:44:46 +00:00
|
|
|
if( GetTextHeight() != tmp->GetTextHeight() )
|
|
|
|
return GetTextHeight() - tmp->GetTextHeight();
|
|
|
|
}
|
2024-04-12 21:00:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
static struct SCH_FIELD_DESC
|
|
|
|
{
|
|
|
|
SCH_FIELD_DESC()
|
|
|
|
{
|
2024-05-07 23:08:47 +00:00
|
|
|
// These are defined in EDA_TEXT as well but initialization order is
|
|
|
|
// not defined, so this needs to be conditional. Defining in both
|
|
|
|
// places leads to duplicate symbols.
|
|
|
|
auto& h_inst = ENUM_MAP<GR_TEXT_H_ALIGN_T>::Instance();
|
|
|
|
|
|
|
|
if( h_inst.Choices().GetCount() == 0)
|
|
|
|
{
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
|
|
|
|
h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& v_inst = ENUM_MAP<GR_TEXT_V_ALIGN_T>::Instance();
|
|
|
|
|
|
|
|
if( v_inst.Choices().GetCount() == 0)
|
|
|
|
{
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
|
|
|
|
v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
|
|
|
|
}
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_FIELD );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<SCH_FIELD, SCH_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<SCH_FIELD, EDA_TEXT> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ) );
|
|
|
|
|
2024-05-07 23:08:47 +00:00
|
|
|
const wxString textProps = _HKI( "Text Properties" );
|
|
|
|
|
|
|
|
auto horiz = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_H_ALIGN_T>( _HKI( "Horizontal Justification" ),
|
|
|
|
&SCH_FIELD::SetEffectiveHorizJustify, &SCH_FIELD::GetEffectiveHorizJustify );
|
|
|
|
|
|
|
|
propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Horizontal Justification" ), horiz, textProps );
|
|
|
|
|
|
|
|
auto vert = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_V_ALIGN_T>( _HKI( "Vertical Justification" ),
|
|
|
|
&SCH_FIELD::SetEffectiveVertJustify, &SCH_FIELD::GetEffectiveVertJustify );
|
|
|
|
|
|
|
|
propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Vertical Justification" ), vert, textProps );
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Show Field Name" ),
|
|
|
|
&SCH_FIELD::SetNameShown, &SCH_FIELD::IsNameShown ) );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Allow Autoplacement" ),
|
|
|
|
&SCH_FIELD::SetCanAutoplace, &SCH_FIELD::CanAutoplace ) );
|
|
|
|
|
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
|
2023-07-12 15:28:23 +00:00
|
|
|
|
2024-05-07 23:08:47 +00:00
|
|
|
|
2024-02-27 17:48:09 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_FIELD, int>( _HKI( "Text Size" ),
|
|
|
|
&SCH_FIELD::SetSchTextSize, &SCH_FIELD::GetSchTextSize, PROPERTY_DISPLAY::PT_SIZE ),
|
2024-02-28 17:50:51 +00:00
|
|
|
_HKI( "Text Properties" ) );
|
2024-02-27 17:48:09 +00:00
|
|
|
|
2023-07-16 19:19:03 +00:00
|
|
|
propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
|
|
|
|
|
2023-07-12 15:28:23 +00:00
|
|
|
auto isNotNamedVariable =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
|
|
|
|
return !field->IsNamedVariable();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.OverrideWriteability( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Text" ),
|
|
|
|
isNotNamedVariable );
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
} _SCH_FIELD_DESC;
|
2024-05-07 23:08:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
DECLARE_ENUM_TO_WXANY( GR_TEXT_H_ALIGN_T )
|
|
|
|
DECLARE_ENUM_TO_WXANY( GR_TEXT_V_ALIGN_T )
|