PCB Environment 2

Loading...
Searching...
No Matches
Object.hpp
1
2#ifndef GYM_PCB_OBJECT_H
3#define GYM_PCB_OBJECT_H
4
5#include "AShape.hpp"
6#include <string>
7
8 class CloneEnv;
9 class Via;
10
11 class Object
12{
13 protected:
14 Object(Object *parent, const std::string &name);
15 public:
16 virtual Object *clone(CloneEnv&) const { return 0; }
17 virtual ~Object();
18
19 const std::string& name() const { return mName; }
20 std::string getFullName() const;
21
22 uint id() const { return mId; }
23 void setId(uint id) { mId = id; }
24
25 bool hasParent() const { return !!mParent; }
26 Object *getParent() const { return mParent; }
27 Object *getChildAt(const Point_2&) const;
28
29 const std::vector<Object *>& getChildren() const { return mChildren; }
30 void addChild(Object&);
31 uint numChildren() const { return mChildren.size(); }
32 bool hasChildren() const { return !mChildren.empty(); }
33 void removeChild(Object&);
34
35 const Point_2& getCenter() const { return mCenter; }
37 Point_25 getCenter25() const;
38 const Bbox_2 getBbox() const { return mShape->bbox(); }
39
40 virtual void addOccludedObject(Object&) { }
41
42 void translate(const Vector_2&);
43 void transform(const Aff_transformation_2&);
44 void rotateAround(const Point_2 &refPoint, Real angleRadians);
45
46 bool isOnLayer(int z) const { return mLayerRange[0] <= z && z <= mLayerRange[1]; }
47 int minLayer() const { return mLayerRange[0]; }
48 int maxLayer() const { return mLayerRange[1]; }
49 void setLayer(int);
50 void setLayerRange(int, int);
51 int getSingleLayer() const { assert(mLayerRange[0] == mLayerRange[1]); return mLayerRange[0]; }
52 bool sharesLayer(const Object&) const;
53
54 Real getClearance() const { return mClearance; }
55 void setClearance(Real c) { mClearance = c; }
56
57 AShape *getShape() const { return mShape.get(); }
58
59 void setShape(const Circle_2&);
60 void setShape(const Triangle_2&);
61 void setShape(const Iso_rectangle_2&);
62 void setShape(const Polygon_2&);
63 void setShape(const WideSegment_25&, Real angleTolerance = 0.0);
64 void setShape(Polygon_2&&);
65
66 bool canRouteInside() const { return mCanRouteInside; }
67 void setCanRouteInside(bool b) { mCanRouteInside = b; }
68 bool canPlaceViasInside() const { return mCanPlaceViasInside; }
69 void setCanPlaceViasInside(bool b) { mCanPlaceViasInside = b; }
70 bool isSelected() const { return mSelectionFlag; }
71 void setSelected(bool b) { mSelectionFlag = b; }
72 void setSelected(bool b, uint recursion);
73
74 bool violatesClearance(const Via&, Real clearance, Point_25 * = 0) const;
75 bool violatesClearance(const WideSegment_25&, Real clearance, Point_25 * = 0) const;
76
77 Real distanceTo(const Point_2 &v) const { return std::sqrt(mShape->squared_distance(v)); }
78 bool contains2D(const Point_2 &v) const { return mShape->contains(v); }
79 bool contains3D(const Point_25 &v) const { return mShape->contains(v.xy()) && isOnLayer(v.z()); }
80 bool isInsideBbox(const Point_2 &v) const;
81 bool isInsideBbox(const Point_2 &v, int zmin, int zmax) const;
82 bool intersects(const Bbox_2 &B) const { return mShape->intersects(B); }
83 bool intersects(const WideSegment_25 &s) const { return isOnLayer(s.z()) && mShape->intersects(s); }
84 bool intersects(const Object &A) const { return sharesLayer(A) && mShape->intersects(*A.getShape()); }
85 bool bboxTest(const Bbox_2 &B) { return CGAL::do_overlap(getBbox(), B); }
86 bool bboxTest(const Bbox_2 &B, int z0, int z1 = -1);
87
88 bool isContainerOf(const Object&) const;
89
90 void copyFrom(CloneEnv&, const Object&);
91
92 virtual std::string str() const { return "?"; }
93 virtual PyObject *getPy(uint depth) const;
94
95 template<typename T> bool is_a() const { return !!dynamic_cast<const T *>(this); }
96 template<typename T> const T *as() const { return dynamic_cast<const T *>(this); }
97 template<typename T> T *as() { return dynamic_cast<T *>(this); }
98
99 protected:
100 std::unique_ptr<AShape> mShape;
101 Point_2 mCenter;
102 Object *const mParent;
103 std::vector<Object *> mChildren;
104 std::string mName;
105 uint mId;
106 uint mChildIndex{std::numeric_limits<uint>::max()};
107 int mLayerRange[2]{-1,-1};
108 Real mClearance{0.0};
109 bool mCanRouteInside{false};
110 bool mCanPlaceViasInside{true};
111 bool mSelectionFlag{false};
112
113 private:
114 void update() { mCenter = mShape->centroid(); }
115};
116
117 inline Point_25 Object::getCenter25() const
118{
119 int z = minLayer();
120 if (hasParent())
121 z = std::max(z, getParent()->minLayer());
122 return Point_25(getCenter(), z);
123}
124
125 inline bool Object::sharesLayer(const Object &A) const
126{
127 return minLayer() <= A.maxLayer() && maxLayer() >= A.minLayer();
128}
129
130 inline bool Object::bboxTest(const Bbox_2 &B, int z0, int z1)
131{
132 if (z1 < 0)
133 z1 = z0;
134 if (mLayerRange[0] > z1 || mLayerRange[1] < z0)
135 return false;
136 return bboxTest(B);
137}
138
139#endif // GYM_PCB_OBJECT_H
AShape
Definition AShape.hpp:21
CloneEnv
Definition Clone.hpp:17
Object
Definition Object.hpp:12
Object::getCenter25
Point_25 getCenter25() const
Layer is set to max(LayerMin, parent.LayerMin) to account for bottom layer thru-hole pins.
Definition Object.hpp:117
Point_25
Definition Geometry.hpp:131
Via
Definition Via.hpp:10
WideSegment_25
Definition AShape.hpp:332