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.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  // Set the differential pair width/gap using netclass if selected
128  if( ( bds.UseNetClassTrack() && netClass != NULL ) )
129  {
130  m_diffPairWidth = netClass->GetDiffPairWidth();
131  m_diffPairGap = netClass->GetDiffPairGap();
132  }
133 
134  m_layerPairs.clear();
135 }
136 
137 
139 {
140  m_layerPairs.clear();
141 }
142 
143 
144 void SIZES_SETTINGS::AddLayerPair( int aL1, int aL2 )
145 {
146  int top = std::min( aL1, aL2 );
147  int bottom = std::max( aL1, aL2 );
148 
149  m_layerPairs[bottom] = top;
150  m_layerPairs[top] = bottom;
151 }
152 
153 
155 {
156  m_trackWidth = aSettings.GetCurrentTrackWidth();
157  m_viaDiameter = aSettings.GetCurrentViaSize();
158  m_viaDrill = aSettings.GetCurrentViaDrill();
159 }
160 
161 
163 {
164  if( m_layerPairs.empty() )
165  return F_Cu;
166  else
167  return m_layerPairs.begin()->first;
168 }
169 
170 
172 {
173  if( m_layerPairs.empty() )
174  return B_Cu;
175  else
176  return m_layerPairs.begin()->second;
177 }
178 
179 }
Class ITEM.
Definition: pns_item.h:53
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:144
NETCLASSPTR GetDefault() const
Function GetDefault.
Class NODE.
Definition: pns_node.h:136
Class BOARD to handle a board.
ENTRIES & Items()
Definition: pns_itemset.h:140
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
Definition: pns_itemset.cpp:70
ITEM_SET & ExcludeItem(const ITEM *aItem)
int GetCurrentViaSize() const
Function GetCurrentViaSize.
bool m_UseConnectedTrackWidth
if true, when creating a new track starting on an existing track, use this track width ...
ITEM_SET & Links()
Definition: pns_joint.h:200
Class JOINT.
Definition: pns_joint.h:43
bool UseNetClassTrack() const
Function UseNetClassTrack returns true if netclass values should be used to obtain appropriate track ...
void Init(BOARD *aBoard, ITEM *aStartItem=NULL, int aNet=-1)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
void ImportCurrent(BOARD_DESIGN_SETTINGS &aSettings)
int inheritTrackWidth(ITEM *aItem)
NODE * Owner() const
Function Owner()
Definition: pns_item.h:261
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
std::map< int, int > m_layerPairs
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
bool UseNetClassVia() const
Function UseNetClassVia returns true if netclass values should be used to obtain appropriate via size...
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
int Net() const
Function Net()
Definition: pns_item.h:179
void AddLayerPair(int aL1, int aL2)
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
Push and Shove diff pair dimensions (gap) settings dialog.
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
#define min(a, b)
Definition: auxiliary.h:85
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.