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, 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
24
25// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
26// (unless you want to improve it).
27
28#ifndef __PNS_LOG_VIEWER_FRAME_H
29#define __PNS_LOG_VIEWER_FRAME_H
30
32#include <pcb_painter.h>
33#include <pcb_test_frame.h>
35#include <reporter.h>
36#include <router/pns_solid.h>
37
38#include "pns_log_file.h"
39#include "pns_log_player.h"
42
43#include "label_manager.h"
44
45#define ID_LIST_COPY 10001
46#define ID_LIST_SHOW_ALL 10002
47#define ID_LIST_SHOW_NONE 10003
48#define ID_LIST_DISPLAY_LINE 10004
49
51
53{
54public:
55 PNS_VIEWER_IFACE( std::shared_ptr<BOARD> aBoard ){ m_board = aBoard; };
56 ~PNS_VIEWER_IFACE() override{};
57
58 void EraseView() override {};
59 void SyncWorld( PNS::NODE* aWorld ) override {};
60 bool IsAnyLayerVisible( const PNS_LAYER_RANGE& aLayer ) const override { return true; };
61 bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const override { return false; };
62 bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const override { return false; };
63 bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; };
64 bool IsPNSCopperLayer( int aLayer ) const override { return false; };
65 void HideItem( PNS::ITEM* aItem ) override {}
66 void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
67 int aFlags = 0 ) override {}
68 void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) override {}
69 void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, PNS::NET_HANDLE aNet ) override {}
70 void AddItem( PNS::ITEM* aItem ) override {}
71 void UpdateItem( PNS::ITEM* aItem ) override {}
72 void RemoveItem( PNS::ITEM* aItem ) override {}
73 void Commit() override {}
74 bool ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem,
75 PNS::NET_HANDLE aNet, VECTOR2D aStartPosition ) override { return false; }
76 int StackupHeight( int aFirstLayer, int aSecondLayer ) const override { return 0; }
77
78 int GetNetCode( PNS::NET_HANDLE aNet ) const override { return -1; }
79 wxString GetNetName( PNS::NET_HANDLE aNet ) const override { return wxEmptyString; }
80 void UpdateNet( PNS::NET_HANDLE aNet ) override {}
81 PNS::NET_HANDLE GetOrphanedNetHandle() override { return nullptr; }
82
83 virtual PNS::NODE* GetWorld() const override { return nullptr; };
84 PNS::RULE_RESOLVER* GetRuleResolver() override { return nullptr; }
85 PNS::DEBUG_DECORATOR* GetDebugDecorator() override { return nullptr; }
86
87 PCB_LAYER_ID GetBoardLayerFromPNSLayer( int aLayer ) const override
88 {
89 if( aLayer == 0 )
90 return F_Cu;
91
92 if( aLayer == m_board->GetCopperLayerCount() - 1 )
93 return B_Cu;
94
95 return ToLAYER_ID( ( aLayer + 1 ) * 2 );
96 }
97
98
99 int GetPNSLayerFromBoardLayer( PCB_LAYER_ID aLayer ) const override
100 {
101 if( aLayer == F_Cu )
102 return 0;
103
104 if( aLayer == B_Cu )
105 return m_board->GetCopperLayerCount() - 1;
106
107 return ( aLayer / 2 ) - 1;
108 }
109
110 long long int CalculateRoutedPathLength( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
111 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
112 {
113 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = getLengthDelayCalculationItems( aLine, aNetClass );
114
115 const PAD* startPad = nullptr;
116 const PAD* endPad = nullptr;
117
118 if( aStartPad )
119 startPad = static_cast<PAD*>( aStartPad->Parent() );
120
121 if( aEndPad )
122 endPad = static_cast<PAD*>( aEndPad->Parent() );
123
124 constexpr PATH_OPTIMISATIONS opts = {
125 .OptimiseViaLayers = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
126 };
127
128 return m_board->GetLengthCalculation()->CalculateLength( lengthItems, opts, startPad, endPad );
129 }
130
131 int64_t CalculateRoutedPathDelay( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
132 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
133 {
134 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = getLengthDelayCalculationItems( aLine, aNetClass );
135
136 const PAD* startPad = nullptr;
137 const PAD* endPad = nullptr;
138
139 if( aStartPad )
140 startPad = static_cast<PAD*>( aStartPad->Parent() );
141
142 if( aEndPad )
143 endPad = static_cast<PAD*>( aEndPad->Parent() );
144
145 constexpr PATH_OPTIMISATIONS opts = {
146 .OptimiseViaLayers = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
147 };
148
149 return m_board->GetLengthCalculation()->CalculateDelay( lengthItems, opts, startPad, endPad );
150 }
151
152 std::vector<LENGTH_DELAY_CALCULATION_ITEM> getLengthDelayCalculationItems( const PNS::ITEM_SET& aLine,
153 const NETCLASS* aNetClass ) const
154 {
155 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
156
157 for( int idx = 0; idx < aLine.Size(); idx++ )
158 {
159 const PNS::ITEM* lineItem = aLine[idx];
160
161 if( const PNS::LINE* l = dyn_cast<const PNS::LINE*>( lineItem ) )
162 {
164 item.SetLine( l->CLine() );
165
166 const PCB_LAYER_ID layer = GetBoardLayerFromPNSLayer( lineItem->Layer() );
167 item.SetLayers( layer );
168 item.SetEffectiveNetClass( aNetClass );
169
170 lengthItems.emplace_back( std::move( item ) );
171 }
172 else if( lineItem->OfKind( PNS::ITEM::VIA_T ) && idx > 0 && idx < aLine.Size() - 1 )
173 {
174 const int layerPrev = aLine[idx - 1]->Layer();
175 const int layerNext = aLine[idx + 1]->Layer();
176 const PCB_LAYER_ID pcbLayerPrev = GetBoardLayerFromPNSLayer( layerPrev );
177 const PCB_LAYER_ID pcbLayerNext = GetBoardLayerFromPNSLayer( layerNext );
178
179 if( layerPrev != layerNext )
180 {
182 item.SetVia( static_cast<PCB_VIA*>( lineItem->GetSourceItem() ) );
183 item.SetLayers( pcbLayerPrev, pcbLayerNext );
184 item.SetEffectiveNetClass( aNetClass );
185 lengthItems.emplace_back( std::move( item ) );
186 }
187 }
188 }
189
190 return lengthItems;
191 }
192
193 int64_t CalculateLengthForDelay( int64_t aDesiredDelay, const int aWidth, const bool aIsDiffPairCoupled,
194 const int aDiffPairCouplingGap, const int aPNSLayer,
195 const NETCLASS* aNetClass ) override
196 {
198 ctx.NetClass = aNetClass;
199 ctx.Width = aWidth;
200 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
201 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
202 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
203
204 return m_board->GetLengthCalculation()->CalculateLengthForDelay( aDesiredDelay, ctx );
205 }
206
207 int64_t CalculateDelayForShapeLineChain( const SHAPE_LINE_CHAIN& aShape, int aWidth, bool aIsDiffPairCoupled,
208 int aDiffPairCouplingGap, int aPNSLayer,
209 const NETCLASS* aNetClass ) override
210 {
212 ctx.NetClass = aNetClass;
213 ctx.Width = aWidth;
214 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
215 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
216 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
217
218 return m_board->GetLengthCalculation()->CalculatePropagationDelayForShapeLineChain( aShape, ctx );
219 }
220
221 private:
222 std::shared_ptr<BOARD> m_board;
223};
224
226{
227public:
228 PNS_LOG_VIEWER_FRAME( wxFrame* frame );
229 virtual ~PNS_LOG_VIEWER_FRAME();
230
231 void LoadLogFile( const wxString& aFile );
232 void SetLogFile( PNS_LOG_FILE* aLog );
233 void SetBoard2( std::shared_ptr<BOARD> aBoard );
235
236 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> GetOverlay() const { return m_overlay; }
237
238private:
239 void drawLoggedItems( int iter );
240 void updateDumpPanel( int iter );
241 virtual void createUserTools() override;
242 void buildListTree( wxTreeListItem item, PNS_DEBUG_SHAPE* ent, int depth = 0 );
243 void syncModel();
245 void updatePnsPreviewItems( int iter );
247 void updateViewerIface();
248
249 virtual void onOpen( wxCommandEvent& event ) override;
250 virtual void onSaveAs( wxCommandEvent& event ) override;
251 virtual void onExit( wxCommandEvent& event ) override;
252 virtual void onRewindScroll( wxScrollEvent& event ) override;
253 virtual void onRewindCountText( wxCommandEvent& event ) override;
254 virtual void onListRightClick( wxMouseEvent& event );
255 virtual void onListSelect( wxCommandEvent& event );
256 virtual void onBtnRewindLeft( wxCommandEvent& event ) override;
257 virtual void onBtnRewindRight( wxCommandEvent& event ) override;
258 virtual void onListChecked( wxCommandEvent& event );
259 virtual void onShowThinLinesChecked( wxCommandEvent& event ) override;
260 virtual void onShowRPIsChecked( wxCommandEvent& event ) override;
261 virtual void onShowVerticesChecked( wxCommandEvent& event ) override;
262 virtual void onFilterText( wxCommandEvent& event ) override;
263 void drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName );
264
265 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> m_overlay;
266 std::shared_ptr<PNS_LOG_FILE> m_logFile;
267 std::shared_ptr<PNS_LOG_PLAYER> m_logPlayer;
270 std::shared_ptr<KIGFX::VIEW_GROUP> m_previewItems;
271 std::shared_ptr<PNS_VIEWER_IFACE> m_viewerIface;
272 std::map<wxString,wxString> m_filenameToPathMap;
273
274 bool m_showThinLines = true;
275 bool m_showRPIs = true;
276 bool m_showVertices = false;
278 //KI_TEST::CONSOLE_LOG m_consoleLog;
279 std::shared_ptr<WX_TEXT_CTRL_REPORTER> m_reporter;
280};
281
282class LABEL_MANAGER;
283
285{
286public:
288 void AnnotatedPolyset( const SHAPE_POLY_SET& aL, std::string name = "",
289 bool aShowVertexNumbers = false );
290 void AnnotatedPolyline( const SHAPE_LINE_CHAIN& aL, std::string name,
291 bool aShowVertexNumbers = false );
292 void AnnotatedPoint( const VECTOR2I p, int size, std::string name = "",
293 bool aShowVertexNumbers = false );
294 void Arc( const SHAPE_ARC& arc );
295 void DrawAnnotations();
296
297private:
298
299
300 std::unique_ptr<LABEL_MANAGER> m_labelMgr;
301};
302
303#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:45
Definition pad.h:54
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:232
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
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
void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, PNS::NET_HANDLE aNet) override
bool IsItemVisible(const PNS::ITEM *aItem) const override
std::vector< LENGTH_DELAY_CALCULATION_ITEM > getLengthDelayCalculationItems(const PNS::ITEM_SET &aLine, const NETCLASS *aNetClass) const
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:73
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:126
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ B_Cu
Definition layer_ids.h:65
@ F_Cu
Definition layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
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.
PCB_LAYER_ID Layer
The layer this track is on.
bool IsDiffPairCoupled
Whether this track or via is a member of a coupled differential pair.
int64_t DiffPairCouplingGap
The gap between coupled tracks.
int64_t Width
The width (in internal units) of the track.
const NETCLASS * NetClass
The net class this track belongs to.
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:61
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694