KiCad PCB EDA Suite
pns_log.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020-2021 KiCad Developers.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 #ifndef __PNS_LOG_H
24 #define __PNS_LOG_H
25 
26 #include <cstdio>
27 
28 #include <wx/tokenzr.h>
29 
30 #include <geometry/shape.h>
31 #include <geometry/shape_circle.h>
32 #include <geometry/shape_file_io.h>
34 #include <geometry/shape_rect.h>
35 
37 #include <router/pns_item.h>
38 #include <router/pns_line.h>
39 #include <router/pns_line_placer.h>
40 #include <router/pns_dragger.h>
41 #include <router/pns_logger.h>
42 #include <router/pns_node.h>
43 #include <router/pns_router.h>
44 #include <router/pns_solid.h>
46 
47 #include <pcb_shape.h>
48 #include <pcb_text.h>
49 #include <pcbnew/zone.h>
50 
51 #include <router/pns_kicad_iface.h>
52 
53 #include <pcbnew/board.h>
54 
57 
58 #include <wx/treelist.h>
59 
61 {
62 public:
63  PNS_LOG_FILE();
65 
66  struct EVENT_ENTRY
67  {
70  const PNS::ITEM* item;
72  };
73 
74  // loads a board file and associated P&s event log
75  bool Load( const std::string& logName, const std::string boardName );
76 
78  {
79  BOARD_CONNECTED_ITEM* parent = nullptr;
80 
81  for( auto item : m_board->AllConnectedItems() )
82  {
83  if( item->m_Uuid == evt.uuid )
84  {
85  parent = item;
86  break;
87  };
88  }
89 
90  return parent;
91  }
92 
93  std::vector<EVENT_ENTRY>& Events() { return m_events; }
94 
95  std::shared_ptr<BOARD> GetBoard() const { return m_board; }
96 
97  void SetBoard( std::shared_ptr<BOARD> brd ) { m_board = brd; }
98 
100 
101 private:
102  std::unique_ptr<PNS::ROUTING_SETTINGS> m_routerSettings;
103  std::vector<EVENT_ENTRY> m_events;
104  std::shared_ptr<BOARD> m_board;
105 };
106 
107 
109 {
110 public:
111 
112  struct DEBUG_ENT
113  {
114  DEBUG_ENT( DEBUG_ENT* aParent = nullptr )
115  {
116  m_iter = 0;
118  m_width = 10000;
119  m_name = "<unknown>";
120  m_parent = aParent;
121  m_visible = true;
122  m_selected = false;
123  }
124 
126  {
127  for( auto s : m_shapes )
128  {
129  delete s;
130  }
131 
132  for( auto ch : m_children )
133  {
134  delete ch;
135  }
136  }
137 
139  {
140  DEBUG_ENT* ent = new DEBUG_ENT( this );
141  m_children.push_back( ent );
142 
143  return ent;
144  }
145 
146  void AddChild( DEBUG_ENT* ent )
147  {
148  ent->m_parent = this;
149  m_children.push_back( ent );
150  }
151 
152  bool IsVisible() const
153  {
154  if ( m_visible )
155  return true;
156 
157  auto parent = m_parent;
158 
159  while(parent)
160  {
161  if(parent->m_visible)
162  return true;
163 
164  parent = parent->m_parent;
165  }
166 
167  return false;
168  }
169 
170  void IterateTree( std::function<bool(DEBUG_ENT*)> visitor, int depth=0 );
171 
173  std::vector<SHAPE*> m_shapes;
174  std::vector<DEBUG_ENT*> m_children;
176  int m_width;
177  bool m_hasLabels = true;
178  int m_iter;
179  std::string m_name;
180  std::string m_msg;
182  bool m_visible;
184  };
185 
186  struct STAGE
187  {
189  {
190  m_name = "<unknown>";
191  m_iter = 0;
192  m_entries = new DEBUG_ENT();
193  }
194 
196  {
197  }
198 
199  std::string m_name;
200  int m_iter;
202  };
203 
205  {
206  m_iter = 0;
207  m_grouping = false;
208  m_activeEntry = nullptr;
209  SetDebugEnabled( true );
210  }
211 
213  {
214  // fixme: I know it's a hacky tool but it should clean after itself at some point...
215 
216  }
217 
218  virtual void SetIteration( int iter ) override { m_iter = iter; }
219 
220  virtual void Message( const wxString& msg,
221  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
222  virtual void NewStage( const std::string& name, int iter,
223  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
224  virtual void BeginGroup( const std::string& name,
225  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
226  virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
227  virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize,
228  const std::string& aName,
229  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
230  virtual void AddLine( const SHAPE_LINE_CHAIN& aLine, const KIGFX::COLOR4D& aColor,
231  int aWidth, const std::string& aName,
232  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
233  virtual void AddSegment( const SEG& aS, const KIGFX::COLOR4D& aColor,
234  const std::string& aName,
235  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
236  virtual void AddBox( const BOX2I& aB, const KIGFX::COLOR4D& aColor,
237  const std::string& aName,
238  const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override;
239  virtual void Clear(){};
240 
241  int GetStageCount() const { return m_stages.size(); }
242 
243  STAGE* GetStage( int index ) { return m_stages[index]; }
244 
245  BOX2I GetStageExtents( int stage ) const;
246 
247 private:
248  void addEntry( DEBUG_ENT* ent );
249 
252  STAGE* currentStage();
253  int m_iter;
254  std::vector<STAGE*> m_stages;
255 };
256 
257 
259 {
260 public:
263 
264  void SetMode( PNS::ROUTER_MODE mode );
265  void ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex = 0, int aFrom = 0, int aTo = -1 );
266 
268 
269 private:
270  void createRouter();
271 
274  std::shared_ptr<BOARD> m_board;
275  std::unique_ptr<PNS_KICAD_IFACE_BASE> m_iface;
276  std::unique_ptr<PNS::ROUTER> m_router;
277 };
278 
279 
280 #endif
bool Load(const std::string &logName, const std::string boardName)
Definition: pns_log.cpp:52
Base class for PNS router board items.
Definition: pns_item.h:55
Contain all persistent settings of the router, such as the mode, optimization effort,...
STAGE * GetStage(int index)
Definition: pns_log.h:243
DEBUG_ENT(DEBUG_ENT *aParent=nullptr)
Definition: pns_log.h:114
DEBUG_ENT * m_activeEntry
Definition: pns_log.h:251
std::unique_ptr< PNS::ROUTING_SETTINGS > m_routerSettings
Definition: pns_log.h:102
std::shared_ptr< BOARD > m_board
Definition: pns_log.h:274
void addEntry(DEBUG_ENT *ent)
Definition: pns_log.cpp:321
std::vector< SHAPE * > m_shapes
Definition: pns_log.h:173
void SetBoard(std::shared_ptr< BOARD > brd)
Definition: pns_log.h:97
std::vector< EVENT_ENTRY > & Events()
Definition: pns_log.h:93
KIID uuid
Definition: pns_log.h:71
PNS::ROUTER_MODE m_mode
Definition: pns_log.h:272
PNS_TEST_DEBUG_DECORATOR * GetDebugDecorator()
Definition: pns_log.h:267
std::vector< STAGE * > m_stages
Definition: pns_log.h:254
std::shared_ptr< BOARD > GetBoard() const
Definition: pns_log.h:95
BOARD_CONNECTED_ITEM * ItemById(const EVENT_ENTRY &evt)
Definition: pns_log.h:77
PNS::ROUTING_SETTINGS * GetRoutingSettings() const
Definition: pns_log.h:99
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
void SetDebugEnabled(bool aEnabled)
~PNS_LOG_FILE()
Definition: pns_log.h:64
std::vector< EVENT_ENTRY > m_events
Definition: pns_log.h:103
virtual void NewStage(const std::string &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:427
std::unique_ptr< PNS_KICAD_IFACE_BASE > m_iface
Definition: pns_log.h:275
int GetStageCount() const
Definition: pns_log.h:241
Definition: kiid.h:44
Definition: pns_log.h:66
void AddChild(DEBUG_ENT *ent)
Definition: pns_log.h:146
std::shared_ptr< BOARD > m_board
Definition: pns_log.h:104
void SetMode(PNS::ROUTER_MODE mode)
Definition: pns_log.cpp:127
virtual void Clear()
Definition: pns_log.h:239
PNS::LOGGER::EVENT_TYPE type
Definition: pns_log.h:69
static const COLOR4D WHITE
Definition: color4d.h:386
virtual void AddBox(const BOX2I &aB, const KIGFX::COLOR4D &aColor, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:402
virtual ~PNS_TEST_DEBUG_DECORATOR()
Definition: pns_log.h:212
BOX2I GetStageExtents(int stage) const
Definition: pns_log.cpp:453
std::vector< DEBUG_ENT * > m_children
Definition: pns_log.h:174
std::unique_ptr< PNS::ROUTER > m_router
Definition: pns_log.h:276
virtual void AddSegment(const SEG &aS, const KIGFX::COLOR4D &aColor, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:384
Definition: seg.h:40
PNS_TEST_DEBUG_DECORATOR m_debugDecorator
Definition: pns_log.h:273
void IterateTree(std::function< bool(DEBUG_ENT *)> visitor, int depth=0)
Definition: pns_log.cpp:439
ROUTER_MODE
Definition: pns_router.h:62
PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO m_srcLoc
Definition: pns_log.h:181
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:418
virtual void AddPoint(const VECTOR2I &aP, const KIGFX::COLOR4D &aColor, int aSize, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:340
const char * name
Definition: DXF_plotter.cpp:56
virtual void BeginGroup(const std::string &name, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:287
Represent a polyline (an zero-thickness chain of connected line segments).
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:308
virtual void SetIteration(int iter) override
Definition: pns_log.h:218
VECTOR2I p
Definition: pns_log.h:68
Pcbnew s-expression file format parser definition.
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, const KIGFX::COLOR4D &aColor, int aWidth, const std::string &aName, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
Definition: pns_log.cpp:366
const PNS::ITEM * item
Definition: pns_log.h:70
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1)
Definition: pns_log.cpp:152
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103