KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_test_debug_decorator.cpp
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-2021 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
26
27#include <reporter.h>
28#include <router/pns_item.h>
29
30
31#define VERBOSE // Sends PSN_DBG message output to the console
32
33
35{
36 m_iter = 0;
38 m_width = 10000;
39 m_name = "<unknown>";
40 m_parent = aParent;
41 m_visible = true;
42 m_selected = false;
43 m_level = 0;
44}
45
47{
48 for( SHAPE* shape : m_shapes )
49 delete shape;
50
51 for( PNS_DEBUG_SHAPE* child : m_children )
52 delete child;
53}
54
55
57{
58 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE( this );
59 m_children.push_back( ent );
60
61 return ent;
62}
63
64
66{
67 ent->m_parent = this;
68 m_children.push_back( ent );
69}
70
71
73{
74 if( m_visible )
75 return true;
76
77 PNS_DEBUG_SHAPE* parent = m_parent;
78
79 while( parent )
80 {
81 if( parent->m_visible )
82 return true;
83
84 parent = parent->m_parent;
85 }
86
87 return false;
88}
89
90void PNS_DEBUG_SHAPE::IterateTree( std::function<bool( PNS_DEBUG_SHAPE* )> visitor, int depth )
91{
92 if( !visitor( this ) )
93 return;
94
95
96 for( PNS_DEBUG_SHAPE* child : m_children )
97 child->IterateTree( visitor, depth + 1 );
98}
99
100
102{
103 m_name = "<unknown>";
104 m_iter = 0;
106 m_status = false;
107}
108
110{
111 delete m_entries;
112}
113
114
116 m_reporter( aReporter )
117{
118 m_iter = 0;
119 m_grouping = false;
120 m_activeEntry = nullptr;
121 SetDebugEnabled( true );
122}
123
124
126{
127 for( PNS_DEBUG_STAGE* stage : m_stages )
128 delete stage;
129 // fixme: I know it's a hacky tool but it should clean after itself at some point...
130}
131
132
134{
135 if( m_stages.empty() )
136 m_stages.push_back( new PNS_DEBUG_STAGE() );
137
138 return m_stages.back();
139}
140
141
142void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
143 const SRC_LOCATION_INFO& aSrcLoc )
144{
145 PNS_DEBUG_STAGE* stage = currentStage();
146 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
147
148 ent->m_name = name;
149 ent->m_iter = m_iter;
150 ent->m_level = aLevel;
151
152 if( m_activeEntry )
153 m_activeEntry->AddChild( ent );
154
155 m_activeEntry = ent;
156 m_grouping = true;
157}
158
159
161{
162 if( !m_activeEntry )
163 return;
164
166
167 if( !m_activeEntry )
168 m_grouping = false;
169}
170
171
173{
174 auto st = currentStage();
175 m_activeEntry->AddChild( ent );
176}
177
178
180 int aSize, const wxString& aName,
181 const SRC_LOCATION_INFO& aSrcLoc )
182{
184
185 sh->Append( aP.x - aSize, aP.y - aSize );
186 sh->Append( aP.x + aSize, aP.y + aSize );
187 sh->Append( aP.x, aP.y );
188 sh->Append( aP.x - aSize, aP.y + aSize );
189 sh->Append( aP.x + aSize, aP.y - aSize );
190
191 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
192
193 ent->m_shapes.push_back( sh );
194 ent->m_color = aColor;
195 ent->m_width = 30000;
196 ent->m_iter = m_iter;
197 ent->m_name = aName;
198 ent->m_hasLabels = false;
199 ent->m_srcLoc = aSrcLoc;
200
201 addEntry( ent );
202}
203
204
206 int aOverrideWidth, const wxString& aName,
207 const SRC_LOCATION_INFO& aSrcLoc )
208{
209 // TODO(JE) padstacks
210 SHAPE* sh = aItem->Shape( -1 )->Clone();
211 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
212
213 ent->m_shapes.push_back( sh );
214 ent->m_color = aColor;
215 ent->m_width = aOverrideWidth;
216 ent->m_name = aName;
217 ent->m_iter = m_iter;
218 ent->m_srcLoc = aSrcLoc;
219
220 addEntry( ent );
221}
222
223
224void PNS_TEST_DEBUG_DECORATOR::AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
225 int aOverrideWidth, const wxString& aName,
226 const SRC_LOCATION_INFO& aSrcLoc )
227{
228 SHAPE* sh = aShape->Clone();
229 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
230
231 ent->m_shapes.push_back( sh );
232 ent->m_color = aColor;
233 ent->m_width = aOverrideWidth;
234 ent->m_name = aName;
235 ent->m_iter = m_iter;
236 ent->m_srcLoc = aSrcLoc;
237
238 addEntry( ent );
239}
240
241
242void PNS_TEST_DEBUG_DECORATOR::Message( const wxString& msg, const SRC_LOCATION_INFO& aSrcLoc )
243{
244 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
245 ent->m_msg = msg.c_str();
246 ent->m_srcLoc = aSrcLoc;
247 addEntry( ent );
248
249 printf("PNS: %s\n", msg.c_str().AsChar() );
250
251#ifdef VERBOSE
252 static wxString lastMsg;
253
254 if( msg != lastMsg )
255 {
256 m_reporter->Report( msg );
257 lastMsg = msg;
258 }
259#endif
260}
261
262
263void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
264 const SRC_LOCATION_INFO& aSrcLoc )
265{
266 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
267 stage->m_name = name;
268 stage->m_iter = iter;
269
270 m_stages.push_back( stage );
271 m_activeEntry = m_stages.back()->m_entries;
272}
273
275{
276 if( m_stages.empty() )
277 return;
278
279 m_stages.back()->m_status = stat;
280}
281
282
284{
285 PNS_DEBUG_STAGE* st = m_stages[stage];
286 BOX2I bb;
287 bool first = true;
288
289 auto visitor =
290 [&]( PNS_DEBUG_SHAPE* ent ) -> bool
291 {
292 for( SHAPE* sh : ent->m_shapes )
293 {
294 if( first )
295 bb = sh->BBox();
296 else
297 bb.Merge( sh->BBox() );
298
299 first = false;
300 }
301
302 return true;
303 };
304
305 return bb;
306}
const char * name
Definition: DXF_plotter.cpp:57
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D WHITE
Definition: color4d.h:401
void SetDebugEnabled(bool aEnabled)
Base class for PNS router board items.
Definition: pns_item.h:97
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
Definition: pns_item.h:229
std::vector< SHAPE * > m_shapes
PNS_DEBUG_SHAPE * NewChild()
PNS_DEBUG_SHAPE(PNS_DEBUG_SHAPE *aParent=nullptr)
void IterateTree(std::function< bool(PNS_DEBUG_SHAPE *)> visitor, int depth=0)
void AddChild(PNS_DEBUG_SHAPE *ent)
PNS_DEBUG_SHAPE * m_parent
PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO m_srcLoc
std::vector< PNS_DEBUG_SHAPE * > m_children
virtual void AddPoint(const VECTOR2I &aP, const KIGFX::COLOR4D &aColor, int aSize, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
void addEntry(PNS_DEBUG_SHAPE *ent)
virtual void AddItem(const PNS::ITEM *aItem, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
std::vector< PNS_DEBUG_STAGE * > m_stages
BOX2I GetStageExtents(int stage) const
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void BeginGroup(const wxString &name, int aLevel=0, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void AddShape(const SHAPE *aShape, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void NewStage(const wxString &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
PNS_TEST_DEBUG_DECORATOR(REPORTER *aReporter)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
An abstract shape on 2D plane.
Definition: shape.h:126
virtual SHAPE * Clone() const
Return a dynamically allocated copy of the shape.
Definition: shape.h:148
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
PNS_DEBUG_SHAPE * m_entries