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
112 long long int CalculateRoutedPathLength( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
113 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
114 {
115 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = getLengthDelayCalculationItems( aLine, aNetClass );
116
117 const PAD* startPad = nullptr;
118 const PAD* endPad = nullptr;
119
120 if( aStartPad )
121 startPad = static_cast<PAD*>( aStartPad->Parent() );
122
123 if( aEndPad )
124 endPad = static_cast<PAD*>( aEndPad->Parent() );
125
126 constexpr PATH_OPTIMISATIONS opts = {
127 .OptimiseViaLayers = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
128 };
129
130 return m_board->GetLengthCalculation()->CalculateLength( lengthItems, opts, startPad, endPad );
131 }
132
133 int64_t CalculateRoutedPathDelay( const PNS::ITEM_SET& aLine, const PNS::SOLID* aStartPad,
134 const PNS::SOLID* aEndPad, const NETCLASS* aNetClass ) override
135 {
136 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems = getLengthDelayCalculationItems( aLine, aNetClass );
137
138 const PAD* startPad = nullptr;
139 const PAD* endPad = nullptr;
140
141 if( aStartPad )
142 startPad = static_cast<PAD*>( aStartPad->Parent() );
143
144 if( aEndPad )
145 endPad = static_cast<PAD*>( aEndPad->Parent() );
146
147 constexpr PATH_OPTIMISATIONS opts = {
148 .OptimiseViaLayers = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
149 };
150
151 return m_board->GetLengthCalculation()->CalculateDelay( lengthItems, opts, startPad, endPad );
152 }
153
154 std::vector<LENGTH_DELAY_CALCULATION_ITEM> getLengthDelayCalculationItems( const PNS::ITEM_SET& aLine,
155 const NETCLASS* aNetClass ) const
156 {
157 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
158
159 for( int idx = 0; idx < aLine.Size(); idx++ )
160 {
161 const PNS::ITEM* lineItem = aLine[idx];
162
163 if( const PNS::LINE* l = dyn_cast<const PNS::LINE*>( lineItem ) )
164 {
166 item.SetLine( l->CLine() );
167
168 const PCB_LAYER_ID layer = GetBoardLayerFromPNSLayer( lineItem->Layer() );
169 item.SetLayers( layer );
170 item.SetEffectiveNetClass( aNetClass );
171
172 lengthItems.emplace_back( std::move( item ) );
173 }
174 else if( lineItem->OfKind( PNS::ITEM::VIA_T ) && idx > 0 && idx < aLine.Size() - 1 )
175 {
176 const int layerPrev = aLine[idx - 1]->Layer();
177 const int layerNext = aLine[idx + 1]->Layer();
178 const PCB_LAYER_ID pcbLayerPrev = GetBoardLayerFromPNSLayer( layerPrev );
179 const PCB_LAYER_ID pcbLayerNext = GetBoardLayerFromPNSLayer( layerNext );
180
181 if( layerPrev != layerNext )
182 {
184 item.SetVia( static_cast<PCB_VIA*>( lineItem->GetSourceItem() ) );
185 item.SetLayers( pcbLayerPrev, pcbLayerNext );
186 item.SetEffectiveNetClass( aNetClass );
187 lengthItems.emplace_back( std::move( item ) );
188 }
189 }
190 }
191
192 return lengthItems;
193 }
194
195 int64_t CalculateLengthForDelay( int64_t aDesiredDelay, const int aWidth, const bool aIsDiffPairCoupled,
196 const int aDiffPairCouplingGap, const int aPNSLayer,
197 const NETCLASS* aNetClass ) override
198 {
200 ctx.NetClass = aNetClass;
201 ctx.Width = aWidth;
202 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
203 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
204 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
205
206 return m_board->GetLengthCalculation()->CalculateLengthForDelay( aDesiredDelay, ctx );
207 }
208
209 int64_t CalculateDelayForShapeLineChain( const SHAPE_LINE_CHAIN& aShape, int aWidth, bool aIsDiffPairCoupled,
210 int aDiffPairCouplingGap, int aPNSLayer,
211 const NETCLASS* aNetClass ) override
212 {
214 ctx.NetClass = aNetClass;
215 ctx.Width = aWidth;
216 ctx.IsDiffPairCoupled = aIsDiffPairCoupled;
217 ctx.DiffPairCouplingGap = aDiffPairCouplingGap;
218 ctx.Layer = GetBoardLayerFromPNSLayer( aPNSLayer );
219
220 return m_board->GetLengthCalculation()->CalculatePropagationDelayForShapeLineChain( aShape, ctx );
221 }
222
223 private:
224 std::shared_ptr<BOARD> m_board;
225};
226
228{
229public:
230 PNS_LOG_VIEWER_FRAME( wxFrame* frame );
231 virtual ~PNS_LOG_VIEWER_FRAME();
232
233 void LoadLogFile( const wxString& aFile );
234 void SetLogFile( PNS_LOG_FILE* aLog );
235 void SetBoard2( std::shared_ptr<BOARD> aBoard );
237
238 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> GetOverlay() const { return m_overlay; }
239
240private:
241 void drawLoggedItems( int iter );
242 void updateDumpPanel( int iter );
243 virtual void createUserTools() override;
244 void buildListTree( wxTreeListItem item, PNS_DEBUG_SHAPE* ent, int depth = 0 );
245 void syncModel();
247 void updatePnsPreviewItems( int iter );
249 void updateViewerIface();
250
251 virtual void onOpen( wxCommandEvent& event ) override;
252 virtual void onSaveAs( wxCommandEvent& event ) override;
253 virtual void onExit( wxCommandEvent& event ) override;
254 virtual void onRewindScroll( wxScrollEvent& event ) override;
255 virtual void onRewindCountText( wxCommandEvent& event ) override;
256 virtual void onListRightClick( wxMouseEvent& event );
257 virtual void onListSelect( wxCommandEvent& event );
258 virtual void onBtnRewindLeft( wxCommandEvent& event ) override;
259 virtual void onBtnRewindRight( wxCommandEvent& event ) override;
260 virtual void onListChecked( wxCommandEvent& event );
261 virtual void onShowThinLinesChecked( wxCommandEvent& event ) override;
262 virtual void onShowRPIsChecked( wxCommandEvent& event ) override;
263 virtual void onShowVerticesChecked( wxCommandEvent& event ) override;
264 virtual void onFilterText( wxCommandEvent& event ) override;
265 void drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName );
266
267 std::shared_ptr<PNS_LOG_VIEWER_OVERLAY> m_overlay;
268 std::shared_ptr<PNS_LOG_FILE> m_logFile;
269 std::shared_ptr<PNS_LOG_PLAYER> m_logPlayer;
272 std::shared_ptr<KIGFX::VIEW_GROUP> m_previewItems;
273 std::shared_ptr<PNS_VIEWER_IFACE> m_viewerIface;
274 std::map<wxString,wxString> m_filenameToPathMap;
275
276 bool m_showThinLines = true;
277 bool m_showRPIs = true;
278 bool m_showVertices = false;
280 //KI_TEST::CONSOLE_LOG m_consoleLog;
281 std::shared_ptr<WX_TEXT_CTRL_REPORTER> m_reporter;
282};
283
284class LABEL_MANAGER;
285
287{
288public:
290 void AnnotatedPolyset( const SHAPE_POLY_SET& aL, std::string name = "",
291 bool aShowVertexNumbers = false );
292 void AnnotatedPolyline( const SHAPE_LINE_CHAIN& aL, std::string name,
293 bool aShowVertexNumbers = false );
294 void AnnotatedPoint( const VECTOR2I p, int size, std::string name = "",
295 bool aShowVertexNumbers = false );
296 void Arc( const SHAPE_ARC& arc );
297 void DrawAnnotations();
298
299private:
300
301
302 std::unique_ptr<LABEL_MANAGER> m_labelMgr;
303};
304
305#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: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
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: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:61
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694