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  m_layerPairs.clear();
128 }
129 
130 
132 {
133  m_layerPairs.clear();
134 }
135 
136 
137 void SIZES_SETTINGS::AddLayerPair( int aL1, int aL2 )
138 {
139  int top = std::min( aL1, aL2 );
140  int bottom = std::max( aL1, aL2 );
141 
142  m_layerPairs[bottom] = top;
143  m_layerPairs[top] = bottom;
144 }
145 
146 
148 {
149  m_trackWidth = aSettings.GetCurrentTrackWidth();
150  m_viaDiameter = aSettings.GetCurrentViaSize();
151  m_viaDrill = aSettings.GetCurrentViaDrill();
152 }
153 
154 
156 {
157  if( m_layerPairs.empty() )
158  return F_Cu;
159  else
160  return m_layerPairs.begin()->first;
161 }
162 
163 
165 {
166  if( m_layerPairs.empty() )
167  return B_Cu;
168  else
169  return m_layerPairs.begin()->second;
170 }
171 
172 }
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.
NETCLASSPTR GetDefault() const
Function GetDefault.
Class NODE.
Definition: pns_node.h:137
Class BOARD to handle a board.
ENTRIES & Items()
Definition: pns_itemset.h:137
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:187
Class JOINT.
Definition: pns_joint.h:44
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:530
void ImportCurrent(BOARD_DESIGN_SETTINGS &aSettings)
int inheritTrackWidth(ITEM *aItem)
NODE * Owner() const
Function Owner()
Definition: pns_item.h:259
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
Class NETINFO_ITEM handles the data for a net.
const wxString & GetClassName() const
Function GetClassName returns the class name.
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:166
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:177
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.