KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_builder.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef CONSTRAINT_BUILDER_H_
21#define CONSTRAINT_BUILDER_H_
22
23#include <functional>
24#include <map>
25#include <memory>
26#include <optional>
27#include <vector>
28
29#include <math/vector2d.h>
30#include <geometry/eda_angle.h>
31#include <layer_ids.h>
32
34
35class BOARD;
36class BOARD_ITEM;
38class PCB_SHAPE;
39class SEG;
40
41
51EDA_ANGLE MeasureCornerAngle( const SEG& aA, const SEG& aB );
52
53
61
62
67bool ConstraintPolygonIsModelable( const PCB_SHAPE* aShape );
68
69
75std::vector<CONSTRAINT_ANCHOR_POINT> ConstraintShapeAnchors( const PCB_SHAPE* aShape );
76
77
85std::optional<CONSTRAINT_ANCHOR_POINT> ConstraintShapeVertex( const PCB_SHAPE* aShape, int aIndex );
86
87
91std::vector<PCB_SHAPE*> CollectConstraintShapes( BOARD* aBoard, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
92
93
96std::vector<BOARD_ITEM*> CollectConstrainableItems( BOARD* aBoard, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
97
98
103std::optional<CONSTRAINT_MEMBER> NearestAnchorAmong( const std::vector<PCB_SHAPE*>& aShapes,
104 const VECTOR2I& aPos, double aMaxDist );
105
106
118std::unique_ptr<PCB_CONSTRAINT> BuildConstraintFromItems( BOARD_ITEM* aParent,
120 const std::vector<BOARD_ITEM*>& aItems );
121
122
132
133
147std::optional<CONSTRAINT_MEMBER> NearestConstraintAnchor( BOARD* aBoard, const VECTOR2I& aPos,
148 double aMaxDist,
149 const std::vector<CONSTRAINT_MEMBER>& aExclude = {},
150 PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
151
152
157BOARD_ITEM* ResolveConstrainableItem( BOARD* aBoard, const KIID& aId );
158
159
163std::optional<KIID> NearestOutlineShape( BOARD* aBoard, const VECTOR2I& aPos, double aMaxDist, bool aAllowCircle,
164 PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
165
166
174
175
188std::vector<ENDPOINT_BINDING> SelectEndpointBindings( BOARD* aBoard, const KIID& aItem, const VECTOR2I& aStart,
189 const std::optional<VECTOR2I>& aEnd, double aMaxDist,
190 PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
191
192
196{
197 std::unique_ptr<PCB_CONSTRAINT> constraint;
198 bool needsSolve = false;
199};
200
201
217std::vector<AUTO_CONSTRAINT> SelectShapeAutoConstraints( BOARD* aBoard, const PCB_SHAPE* aShape, BOARD_ITEM* aParent,
218 bool aAxisConstraint );
219
220
222bool ConstraintIsDuplicateOnBoard( BOARD* aBoard, const PCB_CONSTRAINT* aConstraint );
223
224
230std::vector<CONSTRAINT_ANCHOR_POINT> ConstraintItemAnchors( const BOARD_ITEM* aItem );
231
232
237std::optional<VECTOR2I> ConstraintAnchorPosition( BOARD* aBoard, const CONSTRAINT_MEMBER& aMember );
238
239
247double InitialConstraintValue( PCB_CONSTRAINT_TYPE aType, double aMeasured,
248 const std::map<PCB_CONSTRAINT_TYPE, double>& aRemembered );
249
250
256std::optional<KIID> NearestConstrainedShape( const std::vector<PCB_SHAPE*>& aCandidates,
257 const VECTOR2I& aPos, int aMaxDist );
258
259
267std::optional<KIID> SelectRadialDimensionTarget( BOARD* aBoard, const KIID& aDimension,
268 const VECTOR2I& aCenter, const VECTOR2I& aRim,
269 double aMaxDist );
270
271
279bool DimensionEndpointsBound( BOARD* aBoard, const PCB_DIMENSION_BASE* aDimension );
280
281
290
291
294bool DimensionHasValueMode( const PCB_DIMENSION_BASE* aDimension );
295
296
304
305
310bool DimensionCanDrive( BOARD* aBoard, const PCB_DIMENSION_BASE* aDimension );
311
312
318DIM_VALUE_MODE DimensionValueMode( BOARD* aBoard, const PCB_DIMENSION_BASE* aDimension );
319
320
338 std::optional<int> aDrivingLengthIU,
339 const std::optional<wxString>& aOverrideText,
340 const std::function<void( BOARD_ITEM* )>& aBeforeModify,
341 const std::function<void( BOARD_ITEM* )>& aStageAdd,
342 const std::function<void( BOARD_ITEM* )>& aBeforeRemove );
343
344
356void RemapPolygonVertexMembers( BOARD* aBoard, const KIID& aPoly, int aChangedIndex, int aDelta,
357 const std::function<void( BOARD_ITEM* )>& aBeforeModify,
358 const std::function<void( BOARD_ITEM* )>& aBeforeRemove );
359
360#endif // CONSTRAINT_BUILDER_H_
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
Definition kiid.h:46
A geometric constraint between board items (issue #2329).
Abstract dimension API.
Definition seg.h:38
DIM_VALUE_MODE DimensionValueMode(BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
The value mode aDimension is in, derived from state: a self driving length means Driving,...
void RemapPolygonVertexMembers(BOARD *aBoard, const KIID &aPoly, int aChangedIndex, int aDelta, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::function< void(BOARD_ITEM *)> &aBeforeRemove)
Repoint persisted VERTEX constraint members after an outline edit of polygon aPoly inserts or removes...
std::optional< CONSTRAINT_MEMBER > NearestConstraintAnchor(BOARD *aBoard, const VECTOR2I &aPos, double aMaxDist, const std::vector< CONSTRAINT_MEMBER > &aExclude={}, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Find the constrainable-item anchor (a shape's segment/arc endpoint or centre, or a dimension's featur...
std::vector< AUTO_CONSTRAINT > SelectShapeAutoConstraints(BOARD *aBoard, const PCB_SHAPE *aShape, BOARD_ITEM *aParent, bool aAxisConstraint)
Choose the constraints a freshly drawn shape should get from what its features landed on.
double InitialConstraintValue(PCB_CONSTRAINT_TYPE aType, double aMeasured, const std::map< PCB_CONSTRAINT_TYPE, double > &aRemembered)
Value a freshly authored constraint dialog should open with.
EDA_ANGLE MeasureCornerAngle(const SEG &aA, const SEG &aB)
The corner angle between two segments, in the closed range [0, 180] degrees.
bool DimensionHasValueMode(const PCB_DIMENSION_BASE *aDimension)
True for dimension types with a measured value aligned orthogonal or radial offering the Driven Drivi...
PCB_CONSTRAINT * FindDimensionLengthConstraint(BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
Self FIXED_LENGTH constraint whose members are exactly aDimension START and END or nullptr the drivin...
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintItemAnchors(const BOARD_ITEM *aItem)
The constraint anchors an item exposes.
std::optional< KIID > NearestConstrainedShape(const std::vector< PCB_SHAPE * > &aCandidates, const VECTOR2I &aPos, int aMaxDist)
The candidate shape whose outline aPos hits within aMaxDist, or std::nullopt.
std::vector< PCB_SHAPE * > CollectConstraintShapes(BOARD *aBoard, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Every PCB_SHAPE on a visible layer (drawings plus footprint graphics) – the candidates constraints ca...
std::optional< CONSTRAINT_ANCHOR_POINT > ConstraintShapeVertex(const PCB_SHAPE *aShape, int aIndex)
VERTEX anchor at ordinal aIndex of a rectangle or eligible polygon or std::nullopt if the shape has n...
wxString ConstraintSelectionHint(PCB_CONSTRAINT_TYPE aType)
A sentence naming what aType needs selected, for the moment a selection does not fit it and the tool ...
std::optional< KIID > NearestOutlineShape(BOARD *aBoard, const VECTOR2I &aPos, double aMaxDist, bool aAllowCircle, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
The shape whose outline is nearest aPos within aMaxDist.
std::unique_ptr< PCB_CONSTRAINT > BuildConstraintFromItems(BOARD_ITEM *aParent, PCB_CONSTRAINT_TYPE aType, const std::vector< BOARD_ITEM * > &aItems)
Build a constraint of aType from a set of selected board items, or nullptr if the selection does not ...
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintShapeAnchors(const PCB_SHAPE *aShape)
Enumerate a shape constraint anchors with positions segment and arc endpoints arc centre circle centr...
std::optional< KIID > SelectRadialDimensionTarget(BOARD *aBoard, const KIID &aDimension, const VECTOR2I &aCenter, const VECTOR2I &aRim, double aMaxDist)
Single circle or arc a radial dimension binds to or std::nullopt.
std::optional< VECTOR2I > ConstraintAnchorPosition(BOARD *aBoard, const CONSTRAINT_MEMBER &aMember)
Current location of a constraint member's anchor (its shape's START/END/CENTER, or a dimension's feat...
DIM_VALUE_MODE
Mode a value bearing dimension value is in Driven mirrors measured geometry Driving forces geometry t...
std::vector< ENDPOINT_BINDING > SelectEndpointBindings(BOARD *aBoard, const KIID &aItem, const VECTOR2I &aStart, const std::optional< VECTOR2I > &aEnd, double aMaxDist, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Choose the coincident bindings a freshly drawn item endpoints should take so it tracks the geometry i...
bool DimensionCanDrive(BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
True when Driving mode may be offered for aDimension needs both endpoints bound via DimensionEndpoint...
bool ConstraintPolygonIsModelable(const PCB_SHAPE *aShape)
True when polygon has one non empty hole free arc free outline making it solver eligible Shared by ad...
BOARD_ITEM * ResolveConstrainableItem(BOARD *aBoard, const KIID &aId)
The board item a constraint may reference: a PCB_SHAPE or a dimension, or nullptr for anything else (...
bool ConstraintIsDuplicateOnBoard(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint)
True if the board or one of its footprints already carries an equal constraint.
std::optional< CONSTRAINT_MEMBER > NearestAnchorAmong(const std::vector< PCB_SHAPE * > &aShapes, const VECTOR2I &aPos, double aMaxDist)
The {shape, anchor} member nearest aPos within aMaxDist among aShapes, or std::nullopt.
std::vector< BOARD_ITEM * > CollectConstrainableItems(BOARD *aBoard, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Every constrainable item on a visible layer – shapes plus dimensions – for board-wide anchor picking.
bool DimensionEndpointsBound(BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
True when both of aDimension measured endpoints are bound to anchors that still resolve a coincident ...
PCB_CONSTRAINT * SetDimensionValueMode(BOARD *aBoard, PCB_DIMENSION_BASE *aDimension, DIM_VALUE_MODE aMode, std::optional< int > aDrivingLengthIU, const std::optional< wxString > &aOverrideText, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::function< void(BOARD_ITEM *)> &aStageAdd, const std::function< void(BOARD_ITEM *)> &aBeforeRemove)
Apply a value mode transition to aDimension Driving creates or updates the driving length with aDrivi...
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
CONSTRAINT_ANCHOR
Which feature of a referenced board item participates in a constraint.
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
One constraint chosen for a freshly drawn shape.
std::unique_ptr< PCB_CONSTRAINT > constraint
A selectable feature of a shape (a segment endpoint, arc centre, ...) and its location.
int index
Vertex ordinal; only meaningful for the VERTEX anchor.
One participant in a constraint: a referenced board item plus the feature of that item that participa...
One of a drawn item feature points bound coincident to an object anchor by draw time auto constrain s...
CONSTRAINT_ANCHOR sourceAnchor
CONSTRAINT_MEMBER target
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683