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 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  struct DEBUG_ENT
112  {
113  DEBUG_ENT( DEBUG_ENT* aParent = nullptr )
114  {
115  m_iter = 0;
116  m_color = 0;
117  m_width = 10000;
118  m_name = "<unknown>";
119  m_parent = aParent;
120  m_visible = true;
121  m_selected = false;
122  }
123 
125  {
126  for( auto s : m_shapes )
127  {
128  delete s;
129  }
130 
131  for( auto ch : m_children )
132  {
133  delete ch;
134  }
135  }
136 
138  {
139  DEBUG_ENT* ent = new DEBUG_ENT( this );
140  m_children.push_back( ent );
141 
142  return ent;
143  }
144 
145  void AddChild( DEBUG_ENT* ent )
146  {
147  ent->m_parent = this;
148  m_children.push_back( ent );
149  }
150 
151  bool IsVisible() const
152  {
153  if ( m_visible )
154  return true;
155 
156  auto parent = m_parent;
157 
158  while(parent)
159  {
160  if(parent->m_visible)
161  return true;
162 
163  parent = parent->m_parent;
164  }
165 
166  return false;
167  }
168 
169  void IterateTree( std::function<bool(DEBUG_ENT*)> visitor, int depth=0 );
170 
172  std::vector<SHAPE*> m_shapes;
173  std::vector<DEBUG_ENT*> m_children;
174  int m_color;
175  int m_width;
176  int m_iter;
177  std::string m_name;
178  std::string m_msg;
179  //wxTreeListItem m_item;
180  bool m_visible;
182  };
183 
184  struct STAGE
185  {
187  {
188  m_name = "<unknown>";
189  m_iter = 0;
190  m_entries = new DEBUG_ENT();
191  }
192 
194  {
195  }
196 
197  std::string m_name;
198  int m_iter;
200  };
201 
203  {
204  m_iter = 0;
205  m_grouping = false;
206  m_activeEntry = nullptr;
207  }
208 
210 
211  virtual void SetIteration( int iter ) override { m_iter = iter; }
212 
213  virtual void Message( const wxString msg ) override;
214  virtual void AddPoint( VECTOR2I aP, int aColor, int aSize = 100000,
215  const std::string aName = "" ) override;
216  virtual void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType = 0, int aWidth = 0,
217  const std::string aName = "" ) override;
218  virtual void AddSegment( SEG aS, int aColor, const std::string aName = "" ) override;
219  virtual void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) override;
220  virtual void AddDirections( VECTOR2D aP, int aMask, int aColor,
221  const std::string aName = "" ) override;
222  virtual void Clear() override;
223  virtual void NewStage( const std::string& name, int iter ) override;
224 
225  virtual void BeginGroup( const std::string name ) override;
226  virtual void EndGroup() override;
227 
228  int GetStageCount() const { return m_stages.size(); }
229 
230  STAGE* GetStage( int index ) { return m_stages[index]; }
231 
232  BOX2I GetStageExtents( int stage ) const;
233 
234 private:
235  void addEntry( DEBUG_ENT* ent );
236 
239  STAGE* currentStage();
240  int m_iter;
241  std::vector<STAGE*> m_stages;
242 };
243 
244 
246 {
247 public:
250 
251  void SetMode( PNS::ROUTER_MODE mode );
252  void ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex = 0, int aFrom = 0, int aTo = -1 );
253 
255 
256 private:
257  void createRouter();
258 
261  std::shared_ptr<BOARD> m_board;
262  std::unique_ptr<PNS_KICAD_IFACE_BASE> m_iface;
263  std::unique_ptr<PNS::ROUTER> m_router;
264 };
265 
266 
267 #endif
bool Load(const std::string &logName, const std::string boardName)
Definition: pns_log.cpp:45
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:230
DEBUG_ENT(DEBUG_ENT *aParent=nullptr)
Definition: pns_log.h:113
virtual void BeginGroup(const std::string name) override
Definition: pns_log.cpp:252
DEBUG_ENT * m_activeEntry
Definition: pns_log.h:238
std::unique_ptr< PNS::ROUTING_SETTINGS > m_routerSettings
Definition: pns_log.h:102
std::shared_ptr< BOARD > m_board
Definition: pns_log.h:261
virtual void AddBox(BOX2I aB, int aColor, const std::string aName="") override
Definition: pns_log.cpp:342
void addEntry(DEBUG_ENT *ent)
Definition: pns_log.cpp:285
std::vector< SHAPE * > m_shapes
Definition: pns_log.h:172
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:259
PNS_TEST_DEBUG_DECORATOR * GetDebugDecorator()
Definition: pns_log.h:254
std::vector< STAGE * > m_stages
Definition: pns_log.h:241
virtual void AddPoint(VECTOR2I aP, int aColor, int aSize=100000, const std::string aName="") override
Definition: pns_log.cpp:291
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,...
~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) override
Definition: pns_log.cpp:373
std::unique_ptr< PNS_KICAD_IFACE_BASE > m_iface
Definition: pns_log.h:262
int GetStageCount() const
Definition: pns_log.h:228
Definition: kiid.h:44
virtual void EndGroup() override
Definition: pns_log.cpp:272
Definition: pns_log.h:66
void AddChild(DEBUG_ENT *ent)
Definition: pns_log.h:145
std::shared_ptr< BOARD > m_board
Definition: pns_log.h:104
void SetMode(PNS::ROUTER_MODE mode)
Definition: pns_log.cpp:116
virtual void AddDirections(VECTOR2D aP, int aMask, int aColor, const std::string aName="") override
Definition: pns_log.cpp:356
virtual void Clear() override
Definition: pns_log.cpp:368
PNS::LOGGER::EVENT_TYPE type
Definition: pns_log.h:69
virtual void Message(const wxString msg) override
Definition: pns_log.cpp:361
virtual ~PNS_TEST_DEBUG_DECORATOR()
Definition: pns_log.h:209
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType=0, int aWidth=0, const std::string aName="") override
Definition: pns_log.cpp:313
BOX2I GetStageExtents(int stage) const
Definition: pns_log.cpp:393
std::vector< DEBUG_ENT * > m_children
Definition: pns_log.h:173
std::unique_ptr< PNS::ROUTER > m_router
Definition: pns_log.h:263
Definition: seg.h:41
PNS_TEST_DEBUG_DECORATOR m_debugDecorator
Definition: pns_log.h:260
void IterateTree(std::function< bool(DEBUG_ENT *)> visitor, int depth=0)
Definition: pns_log.cpp:380
ROUTER_MODE
Definition: pns_router.h:62
const char * name
Definition: DXF_plotter.cpp:59
SHAPE_LINE_CHAIN.
virtual void SetIteration(int iter) override
Definition: pns_log.h:211
VECTOR2I p
Definition: pns_log.h:68
Pcbnew s-expression file format parser definition.
virtual void AddSegment(SEG aS, int aColor, const std::string aName="") override
Definition: pns_log.cpp:328
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:139