KiCad PCB EDA Suite
Loading...
Searching...
No Matches
autoplace_fields.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Chris Pavlina <[email protected]>
5 * Copyright (C) 2015, 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/******************************************************************************
26 * Field autoplacer: Tries to find an optimal place for symbol fields, and places them there.
27 * There are two modes: "auto"-autoplace, and "manual" autoplace.
28 * Auto mode is for when the process is run automatically, like when rotating parts, and it
29 * avoids doing things that would be helpful for the final positioning but annoying if they
30 * happened without permission.
31 * Short description of the process:
32 *
33 * 1. Compute the dimensions of the fields' bounding box ::computeFBoxSize
34 * 2. Determine which side the fields will go on. ::chooseSideForFields
35 * 1. Sort the four sides in preference order,
36 * depending on the symbol's shape and
37 * orientation ::getPreferredSides
38 * 2. If in manual mode, sift out the sides that would
39 * cause fields to overlap other items ::getCollidingSides
40 * 3. If any remaining sides have zero pins there,
41 * choose the highest zero-pin side according to
42 * preference order.
43 * 4. If all sides have pins, choose the side with the
44 * fewest pins.
45 * 3. Compute the position of the fields' bounding box ::fieldBoxPlacement
46 * 4. In manual mode, shift the box vertically if possible
47 * to fit fields between adjacent wires ::fitFieldsBetweenWires
48 * 5. Move all fields to their final positions
49 * 1. Re-justify fields if options allow that ::justifyField
50 * 2. Round to a 50-mil grid coordinate if desired
51 */
52
53#include <boost/range/adaptor/reversed.hpp>
54
55#include <sch_edit_frame.h>
56#include <symbol.h>
57#include <sch_line.h>
58#include <sch_pin.h>
59#include <kiface_base.h>
60#include <algorithm>
61#include <tool/tool_manager.h>
63#include <eeschema_settings.h>
64#include <core/arraydim.h>
65
66#define FIELD_PADDING schIUScale.MilsToIU( 15 ) // arbitrarily chosen for aesthetics
67#define WIRE_V_SPACING schIUScale.MilsToIU( 100 )
68#define HPADDING schIUScale.MilsToIU( 25 ) // arbitrarily chosen for aesthetics
69#define VPADDING schIUScale.MilsToIU( 15 ) // arbitrarily chosen for aesthetics
70
74template<typename T> T round_n( const T& value, const T& n, bool aRoundUp )
75{
76 if( value % n )
77 return n * (value / n + (aRoundUp ? 1 : 0));
78 else
79 return value;
80}
81
82
84{
85public:
86 typedef VECTOR2I SIDE;
89
91 {
93 unsigned pins;
94 };
95
97 {
100 };
101
102 AUTOPLACER( SYMBOL* aSymbol, SCH_SCREEN* aScreen ) :
103 m_screen( aScreen ),
104 m_symbol( aSymbol ),
105 m_is_power_symbol( false )
106 {
107 m_symbol->GetFields( m_fields, /* aVisibleOnly */ true );
108
109 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
110 wxASSERT( cfg );
111
112 m_allow_rejustify = false;
113 m_align_to_grid = true;
114
115 if( cfg )
116 {
117 m_allow_rejustify = cfg->m_AutoplaceFields.allow_rejustify;
118 m_align_to_grid = cfg->m_AutoplaceFields.align_to_grid;
119 }
120
122 m_fbox_size = computeFBoxSize( /* aDynamic */ true );
123
124 if( SCH_SYMBOL* schSymbol = dynamic_cast<SCH_SYMBOL*>( m_symbol ) )
125 m_is_power_symbol = !schSymbol->IsInNetlist();
126
127 if( aScreen )
129 }
130
137 {
138 bool forceWireSpacing = false;
139 SIDE_AND_NPINS sideandpins = chooseSideForFields( aAlgo == AUTOPLACE_MANUAL );
140 SIDE field_side = sideandpins.side;
141 VECTOR2I fbox_pos = fieldBoxPlacement( sideandpins );
142 BOX2I field_box( fbox_pos, m_fbox_size );
143
144 if( aAlgo == AUTOPLACE_MANUAL )
145 forceWireSpacing = fitFieldsBetweenWires( &field_box, field_side );
146
147 // Move the fields
148 int last_y_coord = field_box.GetTop();
149
150 for( SCH_FIELD* field : m_fields )
151 {
152 if( !field->IsVisible() || !field->CanAutoplace() )
153 continue;
154
155 if( aAlgo == AUTOPLACE_AUTOADDED && !field->IsAutoAdded() )
156 continue;
157
159 {
160 if( sideandpins.pins > 0 )
161 {
162 if( field_side == SIDE_TOP || field_side == SIDE_BOTTOM )
163 justifyField( field, SIDE_RIGHT );
164 else
165 justifyField( field, SIDE_TOP );
166 }
167 else
168 {
169 justifyField( field, field_side );
170 }
171 }
172
173 VECTOR2I pos( fieldHPlacement( field, field_box ),
174 fieldVPlacement( field, field_box, &last_y_coord, !forceWireSpacing ) );
175
176 if( m_align_to_grid )
177 {
178 if( abs( field_side.x ) > 0 )
179 pos.x = round_n( pos.x, schIUScale.MilsToIU( 50 ), field_side.x >= 0 );
180
181 if( abs( field_side.y ) > 0 )
182 pos.y = round_n( pos.y, schIUScale.MilsToIU( 50 ), field_side.y >= 0 );
183 }
184
185 field->SetPosition( pos );
186 }
187 }
188
189protected:
194 VECTOR2I computeFBoxSize( bool aDynamic )
195 {
196 int max_field_width = 0;
197 int total_height = 0;
198
199 for( SCH_FIELD* field : m_fields )
200 {
201 if( !field->IsVisible() || !field->CanAutoplace() )
202 {
203 continue;
204 }
205
206 if( m_symbol->GetTransform().y1 )
207 field->SetTextAngle( ANGLE_VERTICAL );
208 else
209 field->SetTextAngle( ANGLE_HORIZONTAL );
210
211 BOX2I bbox = field->GetBoundingBox();
212 int field_width = bbox.GetWidth();
213 int field_height = bbox.GetHeight();
214
215 max_field_width = std::max( max_field_width, field_width );
216
217 if( !aDynamic )
218 total_height += WIRE_V_SPACING;
219 else if( m_align_to_grid )
220 total_height += round_n( field_height, schIUScale.MilsToIU( 50 ), true );
221 else
222 total_height += field_height + FIELD_PADDING;
223 }
224
225 return VECTOR2I( max_field_width, total_height );
226 }
227
232 {
233 PIN_ORIENTATION pin_orient = aPin->PinDrawOrient( m_symbol->GetTransform() );
234
235 switch( pin_orient )
236 {
237 case PIN_ORIENTATION::PIN_RIGHT: return SIDE_LEFT;
238 case PIN_ORIENTATION::PIN_LEFT: return SIDE_RIGHT;
239 case PIN_ORIENTATION::PIN_UP: return SIDE_BOTTOM;
240 case PIN_ORIENTATION::PIN_DOWN: return SIDE_TOP;
241 default:
242 wxFAIL_MSG( wxS( "Invalid pin orientation" ) );
243 return SIDE_LEFT;
244 }
245 }
246
250 unsigned pinsOnSide( SIDE aSide )
251 {
252 unsigned pin_count = 0;
253
254 for( SCH_PIN* each_pin : m_symbol->GetPins() )
255 {
256 if( !each_pin->IsVisible() && !m_is_power_symbol )
257 continue;
258
259 if( getPinSide( each_pin ) == aSide )
260 ++pin_count;
261 }
262
263 return pin_count;
264 }
265
270 void getPossibleCollisions( std::vector<SCH_ITEM*>& aItems )
271 {
272 wxCHECK_RET( m_screen, wxS( "getPossibleCollisions() with null m_screen" ) );
273
275 std::vector<SIDE_AND_NPINS> sides = getPreferredSides();
276
277 for( SIDE_AND_NPINS& side : sides )
278 {
279 BOX2I box( fieldBoxPlacement( side ), m_fbox_size );
280 box.Merge( symbolBox );
281
282 for( SCH_ITEM* item : m_screen->Items().Overlapping( box ) )
283 {
284 if( SCH_SYMBOL* candidate = dynamic_cast<SCH_SYMBOL*>( item ) )
285 {
286 if( candidate == m_symbol )
287 continue;
288
289 std::vector<SCH_FIELD*> fields;
290 candidate->GetFields( fields, /* aVisibleOnly */ true );
291
292 for( SCH_FIELD* field : fields )
293 aItems.push_back( field );
294 }
295
296 aItems.push_back( item );
297 }
298 }
299 }
300
305 std::vector<SCH_ITEM*> filterCollisions( const BOX2I& aRect )
306 {
307 std::vector<SCH_ITEM*> filtered;
308
309 for( SCH_ITEM* item : m_colliders )
310 {
311 BOX2I item_box;
312
313 if( SCH_SYMBOL* item_comp = dynamic_cast<SCH_SYMBOL*>( item ) )
314 item_box = item_comp->GetBodyAndPinsBoundingBox();
315 else
316 item_box = item->GetBoundingBox();
317
318 if( item_box.Intersects( aRect ) )
319 filtered.push_back( item );
320 }
321
322 return filtered;
323 }
324
329 std::vector<SIDE_AND_NPINS> getPreferredSides()
330 {
331 SIDE_AND_NPINS sides_init[] = {
336 };
337 std::vector<SIDE_AND_NPINS> sides( sides_init, sides_init + arrayDim( sides_init ) );
338
339 int orient = m_symbol->GetOrientation();
340 int orient_angle = orient & 0xff; // enum is a bitmask
341 bool h_mirrored = ( ( orient & SYM_MIRROR_X )
342 && ( orient_angle == SYM_ORIENT_0 || orient_angle == SYM_ORIENT_180 ) );
343 double w = double( m_symbol_bbox.GetWidth() );
344 double h = double( m_symbol_bbox.GetHeight() );
345
346 // The preferred-sides heuristics are a bit magical. These were determined mostly
347 // by trial and error.
348
350 {
351 // For power symbols, we generally want the label at the top first.
352 switch( orient_angle )
353 {
354 case SYM_ORIENT_0:
355 std::swap( sides[0], sides[1] );
356 std::swap( sides[1], sides[3] );
357 // TOP, BOTTOM, RIGHT, LEFT
358 break;
359 case SYM_ORIENT_90:
360 std::swap( sides[0], sides[2] );
361 std::swap( sides[1], sides[2] );
362 // LEFT, RIGHT, TOP, BOTTOM
363 break;
364 case SYM_ORIENT_180:
365 std::swap( sides[0], sides[3] );
366 // BOTTOM, TOP, LEFT, RIGHT
367 break;
368 case SYM_ORIENT_270:
369 std::swap( sides[1], sides[2] );
370 // RIGHT, LEFT, TOP, BOTTOM
371 break;
372 }
373 }
374 else
375 {
376 // If the symbol is horizontally mirrored, swap left and right
377 if( h_mirrored )
378 {
379 std::swap( sides[0], sides[2] );
380 }
381
382 // If the symbol is very long or is a power symbol, swap H and V
383 if( w/h > 3.0 )
384 {
385 std::swap( sides[0], sides[1] );
386 std::swap( sides[1], sides[3] );
387 }
388 }
389
390 return sides;
391 }
392
396 std::vector<SIDE_AND_COLL> getCollidingSides()
397 {
398 SIDE sides_init[] = { SIDE_RIGHT, SIDE_TOP, SIDE_LEFT, SIDE_BOTTOM };
399 std::vector<SIDE> sides( sides_init, sides_init + arrayDim( sides_init ) );
400 std::vector<SIDE_AND_COLL> colliding;
401
402 // Iterate over all sides and find the ones that collide
403 for( SIDE side : sides )
404 {
405 SIDE_AND_NPINS sideandpins;
406 sideandpins.side = side;
407 sideandpins.pins = pinsOnSide( side );
408
409 BOX2I box( fieldBoxPlacement( sideandpins ), m_fbox_size );
410
411 COLLISION collision = COLLIDE_NONE;
412
413 for( SCH_ITEM* collider : filterCollisions( box ) )
414 {
415 SCH_LINE* line = dynamic_cast<SCH_LINE*>( collider );
416
417 if( line && !side.x )
418 {
419 VECTOR2I start = line->GetStartPoint(), end = line->GetEndPoint();
420
421 if( start.y == end.y && collision != COLLIDE_OBJECTS )
422 collision = COLLIDE_H_WIRES;
423 else
424 collision = COLLIDE_OBJECTS;
425 }
426 else
427 {
428 collision = COLLIDE_OBJECTS;
429 }
430 }
431
432 if( collision != COLLIDE_NONE )
433 colliding.push_back( { side, collision } );
434 }
435
436 return colliding;
437 }
438
443 SIDE_AND_NPINS chooseSideFiltered( std::vector<SIDE_AND_NPINS>& aSides,
444 const std::vector<SIDE_AND_COLL>& aCollidingSides,
445 COLLISION aCollision,
446 SIDE_AND_NPINS aLastSelection)
447 {
448 SIDE_AND_NPINS sel = aLastSelection;
449
450 std::vector<SIDE_AND_NPINS>::iterator it = aSides.begin();
451
452 while( it != aSides.end() )
453 {
454 bool collide = false;
455
456 for( SIDE_AND_COLL collision : aCollidingSides )
457 {
458 if( collision.side == it->side && collision.collision == aCollision )
459 collide = true;
460 }
461
462 if( !collide )
463 {
464 ++it;
465 }
466 else
467 {
468 if( it->pins <= sel.pins )
469 {
470 sel.pins = it->pins;
471 sel.side = it->side;
472 }
473
474 it = aSides.erase( it );
475 }
476 }
477
478 return sel;
479 }
480
486 SIDE_AND_NPINS chooseSideForFields( bool aAvoidCollisions )
487 {
488 std::vector<SIDE_AND_NPINS> sides = getPreferredSides();
489
490 std::reverse( sides.begin(), sides.end() );
491 SIDE_AND_NPINS side = { VECTOR2I( 1, 0 ), UINT_MAX };
492
493 if( aAvoidCollisions )
494 {
495 std::vector<SIDE_AND_COLL> colliding_sides = getCollidingSides();
496 side = chooseSideFiltered( sides, colliding_sides, COLLIDE_OBJECTS, side );
497 side = chooseSideFiltered( sides, colliding_sides, COLLIDE_H_WIRES, side );
498 }
499
500 for( SIDE_AND_NPINS& each_side : sides | boost::adaptors::reversed )
501 {
502 if( !each_side.pins ) return each_side;
503 }
504
505 for( SIDE_AND_NPINS& each_side : sides )
506 {
507 if( each_side.pins <= side.pins )
508 {
509 side.pins = each_side.pins;
510 side.side = each_side.side;
511 }
512 }
513
514 return side;
515 }
516
522 void justifyField( SCH_FIELD* aField, SIDE aFieldSide )
523 {
524 // Justification is set twice to allow IsHorizJustifyFlipped() to work correctly.
525 aField->SetHorizJustify( ToHAlignment( -aFieldSide.x ) );
526 if( aField->IsHorizJustifyFlipped() )
528
530 }
531
536 {
537 VECTOR2I fbox_center = m_symbol_bbox.Centre();
538 int offs_x = ( m_symbol_bbox.GetWidth() + m_fbox_size.x ) / 2;
539 int offs_y = ( m_symbol_bbox.GetHeight() + m_fbox_size.y ) / 2;
540
541 if( aFieldSideAndPins.side.x != 0 )
542 offs_x += HPADDING;
543 else if( aFieldSideAndPins.side.y != 0 )
544 offs_y += VPADDING;
545
546 fbox_center.x += aFieldSideAndPins.side.x * offs_x;
547 fbox_center.y += aFieldSideAndPins.side.y * offs_y;
548
549 int x = fbox_center.x - ( m_fbox_size.x / 2 );
550 int y = fbox_center.y - ( m_fbox_size.y / 2 );
551
552 auto getPinsBox =
553 [&]( const VECTOR2I& aSide )
554 {
555 BOX2I pinsBox;
556
557 for( SCH_PIN* each_pin : m_symbol->GetPins() )
558 {
559 if( !each_pin->IsVisible() && !m_is_power_symbol )
560 continue;
561
562 if( getPinSide( each_pin ) == aSide )
563 pinsBox.Merge( each_pin->GetBoundingBox() );
564 }
565
566 return pinsBox;
567 };
568
569 if( aFieldSideAndPins.pins > 0 )
570 {
571 BOX2I pinsBox = getPinsBox( aFieldSideAndPins.side );
572
573 if( aFieldSideAndPins.side == SIDE_TOP || aFieldSideAndPins.side == SIDE_BOTTOM )
574 {
575 x = pinsBox.GetRight() + ( HPADDING * 2 );
576 }
577 else if( aFieldSideAndPins.side == SIDE_RIGHT || aFieldSideAndPins.side == SIDE_LEFT )
578 {
579 y = pinsBox.GetTop() - ( m_fbox_size.y + ( VPADDING * 2 ) );
580 }
581 }
582
583 return VECTOR2I( x, y );
584 }
585
590 bool fitFieldsBetweenWires( BOX2I* aBox, SIDE aSide )
591 {
592 if( aSide != SIDE_TOP && aSide != SIDE_BOTTOM )
593 return false;
594
595 std::vector<SCH_ITEM*> colliders = filterCollisions( *aBox );
596
597 if( colliders.empty() )
598 return false;
599
600 // Find the offset of the wires for proper positioning
601 int offset = 0;
602
603 for( SCH_ITEM* item : colliders )
604 {
605 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
606
607 if( !line )
608 return false;
609
610 VECTOR2I start = line->GetStartPoint(), end = line->GetEndPoint();
611
612 if( start.y != end.y )
613 return false;
614
615 int this_offset = (3 * WIRE_V_SPACING / 2) - ( start.y % WIRE_V_SPACING );
616
617 if( offset == 0 )
618 offset = this_offset;
619 else if( offset != this_offset )
620 return false;
621 }
622
623 // At this point we are recomputing the field box size. Do not
624 // return false after this point.
625 m_fbox_size = computeFBoxSize( /* aDynamic */ false );
626
627 VECTOR2I pos = aBox->GetPosition();
628
629 pos.y = round_n( pos.y, WIRE_V_SPACING, aSide == SIDE_BOTTOM );
630
631 aBox->SetOrigin( pos );
632 return true;
633 }
634
643 int fieldHPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox )
644 {
645 int field_hjust;
646 int field_xcoord;
647
648 if( aField->IsHorizJustifyFlipped() )
649 field_hjust = -aField->GetHorizJustify();
650 else
651 field_hjust = aField->GetHorizJustify();
652
653 switch( field_hjust )
654 {
656 field_xcoord = aFieldBox.GetLeft();
657 break;
659 field_xcoord = aFieldBox.Centre().x;
660 break;
662 field_xcoord = aFieldBox.GetRight();
663 break;
664 default:
665 wxFAIL_MSG( wxS( "Unexpected value for SCH_FIELD::GetHorizJustify()" ) );
666 field_xcoord = aFieldBox.Centre().x; // Most are centered
667 }
668
669 return field_xcoord;
670 }
671
683 int fieldVPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox, int* aAccumulatedPosition,
684 bool aDynamic )
685 {
686 int field_height;
687 int padding;
688
689 if( !aDynamic )
690 {
691 field_height = WIRE_V_SPACING / 2;
692 padding = WIRE_V_SPACING / 2;
693 }
694 else if( m_align_to_grid )
695 {
696 field_height = aField->GetBoundingBox().GetHeight();
697 padding = round_n( field_height, schIUScale.MilsToIU( 50 ), true ) - field_height;
698 }
699 else
700 {
701 field_height = aField->GetBoundingBox().GetHeight();
702 padding = FIELD_PADDING;
703 }
704
705 int placement = *aAccumulatedPosition + padding / 2 + field_height / 2;
706
707 *aAccumulatedPosition += padding + field_height;
708
709 return placement;
710 }
711
712private:
715 std::vector<SCH_FIELD*> m_fields;
716 std::vector<SCH_ITEM*> m_colliders;
722};
723
724
729
730
732{
733 if( aAlgo == AUTOPLACE_MANUAL )
734 wxASSERT_MSG( aScreen, wxS( "A SCH_SCREEN pointer must be given for manual autoplacement" ) );
735
736 AUTOPLACER autoplacer( this, aScreen );
737 autoplacer.DoAutoplace( aAlgo );
738
739 if( aAlgo == AUTOPLACE_AUTO )
741 else if( aAlgo == AUTOPLACE_MANUAL )
743 else if( aAlgo == AUTOPLACE_AUTOADDED )
744 /* leave m_fieldsAutoplaced as it is */;
745}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
#define HPADDING
#define FIELD_PADDING
#define VPADDING
#define WIRE_V_SPACING
T round_n(const T &value, const T &n, bool aRoundUp)
Round up/down to the nearest multiple of n.
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
VECTOR2I computeFBoxSize(bool aDynamic)
Compute and return the size of the fields' bounding box.
VECTOR2I fieldBoxPlacement(SIDE_AND_NPINS aFieldSideAndPins)
Return the position of the field bounding box.
SIDE getPinSide(SCH_PIN *aPin)
Return the side that a pin is on.
int fieldVPlacement(SCH_FIELD *aField, const BOX2I &aFieldBox, int *aAccumulatedPosition, bool aDynamic)
Place a field vertically.
void getPossibleCollisions(std::vector< SCH_ITEM * > &aItems)
Populate a list of all drawing items that may collide with the fields.
static const SIDE SIDE_TOP
static const SIDE SIDE_BOTTOM
unsigned pinsOnSide(SIDE aSide)
Count the number of pins on a side of the symbol.
std::vector< SCH_FIELD * > m_fields
VECTOR2I m_fbox_size
SIDE_AND_NPINS chooseSideForFields(bool aAvoidCollisions)
Look where a symbol's pins are to pick a side to put the fields on.
bool fitFieldsBetweenWires(BOX2I *aBox, SIDE aSide)
Shift a field box up or down a bit to make the fields fit between some wires.
int fieldHPlacement(SCH_FIELD *aField, const BOX2I &aFieldBox)
Place a field horizontally, taking into account the field width and justification.
SCH_SCREEN * m_screen
std::vector< SCH_ITEM * > m_colliders
static const SIDE SIDE_RIGHT
std::vector< SCH_ITEM * > filterCollisions(const BOX2I &aRect)
Filter a list of possible colliders to include only those that actually collide with a given rectangl...
std::vector< SIDE_AND_NPINS > getPreferredSides()
Return a list with the preferred field sides for the symbol, in decreasing order of preference.
std::vector< SIDE_AND_COLL > getCollidingSides()
Return a list of the sides where a field set would collide with another item.
AUTOPLACER(SYMBOL *aSymbol, SCH_SCREEN *aScreen)
static const SIDE SIDE_LEFT
SIDE_AND_NPINS chooseSideFiltered(std::vector< SIDE_AND_NPINS > &aSides, const std::vector< SIDE_AND_COLL > &aCollidingSides, COLLISION aCollision, SIDE_AND_NPINS aLastSelection)
Choose a side for the fields, filtered on only one side collision type.
void DoAutoplace(AUTOPLACE_ALGO aAlgo)
Do the actual autoplacement.
void justifyField(SCH_FIELD *aField, SIDE aFieldSide)
Set the justification of a field based on the side it's supposed to be on, taking into account whethe...
constexpr const Vec & GetPosition() const
Definition: box2.h:211
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr Vec Centre() const
Definition: box2.h:97
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr coord_type GetLeft() const
Definition: box2.h:228
constexpr coord_type GetRight() const
Definition: box2.h:217
constexpr coord_type GetTop() const
Definition: box2.h:229
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:408
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:400
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition: sch_rtree.h:243
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:617
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:645
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
AUTOPLACE_ALGO m_fieldsAutoplaced
Definition: sch_item.h:714
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
PIN_ORIENTATION PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: sch_pin.cpp:1374
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
Schematic symbol object.
Definition: sch_symbol.h:77
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
virtual void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)=0
virtual BOX2I GetBodyAndPinsBoundingBox() const =0
Return a bounding box for the symbol body and pins but not the fields.
const TRANSFORM & GetTransform() const
Definition: symbol.h:191
virtual BOX2I GetBodyBoundingBox() const =0
Return a bounding box for the symbol body but not the pins or fields.
virtual std::vector< SCH_PIN * > GetPins() const =0
virtual int GetOrientation() const
Definition: symbol.h:189
int y1
Definition: transform.h:49
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:78
AUTOPLACE_ALGO
Definition: sch_item.h:68
@ AUTOPLACE_MANUAL
Definition: sch_item.h:71
@ AUTOPLACE_AUTOADDED
Definition: sch_item.h:73
@ AUTOPLACE_AUTO
Definition: sch_item.h:70
bool collide(T aObject, U aAnotherObject, int aLayer, int aMinDistance)
Used by SHAPE_INDEX to implement Query().
Definition: shape_index.h:97
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
@ SYM_ORIENT_270
Definition: symbol.h:42
@ SYM_ORIENT_180
Definition: symbol.h:41
@ SYM_MIRROR_X
Definition: symbol.h:43
@ SYM_ORIENT_90
Definition: symbol.h:40
@ SYM_ORIENT_0
Definition: symbol.h:39
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_CENTER
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
constexpr GR_TEXT_H_ALIGN_T ToHAlignment(int x)
Convert an integral value to horizontal alignment.
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691