KiCad PCB EDA Suite
LAYER_ITEM_2D Class Reference

Make solid geometry for objects on layers. More...

#include <layer_item_2d.h>

Inheritance diagram for LAYER_ITEM_2D:
OBJECT_2D

Public Member Functions

 LAYER_ITEM_2D (const OBJECT_2D *aObjectA, std::vector< const OBJECT_2D * > *aObjectB, const OBJECT_2D *aObjectC, const BOARD_ITEM &aBoardItem)
 
 ~LAYER_ITEM_2D ()
 
bool Overlaps (const BBOX_2D &aBBox) const override
 Test if the box overlaps the object. More...
 
bool Intersects (const BBOX_2D &aBBox) const override
 a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅) More...
 
bool Intersect (const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
 
INTERSECTION_RESULT IsBBoxInside (const BBOX_2D &aBBox) const override
 Test this object if it's completely outside, intersects, or is completely inside aBBox. More...
 
bool IsPointInside (const SFVEC2F &aPoint) const override
 
const BOARD_ITEMGetBoardItem () const
 
const BBOX_2DGetBBox () const
 
const SFVEC2FGetCentroid () const
 
OBJECT_2D_TYPE GetObjectType () const
 

Protected Attributes

BBOX_2D m_bbox
 
SFVEC2F m_centroid
 
OBJECT_2D_TYPE m_obj_type
 
const BOARD_ITEMm_boardItem
 

Private Attributes

const OBJECT_2Dm_objectA
 
std::vector< const OBJECT_2D * > * m_objectB
 
const OBJECT_2Dm_objectC
 

Detailed Description

Make solid geometry for objects on layers.

The operation is in the form (A - B) /\ C For almost all of the layers it translate something like: A (a via, a track, pad, polygon), B (a via hole, a THT hole, .. ), C the board (epoxy) For layers like Solder mask that are negative: A ( epoxy ), B( pads, polygons, ..), C=1

Some notes: BODY = PCB_outlines - PCB_holes - (Modules_THT_holes + VIA_THT_holes)

Plated_vias_and_holes = Tracks.Vias + Modules.PlatedHoles

Layer.cu = ( Tracks.cu + Modules_Pads.cu + Modules_Graphics.cu + Layer_zones.cu + PCB_drawings.cu - Layer_VIA_holes ) & BODY

Layer.Mask = BODY - (PCB_drawing.Mask + Modules_Graphics.Mask + Modules_Pads.Mask + Layer_zones.Mask ) Layer.Paste = (PCB_drawing.Paste + Modules_Graphics.Paste + Modules_Pads.Paste + Layer_zones.Paste) & BODY Layer.Silk = (PCB_drawing.Silk + Modules_Graphics.Silk + Modules_Pads.Silk + Layer_zones.Paste) & BODY

BODY = A - B /\ 1 Layer.cu = A - B /\ C Layer.mask = A - B /\ 1 Layers.Paste = A - 0 /\ C Layers.Silk = A - 0 /\ C

BODY = P - T /\ 1 Layer.cu = T - H /\ BODY Layer.mask = BODY - M /\ 1 Layers.Paste = P - 0 /\ BODY Layers.Silk = S - 0 /\ BODY

Definition at line 79 of file layer_item_2d.h.

Constructor & Destructor Documentation

◆ LAYER_ITEM_2D()

LAYER_ITEM_2D::LAYER_ITEM_2D ( const OBJECT_2D aObjectA,
std::vector< const OBJECT_2D * > *  aObjectB,
const OBJECT_2D aObjectC,
const BOARD_ITEM aBoardItem 
)

Definition at line 35 of file layer_item_2d.cpp.

36  :
37  OBJECT_2D( OBJECT_2D_TYPE::CSG, aBoardItem ),
38  m_objectA( aObjectA ),
39  m_objectB( aObjectB ),
40  m_objectC( aObjectC )
41 {
42  wxASSERT( aObjectA );
43 
44  m_bbox.Reset();
45  m_bbox.Set( aObjectA->GetBBox() );
48 
49  wxASSERT( m_bbox.IsInitialized() );
50 }
BBOX_2D m_bbox
Definition: object_2d.h:110
const OBJECT_2D * m_objectA
Definition: layer_item_2d.h:95
SFVEC2F GetCenter() const
Definition: bbox_2d.cpp:119
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_2d.cpp:61
SFVEC2F m_centroid
Definition: object_2d.h:111
OBJECT_2D(OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition: object_2d.cpp:36
void Reset()
Reset the bounding box to zero and uninitialize it.
Definition: bbox_2d.cpp:86
const BBOX_2D & GetBBox() const
Definition: object_2d.h:103
const OBJECT_2D * m_objectC
Definition: layer_item_2d.h:97
std::vector< const OBJECT_2D * > * m_objectB
Definition: layer_item_2d.h:96
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition: bbox_2d.cpp:162
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_2d.cpp:79

References CSG, OBJECT_2D::GetBBox(), BBOX_2D::GetCenter(), BBOX_2D::IsInitialized(), OBJECT_2D::m_bbox, OBJECT_2D::m_centroid, BBOX_2D::Reset(), BBOX_2D::ScaleNextUp(), and BBOX_2D::Set().

◆ ~LAYER_ITEM_2D()

LAYER_ITEM_2D::~LAYER_ITEM_2D ( )

Definition at line 53 of file layer_item_2d.cpp.

54 {
55  if( ( (void*) m_objectB != CSGITEM_EMPTY ) && ( (void*) m_objectB != CSGITEM_FULL ) )
56  {
57  delete m_objectB;
58  m_objectB = nullptr;
59  }
60 }
#define CSGITEM_FULL
Definition: layer_item_2d.h:39
#define CSGITEM_EMPTY
Definition: layer_item_2d.h:38
std::vector< const OBJECT_2D * > * m_objectB
Definition: layer_item_2d.h:96

References CSGITEM_EMPTY, CSGITEM_FULL, and m_objectB.

Member Function Documentation

◆ GetBBox()

const BBOX_2D& OBJECT_2D::GetBBox ( ) const
inlineinherited

◆ GetBoardItem()

const BOARD_ITEM& OBJECT_2D::GetBoardItem ( ) const
inlineinherited

Definition at line 66 of file object_2d.h.

66 { return m_boardItem; }
const BOARD_ITEM & m_boardItem
Definition: object_2d.h:114

References OBJECT_2D::m_boardItem.

Referenced by RENDER_3D_RAYTRACE::createItemsFromContainer().

◆ GetCentroid()

const SFVEC2F& OBJECT_2D::GetCentroid ( ) const
inlineinherited

Definition at line 105 of file object_2d.h.

105 { return m_centroid; }
SFVEC2F m_centroid
Definition: object_2d.h:111

References OBJECT_2D::m_centroid.

Referenced by LAYER_ITEM::LAYER_ITEM(), sortByCentroidX(), sortByCentroidY(), and sortByCentroidZ().

◆ GetObjectType()

◆ Intersect()

bool LAYER_ITEM_2D::Intersect ( const RAYSEG2D aSegRay,
float *  aOutT,
SFVEC2F aNormalOut 
) const
overridevirtual
Parameters
aOutTa value between 0.0 and 1.0 in relation to the time of the hit of the segment.

Implements OBJECT_2D.

Definition at line 80 of file layer_item_2d.cpp.

81 {
83  return false;
84 
85  SFVEC2F currentRayPos = aSegRay.m_Start;
86  SFVEC2F currentNormal;
87  RAYSEG2D currentRay = aSegRay;
88 
89  if( !m_objectA->IsPointInside( aSegRay.m_Start ) )
90  {
91  //move ray point to start of main object
92  float tmpRayDist;
93 
94  if( !m_objectA->Intersect( aSegRay, &tmpRayDist, &currentNormal ) )
95  return false;
96 
97  currentRayPos = aSegRay.atNormalized( tmpRayDist + 0.003f );
98 
99  currentRay = RAYSEG2D( currentRayPos, aSegRay.m_End );
100  }
101 
102  // move through the union of subtracted regions
103  if( m_objectB )
104  {
105  for( unsigned int l = 0; l < ( m_objectB->size() * 2 ); ++l )
106  {
107  bool wasCrossedSubVol = false;
108 
109  //check against all subbed objects
110  for( unsigned int i = 0; i < m_objectB->size(); ++i )
111  {
112  if( ( (const OBJECT_2D*) ( *m_objectB )[i] )->IsPointInside( currentRayPos ) )
113  {
114  // ray point is inside a subtracted region, so move it to the end of the
115  // subtracted region
116  float hitDist;
117  SFVEC2F tmpNormal;
118 
119  if( !( (const OBJECT_2D*) ( *m_objectB )[i] )
120  ->Intersect( currentRay, &hitDist, &tmpNormal ) )
121  return false; // ray hit main object but did not leave subtracted volume
122 
123  wxASSERT( hitDist <= 1.0f );
124 
125  if( hitDist > FLT_EPSILON )
126  {
127  wasCrossedSubVol = true;
128 
129  currentRayPos =
130  currentRay.atNormalized( glm::min( hitDist + 0.0001f, 1.0f ) );
131 
132  currentRay = RAYSEG2D( currentRayPos, aSegRay.m_End );
133 
134  currentNormal = tmpNormal * -1.0f;
135  }
136  }
137  }
138 
139  if( !wasCrossedSubVol )
140  break;
141  }
142  }
143 
144  if( aNormalOut )
145  *aNormalOut = currentNormal;
146 
147  if( aOutT )
148  *aOutT = glm::min(
149  glm::max( glm::length( currentRayPos - aSegRay.m_Start ) / aSegRay.m_Length, 0.0f ),
150  1.0f );
151 
152  return true;
153 }
SFVEC2F atNormalized(float t) const
Return the position at t.
Definition: ray.h:135
const OBJECT_2D * m_objectA
Definition: layer_item_2d.h:95
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
float m_Length
Definition: ray.h:112
SFVEC2F m_End
Definition: ray.h:108
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
OBJECT_2D_TYPE GetObjectType() const
Definition: object_2d.h:107
std::vector< const OBJECT_2D * > * m_objectB
Definition: layer_item_2d.h:96
SFVEC2F m_Start
Definition: ray.h:107
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
Definition: ray.h:105

References RAYSEG2D::atNormalized(), DUMMYBLOCK, OBJECT_2D::GetObjectType(), OBJECT_2D::Intersect(), OBJECT_2D::IsPointInside(), RAYSEG2D::m_End, RAYSEG2D::m_Length, m_objectA, m_objectB, and RAYSEG2D::m_Start.

◆ Intersects()

bool LAYER_ITEM_2D::Intersects ( const BBOX_2D aBBox) const
overridevirtual

a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)

Implements OBJECT_2D.

Definition at line 63 of file layer_item_2d.cpp.

64 {
65  return m_bbox.Intersects( aBBox );
66  // !TODO: improve this implementation
67  //return false;
68 }
BBOX_2D m_bbox
Definition: object_2d.h:110
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_2d.cpp:211

References BBOX_2D::Intersects(), and OBJECT_2D::m_bbox.

◆ IsBBoxInside()

INTERSECTION_RESULT LAYER_ITEM_2D::IsBBoxInside ( const BBOX_2D aBBox) const
overridevirtual

Test this object if it's completely outside, intersects, or is completely inside aBBox.

Returns
INTERSECTION_RESULT

Implements OBJECT_2D.

Definition at line 156 of file layer_item_2d.cpp.

157 {
158 
159  // !TODO:
160 
162 }

References MISSES.

◆ IsPointInside()

bool LAYER_ITEM_2D::IsPointInside ( const SFVEC2F aPoint) const
overridevirtual

Implements OBJECT_2D.

Definition at line 165 of file layer_item_2d.cpp.

166 {
167  // Perform the operation (A - B) /\ C
168  if( m_objectA->IsPointInside( aPoint ) )
169  {
170 
171  if( m_objectB != CSGITEM_EMPTY )
172  {
173  for( unsigned int i = 0; i < m_objectB->size(); i++ )
174  {
175  if( ( *m_objectB )[i]->IsPointInside( aPoint ) )
176  return false;
177  }
178  }
179 
180  // !TODO: not yet implemented
181  //if( m_objectC && m_objectC != CSGITEM_FULL )
182  // return m_objectC->IsPointInside( aPoint );
183 
184  return true;
185  }
186 
187  return false;
188 }
const OBJECT_2D * m_objectA
Definition: layer_item_2d.h:95
#define CSGITEM_EMPTY
Definition: layer_item_2d.h:38
std::vector< const OBJECT_2D * > * m_objectB
Definition: layer_item_2d.h:96
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0

References CSGITEM_EMPTY, OBJECT_2D::IsPointInside(), m_objectA, and m_objectB.

◆ Overlaps()

bool LAYER_ITEM_2D::Overlaps ( const BBOX_2D aBBox) const
overridevirtual

Test if the box overlaps the object.

Conformance Implements the Overlaps function from the OGC Simple Feature Specification at http://www.opengeospatial.org/standards/sfa. a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a)I(b))) ∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b) It means that the result dimension of an overlap is the same dimensions of the bounding box (so the overlap cannot be a point or a line) and one of the boxes cannot full contain the other box.

Parameters
aBBoxis the bounding box to test.
Returns
true if the BBox intersects the object or is inside it.

Implements OBJECT_2D.

Definition at line 71 of file layer_item_2d.cpp.

72 {
73  // NOT IMPLEMENTED, why?
74  return false;
75 }

Member Data Documentation

◆ m_bbox

◆ m_boardItem

const BOARD_ITEM& OBJECT_2D::m_boardItem
protectedinherited

Definition at line 114 of file object_2d.h.

Referenced by OBJECT_2D::GetBoardItem().

◆ m_centroid

◆ m_obj_type

OBJECT_2D_TYPE OBJECT_2D::m_obj_type
protectedinherited

Definition at line 112 of file object_2d.h.

Referenced by OBJECT_2D::GetObjectType(), and OBJECT_2D::OBJECT_2D().

◆ m_objectA

const OBJECT_2D* LAYER_ITEM_2D::m_objectA
private

Definition at line 95 of file layer_item_2d.h.

Referenced by Intersect(), and IsPointInside().

◆ m_objectB

std::vector<const OBJECT_2D*>* LAYER_ITEM_2D::m_objectB
private

Definition at line 96 of file layer_item_2d.h.

Referenced by Intersect(), IsPointInside(), and ~LAYER_ITEM_2D().

◆ m_objectC

const OBJECT_2D* LAYER_ITEM_2D::m_objectC
private

Definition at line 97 of file layer_item_2d.h.


The documentation for this class was generated from the following files: