2015-12-13 16:56:47 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Chris Pavlina <pavlina.chris@gmail.com>
|
2023-03-23 17:26:32 +00:00
|
|
|
* Copyright (C) 2015, 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-13 16:56:47 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
2021-05-05 21:41:51 +00:00
|
|
|
* Field autoplacer: Tries to find an optimal place for symbol fields, and places them there.
|
|
|
|
* There are two modes: "auto"-autoplace, and "manual" autoplace.
|
|
|
|
* Auto mode is for when the process is run automatically, like when rotating parts, and it
|
|
|
|
* avoids doing things that would be helpful for the final positioning but annoying if they
|
|
|
|
* happened without permission.
|
2015-12-13 16:56:47 +00:00
|
|
|
* Short description of the process:
|
|
|
|
*
|
2020-12-18 17:41:56 +00:00
|
|
|
* 1. Compute the dimensions of the fields' bounding box ::computeFBoxSize
|
|
|
|
* 2. Determine which side the fields will go on. ::chooseSideForFields
|
2015-12-13 16:56:47 +00:00
|
|
|
* 1. Sort the four sides in preference order,
|
2021-05-05 21:41:51 +00:00
|
|
|
* depending on the symbol's shape and
|
2020-12-18 17:41:56 +00:00
|
|
|
* orientation ::getPreferredSides
|
2015-12-13 16:56:47 +00:00
|
|
|
* 2. If in manual mode, sift out the sides that would
|
2020-12-18 17:41:56 +00:00
|
|
|
* cause fields to overlap other items ::getCollidingSides
|
2015-12-13 16:56:47 +00:00
|
|
|
* 3. If any remaining sides have zero pins there,
|
|
|
|
* choose the highest zero-pin side according to
|
|
|
|
* preference order.
|
|
|
|
* 4. If all sides have pins, choose the side with the
|
|
|
|
* fewest pins.
|
2020-12-18 17:41:56 +00:00
|
|
|
* 3. Compute the position of the fields' bounding box ::fieldBoxPlacement
|
2015-12-13 16:56:47 +00:00
|
|
|
* 4. In manual mode, shift the box vertically if possible
|
2020-12-18 17:41:56 +00:00
|
|
|
* to fit fields between adjacent wires ::fitFieldsBetweenWires
|
2015-12-13 16:56:47 +00:00
|
|
|
* 5. Move all fields to their final positions
|
2020-12-18 17:41:56 +00:00
|
|
|
* 1. Re-justify fields if options allow that ::justifyField
|
2015-12-13 16:56:47 +00:00
|
|
|
* 2. Round to a 50-mil grid coordinate if desired
|
|
|
|
*/
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
#include <boost/range/adaptor/reversed.hpp>
|
|
|
|
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2015-12-13 16:56:47 +00:00
|
|
|
#include <sch_line.h>
|
2024-04-20 09:44:34 +00:00
|
|
|
#include <sch_pin.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2015-12-13 16:56:47 +00:00
|
|
|
#include <algorithm>
|
2019-04-21 23:45:34 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2023-05-07 20:51:55 +00:00
|
|
|
#define FIELD_PADDING schIUScale.MilsToIU( 15 ) // arbitrarily chosen for aesthetics
|
2022-09-16 23:42:20 +00:00
|
|
|
#define WIRE_V_SPACING schIUScale.MilsToIU( 100 )
|
2023-05-07 20:51:55 +00:00
|
|
|
#define HPADDING schIUScale.MilsToIU( 25 ) // arbitrarily chosen for aesthetics
|
|
|
|
#define VPADDING schIUScale.MilsToIU( 15 ) // arbitrarily chosen for aesthetics
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Round up/down to the nearest multiple of n
|
|
|
|
*/
|
|
|
|
template<typename T> T round_n( const T& value, const T& n, bool aRoundUp )
|
|
|
|
{
|
|
|
|
if( value % n )
|
|
|
|
return n * (value / n + (aRoundUp ? 1 : 0));
|
|
|
|
else
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AUTOPLACER
|
|
|
|
{
|
|
|
|
public:
|
2022-01-01 18:08:03 +00:00
|
|
|
typedef VECTOR2I SIDE;
|
2015-12-13 16:56:47 +00:00
|
|
|
static const SIDE SIDE_TOP, SIDE_BOTTOM, SIDE_LEFT, SIDE_RIGHT;
|
|
|
|
enum COLLISION { COLLIDE_NONE, COLLIDE_OBJECTS, COLLIDE_H_WIRES };
|
|
|
|
|
|
|
|
struct SIDE_AND_NPINS
|
|
|
|
{
|
2021-11-17 00:33:12 +00:00
|
|
|
SIDE side;
|
2015-12-13 16:56:47 +00:00
|
|
|
unsigned pins;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SIDE_AND_COLL
|
|
|
|
{
|
2021-11-17 00:33:12 +00:00
|
|
|
SIDE side;
|
2015-12-13 16:56:47 +00:00
|
|
|
COLLISION collision;
|
|
|
|
};
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
AUTOPLACER( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen ) :
|
2020-12-18 17:41:56 +00:00
|
|
|
m_screen( aScreen ),
|
|
|
|
m_symbol( aSymbol )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2020-12-18 17:41:56 +00:00
|
|
|
m_symbol->GetFields( m_fields, /* aVisibleOnly */ true );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-21 16:31:48 +00:00
|
|
|
wxASSERT( cfg );
|
|
|
|
|
2020-03-22 08:45:51 +00:00
|
|
|
m_allow_rejustify = false;
|
|
|
|
m_align_to_grid = true;
|
|
|
|
|
2020-03-21 16:31:48 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
m_allow_rejustify = cfg->m_AutoplaceFields.allow_rejustify;
|
|
|
|
m_align_to_grid = cfg->m_AutoplaceFields.align_to_grid;
|
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-11-17 00:33:12 +00:00
|
|
|
m_symbol_bbox = m_symbol->GetBodyBoundingBox();
|
2020-12-18 17:41:56 +00:00
|
|
|
m_fbox_size = computeFBoxSize( /* aDynamic */ true );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
m_is_power_symbol = !m_symbol->IsInNetlist();
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
if( aScreen )
|
2020-12-18 17:41:56 +00:00
|
|
|
getPossibleCollisions( m_colliders );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do the actual autoplacement.
|
|
|
|
* @param aManual - if true, use extra heuristics for smarter placement when manually
|
|
|
|
* called up.
|
|
|
|
*/
|
|
|
|
void DoAutoplace( bool aManual )
|
|
|
|
{
|
2022-02-28 00:17:55 +00:00
|
|
|
bool forceWireSpacing = false;
|
2021-11-14 17:02:36 +00:00
|
|
|
SIDE_AND_NPINS sideandpins = chooseSideForFields( aManual );
|
|
|
|
SIDE field_side = sideandpins.side;
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I fbox_pos = fieldBoxPlacement( sideandpins );
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I field_box( fbox_pos, m_fbox_size );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
if( aManual )
|
2022-02-28 00:17:55 +00:00
|
|
|
forceWireSpacing = fitFieldsBetweenWires( &field_box, field_side );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
// Move the fields
|
2015-12-17 16:36:03 +00:00
|
|
|
int last_y_coord = field_box.GetTop();
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
for( unsigned field_idx = 0; field_idx < m_fields.size(); ++field_idx )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD* field = m_fields[field_idx];
|
2023-01-17 04:14:38 +00:00
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
if( !field->IsVisible() || !field->CanAutoplace() )
|
2022-02-28 00:17:55 +00:00
|
|
|
continue;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
if( m_allow_rejustify )
|
2021-11-17 00:33:12 +00:00
|
|
|
{
|
|
|
|
if( sideandpins.pins > 0 )
|
|
|
|
{
|
|
|
|
if( field_side == SIDE_TOP || field_side == SIDE_BOTTOM )
|
|
|
|
justifyField( field, SIDE_RIGHT );
|
|
|
|
else
|
|
|
|
justifyField( field, SIDE_TOP );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
justifyField( field, field_side );
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2022-02-28 00:17:55 +00:00
|
|
|
VECTOR2I pos( fieldHPlacement( field, field_box ),
|
|
|
|
fieldVPlacement( field, field_box, &last_y_coord, !forceWireSpacing ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
if( m_align_to_grid )
|
|
|
|
{
|
2021-03-14 22:29:41 +00:00
|
|
|
if( abs( field_side.x ) > 0 )
|
2022-09-16 23:42:20 +00:00
|
|
|
pos.x = round_n( pos.x, schIUScale.MilsToIU( 50 ), field_side.x >= 0 );
|
2021-03-14 22:29:41 +00:00
|
|
|
|
|
|
|
if( abs( field_side.y ) > 0 )
|
2022-09-16 23:42:20 +00:00
|
|
|
pos.y = round_n( pos.y, schIUScale.MilsToIU( 50 ), field_side.y >= 0 );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
field->SetPosition( pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Compute and return the size of the fields' bounding box.
|
2015-12-17 16:36:03 +00:00
|
|
|
* @param aDynamic - if true, use dynamic spacing
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2022-08-31 09:15:42 +00:00
|
|
|
VECTOR2I computeFBoxSize( bool aDynamic )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
int max_field_width = 0;
|
2015-12-17 16:36:03 +00:00
|
|
|
int total_height = 0;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_FIELD* field : m_fields )
|
2022-02-28 00:17:55 +00:00
|
|
|
{
|
2024-01-24 00:24:16 +00:00
|
|
|
if( !field->IsVisible() || !field->CanAutoplace() )
|
2022-09-04 16:34:16 +00:00
|
|
|
{
|
2024-01-24 00:24:16 +00:00
|
|
|
continue;
|
2022-09-04 16:34:16 +00:00
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2024-01-24 00:24:16 +00:00
|
|
|
if( m_symbol->GetTransform().y1 )
|
|
|
|
field->SetTextAngle( ANGLE_VERTICAL );
|
|
|
|
else
|
|
|
|
field->SetTextAngle( ANGLE_HORIZONTAL );
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox = field->GetBoundingBox();
|
|
|
|
int field_width = bbox.GetWidth();
|
|
|
|
int field_height = bbox.GetHeight();
|
2015-12-17 16:36:03 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
max_field_width = std::max( max_field_width, field_width );
|
2015-12-17 16:36:03 +00:00
|
|
|
|
2020-12-18 19:56:16 +00:00
|
|
|
if( !aDynamic )
|
2015-12-17 16:36:03 +00:00
|
|
|
total_height += WIRE_V_SPACING;
|
2020-12-18 19:56:16 +00:00
|
|
|
else if( m_align_to_grid )
|
2022-09-16 23:42:20 +00:00
|
|
|
total_height += round_n( field_height, schIUScale.MilsToIU( 50 ), true );
|
2020-12-18 19:56:16 +00:00
|
|
|
else
|
|
|
|
total_height += field_height + FIELD_PADDING;
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
return VECTOR2I( max_field_width, total_height );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the side that a pin is on.
|
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
SIDE getPinSide( SCH_PIN* aPin )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
PIN_ORIENTATION pin_orient = aPin->GetLibPin()->PinDrawOrient( m_symbol->GetTransform() );
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
switch( pin_orient )
|
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
case PIN_ORIENTATION::PIN_RIGHT: return SIDE_LEFT;
|
|
|
|
case PIN_ORIENTATION::PIN_LEFT: return SIDE_RIGHT;
|
|
|
|
case PIN_ORIENTATION::PIN_UP: return SIDE_BOTTOM;
|
|
|
|
case PIN_ORIENTATION::PIN_DOWN: return SIDE_TOP;
|
2015-12-13 16:56:47 +00:00
|
|
|
default:
|
2023-01-17 04:14:38 +00:00
|
|
|
wxFAIL_MSG( wxS( "Invalid pin orientation" ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
return SIDE_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Count the number of pins on a side of the symbol.
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
unsigned pinsOnSide( SIDE aSide )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
unsigned pin_count = 0;
|
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
for( SCH_PIN* each_pin : m_symbol->GetPins() )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2020-12-18 17:41:56 +00:00
|
|
|
if( !each_pin->IsVisible() && !m_is_power_symbol )
|
2015-12-13 16:56:47 +00:00
|
|
|
continue;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
|
|
|
if( getPinSide( each_pin ) == aSide )
|
2015-12-13 16:56:47 +00:00
|
|
|
++pin_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pin_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Populate a list of all drawing items that *may* collide with the fields. That is, all
|
|
|
|
* drawing items, including other fields, that are not the current symbol or its own fields.
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
void getPossibleCollisions( std::vector<SCH_ITEM*>& aItems )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_RET( m_screen, wxS( "getPossibleCollisions() with null m_screen" ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I symbolBox = m_symbol->GetBodyAndPinsBoundingBox();
|
2021-11-25 12:47:53 +00:00
|
|
|
std::vector<SIDE_AND_NPINS> sides = getPreferredSides();
|
|
|
|
|
|
|
|
for( SIDE_AND_NPINS& side : sides )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I box( fieldBoxPlacement( side ), m_fbox_size );
|
2021-11-25 12:47:53 +00:00
|
|
|
box.Merge( symbolBox );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_screen->Items().Overlapping( box ) )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2021-11-25 12:47:53 +00:00
|
|
|
if( SCH_SYMBOL* candidate = dynamic_cast<SCH_SYMBOL*>( item ) )
|
|
|
|
{
|
|
|
|
if( candidate == m_symbol )
|
|
|
|
continue;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-11-25 12:47:53 +00:00
|
|
|
std::vector<SCH_FIELD*> fields;
|
|
|
|
candidate->GetFields( fields, /* aVisibleOnly */ true );
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2021-11-25 12:47:53 +00:00
|
|
|
for( SCH_FIELD* field : fields )
|
|
|
|
aItems.push_back( field );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2021-11-25 12:47:53 +00:00
|
|
|
aItems.push_back( item );
|
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter a list of possible colliders to include only those that actually collide
|
|
|
|
* with a given rectangle. Returns the new vector.
|
|
|
|
*/
|
2022-08-31 09:15:42 +00:00
|
|
|
std::vector<SCH_ITEM*> filterCollisions( const BOX2I& aRect )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
std::vector<SCH_ITEM*> filtered;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_ITEM* item : m_colliders )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I item_box;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( SCH_SYMBOL* item_comp = dynamic_cast<SCH_SYMBOL*>( item ) )
|
2021-09-23 21:07:19 +00:00
|
|
|
item_box = item_comp->GetBodyAndPinsBoundingBox();
|
2015-12-13 16:56:47 +00:00
|
|
|
else
|
|
|
|
item_box = item->GetBoundingBox();
|
|
|
|
|
|
|
|
if( item_box.Intersects( aRect ) )
|
|
|
|
filtered.push_back( item );
|
|
|
|
}
|
2022-02-28 00:17:55 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Return a list with the preferred field sides for the symbol, in decreasing order of
|
|
|
|
* preference.
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SIDE_AND_NPINS> getPreferredSides()
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
SIDE_AND_NPINS sides_init[] = {
|
2020-12-18 17:41:56 +00:00
|
|
|
{ SIDE_RIGHT, pinsOnSide( SIDE_RIGHT ) },
|
|
|
|
{ SIDE_TOP, pinsOnSide( SIDE_TOP ) },
|
|
|
|
{ SIDE_LEFT, pinsOnSide( SIDE_LEFT ) },
|
|
|
|
{ SIDE_BOTTOM, pinsOnSide( SIDE_BOTTOM ) },
|
2015-12-13 16:56:47 +00:00
|
|
|
};
|
2019-01-06 16:43:12 +00:00
|
|
|
std::vector<SIDE_AND_NPINS> sides( sides_init, sides_init + arrayDim( sides_init ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
int orient = m_symbol->GetOrientation();
|
|
|
|
int orient_angle = orient & 0xff; // enum is a bitmask
|
2021-06-10 14:10:55 +00:00
|
|
|
bool h_mirrored = ( ( orient & SYM_MIRROR_X )
|
|
|
|
&& ( orient_angle == SYM_ORIENT_0 || orient_angle == SYM_ORIENT_180 ) );
|
2020-12-18 17:41:56 +00:00
|
|
|
double w = double( m_symbol_bbox.GetWidth() );
|
|
|
|
double h = double( m_symbol_bbox.GetHeight() );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
// The preferred-sides heuristics are a bit magical. These were determined mostly
|
|
|
|
// by trial and error.
|
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
if( m_is_power_symbol )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
// For power symbols, we generally want the label at the top first.
|
|
|
|
switch( orient_angle )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_0:
|
2015-12-13 16:56:47 +00:00
|
|
|
std::swap( sides[0], sides[1] );
|
|
|
|
std::swap( sides[1], sides[3] );
|
|
|
|
// TOP, BOTTOM, RIGHT, LEFT
|
|
|
|
break;
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_90:
|
2015-12-13 16:56:47 +00:00
|
|
|
std::swap( sides[0], sides[2] );
|
|
|
|
std::swap( sides[1], sides[2] );
|
|
|
|
// LEFT, RIGHT, TOP, BOTTOM
|
|
|
|
break;
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_180:
|
2015-12-13 16:56:47 +00:00
|
|
|
std::swap( sides[0], sides[3] );
|
|
|
|
// BOTTOM, TOP, LEFT, RIGHT
|
|
|
|
break;
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_270:
|
2015-12-13 16:56:47 +00:00
|
|
|
std::swap( sides[1], sides[2] );
|
|
|
|
// RIGHT, LEFT, TOP, BOTTOM
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-05 21:41:51 +00:00
|
|
|
// If the symbol is horizontally mirrored, swap left and right
|
2015-12-13 16:56:47 +00:00
|
|
|
if( h_mirrored )
|
|
|
|
{
|
|
|
|
std::swap( sides[0], sides[2] );
|
|
|
|
}
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
// If the symbol is very long or is a power symbol, swap H and V
|
2015-12-13 16:56:47 +00:00
|
|
|
if( w/h > 3.0 )
|
|
|
|
{
|
|
|
|
std::swap( sides[0], sides[1] );
|
|
|
|
std::swap( sides[1], sides[3] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of the sides where a field set would collide with another item.
|
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SIDE_AND_COLL> getCollidingSides()
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2020-12-18 17:41:56 +00:00
|
|
|
SIDE sides_init[] = { SIDE_RIGHT, SIDE_TOP, SIDE_LEFT, SIDE_BOTTOM };
|
|
|
|
std::vector<SIDE> sides( sides_init, sides_init + arrayDim( sides_init ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
std::vector<SIDE_AND_COLL> colliding;
|
|
|
|
|
|
|
|
// Iterate over all sides and find the ones that collide
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SIDE side : sides )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2021-11-14 17:02:36 +00:00
|
|
|
SIDE_AND_NPINS sideandpins;
|
|
|
|
sideandpins.side = side;
|
2021-11-17 00:33:12 +00:00
|
|
|
sideandpins.pins = pinsOnSide( side );
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I box( fieldBoxPlacement( sideandpins ), m_fbox_size );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
COLLISION collision = COLLIDE_NONE;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* collider : filterCollisions( box ) )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( collider );
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( line && !side.x )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = line->GetStartPoint(), end = line->GetEndPoint();
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( start.y == end.y && collision != COLLIDE_OBJECTS )
|
|
|
|
collision = COLLIDE_H_WIRES;
|
|
|
|
else
|
|
|
|
collision = COLLIDE_OBJECTS;
|
|
|
|
}
|
|
|
|
else
|
2020-12-18 17:41:56 +00:00
|
|
|
{
|
2015-12-13 16:56:47 +00:00
|
|
|
collision = COLLIDE_OBJECTS;
|
2020-12-18 17:41:56 +00:00
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( collision != COLLIDE_NONE )
|
2016-05-28 16:57:24 +00:00
|
|
|
colliding.push_back( { side, collision } );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return colliding;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose a side for the fields, filtered on only one side collision type.
|
|
|
|
* Removes the sides matching the filter from the list.
|
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
SIDE_AND_NPINS chooseSideFiltered( std::vector<SIDE_AND_NPINS>& aSides,
|
|
|
|
const std::vector<SIDE_AND_COLL>& aCollidingSides,
|
|
|
|
COLLISION aCollision,
|
|
|
|
SIDE_AND_NPINS aLastSelection)
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
SIDE_AND_NPINS sel = aLastSelection;
|
|
|
|
|
|
|
|
std::vector<SIDE_AND_NPINS>::iterator it = aSides.begin();
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
while( it != aSides.end() )
|
|
|
|
{
|
|
|
|
bool collide = false;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SIDE_AND_COLL collision : aCollidingSides )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
if( collision.side == it->side && collision.collision == aCollision )
|
|
|
|
collide = true;
|
|
|
|
}
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( !collide )
|
2020-12-18 17:41:56 +00:00
|
|
|
{
|
2015-12-13 16:56:47 +00:00
|
|
|
++it;
|
2020-12-18 17:41:56 +00:00
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( it->pins <= sel.pins )
|
|
|
|
{
|
|
|
|
sel.pins = it->pins;
|
|
|
|
sel.side = it->side;
|
|
|
|
}
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
it = aSides.erase( it );
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-05 21:41:51 +00:00
|
|
|
* Look where a symbol's pins are to pick a side to put the fields on
|
2015-12-13 16:56:47 +00:00
|
|
|
* @param aAvoidCollisions - if true, pick last the sides where the label will collide
|
|
|
|
* with other items.
|
|
|
|
*/
|
2021-11-14 17:02:36 +00:00
|
|
|
SIDE_AND_NPINS chooseSideForFields( bool aAvoidCollisions )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SIDE_AND_NPINS> sides = getPreferredSides();
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
std::reverse( sides.begin(), sides.end() );
|
2022-01-01 18:08:03 +00:00
|
|
|
SIDE_AND_NPINS side = { VECTOR2I( 1, 0 ), UINT_MAX };
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
if( aAvoidCollisions )
|
|
|
|
{
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SIDE_AND_COLL> colliding_sides = getCollidingSides();
|
|
|
|
side = chooseSideFiltered( sides, colliding_sides, COLLIDE_OBJECTS, side );
|
|
|
|
side = chooseSideFiltered( sides, colliding_sides, COLLIDE_H_WIRES, side );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SIDE_AND_NPINS& each_side : sides | boost::adaptors::reversed )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2021-11-14 17:02:36 +00:00
|
|
|
if( !each_side.pins ) return each_side;
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SIDE_AND_NPINS& each_side : sides )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
if( each_side.pins <= side.pins )
|
|
|
|
{
|
|
|
|
side.pins = each_side.pins;
|
|
|
|
side.side = each_side.side;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-14 17:02:36 +00:00
|
|
|
return side;
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the justification of a field based on the side it's supposed to be on, taking
|
|
|
|
* into account whether the field will be displayed with flipped justification due to
|
|
|
|
* mirroring.
|
|
|
|
*/
|
2020-12-18 17:41:56 +00:00
|
|
|
void justifyField( SCH_FIELD* aField, SIDE aFieldSide )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
// Justification is set twice to allow IsHorizJustifyFlipped() to work correctly.
|
|
|
|
aField->SetHorizJustify( TO_HJUSTIFY( -aFieldSide.x ) );
|
2020-12-18 17:41:56 +00:00
|
|
|
aField->SetHorizJustify( TO_HJUSTIFY( -aFieldSide.x
|
|
|
|
* ( aField->IsHorizJustifyFlipped() ? -1 : 1 ) ) );
|
2021-12-28 22:13:54 +00:00
|
|
|
aField->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-30 18:28:00 +00:00
|
|
|
* Return the position of the field bounding box.
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I fieldBoxPlacement( SIDE_AND_NPINS aFieldSideAndPins )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I fbox_center = m_symbol_bbox.Centre();
|
2022-08-31 09:15:42 +00:00
|
|
|
int offs_x = ( m_symbol_bbox.GetWidth() + m_fbox_size.x ) / 2;
|
|
|
|
int offs_y = ( m_symbol_bbox.GetHeight() + m_fbox_size.y ) / 2;
|
2020-12-18 19:56:16 +00:00
|
|
|
|
2021-11-17 00:33:12 +00:00
|
|
|
if( aFieldSideAndPins.side.x != 0 )
|
2020-12-18 19:56:16 +00:00
|
|
|
offs_x += HPADDING;
|
2021-11-17 00:33:12 +00:00
|
|
|
else if( aFieldSideAndPins.side.y != 0 )
|
2020-12-18 19:56:16 +00:00
|
|
|
offs_y += VPADDING;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-11-17 00:33:12 +00:00
|
|
|
fbox_center.x += aFieldSideAndPins.side.x * offs_x;
|
|
|
|
fbox_center.y += aFieldSideAndPins.side.y * offs_y;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
int x = fbox_center.x - ( m_fbox_size.x / 2 );
|
|
|
|
int y = fbox_center.y - ( m_fbox_size.y / 2 );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-11-17 00:33:12 +00:00
|
|
|
auto getPinsBox =
|
2022-01-01 18:08:03 +00:00
|
|
|
[&]( const VECTOR2I& aSide )
|
2021-11-17 00:33:12 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I pinsBox;
|
2021-11-17 00:33:12 +00:00
|
|
|
|
|
|
|
for( SCH_PIN* each_pin : m_symbol->GetPins() )
|
|
|
|
{
|
|
|
|
if( !each_pin->IsVisible() && !m_is_power_symbol )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( getPinSide( each_pin ) == aSide )
|
|
|
|
pinsBox.Merge( each_pin->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return pinsBox;
|
|
|
|
};
|
|
|
|
|
2021-11-14 17:02:36 +00:00
|
|
|
if( aFieldSideAndPins.pins > 0 )
|
2021-11-17 00:33:12 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2I pinsBox = getPinsBox( aFieldSideAndPins.side );
|
2021-11-17 00:33:12 +00:00
|
|
|
|
|
|
|
if( aFieldSideAndPins.side == SIDE_TOP || aFieldSideAndPins.side == SIDE_BOTTOM )
|
2021-11-14 17:02:36 +00:00
|
|
|
{
|
2021-11-17 00:33:12 +00:00
|
|
|
x = pinsBox.GetRight() + ( HPADDING * 2 );
|
2021-11-14 17:02:36 +00:00
|
|
|
}
|
2021-11-17 00:33:12 +00:00
|
|
|
else if( aFieldSideAndPins.side == SIDE_RIGHT || aFieldSideAndPins.side == SIDE_LEFT )
|
2021-11-14 17:02:36 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
y = pinsBox.GetTop() - ( m_fbox_size.y + ( VPADDING * 2 ) );
|
2021-11-17 00:33:12 +00:00
|
|
|
}
|
2021-11-14 17:02:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
return VECTOR2I( x, y );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shift a field box up or down a bit to make the fields fit between some wires.
|
2015-12-17 16:36:03 +00:00
|
|
|
* Returns true if a shift was made.
|
2015-12-13 16:56:47 +00:00
|
|
|
*/
|
2022-08-31 09:15:42 +00:00
|
|
|
bool fitFieldsBetweenWires( BOX2I* aBox, SIDE aSide )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
if( aSide != SIDE_TOP && aSide != SIDE_BOTTOM )
|
2015-12-17 16:36:03 +00:00
|
|
|
return false;
|
2021-11-17 00:33:12 +00:00
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SCH_ITEM*> colliders = filterCollisions( *aBox );
|
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( colliders.empty() )
|
2015-12-17 16:36:03 +00:00
|
|
|
return false;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
|
|
|
// Find the offset of the wires for proper positioning
|
|
|
|
int offset = 0;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SCH_ITEM* item : colliders )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( !line )
|
2015-12-17 16:36:03 +00:00
|
|
|
return false;
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = line->GetStartPoint(), end = line->GetEndPoint();
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( start.y != end.y )
|
2015-12-17 16:36:03 +00:00
|
|
|
return false;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2015-12-17 16:36:03 +00:00
|
|
|
int this_offset = (3 * WIRE_V_SPACING / 2) - ( start.y % WIRE_V_SPACING );
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( offset == 0 )
|
|
|
|
offset = this_offset;
|
|
|
|
else if( offset != this_offset )
|
2015-12-17 16:36:03 +00:00
|
|
|
return false;
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:17:05 +00:00
|
|
|
// At this point we are recomputing the field box size. Do not
|
|
|
|
// return false after this point.
|
2020-12-18 17:41:56 +00:00
|
|
|
m_fbox_size = computeFBoxSize( /* aDynamic */ false );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = aBox->GetPosition();
|
2015-12-17 16:36:03 +00:00
|
|
|
|
2015-12-18 09:17:05 +00:00
|
|
|
pos.y = round_n( pos.y, WIRE_V_SPACING, aSide == SIDE_BOTTOM );
|
|
|
|
|
2015-12-17 16:36:03 +00:00
|
|
|
aBox->SetOrigin( pos );
|
|
|
|
return true;
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-30 18:28:00 +00:00
|
|
|
* Place a field horizontally, taking into account the field width and justification.
|
2015-12-13 16:56:47 +00:00
|
|
|
*
|
|
|
|
* @param aField - the field to place.
|
|
|
|
* @param aFieldBox - box in which fields will be placed
|
|
|
|
*
|
|
|
|
* @return Correct field horizontal position
|
|
|
|
*/
|
2022-08-31 22:57:24 +00:00
|
|
|
int fieldHPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
int field_hjust;
|
|
|
|
int field_xcoord;
|
|
|
|
|
|
|
|
if( aField->IsHorizJustifyFlipped() )
|
|
|
|
field_hjust = -aField->GetHorizJustify();
|
|
|
|
else
|
|
|
|
field_hjust = aField->GetHorizJustify();
|
|
|
|
|
|
|
|
switch( field_hjust )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
2015-12-13 16:56:47 +00:00
|
|
|
field_xcoord = aFieldBox.GetLeft();
|
|
|
|
break;
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_CENTER:
|
2015-12-13 16:56:47 +00:00
|
|
|
field_xcoord = aFieldBox.Centre().x;
|
|
|
|
break;
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
2015-12-13 16:56:47 +00:00
|
|
|
field_xcoord = aFieldBox.GetRight();
|
|
|
|
break;
|
|
|
|
default:
|
2023-01-17 04:14:38 +00:00
|
|
|
wxFAIL_MSG( wxS( "Unexpected value for SCH_FIELD::GetHorizJustify()" ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
field_xcoord = aFieldBox.Centre().x; // Most are centered
|
|
|
|
}
|
|
|
|
|
|
|
|
return field_xcoord;
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:36:03 +00:00
|
|
|
/**
|
|
|
|
* Place a field vertically. Because field vertical placements accumulate,
|
|
|
|
* this takes a pointer to a vertical position accumulator.
|
|
|
|
*
|
|
|
|
* @param aField - the field to place.
|
|
|
|
* @param aFieldBox - box in which fields will be placed.
|
2022-02-28 00:17:55 +00:00
|
|
|
* @param aAccumulatedPosition - pointer to a position accumulator
|
2015-12-17 16:36:03 +00:00
|
|
|
* @param aDynamic - use dynamic spacing
|
|
|
|
*
|
|
|
|
* @return Correct field vertical position
|
|
|
|
*/
|
2022-08-31 22:57:24 +00:00
|
|
|
int fieldVPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox, int* aAccumulatedPosition,
|
2022-02-28 00:17:55 +00:00
|
|
|
bool aDynamic )
|
2015-12-17 16:36:03 +00:00
|
|
|
{
|
|
|
|
int field_height;
|
|
|
|
int padding;
|
|
|
|
|
2020-12-18 19:56:16 +00:00
|
|
|
if( !aDynamic )
|
|
|
|
{
|
|
|
|
field_height = WIRE_V_SPACING / 2;
|
|
|
|
padding = WIRE_V_SPACING / 2;
|
|
|
|
}
|
|
|
|
else if( m_align_to_grid )
|
2015-12-17 16:36:03 +00:00
|
|
|
{
|
|
|
|
field_height = aField->GetBoundingBox().GetHeight();
|
2022-09-16 23:42:20 +00:00
|
|
|
padding = round_n( field_height, schIUScale.MilsToIU( 50 ), true ) - field_height;
|
2015-12-17 16:36:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-18 19:56:16 +00:00
|
|
|
field_height = aField->GetBoundingBox().GetHeight();
|
|
|
|
padding = FIELD_PADDING;
|
2015-12-17 16:36:03 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 00:17:55 +00:00
|
|
|
int placement = *aAccumulatedPosition + padding / 2 + field_height / 2;
|
2015-12-17 16:36:03 +00:00
|
|
|
|
2022-02-28 00:17:55 +00:00
|
|
|
*aAccumulatedPosition += padding + field_height;
|
2015-12-17 16:36:03 +00:00
|
|
|
|
|
|
|
return placement;
|
|
|
|
}
|
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
private:
|
|
|
|
SCH_SCREEN* m_screen;
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* m_symbol;
|
2020-12-18 17:41:56 +00:00
|
|
|
std::vector<SCH_FIELD*> m_fields;
|
|
|
|
std::vector<SCH_ITEM*> m_colliders;
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I m_symbol_bbox;
|
|
|
|
VECTOR2I m_fbox_size;
|
2020-12-18 17:41:56 +00:00
|
|
|
bool m_allow_rejustify;
|
|
|
|
bool m_align_to_grid;
|
|
|
|
bool m_is_power_symbol;
|
2015-12-13 16:56:47 +00:00
|
|
|
};
|
|
|
|
|
2020-12-18 17:41:56 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
const AUTOPLACER::SIDE AUTOPLACER::SIDE_TOP( 0, -1 );
|
|
|
|
const AUTOPLACER::SIDE AUTOPLACER::SIDE_BOTTOM( 0, 1 );
|
|
|
|
const AUTOPLACER::SIDE AUTOPLACER::SIDE_LEFT( -1, 0 );
|
|
|
|
const AUTOPLACER::SIDE AUTOPLACER::SIDE_RIGHT( 1, 0 );
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
|
|
|
if( aManual )
|
2023-01-17 04:14:38 +00:00
|
|
|
wxASSERT_MSG( aScreen, wxS( "A SCH_SCREEN pointer must be given for manual autoplacement" ) );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
AUTOPLACER autoplacer( this, aScreen );
|
|
|
|
autoplacer.DoAutoplace( aManual );
|
2020-03-06 12:05:21 +00:00
|
|
|
m_fieldsAutoplaced = ( aManual ? FIELDS_AUTOPLACED_MANUAL : FIELDS_AUTOPLACED_AUTO );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|