KiCad PCB EDA Suite
pns_log_file.cpp File Reference

Go to the source code of this file.

Functions

static const wxString readLine (FILE *f)
 
static std::shared_ptr< SHAPEparseShape (SHAPE_TYPE expectedType, wxStringTokenizer &aTokens)
 
bool parseCommonPnsProps (PNS::ITEM *aItem, const wxString &cmd, wxStringTokenizer &aTokens)
 
static PNS::SEGMENTparsePnsSegmentFromString (PNS::SEGMENT *aSeg, wxStringTokenizer &aTokens)
 
static PNS::VIAparsePnsViaFromString (PNS::VIA *aSeg, wxStringTokenizer &aTokens)
 
static PNS::ITEMparseItemFromString (wxStringTokenizer &aTokens)
 
bool comparePnsItems (const PNS::ITEM *a, const PNS::ITEM *b)
 

Function Documentation

◆ comparePnsItems()

bool comparePnsItems ( const PNS::ITEM a,
const PNS::ITEM b 
)

Definition at line 194 of file pns_log_file.cpp.

195{
196 if( a->Kind() != b->Kind() )
197 return false;
198
199 if( a->Net() != b->Net() )
200 return false;
201
202 if( a->Layers() != b->Layers() )
203 return false;
204
205 if( a->Kind() == PNS::ITEM::VIA_T )
206 {
207 auto va = static_cast<const PNS::VIA*>(a);
208 auto vb = static_cast<const PNS::VIA*>(b);
209
210 if( va->Diameter() != vb->Diameter() )
211 return false;
212
213 if( va->Drill() != vb->Drill() )
214 return false;
215
216 if( va->Pos() != vb->Pos() )
217 return false;
218
219 }
220 else if ( a->Kind() == PNS::ITEM::SEGMENT_T )
221 {
222 auto sa = static_cast<const PNS::SEGMENT*>(a);
223 auto sb = static_cast<const PNS::SEGMENT*>(b);
224
225 if( sa->Seg() != sb->Seg() )
226 return false;
227
228 if( sa->Width() != sb->Width() )
229 return false;
230 }
231
232 return true;
233}
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:132
@ SEGMENT_T
Definition: pns_item.h:66
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
int Net() const
Definition: pns_item.h:154

References PNS::ITEM::Kind(), PNS::ITEM::Layers(), PNS::ITEM::Net(), PNS::ITEM::SEGMENT_T, and PNS::ITEM::VIA_T.

Referenced by PNS_LOG_FILE::COMMIT_STATE::Compare().

◆ parseCommonPnsProps()

bool parseCommonPnsProps ( PNS::ITEM aItem,
const wxString &  cmd,
wxStringTokenizer &  aTokens 
)

Definition at line 102 of file pns_log_file.cpp.

103{
104 if( cmd == "net" )
105 {
106 aItem->SetNet( wxAtoi( aTokens.GetNextToken() ) );
107 return true;
108 } else if ( cmd == "layers" )
109 {
110 int start = wxAtoi( aTokens.GetNextToken() );
111 int end = wxAtoi( aTokens.GetNextToken() );
112 aItem->SetLayers( LAYER_RANGE( start, end ));
113 return true;
114 }
115 return false;
116
117}
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:157
void SetNet(int aNet)
Definition: pns_item.h:153

References PNS::ITEM::SetLayers(), and PNS::ITEM::SetNet().

Referenced by parsePnsSegmentFromString(), and parsePnsViaFromString().

◆ parseItemFromString()

static PNS::ITEM * parseItemFromString ( wxStringTokenizer &  aTokens)
static

Definition at line 176 of file pns_log_file.cpp.

177{
178 wxString type = aTokens.GetNextToken();
179
180 if( type == "segment" )
181 {
182 auto seg = new PNS::SEGMENT();
183 return parsePnsSegmentFromString( seg, aTokens );
184 }
185 else if( type == "via" )
186 {
187 auto seg = new PNS::VIA();
188 return parsePnsViaFromString( seg, aTokens );
189 }
190
191 return nullptr;
192}
static PNS::VIA * parsePnsViaFromString(PNS::VIA *aSeg, wxStringTokenizer &aTokens)
static PNS::SEGMENT * parsePnsSegmentFromString(PNS::SEGMENT *aSeg, wxStringTokenizer &aTokens)

References parsePnsSegmentFromString(), and parsePnsViaFromString().

Referenced by PNS_LOG_FILE::Load().

◆ parsePnsSegmentFromString()

static PNS::SEGMENT * parsePnsSegmentFromString ( PNS::SEGMENT aSeg,
wxStringTokenizer &  aTokens 
)
static

Definition at line 119 of file pns_log_file.cpp.

120{
121 PNS::SEGMENT* seg = new ( PNS::SEGMENT );
122
123 while( aTokens.CountTokens() )
124 {
125 wxString cmd = aTokens.GetNextToken();
126 if( !parseCommonPnsProps( seg, cmd, aTokens ) )
127 {
128 if ( cmd == "shape" )
129 {
130 auto sh = parseShape( SH_SEGMENT, aTokens );
131
132 if(!sh)
133 return nullptr;
134
135 seg->SetShape( *static_cast<SHAPE_SEGMENT*>(sh.get()) );
136
137 }
138 }
139 }
140
141 return seg;
142}
void SetShape(const SHAPE_SEGMENT &aShape)
Definition: pns_segment.h:122
static std::shared_ptr< SHAPE > parseShape(SHAPE_TYPE expectedType, wxStringTokenizer &aTokens)
bool parseCommonPnsProps(PNS::ITEM *aItem, const wxString &cmd, wxStringTokenizer &aTokens)
@ SH_SEGMENT
line segment
Definition: shape.h:46

References parseCommonPnsProps(), parseShape(), PNS::SEGMENT::SetShape(), and SH_SEGMENT.

Referenced by parseItemFromString().

◆ parsePnsViaFromString()

static PNS::VIA * parsePnsViaFromString ( PNS::VIA aSeg,
wxStringTokenizer &  aTokens 
)
static

Definition at line 144 of file pns_log_file.cpp.

145{
146 PNS::VIA* via = new ( PNS::VIA );
147
148 while( aTokens.CountTokens() )
149 {
150 wxString cmd = aTokens.GetNextToken();
151 if( !parseCommonPnsProps( via, cmd, aTokens ) )
152 {
153 if ( cmd == "shape" )
154 {
155 auto sh = parseShape( SH_CIRCLE, aTokens );
156
157 if(!sh)
158 return nullptr;
159
160 auto *sc = static_cast<SHAPE_CIRCLE*>( sh.get() );
161
162 via->SetPos( sc->GetCenter() );
163 via->SetDiameter( 2 * sc->GetRadius() );
164 }
165 else if ( cmd == "drill" )
166 {
167 via->SetDrill( wxAtoi( aTokens.GetNextToken() ) );
168 }
169 }
170 }
171
172 return via;
173}
@ SH_CIRCLE
circle
Definition: shape.h:48

References parseCommonPnsProps(), parseShape(), SH_CIRCLE, and via.

Referenced by parseItemFromString().

◆ parseShape()

static std::shared_ptr< SHAPE > parseShape ( SHAPE_TYPE  expectedType,
wxStringTokenizer &  aTokens 
)
static

Definition at line 69 of file pns_log_file.cpp.

70{
71 SHAPE_TYPE type = static_cast<SHAPE_TYPE> ( wxAtoi( aTokens.GetNextToken() ) );
72
73 if( type == SHAPE_TYPE::SH_SEGMENT )
74 {
75 std::shared_ptr<SHAPE_SEGMENT> sh( new SHAPE_SEGMENT );
76 VECTOR2I a,b;
77 a.x = wxAtoi( aTokens.GetNextToken() );
78 a.y = wxAtoi( aTokens.GetNextToken() );
79 b.x = wxAtoi( aTokens.GetNextToken() );
80 b.y = wxAtoi( aTokens.GetNextToken() );
81 int width = wxAtoi( aTokens.GetNextToken() );
82 sh->SetSeg( SEG( a, b ));
83 sh->SetWidth( width );
84 return sh;
85 }
86 else if ( type == SHAPE_TYPE::SH_CIRCLE )
87 {
88
89 std::shared_ptr<SHAPE_CIRCLE> sh( new SHAPE_CIRCLE );
90 VECTOR2I a;
91 a.x = wxAtoi( aTokens.GetNextToken() );
92 a.y = wxAtoi( aTokens.GetNextToken() );
93 int radius = wxAtoi( aTokens.GetNextToken() );
94 sh->SetCenter( a );
95 sh->SetRadius( radius );
96 return sh;
97 }
98
99 return nullptr;
100}
Definition: seg.h:42
SHAPE_TYPE
Lists all supported shapes.
Definition: shape.h:44

References SH_CIRCLE, SH_SEGMENT, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SCH_SEXPR_PARSER::parsePin(), parsePnsSegmentFromString(), and parsePnsViaFromString().

◆ readLine()

static const wxString readLine ( FILE *  f)
static

Definition at line 55 of file pns_log_file.cpp.

56{
57 char str[16384];
58 fgets( str, sizeof( str ) - 1, f );
59 return wxString( str );
60}

Referenced by PNS_LOG_FILE::Load().