KiCad PCB EDA Suite
pns_logger.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 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_logger.h"
23 #include "pns_item.h"
24 #include "pns_via.h"
25 #include "pns_line.h"
26 #include "pns_segment.h"
27 #include "pns_solid.h"
28 
29 #include <geometry/shape.h>
31 #include <geometry/shape_rect.h>
32 #include <geometry/shape_circle.h>
33 #include <geometry/shape_convex.h>
34 
35 namespace PNS {
36 
38 {
39  m_groupOpened = false;
40 }
41 
42 
44 {
45 }
46 
47 
49 {
50  m_theLog.str( std::string() );
51  m_groupOpened = false;
52 }
53 
54 
55 void LOGGER::NewGroup( const std::string& aName, int aIter )
56 {
57  if( m_groupOpened )
58  m_theLog << "endgroup" << std::endl;
59 
60  m_theLog << "group " << aName << " " << aIter << std::endl;
61  m_groupOpened = true;
62 }
63 
64 
66 {
67  if( !m_groupOpened )
68  return;
69 
70  m_groupOpened = false;
71  m_theLog << "endgroup" << std::endl;
72 }
73 
74 
75 void LOGGER::Log ( const ITEM* aItem, int aKind, const std::string aName )
76 {
77  m_theLog << "item " << aKind << " " << aName << " ";
78  m_theLog << aItem->Net() << " " << aItem->Layers().Start() << " " <<
79  aItem->Layers().End() << " " << aItem->Marker() << " " << aItem->Rank();
80 
81  switch( aItem->Kind() )
82  {
83  case ITEM::LINE_T:
84  {
85  LINE* l = (LINE*) aItem;
86  m_theLog << " line ";
87  m_theLog << l->Width() << " " << ( l->EndsWithVia() ? 1 : 0 ) << " ";
88  dumpShape ( l->Shape() );
89  m_theLog << std::endl;
90  break;
91  }
92 
93  case ITEM::VIA_T:
94  {
95  m_theLog << " via 0 0 ";
96  dumpShape ( aItem->Shape() );
97  m_theLog << std::endl;
98  break;
99  }
100 
101  case ITEM::SEGMENT_T:
102  {
103  SEGMENT* s =(SEGMENT*) aItem;
104  m_theLog << " line ";
105  m_theLog << s->Width() << " 0 linechain 2 0 " << s->Seg().A.x << " " <<
106  s->Seg().A.y << " " << s->Seg().B.x << " " <<s->Seg().B.y << std::endl;
107  break;
108  }
109 
110  case ITEM::SOLID_T:
111  {
112  SOLID* s = (SOLID*) aItem;
113  m_theLog << " solid 0 0 ";
114  dumpShape( s->Shape() );
115  m_theLog << std::endl;
116  break;
117  }
118 
119  default:
120  break;
121  }
122 }
123 
124 
125 void LOGGER::Log( const SHAPE_LINE_CHAIN *aL, int aKind, const std::string aName )
126 {
127  m_theLog << "item " << aKind << " " << aName << " ";
128  m_theLog << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0;
129  m_theLog << " line ";
130  m_theLog << 0 << " " << 0 << " ";
131  dumpShape( aL );
132  m_theLog << std::endl;
133 }
134 
135 
136 void LOGGER::Log( const VECTOR2I& aStart, const VECTOR2I& aEnd,
137  int aKind, const std::string aName)
138 {
139 }
140 
141 
142 void LOGGER::dumpShape( const SHAPE* aSh )
143 {
144  switch( aSh->Type() )
145  {
146  case SH_LINE_CHAIN:
147  {
148  const SHAPE_LINE_CHAIN* lc = (const SHAPE_LINE_CHAIN*) aSh;
149  m_theLog << "linechain " << lc->PointCount() << " " << ( lc->IsClosed() ? 1 : 0 ) << " ";
150 
151  for( int i = 0; i < lc->PointCount(); i++ )
152  m_theLog << lc->CPoint( i ).x << " " << lc->CPoint( i ).y << " ";
153 
154  break;
155  }
156 
157  case SH_CIRCLE:
158  {
159  const SHAPE_CIRCLE *c = (const SHAPE_CIRCLE*) aSh;
160  m_theLog << "circle " << c->GetCenter().x << " " << c->GetCenter().y << " " << c->GetRadius();
161  break;
162  }
163 
164  case SH_RECT:
165  {
166  const SHAPE_RECT* r = (const SHAPE_RECT*) aSh;
167  m_theLog << "rect " << r->GetPosition().x << " " << r->GetPosition().y << " " <<
168  r->GetSize().x << " " <<r->GetSize().y;
169  break;
170  }
171 
172  case SH_SEGMENT:
173  {
174  const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) aSh;
175  m_theLog << "linechain 2 0 " << s->GetSeg().A.x << " " << s->GetSeg().A.y << " " <<
176  s->GetSeg().B.x << " " << s->GetSeg().B.y;
177  break;
178  }
179 
180  case SH_CONVEX:
181  {
182  const SHAPE_CONVEX* c = (const SHAPE_CONVEX*) aSh;
183  m_theLog << "convex " << c->PointCount() << " ";
184 
185  for( int i = 0; i < c->PointCount(); i++ )
186  m_theLog << c->CPoint( i ).x << " " << c->CPoint( i ).y << " ";
187 
188  break;
189  }
190 
191  default:
192  break;
193  }
194 }
195 
196 
197 void LOGGER::Save( const std::string& aFilename )
198 {
199  EndGroup();
200 
201  FILE* f = fopen( aFilename.c_str(), "wb" );
202  wxLogTrace( "PNS", "Saving to '%s' [%p]", aFilename.c_str(), f );
203  const std::string s = m_theLog.str();
204  fwrite( s.c_str(), 1, s.length(), f );
205  fclose( f );
206 }
207 
208 }
void dumpShape(const SHAPE *aSh)
Definition: pns_logger.cpp:142
Class ITEM.
Definition: pns_item.h:53
const SHAPE * Shape() const override
Function Shape()
Definition: pns_solid.h:62
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:207
int PointCount() const
Function PointCount()
int GetRadius() const
Definition: shape_circle.h:79
bool m_groupOpened
Definition: pns_logger.h:59
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:296
Class SHAPE_CONVEX.
Definition: shape_convex.h:42
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
Definition: shape_convex.h:113
virtual int Marker() const
Definition: pns_item.h:311
int Width() const
Returns line width
Definition: pns_line.h:159
int End() const
Definition: pns_layerset.h:88
const SHAPE * Shape() const override
Returns the shape of the line
Definition: pns_line.h:111
void NewGroup(const std::string &aName, int aIter=0)
Definition: pns_logger.cpp:55
virtual int Rank() const
Definition: pns_item.h:321
int PointCount() const
Function PointCount()
Definition: shape_convex.h:85
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
bool EndsWithVia() const
Definition: pns_line.h:248
Class SHAPE.
Definition: shape.h:57
int Width() const
Definition: pns_segment.h:88
int Start() const
Definition: pns_layerset.h:83
void Clear()
Definition: pns_logger.cpp:48
line chain (polyline)
Definition: shape.h:46
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
void Save(const std::string &aFilename)
Definition: pns_logger.cpp:197
const SEG & GetSeg() const
Definition: shape_segment.h:70
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:82
Class SHAPE_LINE_CHAIN.
std::stringstream m_theLog
Definition: pns_logger.h:60
VECTOR2I A
Definition: seg.h:49
int Net() const
Function Net()
Definition: pns_item.h:177
line segment
Definition: shape.h:45
bool IsClosed() const
Function IsClosed()
const SEG & Seg() const
Definition: pns_segment.h:93
void Log(const ITEM *aItem, int aKind=0, const std::string aName=std::string())
Definition: pns_logger.cpp:75
Definition: shape.h:43
Push and Shove diff pair dimensions (gap) settings dialog.
circle
Definition: shape.h:47
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
void EndGroup()
Definition: pns_logger.cpp:65
axis-aligned rectangle
Definition: shape.h:44
VECTOR2I B
Definition: seg.h:50