KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_log_viewer_frame.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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
22// (unless you want to improve it).
23
24#ifndef __PNS_LOG_VIEWER_FRAME_H
25#define __PNS_LOG_VIEWER_FRAME_H
26
28#include <pad.h>
29#include <pcb_painter.h>
30#include <pcb_track.h>
31#include <pcb_test_frame.h>
33#include <reporter.h>
34#include <router/pns_solid.h>
35
36#include "pns_log_file.h"
37#include "pns_log_player.h"
40
41#include "label_manager.h"
42
43#define ID_LIST_COPY 10001
44#define ID_LIST_SHOW_ALL 10002
45#define ID_LIST_SHOW_NONE 10003
46#define ID_LIST_DISPLAY_LINE 10004
47
49
51{
52public:
53 PNS_VIEWER_IFACE( std::shared_ptr<BOARD> aBoard ){ m_board = aBoard; };
54 ~PNS_VIEWER_IFACE() override{};
55
56 void EraseView() override {};
57 void SyncWorld( PNS::NODE* aWorld ) override {};
58 bool IsAnyLayerVisible( const PNS_LAYER_RANGE& aLayer ) const override { return true; };
59 bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const override { return false; };
60 bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const override { return false; };
61 bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; };
62 bool IsPNSCopperLayer( int aLayer ) const override { return false; };
63 void HideItem( PNS::ITEM* aItem ) override {}
64 void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
65 int aFlags = 0 ) override {}
66 void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) override {}
67 void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, PNS::NET_HANDLE aNet ) override {}
68 void AddItem( PNS::ITEM* aItem ) override {}
69 void UpdateItem( PNS::ITEM* aItem ) override {}
70 void RemoveItem( PNS::ITEM* aItem ) override {}
71 void Commit() override {}
72 bool ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem,
73 PNS::NET_HANDLE aNet, VECTOR2D aStartPosition ) override { return false; }
74 int StackupHeight( int aFirstLayer, int aSecondLayer ) const override { return 0; }
75
76 int GetNetCode( PNS::NET_HANDLE aNet ) const override { return -1; }
77 wxString GetNetName( PNS::NET_HANDLE aNet ) const override { return wxEmptyString; }
78 void UpdateNet( PNS::NET_HANDLE aNet ) override {}
79 PNS::NET_HANDLE GetOrphanedNetHandle() override { return nullptr; }
80
81 virtual PNS::NODE* GetWorld() const override { return nullptr; };
82 PNS::RULE_RESOLVER* GetRuleResolver() override { return nullptr; }
83 PNS::DEBUG_DECORATOR* GetDebugDecorator() override { return nullptr; }
84
85 PCB_LAYER_ID GetBoardLayerFromPNSLayer( int aLayer ) const override
86 {
87 if( aLayer == 0 )
88 return F_Cu;
89
90 if( aLayer == m_board->GetCopperLayerCount() - 1 )
91 return B_Cu;
92
93 return ToLAYER_ID( ( aLayer + 1 ) * 2 );
94 }
95
96
97 int GetPNSLayerFromBoardLayer( PCB_LAYER_ID aLayer ) const override
98 {
99 if( aLayer == F_Cu )
100 return 0;
101
102 if( aLayer == B_Cu )
103 return m_board->GetCopperLayerCount() - 1;
104
105 return ( aLayer / 2 ) - 1;
106 }
107
109 long long& aExtraLength, long long& aExtraDelay ) const override
110 {
111 aExtraLength = 0;
112 aExtraDelay = 0;
113 return false; // Not needed for log viewer
114 }
115
116 long long int CalculateRoutedPathLength( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
117 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
118 {
119 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = GetLengthDelayCalculationItems( aLine, aNetClass );
120
121 const PAD* startPad = nullptr;
122 const PAD* endPad = nullptr;
123
124 if( aStartPad )
125 startPad = static_cast<PAD*>( aStartPad->Parent() );
126
127 if( aEndPad )
128 endPad = static_cast<PAD*>( aEndPad->Parent() );
129
130 constexpr PATH_OPTIMISATIONS opts = {
131 .OptimiseVias = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
132 };
133
134 return m_board->GetLengthCalculation()->CalculateLength( lengthItems, opts, startPad, endPad );
135 }
136
137 int64_t CalculateRoutedPathDelay( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
138 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
139 {
140 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = GetLengthDelayCalculationItems( aLine, aNetClass );
141
142 const PAD* startPad = nullptr;
143 const PAD* endPad = nullptr;
144
145 if( aStartPad )
146 startPad = static_cast<PAD*>( aStartPad->Parent() );
147
148 if( aEndPad )
149 endPad = static_cast<PAD*>( aEndPad->Parent() );
150
151 constexpr PATH_OPTIMISATIONS opts = {
152 .OptimiseVias = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
153 };
154
155 return m_board->GetLengthCalculation()->CalculateDelay( lengthItems, opts, startPad, endPad );
156 }
157
158 std::vector<LENGTH_DELAY_CALCULATION_ITEM> GetLengthDelayCalculationItems( const PNS::ITEM_SET& aLine,
159 const NETCLASS* aNetClass ) const
160 {
161 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
162
163 for( int idx = 0; idx < aLine.Size(); idx++ )
164 {
165 const PNS::ITEM* lineItem = aLine[idx];
166
167 if( const PNS::LINE* l = dyn_cast<const PNS::LINE*>( lineItem ) )
168 {
170 item.SetLine( l->CLine() );
171
172 const PCB_LAYER_ID layer = GetBoardLayerFromPNSLayer( lineItem->Layer() );
173 item.SetLayers( layer );
174 item.SetEffectiveNetClass( aNetClass );
175
176 lengthItems.emplace_back( std::move( item ) );
177 }
178 else if( lineItem->OfKind( PNS::ITEM::VIA_T ) && idx > 0 && idx < aLine.Size() - 1 )
179 {
180 const int layerPrev = aLine[idx - 1]->Layer();
181 const int layerNext = aLine[idx + 1]->Layer();
182 const PCB_LAYER_ID pcbLayerPrev = GetBoardLayerFromPNSLayer( layerPrev );
183 const PCB_LAYER_ID pcbLayerNext = GetBoardLayerFromPNSLayer( layerNext );
184
185 if( layerPrev != layerNext )
186 {
188 item.SetVia( static_cast<PCB_VIA*>( lineItem->GetSourceItem() ) );
189 item.SetLayers( pcbLayerPrev, pcbLayerNext );
190 item.SetEffectiveNetClass( aNetClass );
191 lengthItems.emplace_back( std::move( item ) );
192 }
193 }
194 }
195
196 return lengthItems;
197 }
198
199 int64_t CalculateLengthForDelay( int64_t aDesiredDelay, const int aWidth, const bool aIsDiffPairCoupled,
200 const int aDiffPairCouplingGap, const int aPNSLayer,
201 const NETCLASS* aNetClass ) override
202 {
204 ctx.NetClass = aNetClass;
205 ctx.Width = aWidth;
206 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
207 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
208 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
209
210 return m_board->GetLengthCalculation()->CalculateLengthForDelay( aDesiredDelay, ctx );
211 }
212
213 int64_t CalculateDelayForShapeLineChain( const SHAPE_LINE_CHAIN& aShape, int aWidth, bool aIsDiffPairCoupled,
214 int aDiffPairCouplingGap, int aPNSLayer,
215 const NETCLASS* aNetClass ) override
216 {
218 ctx.NetClass = aNetClass;
219 ctx.Width = aWidth;
220 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
221 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
222 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
223
224 return m_board->GetLengthCalculation()->CalculatePropagationDelayForShapeLineChain( aShape, ctx );
225 }
226
227 private:
228 std::shared_ptr<BOARD> m_board;
229};
230
232{
233public:
234 PNS_LOG_VIEWER_FRAME( wxFrame* frame );
235 virtual ~PNS_LOG_VIEWER_FRAME();
236
237 void LoadLogFile( const wxString& aFile );
238 void SetLogFile( PNS_LOG_FILE* aLog );
239 void SetBoard2( std::shared_ptr<BOARD> aBoard );
241
242 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> GetOverlay() const { return m_overlay; }
243
244private:
245 void drawLoggedItems( int iter );
246 void updateDumpPanel( int iter );
247 virtual void createUserTools() override;
248 void buildListTree( wxTreeListItem item, PNS_DEBUG_SHAPE* ent, int depth = 0 );
249 void syncModel();
251 void updatePnsPreviewItems( int iter );
253 void updateViewerIface();
254
255 virtual void onOpen( wxCommandEvent& event ) override;
256 virtual void onSaveAs( wxCommandEvent& event ) override;
257 virtual void onExit( wxCommandEvent& event ) override;
258 virtual void onRewindScroll( wxScrollEvent& event ) override;
259 virtual void onRewindCountText( wxCommandEvent& event ) override;
260 virtual void onListRightClick( wxMouseEvent& event );
261 virtual void onListSelect( wxCommandEvent& event );
262 virtual void onBtnRewindLeft( wxCommandEvent& event ) override;
263 virtual void onBtnRewindRight( wxCommandEvent& event ) override;
264 virtual void onListChecked( wxCommandEvent& event );
265 virtual void onShowThinLinesChecked( wxCommandEvent& event ) override;
266 virtual void onShowRPIsChecked( wxCommandEvent& event ) override;
267 virtual void onShowVerticesChecked( wxCommandEvent& event ) override;
268 virtual void onFilterText( wxCommandEvent& event ) override;
269 void drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName );
270
271 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> m_overlay;
272 std::shared_ptr<PNS_LOG_FILE> m_logFile;
273 std::shared_ptr<PNS_LOG_PLAYER> m_logPlayer;
276 std::shared_ptr<KIGFX::VIEW_GROUP> m_previewItems;
277 std::shared_ptr<PNS_VIEWER_IFACE> m_viewerIface;
278 std::map<wxString,wxString> m_filenameToPathMap;
279
280 bool m_showThinLines = true;
281 bool m_showRPIs = true;
282 bool m_showVertices = false;
284 //KI_TEST::CONSOLE_LOG m_consoleLog;
285 std::shared_ptr<WX_TEXT_CTRL_REPORTER> m_reporter;
286};
287
288class LABEL_MANAGER;
289
291{
292public:
294 void AnnotatedPolyset( const SHAPE_POLY_SET& aL, std::string name = "",
295 bool aShowVertexNumbers = false );
296 void AnnotatedPolyline( const SHAPE_LINE_CHAIN& aL, std::string name,
297 bool aShowVertexNumbers = false );
298 void AnnotatedPoint( const VECTOR2I p, int size, std::string name = "",
299 bool aShowVertexNumbers = false );
300 void Arc( const SHAPE_ARC& arc );
301 void DrawAnnotations();
302
303private:
304
305
306 std::unique_ptr<LABEL_MANAGER> m_labelMgr;
307};
308
309#endif
const char * name
Abstract interface for drawing on a 2D-surface.
Lightweight class which holds a pad, via, or a routed trace outline.
void SetLine(const SHAPE_LINE_CHAIN &aLine)
Sets the source SHAPE_LINE_CHAIN of this item.
void SetVia(const PCB_VIA *aVia)
Sets the VIA associated with this item.
void SetEffectiveNetClass(const NETCLASS *aNetClass)
Sets the effective net class for the item.
void SetLayers(const PCB_LAYER_ID aStart, const PCB_LAYER_ID aEnd=PCB_LAYER_ID::UNDEFINED_LAYER)
Sets the first and last layers associated with this item.
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:38
Definition pad.h:61
int Size() const
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * Parent() const
Definition pns_item.h:199
BOARD_ITEM * GetSourceItem() const
Definition pns_item.h:202
virtual int Layer() const
Definition pns_item.h:216
bool OfKind(int aKindMask) const
Definition pns_item.h:181
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
Keep the router "world" - i.e.
Definition pns_node.h:242
Represent a contiguous set of PCB layers.
PNS_LOG_VIEWER_FRAME_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=wxT("P&S Log Viewer"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1045, 574), long style=wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL)
std::shared_ptr< WX_TEXT_CTRL_REPORTER > m_reporter
std::shared_ptr< PNS_LOG_FILE > m_logFile
virtual void onListRightClick(wxMouseEvent &event)
std::shared_ptr< PNS_LOG_PLAYER > m_logPlayer
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > GetOverlay() const
std::map< wxString, wxString > m_filenameToPathMap
void drawSimpleShape(SHAPE *aShape, bool aIsSelected, const std::string &aName)
virtual void onRewindCountText(wxCommandEvent &event) override
std::shared_ptr< KIGFX::VIEW_GROUP > m_previewItems
PNS_DEBUG_STAGE * getCurrentStage()
bool filterStringMatches(PNS_DEBUG_SHAPE *ent)
void SetBoard2(std::shared_ptr< BOARD > aBoard)
virtual void createUserTools() override
void buildListTree(wxTreeListItem item, PNS_DEBUG_SHAPE *ent, int depth=0)
virtual void onShowVerticesChecked(wxCommandEvent &event) override
void SetLogFile(PNS_LOG_FILE *aLog)
virtual void onShowThinLinesChecked(wxCommandEvent &event) override
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > m_overlay
void LoadLogFile(const wxString &aFile)
virtual void onListChecked(wxCommandEvent &event)
std::shared_ptr< PNS_VIEWER_IFACE > m_viewerIface
virtual void onListSelect(wxCommandEvent &event)
virtual void onSaveAs(wxCommandEvent &event) override
virtual void onRewindScroll(wxScrollEvent &event) override
virtual void onShowRPIsChecked(wxCommandEvent &event) override
virtual void onBtnRewindRight(wxCommandEvent &event) override
virtual void onFilterText(wxCommandEvent &event) override
PNS_LOG_VIEWER_FRAME(wxFrame *frame)
virtual void onOpen(wxCommandEvent &event) override
virtual void onBtnRewindLeft(wxCommandEvent &event) override
virtual void onExit(wxCommandEvent &event) override
void AnnotatedPoint(const VECTOR2I p, int size, std::string name="", bool aShowVertexNumbers=false)
void AnnotatedPolyset(const SHAPE_POLY_SET &aL, std::string name="", bool aShowVertexNumbers=false)
void AnnotatedPolyline(const SHAPE_LINE_CHAIN &aL, std::string name, bool aShowVertexNumbers=false)
PNS_LOG_VIEWER_OVERLAY(KIGFX::GAL *aGal)
std::unique_ptr< LABEL_MANAGER > m_labelMgr
void Arc(const SHAPE_ARC &arc)
int StackupHeight(int aFirstLayer, int aSecondLayer) const override
int64_t CalculateRoutedPathDelay(const PNS::ITEM_SET &aLine, const PNS::SOLID *aStartPad, const PNS::SOLID *aEndPad, const NETCLASS *aNetClass) override
void RemoveItem(PNS::ITEM *aItem) override
int64_t CalculateLengthForDelay(int64_t aDesiredDelay, const int aWidth, const bool aIsDiffPairCoupled, const int aDiffPairCouplingGap, const int aPNSLayer, const NETCLASS *aNetClass) override
void AddItem(PNS::ITEM *aItem) override
int GetPNSLayerFromBoardLayer(PCB_LAYER_ID aLayer) const override
PNS::DEBUG_DECORATOR * GetDebugDecorator() override
bool IsFlashedOnLayer(const PNS::ITEM *aItem, int aLayer) const override
int GetNetCode(PNS::NET_HANDLE aNet) const override
PNS_VIEWER_IFACE(std::shared_ptr< BOARD > aBoard)
void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance) override
PCB_LAYER_ID GetBoardLayerFromPNSLayer(int aLayer) const override
void SyncWorld(PNS::NODE *aWorld) override
bool IsPNSCopperLayer(int aLayer) const override
bool IsAnyLayerVisible(const PNS_LAYER_RANGE &aLayer) const override
void UpdateItem(PNS::ITEM *aItem) override
bool IsFlashedOnLayer(const PNS::ITEM *aItem, const PNS_LAYER_RANGE &aLayer) const override
long long int CalculateRoutedPathLength(const PNS::ITEM_SET &aLine, const PNS::SOLID *aStartPad, const PNS::SOLID *aEndPad, const NETCLASS *aNetClass) override
void Commit() override
void UpdateNet(PNS::NET_HANDLE aNet) override
std::vector< LENGTH_DELAY_CALCULATION_ITEM > GetLengthDelayCalculationItems(const PNS::ITEM_SET &aLine, const NETCLASS *aNetClass) const
bool ImportSizes(PNS::SIZES_SETTINGS &aSizes, PNS::ITEM *aStartItem, PNS::NET_HANDLE aNet, VECTOR2D aStartPosition) override
int64_t CalculateDelayForShapeLineChain(const SHAPE_LINE_CHAIN &aShape, int aWidth, bool aIsDiffPairCoupled, int aDiffPairCouplingGap, int aPNSLayer, const NETCLASS *aNetClass) override
wxString GetNetName(PNS::NET_HANDLE aNet) const override
PNS::NET_HANDLE GetOrphanedNetHandle() override
bool GetSignalAggregate(PNS::NET_HANDLE, PNS::NET_HANDLE, long long &aExtraLength, long long &aExtraDelay) const override
void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, PNS::NET_HANDLE aNet) override
bool IsItemVisible(const PNS::ITEM *aItem) const override
virtual PNS::NODE * GetWorld() const override
PNS::RULE_RESOLVER * GetRuleResolver() override
std::shared_ptr< BOARD > m_board
void HideItem(PNS::ITEM *aItem) override
void EraseView() override
void DisplayItem(const PNS::ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0) override
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
An abstract shape on 2D plane.
Definition shape.h:124
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
void * NET_HANDLE
Definition pns_item.h:55
Struct to control which optimisations the length calculation code runs on the given path objects.
A data structure to contain basic geometry data which can affect signal propagation calculations.
int64_t DiffPairCouplingGap
The gap between coupled tracks.
const NETCLASS * NetClass
The net class this track belongs to.
int64_t Width
The width (in internal units) of the track.
bool IsDiffPairCoupled
Whether this track or via is a member of a coupled differential pair.
PCB_LAYER_ID Layer
The layer this track is on.
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:56
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682