KiCad PCB EDA Suite
pns_sizes_settings.cpp
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2014 CERN
5  * Copyright (C) 2016 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 <class_board.h>
23 
24 #include "pns_item.h"
25 #include "pns_via.h"
26 #include "pns_solid.h"
27 #include "pns_node.h"
28 #include "pns_sizes_settings.h"
29 
30 namespace PNS {
31 
33 {
34  VECTOR2I p;
35 
36  assert( aItem->Owner() != NULL );
37 
38  switch( aItem->Kind() )
39  {
40  case ITEM::VIA_T:
41  p = static_cast<VIA*>( aItem )->Pos();
42  break;
43 
44  case ITEM::SOLID_T:
45  p = static_cast<SOLID*>( aItem )->Pos();
46  break;
47 
48  case ITEM::SEGMENT_T:
49  return static_cast<SEGMENT*>( aItem )->Width();
50 
51  default:
52  return 0;
53  }
54 
55  JOINT* jt = static_cast<NODE*>( aItem->Owner() )->FindJoint( p, aItem );
56 
57  assert( jt != NULL );
58 
59  int mval = INT_MAX;
60 
61 
62  ITEM_SET linkedSegs = jt->Links();
63  linkedSegs.ExcludeItem( aItem ).FilterKinds( ITEM::SEGMENT_T );
64 
65  for( ITEM* item : linkedSegs.Items() )
66  {
67  int w = static_cast<SEGMENT*>( item )->Width();
68  mval = std::min( w, mval );
69  }
70 
71  return ( mval == INT_MAX ? 0 : mval );
72 }
73 
74 
75 void SIZES_SETTINGS::Init( BOARD* aBoard, ITEM* aStartItem, int aNet )
76 {
78 
79  NETCLASSPTR netClass;
80  int net = aNet;
81 
82  if( aStartItem )
83  net = aStartItem->Net();
84 
85  if( net >= 0 )
86  {
87  NETINFO_ITEM* ni = aBoard->FindNet( net );
88 
89  if( ni )
90  {
91  wxString netClassName = ni->GetClassName();
92  netClass = bds.m_NetClasses.Find( netClassName );
93  }
94  }
95 
96  if( !netClass )
97  netClass = bds.m_NetClasses.GetDefault();
98 
99  m_trackWidth = 0;
100 
101  if( bds.m_UseConnectedTrackWidth && aStartItem != NULL )
102  {
103  m_trackWidth = inheritTrackWidth( aStartItem );
104  }
105 
106  if( !m_trackWidth && ( bds.UseNetClassTrack() && netClass != NULL ) ) // netclass value
107  {
108  m_trackWidth = netClass->GetTrackWidth();
109  }
110 
111  if( !m_trackWidth )
112  {
114  }
115 
116  if( bds.UseNetClassVia() && netClass != NULL ) // netclass value
117  {
118  m_viaDiameter = netClass->GetViaDiameter();
119  m_viaDrill = netClass->GetViaDrill();
120  }
121  else
122  {
125  }
126 
127  if( bds.UseNetClassDiffPair() && netClass != NULL )
128  {
129  m_diffPairWidth = netClass->GetDiffPairWidth();
130  m_diffPairGap = netClass->GetDiffPairGap();
131  m_diffPairViaGap = netClass->GetDiffPairViaGap();
132  }
133  else if( bds.UseCustomDiffPairDimensions() )
134  {
138  }
139  else
140  {
144  }
145 
146  m_layerPairs.clear();
147 }
148 
149 
151 {
152  m_layerPairs.clear();
153 }
154 
155 
156 void SIZES_SETTINGS::AddLayerPair( int aL1, int aL2 )
157 {
158  int top = std::min( aL1, aL2 );
159  int bottom = std::max( aL1, aL2 );
160 
161  m_layerPairs[bottom] = top;
162  m_layerPairs[top] = bottom;
163 }
164 
165 
167 {
168  m_trackWidth = aSettings.GetCurrentTrackWidth();
169  m_viaDiameter = aSettings.GetCurrentViaSize();
170  m_viaDrill = aSettings.GetCurrentViaDrill();
171 
173  m_diffPairGap = aSettings.GetCurrentDiffPairGap();
175 }
176 
177 
179 {
180  if( m_layerPairs.empty() )
181  return F_Cu;
182  else
183  return m_layerPairs.begin()->first;
184 }
185 
186 
188 {
189  if( m_layerPairs.empty() )
190  return B_Cu;
191  else
192  return m_layerPairs.begin()->second;
193 }
194 
195 }
ITEM.
Definition: pns_item.h:53
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
bool UseNetClassTrack() const
Function UseNetClassTrack returns true if netclass values should be used to obtain appropriate track ...
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:141
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
int GetCurrentDiffPairGap() const
Function GetCurrentDiffPairGap.
bool UseNetClassDiffPair() const
Function UseNetClassDiffPair returns true if netclass values should be used to obtain appropriate dif...
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
ENTRIES & Items()
Definition: pns_itemset.h:140
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
Definition: pns_itemset.cpp:70
void UseCustomDiffPairDimensions(bool aEnabled)
Function UseCustomDiffPairDimensions Enables/disables custom differential pair dimensions.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
ITEM_SET & ExcludeItem(const ITEM *aItem)
int GetCustomDiffPairWidth()
Function GetCustomDiffPairWidth.
ITEM_SET & Links()
Definition: pns_joint.h:206
JOINT.
Definition: pns_joint.h:43
#define NULL
int Net() const
Definition: pns_item.h:149
bool UseNetClassVia() const
Function UseNetClassVia returns true if netclass values should be used to obtain appropriate via size...
int GetCurrentDiffPairWidth() const
Function GetCurrentDiffPairWidth.
void Init(BOARD *aBoard, ITEM *aStartItem=NULL, int aNet=-1)
void ImportCurrent(BOARD_DESIGN_SETTINGS &aSettings)
int inheritTrackWidth(ITEM *aItem)
int GetCurrentViaSize() const
Function GetCurrentViaSize.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
std::map< int, int > m_layerPairs
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
int GetCustomDiffPairViaGap()
Function GetCustomDiffPairViaGap.
int GetCurrentDiffPairViaGap() const
Function GetCurrentDiffPairViaGap.
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:275
unsigned GetDiffPairIndex() const
Function GetDiffPairIndex.
void AddLayerPair(int aL1, int aL2)
NODE * Owner() const
Function Owner()
Definition: pns_item.h:173
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:137
Push and Shove diff pair dimensions (gap) settings dialog.
int GetCustomDiffPairGap()
Function GetCustomDiffPairGap.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.