KiCad PCB EDA Suite
pns_item.cpp
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2014 CERN
5  * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "pns_node.h"
23 #include "pns_item.h"
24 #include "pns_line.h"
25 
27 
28 namespace PNS {
29 
30 bool ITEM::collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
31  const NODE* aParentNode, bool aDifferentNetsOnly ) const
32 {
33  // same nets? no collision!
34  if( aDifferentNetsOnly && m_net == aOther->m_net && m_net >= 0 && aOther->m_net >= 0 )
35  return false;
36 
37  // check if we are not on completely different layers first
38  if( !m_layers.Overlaps( aOther->m_layers ) )
39  return false;
40 
41  if( aNeedMTV )
42  return Shape()->Collide( aOther->Shape(), aClearance, *aMTV );
43  else
44  return Shape()->Collide( aOther->Shape(), aClearance );
45 }
46 
47 
48 bool ITEM::Collide( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
49  const NODE* aParentNode, bool aDifferentNetsOnly ) const
50 {
51  if( collideSimple( aOther, aClearance, aNeedMTV, aMTV, aParentNode, aDifferentNetsOnly ) )
52  return true;
53 
54  // special case for "head" line with a via attached at the end.
55  if( aOther->m_kind == LINE_T )
56  {
57  const LINE* line = static_cast<const LINE*>( aOther );
58  int clearance = aClearance - line->Width() / 2;
59 
60  if( line->EndsWithVia() )
61  {
62  return collideSimple( &line->Via(), clearance, aNeedMTV, aMTV, aParentNode,
63  aDifferentNetsOnly );
64  }
65  }
66 
67  return false;
68 }
69 
70 
71 std::string ITEM::KindStr() const
72 {
73  switch( m_kind )
74  {
75  case LINE_T: return "line";
76  case SEGMENT_T: return "segment";
77  case VIA_T: return "via";
78  case JOINT_T: return "joint";
79  case SOLID_T: return "solid";
80  default: return "unknown";
81  }
82 }
83 
84 
86 {
87 }
88 
89 }
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
ITEM.
Definition: pns_item.h:53
NODE.
Definition: pns_node.h:140
virtual ~ITEM()
Definition: pns_item.cpp:85
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
virtual bool Collide(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.cpp:48
LAYER_RANGE m_layers
Definition: pns_item.h:252
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:109
bool EndsWithVia() const
Definition: pns_line.h:267
VECTOR2I::extended_type ecoord
Definition: pns_item.cpp:26
bool collideSimple(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:30
std::string KindStr() const
Function KindStr()
Definition: pns_item.cpp:71
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:213
int m_net
Definition: pns_item.h:255
PnsKind m_kind
Definition: pns_item.h:248
int Width() const
Returns line width
Definition: pns_line.h:178
const VIA & Via() const
Definition: pns_line.h:272
Push and Shove diff pair dimensions (gap) settings dialog.