KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_constraint.h File Reference
#include <optional>
#include <vector>
#include <board_item.h>

Go to the source code of this file.

Classes

struct  CONSTRAINT_MEMBER
 One participant in a constraint: a referenced board item plus the feature of that item that participates. More...
 
class  PCB_CONSTRAINT
 A geometric constraint between board items (issue #2329). More...
 

Enumerations

enum class  PCB_CONSTRAINT_TYPE {
  UNDEFINED = 0 , COINCIDENT , HORIZONTAL , VERTICAL ,
  PARALLEL , PERPENDICULAR , COLLINEAR , SYMMETRIC ,
  EQUAL_LENGTH , EQUAL_RADIUS , POINT_ON_LINE , MIDPOINT ,
  FIXED_POSITION , FIXED_LENGTH , CONCENTRIC , FIXED_RADIUS ,
  ANGULAR_DIMENSION , TANGENT , ARC_ANGLE
}
 The geometric relationship a PCB_CONSTRAINT enforces between its members. More...
 
enum class  CONSTRAINT_ANCHOR {
  WHOLE = 0 , START , END , MID ,
  CENTER , RADIUS , VERTEX
}
 Which feature of a referenced board item participates in a constraint. More...
 

Functions

const char * ConstraintTypeToken (PCB_CONSTRAINT_TYPE aType)
 Stable file-format token for a constraint type (e.g. "parallel"). Used by serialization.
 
PCB_CONSTRAINT_TYPE ConstraintTypeFromToken (const wxString &aToken)
 Parse a constraint-type token; returns UNDEFINED for an unknown token.
 
const char * ConstraintAnchorToken (CONSTRAINT_ANCHOR aAnchor)
 Stable file-format token for a member anchor (e.g. "start").
 
CONSTRAINT_ANCHOR ConstraintAnchorFromToken (const wxString &aToken)
 Parse an anchor token; returns WHOLE for an unknown token.
 
wxString ConstraintAnchorLabel (CONSTRAINT_ANCHOR aAnchor)
 Translated name of the feature an anchor references (e.g.
 
bool ConstraintValueIsLength (PCB_CONSTRAINT_TYPE aType)
 True if this type's value is a length in IU (serialized in mm); false for an angle in degrees.
 
wxString ConstraintTypeLabel (PCB_CONSTRAINT_TYPE aType)
 Human-readable name of a constraint type (e.g. "Parallel"), for menus and lists.
 
wxString ConstraintTypeGlyph (PCB_CONSTRAINT_TYPE aType)
 Compact glyph for a constraint type (e.g. "//", "=") for on-canvas badges.
 
BITMAPS ConstraintTypeBitmap (PCB_CONSTRAINT_TYPE aType)
 Badge icon for a constraint type; INVALID_BITMAP for UNDEFINED.
 
wxString ConstraintDisplayLabel (const PCB_CONSTRAINT &aConstraint, EDA_UNITS aUnits)
 Display label for a constraint in lists and menus.
 
wxString ConstraintMemberLabel (BOARD_ITEM *aItem, const CONSTRAINT_MEMBER &aMember, UNITS_PROVIDER *aUnitsProvider)
 Label for one constrained item in a list combining the item description with its anchored feature such as Line start An indexed VERTEX member names the feature by 1 based ordinal corner N on a rectangle or vertex N on a polygon Shared by the board panel and the footprint editor dialog.
 
bool ConstraintsAreDuplicate (const PCB_CONSTRAINT &aA, const PCB_CONSTRAINT &aB)
 True if two constraints express the same relation, meaning the same type and the same members compared without regard to order (so A-B equals B-A).
 

Enumeration Type Documentation

◆ CONSTRAINT_ANCHOR

enum class CONSTRAINT_ANCHOR
strong

Which feature of a referenced board item participates in a constraint.

A bare KIID cannot say "the start point" vs "the end point" of a segment, so each constraint member pairs the referenced item with one of these anchors. START/END resolve the ambiguity the geometric-meaning bitmask POINT_TYPE (libs/kimath/include/geometry/point_types.h) cannot with its single PT_END.

Enumerator
WHOLE 

The item as a whole (a segment as a line, a circle).

START 

First endpoint of a segment or arc.

END 

Second endpoint of a segment or arc.

MID 

Midpoint of a segment or arc.

CENTER 

Center of an arc or circle.

RADIUS 

The radius (scalar feature) of an arc or circle.

VERTEX 

An indexed rectangle corner or polygon outline vertex; pairs with CONSTRAINT_MEMBER::m_index.

Definition at line 69 of file pcb_constraint.h.

◆ PCB_CONSTRAINT_TYPE

enum class PCB_CONSTRAINT_TYPE
strong

The geometric relationship a PCB_CONSTRAINT enforces between its members.

The set mirrors the constraint families the planegcs adapter maps onto (see pcbnew/constraints/board_constraint_adapter.*). Ordinals are not part of the file format; serialization is by token name, so values may be reordered freely.

Enumerator
UNDEFINED 
COINCIDENT 

Two points are made to coincide.

HORIZONTAL 

A segment (or two points) is horizontal.

VERTICAL 

A segment (or two points) is vertical.

PARALLEL 

Two segments are parallel.

PERPENDICULAR 

Two segments are perpendicular.

COLLINEAR 

Two segments lie on the same line.

SYMMETRIC 

Two points are mirror images about an axis.

EQUAL_LENGTH 

Two segments have equal length.

EQUAL_RADIUS 

Two arcs/circles have equal radius.

POINT_ON_LINE 

A point lies on a segment's supporting line.

MIDPOINT 

A point is the midpoint of a segment.

FIXED_POSITION 

A point is locked at its current location.

FIXED_LENGTH 

A segment has a driving length value.

CONCENTRIC 

Two arcs/circles share a center.

FIXED_RADIUS 

An arc/circle has a driving radius value.

ANGULAR_DIMENSION 

An angle between members (driving or reference).

TANGENT 

A line and a curve, or two curves, touch tangentially.

ARC_ANGLE 

An arc has a driving or reference swept-angle value.

Definition at line 37 of file pcb_constraint.h.

Function Documentation

◆ ConstraintAnchorFromToken()

CONSTRAINT_ANCHOR ConstraintAnchorFromToken ( const wxString & aToken)

Parse an anchor token; returns WHOLE for an unknown token.

Definition at line 112 of file pcb_constraint.cpp.

References anchor, ConstraintAnchorToken(), VERTEX, and WHOLE.

Referenced by BOOST_AUTO_TEST_CASE(), and PCB_IO_KICAD_SEXPR_PARSER::parseCONSTRAINT().

◆ ConstraintAnchorLabel()

wxString ConstraintAnchorLabel ( CONSTRAINT_ANCHOR aAnchor)

Translated name of the feature an anchor references (e.g.

"start"); empty for WHOLE. The caller supplies any surrounding punctuation.

Definition at line 186 of file pcb_constraint.cpp.

References _, CENTER, END, MID, RADIUS, START, VERTEX, and WHOLE.

Referenced by ConstraintMemberLabel().

◆ ConstraintAnchorToken()

const char * ConstraintAnchorToken ( CONSTRAINT_ANCHOR aAnchor)

Stable file-format token for a member anchor (e.g. "start").

Definition at line 95 of file pcb_constraint.cpp.

References CENTER, END, MID, RADIUS, START, VERTEX, and WHOLE.

Referenced by ConstraintAnchorFromToken(), and PCB_IO_KICAD_SEXPR::format().

◆ ConstraintDisplayLabel()

wxString ConstraintDisplayLabel ( const PCB_CONSTRAINT & aConstraint,
EDA_UNITS aUnits )

Display label for a constraint in lists and menus.

A valued constraint reads "<type>: <value>" with the value formatted in aUnits (lengths) or degrees (angles); a reference (non-driving) value is parenthesized, mirroring CAD reference dimensions. A constraint with no value is just its type name.

Definition at line 385 of file pcb_constraint.cpp.

References ConstraintTypeLabel(), ConstraintValueIsLength(), DEGREES_T, PCB_CONSTRAINT::GetConstraintType(), PCB_CONSTRAINT::GetValue(), PCB_CONSTRAINT::HasValue(), PCB_CONSTRAINT::IsDriving(), EDA_UNIT_UTILS::UI::MessageTextFromValue(), pcbIUScale, and text.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PopulateConstraintList(), and CONSTRAINT_EDIT_TOOL::updateConstraintMsgPanel().

◆ ConstraintMemberLabel()

wxString ConstraintMemberLabel ( BOARD_ITEM * aItem,
const CONSTRAINT_MEMBER & aMember,
UNITS_PROVIDER * aUnitsProvider )

Label for one constrained item in a list combining the item description with its anchored feature such as Line start An indexed VERTEX member names the feature by 1 based ordinal corner N on a rectangle or vertex N on a polygon Shared by the board panel and the footprint editor dialog.

Definition at line 405 of file pcb_constraint.cpp.

References _, anchor, ConstraintAnchorLabel(), EDA_ITEM::GetItemDescription(), EDA_SHAPE::GetShape(), CONSTRAINT_MEMBER::m_anchor, CONSTRAINT_MEMBER::m_index, RECTANGLE, text, and VERTEX.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PopulateConstraintList(), and CONSTRAINT_EDIT_TOOL::updateConstraintMsgPanel().

◆ ConstraintsAreDuplicate()

bool ConstraintsAreDuplicate ( const PCB_CONSTRAINT & aA,
const PCB_CONSTRAINT & aB )

True if two constraints express the same relation, meaning the same type and the same members compared without regard to order (so A-B equals B-A).

Value and driving are ignored, so a second dimensional constraint on the same geometry counts as a duplicate since it could only conflict. Used to reject authoring an identical constraint.

Definition at line 437 of file pcb_constraint.cpp.

References PCB_CONSTRAINT::GetConstraintType(), and PCB_CONSTRAINT::GetMembers().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), dimensionBindingIsDuplicate(), and CONSTRAINT_EDIT_TOOL::isDuplicateConstraint().

◆ ConstraintTypeBitmap()

◆ ConstraintTypeFromToken()

PCB_CONSTRAINT_TYPE ConstraintTypeFromToken ( const wxString & aToken)

Parse a constraint-type token; returns UNDEFINED for an unknown token.

Definition at line 68 of file pcb_constraint.cpp.

References ARC_ANGLE, ConstraintTypeToken(), and UNDEFINED.

Referenced by PCB_IO_KICAD_SEXPR_PARSER::parseCONSTRAINT().

◆ ConstraintTypeGlyph()

wxString ConstraintTypeGlyph ( PCB_CONSTRAINT_TYPE aType)

Compact glyph for a constraint type (e.g. "//", "=") for on-canvas badges.

Definition at line 126 of file pcb_constraint.cpp.

References ANGULAR_DIMENSION, ARC_ANGLE, COINCIDENT, COLLINEAR, CONCENTRIC, EQUAL_LENGTH, EQUAL_RADIUS, FIXED_LENGTH, FIXED_POSITION, FIXED_RADIUS, HORIZONTAL, MIDPOINT, PARALLEL, PERPENDICULAR, POINT_ON_LINE, SYMMETRIC, TANGENT, UNDEFINED, and VERTICAL.

Referenced by BOOST_AUTO_TEST_CASE().

◆ ConstraintTypeLabel()

◆ ConstraintTypeToken()

const char * ConstraintTypeToken ( PCB_CONSTRAINT_TYPE aType)

Stable file-format token for a constraint type (e.g. "parallel"). Used by serialization.

Definition at line 39 of file pcb_constraint.cpp.

References ANGULAR_DIMENSION, ARC_ANGLE, COINCIDENT, COLLINEAR, CONCENTRIC, EQUAL_LENGTH, EQUAL_RADIUS, FIXED_LENGTH, FIXED_POSITION, FIXED_RADIUS, HORIZONTAL, MIDPOINT, PARALLEL, PERPENDICULAR, POINT_ON_LINE, SYMMETRIC, TANGENT, UNDEFINED, and VERTICAL.

Referenced by ConstraintTypeFromToken(), and PCB_IO_KICAD_SEXPR::format().

◆ ConstraintValueIsLength()

bool ConstraintValueIsLength ( PCB_CONSTRAINT_TYPE aType)

True if this type's value is a length in IU (serialized in mm); false for an angle in degrees.

Definition at line 82 of file pcb_constraint.cpp.

References FIXED_LENGTH, and FIXED_RADIUS.

Referenced by ConstraintDisplayLabel(), DIALOG_CONSTRAINT_VALUE::DIALOG_CONSTRAINT_VALUE(), PCB_IO_KICAD_SEXPR::format(), and PCB_IO_KICAD_SEXPR_PARSER::parseCONSTRAINT().