KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_constraint.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 PCB_CONSTRAINT_H_
21#define PCB_CONSTRAINT_H_
22
23#include <optional>
24#include <vector>
25
26#include <board_item.h>
27
28
59
60
79
80
86{
89 int m_index = -1;
90
96
97 CONSTRAINT_MEMBER( const KIID& aItem, CONSTRAINT_ANCHOR aAnchor, int aIndex = -1 ) :
98 m_item( aItem ),
99 m_anchor( aAnchor ),
100 m_index( aIndex )
101 {
102 }
103
104 bool operator==( const CONSTRAINT_MEMBER& aOther ) const = default;
105};
106
107
109const char* ConstraintTypeToken( PCB_CONSTRAINT_TYPE aType );
110
112PCB_CONSTRAINT_TYPE ConstraintTypeFromToken( const wxString& aToken );
113
115const char* ConstraintAnchorToken( CONSTRAINT_ANCHOR aAnchor );
116
118CONSTRAINT_ANCHOR ConstraintAnchorFromToken( const wxString& aToken );
119
122wxString ConstraintAnchorLabel( CONSTRAINT_ANCHOR aAnchor );
123
126
129
132
133enum class BITMAPS : unsigned int;
134
137
138enum class EDA_UNITS : int;
139
140
152{
153public:
154 PCB_CONSTRAINT( BOARD_ITEM* aParent = nullptr );
156
157 static inline bool ClassOf( const EDA_ITEM* aItem )
158 {
159 return aItem && PCB_CONSTRAINT_T == aItem->Type();
160 }
161
162 wxString GetClass() const override { return wxT( "PCB_CONSTRAINT" ); }
163
166
167 const std::vector<CONSTRAINT_MEMBER>& GetMembers() const { return m_members; }
168 std::vector<CONSTRAINT_MEMBER>& Members() { return m_members; }
169
171 int aIndex = -1 )
172 {
173 m_members.emplace_back( aItem, aAnchor, aIndex );
174 }
175
176 bool HasValue() const { return m_value.has_value(); }
177 std::optional<double> GetValue() const { return m_value; }
178 void SetValue( std::optional<double> aValue ) { m_value = aValue; }
179
181 bool IsDriving() const { return m_driving; }
182 void SetDriving( bool aDriving ) { m_driving = aDriving; }
183
184 void Serialize( google::protobuf::Any& aContainer ) const override;
185 bool Deserialize( const google::protobuf::Any& aContainer ) override;
186
187 EDA_ITEM* Clone() const override;
188
189 double Similarity( const BOARD_ITEM& aOther ) const override;
190 bool operator==( const PCB_CONSTRAINT& aOther ) const;
191 bool operator==( const BOARD_ITEM& aOther ) const override;
192
193 // A constraint occupies no space and is never on a layer.
194 VECTOR2I GetPosition() const override { return VECTOR2I(); }
195 void SetPosition( const VECTOR2I& ) override {}
196
197 const BOX2I GetBoundingBox() const override { return BOX2I(); }
198
199 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override { return false; }
200 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
201 {
202 return false;
203 }
204
205 std::vector<int> ViewGetLayers() const override { return {}; }
206
207 // A constraint has no geometry, so the spatial transforms are no-ops (the base
208 // implementations wxFAIL_MSG). Its members move with their own host items.
209 void Move( const VECTOR2I& aMoveVector ) override {}
210 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override {}
211 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override {}
212 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override {}
213
215 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
216 FLASHING aFlash = FLASHING::DEFAULT ) const override;
217
218 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
219 BITMAPS GetMenuImage() const override;
220
221 void RemapKIIDs( const std::map<KIID, KIID>& aIdMap ) override;
222
223#if defined( DEBUG )
224 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
225#endif
226
227protected:
228 void swapData( BOARD_ITEM* aImage ) override;
229
230private:
232 std::vector<CONSTRAINT_MEMBER> m_members;
233 std::optional<double> m_value;
235};
236
237
245wxString ConstraintDisplayLabel( const PCB_CONSTRAINT& aConstraint, EDA_UNITS aUnits );
246
247
254wxString ConstraintMemberLabel( BOARD_ITEM* aItem, const CONSTRAINT_MEMBER& aMember,
255 UNITS_PROVIDER* aUnitsProvider );
256
257
264bool ConstraintsAreDuplicate( const PCB_CONSTRAINT& aA, const PCB_CONSTRAINT& aB );
265
266#endif // PCB_CONSTRAINT_H_
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:85
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
Definition kiid.h:44
A geometric constraint between board items (issue #2329).
void swapData(BOARD_ITEM *aImage) override
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
const std::vector< CONSTRAINT_MEMBER > & GetMembers() const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this item.
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
std::optional< double > GetValue() const
PCB_CONSTRAINT(BOARD_ITEM *aParent=nullptr)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool IsDriving() const
A driving constraint forces its value; a reference (non-driving) one only measures it.
PCB_CONSTRAINT_TYPE GetConstraintType() const
void AddMember(const KIID &aItem, CONSTRAINT_ANCHOR aAnchor=CONSTRAINT_ANCHOR::WHOLE, int aIndex=-1)
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
bool operator==(const PCB_CONSTRAINT &aOther) const
wxString GetClass() const override
Return the class name.
std::optional< double > m_value
PCB_CONSTRAINT_TYPE m_type
bool HasValue() const
void SetValue(std::optional< double > aValue)
VECTOR2I GetPosition() const override
void SetConstraintType(PCB_CONSTRAINT_TYPE aType)
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void RemapKIIDs(const std::map< KIID, KIID > &aIdMap) override
Remap KIIDs this item stores to reference other items (e.g.
void SetDriving(bool aDriving)
std::vector< CONSTRAINT_MEMBER > m_members
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
std::vector< CONSTRAINT_MEMBER > & Members()
static bool ClassOf(const EDA_ITEM *aItem)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetPosition(const VECTOR2I &) override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Empty shape so any generic GetItemSet()/RunOnChildren consumer stays safe.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
EDA_UNITS
Definition eda_units.h:44
@ FIXED_LENGTH
Dragged line maintains its length, adjacent lines adjust angles.
KIID niluuid(0)
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
FLIP_DIRECTION
Definition mirror.h:23
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 compare...
wxString ConstraintTypeGlyph(PCB_CONSTRAINT_TYPE aType)
Compact glyph for a constraint type (e.g. "//", "=") for on-canvas badges.
PCB_CONSTRAINT_TYPE ConstraintTypeFromToken(const wxString &aToken)
Parse a constraint-type token; returns UNDEFINED for an unknown token.
BITMAPS ConstraintTypeBitmap(PCB_CONSTRAINT_TYPE aType)
Badge icon for a constraint type; INVALID_BITMAP for UNDEFINED.
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.
CONSTRAINT_ANCHOR
Which feature of a referenced board item participates in a constraint.
@ MID
Midpoint of a segment or arc.
@ RADIUS
The radius (scalar feature) of an arc or circle.
@ WHOLE
The item as a whole (a segment as a line, a circle).
@ START
First endpoint of a segment or arc.
wxString ConstraintTypeLabel(PCB_CONSTRAINT_TYPE aType)
Human-readable name of a constraint type (e.g. "Parallel"), for menus and lists.
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 suc...
CONSTRAINT_ANCHOR ConstraintAnchorFromToken(const wxString &aToken)
Parse an anchor token; returns WHOLE for an unknown token.
const char * ConstraintTypeToken(PCB_CONSTRAINT_TYPE aType)
Stable file-format token for a constraint type (e.g. "parallel"). Used by serialization.
const char * ConstraintAnchorToken(CONSTRAINT_ANCHOR aAnchor)
Stable file-format token for a member anchor (e.g. "start").
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
@ CONCENTRIC
Two arcs/circles share a center.
@ SYMMETRIC
Two points are mirror images about an axis.
@ FIXED_POSITION
A point is locked at its current location.
@ VERTICAL
A segment (or two points) is vertical.
@ TANGENT
A line and a curve, or two curves, touch tangentially.
@ COINCIDENT
Two points are made to coincide.
@ PERPENDICULAR
Two segments are perpendicular.
@ FIXED_RADIUS
An arc/circle has a driving radius value.
@ HORIZONTAL
A segment (or two points) is horizontal.
@ EQUAL_RADIUS
Two arcs/circles have equal radius.
@ MIDPOINT
A point is the midpoint of a segment.
@ POINT_ON_LINE
A point lies on a segment's supporting line.
@ ANGULAR_DIMENSION
An angle between members (driving or reference).
@ COLLINEAR
Two segments lie on the same line.
@ ARC_ANGLE
An arc has a driving or reference swept-angle value.
@ PARALLEL
Two segments are parallel.
@ EQUAL_LENGTH
Two segments have equal length.
wxString ConstraintAnchorLabel(CONSTRAINT_ANCHOR aAnchor)
Translated name of the feature an anchor references (e.g.
wxString ConstraintDisplayLabel(const PCB_CONSTRAINT &aConstraint, EDA_UNITS aUnits)
Display label for a constraint in lists and menus.
One participant in a constraint: a referenced board item plus the feature of that item that participa...
KIID m_item
Referenced board item, usually a PCB_SHAPE.
CONSTRAINT_MEMBER(const KIID &aItem, CONSTRAINT_ANCHOR aAnchor, int aIndex=-1)
CONSTRAINT_ANCHOR m_anchor
Which feature of that item participates.
bool operator==(const CONSTRAINT_MEMBER &aOther) const =default
int m_index
Vertex ordinal; only meaningful for the VERTEX anchor.
@ PCB_CONSTRAINT_T
class PCB_CONSTRAINT, a geometric constraint between board items
Definition typeinfo.h:238
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683