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